modif archi apxtri

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

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)) {