# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
# zf200101.1304

Todo à faire pour ce projet !

-
- ajouter fonction restart dans zindex.html (argument restart)
- ajouter argument ok dans wifi_init.html
- ajouter get_data() dans 0_send_data.lua
- cron 10 seconde get_data avec moyenne et cron 300 sendata et zero moyenne
- if verbose print partout dans 0_send_data.lua
- garder variable node_id pour identification après poweron général, reattribution adrs ip sur modem 4G
- indiquer nodeMCU name du dhcp modem 4G dans table liste adresses ip
- passer à 10 secondes la seconde chance
- passer à 15x les tentatives de connexions au WIFI
- déplacer le mode AP dans wifi_init
- ajouter le web_srv2 dans boot au lieu de boot2










# si luatool ne marche pas sur le MAC, il faut lire ceci:
# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0

# raccourcis clavier
# CTRL+ALT+ENTER envoie au terminal la ligne de l'éditeur
# SHIT+CTRL+` ouvre le terminal (attention, ne pas oublier de copier le *path* dans le *tree* et le changer)
# ALT+CMD+F bascule entre le terminal et l'éditeur

# définitions à faire AVANT !
cd /Users/zuzu/Desktop/NodeMCU/NodeMCU_Lua/WIFI_sniffer/cret_project
export luatool_tty="/dev/cu.wchusbserial1410"
export zIP="192.168.0.113"

#th0 dev mobile
192.168.0.118
#th1
192.168.0.143   192.168.8.102
#th2
192.168.0.132   192.168.8.105
#th3
192.168.0.145   192.168.8.104
#th4
192.168.0.117   192.168.8.103
#th5 chambre à coucher
192.168.0.178
#th6 buanderie
192.168.0.162
#th7 cave
192.168.0.199
#th8 salon
192.168.0.124



export zIP="192.168.0.143"
export zport="23"

cd '/Users/zuzu/Google Drive/FamilleZ Share/FamilleZ/Papa/LUA/NodeMCU ESP8266/NodeMCU_Lua/Mesures/humidity/bolo
'
export zIP="localhost"
export zport="2323"
ATTENTION: voir les tunnels tout à la fin !


# ouvrir et fermer (ALT+N+.) une session telnet sur le NodeMCU avec l'adresse zIP)
telnet -rN $zIP $zport
~.
--node.restart()
collectgarbage()
=node.heap()
for k,v in pairs(_G) do print(k,v) end


# commandes lua pour ce projet
export zIP="192.168.0.162"
telnet -rN $zIP $zport
verbose=false
dofile("dir.lua")
dir()
#filec('dir2.lua')
#dirc()
~.
./luatool.py --ip $zIP:$zport -f dir.lua



verbose=true
verbose=false
zsort_rssi()   zshow()


#commandes luatool pour ce projet le .137 est à jour avec la nouvelle version du wifi !
~.
./luatool.py --ip $zIP:$zport -l
./luatool.py --ip $zIP:$zport -f wifi_init.lua


./luatool.py --ip $zIP:$zport -f secrets_wifi.lua
./luatool.py --ip $zIP:$zport -f initz.lua -t init.lua
./luatool.py --ip $zIP:$zport -f boot.lua
./luatool.py --ip $zIP:$zport -f boot2.lua
./luatool.py --ip $zIP:$zport -f wifi_init.lua
./luatool.py --ip $zIP:$zport -f set_time.lua
./luatool.py --ip $zIP:$zport -f wifi_info.lua
./luatool.py --ip $zIP:$zport -f c.lua
./luatool.py --ip $zIP:$zport -f cat.lua
./luatool.py --ip $zIP:$zport -f flash_led_xfois.lua
./luatool.py --ip $zIP:$zport -f head.lua

./luatool.py --ip $zIP:$zport -f b.lua
./luatool.py --ip $zIP:$zport -f web_srv2.lua
./luatool.py --ip $zIP:$zport -f z_index.html


./luatool.py --ip $zIP:$zport -f wifi_get_conf.html
./luatool.py --ip $zIP:$zport -f wifi_set_conf.html


./luatool.py --ip $zIP:$zport -f z_page1.html
./luatool.py --ip $zIP:$zport -f z_page2.html
./luatool.py --ip $zIP:$zport -f z_page3.html
./luatool.py --ip $zIP:$zport -f z_page4.html

