device tracking

This commit is contained in:
2025-02-25 12:24:55 +01:00
parent 4521c757ab
commit 1473f07e3d
4 changed files with 184 additions and 61 deletions

View File

@@ -43,6 +43,9 @@ Wwws.getwco = (wconame, ctx) => {
//check in ctx.wcotribe if ctx.tribe_ctx.code exist in
console.log("@todo don't forget to manage accessright to wco in Wwws");
//check that all tpl, tpldata, ... are available for this pagename
if (wconame=="tracker" && !fs.pathExistsSync(`../${ctx.tribe}/objects/wwws/cdn/log`)){
fs.cpSync(`../adminapi/objects/wwws/cdn/log ../${ctx.tribe}/objects/wwws/cdn/`)
}
const webconf = `../${ctx.tribe}/objects/wwws/itm/${ctx.xapp}.json`;
const webpageinit = {
dns: [],
@@ -77,6 +80,7 @@ Wwws.getwco = (wconame, ctx) => {
ref: {},
schema: [],
tpldata: {},
wco:{}
};
const wcoinfo = fs.readJSONSync(wcoconf);
const webpage = fs.existsSync(webconf)

View File

@@ -10,7 +10,7 @@ const checkHeaders = require("../middlewares/checkHeaders.js");
const isAuthenticated = require("../middlewares/isAuthenticated.js");
const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod = "pagans";
const currentmod = "Pagans";
const log = conf.api.activelog.includes(currentmod);
const router = express.Router();

View File

@@ -3,6 +3,8 @@ const glob = require("glob");
const fs = require("fs-extra");
const path = require("path");
const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
const currentmod="Trackings"
const log = conf.api.activelog.includes(currentmod);
const Odmdb = require("../models/Odmdb.js");
// Middlewares
const checkHeaders = require("../middlewares/checkHeaders");
@@ -10,6 +12,68 @@ const isAuthenticated = require("../middlewares/isAuthenticated");
const router = express.Router();
/**
* @api {post} adminapi/trackings/newdevice - Post new device
* @apiName adddevice
* @apiGroup Trackings
* @apiDescription
* Create a device from a xuuid wco tracker.js with information about the device. It is suppose to be a new device but if xuuid already exist then it will be update with new information
* @apiBody {object} device see schema/adminapi/schema/device.json
*
* @apiError {json} objectNotfound the file does not exist
* @apiErrorExample {json}
* HTTP/1.1 406 Not Acceptable
{"status":406,"ref":"Trackings","multimsg":{},"data":{body}}
*
* @apiSuccessExample {json} Success-create:
* HTTP/1.1 200 OK
* {"status":200, "ref":"Trackings", "msg":"successfullcreate", "data":{}}
* @apiSuccessExample {json} Success-update:
* HTTP/1.1 200 OK
* {"status":200, "ref":"Trackings", "msg":"successfullupdate", "data":{}}
*/
router.post("/newdevice", checkHeaders, async (req, res) => {
if (log) console.log(currentmod, "post new device with", req.body);
const newdevice= {status: 200,
ref: "Trackings",
msg: "success",
data: {},
};
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
};
const devicepath=`../${req.session.header.xtribe}/objects/devices/itm/${req.session.header.xuuid}.json`;
const device=req.body;
device.xuuid=req.session.header.xuuid
if (req.session.header.xalias!="anonymous"){
device.alias=req.session.header.xalias
}
if (await fs.pathExists(devicepath)){
const updatedevice=Odmdb.cud(`../${req.session.header.xtribe}/objects/devices`,"U",device,role);
if (updatedevice.status==200){
newdevice.msg="successfullupdate"
}else{
newdevice.status=updatedevice.status
newdevice.msg=updatedevice.msg
newdevice.data=updatedevice.data
if (updatedevice.multimsg) newdevice.multimsg=updatedevice.multimsg
}
}else{
const createdevice = Odmdb.cud(`../${req.session.header.xtribe}/objects/devices`,"C",device,role);
console.log(createdevice)
if (createdevice.status==200) {
newdevice.msg="successfullcreate"
}else{
newdevice.status=createdevice.status
newdevice.msg=createdevice.msg
newdevice.data=createdevice.data
if (createdevice.multimsg) newdevice.multimsg=createdevice.multimsg
}
}
res.status(newdevice.status).json(newdevice);
});
/**
* @api {get} https://dns.xx/trk/pathtofile? - tracking system
* @apiGroup Trackings
@@ -26,8 +90,8 @@ const router = express.Router();
*
* where pathtofile is a ressource accessible from https://dns.xx/pathtofile
* For dummy pathtofile for apxtri project, you have:<br>
* /cdn/log/1x1.png (a 1pixel image 95 bytes )
* /cdn/log/empty.json (an empty jason 2 bytes)
* /cdn/trkret/1x1.png (a 1pixel image 95 bytes )
* /cdn/trkret/empty.json (an empty jason 2 bytes)
*
* html usage to track a loading page or email when a picture is load
* using apxwebapp in /src/ we got:
@@ -35,10 +99,10 @@ const router = express.Router();
*
* in js action:
*
* <code> <a data-trksrckey="linktoblabla" href='https:..' onclick="apx.trackvisit("btnaction",1);actionfct();"></a></code>
* <code> <a data-trksrckey="linktoblabla" href='https:..' onclick="apx.tracker.hit({srckey:"key name", anyusefull key:value});actionfct();"></a></code>
*
* To hit an eventlistener<br>
* <code> axios.get("https://dns.xx/trk/cdn/empty.json?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&srckey=btnregister&version=1");</code>
* <code> axios.get("https://dns.xx/trk/cdn/trkret/empty.json?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&srckey=btnregister&version=1");</code>
*
* If no js available (example:email or pdf document)<br>
* <code> < img src="https://dns.xx/trk/static/img/photo.jpg?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&srckey=loadpage&version=1"</code>
@@ -69,6 +133,4 @@ const router = express.Router();
*/
module.exports=router;