change path

This commit is contained in:
philc 2024-11-15 13:19:01 +01:00
parent cdcab5bf38
commit 34c780d460
10 changed files with 63 additions and 59 deletions

View File

@ -1,3 +1,4 @@
const path=require('path')
const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod='checkHeaders';
const log = conf.api.activelog.includes(currentmod)
@ -16,7 +17,9 @@ const log = conf.api.activelog.includes(currentmod)
* @apiHeader {array[]} xprofils list of string profil apply into xtribe for xapp
* @apiHeader {string} xuuid a unique number uuid.v4 created the fisrt time a domain is visited on a device
* @apiHeader {integer} xtrkversion a version number link to tracking system
* @apiHeaderExample {json} Header-Example for anonymous:
* @apiHeaderExample {json} Headeconst conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod='checkHeaders';
const log = conf.api.activelog.includes(currentmod)r-Example for anonymous:
* {
* "xtrkversion":1,
* "xtribe":"smatchit",

View File

@ -38,18 +38,18 @@ const isAuthenticated = async (req, res, next) => {
if (fs.existsSync('../tmp/tokens')) console.log('pass B')
*/
const currentday = dayjs().date();
fs.ensureDirSync(`../tmp/tokens`);
fs.ensureDirSync(`../adminapi/tmp/tokens`);
let menagedone = fs.existsSync(
`../../tmp/tokens/menagedone${currentday}`
`../adminapi/tmp/tokens/menagedone${currentday}`
);
if (menagedone) console.log(Date.now(),`menagedone${currentday} was it done today?:${menagedone}`);
if (!menagedone) {
// clean oldest
const tsday = dayjs().valueOf(); // now in timestamp format
glob.sync(`../../tmp/tokens/menagedone*`).forEach((f) => {
glob.sync(`../adminapi/tmp/tokens/menagedone*`).forEach((f) => {
fs.removeSync(f);
});
glob.sync(`../../tmp/tokens/*.json`).forEach((f) => {
glob.sync(`../adminapi/tmp/tokens/*.json`).forEach((f) => {
const fsplit = f.split("_");
const elapse = tsday - parseInt(fsplit[2]);
//24h 86400000 milliseconde 15mn 900000
@ -58,11 +58,11 @@ const isAuthenticated = async (req, res, next) => {
}
});
//clean tmp
glob.sync(`../../tmp/*.txt`).forEach((f) => {
glob.sync(`../adminapi/tmp/*.txt`).forEach((f) => {
fs.remove(f);
});
fs.outputFile(
`../../tmp/tokens/menagedone${currentday}`,
`../adminapi/tmp/tokens/menagedone${currentday}`,
"done by middleware/isAUthenticated"
);
}
@ -86,7 +86,7 @@ const isAuthenticated = async (req, res, next) => {
return res.status(resnotauth.status).json(resnotauth);
}
let tmpfs = `../../tmp/tokens/${req.session.header.xalias}_${req.session.header.xtribe}_${req.session.header.xdays}`;
let tmpfs = `../adminapi/tmp/tokens/${req.session.header.xalias}_${req.session.header.xtribe}_${req.session.header.xdays}`;
//max filename in ext4: 255 characters
tmpfs += `_${req.session.header.xhash.substring(
150,
@ -97,7 +97,7 @@ const isAuthenticated = async (req, res, next) => {
const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
const failstamp = `../../tmp/tokens/${alias}.json`;
const failstamp = `../adminapi/tmp/tokens/${alias}.json`;
if (action == "clean") {
//to reinit bruteforce checker
if (log) console.log(currentmod, "try to clean penalty file ", failstamp);
@ -119,7 +119,7 @@ const isAuthenticated = async (req, res, next) => {
if (!fs.existsSync(tmpfs)) {
// need to check detached sign
let publickey = "";
const aliasinfo = `../objects/pagans/itm/${req.session.header.xalias}.json`;
const aliasinfo = `../adminapi/objects/pagans/itm/${req.session.header.xalias}.json`;
if (fs.existsSync(aliasinfo)) {
publickey = fs.readJsonSync(aliasinfo).publickey;
} else if (req.body.publickey) {
@ -183,7 +183,7 @@ const isAuthenticated = async (req, res, next) => {
return res.status(resnotauth.status).send(resnotauth);
}
// authenticated then get person profils (person = pagan for a xtrib)
const person = `../../${req.session.header.xtribe}/objects/persons/itm/${req.session.header.xalias}.json`;
const person = `../${req.session.header.xtribe}/objects/persons/itm/${req.session.header.xalias}.json`;
if (log) console.log(currentmod,"Profils tribe/app management");
if (log) console.log(currentmod,"person", person);
if (fs.existsSync(person)) {

View File

@ -19,7 +19,7 @@ const log = conf.api.activelog.includes(currentmod);
const Notifications = {};
Notifications.get = (alias, tribeId) => {
const notiffile = `../../${req.params.tribeId}/notifications/${req.params.alias}.json`;
const notiffile = `../${req.params.tribe}/notifications/${req.params.alias}.json`;
const msg = fs.existsSync(notiffile) ? fs.readJSONSync(notiffile) : {};
return {
status: 200,
@ -34,7 +34,7 @@ Notifications.get = (alias, tribeId) => {
Notifications.statmaillist = (tribe) => {
const statinfo = {};
let csv = "email/phone;name;srckey\n";
const src = `../../${tribe}/objects/maillinglists/*.json`;
const src = `../${tribe}/objects/maillinglists/*.json`;
console.log(path.resolve(src));
glob.sync(src).forEach((f) => {
const name = path.basename(f, ".json");
@ -49,7 +49,7 @@ Notifications.statmaillist = (tribe) => {
});
});
// fichier csv stocker en local en attendant d'avoir un back pour stocker la reponse dans data.csv
fs.outputFileSync(`../../${tribe}/mailinglst.csv`, csv, "utf-8");
fs.outputFileSync(`../${tribe}/mailinglst.csv`, csv, "utf-8");
return {
status: 200,
ref: "Notifications",
@ -73,7 +73,7 @@ Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
data: { fielderr: typekey, format: typekey },
};
const destin = `../../${tribe}/objects/maillinglists/${typekey}_${mlist}.json`;
const destin = `../${tribe}/objects/maillinglists/${typekey}_${mlist}.json`;
if (!fs.existsSync(destin)) {
console.log(
`######## Attention tentative d'ecriture non autorisé,le fichier n'existe pas ${destin} créer le à la main vide {}`
@ -153,9 +153,9 @@ Notifications.sendsms = async (data, tribeId) => {
};
}
let confsms = conf.sms;
if (fs.existsSync(`../../adminapi/objects/tribes/itm/${req.session.header.xtribe}.json`)) {
if (fs.existsSync(`../adminapi/objects/tribes/itm/${req.session.header.xtribe}.json`)) {
const conftrib = fs.readJSONSync(
`../../adminapi/objects/tribes/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 = `../../adminapi/objects/tribes/itm/${tribe}.json`;
const conftribfile = `../adminapi/objects/tribes/itm/${tribe}.json`;
if (fs.existsSync(conftribfile)) {
const conftrib = fs.readJSONSync(conftribfile);
if (!conftrib.emailcontact){

View File

@ -32,7 +32,7 @@ const Pagans = {};
Pagans.logout = (alias, tribe, xdays, xhash) => {
//console.log(alias, tribe, xdays, xhash);
// inline with middleware isAuthenticated.js
let tmpfs = `../../tmp/tokens/${alias}_${tribe}_${xdays}`;
let tmpfs = `../adminapi/tmp/tokens/${alias}_${tribe}_${xdays}`;
//max filename in ext4: 255 characters
tmpfs += `_${xhash.substring(150, 150 + tmpfs.length - 249)}.json`;
fs.remove(tmpfs);
@ -69,7 +69,7 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => {
let emaillist = [];
if (emailalias == "email") {
search = search.toLowerCase();
const idxreco = `../../${tribe}/objects/persons/idx/emailrecovery_alias.json`;
const idxreco = `../${tribe}/objects/persons/idx/emailrecovery_alias.json`;
if (fs.existsSync(idxreco)) {
const emailreco = fs.readJSONSync(idxreco);
const listalias = emailreco[search] ? emailreco[search] : [];
@ -78,7 +78,7 @@ Pagans.keyrecovery = (emailalias, tribe, search, lg) => {
});
}
} else {
const personpath = `../../${tribe}/objects/persons/itm/${search}.json`;
const personpath = `../${tribe}/objects/persons/itm/${search}.json`;
if (fs.existsSync(personpath)) {
const person = fs.readJSONSync(personpath);
@ -170,7 +170,7 @@ Pagans.sendmailkey = (data) => {
};
if (!data.publickey || !data.email || !data.privatekey) {
const personfile = `../../${data.tribe}/objects/persons/itm/${data.alias}.json`;
const personfile = `../${data.tribe}/objects/persons/itm/${data.alias}.json`;
if (!fs.existsSync(personfile)) {
return {
status: 404,
@ -198,7 +198,7 @@ Pagans.sendmailkey = (data) => {
person.publickey = data.publickey;
}
person.avecpassphrase = person.passphrase != "";
let tplfile = `../../${data.tribe}/template/createidentity_${data.lg}.js`;
let tplfile = `../${data.tribe}/template/createidentity_${data.lg}.js`;
if (!fs.existsSync(tplfile)) {
tplfile = `../template/createidentity_${data.lg}.js`;
if (!fs.existsSync(tplfile)) {

View File

@ -10,7 +10,7 @@ const Wwws = {};
Wwws.initlocalwco=(tribwco,profils,lg)=>{
const wco={}
Object.keys(tribwco).forEach(t=>{
if (!fs.existsSync(`../../../${tribwco}`)){}
if (!fs.existsSync(`../${tribwco}`)){}
})
}
@ -18,7 +18,7 @@ Wwws.initlocalwco=(tribwco,profils,lg)=>{
Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
const fileparam = `../${tribe}/objects/wwws/itm/${appname}.json`;
console.log(path.resolve(fileparam));
//console.log(path.resolve(fileparam));
if (!fs.existsSync(fileparam)) {
return { status: 404, ref: "Wwws", msg: "appdoesnotexist", data: {} };
}
@ -47,7 +47,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
};
}
//check version
const initname = `../tmp/initlocaldata/${tribe}_${appname}_${pagename}_${lg}_${locals.pages[pagename].version}.json`;
const initname = `../${tribe}/tmp/initlocaldata/${tribe}_${appname}_${pagename}_${lg}_${locals.pages[pagename].version}.json`;
if (fs.existsSync(initname) && 1 != 1) {
const init = fs.readJsonSync(initname);
if (init.app.version == locals.app.version) {
@ -82,9 +82,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
const loc = locals.pages[pagename];
if (loc.itms){
Object.keys(loc.itms).forEach((r) => {
const src = `${loc.itms[r]}.json`;
console.log(path.resolve(src))
console.log(path.resolve(`${loc.itms[r]}.json`))
const src = `../${loc.itms[r]}.json`;
if (fs.existsSync(src)) {
localstorage.itms[r] = fs.readJSONSync(src);
} else {
@ -94,7 +92,7 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
}
if (loc.ref) {
Object.keys(loc.ref).forEach((r) => {
const src = `${loc.ref[r]}_${lg}.json`;
const src = `../${loc.ref[r]}_${lg}.json`;
if (fs.existsSync(src)) {
localstorage.ref[r] = fs.readJSONSync(src);
} else {
@ -106,7 +104,10 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
}
if (loc.options) {
Object.keys(loc.options).forEach((r) => {
const src = `${loc.options[r]}_${lg}.json`;
const src = `../${loc.options[r]}_${lg}.json`;
//console.log(path.resolve(src))
if (fs.existsSync(src)) {
localstorage.options[r] = fs.readJSONSync(src);
} else {
@ -127,8 +128,8 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
}
if (loc.tpl) {
Object.keys(loc.tpl).forEach((r) => {
let src = `${loc.tpl[r]}`;
console.log(path.resolve(src))
let src = `../${loc.tpl[r]}`;
//console.log(path.resolve(src))
if (!fs.existsSync(src)) {
src += `_${lg}.mustache`;
}
@ -143,8 +144,8 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
}
if (loc.tpldata) {
Object.keys(loc.tpldata).forEach((r) => {
let src = `${loc.tpldata[r]}`;
console.log(path.resolve(src))
let src = `../${loc.tpldata[r]}`;
//console.log(path.resolve(src))
if (!fs.existsSync(src)) {
src += `_${lg}.json`;
}
@ -160,11 +161,11 @@ Wwws.initlocaldata = (tribe, appname, pagename, version, profils, lg) => {
if (loc.schema) {
loc.schema.forEach((objpath) => {
const name = path.basename(objpath);
const schema = Odmdb.Schema(`../../${objpath}`, false, lg);
const schema = Odmdb.Schema(`../${objpath}`, false, lg);
if (schema.status == 200) {
localstorage.schema[name] = schema.data.schema;
} else {
console.log(schema);
//console.log(schema);
let msg=`Check your ${fileparam} for schema in ${pagename}, for ${schema.status} ${schema.ref} ${schema.msg} :`
if (schema.status==406){
if (schema.msg) msg+=schema.msg

View File

@ -76,7 +76,7 @@ router.post(
async (req, res) => {
const data = req.body.data;
data.emailsto = req.body.emails;
const pathtpl = `../../${req.params.tribe}/template/${req.params.template}_${req.session.header.xlang}.js`;
const pathtpl = `../${req.params.tribe}/template/${req.params.template}_${req.session.header.xlang}.js`;
const sendemail = await Notifications.manageemail(
data,
pathtpl,

View File

@ -57,7 +57,7 @@ router.get(
checkHeaders,
isAuthenticated,
(req, res) => {
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
console.log(objectPathname);
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang);
res.status(retschema.status).json(retschema);
@ -82,7 +82,7 @@ router.get(
checkHeaders,
isAuthenticated,
(req, res) => {
const objectPathname = `../../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json`;
const objectPathname = `../${req.params.tribe}/objects/options/${req.params.optionname}_${req.header.xlang}.json`;
if (fs.existsSync(objectPathname)) {
res.status(200).json({
status: 200,
@ -128,7 +128,7 @@ router.get(
isAuthenticated,
(req, res) => {
console.log("passe");
const indexpath = `../../${req.params.tribe}/objects/${req.params.objectname}/idx/${req.params.indexname}`;
const indexpath = `../${req.params.tribe}/objects/${req.params.objectname}/idx/${req.params.indexname}`;
console.log(indexpath);
if (fs.existsSync(indexpath)) {
res.status(200).json({
@ -176,7 +176,7 @@ router.get(
console.log("reindex");
// check validity and accessright
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
if (!fs.existsSync(objectPathname)) {
res.status(404).json({
status: 404,
@ -249,7 +249,7 @@ router.post(
(req, res) => {
// Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
const postitm = Odmdb.cud(objectPathname, "C", req.body, {
xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
@ -292,7 +292,7 @@ router.put(
(req, res) => {
// Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
const postitm = Odmdb.cud(objectPathname, "U", req.body, {
xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
@ -334,7 +334,7 @@ router.delete(
(req, res) => {
// Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
const itmtoremove={}
itmtoremove[req.params.apxid]=req.params.primaryid;
const delitm = Odmdb.cud(objectPathname, "D", itmtoremove, {
@ -376,7 +376,7 @@ router.post(
checkHeaders,
isAuthenticated,
(req, res) => {
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const objectPathname = `../${req.params.tribe}/objects/${req.params.objectname}`;
const ressearch = Odmdb.search(objectPathname, req.body, {
xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
@ -410,11 +410,11 @@ router.get(
checkHeaders,
isAuthenticated,
(req, res) => {
const objectpath = `../../${req.params.tribe}/objects/${req.params.objectname}/itm/${req.params.primaryindex}.json`;
const objectpath = `../${req.params.tribe}/objects/${req.params.objectname}/itm/${req.params.primaryindex}.json`;
if (fs.existsSync(objectpath)) {
const readobj = Odmdb.r(
`../../${req.params.tribe}/objects/${req.params.objectname}`,
`../${req.params.tribe}/objects/${req.params.objectname}`,
req.params.primaryindex,
{
xprofils: req.session.header.xprofils,

View File

@ -143,8 +143,8 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
return;
}
const objpagan = { alias: req.body.alias, publickey: req.body.publickey };
console.log(path.resolve(`../objects/pagans`));
const newpagan = Odmdb.cud(`../objects/pagans`, "C", objpagan, role);
console.log(path.resolve(`../adminapi/objects/pagans`));
const newpagan = Odmdb.cud(`../adminapi/objects/pagans`, "C", objpagan, role);
const createprocess = {
status: 200,
ref: "Pagans",
@ -183,7 +183,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
},
};
const personup = Odmdb.cud(
`../../${req.body.trustedtribe}/objects/persons`,
`../${req.body.trustedtribe}/objects/persons`,
"C",
persondata,
{ xprofils: ["anonymous", "pagans"], xalias: req.body.alias }
@ -219,7 +219,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
* Delete an alias and his publickey, this mean that publickey disapear as well as alias. We set dt_delete
* */
router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
const personpath = `../objects/pagans`;
const personpath = `../adminapi/objects/pagans`;
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
@ -263,7 +263,7 @@ router.delete(
checkHeaders,
isAuthenticated,
(req, res) => {
const personpath = `../../${req.params.tribe}/objects/persons`;
const personpath = `../${req.params.tribe}/objects/persons`;
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
@ -308,10 +308,10 @@ router.delete(
* */
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
console.log(
path.resolve(`../../${req.session.header.xtribe}/objects/persons`)
path.resolve(`../${req.session.header.xtribe}/objects/persons`)
);
const getperson = Odmdb.r(
`../../${req.session.header.xtribe}/objects/persons`,
`../${req.session.header.xtribe}/objects/persons`,
req.params.alias,
{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias }
);
@ -333,7 +333,7 @@ router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
*/
router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
//console.log(req.body);
const pathobj = `../../${req.params.tribe}/objects/persons`;
const pathobj = `../${req.params.tribe}/objects/persons`;
const action = fs.existsSync(`${pathobj}/itm/${req.body.alias}.json`)
? "U"
: "C";
@ -362,7 +362,7 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
(e) => e !== req.body.removeprofils
);
Odmdb.cud(
`../../${req.params.tribe}/objects/${req.body.removeprofils}`,
`../${req.params.tribe}/objects/${req.body.removeprofils}`,
"D",
{ alias: req.body.alias },
{

View File

@ -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=`../../adminapi/objects/tribes/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{

View File

@ -137,7 +137,7 @@ router.get(
*/
router.get("/buildpage/:tribe/:appname/:pagename", checkHeaders, (req, res) => {
console.log("pass get version localstorage");
const localdbf = `../../${req.params.tribe}/objects/wwws/itm/${req.params.appname}`;
const localdbf = `../${req.params.tribe}/objects/wwws/itm/${req.params.appname}`;
if (!existsSync(localdbf)) {
return res
.status(404)