Reputation: 1
I'm trying to learn how to change some debian system settings using html and php. I have a few bash scripts that do things for me and I want to do them through a web app.
Right now I'm trying to figure out how to change the SSID name in a file called /etc/hostapd/hostapd.conf.
Change SSID Name: _____Enter New SSID_____ [Button]
Once someone typed in the new SSID name and hit the button then I would have php exec a bash script or just a SED command to replace the text in the /etc/hostapd/hostapd.conf and then display if it was successful or not. I'm assuming I would use functions and if/then/else. I've made some decent bash scripts to automate certain things and want to dive into web. I know and understand HTML really well, and PHP doesn't seem too hard to figure out.
How can I accomplish something like this?
I've tried making a button without user input, but can't get that to work so haven't tried a text box yet. Assuming permissions and found something about adding Nginx or www-data to sudo.
<?php if (isset($_POST['button'])) { exec('echo Hello World'); } ?>
<form action="" method="post">
<button type="submit" name="button">Run</button>
</form>
(I modified this code from another post I found, but isn't displaying Hello World on the page.)
Upvotes: 0
Views: 4171
Reputation: 73
if you run the echo as user www-data than where will the echo show up?
echo it into a file that you can use
if (isset($_POST['button']))
{
shell_exec("echo $_POST['button'] > /tmp/ssid");
}
than use a shell script to do what you want with the ssid.
Upvotes: 0
Reputation: 1
I found this code somewhere else that works out for the button. Now how can I use an input text box and pass that variable to SED command in linux?
<?php
echo
"<form action='' method='post'>
<input type='submit' name='use_button' value='something' />
</form>";
if(isset($_POST['use_button']))
{
echo "hey";
}
?>
Upvotes: 0
Reputation: 1
maybe authority is limited,try { exec('sudo echo Hello World'); }
echo exec('whoami');
whether it can workmybe you just need to show the result
{ echo exec('sudo echo Hello World'); }
Upvotes: 0
Reputation: 3246
As in your code, you have just called exec()
method and passed a bash command, the output is returned to the function and not echo-ed or printed. You need to echo out the returned string or anything like:
<?php
echo exec("echo \"Hello World\");
?>
Reference here - http://php.net/manual/en/function.exec.php
Upvotes: 1