/v1.9/index.php
PHP | 1919 lines | 1549 code | 263 blank | 107 comment | 361 complexity | 7a6173da1978694e1309410bf2ecd409 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?PHP
- include 'templates.php';
- session_name("timekoin");
- session_start();
- if($_SESSION["valid_login"] == FALSE && $_GET["action"] != "login")
- {
- sleep(1); // One second delay to help prevent brute force attack
- $_SESSION["valid_session"] = TRUE;
- if($_SESSION["valid_session"] == TRUE)
- {
- // Not logged in, display login page
- login_screen();
- }
- exit;
- }
- include 'configuration.php';
- if($_SESSION["valid_session"] == TRUE && $_GET["action"] == "login")
- {
- $http_username = $_POST["timekoin_username"];
- $http_password = $_POST["timekoin_password"];
- if(empty($http_username) == FALSE && empty($http_password) == FALSE)
- {
- if(mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE)
- {
- login_screen('Could Not Connect To Database');
- exit;
- }
-
- if(mysql_select_db(MYSQL_DATABASE) == FALSE)
- {
- login_screen('Could Not Select Database');
- exit;
- }
- $username_hash = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'username' LIMIT 1"),0,"field_data");
- $password_hash = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'password' LIMIT 1"),0,"field_data");
- if(hash('sha256', $http_username) == $username_hash)
- {
- //Username match, check password
- if(hash('sha256', $http_password) == $password_hash)
- {
- // All match, set login variable and store username in cookie
- $_SESSION["login_username"] = $http_username;
- $_SESSION["valid_login"] = TRUE;
- header("Location: index.php?menu=home");
- exit;
- }
- }
- }
- sleep(1); // One second delay to help prevent brute force attack
- login_screen("Login Failed");
- exit;
- }
- if($_SESSION["valid_login"] == TRUE)
- {
- include 'function.php';
- //****************************************************************************
- if(mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE)
- {
- home_screen('ERROR', '<font color="red"><strong>Could Not Connect To Database</strong></font>', '', '');
- exit;
- }
-
- if(mysql_select_db(MYSQL_DATABASE) == FALSE)
- {
- home_screen('ERROR','<font color="red"><strong>Could Not Select Database</strong></font>', '', '');
- exit;
- }
- //****************************************************************************
- if($_GET["menu"] == "home" || empty($_GET["menu"]) == TRUE)
- {
- $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
- $body_string = '<table border="0" cellspacing="10" cellpadding="2" bgcolor="#FFFFFF"><tr><td align="center"><strong>Status</strong></td>
- <td align="center"><strong>Program</strong></td><td align="left"><strong>Message</strong></td></tr>';
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Main should still be active
- if((time() - $script_last_heartbeat) > 30) // Greater than triple the loop time, something is wrong
- {
- $main_msg = last_debug_msg("main");
- if ($main_msg) {
- $main_msg = "Stalled: " . $main_msg;
- } else {
- $main_msg = "Program Stalled.";
- }
- // Main has stop was unexpected
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Main Program Processor</strong></font></td>
- <td><strong>' . $main_msg . '</strong></td></tr>';
- }
- else
- {
- $main_msg = last_debug_msg("main");
- if (!$main_msg) { $main_msg = "Normal Operations"; }
- // Main processor script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Main Program Processor</strong></font></td>
- <td><strong>' . $main_msg . '</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/stop.gif" alt="" /></td><td><font color="red"><strong>Main Program Processor</strong></font></td>
- <td><strong>Main Program Offline</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'treasurer_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'treasurer_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Treasurer should still be active
- if((time() - $script_last_heartbeat) > 60)
- {
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Treasurer Processor</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Treasurer Processor</strong></font></td>
- <td><strong>Examining Transactions for Accuracy...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Treasurer Processor</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'peerlist_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'peerlist_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Peerlist should still be active
- if((time() - $script_last_heartbeat) > 60)
- {
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Peer Processor</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Peer Processor</strong></font></td>
- <td><strong>Talking to Peers...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Peer Processor</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'queueclerk_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'queueclerk_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Queueclerk should still be active
- if((time() - $script_last_heartbeat) > 90)
- {
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Transaction Queue Clerk</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Transaction Queue Clerk</strong></font></td>
- <td><strong>Consulting with Peers...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Transaction Queue Clerk</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'genpeer_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'genpeer_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Genpeer should still be active
- if((time() - $script_last_heartbeat) > 90)
- {
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Generation Peer Manager</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Generation Peer Manager</strong></font></td>
- <td><strong>Consulting with Peers...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Generation Peer Manager</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'generation_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'generation_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Generation should still be active
- if((time() - $script_last_heartbeat) > 60)
- {
- // Generation has stop was unexpected
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Generation Processor</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Generation processor script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Generation Processor</strong></font></td>
- <td><strong>Doing Crypto Magic...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Generation Processor</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'transclerk_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'transclerk_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Transclerk should still be active
- if((time() - $script_last_heartbeat) > 120)
- {
- // Script has stop was unexpected
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Transaction Clerk</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Transaction Clerk</strong></font></td>
- <td><strong>Consulting with Peers...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Transaction Clerk</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'foundation_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'foundation_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Foundation should still be active
- if((time() - $script_last_heartbeat) > 100)
- {
- // Script has stop was unexpected
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Foundation Manager</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Foundation Manager</strong></font></td>
- <td><strong>Inspecting Transaction Foundations...</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Foundation Manager</strong></font></td>
- <td><strong>Idle</strong></td></tr>';
- }
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Watchdog should still be active
- if((time() - $script_last_heartbeat) > 60) // Greater than double the loop time, something is wrong
- {
- // Script has stop was unexpected
- $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Watchdog</strong></font></td>
- <td><strong>Program Stalled.</strong></td></tr>';
- }
- else
- {
- // Script is working properly
- $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Watchdog</strong></font></td>
- <td><strong>Active</strong></td></tr>';
- }
- }
- else
- {
- $body_string .= '<tr><td align="center"><img src="img/stop.gif" alt="" /></td><td><font color="#b0a454"><strong>Watchdog</strong></font></td>
- <td><strong>Disabled</strong></td></tr>';
- }
- $body_string = $body_string . '</table>';
- $display_balance = db_cache_balance($my_public_key);
- $firewall_blocked = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'firewall_blocked_peer' LIMIT 1"),0,"field_data");
- if($firewall_blocked == "1")
- {
- $firewall_blocked = '<tr><td colspan="3"><font color="#827f00"><strong>*** Operating in Outbound Only Mode ***</strong></font></td></tr>';
- }
- else
- {
- $firewall_blocked = NULL;
- }
- $time_sync_error = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'time_sync_error' LIMIT 1"),0,"field_data");
- if($time_sync_error == "1")
- {
- $time_sync_error = '<tr><td colspan="3"><font color="red"><strong>*** Timekoin Might Be Out of Sync with the Network Peers ***</strong></font></td></tr>';
- }
- else
- {
- $time_sync_error = NULL;
- }
- $text_bar = '<table border="0"><tr><td width="250"><strong>Current Server Balance: <font color="green">' . number_format($display_balance) . '</font></strong></td>
- <td width="180"><strong>Peer Time: <font color="blue">' . time() . '</font></strong></td>
- <td><strong><font color="#827f00">' . tk_time_convert(transaction_cycle(1) - time()) . '</font> until next cycle</strong></td></tr>
- ' . $firewall_blocked . $time_sync_error . '</table>';
- $quick_info = 'Check on the Status of the Timekoin inner workings.';
- $home_update = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'refresh_realtime_home' LIMIT 1"),0,"field_data");
- home_screen("Realtime Server Status", $text_bar, $body_string, $quick_info , $home_update);
- exit;
- }
- //****************************************************************************
- if($_GET["menu"] == "peerlist")
- {
- if($_GET["remove"] == "peer")
- {
- // Manually remove this peer
- $sql = "DELETE FROM `active_peer_list` WHERE `active_peer_list`.`IP_Address` = '" . $_POST["ip"] . "' AND `active_peer_list`.`domain` = '" . $_POST["domain"] . "' LIMIT 1";
- mysql_query($sql);
- }
- if($_GET["save"] == "peer" && empty($_POST["edit_port"]) == FALSE)
- {
- // Save manual peer edit
- if($_POST["perm_peer"] == "perm")
- {
- $join_peer_list = '0';
- }
- else
- {
- $join_peer_list = 'UNIX_TIMESTAMP()';
- }
-
- $sql = "UPDATE `active_peer_list` SET `last_heartbeat` = UNIX_TIMESTAMP() ,`join_peer_list` = $join_peer_list , `failed_sent_heartbeat` = '0',
- `IP_Address` = '" . $_POST["edit_ip"] . "', `domain` = '" . $_POST["edit_domain"] . "', `subfolder` = '" . $_POST["edit_subfolder"] . "', `port_number` = '" . $_POST["edit_port"] . "'
- WHERE `active_peer_list`.`IP_Address` = '" . $_POST["update_ip"] . "' AND `active_peer_list`.`domain` = '" . $_POST["update_domain"] . "' LIMIT 1";
- mysql_query($sql);
- }
- if($_GET["save"] == "newpeer" && empty($_POST["edit_port"]) == FALSE)
- {
- // Manually insert new peer
- $sql = "INSERT INTO `active_peer_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`last_heartbeat` ,`join_peer_list` ,`failed_sent_heartbeat`)
- VALUES ('" . $_POST["edit_ip"] . "', '" . $_POST["edit_domain"] . "', '" . $_POST["edit_subfolder"] . "', '" . $_POST["edit_port"] . "', UNIX_TIMESTAMP() , UNIX_TIMESTAMP() , '0')";
- mysql_query($sql);
- }
- if($_GET["save"] == "firstcontact")
- {
- // Wipe Current First Contact Server List and Save the New List
- $field_numbers = intval($_POST["field_numbers"]);
- if($field_numbers > 0)
- {
- mysql_query("DELETE FROM `options` WHERE `options`.`field_name` = 'first_contact_server'");
- while($field_numbers > 0)
- {
- if(empty($_POST["first_contact_ip$field_numbers"]) == FALSE || empty($_POST["first_contact_domain$field_numbers"]) == FALSE)
- {
- $sql = "INSERT INTO `options` (`field_name` ,`field_data`)
- VALUES ('first_contact_server', '---ip=" . $_POST["first_contact_ip$field_numbers"] .
- "---domain=" . $_POST["first_contact_domain$field_numbers"] .
- "---subfolder=" . $_POST["first_contact_subfolder$field_numbers"] .
- "---port=" . $_POST["first_contact_port$field_numbers"] . "---end')";
- mysql_query($sql);
- }
-
- $field_numbers--;
- }
- }
- }
- if($_GET["edit"] == "peer")
- {
- $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr><th>IP Address</th>
- <th>Domain</th><th>Subfolder</th><th>Port Number</th><th></th><th></th></tr>';
- if($_GET["type"] == "new")
- {
- // Manually add a peer
- $body_string .= '<FORM ACTION="index.php?menu=peerlist&save=newpeer" METHOD="post"><tr>
- <td class="style2"><input type="text" name="edit_ip" size="13" /></td>
- <td class="style2"><input type="text" name="edit_domain" size="20" /></td>
- <td class="style2"><input type="text" name="edit_subfolder" size="10" /></td>
- <td class="style2"><input type="text" name="edit_port" size="5" /></td>
- <td><input type="image" src="img/save-icon.gif" name="submit1" border="0"></FORM></td><td>
- <FORM ACTION="index.php?menu=peerlist" METHOD="post">
- <input type="image" src="img/stop.gif" name="submit2" border="0"></FORM>
- </td></tr>';
- $body_string .= '</table></div>';
- }
- else if($_GET["type"] == "firstcontact")
- {
- $sql = "SELECT * FROM `options` WHERE `field_name` = 'first_contact_server'";
- $sql_result = mysql_query($sql);
- $sql_num_results = mysql_num_rows($sql_result) + 2;
- $counter = 1;
- $body_string .= '<FORM ACTION="index.php?menu=peerlist&save=firstcontact" METHOD="post">';
- for ($i = 0; $i < $sql_num_results; $i++)
- {
- $sql_row = mysql_fetch_array($sql_result);
- $peer_ip = find_string("---ip=", "---domain", $sql_row["field_data"]);
- $peer_domain = find_string("---domain=", "---subfolder", $sql_row["field_data"]);
- $peer_subfolder = find_string("---subfolder=", "---port", $sql_row["field_data"]);
- $peer_port_number = find_string("---port=", "---end", $sql_row["field_data"]);
-
- $body_string .= '<tr><td class="style2"><input type="text" name="first_contact_ip' . $counter . '" size="13" value="' . $peer_ip . '" /></br></br></td>
- <td class="style2" valign="top"><input type="text" name="first_contact_domain' . $counter . '" size="20" value="' . $peer_domain . '" /></td>
- <td class="style2" valign="top"><input type="text" name="first_contact_subfolder' . $counter . '" size="10" value="' . $peer_subfolder . '" /></td>
- <td class="style2" valign="top"><input type="text" name="first_contact_port' . $counter . '" size="5" value="' . $peer_port_number . '" /></td>
- </td></tr>';
- $counter++;
- }
- $body_string .= '<input type="hidden" name="field_numbers" value="' . ($counter - 1) . '">
- <tr><td colspan="2"><input type="submit" value="Save First Contact Servers"/></FORM></td></tr>';
- $body_string .= '</table></div>';
- }
- else
- {
- // Manually edit this peer
- $sql = "SELECT * FROM `active_peer_list` WHERE `IP_Address` = '" . $_POST["ip"] ."' AND `domain` = '" . $_POST["domain"] ."' LIMIT 1";
- $sql_result = mysql_query($sql);
- $sql_row = mysql_fetch_array($sql_result);
- $body_string .= '<FORM ACTION="index.php?menu=peerlist&save=peer" METHOD="post"><tr>
- <td class="style2"><input type="text" name="edit_ip" size="13" value="' . $sql_row["IP_Address"] . '" /></br></br>
- <select name="perm_peer"><option value="expires" SELECTED>Purge When Inactive</option><option value="perm">Do Not Purge</select></td>
- <td class="style2" valign="top"><input type="text" name="edit_domain" size="20" value="' . $sql_row["domain"] . '" /></td>
- <td class="style2" valign="top"><input type="text" name="edit_subfolder" size="10" value="' . $sql_row["subfolder"] . '" /></td>
- <td class="style2" valign="top"><input type="text" name="edit_port" size="5" value="' . $sql_row["port_number"] . '" /></td>
- <td valign="top"><input type="hidden" name="update_ip" value="' . $sql_row["IP_Address"] . '">
- <input type="hidden" name="update_domain" value="' . $sql_row["domain"] . '">
- <input type="image" src="img/save-icon.gif" name="submit1" border="0"></FORM></td>
- <td valign="top"><FORM ACTION="index.php?menu=peerlist" METHOD="post">
- <input type="image" src="img/stop.gif" name="submit2" border="0"></FORM>
- </td></tr>';
- $body_string .= '</table></div>';
- }
- $sql = "SELECT * FROM `active_peer_list`";
- $active_peers = mysql_num_rows(mysql_query($sql));
- $sql = "SELECT * FROM `new_peers_list`";
- $new_peers = mysql_num_rows(mysql_query($sql));
- $peer_number_bar = '<strong>Active Peers: <font color="green">' . $active_peers . '</font> Peers in Reserve: <font color="blue">' . $new_peers . '</font></strong>';
- $quick_info = 'Shows all Active Peers.</br></br>
- You can manually delete or edit peers in this section.</br></br>
- <font color="blue">First Contact Servers</font> can be changed, deleted, or new ones added to the bottom of the list.';
- home_screen('Realtime Network Peer List', $peer_number_bar, $body_string , $quick_info);
- }
- else
- {
- // Default screen
- $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr>
- <th><p style="font-size:10px;">IP Address</p></th><th><p style="font-size:10px;">Domain</p></th>
- <th><p style="font-size:10px;">Subfolder</p></th><th><p style="font-size:10px;">Port Number</p></th>
- <th><p style="font-size:10px;">Last Heartbeat</p></th><th><p style="font-size:10px;">Joined</p></th>
- <th><p style="font-size:10px;">Failed Heartbeat</p></th><th></th><th></th></tr>';
-
- if($_GET["show"] == "reserve")
- {
- $sql = "SELECT * FROM `new_peers_list`";
- }
- else
- {
- $sql = "SELECT * FROM `active_peer_list`";
- }
- $sql_result = mysql_query($sql);
- $sql_num_results = mysql_num_rows($sql_result);
- for ($i = 0; $i < $sql_num_results; $i++)
- {
- $sql_row = mysql_fetch_array($sql_result);
- if($_GET["show"] != "reserve")
- {
- $last_heartbeat = time() - $sql_row["last_heartbeat"];
- $last_heartbeat = tk_time_convert($last_heartbeat);
- if($sql_row["join_peer_list"] == 0)
- {
- $joined = 'P';
- $permanent1 = '<font color="blue">';
- $permanent2 = '</font>';
- }
- else
- {
- $joined = time() - $sql_row["join_peer_list"];
- $joined = tk_time_convert($joined);
- $permanent1 = NULL;
- $permanent2 = NULL;
- }
- }
- $body_string .= '<tr>
- <td class="style2"><p style="word-wrap:break-word; width:85px; font-size:10px;">' . $permanent1 . $sql_row["IP_Address"] . $permanent2 . '</p></td>
- <td class="style2"><p style="word-wrap:break-word; width:130px; font-size:10px;">' . $permanent1 . $sql_row["domain"] . $permanent2 . '</p></td>
- <td class="style2"><p style="word-wrap:break-word; width:55px; font-size:10px;">' . $permanent1 . $sql_row["subfolder"] . $permanent2 . '</p></td>
- <td class="style2"><p style="word-wrap:break-word; font-size:10px;">' . $permanent1 . $sql_row["port_number"] . $permanent2 . '</p></td>
- <td class="style2"><p style="word-wrap:break-word; font-size:11px;">' . $permanent1 . $last_heartbeat . $permanent2 . '</p></td>
- <td class="style2"><p style="word-wrap:break-word; font-size:11px;">' . $permanent1 . $joined . $permanent2 . '</p></td>
- <td class="style2"><p style="word-wrap:break-word; font-size:11px;">' . $permanent1 . $sql_row["failed_sent_heartbeat"] . $permanent2 . '</p></td>';
- if($_GET["show"] == "reserve")
- {
- $body_string .= '<td></td><td></td></tr>';
- }
- else
- {
- $body_string .= '<td><FORM ACTION="index.php?menu=peerlist&remove=peer" METHOD="post"><input type="image" src="img/stop.gif" name="remove' . $i . '" border="0">
- <input type="hidden" name="ip" value="' . $sql_row["IP_Address"] . '">
- <input type="hidden" name="domain" value="' . $sql_row["domain"] . '">
- </FORM></td><td>
- <FORM ACTION="index.php?menu=peerlist&edit=peer" METHOD="post"><input type="image" src="img/edit-icon.gif" name="edit' . $i . '" border="0">
- <input type="hidden" name="ip" value="' . $sql_row["IP_Address"] . '">
- <input type="hidden" name="domain" value="' . $sql_row["domain"] . '">
- </FORM>
- </td></tr>';
- }
- }
- $body_string .= '<tr><td colspan="2"><FORM ACTION="index.php?menu=peerlist&show=reserve" METHOD="post"><input type="submit" value="Show Reserve Peers"/></FORM></td>
- <td colspan="3"><FORM ACTION="index.php?menu=peerlist&edit=peer&type=new" METHOD="post"><input type="submit" value="Add New Peer"/></FORM></td>
- <td colspan="4"><FORM ACTION="index.php?menu=peerlist&edit=peer&type=firstcontact" METHOD="post"><input type="submit" value="First Contact Servers"/></FORM></td></tr></table></div>';
- $sql = "SELECT * FROM `new_peers_list`";
- $new_peers = mysql_num_rows(mysql_query($sql));
- if($_GET["show"] == "reserve")
- {
- $sql = "SELECT * FROM `active_peer_list`";
- $sql_num_results = mysql_num_rows(mysql_query($sql));
- }
- $peer_number_bar = '<strong>Active Peers: <font color="green">' . $sql_num_results . '</font> Peers in Reserve: <font color="blue">' . $new_peers . '</font></strong>';
- $quick_info = 'Shows all Active Peers.</br></br>You can manually delete or edit peers in this section.
- </br></br>Peers in <font color="blue">Blue</font> will not expire after 5 minutes of inactivity.';
- $peerlist_update = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'refresh_realtime_peerlist' LIMIT 1"),0,"field_data");
- if($_GET["show"] == "reserve")
- {
- home_screen('Reserve Peer List', $peer_number_bar, $body_string , $quick_info);
- }
- else
- {
- home_screen('Realtime Network Peer List', $peer_number_bar, $body_string , $quick_info, $peerlist_update);
- }
- }
- exit;
- }
- //****************************************************************************
- if($_GET["menu"] == "system")
- {
- if($_GET["peer_settings"] == "change")
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["max_peers"] . "' WHERE `options`.`field_name` = 'max_active_peers' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["max_new_peers"] . "' WHERE `options`.`field_name` = 'max_new_peers' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="green"><strong>Peer Settings Updated...</strong></font></br></br>';
- }
- }
- }
- if($_GET["server_settings"] == "change")
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["domain"] . "' WHERE `options`.`field_name` = 'server_domain' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["subfolder"] . "' WHERE `options`.`field_name` = 'server_subfolder' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["port"] . "' WHERE `options`.`field_name` = 'server_port_number' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["max_request"] . "' WHERE `options`.`field_name` = 'server_request_max' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["allow_LAN"] . "' WHERE `options`.`field_name` = 'allow_LAN_peers' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["allow_ambient"] . "' WHERE `options`.`field_name` = 'allow_ambient_peer_restart' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="blue"><strong>Server Settings Updated...</strong></font></br></br>';
- }
- }
- }
- }
- }
- }
- }
- if($_GET["stop"] == "watchdog")
- {
- $watchdog_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_heartbeat_active' LIMIT 1"),0,"field_data");
- $watchdog_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_last_heartbeat' LIMIT 1"),0,"field_data");
- if($watchdog_loop_active > 0)
- {
- // Watchdog should still be active
- if((time() - $watchdog_last_heartbeat) > 60) // Greater than double the loop time, something is wrong
- {
- // Watchdog stop was unexpected
- $sql = "UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'watchdog_heartbeat_active' LIMIT 1";
-
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="red"><strong>Watchdog was already Stopped...</strong></font></br></br>';
- }
- }
- else
- {
- // Set database to flag watchdog to stop
- $sql = "UPDATE `main_loop_status` SET `field_data` = '3' WHERE `main_loop_status`.`field_name` = 'watchdog_heartbeat_active' LIMIT 1";
-
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="blue"><strong>Watchdog Stopping...</strong></font></br></br>';
- }
- }
- }
- else
- {
- $server_code = '</br><font color="red"><strong>Watchdog was already Stopped...</strong></font></br></br>';
- }
- }
- if($_GET["stop"] == "main")
- {
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Main should still be active
- if((time() - $script_last_heartbeat) > 30) // Greater than triple the loop time, something is wrong
- {
- // Main stop was unexpected
- $sql = "UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
-
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="red"><strong>Timekoin Main Processor was already Stopped...</strong></font></br></br>';
- // Clear transaction queue to avoid unnecessary peer confusion
- mysql_query("TRUNCATE TABLE `transaction_queue`");
- }
- }
- else
- {
- // Set database to flag watchdog to stop
- $sql = "UPDATE `main_loop_status` SET `field_data` = '3' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
-
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="blue"><strong>Timekoin Main Processor Stopping...</strong></font></br></br>';
- // Clear transaction queue to avoid unnecessary peer confusion
- mysql_query("TRUNCATE TABLE `transaction_queue`");
- }
- }
- }
- else
- {
- $server_code = '</br><font color="red"><strong>Timekoin Main Processor was already Stopped...</strong></font></br></br>';
- // Clear transaction queue to avoid unnecessary peer confusion
- mysql_query("TRUNCATE TABLE `transaction_queue`");
- }
- }
- if($_GET["stop"] == "emergency")
- {
- $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"),0,"field_data");
- $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_last_heartbeat' LIMIT 1"),0,"field_data");
- if($script_loop_active > 0)
- {
- // Main should still be active
- if((time() - $script_last_heartbeat) > 30) // Greater than triple the loop time, something is wrong
- {
- // Main stop was unexpected
- $sql = "UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
-
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="red"><strong>Entire Timekoin System has been Halted!</strong></font></br></br>';
- activate(TIMEKOINSYSTEM, 0);
- }
- }
- else
- {
- // Set database to flag watchdog to stop
- $sql = "UPDATE `main_loop_status` SET `field_data` = '3' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
-
- if(mysql_query($sql) == TRUE)
- {
- $server_code = '</br><font color="red"><strong>Entire Timekoin System has been Halted!</strong></font></br></br>';
- activate(TIMEKOINSYSTEM, 0);
- }
- }
- }
- else
- {
- $server_code = '</br><font color="red"><strong>Entire Timekoin System has been Halted!</strong></font></br></br>';
- activate(TIMEKOINSYSTEM, 0);
- }
- }
- if($_GET["code"] == "1")
- {
- $server_code = '</br><font color="green"><strong>Main Timekoin Processing Started...</strong></font></br></br>';
- }
- if($_GET["code"] == "99")
- {
- $server_code = '</br><font color="blue"><strong>Timekoin Already Active...</strong></font></br></br>';
- }
- if($_GET["code"] == "2")
- {
- $server_code = '</br><font color="green"><strong>Watchdog Started...</strong></font></br></br>';
- }
- if($_GET["code"] == "89")
- {
- $server_code = '</br><font color="blue"><strong>Watchdog Already Active...</strong></font></br></br>';
- }
- if($_GET["time"] == "poll")
- {
- $context = stream_context_create(array('http' => array('header'=>'Connection: close'))); // Force close socket after complete
- ini_set('user_agent', 'Timekoin Server (GUI) v' . TIMEKOIN_VERSION);
- ini_set('default_socket_timeout', 3); // Timeout for request in seconds
- $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" >
- <tr><th>Peer</th><th>Time</th><th>Variance</th></tr>';
- // Add more possible peers to the new peer list by polling what the active peers have
- $sql = "SELECT * FROM `active_peer_list`";
- $sql_result = mysql_query($sql);
- $sql_num_results = mysql_num_rows($sql_result);
- $response_counter = 0;
- $variance_total = 0;
- for ($i = 0; $i < $sql_num_results; $i++)
- {
- $sql_row = mysql_fetch_array($sql_result);
-
- $ip_address = $sql_row["IP_Address"];
- $domain = $sql_row["domain"];
- $subfolder = $sql_row["subfolder"];
- $port_number = $sql_row["port_number"];
- if(empty($domain) == TRUE)
- {
- $site_address = $ip_address;
- }
- else
- {
- $site_address = $domain;
- }
- if($port_number == 443)
- {
- $ssl = "s";
- }
- else
- {
- $ssl = NULL;
- }
- //Use site address name to poll
- $poll_peer = filter_sql(file_get_contents("http$ssl://$site_address:$port_number/$subfolder/peerlist.php?action=polltime", FALSE, $context, NULL, 12));
- $my_time = time();
-
- if($my_time == $poll_peer && empty($poll_peer) == FALSE)
- {
- $variance = '0 seconds';
- $response_counter++;
- }
- else if(empty($poll_peer) == FALSE)
- {
- $variance = $my_time - $poll_peer;
- $response_counter++;
- $variance_total = $variance_total + abs($variance);
- if($variance > 1)
- {
- $variance = '+' . $variance . ' seconds';
- }
- else if($variance == 1)
- {
- $variance = '+' . $variance . ' second';
- }
- else if($variance == -1)
- {
- $variance = $variance . ' second';
- }
- else
- {
- $variance = $variance . ' seconds';
- }
- }
- else
- {
- $variance = 'No Response';
- }
- $body_string .= '<tr><td class="style2"><p style="word-wrap:break-word; font-size:12px;">' . $site_address . ':' . $port_number . '/' . $subfolder . '</p></td>';
- $body_string .= '<td class="style2"><p style="font-size:12px;">' . $poll_peer . '</p></td>';
- $body_string .= '<td class="style2"><p style="font-size:12px;">' . $variance . '</p></td></tr>';
-
- }
- $body_string .= '</table></div>';
- $variance_average = round($variance_total / $response_counter);
- if($variance_average > 15)
- {
- $variance_average = '<font color="red">' . $variance_average . '</font> seconds';
- }
- else if($variance_average == 1)
- {
- $variance_average = '<font color="green">' . $variance_average . '</font> second';
- }
- else if($variance_average <= 15 && $variance_average > 1)
- {
- $variance_average = '<font color="blue">' . $variance_average . '</font> seconds';
- }
- else
- {
- $variance_average = '<font color="green">' . $variance_average . '</font> seconds';
- }
- $body_string .= '<strong>Variance Average: ' . $variance_average . '</strong></br></br>';
- }
- else
- {
- $body_string = system_screen();
- $body_string .= $server_code;
- }
- $quick_info = '<strong>Start</strong> will activate all Timekoin Processing.</br></br>
- <strong>Stop</strong> will halt Timekoin from further processing.</br></br>
- <strong>Emergency Stop</strong> will halt Timekoin from further processing and Block all Peer Internet activity.</br></br>
- <strong>Max Peer Query</strong> is the per 10 seconds limit imposed on each individual peer before being banned for 24 hours.</br></br>
- <strong>Allow LAN Peers</strong> controls if LAN peers will be allowed to populate the peer list.</br></br>
- <strong>Allow Ambient Peer Restarts</strong> controls if other peers can restart Timekoin from unknown failures.</br></br>
- <strong>Variance</strong> of 15 seconds or less with the other peers is good.';
- home_screen('System Settings', system_service_bar(), $body_string , $quick_info);
- exit;
- }
- //****************************************************************************
- if($_GET["menu"] == "options")
- {
- if($_GET["menu"] == "options" && $_GET["password"] == "change")
- {
- if(empty($_POST["current_username"]) == FALSE && empty($_POST["new_username"]) == FALSE && empty($_POST["confirm_username"]) == FALSE)
- {
- // Attemping to change username
- if($_POST["current_username"] == $_SESSION["login_username"])
- {
- // Right username, does the new username match the confirmation username?
- if($_POST["new_username"] == $_POST["confirm_username"])
- {
- // Write new hash to database for username and change the session username
- $username_hash = hash('sha256', $_POST["confirm_username"]);
- $sql = "UPDATE `options` SET `field_data` = '$username_hash' WHERE `options`.`field_name` = 'username' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- // Update success, now change the session username
- $_SESSION["login_username"] = $_POST["confirm_username"];
- $username_change = TRUE;
- }
- }
- }
- }
- if(empty($_POST["current_password"]) == FALSE && empty($_POST["new_password"]) == FALSE && empty($_POST["confirm_password"]) == FALSE)
- {
- $password_hash = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'password' LIMIT 1"),0,"field_data");
- $current_password_hash = hash('sha256', $_POST["current_password"]);
- $new_password_hash = hash('sha256', $_POST["new_password"]);
- // Attemping to change password
- if($current_password_hash == $password_hash)
- {
- // Right password, does the new password match the confirmation password?
- if($_POST["new_password"] == $_POST["confirm_password"])
- {
- // Write new hash to database for username and change the session username
- $sql = "UPDATE `options` SET `field_data` = '$new_password_hash' WHERE `options`.`field_name` = 'password' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $password_change = TRUE;
- }
- }
- }
- }
- $body_text = options_screen2();
- if($username_change == TRUE)
- {
- $body_text = $body_text . '<font color="blue"><strong>Username Change Complete!</strong></font></br>';
- }
- else
- {
- $body_text = $body_text . '<strong>Username Has Not Been Changed</strong></br>';
- }
- if($password_change == TRUE)
- {
- $body_text = $body_text . '<font color="blue"><strong>Password Change Complete!</strong></font>';
- }
- else
- {
- $body_text = $body_text . '<strong>Password Has Not Been Changed</strong>';
- }
- } // End username/password change check
- if($_GET["menu"] == "options" && $_GET["refresh"] == "change")
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["home_update"] . "' WHERE `options`.`field_name` = 'refresh_realtime_home' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["peerlist_update"] . "' WHERE `options`.`field_name` = 'refresh_realtime_peerlist' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $sql = "UPDATE `options` SET `field_data` = '" . $_POST["queue_update"] . "' WHERE `options`.`field_name` = 'refresh_realtime_queue' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $hash_code = $_POST["hash_code"];
-
- // Sanitization of message !#$%&'*+-/=?^_`{|}~@.[] allowed
- $hash_code = filter_var($hash_code, FILTER_SANITIZE_EMAIL);
- // Filter symbols that might lead to an HTML access error
- $symbols = array("'", "%", "*", "$", "`", "?", "=", "~", "&", "#", "/", "+",);
- $hash_code = str_replace($symbols, "", $hash_code);
-
- $sql = "UPDATE `options` SET `field_data` = '" . $hash_code . "' WHERE `options`.`field_name` = 'server_hash_code' LIMIT 1";
- if(mysql_query($sql) == TRUE)
- {
- $refresh_change = TRUE;
- }
- }
- }
- }
- $body_text = options_screen2();
- if($refresh_change == TRUE)
- {
- $body_text .= '<font color="blue"><strong>Refresh Settings & Hash Code Update Saved!</strong></font></br>';
- }
- else
- {
- $body_text .= '<strong>Refresh / Hash Code Update ERROR...</strong></br>';
- }
- } // End refresh update save
- else if(empty($_GET["password"]) == TRUE && empty($_GET["refresh"]) == TRUE)
- {
- $body_text = options_screen2();
- }
- $quick_info = 'You may change the username and password individually or at the same time.</br></br>
- Remember that usernames and passwords are Case Sensitive.
- </br></br><strong>Hash Code</strong> is a private code you create for any external program or server that request access to more advanced features of your Timekoin server.';
- home_screen("Options & Personal Settings", options_screen(), $body_text , $quick_info);
- exit;
- }
- //****************************************************************************
- if($_GET["menu"] == "generation")
- {
- if($_GET["generate"] == "enable")
- {
- $sql = "UPDATE `options` SET `field_data` = '1' WHERE `options`.`field_name` = 'generate_currency' LIMIT 1";
- mysql_query($sql);
- }
- else if($_GET["generate"] == "disable")
- {
- $sql = "UPDATE `options` SET `field_data` = '0' WHERE `options`.`field_name` = 'generate_currency' LIMIT 1";
- mysql_query($sql);
- }
- $sql = "SELECT * FROM `generating_peer_queue`";
- $generate_peer_queue = mysql_num_rows(mysql_query($sql));
- $generate_currency_enabled = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'generate_currency' LIMIT 1"),0,"field_data");
- $sql = "SELECT * FROM `generating_peer_list`";
- $sql_result = mysql_query($sql);
- $sql_num_results = mysql_num_rows($sql_result);
- $generating_peers_now = $sql_num_results;
- if($generate_currency_enabled == "1")
- {
- $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
- $join_peer_list = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `public_key` = '$my_public_key' LIMIT 1"),0,"join_peer_list");
- $last_generation = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `public_key` = '$my_public_key' LIMIT 1"),0,"last_generation");
- if(time() - $join_peer_list < 3600)
- {
- // Can't generate yet
- $generate_currency = 'Generation <font color="green"><strong>Enabled</strong></font>';
- $generate_rate = '@ <font color="green"><strong>' . peer_gen_amount($my_public_key) . '</strong></font> per Cycle';
- $continuous_production = '<font color="blue">Generation not allowed for ' . tk_time_convert(3600 - (time() - $join_peer_list)) . '</font>';
- }
- else if($join_peer_list === FALSE)
- {
- // Not elected to the generating peer list yet
- $generate_currency = 'Generation <font color="green"><strong>Enabled</strong></font>';
- $generate_rate = '@ <font color="green"><strong>' . peer_gen_amount($my_public_key) . '</strong></font> per Cycle';
- $continuous_production = '<font color="red"><strong>This Peer Has Not</br> Been Elected Yet</strong></font>';
- }
- else
- {
- $production_time = tk_time_convert(time() - $join_peer_list);
- $last_generation = tk_time_convert(time() - $last_generation);
- $generate_currency = 'Generation <font color="green"><strong>Enabled</strong></font>';
- $generate_rate = '@ <font color="green"><strong>' . peer_gen_amount($my_public_key) . '</strong></font> per Cycle';
- $continuous_production = 'Continuous Production for ' . $production_time . '</br>Last Generated ' . $last_generation . ' ago';
- }
- }
- else
- {
- $generate_currency = 'Generation <font color="red">Disabled</strong></font>';
- }
- $body_string = generation_body($generate_currency_enabled);
- if($_GET["generate"] == "showlist")
- {
- $default_public_key_font = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'public_key_font_size' LIMIT 1"),0,"field_data");
- $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
- $body_string = $body_string . '<hr></hr><strong>Current Generation List</strong>
- <div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr><th>Public Key</th><th>Joined</th><th>Last Generated</th></tr>';
- $sql = "SELECT * FROM `generating_peer_list` ORDER BY `join_peer_list` ASC";
- $sql_result = mysql_query($sql);
- $sql_num_results = mysql_num_rows($sql_result);
- for ($i = 0; $i < $sql_num_results; $i++)
- {
- $sql_row = mysql_fetch_array($sql_result);
- if($my_public_key == $sql_row["public_key"])
- {
- $public_key = '<p style="font-size:12px;"><font color="green"><strong>My Public Key</strong></font>';
- }
- else
- {
- $public_key = '<p style="word-wrap:break-word; width:325px; font-size:' . $default_public_key_font . 'px;">' . base64_encode($sql_row["public_key"]);
- }
- $body_string .= '<tr>
- <td class="style2">' . $public_key . '</p></td>
- <td class="style2"><p style="font-size:10px;">' . unix_timestamp_to_human($sql_row["join_peer_list"]) . '</p></td>
- <td class="style2"><p style="font-size:10px;">' . tk_time_convert(time() - $sql_row["last_generation"]) . ' ago</p></td></tr>';
- }
- $body_string .= '</table></div>';
- }
- if($_GET["generate"] == "showqueue")
- {
- $default_public_key_font = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'public_key_font_size' LIMIT 1"),0,"field_data");
- $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
- $body_string .= '<hr></hr><strong>Election Queue List</strong>
- <div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr><th>Public Key</th><th>Join Queue</th></tr>';
- $sql = "SELECT * FROM `generating_peer_queue` ORDER BY `timestamp` ASC";
- $sql_result = mysql_query($sql);
- $sql_num_results = mysql_num_rows($sql_result);
- for ($i = 0; $i < $sql_num_results; $i++)
- {
- $sql_row = mysql_fetch_array($sql_result);
- if($my_public_key == $sql_row["public_key"])
- {
- $public_key = '<p style="font-size:12px;"><font color="green"><strong>My Public Key</strong></font>';
- }
- else
- {
- $public_key = '<p style="word-wrap:break-word; width:425px; font-size:' . $default_public_key_font . 'px;">' . base64_encode($sql_row["public_key"]);
- }
- $body_string .= '<tr>
- <td class="style2">' . $public_key . '</p></td>
- <td class="style2"><p style="font-size:10px;">' . tk_time_convert(time() - $sql_row["timestamp"]) . ' ago</p></td></tr>';
- }
- $body_string .= '</table></div>';
- }
- // Next Election Calculator
- // Determine when to run this by comparing the last digit the current block and
- // the 3rd digit the generation time; when they match, run the gen key scoring.
- $max_cycles_ahead = 200;
-
- for ($i = 0; $i < $max_cycles_ahead; $i++)
- {
- $current_generation_cycle = transactio…
Large files files are truncated, but you can click here to view the full file