diff --git a/auto_startx_bashrc b/auto_startx_bashrc new file mode 100755 index 0000000..50f85ad --- /dev/null +++ b/auto_startx_bashrc @@ -0,0 +1,9 @@ +#! /bin/bash +if grep "#modif bashrc = ok" /home/sysop/.bashrc > /dev/null +then + echo 'bashrc déjà modifié pour auto startx !' +else + sudo echo 'export TYPE_SERVEUR_NFC=VMA405' >> /home/sysop/.bashrc + sudo echo '#modif bashrc = ok' >> /home/sysop/.bashrc + sudo echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor' >> /home/sysop/.bashrc +fi diff --git a/autostart b/autostart index 1672291..a5198df 100755 --- a/autostart +++ b/autostart @@ -18,5 +18,5 @@ rm -fr /home/sysop/.config/chromium/Default/ xrandr --output DSI-1 --rotate right # lance chromium avec un user agent spécifique hostname,password,periph,ip (provenant en partie de .chromium_env) -cd /home/sysop/serveurNfcNodeJs/ +cd /home/sysop/serveurNfcNodeJsVma405/ node serveur_nfc.js diff --git a/branchement_ecran_pi.png b/branchement_ecran_pi.png new file mode 100644 index 0000000..a83094c Binary files /dev/null and b/branchement_ecran_pi.png differ diff --git a/install_1024x600_vma405_chromium.yml b/install_1024x600_vma405_chromium.yml new file mode 100644 index 0000000..8e320fd --- /dev/null +++ b/install_1024x600_vma405_chromium.yml @@ -0,0 +1,248 @@ +--- +- hosts: dsi1024x600_vma405Pi2 + remote_user: sysop + become: yes + tasks: + - name: Maj dépôts + apt: + upgrade: yes + update_cache: yes + + - name: install "7zip" + apt: + name: p7zip-full + state: present + + - name: install git + apt: + name: git + state: present + + - name: install "xserver-xorg" + apt: + name: xserver-xorg + state: present + + - name: install "x11-xserver-utils" + apt: + name: x11-xserver-utils + state: present + + - name: install "xinit" + apt: + name: xinit + state: present +# + - name: install "openbox" + apt: + name: openbox + state: present + + - name: install "chromium-browser" + apt: + name: chromium-browser + state: present + + - name: install "xdotool" + apt: + name: xdotool + state: present + + - name: Copie du fichier de démarrage automatique de Xorg + copy: + src: ./auto_startx_bashrc + dest: /home/sysop/auto_startx_bashrc + owner: sysop + group: sysop + mode: '0770' + backup: yes + + - name: Ajout du fichier de démarrage automatique de Xorg au fichier .bashrc + shell: /home/sysop/auto_startx_bashrc + + - name: Copie du fichier autostart + copy: + src: ./autostart + dest: /home/sysop/autostart + owner: sysop + group: sysop + mode: '0770' + backup: yes + + - name: Remplacer le fichier autostart + shell: + cmd: cp /home/sysop/autostart /etc/xdg/openbox/autostart + + - name: Copie du fichier serveurNfcNodeJsVma405.7z + copy: + src: ./serveurNfcNodeJsVma405.7z + dest: /home/sysop/serveurNfcNodeJsVma405.7z + owner: sysop + group: sysop + backup: yes + + - name: décompresser le fichier serveurNfcNodeJsVma405.7z + shell: + cmd: 7z x serveurNfcNodeJsVma405.7z + + - name: Changer les droits du dossier serveurNfcNodeJsVma405 + shell: + cmd: chown -R sysop:sysop /home/sysop/serveurNfcNodeJsVma405 + + - name: Ajout du dépot nodes js + shell: curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - + + - name: install "nodejs" + apt: + name: nodejs + state: present + + - name: Pour nodejs, installation de "gcc" pour la compilation + apt: + name: gcc + state: present + + - name: Pour nodejs, installation de "g++" pour la compilation + apt: + name: g++ + state: present + + - name: Pour nodejs, installation de "make" pour la compilation + apt: + name: make + state: present + + - name: Pour nodejs, installation de "apt-transport-https" pour la compilation + apt: + name: apt-transport-https + state: present + + - name: Installer les modules du serveurNfcNodeJsVma405 + shell: + cmd: npm i + chdir: /home/sysop/serveurNfcNodeJsVma405/ + + - name: Création du fichier de configuration + shell: cp chromium_env.exemple .chromium_env + args: + chdir: /home/sysop/serveurNfcNodeJsVma405/ + + - name: Modification du hostname du fichier de configuration + shell: + cmd: sed -i "s/__hostname__/{{ hostname }}/" /home/sysop/serveurNfcNodeJsVma405/.chromium_env + + - name: Modification du mot de passe du fichier de configuration + shell: + cmd: sed -i "s/__mdp__/{{ password }}/" /home/sysop/serveurNfcNodeJsVma405/.chromium_env + + - name: Modification du token wifi du fichier de configuration + shell: + cmd: sed -i "s/__token__/{{ token }}/" /home/sysop/serveurNfcNodeJsVma405/.chromium_env + + - name: Modification du type de front du fichier de configuration + shell: + cmd: sed -i "s/__frontType__/{{ frontType }}/" /home/sysop/serveurNfcNodeJsVma405/.chromium_env + + - name: Modification du protocole(serveur) du fichier de configuration + shell: + cmd: sed -i "s/__protocole__/{{ protocole }}/" /home/sysop/serveurNfcNodeJsVma405/.chromium_env + + - name: Modification de l'adresse du serveur du fichier de configuration + shell: + cmd: sed -i "s/__serveur__/{{ serveur }}/" /home/sysop/serveurNfcNodeJsVma405/.chromium_env + + - name: Création du dossier repos "7inch-DSI-LCD-C" + file: + path: /home/sysop/7inch-DSI-LCD-C + state: directory + mode: '0775' + + - name: Rapatrier le driver de l'écran + git: + repo: https://github.com/waveshare/7inch-DSI-LCD-C.git + dest: /home/sysop/7inch-DSI-LCD-C/ + clone: yes + update: no + + - name: Installer le driver + shell: /home/sysop/7inch-DSI-LCD-C/32/5.10.103/pi3/WS_7inchDSI1024x600.sh + args: + chdir: /home/sysop/7inch-DSI-LCD-C/32/5.10.103/pi3/ + + - name: Ajouter la rotation de 90° au fichier de configuration /boot/config.txt + shell: + cmd: echo "#90°" >> /boot/config.txt && echo "dtoverlay=WS_7inchDSI1024x600_Touch,invertedx,swappedxy" >> /boot/config.txt + + - name: installe "splash screen" + apt: + name: rpd-plym-splash + state: present + + - name: Installation de "fbi", pour visualiser le splash screen(logo) + apt: + name: fbi + state: present + + - name: install "xserver-xorg-video-fbturbo" + apt: + name: xserver-xorg-video-fbturbo + state: present + + - name: Copie du fichier image splash.png + copy: + src: ./splash.png + dest: /home/sysop/splash.png + owner: sysop + group: sysop + backup: yes + + - name: Suppression du logo raspberry pi, modification du fichier /boot/cmdline.txt + shell: + cmd: echo "\nconsoleblank=0 loglevel=1 quiet logo.nologo" >> /boot/cmdline.txt + + - name: Autoriser startx + shell: + cmd: sed -i "s/quiet splash plymouth.ignore-serial-consoles//" /boot/cmdline.txt + + - name: Copie du fichier du service "splashscreen.service" + copy: + src: ./splashscreen.service + dest: /etc/systemd/system/splashscreen.service + owner: sysop + group: sysop + mode: '0770' + backup: yes + + - name: Activer "splashscreen.service" + shell: + cmd: sudo systemctl enable splashscreen.service + + - name: Démarrer "splashscreen.service" + shell: + cmd: sudo systemctl start splashscreen.service + + - name: Active SPI + shell: + cmd: echo "dtparam=spi=on" >> /boot/config.txt + + - name: Auto-login + shell: + cmd: raspi-config nonint do_boot_behaviour B2 + + - name: Changer le propriétaire et le groupe dupériphérique + shell: chown root:gpio /dev/gpiomem + + - name: Configurer les droits du groupe en lecture ecriture + shell: chmod g+rw /dev/gpiomem + + - name: Ajout de l'utilisateur au groupe gpio + shell: usermod -a -G gpio $USER + + - name: Ajout de l'utilisateur au groupe spi + shell: usermod -a -G spi $USER + + - name: Ajout de l'utilisateur au groupe netdev + shell: usermod -a -G netdev $USER + + - name: Redémarrage ! + reboot: diff --git a/node.yml b/node.yml deleted file mode 100755 index b6351cd..0000000 --- a/node.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -- hosts: testDsiPi - remote_user: sysop - become: yes - tasks: - - - name: install "splash screen" - apt: - name: rpd-plym-splash - state: present - - - name: Active SPI - shell: - cmd: echo "dtparam=spi=on" >> /boot/config.txt - - - name: Ajout du dépot nodes js - shell: curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - - - - name: install "nodejs" - apt: - name: nodejs - state: present - - - name: Pour nodejs, installation de "gcc" pour la compilation - apt: - name: gcc - state: present - - - name: Pour nodejs, installation de "g++" pour la compilation - apt: - name: g++ - state: present - - - name: Pour nodejs, installation de "make" pour la compilation - apt: - name: make - state: present - - - name: Pour nodejs, installation de "apt-transport-https" pour la compilation - apt: - name: apt-transport-https - state: present - - - name: Installation des modules node js - shell: - cmd: npm i - chdir: /home/sysop/nodeJsVma405/ diff --git a/readme.md b/readme.md index d5e5ace..52d2125 100755 --- a/readme.md +++ b/readme.md @@ -13,37 +13,38 @@ - + - +
3937353331292725SCKMISOMOSI17151311GND753vcccôté usb3937353331292725SCKMISOMOSI17151311GND753vcc
4038363432302826NSSRST2018161412108642reseau4038363432302826NSSRST2018161412108642
- - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
VMA405PI 3 B+Couleur cable
VCC1marron
RST22rouge
GND9orange
MISO21jaune
MOSI19vert
SCK23bleu
NSS24violet
IRQpas utilisé
RC522 / VMA405PI 3 B+Couleur cable
3.3v / VCC1rouge
RST22marron
GND9noir
IRQpas utilisé
MISO21jaune
MOSI19vert
SCK23bleu
SDA24violet
+ # installation de node js (ansible) -node.yml +install_1024x600_vma405_chromium.yml # splash screen (écran de boot = pub) ``` diff --git a/rfid_rc522.jpg b/rfid_rc522.jpg new file mode 100644 index 0000000..64c0908 Binary files /dev/null and b/rfid_rc522.jpg differ diff --git a/serveurNfcNodeJsVma405.7z b/serveurNfcNodeJsVma405.7z new file mode 100644 index 0000000..7b65656 Binary files /dev/null and b/serveurNfcNodeJsVma405.7z differ diff --git a/serveurNfcNodeJsVma405/chromium_env.exemple b/serveurNfcNodeJsVma405/chromium_env.exemple index 2acded4..46778d1 100644 --- a/serveurNfcNodeJsVma405/chromium_env.exemple +++ b/serveurNfcNodeJsVma405/chromium_env.exemple @@ -1,16 +1,16 @@ #cp chromium_env.exemple .chromium_env #utilisateur -hostname = testDsiPi +hostname = __hostname__ #front -front_type = FPI +front_type = __frontType__ #url du serveur -url = https://django-local.org:8501/wv/login_hardware +url = __protocole__://__serveur__/wv/login_hardware #mode_nfc = NFCMO mode_nfc = NFCLO -password = xxxxxxxxxxxxxxxxxxxxx -token = xxxxxxxxxxxxxxxxxx +password = __mdp__ +token = __token__ diff --git a/serveurNfcNodeJsVma405/serveur_nfc.js b/serveurNfcNodeJsVma405/serveur_nfc.js index 4c68f28..fac1f59 100755 --- a/serveurNfcNodeJsVma405/serveur_nfc.js +++ b/serveurNfcNodeJsVma405/serveur_nfc.js @@ -7,7 +7,7 @@ // même action pour le fichier sudo nano /usr/lib/pcsc/drivers/ifd-acsccid.bundle/Contents/Info.plist (pour desktop) let script, ip, memSudoMdp = '', etatUrl = 0 -let TAB = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '#', '$', '%', '&', '?','0','1','2','3','4','5','6','7','8','9']; +let TAB = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '#', '$', '%', '&', '?', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; let max_TAB = TAB.length - 1 let donneesFichierConfiguration = {} // type de lecteur nfc @@ -19,9 +19,9 @@ let dev = 1 const vma405Emitter = require('./vma405.js') const os = require('os') -const hostname= os.hostname() +const hostname = os.hostname() -const { spawn, exec } = require('child_process') +const {spawn, exec} = require('child_process') const IP = require('ip') const path = require('path') const fs = require('fs') @@ -42,7 +42,7 @@ let fichier = '', contentType = '' * @param {String|'ipv4'|'ipv6'} famille * @returns {string} */ -function obtenirIp(typeReseau, famille){ +function obtenirIp(typeReseau, famille) { ip = IP.address(typeReseau, famille) let retour = "erreur" if (ip !== "127.0.0.1" && ip !== "0.0.0.0") { @@ -53,18 +53,18 @@ function obtenirIp(typeReseau, famille){ // --- nfc --- vma405Emitter.on('tagId', (tagId) => { - if (retour !== null){ - retour['tagId'] = tagId.toUpperCase() - client_globale.emit('envoieTagId',retour) - console.log('--> demande carte, envoi tag id = ' + tagId.toUpperCase()) - retour = null - } else { - // console.log('-> Aucune demande, carte :' + card.uid.toString().toUpperCase()) - console.log('-> Aucune demande, carte :' + tagId.toUpperCase()) - if (client_globale !== null) { - client_globale.emit('infosTagId', tagId.toUpperCase()) - } + if (retour !== null) { + retour['tagId'] = tagId.toUpperCase() + client_globale.emit('envoieTagId', retour) + console.log('--> demande carte, envoi tag id = ' + tagId.toUpperCase()) + retour = null + } else { + // console.log('-> Aucune demande, carte :' + card.uid.toString().toUpperCase()) + console.log('-> Aucune demande, carte :' + tagId.toUpperCase()) + if (client_globale !== null) { + client_globale.emit('infosTagId', tagId.toUpperCase()) } + } }) vma405Emitter.on('msgVma405', (msg) => { @@ -72,7 +72,6 @@ vma405Emitter.on('msgVma405', (msg) => { }) - // --- commandes système --- /** @function * Obtenir ip extérieur (wan/box) @@ -84,7 +83,7 @@ function obtenirIpWan() { }) prog.on('close', (code) => { - if (code === 0 ){ + if (code === 0) { // ok: ip = prog.resultatRequete } else { // erreur @@ -98,15 +97,15 @@ function obtenirIpWan() { * @param {String} fichier - nom du fichier à lire * @returns {{msg, erreur: number}|{valeurs: {}, erreur: number}} */ -function obtenirConfigurationDunFichier(rechercher,fichier) { +function obtenirConfigurationDunFichier(rechercher, fichier) { try { - const fic = fs.readFileSync(fichier, {encoding:'utf8', flag:'r'}).split('\n') + const fic = fs.readFileSync(fichier, {encoding: 'utf8', flag: 'r'}).split('\n') let obj = {} for (let index = 0; index < fic.length; index++) { let ligne = fic[index].toString() if (ligne.length > 0 && ligne[0] !== '#' && ligne.indexOf('=') !== -1) { let tab = ligne.split('=') - for ( let im in rechercher) { + for (let im in rechercher) { mot = rechercher[im] if (mot === (tab[0].trim())) { obj[tab[0].trim()] = tab[1].trim() @@ -116,18 +115,18 @@ function obtenirConfigurationDunFichier(rechercher,fichier) { } return {erreur: 0, valeurs: obj} } catch (error) { - return {erreur:1 , msg: error} + return {erreur: 1, msg: error} } } -function afficherInfoServeur(donnees){ +function afficherInfoServeur(donnees) { // console.log('-> fonction afficherInfoServeur !') // console.log('donnees = ', donnees) if (donnees.erreur === 0) { let bruteUrl = donnees.valeurs.url let posDeuxSlashs = bruteUrl.indexOf('//') + 2 let posFinDomaine = bruteUrl.indexOf('/wv/login_hardware') - let domaine = bruteUrl.substring(posDeuxSlashs,posFinDomaine) + let domaine = bruteUrl.substring(posDeuxSlashs, posFinDomaine) let onclique = '' if (donnees.valeurs.front_type === "FPI") { onclique = `onclick="clavierVirtuel.obtPosition('serveur');clavierVirtuel.afficher('serveur', 'alpahMin')"` @@ -136,14 +135,14 @@ function afficherInfoServeur(donnees){ let options = '' for (let i = 0; i < fronts.length; i++) { let sel = '' - console.log(`${ i} -> ${ fronts[i] } -- ${ donnees.valeurs.front_type }`) + console.log(`${i} -> ${fronts[i]} -- ${donnees.valeurs.front_type}`) if (fronts[i] === donnees.valeurs.front_type) { sel = 'selected' } - options += `` + options += `` } return ` -
Serveur: ${ domaine }
+
Serveur: ${domaine}
@@ -161,11 +160,11 @@ function afficherInfoServeur(donnees){
- +
- +
@@ -173,7 +172,7 @@ function afficherInfoServeur(donnees){
- +
Valider
@@ -194,7 +193,7 @@ function afficherInfoServeur(donnees){ * @param {Number} nbMaxStderr - nombre maxi d'évènement Stderr avant de sortir de la fonction */ function testUrl(url, nbMaxStderr) { - console.log(`-> fonction testUrl, url = ->${ url }<-`) + console.log(`-> fonction testUrl, url = ->${url}<-`) const prog = spawn('curl', ['-I', url]) prog.nbMaxStderr = nbMaxStderr prog.nbStderr = 0 @@ -206,8 +205,8 @@ function testUrl(url, nbMaxStderr) { }) prog.stderr.on('data', (data) => { - prog.nbStderr ++ - if(prog.nbStderr === prog.nbMaxStderr) { + prog.nbStderr++ + if (prog.nbStderr === prog.nbMaxStderr) { prog.kill() } }) @@ -216,8 +215,8 @@ function testUrl(url, nbMaxStderr) { // header 307 = redirection temporaire // header 308 = redirection permanente console.log('réponse test serveur = ', prog.resultatRequete) - if(prog.resultatRequete === '200' || prog.resultatRequete === '307' || prog.resultatRequete === '308') { - etatUrl = 1 + if (prog.resultatRequete === '200' || prog.resultatRequete === '307' || prog.resultatRequete === '308') { + etatUrl = 1 } client_globale.emit('etatUrlServeur', prog.resultatRequete) }) @@ -231,8 +230,8 @@ function modifierConfigurationWifi(data) { ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ - ssid="${ data.essid }" - psk="${ data.passePhrase }" + ssid="${data.essid}" + psk="${data.passePhrase}" scan_ssid=1 } ` @@ -243,7 +242,7 @@ network={ msg: `

Modification wifi effectuée,

-

réseau = ${ data.essid }

+

réseau = ${data.essid}

Redémmarer l'appareil !

` @@ -253,7 +252,7 @@ network={ erreur: 1, msg: `

Erreur configuration wifi

-

${ erreur }

+

${erreur}

` }) } @@ -270,7 +269,7 @@ function afficherInfosWifi() { let tmpData = ligne.split(':') let etatWifi = 'on' let essid = '' - if (tmpData[1].includes('off')){ + if (tmpData[1].includes('off')) { etatWifi = 'off' } else { essid = tmpData[1].trim().replace(/"/g, '') @@ -286,16 +285,16 @@ function afficherInfosWifi() { if (code === 0) { // wifi actif // if (prog.resultat.etat === 'on' && donneesFichierConfiguration.erreur === 0) { - // uniquement sur pi - if (donneesFichierConfiguration.valeurs.front_type === "FPI") { - let onclique = '' - // if (donneesFichierConfiguration.valeurs.front_type === "FPI") { - oncliqueEssid = `onclick="clavierVirtuel.obtPosition('essid');clavierVirtuel.afficher('essid', 'alpahMin')"` - oncliquePasse = `onclick="clavierVirtuel.obtPosition('pp');clavierVirtuel.afficher('pp', 'alpahMin')"` - // } + // uniquement sur pi + if (donneesFichierConfiguration.valeurs.front_type === "FPI") { + let onclique = '' + // if (donneesFichierConfiguration.valeurs.front_type === "FPI") { + oncliqueEssid = `onclick="clavierVirtuel.obtPosition('essid');clavierVirtuel.afficher('essid', 'alpahMin')"` + oncliquePasse = `onclick="clavierVirtuel.obtPosition('pp');clavierVirtuel.afficher('pp', 'alpahMin')"` + // } - let fragHtml = ` -
Ssid: ${ prog.resultat.essid }
+ let fragHtml = ` +
Ssid: ${prog.resultat.essid}
Modifier Wifi
@@ -305,19 +304,19 @@ function afficherInfosWifi() {
- +
- +
Valider
` - client_globale.emit('retourInfosWifi', fragHtml) - } + client_globale.emit('retourInfosWifi', fragHtml) + } // } } }) @@ -394,7 +393,7 @@ function lancerChromium(etape, dataFichier) { } } -function lancerApplication(){ +function lancerApplication() { console.log('-> fonction lancerApplication !') const dataConf = obtenirConfigurationDunFichier(['hostname', 'token', 'password', 'front_type', 'url', 'mode_nfc'], './.chromium_env') if (dataConf.erreur === 0) { @@ -434,19 +433,20 @@ function afficherFrontType() { return 'inconnu' } } + function rnd(min, max) { - return Math.round(Math.random() * ((max+1) - min) + min,0); + return Math.round(Math.random() * ((max + 1) - min) + min, 0); } function generer_mot_de_passe(longueur) { let mot = ''; - let lettre = TAB[rnd(0,max_TAB)]; - for(let i=0;i<(longueur);i++){ + let lettre = TAB[rnd(0, max_TAB)]; + for (let i = 0; i < (longueur); i++) { - while (mot.indexOf(lettre)!=-1) { - lettre = TAB[rnd(0,59)]; - } - mot += lettre; + while (mot.indexOf(lettre) != -1) { + lettre = TAB[rnd(0, 59)]; + } + mot += lettre; } return mot } @@ -457,9 +457,9 @@ function modifierConfigurationServeur(data) { // Développement serveur = "#serveur.com#", donne un protocol http et serveur = "serveur.com" let serveur = data.serveurDomaine.toString() // console.log('0 = ',serveur[0], ' -- dernier = ',serveur[(serveur.length-1)]) - if (serveur[0] === '#' && serveur[(serveur.length-1)] === '#') { + if (serveur[0] === '#' && serveur[(serveur.length - 1)] === '#') { proto = 'http' - serveur = data.serveurDomaine.toString().substring(1,(serveur.length-1)) + serveur = data.serveurDomaine.toString().substring(1, (serveur.length - 1)) } donnees = obtenirConfigurationDunFichier(['hostname', 'token', 'password', 'front_type', 'url', 'mode_nfc'], './.chromium_env') @@ -480,10 +480,10 @@ front_type = ${data.typeFront} url = ${proto}://${serveur}/wv/login_hardware #mode_nfc = NFCMO -mode_nfc = ${ donnees.valeurs.mode_nfc } +mode_nfc = ${donnees.valeurs.mode_nfc} -password = ${ motDePasse } -token = ${ donnees.valeurs.token } +password = ${motDePasse} +token = ${donnees.valeurs.token} ` try { fs.writeFileSync(".chromium_env", template) @@ -500,26 +500,78 @@ token = ${ donnees.valeurs.token } // --- serveur http --- let typeMime = { - "aac":"audio/aac","abw":"application/x-abiword","arc":"application/octet-stream","avi":"video/x-msvideo","azw":"application/vnd.amazon.ebook", - "bin":"application/octet-stream","bz":"application/x-bzip","bz2":"application/x-bzip2","csh":"application/x-csh","css":"text/css","csv":"text/csv", - "doc":"application/msword","docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","eot":"application/vnd.ms-fontobject", - "epub":"application/epub+zip","gif":"image/gif","htm":"text/html","html":"text/html","ico":"image/x-icon","ics":"text/calendar","jar":"application/java-archive", - "jpeg":"image/jpeg","jpeg":"image/jpeg","js":"application/javascript","json":"application/json","mid":"audio/midi","midi":"audio/midi","mpeg":"video/mpeg", - "mpkg":"application/vnd.apple.installer+xml","odp":"application/vnd.oasis.opendocument.presentation","ods":"application/vnd.oasis.opendocument.spreadsheet", - "odt":"application/vnd.oasis.opendocument.text","oga":"audio/ogg","ogv":"video/ogg","ogx":"application/ogg","otf":"font/otf","png":"image/png","pdf":"application/pdf", - "ppt":"application/vnd.ms-powerpoint","pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation","rar":"application/x-rar-compressed", - "rtf":"application/rtf","sh":"application/x-sh","svg":"image/svg+xml","swf":"application/x-shockwave-flash","tar":"application/x-tar","tif":"image/tiff", - "tiff":"image/tiff","ts":"application/typescript","ttf":"font/ttf","vsd":"application/vnd.visio","wav":"audio/x-wav","weba":"audio/webm","webm":"video/webm", - "webp":"image/webp","woff":"font/woff","woff2":"font/woff2","xhtml":"application/xhtml+xml","xls":"application/vnd.ms-excel", - "xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","xml":"application/xml","xul":"application/vnd.mozilla.xul+xml","zip":"application/zip", - "3gp":"video/3gpp audio/3gpp","3g2":"video/3gpp2 audio/3gpp2", - "7z":"application/x-7z-compressed" + "aac": "audio/aac", + "abw": "application/x-abiword", + "arc": "application/octet-stream", + "avi": "video/x-msvideo", + "azw": "application/vnd.amazon.ebook", + "bin": "application/octet-stream", + "bz": "application/x-bzip", + "bz2": "application/x-bzip2", + "csh": "application/x-csh", + "css": "text/css", + "csv": "text/csv", + "doc": "application/msword", + "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "eot": "application/vnd.ms-fontobject", + "epub": "application/epub+zip", + "gif": "images/gif", + "htm": "text/html", + "html": "text/html", + "ico": "images/x-icon", + "ics": "text/calendar", + "jar": "application/java-archive", + "jpeg": "images/jpeg", + "jpeg": "images/jpeg", + "js": "application/javascript", + "json": "application/json", + "mid": "audio/midi", + "midi": "audio/midi", + "mpeg": "video/mpeg", + "mpkg": "application/vnd.apple.installer+xml", + "odp": "application/vnd.oasis.opendocument.presentation", + "ods": "application/vnd.oasis.opendocument.spreadsheet", + "odt": "application/vnd.oasis.opendocument.text", + "oga": "audio/ogg", + "ogv": "video/ogg", + "ogx": "application/ogg", + "otf": "font/otf", + "png": "images/png", + "pdf": "application/pdf", + "ppt": "application/vnd.ms-powerpoint", + "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "rar": "application/x-rar-compressed", + "rtf": "application/rtf", + "sh": "application/x-sh", + "svg": "images/svg+xml", + "swf": "application/x-shockwave-flash", + "tar": "application/x-tar", + "tif": "images/tiff", + "tiff": "images/tiff", + "ts": "application/typescript", + "ttf": "font/ttf", + "vsd": "application/vnd.visio", + "wav": "audio/x-wav", + "weba": "audio/webm", + "webm": "video/webm", + "webp": "images/webp", + "woff": "font/woff", + "woff2": "font/woff2", + "xhtml": "application/xhtml+xml", + "xls": "application/vnd.ms-excel", + "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "xml": "application/xml", + "xul": "application/vnd.mozilla.xul+xml", + "zip": "application/zip", + "3gp": "video/3gpp audio/3gpp", + "3g2": "video/3gpp2 audio/3gpp2", + "7z": "application/x-7z-compressed" } let www = process.cwd() + '/www/' console.log('www = ', www) -function retour404(res){ +function retour404(res) { res.writeHead(404, {'Content-Type': 'text/html'}); res.write('Page inconnue !'); res.end(); @@ -528,46 +580,46 @@ function retour404(res){ function renderHtml(contenu, ctx) { // let contenuTp1, contenuTp2, contenuTp3, contenuTp4 contenu = contenu.toString() - let rendu = contenu.toString().replace(/{{\s*[\w\.]+\s*}}/g, function(match, token) { - let clef = match.replace(/ /g,'').replace('{{','').replace('}}','') + let rendu = contenu.toString().replace(/{{\s*[\w\.]+\s*}}/g, function (match, token) { + let clef = match.replace(/ /g, '').replace('{{', '').replace('}}', '') console.log('-> match = ', match, ' -- clef = ', clef) return ctx[clef] }) - contenu = {} + contenu = {} return rendu } // lire la conf. dans le fichier .chromium_env donneesFichierConfiguration = obtenirConfigurationDunFichier(['hostname', 'token', 'password', 'front_type', 'url', 'mode_nfc'], './.chromium_env') -const serveur = http.createServer(function(req, res){ +const serveur = http.createServer(function (req, res) { let url = req.url; // routes let ctx = {} - if(url=='/') { + if (url == '/') { url = 'index.html' ctx = { fontType: afficherFrontType(), nomAppareil: os.hostname(), afficherInfoServeur: afficherInfoServeur(donneesFichierConfiguration), urlServeur: donneesFichierConfiguration.url, - ip: obtenirIp('public','ipv4'), + ip: obtenirIp('public', 'ipv4'), typeLecteurNfc: typeLecteurNfc, typeserveurNfc: 'nodejs' } } - if(url=='/favicon.ico') url = 'img/favicon2.ico' + if (url == '/favicon.ico') url = 'img/favicon2.ico' - fichier = www + url.substring(0,url.length); + fichier = www + url.substring(0, url.length); //assets let posDerPoint = url.lastIndexOf('.') let extention = '' - if(posDerPoint != -1){ - extention = url.substring(posDerPoint+1,url.length); - if(extention.toLowerCase() == 'css') contentType = 'text/css'; + if (posDerPoint != -1) { + extention = url.substring(posDerPoint + 1, url.length); + if (extention.toLowerCase() == 'css') contentType = 'text/css'; contentType = typeMime[extention.toLowerCase()]; } @@ -582,7 +634,7 @@ const serveur = http.createServer(function(req, res){ res.writeHead(200, {"Content-Type": contentType}) res.write(contenuFichier) res.end(); - console.log('-> url = '+url+' -- fichier :'+fichier+' -- contentType = '+contentType+' -> chargé !'); + console.log('-> url = ' + url + ' -- fichier :' + fichier + ' -- contentType = ' + contentType + ' -> chargé !'); } catch (err) { console.log('-> url = ' + url + ' -- Erreur: ' + err) retour404(res); @@ -598,16 +650,16 @@ const options = { methods: ["PUT", "GET", "POST"] } } -const IO = require('socket.io')(serveur,options) +const IO = require('socket.io')(serveur, options) // middleware -IO.use(function(socket, next){ +IO.use(function (socket, next) { let token = socket.handshake.query.token // console.log('token reçu = '+token+' -- TOKEN = '+TOKEN) - if (token === TOKEN){ + if (token === TOKEN) { return next() } else { - next(new Error("ERREUR d'autentification !")) + next(new Error("ERREUR d'autentification !")) } }) @@ -615,7 +667,7 @@ IO.on('connection', client => { client_globale = client; client_globale.on('demandeTagId', (data) => { retour = data; - console.log('-> demandeTagIdg = '+JSON.stringify(retour)) + console.log('-> demandeTagIdg = ' + JSON.stringify(retour)) }) client_globale.on('AnnuleDemandeTagId', () => { @@ -624,7 +676,7 @@ IO.on('connection', client => { client_globale.on('disconnect', () => { console.log('Client déconnecté !!') - }) + }) client_globale.on('validerModifierWifi', (data) => { modifierConfigurationWifi(data) @@ -636,7 +688,7 @@ IO.on('connection', client => { client_globale.on('testerUrlServeur', (urlATester) => { - console.log('-> test url serveur = ',urlATester) + console.log('-> test url serveur = ', urlATester) testUrl(urlATester, 12) }) @@ -656,4 +708,4 @@ serveur.listen(PORT, ADR, () => { }) const dataConf = obtenirConfigurationDunFichier(['hostname', 'token', 'password', 'front_type', 'url', 'mode_nfc'], './.chromium_env') -lancerChromium(1,dataConf) +lancerChromium(1, dataConf) diff --git a/serveurNfcNodeJsVma405/vma405.js b/serveurNfcNodeJsVma405/vma405.js index 61d80fc..8a455f1 100755 --- a/serveurNfcNodeJsVma405/vma405.js +++ b/serveurNfcNodeJsVma405/vma405.js @@ -1,7 +1,6 @@ // si problême de droit // sudo chown root:gpio /dev/gpiomem // sudo chmod g+rw /dev/gpiomem -// sudo chmod g+rw /dev/gpiomem // sudo usermod -a -G gpio $USER // sudo usermod -a -G spi $USER // sudo usermod -a -G netdev $USER diff --git a/serveurNfcNodeJsVma405/www/images/logo.png b/serveurNfcNodeJsVma405/www/images/logo.png new file mode 100644 index 0000000..85d0834 Binary files /dev/null and b/serveurNfcNodeJsVma405/www/images/logo.png differ diff --git a/serveurNfcNodeJsVma405/www/index.html b/serveurNfcNodeJsVma405/www/index.html index 7c68147..6d12c1f 100755 --- a/serveurNfcNodeJsVma405/www/index.html +++ b/serveurNfcNodeJsVma405/www/index.html @@ -10,7 +10,7 @@