Last active
February 6, 2017 15:01
-
-
Save linktohack/b5d39c87fa2eee7a72af548771ec66d5 to your computer and use it in GitHub Desktop.
Scarmark Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cat > "$HOME/main.html" <<'EOF' | |
<style> | |
.magasin-lot-info { | |
font-family: monospace; | |
font-size: 8px; | |
color: white; | |
padding: 8px; | |
} | |
</style> | |
<section class="veille"> | |
<p class="magasin-lot-info"> | |
{{Date2}} {{Date}} {{NomMagasin}} #{{NumBorne}} * <br> | |
{{NbLotProduitJour}}.{{NbLotProduitJourTotal}} {{NbLotSacJour}}.{{NbLotSacJourTotal}} - {{NbLotProduit}}.{{NbLotProduitTotal}} {{NbLotSac}}.{{NbLotSacTotal}} | |
</p> | |
</section> | |
EOF | |
cat > "$HOME/peripherique.js" <<'EOF' | |
function check_disponible() { | |
getMaxDate(DATE_SERVERS).then(date => { | |
if ((moment(date, DATE_FORMAT).diff(INDISPONIBLE_FIN) < 0) && (moment(date, DATE_FORMAT).diff(INDISPONIBLE_DEBUT) > 0) && (window.location.hash != '#/indisponible')) { | |
window.game.indisponible(); | |
} else if ((window.location.hash == '#/indisponible') && ((moment(date, DATE_FORMAT).diff(INDISPONIBLE_FIN) > 0) || (moment(date, DATE_FORMAT).diff(INDISPONIBLE_DEBUT) <0))) { | |
window.game.veille(); | |
} | |
}); | |
window.Gain && window.Gain.count().then(function() { | |
window.ERROR.remove('Vérifier la connexion de maitre - esclave'); | |
}).catch(function() { | |
}); | |
} | |
check_disponible() | |
setInterval(check_disponible, 10000); | |
function check_imprimante() { | |
exec('lsusb -d 1c8a:3a10 | wc -l', function(error, stdout, stderr) { | |
if (parseInt(stdout) != 1) { | |
window.ERROR.addAndDisplay('Vérifier la connexion de l\'imprimante'); | |
} else { | |
window.ERROR.remove('Vérifier la connexion de l\'imprimante'); | |
} | |
}); | |
} | |
check_imprimante(); | |
setInterval(check_imprimante, 10000); | |
port.on('open', function() { | |
console.log('ok'); | |
}); | |
port.on('error', function(error) { | |
console.log(error); | |
window.ERROR.addAndDisplay('Vérifier la connexion du lecteur code barre'); | |
}); | |
var confirmFactory = function(func) { | |
var savedArgs = null; | |
return function() { | |
if (_.isEqual(savedArgs, arguments)) { | |
func.apply(this, arguments); | |
} | |
savedArgs = arguments; | |
} | |
} | |
var setMagasin = (codeBarre) => { | |
var found = magasins.find(function(m) { | |
return m.pano == codeBarre.replace(/^DB/, '').replace(/[^a-zA-Z0-9]/g, ''); | |
}); | |
if (found) { | |
window.ERROR.remove("DB NOT FOUND!!!"); | |
exec('mysql -uroot -proot scamark < "' + __dirname + '/database/' + found.file + '.sql"', function(error, stdout, stderr) { | |
config.magasin = found.name; | |
writeFile(CONFIG_FILE, JSON.stringify(config)).then(() => { | |
window.location.hash = "#/"; | |
}); | |
}); | |
} else { | |
window.ERROR.addAndDisplay("DB NOT FOUND!!!"); | |
} | |
} | |
var maybeSetMagasin = confirmFactory(setMagasin); | |
var reset = () => { | |
exec(`mysql -uroot -proot -e"DROP DATABASE IF EXISTS scamark; | |
CREATE DATABASE scamark; | |
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'; | |
FLUSH PRIVILEGES;" && rm ${CONFIG_FILE}`, (error, stdout, stderr) => { | |
writeFile(CONFIG_NETWORK_FILE, CONFIG_NETWORK(1)).then(() => { | |
window.config = { magasin: '', slave: 1 }; | |
window.location.href = '#/vierge'; | |
setTimeout(function() { | |
window.location.reload(); | |
}, 1000); | |
}); | |
}); | |
}; | |
var maybeReset = _.after(2, reset); | |
var setMasterSlave = (slave) => { | |
window.config.slave = slave; | |
bluebird.all([ | |
writeFile(CONFIG_NETWORK_FILE, CONFIG_NETWORK(slave)), | |
writeFile(CONFIG_FILE, JSON.stringify(config)) | |
]).then(() => { | |
window.location.href = "#/"; | |
setTimeout(function() { | |
window.location.reload(); | |
}, 1000); | |
}); | |
}; | |
var maybeSetMasterSlave = confirmFactory(setMasterSlave); | |
port.on('data', function (data) { | |
window.ERROR.remove('Vérifier la connexion du lecteur code barre'); | |
var codeBarre = data.toString().trim(); | |
if (!config.magasin && codeBarre.indexOf('ADMIN6625') == 0) { | |
getMaxDate(DATE_SERVERS).then(date => { | |
exec('python data/print/print_admin.py "' + 'MAGASIN NON CONFIGURE' + '" '+ `0 0 0 0 0 0 0 0 0 0 "${date}"`, (error, stdout, stderr) => { | |
if (error) { | |
hasError = true; | |
console.error(`exec error: ${error}`); | |
window.ERROR.addAndDisplay('Vérifier la connexion de l\'imprimante'); | |
} | |
console.log(`stdout: ${stdout}`); | |
console.log(`stderr: ${stderr}`); | |
}); | |
}); | |
} | |
if (!config.magasin && codeBarre.indexOf('DB') != 0) { | |
maybeSetMagasin = confirmFactory(setMagasin); | |
window.location.href = "#/vierge"; | |
return; | |
} | |
if (codeBarre.indexOf('RESET6625') != 0) { | |
maybeReset = _.after(2, reset); | |
} | |
if(codeBarre.indexOf('IPADDRESS') != 0) { | |
maybeSetMasterSlave = confirmFactory(setMasterSlave); | |
} | |
if (!config.magasin && codeBarre.indexOf('DB') == 0) { | |
maybeSetMagasin(codeBarre); | |
} else if (codeBarre.indexOf('RESET6625') == 0) { | |
maybeReset(); | |
} else if(codeBarre.indexOf('UPLOAD6625') == 0) { | |
exec('./upload.sh', (error, stdout, stderr) => { | |
if (error) { | |
hasError = true; | |
console.error(`exec error: ${error}`); | |
window.ERROR.addAndDisplay('JE NE PEUX PAS TELECHARGER LA BASE DE DONNER'); | |
window.ERROR.addAndDisplay(`stdout: ${stdout}`); | |
window.ERROR.addAndDisplay(`stderr: ${stderr}`); | |
} else { | |
game.admin(); | |
console.log(`stdout: ${stdout}`); | |
console.log(`stderr: ${stderr}`); | |
} | |
}); | |
} else if (codeBarre.indexOf('IPADDRESS') == 0) { | |
var slave = codeBarre[codeBarre.length - 1]; | |
if (slave > 1) { | |
maybeSetMasterSlave(slave); | |
} | |
} else if (game.getStatus() == 'veille') { | |
if(codeBarre.length == 9 && codeBarre.indexOf('ADMIN6625') == 0) { | |
game.admin(); | |
} | |
else if ((codeBarre.length == 24) && /([0-9]{5})([0-9]{4})([0-9]{12})([0-9]{1})([0-9]{2})/.test(codeBarre)) { | |
/** | |
* Split du code barre EAN128 | |
*/ | |
var EAN = codeBarre; | |
var res = EAN.split(/([0-9]{5})([0-9]{4})([0-9]{12})([0-9]{1})([0-9]{2})/); | |
res.shift(); | |
res.pop(); | |
var id = res[0]; | |
var numUniqueMagasin = res[2]; | |
var emetteurMagasin = res[1]; | |
var value = res[3]; | |
var cleEAN128 = res[4]; | |
var cleNumUnique = numUniqueMagasin.substring(numUniqueMagasin.length-2, numUniqueMagasin.length); | |
/** | |
* Calcul de la clé de contrôle EAN128 | |
*/ | |
var valueValidationCle = EAN.substring(0, EAN.length-2); | |
var j = 1; | |
var calcCleEAN128 = 0; | |
for(var i = 0 ; i < valueValidationCle.length ; i+=2) | |
{ | |
calcCleEAN128 += valueValidationCle.substring(i, i+2) * j; | |
j++; | |
} | |
calcCleEAN128 = calcCleEAN128%100; | |
console.log(calcCleEAN128); | |
/** | |
* Calcul de la clé de contrôle Numéro unique | |
*/ | |
var valueValidationCle = emetteurMagasin + numUniqueMagasin.substring(0, numUniqueMagasin.length-2); | |
var j = 1; | |
var calcCleNumUnique = 0; | |
for(var i = 0 ; i < valueValidationCle.length ; i++) | |
{ | |
calcCleNumUnique += valueValidationCle.substring(i, i+1) * j; | |
j++; | |
} | |
calcCleNumUnique = calcCleNumUnique%100; | |
console.log(calcCleNumUnique); | |
if(cleEAN128 == calcCleEAN128 && cleNumUnique == calcCleNumUnique) { | |
game.id_carte = codeBarre; | |
game.launchGame(); | |
} | |
else { | |
window.location.href = '#/erreurCodeBarre'; | |
} | |
} | |
else { | |
window.location.href = '#/erreurCodeBarre'; | |
} | |
} | |
else if(game.getStatus() == 'admin') { | |
game.veille(); | |
} | |
console.log('Data: ' + data); | |
}); | |
EOF | |
sudo mkdir -p /tmp/sda6 | |
sudo mount /dev/sda6 /tmp/sda6 | |
sudo find /tmp/sda6/docker -name peripherique.js -exec sh -c "cp '{}' '{}.5514'; cp -rf '$HOME/peripherique.js' '{}'" \; | |
sudo find /tmp/sda6/docker -name main.html -exec sh -c "cp '{}' '{}.5514'; cp -rf '$HOME/main.html' '{}'" \; | |
sudo umount -l /dev/sda6 | |
sudo umount -l /dev/sda6 | |
sudo umount -l /dev/sda6 | |
for i in $(seq 5 -1 0); do | |
echo -n "$i."; sleep 1 | |
done | |
echo 'Fini...' | |
ping 0.0.0.0 > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment