1
0
forked from apxtri/apxtri

modif archi apxtri

This commit is contained in:
philc 2024-03-15 08:49:23 +01:00
parent 17a1978dd4
commit b025800e26
36 changed files with 270 additions and 6433 deletions

View File

@ -15,7 +15,7 @@ To have a quick understanding and convention before doing deeply in source code
To share configuration :
process.env.dirtown is folder where town folder name /townId-nationId is accessible
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
app.locals.tribeids is defined later in apixtrib.js and allow express app to always have in memory a dynamic of tribeId available in req.app.locals.tribeids
*/
/**
@ -54,7 +54,7 @@ argv.slice(2).forEach((arg) => {
param[kv[0]] = kv[1];
}
});
if (!fs.existsSync("../conf/townconf.json")) {
if (!fs.existsSync("../../../../../conf/townconf.json")) {
// This is a first install
const nam = path.resolve("..").split("/").slice(-1)[0].split("-");
const town = nam[0];
@ -112,7 +112,9 @@ if (
}
}
*/
const conf = require(path.resolve(`../conf/townconf.json`));
const conf = require(path.resolve(`../../../conf/townconf.json`));
let doms = conf.dns; // only dns of town during the init process
const currentmod = "apxtri";
const log = conf.api.activelog.includes(currentmod);
@ -128,39 +130,40 @@ updateobjectsfromfreshesttown(conf.towns, {
// Run main express process for a /towId-nationId/tribes
let tribelist = {};
if (fs.existsSync(`../nationchains/tribes/idx/tribeId_all.json`)) {
tribelist = fs.readJsonSync(`../nationchains/tribes/idx/tribeId_all.json`);
if (fs.existsSync(`../../idx/tribeId_all.json`)) {
tribelist = fs.readJsonSync(`../../idx/tribeId_all.json`);
}
let doms = conf.dns; // only dns of town during the init process
let tribeIds = [];
let routes = glob.sync(`./routes/*.js`).map((f) => {
return { url: `/${path.basename(f, ".js")}`, route: f };
});
glob.sync(`../nationchains/tribes/*/api/routes/*.js`).forEach((f) => {
const ids = f.indexOf(`../nationchains/tribes/`);
const trib = f.slice(
ids + `../nationchains/tribes/`.length,
f.lastIndexOf("/api/routes")
);
routes.push({ url: `/${trib}/${path.basename(f, ".js")}`, route: f });
});
let tribeIds = Object.keys(tribelist);
// context is store in tribes/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)
Object.keys(tribelist).forEach((t) => {
let routes=[]
tribeIds.forEach((t) => {
tribelist[t].dns.forEach((d) => {
const dm = d.split(".").slice(-2).join(".");
if (!doms.includes(dm)) doms.push(dm);
});
tribeIds.push(t);
const context={};
const pathtr=path.resolve(`../../${t}`);
context.routes=[]
tribroutes=glob.sync(`${pathtr}/ap*/routes/*.js`).map(f=>{
const rt=`/${t}/${path.basename(f, ".js")}`
context.routes.push(rt)
return { url: rt, route: f };
});
context.models=glob.sync(`${pathtr}/ap*/models/*.js`).map(f=>{
const modname=`${path.basename(f, ".js")}`
return {
model: modname,
tplstrings:glob.sync(`${pathtr}/objects/tplstrings/${modname}_*.json`).map(l=>path.basename(l,'.json').split("_")[1] )
}
})
const conft=`../../itm/${t}.json`
const ctx=fs.readJsonSync(conft)
ctx.context=context
fs.outputJSONSync(conft,ctx,{spaces:2});
routes=routes.concat(tribroutes);
});
if (log)
console.log(
currentmod,
" Allowed DOMs to access to this apxtri server:",
JSON.stringify(doms)
);
const app = express();
// load express parameter from conf
Object.keys(conf.api.appset).forEach((p) => {
@ -173,8 +176,15 @@ app.use(express.json());
app.use(bodyParser.json(conf.api.bodyparse.json));
app.disable("x-powered-by"); // for security
app.locals.tribeids = tribeIds;
if (log) console.log(currentmod, " app.locals.tribeids", app.locals.tribeids);
// Cors management
if (log){
console.log(
currentmod,
" Allowed DOMs to access to this apxtri server:",
JSON.stringify(doms)
);
console.log(currentmod, " app.locals.tribeids", app.locals.tribeids);
}
// Cors management
let originlst = "test";
doms.forEach((d) => {
originlst += `|${d.replace(/\./g, "\\.")}`;

View File

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

View File

@ -10,35 +10,39 @@ For api tribe's doc  accessible in [https://smatchit.io/cdn/apidoc](https://sma
`yarn apidoctribename`
Objects manage in apxtri: pagans, notifications, nations, towns, tribes, wwws 
A special tribe call adminapi is replicated in any towns (node), it works the same than all the other tribe except that all their data are synchronize with a blockchain 
All others objects are manage in town/tribe 
Objects manage by adminapi are: pagans (numerique id =alias/public key / private key), notifications (cypher message betxeen alias) , nations (rules apply to all towns belonging to a nations), towns ( a server that host IT ressources disk space, ram, bandwith and rules aplly to all tribe belonging to a town), tribes (( a sharing space to store data as well as api with rules to any person that use it), wwws (web space, dns)
All others object are managed by spécifics tribe. 
```plaintext
/townName_nationName/
/apxtri/ # core process
/nationchains/conf.json # town settings contain all glabl parameter
/conf/nginx/tribename_appname.conf # nginx conf
/conf/apidoc # apidoc conf
/conf/townconf.json # town settings contain all glabl parameter
/tribes/idx/triebid_all.json # A global file {tribename:{conf}
/itm/tribename.json # Config file of a tribe
/adminapi # Tribes synchronize with all town
/apxtri # git yarn/npm project package.json entry point apxtri.js
/routes/
/models/
/middlewares/
/logs/nginx # nginx log related to /conf/nginx/apxtri_adminapi.conf
/api
/objects/objectname/idx/ # list of index to search objectname items
/itms/ # 1 json per items name apxid.json where apxid is a unique key
/schema/conf.json # list of schema and version
/objectname.json # schema title and escription are in english
/lg/objectname_lg.json # title and description in lg
/www/appname # web space
/cdn # common file with cache system
/tribename/ # same than adminapi but wit /api instead of apxtri
```
url: **/api/routeName** For core api apxtri in /apxtri :
API Endpoint url: **/api/{tribename}/{routename}/xxx**
```plaintext
/apxtri/middlewares/
/apxtri/routes/
/apxtri/models/
/apxtri/models/lg/ lauage accessible by https://wall-ants.ndda.fr/nationchains/models/Checkjson_fr.json
/apxtri/models/unitest/
```
url: **/api/smatchit/routeName** for tribe smatchit example api in /town\_nation/tribes/smatchit(tribeid) 
```plaintext
/nationchains/tribes/smatchit/api/routes/
/nationchains/tribes/smatchit/api/models/
/nationchains/tribes/smatchit/api/models/lg/ language customization accessible https://smatchit.io/smatchit/models/model_lg.json
```
**static files** are served by nginx, each tribe nginx conf are store and can be customize in /nationchains/tribes/{tribe}/www/nginx\_{xtribe}\_{xapp}.conf
Domaine name can be a adminapi donaim name aswell any tribe's domain  name. Check nginx conf in /conf/nginx 
## Object management (Odmdb)
@ -100,7 +104,7 @@ This contain a json {msg:"mustache template string to render with data"}  
## Accessrights:
An alias is just an identity, to access a tribe, a person must exist with an authenticated alias into /nationchains/tribes/{tribename}/persons/itm/{alias}.json
An alias is just an identity, to access a tribe, a person must exist with an authenticated alias into /tribes/{tribename}/persons/itm/{alias}.json/tribes/tribename/api/routes/
A person has a property profils with a list of profilename, common profiles are : anonymous (no identity) / pagan (an identity)  / person (an identity with access right into a tribe) / druid (the administrator of a tribe) / major (administrator of a town/server)
@ -111,17 +115,17 @@ Each object has an apxaccessrights that is a list of profil and CRUD access per
Accessible with https://dns/api/tribename/routes
```plaintext
/nationchains/tribes/tribename/api/routes
/nationchains/tribes/tribename/api/middlewares
/nationchains/tribes/tribename/api/models
/nationchains/tribes/tribename/schema
/nationchains/tribes/tribename/schema/lg
/tribes/tribename/api/routes
/tribes/tribename/api/middlewares
/tribes/tribename/api/models
/tribes/tribename/schema
/tribes/tribename/schema/lg
```
```plaintext
// Example of a route
const conf = require(`../../../../../conf/townconf.json`);
const express = require(`../../../../../apxtri/node_modules/express`);
const fs = require(`../../../../../apxtri/node_modules/fs-extra`);
const Nofications = require(`../../../../../apxtri/models/Notifications.js`);
const conf = require(`../../../../conf/townconf.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`);
```

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("openpgp");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const currentmod='isAuthenticated';
const log = conf.api.activelog.includes(currentmod)
/**
@ -40,16 +40,16 @@ const isAuthenticated = async (req, res, next) => {
const currentday = dayjs().date();
fs.ensureDirSync(`../tmp/tokens`);
let menagedone = fs.existsSync(
`../tmp/tokens/menagedone${currentday}`
`../../../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(`../../../tmp/tokens/menagedone*`).forEach((f) => {
fs.removeSync(f);
});
glob.sync(`../tmp/tokens/*.json`).forEach((f) => {
glob.sync(`../../../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(`../../../tmp/*.txt`).forEach((f) => {
fs.remove(f);
});
fs.outputFile(
`../tmp/tokens/menagedone${currentday}`,
`../../../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 = `../../../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 = `../../../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 = `../nationchains/pagans/itm/${req.session.header.xalias}.json`;
const aliasinfo = `../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 = `../nationchains/tribes/${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

@ -62,7 +62,7 @@ Checkjson.schema.properties.enum = (str, enumvalues) => {
//enumvalues is a reference of objectname.key
const { tribeId, obj, keyid } = enumvalues.split(".");
return fs.existsSync(
`../../nationchains/tribes/${tribeId}/schema/${obj}/itm/${keyid}.json`
`../../../${tribeId}/schema/${obj}/itm/${keyid}.json`
);
} else {
return true;

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Odmdb = require("./Odmdb.js");
// lowercase 1st letter is normal
const towns = require("./Towns.js");
@ -35,20 +35,20 @@ Nations.updateobjectsfromfreshesttown = (dnstownlist, objectidx) => {
* if an item exist localy and does not from the town requested
* @Param {array} dnstownlist list of dns to get latest data
* @Param {object} objectidx objectnme:idxfile {agans:"alias_all.json",...}
* @return create/update nationchains/pagans town nation
* @return create/update tribes/adminapi/opjects/pagans town nation
*/
const localversion = {};
const objlist = Object.keys(objectidx);
objlist.forEach((o) => {
let objconf = {
name: o,
schema: `../nationchains/tribes/adminapi/schema/${o}.jsons`,
schema: `../../schema/${o}.jsons`,
lastupdate: -1,
};
if (fs.existsSync(`../nationchains/${o}/conf.json`)) {
objconf = fs.readJsonSync(`../nationchains/${o}/conf.json`);
if (fs.existsSync(`../../${o}/conf.json`)) {
objconf = fs.readJsonSync(`../../${o}/conf.json`);
} else {
fs.outputJsonSync(`../nationchains/${o}/conf.json`, objconf);
fs.outputJsonSync(`../../${o}/conf.json`, objconf);
}
localversion[o] = [conf.dns[0], objconf.lastupdate];
});
@ -231,7 +231,7 @@ Nations.create = (conf) => {
res.info = `your nationId ${conf.nationId} does not exist you have to choose an existing one`;
return res;
}
const towns = fs.readJsonSync("./nationchains/towns/idx/townId_all.json");
const towns = fs.readJsonSync("./tribes/adminapi/opjects/towns/idx/townId_all.json");
if (towns[conf.nationId].includes(conf.townId)) {
res.status = 409;
res.info = `This conf.townId already exist you have to find a unique town name`;

View File

@ -6,7 +6,7 @@ const dayjs = require("dayjs");
const Checkjson = require(`./Checkjson.js`);
//const smtp = require("smtp-client");
const nodemailer = require("nodemailer");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const currentmod = "Notifications";
const log = conf.api.activelog.includes(currentmod);
/**
@ -18,7 +18,7 @@ const log = conf.api.activelog.includes(currentmod);
const Notifications = {};
Notifications.get = (alias, tribeId) => {
const notiffile = `../nationchains/tribes/${req.params.tribeId}/notifications/${req.params.alias}.json`;
const notiffile = `../../../${req.params.tribeId}/notifications/${req.params.alias}.json`;
const msg = fs.existsSync(notiffile) ? fs.readJSONSync(notiffile) : {};
return {
status: 200,
@ -43,7 +43,7 @@ Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
data: { fielderr: typekey, format: typekey }
};
const destin = `../nationchains/tribes/${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 {}`)
return {status:406,ref:"Notifications",msg:"destinnotallow",data:{destin}}
@ -69,7 +69,8 @@ Notifications.registertolist = (key, typekey, tribe, mlist, srckey, uuid) => {
/**
* Unsubscribe an eamil or phone from a mailinglist for a tribe
*/
Notifications.unsubscribefromlist = (body, header) => {
Notifications.unregisterfromlist = (key, typekey, tribe,mlist) => {
key = key.toLowerCase();
}
/**
@ -115,11 +116,11 @@ Notifications.sendsms = async (data, tribeId) => {
let confsms = conf.sms;
if (
fs.existsSync(
`../nationchains/tribes/itm/${req.session.header.xtribe}.json`
`../../../itm/${req.session.header.xtribe}.json`
)
) {
const conftrib = fs.readJSONSync(
`../nationchains/tribes/itm/${req.session.header.xtribe}.json`
`../../../itm/${req.session.header.xtribe}.json`
);
if (conftrib.sms) confsms = conftrib.sms;
}
@ -224,7 +225,7 @@ Notifications.sendmail = async (data, tribe) => {
};
}
let confsmtp = conf.smtp;
const conftribfile = `../nationchains/tribes/itm/${tribe}.json`;
const conftribfile = `../../../itm/${tribe}.json`;
if (fs.existsSync(conftribfile)) {
const conftrib = fs.readJSONSync(conftribfile);
confsmtp = conftrib.smtp;

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Checkjson = require(`./Checkjson.js`);
const { promiseHooks } = require("v8");
const currentmod = "Odmdb";
@ -48,7 +48,7 @@ const log = conf.api.activelog.includes(currentmod);
const Odmdb = {};
/**
*const Checkjson = require(`../../../../../apxtri/models/Checkjson`);
*const Checkjson = require(`../../../adminapi/apxtri/models/Checkjson`);
@api syncObject
* @param {string} url to an existing object conf (/objectname/conf.json)
* @param {timestamp} timestamp
@ -180,7 +180,7 @@ Odmdb.Schema = (objectPathname, validschema, lg="en") => {
if (schemaPath.substring(0, 4) == "http") {
// lance requete http pour recuperer le schema avec un await axios
} else {
schemaPath = `../nationchains/tribes/${schemaPath}`;
schemaPath = `../../${schemaPath}`;
if (log) console.log(currentmod,"resolve path schemaPath:",path.resolve(schemaPath))
if (!fs.existsSync(schemaPath)) {
return {};
@ -232,7 +232,7 @@ Odmdb.Schema = (objectPathname, validschema, lg="en") => {
res.data.schema.properties[p].type == "object" &&
res.data.schema.properties[p]["$ref"]
) {
const subschema = path.resolve(`${objectPathname}/${res.data.schema.properties[p]["$ref"]}`);
const subschema = path.resolve(`${objectPathname}/${res.data.schema.properties[p]["$ref"]}.json`);
if (Object.keys(res.data.schema).length == 0) {
res.status = 404;
res.msg = "missingref";
@ -243,13 +243,14 @@ Odmdb.Schema = (objectPathname, validschema, lg="en") => {
res.data.schema.properties[p] = subschema;
}
}
//`../../${req.session.header.xtribe}/objects/persons`
//looking for options:{"$ref":"../objects/options/xxx.json"}
//to add enum:[] = content of options available
//to add enum:[] = content of options available in
if (
res.data.schema.properties[p].options &&
res.data.schema.properties[p].options["$ref"]
) {
const optionsfile = path.resolve(`${objectPathname}/${res.data.schema.properties[p].options["$ref"]}`)
const optionsfile = path.resolve(`${objectPathname}/${res.data.schema.properties[p].options["$ref"]}_${lg}.json`)
if (log) console.log(currentmod,"Lien vers options:", optionsfile)
if (!fs.existsSync(optionsfile)){
res.status = 404;
@ -260,7 +261,7 @@ Odmdb.Schema = (objectPathname, validschema, lg="en") => {
if (!res.data.schema.apxref) {res.data.schema.apxref=[]}
if (!res.data.schema.apxref.includes(res.data.schema.properties[p].options["$ref"]))
res.data.schema.apxref.push(res.data.schema.properties[p].options["$ref"])
res.data.schema.properties[p].enum=fs.readJSONSync(optionsfile)
res.data.schema.properties[p].enum=fs.readJSONSync(optionsfile).lst_idx
}
}
});
@ -278,6 +279,7 @@ Odmdb.Schema = (objectPathname, validschema, lg="en") => {
if (!res.data.schema.apxuniquekey.includes(res.data.schema.apxid)) {
res.data.schema.apxuniquekey.push(res.data.schema.apxid);
}
//`../../${req.session.header.xtribe}/objects/persons`
res.data.schema.apxidx.forEach((idx) => {
if (
idx.objkey &&
@ -726,15 +728,15 @@ Odmdb.runidx = (objectPathname, schema) => {
* @param {object} schema if empty it use schema from Odmdb.Schema().data.schema
*
* example create alias 12 name fred:
* Odmdb.idxfromitm('.../tribes/ndda/persons',"C",{alias:'12',name:"fred"},{},[], {person schema})
* Odmdb.idxfromitm('../../../ndda/persons',"C",{alias:'12',name:"fred"},{},[], {person schema})
* example update alias 12 in name freddy:
* Odmdb.idxfromitm('.../tribes/ndda/persons',"U",{alias:'12',name:"freddy"},{alias:'12',name:"fred"},[], {person schema})
* Odmdb.idxfromitm('../../../ndda/persons',"U",{alias:'12',name:"freddy"},{alias:'12',name:"fred"},[], {person schema})
* example delete alias 12:
* Odmdb.idxfromitm('.../tribes/ndda/persons',"D",{},{alias:'12',name:"fred"},[], {person schema})
* Odmdb.idxfromitm('../../../ndda/persons',"D",{},{alias:'12',name:"fred"},[], {person schema})
* example to rebuild all index from scratch
* Odmdb.idxfromitm('.../tribes/ndda/persons',"I",{},{},[], {person schema})
* Odmdb.idxfromitm('../../../ndda/persons',"I",{},{},[], {person schema})
* example to rebuild only publickey_alias index from scratch
* Odmdb.idxfromitm('.../tribes/ndda/pagans',"I",{},{},[{ name:"publickey_alias",keyval:"publickey",objkey:["alias"]}], {pagans schema})
* Odmdb.idxfromitm('../../../ndda/pagans',"I",{},{},[{ name:"publickey_alias",keyval:"publickey",objkey:["alias"]}], {pagans schema})
*
*/
Odmdb.ASUPidxfromitm = (

View File

@ -8,7 +8,7 @@ const openpgp = require("openpgp");
const Notifications = require("./Notifications.js");
const Odmdb = require("./Odmdb.js");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const currentmod = "Pagans";
const log = conf.api.activelog.includes(currentmod);
/**
@ -48,13 +48,14 @@ Pagans.logout = (alias, tribe, xdays, xhash) => {
**/
Pagans.getalias = (alias) => {
//bypass Odmdb cause all is public save ressources
if (fs.existsSync(`../nationchains/pagans/itm/${alias}.json`)) {
console.log(path.resolve(`../objects/pagans/itm/${alias}.json`))
if (fs.existsSync(`../objects/pagans/itm/${alias}.json`)) {
return {
status: 200,
ref: "Pagans",
msg: "aliasexist",
data: fs.readJSONSync(
`../nationchains/pagans/itm/${alias}.json`
`../objects/pagans/itm/${alias}.json`
),
};
} else {
@ -102,7 +103,7 @@ Pagans.sendmailkey = (data) => {
const person = { alias:data.alias, privatekey:data.privatekey, tribe:data.tribe };
if (!data.publickey || !data.email || !data.privatekey) {
const personfile = `../../nationchains/tribes/${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,
@ -125,9 +126,9 @@ Pagans.sendmailkey = (data) => {
console.log("person:", person);
let tplfile=`../../nationchains/tribes/${data.tribe}/template/createidentity_${data.lg}.js`;
let tplfile=`../../../${data.tribe}/template/createidentity_${data.lg}.js`;
if (!fs.existsSync(tplfile)){
tplfile=`../../nationchains/tribes/adminapi/template/createidentity_${data.lg}.js`;
tplfile=`../../../adminapi/template/createidentity_${data.lg}.js`;
if (!fs.existsSync(tplfile)){
return {
status:406,

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Checkjson = require(`./Checkjson.js`);
const Odmdb = require("./Odmdb.js");
@ -144,7 +144,7 @@ Towns.changeowner = async (newowner, requestby) => {
/**
*
*/
if (!fs.existsSync(`./nationchains/pagans/itm/${newowner}.json`)) {
if (!fs.existsSync(`./tribes/adminapi/opjects/pagans/itm/${newowner}.json`)) {
return {
status: 404,
ref: "towns",

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Checkjson = require(`./Checkjson.js`);
const Trackings = {}

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Checkjson = require( `./Checkjson.js`);
/*
tribeid manager

View File

@ -3,7 +3,7 @@ const path = require("path");
const dnsSync = require("dns-sync");
const mustache = require("mustache");
const readlineSync = require("readline-sync");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Wwws = {};
/*Wwws.apxtriinstall = (paramconf) => {
@ -39,7 +39,7 @@ const Wwws = {};
);
if (!fs.existsSync(paramconf.nginx.logs)) fs.mkdirSync(paramconf.nginx.logs);
paramconf.nginx.firstinstall = true;
fs.outputJsonSync("../nationchains/tribes/conf.json", paramconf, {
fs.outputJsonSync("../tribes/conf.json", paramconf, {
space: 2,
});

View File

@ -3,7 +3,7 @@ Unit testing
*/
const assert = require("assert");
const Checkjson = require("../Checkjson.js");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const ut = { name: "Checkjson" };

View File

@ -6,7 +6,7 @@ const fs = require("fs-extra");
const path = require("path");
const Odmdb = require("../Odmdb.js");
const { generemdp } = require("../toolsbox.js");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const ut = { name: "Odmdb" };
/*
@ -26,7 +26,7 @@ ut.crud = (objectPathname, itm, profils) => {
const testvar={alias:"tutu", passphrase:"",privatekey:"", publickey:""}
const testitms=[
{objectPathname:`../nationchains/pagans`,
{objectPathname:`../../../../adminapi/opjects/pagans`,
itm:{alias:'toutou', publickey:}}
]

6240
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"name": "apxtri",
"version": "0.0.1",
"logo": {
"file": "../nationchains/tribes/adminapi/www/cdn/share/logo/logocarredark.png"
"file": "../www/cdn/share/logo/logocarredark.png"
},
"description": "apxtri Decentralized Autonomous Organization",
"main": "apxtri.js",
@ -15,10 +15,10 @@
"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",
"apidoc": "apidoc -c ../conf/apidoc/apidoc_$tribe.json -o ../nationchains/tribes/$tribe/www/cdn/apidoc/",
"publishtestwall": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/nationchains/tribes/$space phil@wall-ants://home/phil/apxtowns/testwall-ants/nationchains/tribes/$space/..",
"publishwall": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/nationchains/tribes/$space phil@wall-ants://home/phil/apxtowns/wall-ants/nationchains/tribes/$space/..",
"publishhouse": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/nationchains/tribes/$space phil@house-ants://home/phil/apxtowns/house-ants/nationchains/tribes/$space/.."
"apidoc": "apidoc -c ../../../conf/apidoc/apidoc_$tribe.json -o ../../$tribe/www/cdn/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/..",
"publishhouse": "scp -r /media/phil/usbfarm/apxtowns/dev-ants/tribes/$space phil@house-ants://home/phil/apxtowns/house-ants/tribes/$space/.."
},
"commentscript": "cf wiki apxtri doc for details: yarn startpm2 -n teswallants, yarn pm2 stop testwallants, yarn pm2 delete testwallants, yarn pm2 logs --lines 200 testwall, yarn pm2 monit -n testwallants, yarn pm2 save tribe=tribeid yarn apidoc to build apidoc // space=adminapi/www/cdn/apidoc yarn publishtestwall ",
"maintainers": [

View File

@ -1,6 +1,6 @@
const express = require( 'express' );
const fs=require('fs-extra');
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
// Classes
const Nations = require( '../models/Nations.js' );
@ -17,7 +17,7 @@ Manage a new towns in a nation => update nation:[nationname:towns:[]} contracts/
/**
* @api {put} /nations/viewtown/:town - nationlist from a town major
* @api {put} adminapi/nations/viewtown/:town - nationlist from a town major
* @apigroup Nation
* @apiName nationlist
* @apiDescription get list of nation from a town to help this instance to update network topology

View File

@ -26,7 +26,7 @@ router.post("/backend", (req, res) => {
})
/**
* @api {get} /notifications/:alias/:tribeId
* @api {get} adminapi/notifications/:alias/:tribeId
* @apiName notiflist
* @apiDescription Get list of notifications for an alias and a tribe
* @apiGroup Notifications
@ -46,15 +46,15 @@ router.get("/:alias/:tribeId", (req, res) => {
/**
* @api {POST} /notifications/registeranonymous/:tribe/:mlist/:typekey/:data -Contact anonymous
* @api {POST} adminapi/notifications/registeranonymous/:tribe/:mlist/:typekey/:data -Register email||phone to mlist
* @apiName register
* @apiGroup Notifications
* @apiDescription Register an email into a mailinglist mlist
* @apiDescription Register an email or phone into a mailinglist mlist
* @apiBody {string} tribe an existing tribe
* @apiBody {string} mlist a mailing list name
* @apiBody {string} key email or phone
* @apiBody {string} key email or phone keyword
* @apiBod {string} srckey must exist in tribes/schema/lg/enumtrk_xx.json
* @apiParams {string} data the email or phone
* @apiParams {string} data the email or phone value
* @apiSuccess {object} update mailinglist/{mlist}.json successfull
* @apiSuccessExample {json} successfullmessage
* HTTP/1.1 200 OK
@ -77,8 +77,8 @@ router.post("/registeranonymous",checkHeaders,(req,res)=>{
res.status(result.status).json(result)
})
/**
* @api {GET} /notifications/unregister/:tribe/:mlist/:typekey/:data/:validation -Contact anonymous
* @apiName contactanonymous
* @api {GET} adminapi/notifications/unregister/:tribe/:mlist/:typekey/:data/:validation -Unregister email o r phone from a mlist or all mlist
* @apiName unregister
* @apiGroup Notifications
* @apiDescription Register an email into a mailinglist mlist
* @apiParams {string} tribe an existing tribe
@ -94,7 +94,7 @@ router.post("/registeranonymous",checkHeaders,(req,res)=>{
*
*/
router.get("/unregisteranonymous/:tribe/:mlist/:typekey/:srckey/:data/:validation", checkHeaders, (req, res) => {
router.get("/unregister/:tribe/:mlist/:typekey/:srckey/:data/:validation", checkHeaders, (req, res) => {
Notifications.registertolist = (typekey, tribe, mlist, srckey, uuid)
result= Notifications.registertolist(
req.params.typekey,
@ -106,7 +106,7 @@ router.get("/unregisteranonymous/:tribe/:mlist/:typekey/:srckey/:data/:validatio
})
/**
* @api {POST} /notifications/contactanonymous/:tribe -Contact anonymous
* @api {POST} adminapi/notifications/contactanonymous/:tribe -Contact anonymous
* @apiName contactanonymous
* @apiGroup Notifications
* @apiDescription Register a contact in tribe and send a mail to admin of tribe

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Odmdb = require("../models/Odmdb.js");
// Middlewares
const checkHeaders = require("../middlewares/checkHeaders.js");
@ -10,46 +10,71 @@ const isAuthenticated = require("../middlewares/isAuthenticated.js");
const router = express.Router();
/**
* @api {get} /odmdb/objects - objects Get
* @api {get} adminapi/odmdb/schemas - objects Get
* @apiGroup Odmdb
* @apiName getIndex
* @apiDescription Get objects available for header.xtribe
* @apiDescription Get objects available result is store in data.apx.conf for schema conf of adminapi schema (pagans,towns,... ) and data.apx.objectnames as array of schema name. Schema related to tribe are store in data.tribe.conf and data.tribe.objectnames where tribe come from header.xtribe
*
* @apiSuccess {object} contain data.indexname
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"objectslist", "data":{indexname,content:{index file}}
*
*
* {"status":200, "ref":"Odmdb", "msg":"objectslist", "data":{apx:{conf,objectnames:[]},tribe:{conf,objectnames:[]}}}
*/
router.get("/objects", checkHeaders, isAuthenticated, (req, res) => {
router.get("/schemas", checkHeaders, isAuthenticated, (req, res) => {
const data = {
tribe: req.session.header.xtribe,
apx: { conf: {}, objectnames: [] },
tribe: { conf: {}, objectnames: [] },
};
glob.sync(`../nationchains/tribes/adminapi/schema/*.json`).forEach((f) => {
glob.sync(`../schema/*.json`).forEach((f) => {
const objectname = path.basename(f, ".json");
if (objectname == "conf") {
data.apx.conf = fs.readJSONSync(f);
} else {
data.apx.objectnames.push(objectnames);
data.apx.objectnames.push(objectname);
}
});
glob
.sync(`../nationchains/tribes/${req.session.header.xtribe}/schema/*.json`)
.sync(`../../${req.session.header.xtribe}/schema/*.json`)
.forEach((f) => {
const objectname = path.basename(f, ".json");
if (objectname == "conf") {
data.apx.conf = fs.readJSONSync(f);
data.tribe.conf = fs.readJSONSync(f);
} else {
data.apx.objectnames.push(objectnames);
data.tribe.objectnames.push(objectname);
}
});
res.status(200).json({ status: 200, ref: "Odmdb", msg: "objectslist", data });
});
/**
* @api {get} /odmdb/idx/:tribe/:objectname/:indexname - index Get
* @api {get} adminapi/odmdb/schema/:source/:objectname - Schema Get in the language header
* @apiGroup Odmdb
* @apiName getIndex
* @apiDescription Get schema in the requested language if login have accessright
*
* @apiParams {string} source (adminapi || tribe) looking for adminapi or in tribe (header.xtribe)
* @apiParams {string} objectname requested must exist in adminapi or tribe
* @apiSuccess {object} contain data.schema
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {"status":200, "ref":"Odmdb", "msg":"schema", "data":{schema,objectname,lg}
*/
router.get("/schema/:source/:objectname", checkHeaders, isAuthenticated, (req, res) => {
if (!['adminapi','tribe'].includes(req.params.source)){
res(406).json({status:406,ref:"Odmdb",msg:"mustbetribeoradminapi",data:{source:req.params.source}})
}else{
let objectPathname=`../../adminapi/objects/${req.params.objectname}`
if (req.params.source=="tribe"){
objectPathname=`../../${req.headers.xtribe}/objects/${req.params.objectname}`
}
console.log(objectPathname)
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang)
res.status(retschema.status).json(retschema);
}
});
/**
* @api {get} adminapi/odmdb/idx/:tribe/:objectname/:indexname - index Get
* @apiGroup Odmdb
* @apiName getIndex
* @apiDescription Get index file for an object
@ -104,7 +129,7 @@ router.get(
);
/**
* @api {get} /odmdb/rebuildidx/:objectname - index refresh all
* @api {get} adminapi/odmdb/rebuildidx/:objectname - index refresh all
* @apiGroup Odmdb
* @apiName refreshAllIndex
* @apiDescription Rebuild all index for an object, this can be usefull in case crash or any data conflict.
@ -174,7 +199,7 @@ router.get(
);
/**
* @api {post} /odmdb/itm/:objectname - item Create
* @api {post} adminapi/odmdb/itm/:objectname - item Create
* @apiGroup Odmdb
* @apiName postItm
* @apiPermission none
@ -233,12 +258,12 @@ router.get(
);
/**
* @api {get} /odmdb/itm/:objectname/:primaryindex - item Get
* @api {get} adminapi/odmdb/itm/:objectname/:primaryindex - item Get
* @apiGroup Odmdb
* @apiName getItemFromId
* @apiDescription Get itm for a primaryid of an object
*
* @apiParam {String} objectname name Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname
* @apiParam {String} objectname name Mandatory if in conf.nationObjects then file is into nationchains/ else in /tribes/xtribe/objectname
* @apiParam {String} primaryindex the unique id where item is store
*
* @apiError {json} objectNotfound the file item does not exist
@ -281,11 +306,11 @@ router.get(
}
);
/**
* @api {get} https://wall-ants.ndda.fr/Checkjson.js - schema Checkjson.js
* @api {get} https://wall-ants.ndda.fr/adminapi/Checkjson.js - schema Checkjson.js
* @apiGroup Odmdb
* @apiName checkjsonjs
* @apiDescription Public js lib to import in a browser by :<br>
* ```<script src="wall-ants.ndda.fr/nationchains/contracts/Checkjson.js"></script>```
* ```<script src="https://wall-ants.ndda.fr/adminapi/Checkjson.js"></script>```
* to import in a node.js:<br>
* ```const Checkjson = require(`Checkjson.js`);```
*
@ -299,12 +324,12 @@ router.get(
* - {status:417, multimsg:[{ref:"Checkjson",msg:"errorkey",data:{}}]}<br>
*
* To identify issues, get the language errorkey list with a get
* https://wall-ants.ndda.fr/nationchains/models/Checkjson_lg.json
* MUST BE UPDATE with conf access https://wall-ants.ndda.fr/adminapi/objects/tplstring/Checkjson_lg.json
*
*/
/**
* @api {get} https://wall-ants.ndda.fr/nationchains/schema/:objectname - schema Get public
* @api {get} https://wall-ants.ndda.fr/adminapi/schema/:objectname - schema Get public
* @apiGroup Odmdb
* @apiName getPublicSchema
* @apiDescription Get a Schema model from public apxtri (nations, pagans,persons,towns, tribes,wwws)
@ -312,7 +337,7 @@ router.get(
* @apiSuccessExample {json} Fichier direct
* HTTP/1.1 200 Success-response:
{
"$id": "https://smatchit.io/schema/pagan",
"$id": "https://wall-ants.ndda.fr/schema/pagan",
"$comment": "To create account bin apxtri",
"title": "Pagans identity",
"description": "A numeric id in the nationchains world",
@ -569,7 +594,7 @@ router.put(
);
/**
* @api {get} https://wall-ants.ndda.fr/nationchains/models/:modelname_lg.json - translation notif Get public
* @api {get} https://wall-ants.ndda.fr/adminapi/objects/tplstring/:modelname_lg.json - translation notif Get public
* @apiGroup Odmdb
* @apiName getPublicModelmessagekey
* @apiDescription Get a public json object for the ref: modelname in language lg, to get a template description with key msg

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const currentmod = "pagans";
const log = conf.api.activelog.includes(currentmod);
@ -21,7 +21,7 @@ const router = express.Router();
/**
* Alias exist then return public key or not
* @api {get} /pagans/alias/:alias - alias Get
* @api {get} adminapi/pagans/alias/:alias - alias Get
* @apiName isalias
* @apiGroup Pagans
* @apiDescription If alias exist return its publickey
@ -44,7 +44,7 @@ router.get("/alias/:alias", (req, res) => {
res.status(getalias.status).send(getalias);
});
/**
* @api {get} /pagans/logout - pagan Logout
* @api {get} adminapi/pagans/logout - pagan Logout
* @apiName Removetoken
* @apiGroup Pagans
* @apiDescription Remove server's token only the owner of the token (no one else can delete a token )
@ -66,7 +66,7 @@ router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
res.status(logout.status).json(logout);
});
/**
* @api {get} /pagans/isauth - pagan isAuthenticated?
* @api {get} adminapi/pagans/isauth - pagan isAuthenticated?
* @apiName isAuth
* @apiGroup Pagans
* @apiDescription Check if pagan's token is still valid
@ -94,7 +94,7 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
});
/**
* @api {post} /pagans - pagan Post
* @api {post} adminapi/pagans - pagan Post
* @apiName addpagan
* @apiGroup Pagans
* @apiDescription
@ -137,7 +137,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
return
}
const objpagan = { alias: req.body.alias, publickey: req.body.publickey };
const newpagan = Odmdb.cud(`../nationchains/pagans`, "C", objpagan, role);
const newpagan = Odmdb.cud(`../../objects/pagans`, "C", objpagan, role);
const createprocess={status:200, ref:"Pagans", msg:"successfulcreate",data:{alias:req.body.alias}};
if (newpagan.status == 200) {
if (req.body.email) {
@ -171,7 +171,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
passphrase: req.body.passphrase,
},
};
const personup = Odmdb.cud(`../nationchains/tribes/${req.body.trustedtribe}/objects/persons`, "C", persondata, {xprofils:["pagan"],xalias:req.body.alias});
const personup = Odmdb.cud(`../../${req.body.trustedtribe}/objects/persons`, "C", persondata, {xprofils:["pagan"],xalias:req.body.alias});
if (log) console.log(currentmod,'person create',personup)
if (personup.status==200){
createprocess.data.createperson=true;
@ -191,14 +191,14 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
}
});
/**
* @api {delete} /pagans/alias/:alias - pagan Delete
* @api {delete} adminapi/pagans/alias/:alias - pagan Delete
* @apiName deletepagan
* @apiGroup Pagans
* @apiDescription
* 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=`../nationchains/pagans`;
const personpath=`../objects/pagans`;
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
@ -209,12 +209,12 @@ router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
if (log) console.log(delperson)
res.status(delperson.status).json(delperson);
if (log) console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
if (log) console.log(`DELETE pagans adminapi/objects/pagans/${req.params.alias}.json`);
const result = Pagans.delete(req.params.alias, req.session.header);
res.status(result.status).send(result);
});
/**
* @api {delete} /pagans/person/:tribe/:alias - person Delete
* @api {delete} adminapi/pagans/person/:tribe/:alias - person Delete
* @apiName deleteperson
* @apiGroup Pagans
* @apiDescription
@ -225,7 +225,7 @@ router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
* @apiParam {string} alias to delete as person
* */
router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res) => {
const personpath=`../nationchains/tribes/${req.params.tribe}/objects/persons`;
const personpath=`../../${req.params.tribe}/objects/persons`;
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
@ -238,7 +238,7 @@ router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res)
});
/**
* @api {get} /pagans/person/:alias - person Get
* @api {get} adminapi/pagans/person/:alias - person Get
* @apiName getpersondata
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
* @apiGroup Pagans
@ -258,12 +258,13 @@ router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res)
* else need accessright to on person set at R
* */
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
const getperson=Odmdb.r( `../nationchains/tribes/${req.session.header.xtribe}/objects/persons`,req.params.alias,{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias })
console.log(path.resolve(`../../${req.session.header.xtribe}/objects/persons`))
const getperson=Odmdb.r( `../../${req.session.header.xtribe}/objects/persons`,req.params.alias,{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias })
res.status(getperson.status).send(getperson);
});
/**
* @api {put} /pagans/person/:tribe - person Put
* @api {put} adminapi/pagans/person/:tribe - person Put
* @apiName updateperson
* @apiGroup Pagans
* @apiDescription add or update a person = alias in tribe. xalias authenticated (in header) must have a profil with accessright into schema person to create a person.
@ -275,7 +276,7 @@ router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
*/
router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
//console.log(req.body);
const pathobj=`../nationchains/tribes/${req.params.tribe}/objects/persons`;
const pathobj=`../../${req.params.tribe}/objects/persons`;
const action = (fs.existsSync(`${pathobj}/itm/${req.body.alias}.json`))? "U":"C";
//set req.body to be in line with schema
if (!req.body.profils){
@ -287,7 +288,7 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
});
/**
* @api {get} /pagans/keyrecovery/:tribe/:email - recovery keys by email
* @api {get} adminapi/pagans/keyrecovery/:tribe/:email - recovery keys by email
* @apiName recoveryKey
* @apiGroup Pagans
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register)
@ -303,7 +304,7 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
*
*/
router.get("/keyrecovery/:tribe/:email", checkHeaders, (req, res) => {
const idxreco=`../../nationchains/tribes/${req.params.tribe}/objects/persons/idx/emailrecovery_alias.json`;
const idxreco=`../../${req.params.tribe}/objects/persons/idx/emailrecovery_alias.json`;
if (fs.existsSync(idxreco)){
const emailreco = fs.readJSONSync(idxreco);
if (emailreco[req.params.email]){
@ -321,7 +322,7 @@ router.get("/keyrecovery/:tribe/:email", checkHeaders, (req, res) => {
}
});
/**
* @api {get} /pagans/keyrecovery/:tribe/:alias - recovery keys by alias
* @api {get} adminapi/pagans/keyrecovery/:tribe/:alias - recovery keys by alias
* @apiName recoveryKey
* @apiGroup Pagans
* @apiDescription Send to email recovery if exist key files

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const Odmdb = require("../models/Odmdb.js");
// Middlewares
const checkHeaders = require("../middlewares/checkHeaders");

View File

@ -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/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
// Classes
const Tribes = require( '../models/Tribes.js' );
@ -11,8 +11,41 @@ const checkHeaders = require( '../middlewares/checkHeaders' );
const isAuthenticated = require( '../middlewares/isAuthenticated' );
const router = express.Router();
/**
* @api {get} /tribes/www/:tribeId - tribe list
* @api {get} adminapi/tribes/conf/:tribe - tribe list
* @apiName getconf
* @apiDescription Get list of route and model for a town server
* @apiGroup Tribes
*
* @apiSuccess (object) get tribes conf on this server
* @apiSuccessExample {json}
* HTTP/1.1 200 OK
* {status:200,ref:"Tribes",msg:"tribesconf",data:{routes:[],modele:[{model:,tplstrings:[lg,lg]}]}}
*/
router.get('/config/:tribe', checkHeaders,isAuthenticated,(req,res)=>{
/*console.log("passe la")
AJOUTER gestion accessright
req.session.header.accessrights.data[ req.params.tribe ] &&
req.session.header.accessrights.data[ req.params.tribe ].tribeid &&
req.session.header.accessrights.data[ req.params.tribe ].tribeid.includes( 'R' )
*/
if("authorize"=="authorize"){
const tribconf=`../../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{
res.status(200).json({satatus:200,ref:"Tribes",msg:"tribconf",data:{conf:fs.readJsonSync(tribconf)}})
}
}else{
res.status( 403 )
.json( { msg: [ 'forbidenAccess' ], ref: 'Tribes' } )
.end();
}
})
/**
* @api {get} adminapi/tribes/www/:tribeId - tribe list
* @apiName getlisttrib
* @apiDescription Get list of www object (space web)
* @apiGroup Tribes
@ -23,7 +56,7 @@ const router = express.Router();
* HTTP/1.1 200 OK
* {status:200,ref:"Tribes",msg:"listwww",data:{listwww}}
*/
router.get('www', checkHeaders,isAuthenticated,(req,res)=>{
router.get('/www', checkHeaders,isAuthenticated,(req,res)=>{
let listwww=[]
glob.sync(`${conf.dirtown}/tribes/${req.params.tribeId}/www/*`).forEach(d=>{
listwww.push(d.split("/").pop())
@ -127,7 +160,7 @@ router.get( '/plugins/:tribeid/:pluginname/:key/:filename', ( req, res ) => {
} );
router.get( '/dirls', checkHeaders, isAuthenticated, ( req, res ) => {
// url /Tribes/dirls?rep=referentials/dataManagement
// url adminapi/tribes/dirls?rep=referentials/dataManagement
// request information about a req.query.rep from header xworkon/
// return
// {file:[{}],dir:[{}]}
@ -145,7 +178,7 @@ router.get( '/dirls', checkHeaders, isAuthenticated, ( req, res ) => {
} )
router.delete( '/ls', checkHeaders, isAuthenticated, ( req, res ) => {
// check Accessright with D or O on each
// url /Tribes/ls
// url adminapi/tribes/ls
// req.body.files=[listfiles file to delete ]
const authfiles = Tribes.checkaccessfiles( req.body, 'D', req.session.header.accessrights, req.session.header.apixpaganid );
authfiles.ok.forEach( f => { fs.remove( `${config.tribes}/${f}` ); } )
@ -202,7 +235,7 @@ router.post( '/downloadls', checkHeaders, isAuthenticated, ( req, res ) => {
}
} );
router.post( '/upfilepond', checkHeaders, isAuthenticated, ( req, res ) => {
console.log( 'post /Tribes/uploadfilepond' );
console.log( 'post adminapi/tribes/uploadfilepond' );
// Store file and return a unique id to save button
// that provide folder where to store it
const formidable = require( 'formidable' );
@ -278,7 +311,7 @@ router.post( '/uploadfile', checkHeaders, isAuthenticated, ( req, res ) => {
router.post( '/uploadzip', checkHeaders, ( req, res ) => {
console.log( 'uploadzip a file ' )
/* no authentification to upload a zip filename into /tribes/${xworkon}/${clientconf.uploadzip[filename].dest}
/* no authentification to upload a zip filename into adminapi/tribes/${xworkon}/${clientconf.uploadzip[filename].dest}
unzip it using the password ${clientconf.uploadzip[filename].psw
if no error then run the callback ${clientconf.uploadzip[filename].callback
but a password to unzip
@ -352,7 +385,7 @@ router.post( '/uploadzip', checkHeaders, ( req, res ) => {
router.post( '/upload', checkHeaders, isAuthenticated, ( req, res ) => {
1 // ACHANGER VIA usage sendjson
// url /Tribes/upload?save=tmp&rep=referentials/dataManagement
// url adminapi/tribes/upload?save=tmp&rep=referentials/dataManagement
// if save=tmp then store in a tmp file
// if save=ok then mv the tmp file to the folder
// midlleware hasAccessrighton.js is not apply here only to access/update/create information inside an object

View File

@ -1,12 +1,12 @@
server {
server_name {{#dns}} {{.}} {{/dns}};
access_log {{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/log/nginx/{{tribeId}}_{{website}}.access.log main;
access_log {{foldertowns}}/{{townId}}-{{nationId}}/tribes/log/nginx/{{tribeId}}_{{website}}.access.log main;
set $trackme 0;
if ( $uri ~ ^/trk/ ){
set $trackme 1;
}
access_log {{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/log/nginx/{{tribeId}}_{{website}}.trk.log tracker if=$trackme ;
access_log {{foldertowns}}/{{townId}}-{{nationId}}/tribes/log/nginx/{{tribeId}}_{{website}}.trk.log tracker if=$trackme ;
location ~* /trk/ {
if ( $uri ~ ^/trk/redirect ){
return 301 $arg_url;
@ -28,23 +28,23 @@ location ~* /nationchains/models/ {
location ~* /nationchains/schema/ {
#outside of nationchains for git purpose
rewrite /nationchains/schema/(.*$) /$1 break;
root {{{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/adminapi/schema/;
root {{{foldertowns}}/{{townId}}-{{nationId}}/tribes/adminapi/schema/;
}
location ~* /{{tribeId}}/schema/{
rewrite /{{tribeId}}/schema/(.*$) /$1 break;
root {{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/{{tribeId}}/schema/;
root {{foldertowns}}/{{townId}}-{{nationId}}/tribes/{{tribeId}}/schema/;
}
location ~* /{{tribeId}}/models/{
rewrite /{{tribeId}}/models/(.*$) /$1 break;
root {{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/{{tribeId}}/api/models/lg/;
root {{foldertowns}}/{{townId}}-{{nationId}}/tribes/{{tribeId}}/api/models/lg/;
}
location /cdn/ {
expires 1y;
add_header Cache-Control "public";
rewrite /cdn/(.*$) /$1 break;
root {{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/{{tribeId}}/www//cdn/;
root {{foldertowns}}/{{townId}}-{{nationId}}/tribes/{{tribeId}}/www//cdn/;
}
location /api/ {
@ -66,9 +66,9 @@ option
location / {
{{#private}}
auth_basic "Mot de passe {{privatelogin}}";
auth_basic_user_file {{{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/{{tribeId}}/.htpasswd;
auth_basic_user_file {{{foldertowns}}/{{townId}}-{{nationId}}/tribes/{{tribeId}}/.htpasswd;
{{/private}}
root {{foldertowns}}/{{townId}}-{{nationId}}/nationchains/tribes/{{tribeId}}/www/{{{website}}};
root {{foldertowns}}/{{townId}}-{{nationId}}/tribes/{{tribeId}}/www/{{{website}}};
index index.html {{{pageindex}}};
}
error_page 404 /404.html;

View File

@ -1,6 +1,6 @@
const fs = require("fs-extra");
const dayjs = require("dayjs");
const conf = require(`../../conf/townconf.json`);
const conf = require(`../../../../conf/townconf.json`);
const l = {};
l.context="";
l.og = (...infos) => {
@ -19,7 +19,7 @@ l.og = (...infos) => {
};
l.ogprod = (tribe,info) => {
const logf = `../../nationchains/tribes/${tribe}/logs/apxtri/apxtri_${tribe}.log`;
const logf = `../../tribes/${tribe}/logs/apxtri/apxtri_${tribe}.log`;
const msg = `${days.js().toISOString()}###${l.context}###${tribe}###${info}`;
fs.appendFileSync(logf, msg);
console.log(msg)