I have a Linux proxy server (RaspberryPi-3) running on squid. I want to start the squid service using an HTML button on its webpage. With this button, I'm trying to execute a python program to start the squid service:
#!/usr/bin/env python
import os
os.system ("sudo service squid restart")
But from the web page, it is not working.
What are the other options to get my squid turned on from the browser?
You added the PHP tag so i assume that you are using in fact PHP as your web scripting language.
First you need enable the www-data
user to run the command without sudo
.
sudo visudo # you edit the /etc/sudoers with this program
Add the following line to the file, then save.
www-data ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart squid
When the correct permission are set than this should fairly simple on the PHP side:
<?php
shell_exec ("service squid restart")
reference for shell_exec: https://www.php.net/manual/en/function.shell-exec.php