device tracking

This commit is contained in:
philc 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 //check in ctx.wcotribe if ctx.tribe_ctx.code exist in
console.log("@todo don't forget to manage accessright to wco in Wwws"); console.log("@todo don't forget to manage accessright to wco in Wwws");
//check that all tpl, tpldata, ... are available for this pagename //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 webconf = `../${ctx.tribe}/objects/wwws/itm/${ctx.xapp}.json`;
const webpageinit = { const webpageinit = {
dns: [], dns: [],
@ -77,6 +80,7 @@ Wwws.getwco = (wconame, ctx) => {
ref: {}, ref: {},
schema: [], schema: [],
tpldata: {}, tpldata: {},
wco:{}
}; };
const wcoinfo = fs.readJSONSync(wcoconf); const wcoinfo = fs.readJSONSync(wcoconf);
const webpage = fs.existsSync(webconf) const webpage = fs.existsSync(webconf)

View File

@ -10,7 +10,7 @@ const checkHeaders = require("../middlewares/checkHeaders.js");
const isAuthenticated = require("../middlewares/isAuthenticated.js"); const isAuthenticated = require("../middlewares/isAuthenticated.js");
const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.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);
const router = express.Router(); const router = express.Router();

View File

@ -3,6 +3,8 @@ 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(`../../../adminapi/objects/tribes/itm/adminapi.json`); 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"); const Odmdb = require("../models/Odmdb.js");
// Middlewares // Middlewares
const checkHeaders = require("../middlewares/checkHeaders"); const checkHeaders = require("../middlewares/checkHeaders");
@ -10,6 +12,68 @@ const isAuthenticated = require("../middlewares/isAuthenticated");
const router = express.Router(); 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 * @api {get} https://dns.xx/trk/pathtofile? - tracking system
* @apiGroup Trackings * @apiGroup Trackings
@ -26,8 +90,8 @@ const router = express.Router();
* *
* where pathtofile is a ressource accessible from https://dns.xx/pathtofile * where pathtofile is a ressource accessible from https://dns.xx/pathtofile
* For dummy pathtofile for apxtri project, you have:<br> * For dummy pathtofile for apxtri project, you have:<br>
* /cdn/log/1x1.png (a 1pixel image 95 bytes ) * /cdn/trkret/1x1.png (a 1pixel image 95 bytes )
* /cdn/log/empty.json (an empty jason 2 bytes) * /cdn/trkret/empty.json (an empty jason 2 bytes)
* *
* html usage to track a loading page or email when a picture is load * html usage to track a loading page or email when a picture is load
* using apxwebapp in /src/ we got: * using apxwebapp in /src/ we got:
@ -35,10 +99,10 @@ const router = express.Router();
* *
* in js action: * 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> * 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> * 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> * <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; module.exports=router;

View File

@ -1,71 +1,128 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "adminapi/schema/wco", "$id": "adminapi/schema/devices",
"title": "web components", "title": "Following xuuid",
"description": "A web component wco is a folder with list of mustache and one name.js that deal all the business logic", "description": "xuuid is a unique id that is created for tracking purpose it collect some information about a device mobile, pc,... and a xuuid is generated the first time a domain name is access this is why this information is store into a tribes",
"type": "object", "type": "object",
"properties": { "properties": {
"wconame": { "xuuid": {
"description": "Folder name into a tribeId/objects/wco/itm", "description": "A unique id that is created for a device the first time a user access a domainname",
"title": "Web component reusable in web project based with tailwindcss", "title": "Unique id into a browser",
"type": "string" "type": "string"
}, },
"owner": { "owner": {
"description": "owner that earn some fees", "title": "Owner of this person",
"description": "For accessright purpose this is always equal as alias",
"type": "string" "type": "string"
}, },
"codehash": { "dt_create": {
"description": "Code signature of alias publickey", "title": "Creation date",
"type": "string",
"format": "date-time"
},
"dt_update": {
"type": "string",
"format": "date-time"
},
"alias": {
"description": "If knowns we get an alias",
"type": "string" "type": "string"
}, },
"thumbnail":{ "hits": {
"title":"Thumbnail of the component", "title": "List of hit of 10 minutes",
"type":"string" "description": "not yet formalize {dns:[{tm: timestamp of the event, trk: srctrk, context of the trk}]",
"type": "object"
}, },
"title":{ "useragent": {
"title":"Short description of the wco", "title": "user agent the first time",
"type":"string" "type": "string"
}, },
"description":{ "typedevice": {
"title":"Long description in html of the component", "title": "Type of device",
"type":"string" "type": "string",
"enum": [
"ipad",
"iphone",
"ipod",
"android",
"PC",
""
]
}, },
"tpl":{ "os": {
"description":"list of mustache template to manage components each file must ended by _xx.mustache where xx is the language of the template, so you can add translation easily", "title": "OS detected",
"type":"array" "type": "string",
"enum": [
"mobile",
"windows",
"mac",
"linux",""
]
}, },
"tpldata":{ "ip": {
"description":"Example of tpldata that you have to add in your local to customize the wco ended by _xx.json where xx is the language of the template", "title": "Public IP from api https://ipinfo.io/json",
"type":"array" "type": "string"
},
"city": {
"title": "city from ipinfo.io",
"type": "string"
},
"country": {
"title": "country from ipinfo.io",
"type": "string"
},
"screenWidth": {
"title": "Screen width of the device",
"type": "integer"
},
"screenHeight": {
"title": "Screen height of the device",
"type": "integer"
},
"connection": {
"title": "Bandwidth of thefirst access, this can of course change",
"type": "string"
},
"lang": {
"title": "Language setting of the device",
"type": "string"
},
"plugins": {
"title": "List of current plugins install into the browser during the first access",
"type": "array"
} }
}, },
"required": [ "required": [
"wconame", "xuuid"
"owner", ],
"title" "apxid": "xuuid",
], "apxuniquekey": [
"apxid": "wconame", "xuuid"
"apxuniquekey": [ ],
"wconame" "apxidx": [
], {
"apxidx": [ "name": "alias",
{ "type": "view",
"name": "lst_wconame", "keyval": "alias",
"type": "array", "objkey": [
"keyval": "wconame" "xuuid",
} "type",
], "os"
"apxaccessrights": { ],
"owner": { "filter": ""
"D": [], }
"R": [], ],
"U": [] "apxaccessrights": {
}, "anonymous":{
"mayor": { "C":[],
"C": [] "U":[],
}, "D":[]
"person": { },
"R": [] "mayor": {
} "R": []
} },
"person": {
"R": []
}
}
} }