diff --git a/.package.json.swp b/.package.json.swp new file mode 100644 index 0000000..29a09fd Binary files /dev/null and b/.package.json.swp differ diff --git a/apxchat.js b/apxchat.js new file mode 100644 index 0000000..f614709 --- /dev/null +++ b/apxchat.js @@ -0,0 +1,46 @@ +const express = require('express'); +const app = express(); +const http = require('http'); +const server = http.createServer(app); +const { Server } = require("socket.io"); +const io = new Server(server); +const nodepgp = require('node-pgp'); // ou une autre bibliothèque PGP +const openpgp = require("openpgp"); +// ... (initialisation de nodepgp) + +io.on('connection', (socket) => { + // Gestion de la connexion d'un utilisateur + // ... + + socket.on('message', async (data) => { + // Vérifier si le destinataire est connecté + // ... + + // Générer une nouvelle clé de session + const sessionKey = await nodepgp.generateKey({ + bits: 2048, + type: 'rsa' + }); + + // Chiffrer le message avec la clé publique du destinataire et la clé de session + const encryptedMessage = await nodepgp.encrypt({ + message: data.message, + publicKeys: [destinataire.publicKey], + signingKeys: [sessionKey.privateKey] + }); + + // Envoyer la clé de session chiffrée avec la clé publique du destinataire + // et le message chiffré au destinataire + socket.to(destinataire.id).emit('message', { + message: encryptedMessage, + sessionKey: await nodepgp.encrypt({ + message: sessionKey.publicKey, + publicKeys: [destinataire.publicKey] + }) + }); + }); +}); + +server.listen(3030, () => { + console.log('apxchat listening on *:3030'); +}); \ No newline at end of file diff --git a/apxtri.js b/apxtri.js index 859b94b..82ede61 100755 --- a/apxtri.js +++ b/apxtri.js @@ -18,37 +18,38 @@ if (!fs.existsSync("/etc/nginx/nginx.conf")) { console.log( "\x1b[31m Check documentation, nginx have to be installed on this server first, no /etc/nginx/nginx.conf available, install then rerun yarn command."); } -if (!fs.existsSync("../../conf.json")) { +if (!fs.existsSync("../objects/tribes/itm/adminapi.json")) { console.log("Warning, this is a first install you must run 'node setup.js dns=domainename user=sudoerlinux'") process.exit(); } -const conf = require(path.resolve(`../../conf.json`)); +const conf = require(path.resolve("../objects/tribes/itm/adminapi.json")); let doms = conf.dns; // only dns of town during the init process const currentmod = "apxtri"; const log = conf.api.activelog.includes(currentmod); let tribelist = {}; -if (fs.existsSync(`../../idx/tribeId_all.json`)) { - tribelist = fs.readJsonSync(`../../idx/tribeId_all.json`); +if (fs.existsSync(`../../adminapi/objects/tribes/idx/tribes_dns.json`)) { + tribelist = fs.readJsonSync(`../../adminapi/objects/tribes/idx/tribes_dns.json`); } +console.log(tribelist) let tribeIds = Object.keys(tribelist); // context is store in /itm/tribename.json ={contexte:{routes:[],models:[{model:,tplstringslg:[]}]} // routes={url,route} check how to add plugin tribe route later // keep only the 2 last part (.) of domain name to validate cors with it (generic domain) let routes = [] tribeIds.forEach((t) => { - tribelist[t].dns.forEach((d) => { + tribelist[t].forEach((d) => { const dm = d.split(".").slice(-2).join("."); if (!doms.includes(dm)) doms.push(dm); - //reindex database - if (t == "smatchit" || true) { - glob.sync(`../../${t}/objects/*`).forEach(o => { - console.log(t, o) - Odmdb.runidx(o) - }) - } - }); + console.log("dns", t) + }) + //reindex database + glob.sync(`../../${t}/objects/*`).forEach(o => { + console.log('objetc:', o) + console.log(t, o) + Odmdb.runidx(o) + }) const context = {}; const pathtr = path.resolve(`../../${t}`); context.routes = [] @@ -64,7 +65,7 @@ tribeIds.forEach((t) => { tplstrings: glob.sync(`${pathtr}/objects/tplstrings/${modname}_*.json`).map(l => path.basename(l, '.json').split("_")[1]) } }) - const conft = `../../itm/${t}.json` + const conft = `../../adminapi/objects/tribes/itm/${t}.json` const ctx = fs.readJsonSync(conft) ctx.context = context fs.outputJSONSync(conft, ctx, { spaces: 2 }); @@ -77,9 +78,9 @@ Object.keys(conf.api.appset).forEach((p) => { }); // To set depending of data form or get size to send app.use(bodyParser.urlencoded(conf.api.bodyparse.urlencoded)); -// To set depending of post put json data size to send -app.use(express.json({ limit: '10mb', type: 'application/json', rawBody: true })); app.use(bodyParser.json(conf.api.bodyparse.json)); +// To set depending of post put json data size to send +app.use(express.json(conf.api.json)); app.disable("x-powered-by"); // for security app.locals.tribeids = tribeIds; if (log) { @@ -112,6 +113,7 @@ app.use((req, res, next) => { "testcors:", cor, "headers allowed: [", conf.api.exposedHeaders.join(','), "] match with reg:", regtxt ); + if (!cor) console.log(`The domain name ${req.headers.origin} is not allow to access for CORS settings, add it in itm/tribename.json in dns`) cors({ origin: cor, allowedHeaders: conf.api.exposedHeaders, diff --git a/middlewares/checkHeaders.js b/middlewares/checkHeaders.js index 1da0199..ca69c73 100755 --- a/middlewares/checkHeaders.js +++ b/middlewares/checkHeaders.js @@ -1,4 +1,4 @@ -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod='checkHeaders'; const log = conf.api.activelog.includes(currentmod) /** diff --git a/middlewares/header.md b/middlewares/header.md index ac9caaa..144d7f5 100644 --- a/middlewares/header.md +++ b/middlewares/header.md @@ -112,8 +112,8 @@ Accessible with https://dns/api/tribename/routename/ ```plaintext // Example of a route const tribe="smatchit"; -const conftrib = require(`../../../itm/${tribe}.json`); -const conf = require(`../../../conf.json`); +const conftrib = require(`../../../adminapi/objects/tribes/itm/${tribe}.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const express = require(`../../../adminapi/apxtri/node_modules/express`); const fs = require(`../../../adminapi/apxtri/node_modules/fs-extra`); const Nofications = require(`../../../adminapi/apxtri/models/Notifications.js`); diff --git a/middlewares/isAuthenticated.js b/middlewares/isAuthenticated.js index 4d04ce8..12ce180 100755 --- a/middlewares/isAuthenticated.js +++ b/middlewares/isAuthenticated.js @@ -6,7 +6,7 @@ const glob = require("glob"); // const openpgp = require("/media/phil/usbfarm/apxtri/node_modules/openpgp/dist/node/openpgp.js"); const openpgp = require("openpgp"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod='isAuthenticated'; const log = conf.api.activelog.includes(currentmod) /** diff --git a/models/Nations.js b/models/Nations.js index cb05f91..caf7119 100755 --- a/models/Nations.js +++ b/models/Nations.js @@ -4,7 +4,7 @@ const glob = require("glob"); const jwt = require("jwt-simple"); const axios = require("axios"); const path = require("path"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Odmdb = require("./Odmdb.js"); // lowercase 1st letter is normal const towns = require("./Towns.js"); diff --git a/models/Notifications.js b/models/Notifications.js index a0fd426..116e40e 100644 --- a/models/Notifications.js +++ b/models/Notifications.js @@ -7,7 +7,7 @@ const Mustache = require('mustache'); const Checkjson = require(`./Checkjson.js`); //const smtp = require("smtp-client"); const nodemailer = require("nodemailer"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod = "Notifications"; const log = conf.api.activelog.includes(currentmod); /** @@ -153,9 +153,9 @@ Notifications.sendsms = async (data, tribeId) => { }; } let confsms = conf.sms; - if (fs.existsSync(`../../itm/${req.session.header.xtribe}.json`)) { + if (fs.existsSync(`../../adminapi/objects/tribes/itm/${req.session.header.xtribe}.json`)) { const conftrib = fs.readJSONSync( - `../../itm/${req.session.header.xtribe}.json` + `../../adminapi/objects/tribes/itm/${req.session.header.xtribe}.json` ); if (conftrib.sms) confsms = conftrib.sms; } @@ -332,7 +332,7 @@ Notifications.sendmail = async (data, tribe) => { }; } let confsmtp = conf.smtp; - const conftribfile = `../../itm/${tribe}.json`; + const conftribfile = `../../adminapi/objects/tribes/itm/${tribe}.json`; if (fs.existsSync(conftribfile)) { const conftrib = fs.readJSONSync(conftribfile); if (!conftrib.emailcontact){ diff --git a/models/Odmdb.js b/models/Odmdb.js index 5f3a716..8577aeb 100644 --- a/models/Odmdb.js +++ b/models/Odmdb.js @@ -3,7 +3,7 @@ const path = require("path"); const fs = require("fs-extra"); const dayjs = require("dayjs"); const axios = require("axios"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Checkjson = require(`./Checkjson.js`); const { promiseHooks } = require("v8"); const currentmod = "Odmdb"; diff --git a/models/Pagans.js b/models/Pagans.js index d0ab126..5b8cf9b 100644 --- a/models/Pagans.js +++ b/models/Pagans.js @@ -8,7 +8,7 @@ const openpgp = require("openpgp"); const Notifications = require("./Notifications.js"); const Odmdb = require("./Odmdb.js"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod = "Pagans"; const log = conf.api.activelog.includes(currentmod); /** diff --git a/models/PagansPeter.js b/models/PagansPeter.js index b8d0fcd..f1f86ad 100644 --- a/models/PagansPeter.js +++ b/models/PagansPeter.js @@ -8,7 +8,7 @@ const openpgp = require("openpgp"); const Notifications = require("./Notifications.js"); const Odmdb = require("./Odmdb.js"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod = "Pagans"; const log = conf.api.activelog.includes(currentmod); /** diff --git a/models/Towns.js b/models/Towns.js index ea88627..75a02f7 100644 --- a/models/Towns.js +++ b/models/Towns.js @@ -4,7 +4,7 @@ const glob = require("glob"); const moment = require("moment"); const jwt = require("jwt-simple"); const UUID = require("uuid"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Checkjson = require(`./Checkjson.js`); const Odmdb = require("./Odmdb.js"); diff --git a/models/Trackings.js b/models/Trackings.js index 7e49f37..e14a97d 100644 --- a/models/Trackings.js +++ b/models/Trackings.js @@ -3,7 +3,7 @@ const path = require("path"); const fs = require("fs-extra"); const dayjs = require("dayjs"); const axios = require("axios"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Checkjson = require(`./Checkjson.js`); const Trackings = {} diff --git a/models/Tribes.js b/models/Tribes.js index e20ab48..11bf68f 100755 --- a/models/Tribes.js +++ b/models/Tribes.js @@ -10,7 +10,7 @@ const jwt = require( 'jwt-simple' ); const moment = require( 'moment' ); const UUID = require( 'uuid' ); const Pagans = require( './Pagans.js' ); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Checkjson = require( `./Checkjson.js`); /* tribeid manager diff --git a/models/Wwws.js b/models/Wwws.js index e20179a..1d0aa5e 100644 --- a/models/Wwws.js +++ b/models/Wwws.js @@ -4,7 +4,7 @@ const dnsSync = require("dns-sync"); const mustache = require("mustache"); const readlineSync = require("readline-sync"); const Odmdb = require("./Odmdb.js"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Wwws = {}; Wwws.initlocalwco=(tribwco,profils,lg)=>{ @@ -83,10 +83,11 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { if (loc.itms){ Object.keys(loc.itms).forEach((r) => { const src = `../../${loc.itms[r]}.json`; + console.log("hhhhhhhhhhhhhh",path.resolve(src)) if (fs.existsSync(src)) { localstorage.itms[r] = fs.readJSONSync(src); } else { - localstorage.itms[r] = `Check your ${fileparam} for itms in ${pagename} and ${r}`; + localstorage.itms[r] = `Check your ${fileparam}.json for itms in ${pagename} and ${r}`; } }); } @@ -98,7 +99,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => { } else { localstorage.ref[ r - ] = `Check your ${fileparam} for ref in ${pagename} and ${r}`; + ] = `Check your ${fileparam}.json for ref in ${pagename} and ${r}`; } }); } diff --git a/package.json b/package.json index 72bc5e9..89f9b33 100755 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "restartapx": "pm2 restart apxtri.js --log-date-format 'DD-MM HH:mm:ss.SSS'", "dev": "NODE_MODE=dev node apxtri.js", "unittest": "node unittest.js", - "tar2prod": "rm ../objects/wwws/cdn/share/apxtriV* && tar -czf ../objects/wwws/cdn/share/apxtriV$version.tar --exclude='node_modules' --exclude='.git' ../../adminapi/apxtri ../../adminapi/schema ../../adminapi/objects ../../adminapi/template ../../itm/adminapi.json", + "tar2prod": "rm ../objects/wwws/cdn/share/apxtriV* && tar -czf ../objects/wwws/cdn/share/apxtriV$version.tar --exclude='node_modules' --exclude='.git' ../../adminapi/apxtri ../../adminapi/schema ../../adminapi/objects ../../adminapi/template ../../adminapi/objects/tribes/itm/adminapi.json", "apidoc": "apidoc -c ../../$tribe/apxtri/apidoc_$tribe.json -o ../../$tribe/objects/wwws/apidoc/", "publishtestwall": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/tribes/$space phil@wall-ants://home/phil/apxtowns/testwall-ants/tribes/$space/..", "publishwall": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/tribes/$space phil@wall-ants://home/phil/apxtowns/wall-ants/tribes/$space/..", diff --git a/routes/nations.js b/routes/nations.js index 9fa40d2..9827353 100755 --- a/routes/nations.js +++ b/routes/nations.js @@ -1,6 +1,6 @@ const express = require( 'express' ); const fs=require('fs-extra'); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); // Classes const Nations = require( '../models/Nations.js' ); diff --git a/routes/odmdb.js b/routes/odmdb.js index e815515..466b8dc 100644 --- a/routes/odmdb.js +++ b/routes/odmdb.js @@ -2,7 +2,7 @@ const express = require("express"); const glob = require("glob"); const fs = require("fs-extra"); const path = require("path"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Odmdb = require("../models/Odmdb.js"); // Middlewares const checkHeaders = require("../middlewares/checkHeaders.js"); diff --git a/routes/pagans.js b/routes/pagans.js index 8db2f0f..4421eed 100755 --- a/routes/pagans.js +++ b/routes/pagans.js @@ -9,7 +9,7 @@ const Odmdb = require("../models/Odmdb.js"); const checkHeaders = require("../middlewares/checkHeaders.js"); const isAuthenticated = require("../middlewares/isAuthenticated.js"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const currentmod = "pagans"; const log = conf.api.activelog.includes(currentmod); diff --git a/routes/trackings.js b/routes/trackings.js index 7144fb4..7f5d1b0 100644 --- a/routes/trackings.js +++ b/routes/trackings.js @@ -2,7 +2,7 @@ const express = require("express"); const glob = require("glob"); const fs = require("fs-extra"); const path = require("path"); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); const Odmdb = require("../models/Odmdb.js"); // Middlewares const checkHeaders = require("../middlewares/checkHeaders"); diff --git a/routes/tribes.js b/routes/tribes.js index 1340030..162781c 100755 --- a/routes/tribes.js +++ b/routes/tribes.js @@ -2,7 +2,7 @@ const express = require( 'express' ); const fs = require( 'fs-extra' ); const path = require( 'path' ); const glob = require('glob'); -const conf = require(`../../../conf.json`); +const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`); // Classes const Tribes = require( '../models/Tribes.js' ); @@ -31,7 +31,7 @@ router.get('/config/:tribe', checkHeaders,isAuthenticated,(req,res)=>{ req.session.header.accessrights.data[ req.params.tribe ].tribeid.includes( 'R' ) */ if("authorize"=="authorize"){ - const tribconf=`../../itm/${req.params.tribe}.json` + const tribconf=`../../adminapi/objects/tribes/itm/${req.params.tribe}.json` if (!fs.existsSync(tribconf)){ res.status(404).json({status:404,ref:"Tribes",msg:"tribedoesnotexist", data:{tribe:req.params.tribe}}) }else{ diff --git a/setup.js b/setup.js index bbc897a..ee37275 100644 --- a/setup.js +++ b/setup.js @@ -141,7 +141,7 @@ Setup.addtribe = (tribeId, town, nation) => { }; idxtrib[tribeId] = tribdata; fs.outputJSON(idxtribf, idxtrib, { spaces: 2 }); - fs.outputJSON("../../itm/${tribeId}.json", tribdata, { space: 2 }); + fs.outputJSON("../../adminapi/objects/tribes/itm/${tribeId}.json", tribdata, { space: 2 }); [ `../../${tribeId}/nginx`, `../../${tribeId}/logs/nginx`,