Skip to content

Commit

Permalink
add generation of rapport
Browse files Browse the repository at this point in the history
  • Loading branch information
jenaye committed Dec 21, 2020
1 parent 229bf4b commit a4e61cb
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 3 deletions.
7 changes: 7 additions & 0 deletions api/docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
server {
root /srv/api/public;

location /examples/ {
root /examples;
}

location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}


location ~ ^/index\.php(/|$) {
set_by_lua $upstream_host 'return os.getenv("UPSTREAM") or "php:9000"';
fastcgi_pass $upstream_host;
Expand Down Expand Up @@ -45,4 +50,6 @@ server {
default_type text/plain;
return 200 "healthy\n";
}


}
29 changes: 27 additions & 2 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"@angular/router": "~10.2.0",
"@material/top-app-bar": "^8.0.0",
"axios": "^0.21.0",
"docxtemplater": "^3.19.7",
"file-saver": "^2.0.5",
"moment": "^2.29.1",
"pizzip": "^3.0.6",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</div>
</form>
<br/>

<button mat-button mat-raised-button color="primary" (click)="generate()">Generate document</button>
<mat-card class="example-card" style="margin: 3em; background-color: gainsboro">
<mat-card-header>
<h2>Upload host file</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import {FileInformation} from '../../file-information';
import {MatSnackBar} from "@angular/material/snack-bar";
import axios from 'axios';
import {environment} from "../../../environments/environment";
import Docxtemplater from "docxtemplater";
import PizZip from "pizzip";
import PizZipUtils from "pizzip/utils/index.js";
import { saveAs } from "file-saver";

function loadFile(url, callback) {
PizZipUtils.getBinaryContent(url, callback);
}

@Component({
selector: 'app-mission',
Expand Down Expand Up @@ -109,6 +117,8 @@ export class MissionSingleComponent implements OnInit {
this.users = response['users'];
this.creds = response['credentials'];

console.log(this.users);

this.initForm();
this.id = response.id;

Expand Down Expand Up @@ -189,5 +199,73 @@ export class MissionSingleComponent implements OnInit {
this.router.navigateByUrl(`/missions/${this.id}/add-vuln`);
}

generate() {
console.log("users =>", this.users['hydra:member']);
loadFile(`/assets/template.docx`, (
error,
content
) => {
if (error) {
throw error;
}
var zip = new PizZip(content);
var doc = new Docxtemplater().loadZip(zip);
doc.setData({
CLIENT_NAME: this.missionName,
creds: this.mission.credentials ? this.mission.credentials : 'No Account used',
classification: "C3",
phone: "0661271423",
version: "1.0",
yolo: "yloswag1234",
from: "[email protected]",
to: "[email protected]",
authors: this.users,
scope: this.hosts
});
try {
// render the document (replace all occurences of key by your data)
doc.render();
} catch (error) {
// The error thrown here contains additional information when logged with JSON.stringify (it contains a properties object containing all suberrors).
function replaceErrors(key, value) {
if (value instanceof Error) {
return Object.getOwnPropertyNames(value).reduce(function(
error,
key
) {
error[key] = value[key];
return error;
},
{});
}
return value;
}
console.log(JSON.stringify({ error: error }, replaceErrors));

if (error.properties && error.properties.errors instanceof Array) {
const errorMessages = error.properties.errors
.map(function(error) {
return error.properties.explanation;
})
.join("\n");
console.log("errorMessages", errorMessages);
// errorMessages is a humanly readable message looking like this :
// 'The tag beginning with "foobar" is unopened'
}
throw error;
}
var out = doc.getZip().generate({
type: "blob",
mimeType:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}); //Output the document using Data-URI
saveAs(out, "rapport.docx");
});
}

share() {
window.alert("The product has been shared!");
}


}
Binary file added client/src/assets/template.docx
Binary file not shown.

0 comments on commit a4e61cb

Please sign in to comment.