Bitcoin Forum
April 25, 2024, 06:25:04 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: PHP Panic button  (Read 1966 times)
BCEmporium (OP)
Legendary
*
Offline Offline

Activity: 1218
Merit: 1000



View Profile
June 24, 2011, 01:41:49 AM
Last edit: June 24, 2011, 01:55:27 AM by BCEmporium
 #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).

██████████████████            ██████████
████████████████              ██████████
██████████████          ▄█   ███████████
████████████         ▄████   ███████████
██████████        ▄███████  ████████████
████████        ▄█████████  ████████████
██████        ▄███████████  ████████████
████       ▄██████████████ █████████████
██      ▄███████████████████████████████
▀        ███████████████████████████████
▄          █████████████████████████████
██▄         ▀███████████████████████████
████▄        ▀██████████████████████████
██████▄        ▀████████████████████████
████████▄        ████████████████▀ █████
██████████▄       ▀█████████████  ██████
████████████▄       ██████████   ███████
██████████████▄      ▀██████    ████████
████████████████▄▄     ███     █████████
███████████████████▄    ▀     ██████████
█████████████████████▄       ███████████
███████████████████████▄   ▄████████████





▄█████████████████   ███             ███   ███   ███▄                ▄███            █████            ████████████████   ████████████████▄             █████
███▀                 ███             ███   ███   ████▄              ▄████           ███████           ███                ███           ▀███           ███████
███                  ███             ███   ███   █████▄            ▄█████          ███▀ ▀███          ███                ███            ███          ███▀ ▀███
███                  ███             ███   ███   ███ ███▄        ▄███ ███        ▄███▀   ▀███▄        ███                ███           ▄███        ▄███▀   ▀███▄
███                  ███████████████████   ███   ███  ▀██▄      ▄██▀  ███       ▄███▀     ▀███▄       ████████████████   ████████████████▀        ▄███▀     ▀███▄
███                  ███             ███   ███   ███   ▀███    ███▀   ███      ▄███▀       ▀███▄      ███                ███        ███          ▄███▀       ▀███▄
███                  ███             ███   ███   ███    ▀███  ███▀    ███     ▄███▀         ▀███▄     ███                ███         ███        ▄███▀         ▀███▄
███▄                 ███             ███   ███   ███      ██████      ███    ▄███             ███▄    ███                ███          ███      ▄███             ███▄
▀█████████████████   ███             ███   ███   ███       ████       ███   ▄███               ███▄   ████████████████   ███           ███    ▄███               ███▄

|
  TRUE BLOCKCHAIN GAMING PLATFORM 
DECENTRALISED AUTONOMOUS UNIVERSES

  HOME PAGE                                                                  WHITE PAPER 
|
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714026304
Hero Member
*
Offline Offline

Posts: 1714026304

View Profile Personal Message (Offline)

Ignore
1714026304
Reply with quote  #2

1714026304
Report to moderator
1714026304
Hero Member
*
Offline Offline

Posts: 1714026304

View Profile Personal Message (Offline)

Ignore
1714026304
Reply with quote  #2

1714026304
Report to moderator
1714026304
Hero Member
*
Offline Offline

Posts: 1714026304

View Profile Personal Message (Offline)

Ignore
1714026304
Reply with quote  #2

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

Activity: 322
Merit: 250


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 (OP)
Legendary
*
Offline Offline

Activity: 1218
Merit: 1000



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.

██████████████████            ██████████
████████████████              ██████████
██████████████          ▄█   ███████████
████████████         ▄████   ███████████
██████████        ▄███████  ████████████
████████        ▄█████████  ████████████
██████        ▄███████████  ████████████
████       ▄██████████████ █████████████
██      ▄███████████████████████████████
▀        ███████████████████████████████
▄          █████████████████████████████
██▄         ▀███████████████████████████
████▄        ▀██████████████████████████
██████▄        ▀████████████████████████
████████▄        ████████████████▀ █████
██████████▄       ▀█████████████  ██████
████████████▄       ██████████   ███████
██████████████▄      ▀██████    ████████
████████████████▄▄     ███     █████████
███████████████████▄    ▀     ██████████
█████████████████████▄       ███████████
███████████████████████▄   ▄████████████





▄█████████████████   ███             ███   ███   ███▄                ▄███            █████            ████████████████   ████████████████▄             █████
███▀                 ███             ███   ███   ████▄              ▄████           ███████           ███                ███           ▀███           ███████
███                  ███             ███   ███   █████▄            ▄█████          ███▀ ▀███          ███                ███            ███          ███▀ ▀███
███                  ███             ███   ███   ███ ███▄        ▄███ ███        ▄███▀   ▀███▄        ███                ███           ▄███        ▄███▀   ▀███▄
███                  ███████████████████   ███   ███  ▀██▄      ▄██▀  ███       ▄███▀     ▀███▄       ████████████████   ████████████████▀        ▄███▀     ▀███▄
███                  ███             ███   ███   ███   ▀███    ███▀   ███      ▄███▀       ▀███▄      ███                ███        ███          ▄███▀       ▀███▄
███                  ███             ███   ███   ███    ▀███  ███▀    ███     ▄███▀         ▀███▄     ███                ███         ███        ▄███▀         ▀███▄
███▄                 ███             ███   ███   ███      ██████      ███    ▄███             ███▄    ███                ███          ███      ▄███             ███▄
▀█████████████████   ███             ███   ███   ███       ████       ███   ▄███               ███▄   ████████████████   ███           ███    ▄███               ███▄

|
  TRUE BLOCKCHAIN GAMING PLATFORM 
DECENTRALISED AUTONOMOUS UNIVERSES

  HOME PAGE                                                                  WHITE PAPER 
|
fabianhjr
Sr. Member
****
Offline Offline

Activity: 322
Merit: 250


Do The Evolution


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

Oh ok, really cool then. Smiley

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!