./luatool.py --ip $zIP:$zport --delete wifi_ap_start.lua
./luatool.py --ip $zIP:$zport --delete wifi_cli_conf.lua
./luatool.py --ip $zIP:$zport --delete wifi_cli_start.lua
./luatool.py --ip $zIP:$zport --delete dir.lua
./luatool.py --ip $zIP:$zport --delete initz.lua
./luatool.py --ip $zIP:$zport --delete wifi_conf.lua



dofile("wifi_info.lua")
--node.restart()
for k,v in pairs(_G) do print(k,v) end
t=12
t=nil
print(pcall(function () print("2"..t) end))



# ici c'est maintenant ;-)
~.
./luatool.py --ip $zIP:$zport -f b.lua
#./luatool.py --ip $zIP:$zport --zrestart
telnet -rN $zIP $zport
zsort_rssi()   zshow()
print(ztrig_rssi)
ztrig_rssi=-1000
ztrig_rssi=-90



# test de la gestion des erreurs
~.
./luatool.py --ip $zIP:$zport -f c.lua
#./luatool.py --ip $zIP:$zport --zrestart
telnet -rN $zIP $zport
status, err = pcall(function () dofile("c.lua") end)   if status==false then print("Error: ",err) end
zerr=nil
zerr=1
ztmr_tst_err:unregister()



~.
./luatool.py --ip $zIP:$zport -f head.lua
telnet -rN $zIP $zport
dofile("head.lua")
zhead("c.lua")

ztmr_tst_err:unregister()
for k,v in pairs(_G) do print(k,v) end

./luatool.py --ip $zIP --zrestart


# faire un cat d'un fichier sur le NodeMCU
dofile("cat.lua")
cat("boot2.lua")


# commandes luatool
./luatool.py -h
./luatool.py --ip $zIP:$zport -i
./luatool.py --ip $zIP:$zport -l
./luatool.py --ip $zIP:$zport -f toto.lua -d
./luatool.py --ip $zIP:$zport --delete toto.lua



****************************************************************************


# création des tunnels ssh
ATTENTION: dans un premier terminal !
Pour Bolo à Ruchonnet:
ssh -t -L 2323:localhost:2323 ubuntu@www.zuzutest.ml ssh -N -L 2323:192.168.8.102:23 ubuntu@localhost -p 20223

Pour le Crêt
ssh -N -L 2323:192.168.0.137:23 admin@z.zufferey.com -p 1822
ssh -N -L 2323:192.168.0.122:23 admin@z.zufferey.com -p 1822
ssh -N -L 2323:192.168.0.118:23 admin@z.zufferey.com -p 1822

ATTENTION: dans un deuxième terminal !
export zIP="localhost"
export zport="2323"
telnet -rN $zIP $zport
~.
=node.heap()

verbose=false
verbose=true

dofile("dir2.lua")
dir()
filec("head.lua")

dofile("head.lua")
zhead("dir2.lua")

dofile("cat.lua")
cat("head.lua")

~.
--node.restart()
=node.heap()


status, err = pcall(function () fonction_a_tester() end)  if status==false then print("Error: ",err) end
status, err = pcall(function () toto() end)  if status==false then print("Error: ",err) end



Gestion de la passerelle SSH reverse
Puis depuis une autre console on peut faire directement pour aller sur l'OpiZ (ici le 20223):
ssh -t ubuntu@www.zuzutest.ml ssh ubuntu@localhost -p 20223

ou

1ère console
On établit le tunnel local avec l'OpiZ
ssh -N -L 20223:localhost:20223 ubuntu@www.zuzutest.ml


2ème console, on utilise le tunnel OpiZ en local sur sa machine
pour aller sur l'OpiZ
ssh ubuntu@localhost -p 20223

pour copier sa clef SSH depuis un MAC
./ssh-copy-id -i ~/.ssh/id_rsa.pub 'ubuntu@localhost -p 20223'
après on devrait pouvoir se connecter sans devoir entrer son password à chaque fois
ssh ubuntu@localhost -p 20223

ou, on établit un tunnel pour telnet sur un NodeMCU
ssh -L 2323:192.168.0.137:23 ubuntu@localhost -p 20223
puis
telnet -rN localhost 2323

ou, on établit un tunnel pour le rpimonotor sur l'OpiZ
ssh -N -L 8888:192.168.0.113:8888 ubuntu@localhost -p 20223
puis
http://localhost:8888

ou, on établit un tunnel proxy Socket 5 pour le modem 4G HUAWEI sur l'OpiZ
ssh -N -D 8080 ubuntu@localhost -p 20223
puis depuis le browser FireFox avec le plugin FoxyProxy Socket 5 sur localhost port 8080
http://192.168.8.1



.
