Executing commands by visiting a web page?

I am running an Ubuntu server, I have two game servers that require semi-regular updates.

They run under an account with an account named "gs" on the screens.

I have a "runupdate.sh" script that contains the following line:

/var/gs/steamcmd/one.sh;/var/gs/steamcmd/two.sh; (one line because CR / LF windows threw errors)

one.sh/two.sh - very similar scripts, the contents of one.sh:

screen -r tf2_1 -X quit;
/var/gs/steamcmd/steamcmd.sh +runscript /var/gs/steamcmd/update_tf2_1.txt;
screen -d -m -S tf2_1 /var/gs/tf2/1/srcds_run -game tf -port 27015 +sv_pure 2 +map cp_badlands +maxplayers 24;

these scripts work fine when run as a gs user.

for access purposes, I would like the game servers to always start up on the screens assigned to the gs account.

currently I would like to run a php script when I am on the web page www.mysite.com/admin/restartservers12345, which will execute the "runupdate.sh" script and let the server restart while updating them, my file updateservers12345.html currently looks like this:

<!DOCTYPE html>

<?php
echo exec('/var/gs/runupdate.sh')
?>

<html>
<style>
p {
    text-align: center;
    color:white;
    font: bold 60px arial, sans-serif;
}
</style>
<body style="background-color: rgb(60,60,60)">

<p>Server Updating...</p>

</body>
</html>

the problem is that this script seems to be running as "www-data" or otherwise the default for the Apache account, which means that it cannot access the game server screens running on "gs".

currently I would like to have a window on the screen in shich people should enter the password for the gs account and then press enter, after which the script as

exec(echo $textboxpassword | su -s - gs -c '/var/gs/runupdate.sh')

will be launched by effectively executing the script as the "gs" account.

ssh su: must be run from a terminal, , - php- .

. .

+4
1

"sudo" "su"

www-data sudoers, '/var/gs/runupdate.sh' www- sudoer.

/etc/sudoers.d/www-data​​p >

www-data ALL=(ALL) NOPASSWD:  /var/gs/runupdate.sh

1:

sudo -u gs bash -c '/var/gs/runupdate.sh'

runupdate.sh gs

, /etc/sudoers.d/www-data​​p >

www-data ALL=(gs) NOPASSWD:  /var/gs/runupdate.sh
+2

All Articles