Author

Topic: PHP Panic button (Read 1992 times)

sr. member
Activity: 322
Merit: 250
Do The Evolution
June 24, 2011, 06:26:25 AM
#4
Oh ok, really cool then. Smiley
legendary
Activity: 1218
Merit: 1000
June 24, 2011, 04:41:38 AM
#3
From PHP manual:

Quote
die — Equivalent to exit()
Description

This language construct is equivalent to exit().

Choose what alias you want to use... the header redirect with the exit() bellow terminates the code execution and redirects the visitor to that page.
sr. member
Activity: 322
Merit: 250
Do The Evolution
June 23, 2011, 09:09:38 PM
#2
Now, a question, doesn't the header redirect actually executes the rest of the code? Wouldn't a die() function be more appropriate?
legendary
Activity: 1218
Merit: 1000
June 23, 2011, 08:41:49 PM
#1
Following the events at MtGox I was thinking if it wasn't a good idea to create a Panic Button in the admin area so the site can be shutdown methodically and checked for leaks afterwards.

For this I would start by creating a table, let's say "system" (name it whatever you want), with 2 fields: key - varchar(8) Primary key / value - tinyint(1) default 0
Add to that table 'halt',0

Create a static html page to tell your visitors your site is halted, like system_halted.html

Right after your mysql_select_db perform the following check:

Code:
$q mysql_query("SELECT `value` FROM `system` WHERE `key` = 'halt'");
$r mysql_fetch_assoc($q);
if(
$r['value'] == 1){
    
header("Location: system_halted.html");
    exit();
}
?>


In the event of danger then call this function (adjust it accordingly to your system configuration):

Code:
  function panic_button(){
      
//Uncomment the line bellow if you use monit to check for bitcoind
      //exec("/etc/init.d/monit stop &");
      //Stop bitcoind
      
exec("/path/to/bitcoind/bitcoind stop &");
      
//You can add here some commands you may wish to perform along
      //exec("mv ~/.bitcoin/wallet.dat /some/other/place/");
      
mysql_query("UPDATE `system` SET `value` = 1 WHERE `key` = 'halt'");
  }
?>


Note, this is just a rough sketch, the user httpd under which php runs probably have no permissions to stop services or move wallets, so you probably would need to call another script able to sudo, and the bitcoind stop could be performed using a post request from the localhost.
The whole idea is to develop a system halt that can be easily triggered and perform all halt functions at once, starting by saving the coins (mysql junk you can undo after, bitcoin transactions once in the blockchain no).
Jump to: