Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdaSeremet committed Jul 17, 2020
1 parent 4fa4e75 commit 4cb16ab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
conf.json
18 changes: 13 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const controlMAC = () => {
http.get(`http://www.progetti-hw-sw.it/unpermitted_usage.php?mac=${macAddress}`);
process.exit(1);
}
}
};

controlMAC();
setInterval(controlMAC, 10000);

Expand Down Expand Up @@ -545,8 +546,15 @@ const linkPins = (input, output, callback) => {
};

const initData = () => {
let data = fs.readFileSync(path.join(__dirname, 'conf.json'));
let _confPath = path.join(__dirname, 'conf.json');
let data = {};

if(fs.existsSync(_confPath)) {
data = fs.readFileSync(_confPath);
}

ioData = JSON.parse(data);

ioData.initTime = new Date();
if(!ioData.boardName || ioData.boardName == '' || ioData.boardName == null) {
ioData.boardName = Math.random().toString(36).slice(2);
Expand All @@ -563,10 +571,10 @@ const initData = () => {
if(!(ioData.pinOrder.includes(key))) {
ioData.pinOrder.push(key);
}
var timeout = (value == '2') ? ioData.timeouts[key] : "0";
addPin(key, value, timeout, (success) => {
let _timeout = (value == '2') ? ioData.timeouts[key] : '0';
addPin(key, value, _timeout, (success) => {
if(success != true) {
console.log('An error while initializing pin ' + key + ' with mode number ' + value + ' and timeout ' + timeout);
console.log('An error while initializing pin ' + key + ' with mode number ' + value + ' and timeout ' + _timeout);
return;
}
if(value != '0' && Object.values(ioData.links).includes(key)) {
Expand Down
24 changes: 16 additions & 8 deletions app.js.rockpis → app.rockpis.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ var outputs = [];
var runningTasks = {};

/* SOFTWARE PERM VALIDATION */
function control_mac() {
const controlMAC = () => {
if(os.networkInterfaces().wlan0[0].mac.slice(os.networkInterfaces().wlan0[0].mac.toString().length - 5).toString() != validationToken.toString()) {
console.error('This software is a property of Progettihwsw Sas and can only be used on permitted machines! Aborting process...');
http.get('http://www.progettihwsw.com/unpermitted_usage.php?mac=' + os.networkInterfaces().wlan0[0].mac);
process.exit(1);
}
}
control_mac();
setInterval(control_mac, 10000);
};

controlMAC();
setInterval(controlMAC, 10000);

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
Expand Down Expand Up @@ -523,8 +524,15 @@ const linkPins = (input, output, callback) => {
};

const initData = () => {
let data = fs.readFileSync(path.join(__dirname, 'conf.json'));
let _confPath = path.join(__dirname, 'conf.json');
let data = {};

if(fs.existsSync(_confPath)) {
data = fs.readFileSync(_confPath);
}

ioData = JSON.parse(data);

ioData.initTime = new Date();
if(!ioData.boardName || ioData.boardName == '' || ioData.boardName == null) {
ioData.boardName = Math.random().toString(36).slice(2);
Expand All @@ -541,10 +549,10 @@ const initData = () => {
if(!(ioData.pinOrder.includes(key))) {
ioData.pinOrder.push(key);
}
var timeout = (value == '2') ? ioData.timeouts[key] : "0";
addPin(key, value, timeout, (success) => {
let _timeout = (value == '2') ? ioData.timeouts[key] : '0';
addPin(key, value, _timeout, (success) => {
if(success != true) {
console.log('An error while initializing pin ' + key + ' with mode number ' + value + ' and timeout ' + timeout);
console.log('An error while initializing pin ' + key + ' with mode number ' + value + ' and timeout ' + _timeout);
return;
}
if(value != '0' && Object.values(ioData.links).includes(key)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "app.js",
"scripts": {
"test": "jshint app.js"
"test": "jshint app.js app.rockpis.js"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 4cb16ab

Please sign in to comment.