There's no reason to write a script for this, you can do it through python. In any case, you can't set the SUID bit for scripts on Linux.
The simplest way would be for you to run the shutdown command from within your python script and then give the webserver's user the right to run it.
Give the user your webserver runs as the right to execute
visudo and add this line to the file:
I am assuming your server runs as user
www-data, if not, change appropriately.
Write a little script that runs the shutdown command and save it in one of your
os.system("sudo shutdown -h now");
Make the script executable with
sudo chmod 755 /var/www/yourpage/cgi-bin/shutdown.py
Make a webpage that gives you a button that will run that script:
<FORM method="post" action="cgi-bin/shutdown.py">
<INPUT TYPE="submit" VALUE="Submit" NAME="Submit">
That's it, you now have a button that will shutdown your server.
A note on security
I have no idea why you would want to set up a web interface for this. This is, obviously, very unsafe. Anyone who has access to that page will be able to shutdown the computer. However, there's no way around that, whatever you do, you are going to have a webpage that can shutdown your machine which means that anyone who can see the page can do so. So, be careful.
A much better alternative would be to run something like this from another machine:
ssh root@server shutdown -h now
That's a single command and, assuming you are on a Linux system, you can even create a one-word alias for it. If you're using bash, just add this line to your
alias shtdn='ssh root@server shutdown -h now'
That way, all you need to do is run
shtdn and you can safely and securely shut down the remote machine.
If you really insist on being able to do this via a web interface, I suggest you try something like webmin. It is a full featured, web-based server administration suite. It is free and open source, very easy to install and offers an intuitive GUI for many different aspects of your computer. You can use it to configure SAMBA shares, webservers, databases etc. You can also use it to shut down your system.
On Debian-based systems, you can install it by simply running
sudo apt-get install webmin
Once you have done so, go to
http://localhost:10000 and log in as root. You may have to first activate the root account by running
sudo passwd. Then, go to System -> Bootup and Shutdown, scroll to the end of the page and click on the "Shutdown" button:
This is very easy to set up and is likely to be more secure than any ad hoc solution you implement.