Bitcoin Forum
December 08, 2016, 12:22:31 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: PHP Panic button  (Read 1802 times)
BCEmporium
Legendary
*
Offline Offline

Activity: 938



View Profile
June 24, 2011, 01:41:49 AM
 #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:
<?php
$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:
<?php
  
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).
1481199751
Hero Member
*
Offline Offline

Posts: 1481199751

View Profile Personal Message (Offline)

Ignore
1481199751
Reply with quote  #2

1481199751
Report to moderator
1481199751
Hero Member
*
Offline Offline

Posts: 1481199751

View Profile Personal Message (Offline)

Ignore
1481199751
Reply with quote  #2

1481199751
Report to moderator
1481199751
Hero Member
*
Offline Offline

Posts: 1481199751

View Profile Personal Message (Offline)

Ignore
1481199751
Reply with quote  #2

1481199751
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481199751
Hero Member
*
Offline Offline

Posts: 1481199751

View Profile Personal Message (Offline)

Ignore
1481199751
Reply with quote  #2

1481199751
Report to moderator
1481199751
Hero Member
*
Offline Offline

Posts: 1481199751

View Profile Personal Message (Offline)

Ignore
1481199751
Reply with quote  #2

1481199751
Report to moderator
1481199751
Hero Member
*
Offline Offline

Posts: 1481199751

View Profile Personal Message (Offline)

Ignore
1481199751
Reply with quote  #2

1481199751
Report to moderator
fabianhjr
Sr. Member
****
Offline Offline

Activity: 322


Do The Evolution


View Profile
June 24, 2011, 02:09:38 AM
 #2

Now, a question, doesn't the header redirect actually executes the rest of the code? Wouldn't a die() function be more appropriate?

BCEmporium
Legendary
*
Offline Offline

Activity: 938



View Profile
June 24, 2011, 09: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.
fabianhjr
Sr. Member
****
Offline Offline

Activity: 322


Do The Evolution


View Profile
June 24, 2011, 11:26:25 AM
 #4

Oh ok, really cool then. Smiley

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!