From 19c6ea4d0d61b5a84e9c006d15d83592072909ce Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Tue, 3 Oct 2023 09:16:43 +0000 Subject: [PATCH] update email and REAME.md --- README.md | 12 +++++++++--- index.js | 16 +++++++++++----- node_modules/.package-lock.json | 5 +++++ node_modules/fs/README.md | 9 +++++++++ node_modules/fs/package.json | 20 ++++++++++++++++++++ package-lock.json | 11 +++++++++++ package.json | 1 + service/giteaService | 5 +++++ 8 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 node_modules/fs/README.md create mode 100644 node_modules/fs/package.json diff --git a/README.md b/README.md index 5f111d6..8dcbcd5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ### 2) Access the folder you just cloned * root@root# ```sh - cd /gitea_CICD + cd gitea_CICD ``` ### 3) Check the directory path * root@root# @@ -17,13 +17,16 @@ ``` * output: /gitea_CICD -### 4) Fill in environment variables +### 4) Fill in environment variables (*) * root@root# ```sh nano service/giteaService ``` * GIT_USERNAME: Username of the git account. * GIT_PASSWORD: Password of the git account. + * GIT_BRANCH: The git branch is needed for the server. + * EMAIL_ADDRESS: Your email address. + * SEND_EMAIL: Turn on/off email sending feature. * PROJECT_PATH: Root path of your project. * FE_PROJECT_PATH: Path of the front-end folder. * BE_PROJECT_PATH: Path of the back-end folder. @@ -34,6 +37,8 @@ ```sh ./install.sh ``` + +![install](https://ibb.co/rFbLqvP) #### ** Note: ** - Project gitea_CICD should be placed at the same folder level as your project @@ -44,4 +49,5 @@ - Depending on the technology your project uses, the "gitea_CICD/service/giteaHook.sh" file will be custom configured to match the technology. - **____ Joseph ____ ** \ No newline at end of file + **____ Joseph ____ ** + diff --git a/index.js b/index.js index 633f935..f3a54a6 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ + const fs = require("fs"); const express = require("express"); const app = express(); const { exec } = require("child_process"); @@ -5,12 +6,14 @@ app.use(express.json()); - app.post("/git/gitea-webhook", (req, res) => { - + app.post("/git/gitea-webhook", async(req, res) => { + const contentFile = await fs.readFileSync("./service/giteaService", "utf8"); + const checkSendMail = contentFile.split("\n").filter((i)=>i.includes("SEND_EMAIL"))[0]?.split("=")[1].trim() + const emailAddress = contentFile.split("\n").filter((i)=>i.includes("EMAIL_ADDRESS"))[0]?.split("=")[1].trim() const giteaEvent = req.headers["x-gitea-event"]; console.log("New event: "+giteaEvent) const body = req.body -// console.log(body) + //console.log(body) res.status(200).send({mess: "The event has been received!", data:req.body}) exec( @@ -21,6 +24,8 @@ // res.status(500).send("PULL ERROR") } console.log(stdout) + + if(checkSendMail==="True"){ const transporter = nodeMailer.createTransport({ pool: true, @@ -35,14 +40,15 @@ const options = { from: "admin@apactech.io", - to: "joseph@apactech.io", + to: emailAddress, subject: "New Git envent: "+giteaEvent , - html: "

*** "+giteaEvent+" event ***

Committer: "+req.body.commits[0]?.committer.name+"

Message: "+req.body.commits[0]?.message+"

Link: "+req.body.commits[0]?.url+"

Process output:

" }; return transporter.sendMail(options); + } }); }); diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 8bea207..994f489 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -318,6 +318,11 @@ "node": ">= 0.6" } }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", diff --git a/node_modules/fs/README.md b/node_modules/fs/README.md new file mode 100644 index 0000000..5e9a74c --- /dev/null +++ b/node_modules/fs/README.md @@ -0,0 +1,9 @@ +# Security holding package + +This package name is not currently in use, but was formerly occupied +by another package. To avoid malicious use, npm is hanging on to the +package name, but loosely, and we'll probably give it to you if you +want it. + +You may adopt this package by contacting support@npmjs.com and +requesting the name. diff --git a/node_modules/fs/package.json b/node_modules/fs/package.json new file mode 100644 index 0000000..11661b0 --- /dev/null +++ b/node_modules/fs/package.json @@ -0,0 +1,20 @@ +{ + "name": "fs", + "version": "0.0.1-security", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npm/security-holder.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/npm/security-holder/issues" + }, + "homepage": "https://github.com/npm/security-holder#readme" +} diff --git a/package-lock.json b/package-lock.json index 21063b5..043c6eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "child_process": "^1.0.2", "express": "^4.18.2", + "fs": "^0.0.1-security", "nodemailer": "^6.9.5", "nodemon": "^3.0.1" } @@ -329,6 +330,11 @@ "node": ">= 0.6" } }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1208,6 +1214,11 @@ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" }, + "fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", diff --git a/package.json b/package.json index 0305ccc..3a55d88 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "dependencies": { "child_process": "^1.0.2", "express": "^4.18.2", + "fs": "^0.0.1-security", "nodemailer": "^6.9.5", "nodemon": "^3.0.1" } diff --git a/service/giteaService b/service/giteaService index b1bf7fd..b487909 100755 --- a/service/giteaService +++ b/service/giteaService @@ -9,6 +9,11 @@ GIT_USERNAME=joseph.le@apactech.io GIT_PASSWORD=Maypjtkh0ng GIT_BRANCH=dev +#Email +EMAIL_ADDRESS=joseph@apactech.io +#Send mail: True or False +SEND_EMAIL=False + #Duong dan goc cua project (*) PROJECT_PATH=/home/joseph/Demo_Git_Webhook