Skip to content

Commit

Permalink
Merge pull request #68 from 4urcloud/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
estebanmathia authored Oct 24, 2023
2 parents 7b70156 + 25a78a2 commit 4e807f4
Show file tree
Hide file tree
Showing 67 changed files with 2,688 additions and 1,179 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ build
Kexa/rules/aws-tests.yaml
config_kuber
eastern-rider-263712-9376010a1184.json
config/*.json
config_kuber
config/addOnNeed.json
config/headers.json
config_kuber
config/resources*.html
config/resources*.json
4 changes: 2 additions & 2 deletions Kexa/__tests__/rules/test2/rule-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
objectName: ec2Instance
conditions:
- operator: NAND
rules:
criteria:
- property: State
condition: EQUAL
value: terminated
Expand Down Expand Up @@ -110,7 +110,7 @@
condition: ALL
value:
- operator: AND
rules:
criteria:
- property: FromPort
condition: REGEX
value: '^\d+$'
Expand Down
4 changes: 2 additions & 2 deletions Kexa/__tests__/rules/test2/rule-test2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
objectName: ec2Instance
conditions:
- operator: NAND
rules:
criteria:
- property: State
condition: EQUAL
value: terminated
Expand Down Expand Up @@ -110,7 +110,7 @@
condition: ALL
value:
- operator: AND
rules:
criteria:
- property: FromPort
condition: REGEX
value: '^\d+$'
Expand Down
170 changes: 168 additions & 2 deletions Kexa/emails/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const Emails = {
<div style="margin:0px auto;max-width:640px;background:transparent;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:transparent;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:40px 0px;"><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0"><tr><td style="vertical-align:top;width:640px;">
<![endif]--><div aria-labelledby="mj-column-per-100" class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0"><tbody><tr><td style="width:138px;"><a href="https://click.discord.com/ls/click?upn=3DqDOo8cnwIoKzt0aLL1cBeARJoBrGSa2vu41A5vK-2B4ute1kWYI6zNuxQFCVciWW4KHGYg_QW0xIquR3VakdFxkxznmRW4cx8VEMk2PnXtv2QuOQ7vygTNIMpIQ8jyBV38bQyboGXXkKtQAwE9lVWzoU4pvWzpsPct0k7K0OcaiEPnnDIbQK7O-2Bk05p09cSoYgsH-2FEcSy-2FBBnny5AN20KZoAjYPr2bjmG136A-2BFAA22p5G0iVZrpUYCh5Fcg-2FoFHra4p-2Bouz-2BGLAgmTV2Yb0oiG0o-2Bi9HzB-2F1YBWibv-2BMyWjmV4TiAKBncye-2FaSXLJw8VRNxdGp" target="_blank"></a></td></tr></tbody></table></td></tr></tbody></table></div><!--[if mso | IE]>
<![endif]--><div aria-labelledby="mj-column-per-100" class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0"><tbody><tr><td style="width:138px;"></td></tr></tbody></table></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
Expand Down Expand Up @@ -248,7 +248,7 @@ export const Emails = {
<div style="margin:0px auto;max-width:640px;background:transparent;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:transparent;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:40px 0px;"><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0"><tr><td style="vertical-align:top;width:640px;">
<![endif]--><div aria-labelledby="mj-column-per-100" class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0"><tbody><tr><td style="width:138px;"><a href="https://click.discord.com/ls/click?upn=3DqDOo8cnwIoKzt0aLL1cBeARJoBrGSa2vu41A5vK-2B4ute1kWYI6zNuxQFCVciWW4KHGYg_QW0xIquR3VakdFxkxznmRW4cx8VEMk2PnXtv2QuOQ7vygTNIMpIQ8jyBV38bQyboGXXkKtQAwE9lVWzoU4pvWzpsPct0k7K0OcaiEPnnDIbQK7O-2Bk05p09cSoYgsH-2FEcSy-2FBBnny5AN20KZoAjYPr2bjmG136A-2BFAA22p5G0iVZrpUYCh5Fcg-2FoFHra4p-2Bouz-2BGLAgmTV2Yb0oiG0o-2Bi9HzB-2F1YBWibv-2BMyWjmV4TiAKBncye-2FaSXLJw8VRNxdGp" target="_blank"></a></td></tr></tbody></table></td></tr></tbody></table></div><!--[if mso | IE]>
<![endif]--><div aria-labelledby="mj-column-per-100" class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0"><tbody><tr><td style="width:138px;"></td></tr></tbody></table></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
Expand Down Expand Up @@ -342,4 +342,170 @@ export const Emails = {
<![endif]--></div>
</html>`
},
Recap : (compteError: number[], allScanRenderTable: string, alert: GlobalConfigAlert) => {return `<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title></title>
<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=3Dedge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=3DUTF-8">
<style type="text/css">
#outlook a { padding: 0; }
.ReadMsgBody { width: 100%; }
.ExternalClass { width: 100%; }
.ExternalClass * { line-height:100%; }
body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
table, td { border-collapse:collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; }
p { display: block; margin: 13px 0; }
</style>
<!--[if !mso]><!-->
<style type="text/css">
@media only screen and (max-width:480px) {
@-ms-viewport { width:320px; }
@viewport { width:320px; }
}
</style>
<!--<![endif]-->
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.outlook-group-fix {
width:100% !important;
}
</style>
<![endif]-->
<!--[if !mso]><!-->
<link href="https://fonts.googleapis.com/css?family=3DUbuntu:300,400,500,700" rel="stylesheet" type="text/css">
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=3DUbuntu:300,400,500,700);
</style>
<!--<![endif]--><style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100, * [aria-labelledby="mj-column-per-100"] { width:100%!important; }
}
</style>
</head>
<body style="background: #F9F9F9;">
<div style="background-color:#F9F9F9;"><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0" width="640" align="center" style="width:640px;">
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:e=
xactly;">
<![endif]-->
<style type="text/css">
html, body, * {
-webkit-text-size-adjust: none;
text-size-adjust: none;
}
a {
color:#1EB0F4;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
</style>
<div style="margin:0px auto;max-width:640px;background:transparent;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:transparent;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:40px 0px;"><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0"><tr><td style="vertical-align:top;width:640px;">
<![endif]--><div aria-labelledby="mj-column-per-100" class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:collapse;border-spacing:0px;" align="center" border="0"><tbody><tr><td style="width:138px;"></td></tr></tbody></table></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]-->
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0" width="640" align="center" style="width:640px;">
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:e=
xactly;">
<![endif]--><div style="max-width:640px;margin:0 auto;box-shadow:0px 1px 5px rgba(0,0,0,0.1);border-radius:4px;overflow:hidden"><div style="margin:0px auto;max-width:640px;background:#ffffff;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:#ffffff;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:40px 50px;"><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0"><tr><td style="vertical-align:top;width:640px;">
<![endif]--><div aria-labelledby="mj-column-per-100" class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="left"><div style="cursor:auto;color:#737F8D;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;line-height:24px;text-align:left;">
<p>
Kexa have done a scan on your server, please check the code below to know more about the render.
</p>
</div></td></tr><tr><td style="word-break:break-word;font-size:0px;padding:10px 25px;padding-top:20px;" align="center"><table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background:#f2f3f4;background-color:#f2f3f4;width:100%">
<tbody>
<tr>
<td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center" colspan="4">
<div style="font-family:Poppins,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:24px;font-weight:bold;line-height:36px;text-align:center;color:#4f5660"> `+ (alert.name??'Uname global alert') +` </div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tbody>
`+
compteError.map((compte, index) => {
return `
<tr>
<td style="direction:ltr;padding:20px 0;text-align:center" colspan="1">
`+ levelAlert[index] +` :
</td>
<td style="direction:ltr;padding:20px 0;text-align:center" colspan="3">
` + compte + `
</td>
</tr>
`}).join('')
+`
</tbody>
</table>
</td>
</tr>
`+
allScanRenderTable
+`
<tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="left"><div style="cursor:auto;color:#747F8D;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;line-height:16px;text-align:left;">
<p style="direction:ltr;;padding:20px 0;text-align:center">Thank you, for using Kexa</p>
</div></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]-->
<!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0" width="640" align="center" style="width:640px;">
<tr>
<td style="line-height:0px;font-size:0px;mso-line-height-rule:e=
xactly;">
<![endif]--></div><div style="margin:0px auto;max-width:640px;background:transparent;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:transparent;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:20px 0px;"><!--[if mso | IE]=
>
<table role="presentation" border="0" cellpadding="0" cellspaci=
ng="0"><tr><td style="vertical-align:top;width:640px;">
<![endif]--></td></tr><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="center"><div style="cursor:auto;color:#99AAB5;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12px;line-height:24px;text-align:center;">
4urcloud - 2023
</div></td></tr><tr><td style="word-break:break-word;font-size:0px;padding:0px;" align="left"><div style="cursor:auto;color:#000000;font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px;line-height:22px;text-align:left;">
</div></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></div>
</html>`
}
}
23 changes: 20 additions & 3 deletions Kexa/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const logger = new Logger({ minLevel: 3, type: "pretty", name: "GcpLogger" });
export function writeStringToJsonFile(data: string, filePath: string): boolean {
try {
const fileExists = fs.existsSync(filePath);
logger.debug("File exists: " + fileExists)
logger.debug("File exists: " + fileExists);
if (!fileExists) {
logger.debug("Creating file: " + filePath)
logger.debug("Creating file: " + filePath);
const initialData = JSON.stringify({});
fs.writeFileSync(filePath, initialData);
}
logger.debug("Writing data to file: " + filePath)
logger.debug("Writing data to file: " + filePath);
fs.writeFileSync(filePath, JSON.stringify(JSON.parse(data), null, 4), 'utf8');
return true;
} catch (error) {
Expand Down Expand Up @@ -44,3 +44,20 @@ export function getFile(filePath: string){
return null;
}
}

export function writeFileSync(data: string, filePath:string):boolean{
try{
const fileExists = fs.existsSync(filePath);
logger.debug("File exists: " + fileExists);
if(!fileExists){
logger.debug("Creating file: " + filePath);
fs.writeFileSync(filePath, "");
}
logger.debug("Writing data to file: " + filePath);
fs.writeFileSync(filePath, data);
return true;
}catch(error){
logger.error(error);
return false;
}
}
19 changes: 14 additions & 5 deletions Kexa/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import env from "dotenv";
import { Logger } from "tslog";
import { checkRules, gatheringRules } from "./services/analyse.service";
import { alertGlobal } from "./services/alerte.service";
import { AsciiArtText, talkAboutOtherProject} from "./services/display.service";
import { AsciiArtText, renderTableAllScan, talkAboutOtherProject} from "./services/display.service";
import { getEnvVar } from "./services/manageVarEnvironnement.service";
import { loadAddOns } from "./services/addOn.service";
import { deleteFile, writeStringToJsonFile } from "./helpers/files";
import { deleteFile, writeFileSync, writeStringToJsonFile } from "./helpers/files";
import {getContext, getNewLogger} from "./services/logger.service";
import { Context } from "@azure/functions";
import { Emails } from "./emails/emails";

const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
Expand All @@ -30,6 +29,7 @@ export async function main() {

context?.log("logger configured");

//logger.debug("args");
//logger.debug(args);
AsciiArtText("Kexa");
logger.info("___________________________________________________________________________________________________");
Expand All @@ -41,12 +41,21 @@ export async function main() {
let resources = {};
resources = await loadAddOns(resources);
context?.log("resources", resources);
if(args.o) writeStringToJsonFile(JSON.stringify(resources), "./config/resultScan"+ new Date().toISOString().slice(0, 16).replace(/[-T:/]/g, '') +".json");
if(args.o) writeStringToJsonFile(JSON.stringify(resources), "./config/resources"+ new Date().toISOString().slice(0, 16).replace(/[-T:/]/g, '') +".json");
context?.log("good");
settings.forEach(setting => {
context?.log("setting", setting);
let result = checkRules(setting.rules, resources, setting.alert);
if(setting.alert.global.enabled){
let render_table = renderTableAllScan(result.map(scan => scan.filter(value => value.error.length>0)));
let compteError = [0,0,0,0];
result.forEach((rule) => {
rule.forEach((scan) => {
if(scan.error.length > 0) compteError[scan.rule?.level??4]++;
});
});
let mail = Emails.Recap(compteError, render_table, setting.alert.global);
writeFileSync(mail, "./config/resources"+ setting.alert.global.name + new Date().toISOString().slice(0, 16).replace(/[-T:/]/g, '') +".html");
alertGlobal(result, setting.alert.global);
}
});
Expand Down
1 change: 1 addition & 0 deletions Kexa/models/http/request.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface HttpRequest {
code: number|null;
url: string|null;
ip: any|null;
delays: number|null;
}
2 changes: 1 addition & 1 deletion Kexa/models/settingFile/conditions.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export interface ParentRules {
name?:string;
description?:string;
operator:OperatorEnum; // AND, OR, NOT, XOR, NAND, NOR, XNOR
rules: RulesConditions[]|ParentRules[]; // the conditions to create the rule
criteria: RulesConditions[]|ParentRules[]; // the conditions to create the rule
}
Loading

0 comments on commit 4e807f4

Please sign in to comment.