Add blink command

This commit is contained in:
ABelliqueux 2022-10-25 12:53:05 +02:00
parent 4131ddfb73
commit 1da4beb6ab
7 changed files with 43 additions and 39 deletions

34
app.py
View File

@ -25,7 +25,7 @@ hosts_available, hosts_unavailable = [],[]
# Map vlc cmds # Map vlc cmds
# See https://github.com/videolan/vlc/blob/1336447566c0190c42a1926464fa1ad2e59adc4f/share/lua/http/requests/README.txt # See https://github.com/videolan/vlc/blob/1336447566c0190c42a1926464fa1ad2e59adc4f/share/lua/http/requests/README.txt
cmd = { cmd_player = {
"play" : "pl_play", "play" : "pl_play",
"resume" : "pl_forceresume", "resume" : "pl_forceresume",
"pause" : "pl_forcepause", "pause" : "pl_forcepause",
@ -53,13 +53,15 @@ cmd = {
#"key" : "key=", #"key" : "key=",
#"browse" : "browse.xml?uri=file://~" #"browse" : "browse.xml?uri=file://~"
# System commands : # System commands :
"rssi" : "rssi", # ~ "rssi" : "rssi",
"blink" : "blink", # ~ "blink" : "blink",
"poweroff" : "poweroff", # ~ "poweroff" : "poweroff",
"reboot" : "reboot", # ~ "reboot" : "reboot",
} }
cmd_server = ["blink", "reboot", "poweroff", "rssi"]
# Set configuration # Set configuration
DEBUG = app.config['DEFAULT']['DEBUG'] DEBUG = app.config['DEFAULT']['DEBUG']
@ -137,8 +139,10 @@ def httpUpload(filename, hostl, trailing_slash=1):
if not trailing_slash: if not trailing_slash:
filename = "/" + filename filename = "/" + filename
files = { "file":( filename, open( media_folder_local + filename, "rb"), "multipart/form-data") } files = { "file":( filename, open( media_folder_local + filename, "rb"), "multipart/form-data") }
if DEBUG:
print(files) print(files)
resp = requests.post(url, files=files, headers=headers, verify=CAfile) resp = requests.post(url, files=files, headers=headers, verify=CAfile)
if DEBUG:
print(resp.text) print(resp.text)
if resp.ok: if resp.ok:
return 1 return 1
@ -209,17 +213,11 @@ def sendCommand(host, arg0, arg1, arg2):
req = "/requests/status.xml" req = "/requests/status.xml"
if arg0 == "list" : if arg0 == "list" :
req = "/requests/playlist.xml" req = "/requests/playlist.xml"
elif arg0 == "rssi": elif arg0 in cmd_server:
req = "/rssi" req = "/" + str(arg0)
portl = cmd_port
elif arg0 == "reboot":
req = "/reboot"
portl = cmd_port
elif arg0 == "poweroff":
req = "/poweroff"
portl = cmd_port portl = cmd_port
elif arg0 != "status" : elif arg0 != "status" :
req = req + "?command=" + cmd[arg0] req = req + "?command=" + cmd_player[arg0]
if arg1 != "null" : if arg1 != "null" :
if (arg0 == "play") or (arg0 == "delete") or (arg0 == "sort") or (arg0 == "move"): if (arg0 == "play") or (arg0 == "delete") or (arg0 == "sort") or (arg0 == "move"):
req = req + "&id=" + arg1 req = req + "&id=" + arg1
@ -245,6 +243,7 @@ def sendCommand(host, arg0, arg1, arg2):
try: try:
conn.request( "GET", req, headers = headers ) conn.request( "GET", req, headers = headers )
resp = conn.getresponse() resp = conn.getresponse()
data = resp.read()
except http.client.HTTPException: except http.client.HTTPException:
print("Connection to " + host + " timed out") print("Connection to " + host + " timed out")
return "Connection to " + host + " timed out" return "Connection to " + host + " timed out"
@ -253,7 +252,7 @@ def sendCommand(host, arg0, arg1, arg2):
finally: finally:
conn.close() conn.close()
# Parse response # Parse response
data = resp.read() # ~ data = resp.read()
if arg0 == "rssi": if arg0 == "rssi":
if DEBUG: if DEBUG:
@ -366,7 +365,7 @@ def sync(host):
@app.route("/<host>/<arg0>/<arg1>/<arg2>") @app.route("/<host>/<arg0>/<arg1>/<arg2>")
def action(host, arg0, arg1, arg2): def action(host, arg0, arg1, arg2):
status_message = "Idle" status_message = "Idle"
if arg0 not in cmd: if (arg0 not in cmd_player) and (arg0 not in cmd_server):
status_message = "<p>Wrong command</p>" status_message = "<p>Wrong command</p>"
elif host == "all": elif host == "all":
resp = [] resp = []
@ -383,5 +382,4 @@ def action(host, arg0, arg1, arg2):
if __name__ == '__main__': if __name__ == '__main__':
# ~ app.run() # ~ app.run()
#serve(app, host='127.0.0.1', port=8080) serve(app, host='127.0.0.1', port=8080)
serve(app, host='0.0.0.0', port=8080)

View File

@ -29,8 +29,8 @@ sha256 : 0fe3fe76d0e56e445124fa20646fa8b3d8c59568786b3ebc8a96d83d92f203e3
* Webgui beautifying * Webgui beautifying
## 0.4 : 2022-10-21-videopi.img.xz ## 0.4 : 2022-10-21-videopi.img.xz
md5 : 2a54eb1763060db652c4c5d89c07ef2a md5 : dee7af70135994169cab4f073ee51905
sha256 : 10b65d5260222e4cdc591ad5384247cbc22d515dc55ea6b31b2daf0b6fd01004 sha256 : ec3e17fc9b41f8c5181484e9866be2d1d92cab8403210e3d22f4f689edd4cfde
* Switch to rpi os Bullseye * Switch to rpi os Bullseye
* Switch to user 'pil', pw 'pilpoil' * Switch to user 'pil', pw 'pilpoil'
@ -53,6 +53,7 @@ sha256 : 10b65d5260222e4cdc591ad5384247cbc22d515dc55ea6b31b2daf0b6fd01004
# DOING NEXT : # DOING NEXT :
* ~ Test with several rpis * ~ Test with several rpis
* Define http auth secret at setup * Define http auth secret at setup
* Increase live host scan when host first found
# DONE : # DONE :

View File

@ -151,7 +151,7 @@ do
# Change hostname # Change hostname
echo "$HOST_NAME" | sudo tee "$ROOTFS_MOUNT/etc/hostname" echo "$HOST_NAME" | sudo tee "$ROOTFS_MOUNT/etc/hostname"
# Reflect that in /etc/hosts # Reflect that in /etc/hosts
sed -i "$ d" "$ROOTFS_MOUNT/etc/hosts" sudo sed -i "$ d" "$ROOTFS_MOUNT/etc/hosts"
echo -e "127.0.1.1\t$HOST_NAME" | sudo tee -a "$ROOTFS_MOUNT/etc/hosts" echo -e "127.0.1.1\t$HOST_NAME" | sudo tee -a "$ROOTFS_MOUNT/etc/hosts"
## Enable SSH ## Enable SSH
green "Operation 5/13 : Enabling SSH server on boot ...\n" green "Operation 5/13 : Enabling SSH server on boot ...\n"
@ -165,7 +165,7 @@ do
if [ "$ADD_SSH_CONF" == "y" ] if [ "$ADD_SSH_CONF" == "y" ]
then then
# Add to ~/.ssh/config # Add to ~/.ssh/config
echo -e "Host $HOST_NAME\n\tHostName $HOST\n\tIdentityFile ~/.ssh/$HOST_NAME\n\tUser $PI_USER" | tee -a "$HOME/.ssh/config" echo -e "\nHost $HOST_NAME\n\tHostname $HOST\n\tIdentityFile ~/.ssh/$HOST_NAME\n\tUser $PI_USER" | tee -a "$HOME/.ssh/config"
fi fi
# Copy public key to rpi # Copy public key to rpi
green "Operation 7/13 : Installing public SSH key $HOME/.ssh/$HOST.pub in $ROOTFS_MOUNT/home/$PI_USER/.ssh/authorized_keys...\n" green "Operation 7/13 : Installing public SSH key $HOME/.ssh/$HOST.pub in $ROOTFS_MOUNT/home/$PI_USER/.ssh/authorized_keys...\n"
@ -229,7 +229,7 @@ network={
umount $BOOT_MOUNT umount $BOOT_MOUNT
umount $ROOTFS_MOUNT umount $ROOTFS_MOUNT
yellow "Client $(($IP-9))/$CLIENT_NUMBER done." yellow "Client $(($IP-9))/$CLIENT_NUMBER done."
if [ $(($IP+1)) -lt $(($CLIENT_NUMBER+$IP)) ] if [ $IP -le $IP_CNT ]
then then
red "Please swap sd card in reader and enter uppercase 'yes' to proceed with next client :" red "Please swap sd card in reader and enter uppercase 'yes' to proceed with next client :"
read -n 4 GO_ON read -n 4 GO_ON

View File

@ -10,7 +10,7 @@ media_exts = ["mp4", "avi", "mkv"]
auth = "secret" auth = "secret"
# OnNlY3JldA== # OnNlY3JldA==
cmd_auth = "secret" cmd_auth = "secret"
hosts = ["10.42.0.135", "10.42.0.11"] hosts = ["10.42.0.10", "10.42.0.11"]
# VLC http LUA port # VLC http LUA port
port = 8887 port = 8887
# Clients cmd port # Clients cmd port

View File

@ -156,6 +156,16 @@ Host 10.42.0.135
``` ```
## Sudoers : commandes systèmes sans mot de passe
`/etc/sudoers.d/010_pilpil_nopasswd.conf` :
```
Cmnd_Alias PILPIL=/usr/sbin/reboot, /usr/sbin/poweroff, /usr/bin/tee
pil ALL=(ALL) NOPASSWD: PILPIL
```
## Systemd Unit : démarrage automatique des services ## Systemd Unit : démarrage automatique des services
## VLC ## VLC

View File

@ -202,7 +202,7 @@ function parseResult(command, infos_array) {
document.getElementById("playlist_"+infos_array[i].host).innerHTML = infos_array[i].leng + " item(s) in playlist - " + infos_array[i].duration; document.getElementById("playlist_"+infos_array[i].host).innerHTML = infos_array[i].leng + " item(s) in playlist - " + infos_array[i].duration;
// Build html table and timeline // Build html table and timeline
var items_array = Array.from(infos_array[i].items); var items_array = Array.from(infos_array[i].items);
console.log(items_array.length); //console.log(items_array.length);
if (items_array.length == 0){ if (items_array.length == 0){
var child_list = Array.from(document.getElementById("timeline").children); var child_list = Array.from(document.getElementById("timeline").children);
for(i=0,l=child_list.length;i<l;i++){ for(i=0,l=child_list.length;i<l;i++){
@ -259,10 +259,10 @@ function parseResult(command, infos_array) {
for ( var i=0, l=host_down.length; i<l; i++){ for ( var i=0, l=host_down.length; i<l; i++){
document.getElementById(host_down[i]).style.display = 'none'; document.getElementById(host_down[i]).style.display = 'none';
} }
//~ if (host_up.length) { if (host_up.length) {
//~ scanInterval = 10000; scanInterval = 10000;
//~ document.getElementById("status_all").innerHTML = "Scan intarvel set to " + scanInterval; document.getElementById("status_all").innerHTML = "Scan intarvel set to " + scanInterval;
//~ } }
document.getElementById("status_all").innerHTML = host_up.length + " client(s) found."; document.getElementById("status_all").innerHTML = host_up.length + " client(s) found.";
break; break;
case "/browse": case "/browse":
@ -322,11 +322,5 @@ function sendCmd(command) {
setInterval( sendCmd, 500, "/all/status"); setInterval( sendCmd, 500, "/all/status");
setInterval( sendCmd, 1000, "/all/list"); setInterval( sendCmd, 1000, "/all/list");
setInterval( sendCmd, scanInterval, "/scan"); setInterval( sendCmd, scanInterval, "/scan");
setInterval( sendCmd, 10000, "/all/rssi"); setInterval( sendCmd, 20000, "/all/rssi");
/* TODO :
* Change scanInterval after first results are in (3 to 30 seconds)
*
*/

View File

@ -31,7 +31,7 @@
<button value="/all/enqueue/tst.mp4" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">tst.mp4</span></button> <button value="/all/enqueue/tst.mp4" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">tst.mp4</span></button>
<button value="/all/enqueue/tst1.mp4" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">tst1.mp4</span></button> <button value="/all/enqueue/tst1.mp4" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">tst1.mp4</span></button>
<button value="/all/enqueue/sangliers_1080.mp4" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">sangli.mp4</span></button> <button value="/all/enqueue/sangliers_1080.mp4" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">sangli.mp4</span></button>
<button value="/move/0/1" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">movePl</span></button> <button value="/all/move/0/1" class="command btn btn-block btn-lg btn-default" role="button">&#x3b2;<span class="btn_txt">movePl</span></button>
<button value="/sync/all" class="command btn btn-block btn-lg btn-default" role="button">&#x21ad;<span class="btn_txt">Sync</span></button> <button value="/sync/all" class="command btn btn-block btn-lg btn-default" role="button">&#x21ad;<span class="btn_txt">Sync</span></button>
</p> </p>
</div> </div>
@ -43,6 +43,7 @@
<div class="col_1"> <div class="col_1">
<button value="/{{host}}/poweroff" class="command btn btn-block btn-lg btn-default" role="button">&#x23fb;<span class="btn_txt">&Eacute;teindre</span></button> <button value="/{{host}}/poweroff" class="command btn btn-block btn-lg btn-default" role="button">&#x23fb;<span class="btn_txt">&Eacute;teindre</span></button>
<button value="/{{host}}/reboot" class="command btn btn-block btn-lg btn-default" role="button">&#x21BA;<span class="btn_txt">Red&eacute;marrer</span></button> <button value="/{{host}}/reboot" class="command btn btn-block btn-lg btn-default" role="button">&#x21BA;<span class="btn_txt">Red&eacute;marrer</span></button>
<button value="/{{host}}/blink" class="command btn btn-block btn-lg btn-default" role="button">&#x1F4A1;<span class="btn_txt">Blink</span></button>
<p id="status_{{ host }}">{{status_message}}</p> <p id="status_{{ host }}">{{status_message}}</p>
<p id="signal_{{ host }}"> <p id="signal_{{ host }}">
<span style="">Link:</span> <span style="">Link:</span>