Indicator of a running macproxy daemon in the webapp (#436)

* Support for downloading properties files

* Show extra message when unzipping properties file

* Add logic to unzip method

* Move unzipped properties into CFG_DIR

* Better status message

* Cleanup

* Generic process introspection method

* Show macproxy status in the webapp
This commit is contained in:
Daniel Markstedt 2021-11-08 19:11:27 -08:00 committed by GitHub
parent 08e7531bb6
commit c8b6ac409b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 7 deletions

View File

@ -51,15 +51,16 @@ def running_env():
return {"git": ra_git_version, "env": pi_version} return {"git": ra_git_version, "env": pi_version}
def running_netatalk(): def running_proc(daemon):
""" """
Returns (int) afpd, which is the number of afpd processes currently running Takes (str) daemon
Returns (int) proc, which is the number of processes currently running
""" """
process = subprocess.run(["ps", "aux"], capture_output=True) process = subprocess.run(["ps", "aux"], capture_output=True)
output = process.stdout.decode("utf-8") output = process.stdout.decode("utf-8")
from re import findall from re import findall
afpd = findall("afpd", output) proc = findall(daemon, output)
return len(afpd) return len(proc)
def is_bridge_setup(): def is_bridge_setup():
@ -82,6 +83,24 @@ def disk_space():
total, used, free = disk_usage(__file__) total, used, free = disk_usage(__file__)
return {"total": total, "used": used, "free": free} return {"total": total, "used": used, "free": free}
def get_ip_address():
"""
Use a mock socket connection to identify the Pi's IP address
"""
from socket import socket, AF_INET, SOCK_DGRAM
sock = socket(AF_INET, SOCK_DGRAM)
try:
# mock ip address; doesn't have to be reachable
sock.connect(('10.255.255.255', 1))
ip_addr = sock.getsockname()[0]
except Exception:
ip_addr = '127.0.0.1'
finally:
sock.close()
return ip_addr
def introspect_file(file_path, re_term): def introspect_file(file_path, re_term):
""" """
Takes a (str) file_path and (str) re_term in regex format Takes a (str) file_path and (str) re_term in regex format
@ -96,4 +115,4 @@ def introspect_file(file_path, re_term):
for line in ifile: for line in ifile:
if match(re_term, line): if match(re_term, line):
return True return True
return False return False

View File

@ -317,6 +317,11 @@
</td> </td>
</tr> </tr>
</table> </table>
{% if macproxy_configured %}
<p><small>macproxy is running at {{ ip_addr }} port 5000</small></p>
{% else %}
<p><small>Install <a href="https://github.com/akuker/RASCSI/wiki/Vintage-Web-Proxy#macproxy">macproxy</a> to browse the Web with your vintage browser.</small></p>
{% endif %}
<hr/> <hr/>
<details> <details>

View File

@ -36,9 +36,10 @@ from pi_cmds import (
reboot_pi, reboot_pi,
running_env, running_env,
systemd_service, systemd_service,
running_netatalk, running_proc,
is_bridge_setup, is_bridge_setup,
disk_space, disk_space,
get_ip_address,
introspect_file, introspect_file,
) )
from ractl_cmds import ( from ractl_cmds import (
@ -112,7 +113,9 @@ def index():
return render_template( return render_template(
"index.html", "index.html",
bridge_configured=is_bridge_setup(), bridge_configured=is_bridge_setup(),
netatalk_configured=running_netatalk(), netatalk_configured=running_proc("afpd"),
macproxy_configured=running_proc("macproxy"),
ip_addr=get_ip_address(),
devices=formatted_devices, devices=formatted_devices,
files=sorted_image_files, files=sorted_image_files,
config_files=sorted_config_files, config_files=sorted_config_files,