1
0
forked from apxtri/apxtri

change conf.json to adminapi/objects/tribes/itm/adminapi.conf to harmonize all tribes management

This commit is contained in:
philc 2024-10-16 12:55:17 +02:00
parent 053b45c81c
commit 92132e4ae7
22 changed files with 91 additions and 42 deletions

BIN
.package.json.swp Normal file

Binary file not shown.

46
apxchat.js Normal file
View File

@ -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');
});

View File

@ -18,37 +18,38 @@ if (!fs.existsSync("/etc/nginx/nginx.conf")) {
console.log( 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."); "\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'") console.log("Warning, this is a first install you must run 'node setup.js dns=domainename user=sudoerlinux'")
process.exit(); 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 let doms = conf.dns; // only dns of town during the init process
const currentmod = "apxtri"; const currentmod = "apxtri";
const log = conf.api.activelog.includes(currentmod); const log = conf.api.activelog.includes(currentmod);
let tribelist = {}; let tribelist = {};
if (fs.existsSync(`../../idx/tribeId_all.json`)) { if (fs.existsSync(`../../adminapi/objects/tribes/idx/tribes_dns.json`)) {
tribelist = fs.readJsonSync(`../../idx/tribeId_all.json`); tribelist = fs.readJsonSync(`../../adminapi/objects/tribes/idx/tribes_dns.json`);
} }
console.log(tribelist)
let tribeIds = Object.keys(tribelist); let tribeIds = Object.keys(tribelist);
// context is store in /itm/tribename.json ={contexte:{routes:[],models:[{model:,tplstringslg:[]}]} // context is store in /itm/tribename.json ={contexte:{routes:[],models:[{model:,tplstringslg:[]}]}
// routes={url,route} check how to add plugin tribe route later // 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) // keep only the 2 last part (.) of domain name to validate cors with it (generic domain)
let routes = [] let routes = []
tribeIds.forEach((t) => { tribeIds.forEach((t) => {
tribelist[t].dns.forEach((d) => { tribelist[t].forEach((d) => {
const dm = d.split(".").slice(-2).join("."); const dm = d.split(".").slice(-2).join(".");
if (!doms.includes(dm)) doms.push(dm); if (!doms.includes(dm)) doms.push(dm);
console.log("dns", t)
})
//reindex database //reindex database
if (t == "smatchit" || true) {
glob.sync(`../../${t}/objects/*`).forEach(o => { glob.sync(`../../${t}/objects/*`).forEach(o => {
console.log('objetc:', o)
console.log(t, o) console.log(t, o)
Odmdb.runidx(o) Odmdb.runidx(o)
}) })
}
});
const context = {}; const context = {};
const pathtr = path.resolve(`../../${t}`); const pathtr = path.resolve(`../../${t}`);
context.routes = [] 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]) 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) const ctx = fs.readJsonSync(conft)
ctx.context = context ctx.context = context
fs.outputJSONSync(conft, ctx, { spaces: 2 }); 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 // To set depending of data form or get size to send
app.use(bodyParser.urlencoded(conf.api.bodyparse.urlencoded)); 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)); 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.disable("x-powered-by"); // for security
app.locals.tribeids = tribeIds; app.locals.tribeids = tribeIds;
if (log) { if (log) {
@ -112,6 +113,7 @@ app.use((req, res, next) => {
"testcors:", "testcors:",
cor, "headers allowed: [", conf.api.exposedHeaders.join(','), "] match with reg:", regtxt 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({ cors({
origin: cor, origin: cor,
allowedHeaders: conf.api.exposedHeaders, allowedHeaders: conf.api.exposedHeaders,

View File

@ -1,4 +1,4 @@
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod='checkHeaders'; const currentmod='checkHeaders';
const log = conf.api.activelog.includes(currentmod) const log = conf.api.activelog.includes(currentmod)
/** /**

View File

@ -112,8 +112,8 @@ Accessible with https://dns/api/tribename/routename/
```plaintext ```plaintext
// Example of a route // Example of a route
const tribe="smatchit"; const tribe="smatchit";
const conftrib = require(`../../../itm/${tribe}.json`); const conftrib = require(`../../../adminapi/objects/tribes/itm/${tribe}.json`);
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const express = require(`../../../adminapi/apxtri/node_modules/express`); const express = require(`../../../adminapi/apxtri/node_modules/express`);
const fs = require(`../../../adminapi/apxtri/node_modules/fs-extra`); const fs = require(`../../../adminapi/apxtri/node_modules/fs-extra`);
const Nofications = require(`../../../adminapi/apxtri/models/Notifications.js`); const Nofications = require(`../../../adminapi/apxtri/models/Notifications.js`);

View File

@ -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("/media/phil/usbfarm/apxtri/node_modules/openpgp/dist/node/openpgp.js");
const openpgp = require("openpgp"); const openpgp = require("openpgp");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod='isAuthenticated'; const currentmod='isAuthenticated';
const log = conf.api.activelog.includes(currentmod) const log = conf.api.activelog.includes(currentmod)
/** /**

View File

@ -4,7 +4,7 @@ const glob = require("glob");
const jwt = require("jwt-simple"); const jwt = require("jwt-simple");
const axios = require("axios"); const axios = require("axios");
const path = require("path"); const path = require("path");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Odmdb = require("./Odmdb.js"); const Odmdb = require("./Odmdb.js");
// lowercase 1st letter is normal // lowercase 1st letter is normal
const towns = require("./Towns.js"); const towns = require("./Towns.js");

View File

@ -7,7 +7,7 @@ const Mustache = require('mustache');
const Checkjson = require(`./Checkjson.js`); const Checkjson = require(`./Checkjson.js`);
//const smtp = require("smtp-client"); //const smtp = require("smtp-client");
const nodemailer = require("nodemailer"); const nodemailer = require("nodemailer");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod = "Notifications"; const currentmod = "Notifications";
const log = conf.api.activelog.includes(currentmod); const log = conf.api.activelog.includes(currentmod);
/** /**
@ -153,9 +153,9 @@ Notifications.sendsms = async (data, tribeId) => {
}; };
} }
let confsms = conf.sms; 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( 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; if (conftrib.sms) confsms = conftrib.sms;
} }
@ -332,7 +332,7 @@ Notifications.sendmail = async (data, tribe) => {
}; };
} }
let confsmtp = conf.smtp; let confsmtp = conf.smtp;
const conftribfile = `../../itm/${tribe}.json`; const conftribfile = `../../adminapi/objects/tribes/itm/${tribe}.json`;
if (fs.existsSync(conftribfile)) { if (fs.existsSync(conftribfile)) {
const conftrib = fs.readJSONSync(conftribfile); const conftrib = fs.readJSONSync(conftribfile);
if (!conftrib.emailcontact){ if (!conftrib.emailcontact){

View File

@ -3,7 +3,7 @@ const path = require("path");
const fs = require("fs-extra"); const fs = require("fs-extra");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const axios = require("axios"); const axios = require("axios");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Checkjson = require(`./Checkjson.js`); const Checkjson = require(`./Checkjson.js`);
const { promiseHooks } = require("v8"); const { promiseHooks } = require("v8");
const currentmod = "Odmdb"; const currentmod = "Odmdb";

View File

@ -8,7 +8,7 @@ const openpgp = require("openpgp");
const Notifications = require("./Notifications.js"); const Notifications = require("./Notifications.js");
const Odmdb = require("./Odmdb.js"); const Odmdb = require("./Odmdb.js");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod = "Pagans"; const currentmod = "Pagans";
const log = conf.api.activelog.includes(currentmod); const log = conf.api.activelog.includes(currentmod);
/** /**

View File

@ -8,7 +8,7 @@ const openpgp = require("openpgp");
const Notifications = require("./Notifications.js"); const Notifications = require("./Notifications.js");
const Odmdb = require("./Odmdb.js"); const Odmdb = require("./Odmdb.js");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod = "Pagans"; const currentmod = "Pagans";
const log = conf.api.activelog.includes(currentmod); const log = conf.api.activelog.includes(currentmod);
/** /**

View File

@ -4,7 +4,7 @@ const glob = require("glob");
const moment = require("moment"); const moment = require("moment");
const jwt = require("jwt-simple"); const jwt = require("jwt-simple");
const UUID = require("uuid"); const UUID = require("uuid");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Checkjson = require(`./Checkjson.js`); const Checkjson = require(`./Checkjson.js`);
const Odmdb = require("./Odmdb.js"); const Odmdb = require("./Odmdb.js");

View File

@ -3,7 +3,7 @@ const path = require("path");
const fs = require("fs-extra"); const fs = require("fs-extra");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const axios = require("axios"); const axios = require("axios");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Checkjson = require(`./Checkjson.js`); const Checkjson = require(`./Checkjson.js`);
const Trackings = {} const Trackings = {}

View File

@ -10,7 +10,7 @@ const jwt = require( 'jwt-simple' );
const moment = require( 'moment' ); const moment = require( 'moment' );
const UUID = require( 'uuid' ); const UUID = require( 'uuid' );
const Pagans = require( './Pagans.js' ); const Pagans = require( './Pagans.js' );
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Checkjson = require( `./Checkjson.js`); const Checkjson = require( `./Checkjson.js`);
/* /*
tribeid manager tribeid manager

View File

@ -4,7 +4,7 @@ const dnsSync = require("dns-sync");
const mustache = require("mustache"); const mustache = require("mustache");
const readlineSync = require("readline-sync"); const readlineSync = require("readline-sync");
const Odmdb = require("./Odmdb.js"); const Odmdb = require("./Odmdb.js");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Wwws = {}; const Wwws = {};
Wwws.initlocalwco=(tribwco,profils,lg)=>{ Wwws.initlocalwco=(tribwco,profils,lg)=>{
@ -83,10 +83,11 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
if (loc.itms){ if (loc.itms){
Object.keys(loc.itms).forEach((r) => { Object.keys(loc.itms).forEach((r) => {
const src = `../../${loc.itms[r]}.json`; const src = `../../${loc.itms[r]}.json`;
console.log("hhhhhhhhhhhhhh",path.resolve(src))
if (fs.existsSync(src)) { if (fs.existsSync(src)) {
localstorage.itms[r] = fs.readJSONSync(src); localstorage.itms[r] = fs.readJSONSync(src);
} else { } 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 { } else {
localstorage.ref[ localstorage.ref[
r r
] = `Check your ${fileparam} for ref in ${pagename} and ${r}`; ] = `Check your ${fileparam}.json for ref in ${pagename} and ${r}`;
} }
}); });
} }

View File

@ -15,7 +15,7 @@
"restartapx": "pm2 restart apxtri.js --log-date-format 'DD-MM HH:mm:ss.SSS'", "restartapx": "pm2 restart apxtri.js --log-date-format 'DD-MM HH:mm:ss.SSS'",
"dev": "NODE_MODE=dev node apxtri.js", "dev": "NODE_MODE=dev node apxtri.js",
"unittest": "node unittest.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/", "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/..", "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/..", "publishwall": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/tribes/$space phil@wall-ants://home/phil/apxtowns/wall-ants/tribes/$space/..",

View File

@ -1,6 +1,6 @@
const express = require( 'express' ); const express = require( 'express' );
const fs=require('fs-extra'); const fs=require('fs-extra');
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
// Classes // Classes
const Nations = require( '../models/Nations.js' ); const Nations = require( '../models/Nations.js' );

View File

@ -2,7 +2,7 @@ const express = require("express");
const glob = require("glob"); const glob = require("glob");
const fs = require("fs-extra"); const fs = require("fs-extra");
const path = require("path"); const path = require("path");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Odmdb = require("../models/Odmdb.js"); const Odmdb = require("../models/Odmdb.js");
// Middlewares // Middlewares
const checkHeaders = require("../middlewares/checkHeaders.js"); const checkHeaders = require("../middlewares/checkHeaders.js");

View File

@ -9,7 +9,7 @@ const Odmdb = require("../models/Odmdb.js");
const checkHeaders = require("../middlewares/checkHeaders.js"); const checkHeaders = require("../middlewares/checkHeaders.js");
const isAuthenticated = require("../middlewares/isAuthenticated.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 currentmod = "pagans";
const log = conf.api.activelog.includes(currentmod); const log = conf.api.activelog.includes(currentmod);

View File

@ -2,7 +2,7 @@ const express = require("express");
const glob = require("glob"); const glob = require("glob");
const fs = require("fs-extra"); const fs = require("fs-extra");
const path = require("path"); const path = require("path");
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const Odmdb = require("../models/Odmdb.js"); const Odmdb = require("../models/Odmdb.js");
// Middlewares // Middlewares
const checkHeaders = require("../middlewares/checkHeaders"); const checkHeaders = require("../middlewares/checkHeaders");

View File

@ -2,7 +2,7 @@ const express = require( 'express' );
const fs = require( 'fs-extra' ); const fs = require( 'fs-extra' );
const path = require( 'path' ); const path = require( 'path' );
const glob = require('glob'); const glob = require('glob');
const conf = require(`../../../conf.json`); const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
// Classes // Classes
const Tribes = require( '../models/Tribes.js' ); 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' ) req.session.header.accessrights.data[ req.params.tribe ].tribeid.includes( 'R' )
*/ */
if("authorize"=="authorize"){ if("authorize"=="authorize"){
const tribconf=`../../itm/${req.params.tribe}.json` const tribconf=`../../adminapi/objects/tribes/itm/${req.params.tribe}.json`
if (!fs.existsSync(tribconf)){ if (!fs.existsSync(tribconf)){
res.status(404).json({status:404,ref:"Tribes",msg:"tribedoesnotexist", data:{tribe:req.params.tribe}}) res.status(404).json({status:404,ref:"Tribes",msg:"tribedoesnotexist", data:{tribe:req.params.tribe}})
}else{ }else{

View File

@ -141,7 +141,7 @@ Setup.addtribe = (tribeId, town, nation) => {
}; };
idxtrib[tribeId] = tribdata; idxtrib[tribeId] = tribdata;
fs.outputJSON(idxtribf, idxtrib, { spaces: 2 }); 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}/nginx`,
`../../${tribeId}/logs/nginx`, `../../${tribeId}/logs/nginx`,