PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/v1.9/index.php

https://bitbucket.org/rev22/timekoin
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

  1. <?PHP
  2. include 'templates.php';
  3. session_name("timekoin");
  4. session_start();
  5. if($_SESSION["valid_login"] == FALSE && $_GET["action"] != "login")
  6. {
  7. sleep(1); // One second delay to help prevent brute force attack
  8. $_SESSION["valid_session"] = TRUE;
  9. if($_SESSION["valid_session"] == TRUE)
  10. {
  11. // Not logged in, display login page
  12. login_screen();
  13. }
  14. exit;
  15. }
  16. include 'configuration.php';
  17. if($_SESSION["valid_session"] == TRUE && $_GET["action"] == "login")
  18. {
  19. $http_username = $_POST["timekoin_username"];
  20. $http_password = $_POST["timekoin_password"];
  21. if(empty($http_username) == FALSE && empty($http_password) == FALSE)
  22. {
  23. if(mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE)
  24. {
  25. login_screen('Could Not Connect To Database');
  26. exit;
  27. }
  28. if(mysql_select_db(MYSQL_DATABASE) == FALSE)
  29. {
  30. login_screen('Could Not Select Database');
  31. exit;
  32. }
  33. $username_hash = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'username' LIMIT 1"),0,"field_data");
  34. $password_hash = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'password' LIMIT 1"),0,"field_data");
  35. if(hash('sha256', $http_username) == $username_hash)
  36. {
  37. //Username match, check password
  38. if(hash('sha256', $http_password) == $password_hash)
  39. {
  40. // All match, set login variable and store username in cookie
  41. $_SESSION["login_username"] = $http_username;
  42. $_SESSION["valid_login"] = TRUE;
  43. header("Location: index.php?menu=home");
  44. exit;
  45. }
  46. }
  47. }
  48. sleep(1); // One second delay to help prevent brute force attack
  49. login_screen("Login Failed");
  50. exit;
  51. }
  52. if($_SESSION["valid_login"] == TRUE)
  53. {
  54. include 'function.php';
  55. //****************************************************************************
  56. if(mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE)
  57. {
  58. home_screen('ERROR', '<font color="red"><strong>Could Not Connect To Database</strong></font>', '', '');
  59. exit;
  60. }
  61. if(mysql_select_db(MYSQL_DATABASE) == FALSE)
  62. {
  63. home_screen('ERROR','<font color="red"><strong>Could Not Select Database</strong></font>', '', '');
  64. exit;
  65. }
  66. //****************************************************************************
  67. if($_GET["menu"] == "home" || empty($_GET["menu"]) == TRUE)
  68. {
  69. $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
  70. $body_string = '<table border="0" cellspacing="10" cellpadding="2" bgcolor="#FFFFFF"><tr><td align="center"><strong>Status</strong></td>
  71. <td align="center"><strong>Program</strong></td><td align="left"><strong>Message</strong></td></tr>';
  72. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"),0,"field_data");
  73. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_last_heartbeat' LIMIT 1"),0,"field_data");
  74. if($script_loop_active > 0)
  75. {
  76. // Main should still be active
  77. if((time() - $script_last_heartbeat) > 30) // Greater than triple the loop time, something is wrong
  78. {
  79. $main_msg = last_debug_msg("main");
  80. if ($main_msg) {
  81. $main_msg = "Stalled: " . $main_msg;
  82. } else {
  83. $main_msg = "Program Stalled.";
  84. }
  85. // Main has stop was unexpected
  86. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Main Program Processor</strong></font></td>
  87. <td><strong>' . $main_msg . '</strong></td></tr>';
  88. }
  89. else
  90. {
  91. $main_msg = last_debug_msg("main");
  92. if (!$main_msg) { $main_msg = "Normal Operations"; }
  93. // Main processor script is working properly
  94. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Main Program Processor</strong></font></td>
  95. <td><strong>' . $main_msg . '</strong></td></tr>';
  96. }
  97. }
  98. else
  99. {
  100. $body_string .= '<tr><td align="center"><img src="img/stop.gif" alt="" /></td><td><font color="red"><strong>Main Program Processor</strong></font></td>
  101. <td><strong>Main Program Offline</strong></td></tr>';
  102. }
  103. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'treasurer_heartbeat_active' LIMIT 1"),0,"field_data");
  104. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'treasurer_last_heartbeat' LIMIT 1"),0,"field_data");
  105. if($script_loop_active > 0)
  106. {
  107. // Treasurer should still be active
  108. if((time() - $script_last_heartbeat) > 60)
  109. {
  110. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Treasurer Processor</strong></font></td>
  111. <td><strong>Program Stalled.</strong></td></tr>';
  112. }
  113. else
  114. {
  115. // Script is working properly
  116. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Treasurer Processor</strong></font></td>
  117. <td><strong>Examining Transactions for Accuracy...</strong></td></tr>';
  118. }
  119. }
  120. else
  121. {
  122. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Treasurer Processor</strong></font></td>
  123. <td><strong>Idle</strong></td></tr>';
  124. }
  125. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'peerlist_heartbeat_active' LIMIT 1"),0,"field_data");
  126. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'peerlist_last_heartbeat' LIMIT 1"),0,"field_data");
  127. if($script_loop_active > 0)
  128. {
  129. // Peerlist should still be active
  130. if((time() - $script_last_heartbeat) > 60)
  131. {
  132. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Peer Processor</strong></font></td>
  133. <td><strong>Program Stalled.</strong></td></tr>';
  134. }
  135. else
  136. {
  137. // Script is working properly
  138. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Peer Processor</strong></font></td>
  139. <td><strong>Talking to Peers...</strong></td></tr>';
  140. }
  141. }
  142. else
  143. {
  144. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Peer Processor</strong></font></td>
  145. <td><strong>Idle</strong></td></tr>';
  146. }
  147. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'queueclerk_heartbeat_active' LIMIT 1"),0,"field_data");
  148. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'queueclerk_last_heartbeat' LIMIT 1"),0,"field_data");
  149. if($script_loop_active > 0)
  150. {
  151. // Queueclerk should still be active
  152. if((time() - $script_last_heartbeat) > 90)
  153. {
  154. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Transaction Queue Clerk</strong></font></td>
  155. <td><strong>Program Stalled.</strong></td></tr>';
  156. }
  157. else
  158. {
  159. // Script is working properly
  160. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Transaction Queue Clerk</strong></font></td>
  161. <td><strong>Consulting with Peers...</strong></td></tr>';
  162. }
  163. }
  164. else
  165. {
  166. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Transaction Queue Clerk</strong></font></td>
  167. <td><strong>Idle</strong></td></tr>';
  168. }
  169. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'genpeer_heartbeat_active' LIMIT 1"),0,"field_data");
  170. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'genpeer_last_heartbeat' LIMIT 1"),0,"field_data");
  171. if($script_loop_active > 0)
  172. {
  173. // Genpeer should still be active
  174. if((time() - $script_last_heartbeat) > 90)
  175. {
  176. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Generation Peer Manager</strong></font></td>
  177. <td><strong>Program Stalled.</strong></td></tr>';
  178. }
  179. else
  180. {
  181. // Script is working properly
  182. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Generation Peer Manager</strong></font></td>
  183. <td><strong>Consulting with Peers...</strong></td></tr>';
  184. }
  185. }
  186. else
  187. {
  188. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Generation Peer Manager</strong></font></td>
  189. <td><strong>Idle</strong></td></tr>';
  190. }
  191. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'generation_heartbeat_active' LIMIT 1"),0,"field_data");
  192. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'generation_last_heartbeat' LIMIT 1"),0,"field_data");
  193. if($script_loop_active > 0)
  194. {
  195. // Generation should still be active
  196. if((time() - $script_last_heartbeat) > 60)
  197. {
  198. // Generation has stop was unexpected
  199. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Generation Processor</strong></font></td>
  200. <td><strong>Program Stalled.</strong></td></tr>';
  201. }
  202. else
  203. {
  204. // Generation processor script is working properly
  205. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Generation Processor</strong></font></td>
  206. <td><strong>Doing Crypto Magic...</strong></td></tr>';
  207. }
  208. }
  209. else
  210. {
  211. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Generation Processor</strong></font></td>
  212. <td><strong>Idle</strong></td></tr>';
  213. }
  214. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'transclerk_heartbeat_active' LIMIT 1"),0,"field_data");
  215. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'transclerk_last_heartbeat' LIMIT 1"),0,"field_data");
  216. if($script_loop_active > 0)
  217. {
  218. // Transclerk should still be active
  219. if((time() - $script_last_heartbeat) > 120)
  220. {
  221. // Script has stop was unexpected
  222. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Transaction Clerk</strong></font></td>
  223. <td><strong>Program Stalled.</strong></td></tr>';
  224. }
  225. else
  226. {
  227. // Script is working properly
  228. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Transaction Clerk</strong></font></td>
  229. <td><strong>Consulting with Peers...</strong></td></tr>';
  230. }
  231. }
  232. else
  233. {
  234. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Transaction Clerk</strong></font></td>
  235. <td><strong>Idle</strong></td></tr>';
  236. }
  237. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'foundation_heartbeat_active' LIMIT 1"),0,"field_data");
  238. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'foundation_last_heartbeat' LIMIT 1"),0,"field_data");
  239. if($script_loop_active > 0)
  240. {
  241. // Foundation should still be active
  242. if((time() - $script_last_heartbeat) > 100)
  243. {
  244. // Script has stop was unexpected
  245. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Foundation Manager</strong></font></td>
  246. <td><strong>Program Stalled.</strong></td></tr>';
  247. }
  248. else
  249. {
  250. // Script is working properly
  251. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Foundation Manager</strong></font></td>
  252. <td><strong>Inspecting Transaction Foundations...</strong></td></tr>';
  253. }
  254. }
  255. else
  256. {
  257. $body_string .= '<tr><td align="center"><img src="img/arrow.gif" alt="" /></td><td><font color="#b0a454"><strong>Foundation Manager</strong></font></td>
  258. <td><strong>Idle</strong></td></tr>';
  259. }
  260. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_heartbeat_active' LIMIT 1"),0,"field_data");
  261. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_last_heartbeat' LIMIT 1"),0,"field_data");
  262. if($script_loop_active > 0)
  263. {
  264. // Watchdog should still be active
  265. if((time() - $script_last_heartbeat) > 60) // Greater than double the loop time, something is wrong
  266. {
  267. // Script has stop was unexpected
  268. $body_string .= '<tr><td align="center"><img src="img/stalled.gif" alt="" /></td><td><font color="red"><strong>Watchdog</strong></font></td>
  269. <td><strong>Program Stalled.</strong></td></tr>';
  270. }
  271. else
  272. {
  273. // Script is working properly
  274. $body_string .= '<tr><td align="center"><img src="img/wait16trans.gif" alt="" /></td><td><font color="green"><strong>Watchdog</strong></font></td>
  275. <td><strong>Active</strong></td></tr>';
  276. }
  277. }
  278. else
  279. {
  280. $body_string .= '<tr><td align="center"><img src="img/stop.gif" alt="" /></td><td><font color="#b0a454"><strong>Watchdog</strong></font></td>
  281. <td><strong>Disabled</strong></td></tr>';
  282. }
  283. $body_string = $body_string . '</table>';
  284. $display_balance = db_cache_balance($my_public_key);
  285. $firewall_blocked = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'firewall_blocked_peer' LIMIT 1"),0,"field_data");
  286. if($firewall_blocked == "1")
  287. {
  288. $firewall_blocked = '<tr><td colspan="3"><font color="#827f00"><strong>*** Operating in Outbound Only Mode ***</strong></font></td></tr>';
  289. }
  290. else
  291. {
  292. $firewall_blocked = NULL;
  293. }
  294. $time_sync_error = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'time_sync_error' LIMIT 1"),0,"field_data");
  295. if($time_sync_error == "1")
  296. {
  297. $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>';
  298. }
  299. else
  300. {
  301. $time_sync_error = NULL;
  302. }
  303. $text_bar = '<table border="0"><tr><td width="250"><strong>Current Server Balance: <font color="green">' . number_format($display_balance) . '</font></strong></td>
  304. <td width="180"><strong>Peer Time: <font color="blue">' . time() . '</font></strong></td>
  305. <td><strong><font color="#827f00">' . tk_time_convert(transaction_cycle(1) - time()) . '</font> until next cycle</strong></td></tr>
  306. ' . $firewall_blocked . $time_sync_error . '</table>';
  307. $quick_info = 'Check on the Status of the Timekoin inner workings.';
  308. $home_update = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'refresh_realtime_home' LIMIT 1"),0,"field_data");
  309. home_screen("Realtime Server Status", $text_bar, $body_string, $quick_info , $home_update);
  310. exit;
  311. }
  312. //****************************************************************************
  313. if($_GET["menu"] == "peerlist")
  314. {
  315. if($_GET["remove"] == "peer")
  316. {
  317. // Manually remove this peer
  318. $sql = "DELETE FROM `active_peer_list` WHERE `active_peer_list`.`IP_Address` = '" . $_POST["ip"] . "' AND `active_peer_list`.`domain` = '" . $_POST["domain"] . "' LIMIT 1";
  319. mysql_query($sql);
  320. }
  321. if($_GET["save"] == "peer" && empty($_POST["edit_port"]) == FALSE)
  322. {
  323. // Save manual peer edit
  324. if($_POST["perm_peer"] == "perm")
  325. {
  326. $join_peer_list = '0';
  327. }
  328. else
  329. {
  330. $join_peer_list = 'UNIX_TIMESTAMP()';
  331. }
  332. $sql = "UPDATE `active_peer_list` SET `last_heartbeat` = UNIX_TIMESTAMP() ,`join_peer_list` = $join_peer_list , `failed_sent_heartbeat` = '0',
  333. `IP_Address` = '" . $_POST["edit_ip"] . "', `domain` = '" . $_POST["edit_domain"] . "', `subfolder` = '" . $_POST["edit_subfolder"] . "', `port_number` = '" . $_POST["edit_port"] . "'
  334. WHERE `active_peer_list`.`IP_Address` = '" . $_POST["update_ip"] . "' AND `active_peer_list`.`domain` = '" . $_POST["update_domain"] . "' LIMIT 1";
  335. mysql_query($sql);
  336. }
  337. if($_GET["save"] == "newpeer" && empty($_POST["edit_port"]) == FALSE)
  338. {
  339. // Manually insert new peer
  340. $sql = "INSERT INTO `active_peer_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`last_heartbeat` ,`join_peer_list` ,`failed_sent_heartbeat`)
  341. VALUES ('" . $_POST["edit_ip"] . "', '" . $_POST["edit_domain"] . "', '" . $_POST["edit_subfolder"] . "', '" . $_POST["edit_port"] . "', UNIX_TIMESTAMP() , UNIX_TIMESTAMP() , '0')";
  342. mysql_query($sql);
  343. }
  344. if($_GET["save"] == "firstcontact")
  345. {
  346. // Wipe Current First Contact Server List and Save the New List
  347. $field_numbers = intval($_POST["field_numbers"]);
  348. if($field_numbers > 0)
  349. {
  350. mysql_query("DELETE FROM `options` WHERE `options`.`field_name` = 'first_contact_server'");
  351. while($field_numbers > 0)
  352. {
  353. if(empty($_POST["first_contact_ip$field_numbers"]) == FALSE || empty($_POST["first_contact_domain$field_numbers"]) == FALSE)
  354. {
  355. $sql = "INSERT INTO `options` (`field_name` ,`field_data`)
  356. VALUES ('first_contact_server', '---ip=" . $_POST["first_contact_ip$field_numbers"] .
  357. "---domain=" . $_POST["first_contact_domain$field_numbers"] .
  358. "---subfolder=" . $_POST["first_contact_subfolder$field_numbers"] .
  359. "---port=" . $_POST["first_contact_port$field_numbers"] . "---end')";
  360. mysql_query($sql);
  361. }
  362. $field_numbers--;
  363. }
  364. }
  365. }
  366. if($_GET["edit"] == "peer")
  367. {
  368. $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr><th>IP Address</th>
  369. <th>Domain</th><th>Subfolder</th><th>Port Number</th><th></th><th></th></tr>';
  370. if($_GET["type"] == "new")
  371. {
  372. // Manually add a peer
  373. $body_string .= '<FORM ACTION="index.php?menu=peerlist&save=newpeer" METHOD="post"><tr>
  374. <td class="style2"><input type="text" name="edit_ip" size="13" /></td>
  375. <td class="style2"><input type="text" name="edit_domain" size="20" /></td>
  376. <td class="style2"><input type="text" name="edit_subfolder" size="10" /></td>
  377. <td class="style2"><input type="text" name="edit_port" size="5" /></td>
  378. <td><input type="image" src="img/save-icon.gif" name="submit1" border="0"></FORM></td><td>
  379. <FORM ACTION="index.php?menu=peerlist" METHOD="post">
  380. <input type="image" src="img/stop.gif" name="submit2" border="0"></FORM>
  381. </td></tr>';
  382. $body_string .= '</table></div>';
  383. }
  384. else if($_GET["type"] == "firstcontact")
  385. {
  386. $sql = "SELECT * FROM `options` WHERE `field_name` = 'first_contact_server'";
  387. $sql_result = mysql_query($sql);
  388. $sql_num_results = mysql_num_rows($sql_result) + 2;
  389. $counter = 1;
  390. $body_string .= '<FORM ACTION="index.php?menu=peerlist&save=firstcontact" METHOD="post">';
  391. for ($i = 0; $i < $sql_num_results; $i++)
  392. {
  393. $sql_row = mysql_fetch_array($sql_result);
  394. $peer_ip = find_string("---ip=", "---domain", $sql_row["field_data"]);
  395. $peer_domain = find_string("---domain=", "---subfolder", $sql_row["field_data"]);
  396. $peer_subfolder = find_string("---subfolder=", "---port", $sql_row["field_data"]);
  397. $peer_port_number = find_string("---port=", "---end", $sql_row["field_data"]);
  398. $body_string .= '<tr><td class="style2"><input type="text" name="first_contact_ip' . $counter . '" size="13" value="' . $peer_ip . '" /></br></br></td>
  399. <td class="style2" valign="top"><input type="text" name="first_contact_domain' . $counter . '" size="20" value="' . $peer_domain . '" /></td>
  400. <td class="style2" valign="top"><input type="text" name="first_contact_subfolder' . $counter . '" size="10" value="' . $peer_subfolder . '" /></td>
  401. <td class="style2" valign="top"><input type="text" name="first_contact_port' . $counter . '" size="5" value="' . $peer_port_number . '" /></td>
  402. </td></tr>';
  403. $counter++;
  404. }
  405. $body_string .= '<input type="hidden" name="field_numbers" value="' . ($counter - 1) . '">
  406. <tr><td colspan="2"><input type="submit" value="Save First Contact Servers"/></FORM></td></tr>';
  407. $body_string .= '</table></div>';
  408. }
  409. else
  410. {
  411. // Manually edit this peer
  412. $sql = "SELECT * FROM `active_peer_list` WHERE `IP_Address` = '" . $_POST["ip"] ."' AND `domain` = '" . $_POST["domain"] ."' LIMIT 1";
  413. $sql_result = mysql_query($sql);
  414. $sql_row = mysql_fetch_array($sql_result);
  415. $body_string .= '<FORM ACTION="index.php?menu=peerlist&save=peer" METHOD="post"><tr>
  416. <td class="style2"><input type="text" name="edit_ip" size="13" value="' . $sql_row["IP_Address"] . '" /></br></br>
  417. <select name="perm_peer"><option value="expires" SELECTED>Purge When Inactive</option><option value="perm">Do Not Purge</select></td>
  418. <td class="style2" valign="top"><input type="text" name="edit_domain" size="20" value="' . $sql_row["domain"] . '" /></td>
  419. <td class="style2" valign="top"><input type="text" name="edit_subfolder" size="10" value="' . $sql_row["subfolder"] . '" /></td>
  420. <td class="style2" valign="top"><input type="text" name="edit_port" size="5" value="' . $sql_row["port_number"] . '" /></td>
  421. <td valign="top"><input type="hidden" name="update_ip" value="' . $sql_row["IP_Address"] . '">
  422. <input type="hidden" name="update_domain" value="' . $sql_row["domain"] . '">
  423. <input type="image" src="img/save-icon.gif" name="submit1" border="0"></FORM></td>
  424. <td valign="top"><FORM ACTION="index.php?menu=peerlist" METHOD="post">
  425. <input type="image" src="img/stop.gif" name="submit2" border="0"></FORM>
  426. </td></tr>';
  427. $body_string .= '</table></div>';
  428. }
  429. $sql = "SELECT * FROM `active_peer_list`";
  430. $active_peers = mysql_num_rows(mysql_query($sql));
  431. $sql = "SELECT * FROM `new_peers_list`";
  432. $new_peers = mysql_num_rows(mysql_query($sql));
  433. $peer_number_bar = '<strong>Active Peers: <font color="green">' . $active_peers . '</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Peers in Reserve: <font color="blue">' . $new_peers . '</font></strong>';
  434. $quick_info = 'Shows all Active Peers.</br></br>
  435. You can manually delete or edit peers in this section.</br></br>
  436. <font color="blue">First Contact Servers</font> can be changed, deleted, or new ones added to the bottom of the list.';
  437. home_screen('Realtime Network Peer List', $peer_number_bar, $body_string , $quick_info);
  438. }
  439. else
  440. {
  441. // Default screen
  442. $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr>
  443. <th><p style="font-size:10px;">IP Address</p></th><th><p style="font-size:10px;">Domain</p></th>
  444. <th><p style="font-size:10px;">Subfolder</p></th><th><p style="font-size:10px;">Port Number</p></th>
  445. <th><p style="font-size:10px;">Last Heartbeat</p></th><th><p style="font-size:10px;">Joined</p></th>
  446. <th><p style="font-size:10px;">Failed Heartbeat</p></th><th></th><th></th></tr>';
  447. if($_GET["show"] == "reserve")
  448. {
  449. $sql = "SELECT * FROM `new_peers_list`";
  450. }
  451. else
  452. {
  453. $sql = "SELECT * FROM `active_peer_list`";
  454. }
  455. $sql_result = mysql_query($sql);
  456. $sql_num_results = mysql_num_rows($sql_result);
  457. for ($i = 0; $i < $sql_num_results; $i++)
  458. {
  459. $sql_row = mysql_fetch_array($sql_result);
  460. if($_GET["show"] != "reserve")
  461. {
  462. $last_heartbeat = time() - $sql_row["last_heartbeat"];
  463. $last_heartbeat = tk_time_convert($last_heartbeat);
  464. if($sql_row["join_peer_list"] == 0)
  465. {
  466. $joined = 'P';
  467. $permanent1 = '<font color="blue">';
  468. $permanent2 = '</font>';
  469. }
  470. else
  471. {
  472. $joined = time() - $sql_row["join_peer_list"];
  473. $joined = tk_time_convert($joined);
  474. $permanent1 = NULL;
  475. $permanent2 = NULL;
  476. }
  477. }
  478. $body_string .= '<tr>
  479. <td class="style2"><p style="word-wrap:break-word; width:85px; font-size:10px;">' . $permanent1 . $sql_row["IP_Address"] . $permanent2 . '</p></td>
  480. <td class="style2"><p style="word-wrap:break-word; width:130px; font-size:10px;">' . $permanent1 . $sql_row["domain"] . $permanent2 . '</p></td>
  481. <td class="style2"><p style="word-wrap:break-word; width:55px; font-size:10px;">' . $permanent1 . $sql_row["subfolder"] . $permanent2 . '</p></td>
  482. <td class="style2"><p style="word-wrap:break-word; font-size:10px;">' . $permanent1 . $sql_row["port_number"] . $permanent2 . '</p></td>
  483. <td class="style2"><p style="word-wrap:break-word; font-size:11px;">' . $permanent1 . $last_heartbeat . $permanent2 . '</p></td>
  484. <td class="style2"><p style="word-wrap:break-word; font-size:11px;">' . $permanent1 . $joined . $permanent2 . '</p></td>
  485. <td class="style2"><p style="word-wrap:break-word; font-size:11px;">' . $permanent1 . $sql_row["failed_sent_heartbeat"] . $permanent2 . '</p></td>';
  486. if($_GET["show"] == "reserve")
  487. {
  488. $body_string .= '<td></td><td></td></tr>';
  489. }
  490. else
  491. {
  492. $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">
  493. <input type="hidden" name="ip" value="' . $sql_row["IP_Address"] . '">
  494. <input type="hidden" name="domain" value="' . $sql_row["domain"] . '">
  495. </FORM></td><td>
  496. <FORM ACTION="index.php?menu=peerlist&edit=peer" METHOD="post"><input type="image" src="img/edit-icon.gif" name="edit' . $i . '" border="0">
  497. <input type="hidden" name="ip" value="' . $sql_row["IP_Address"] . '">
  498. <input type="hidden" name="domain" value="' . $sql_row["domain"] . '">
  499. </FORM>
  500. </td></tr>';
  501. }
  502. }
  503. $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>
  504. <td colspan="3"><FORM ACTION="index.php?menu=peerlist&edit=peer&type=new" METHOD="post"><input type="submit" value="Add New Peer"/></FORM></td>
  505. <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>';
  506. $sql = "SELECT * FROM `new_peers_list`";
  507. $new_peers = mysql_num_rows(mysql_query($sql));
  508. if($_GET["show"] == "reserve")
  509. {
  510. $sql = "SELECT * FROM `active_peer_list`";
  511. $sql_num_results = mysql_num_rows(mysql_query($sql));
  512. }
  513. $peer_number_bar = '<strong>Active Peers: <font color="green">' . $sql_num_results . '</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Peers in Reserve: <font color="blue">' . $new_peers . '</font></strong>';
  514. $quick_info = 'Shows all Active Peers.</br></br>You can manually delete or edit peers in this section.
  515. </br></br>Peers in <font color="blue">Blue</font> will not expire after 5 minutes of inactivity.';
  516. $peerlist_update = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'refresh_realtime_peerlist' LIMIT 1"),0,"field_data");
  517. if($_GET["show"] == "reserve")
  518. {
  519. home_screen('Reserve Peer List', $peer_number_bar, $body_string , $quick_info);
  520. }
  521. else
  522. {
  523. home_screen('Realtime Network Peer List', $peer_number_bar, $body_string , $quick_info, $peerlist_update);
  524. }
  525. }
  526. exit;
  527. }
  528. //****************************************************************************
  529. if($_GET["menu"] == "system")
  530. {
  531. if($_GET["peer_settings"] == "change")
  532. {
  533. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["max_peers"] . "' WHERE `options`.`field_name` = 'max_active_peers' LIMIT 1";
  534. if(mysql_query($sql) == TRUE)
  535. {
  536. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["max_new_peers"] . "' WHERE `options`.`field_name` = 'max_new_peers' LIMIT 1";
  537. if(mysql_query($sql) == TRUE)
  538. {
  539. $server_code = '</br><font color="green"><strong>Peer Settings Updated...</strong></font></br></br>';
  540. }
  541. }
  542. }
  543. if($_GET["server_settings"] == "change")
  544. {
  545. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["domain"] . "' WHERE `options`.`field_name` = 'server_domain' LIMIT 1";
  546. if(mysql_query($sql) == TRUE)
  547. {
  548. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["subfolder"] . "' WHERE `options`.`field_name` = 'server_subfolder' LIMIT 1";
  549. if(mysql_query($sql) == TRUE)
  550. {
  551. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["port"] . "' WHERE `options`.`field_name` = 'server_port_number' LIMIT 1";
  552. if(mysql_query($sql) == TRUE)
  553. {
  554. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["max_request"] . "' WHERE `options`.`field_name` = 'server_request_max' LIMIT 1";
  555. if(mysql_query($sql) == TRUE)
  556. {
  557. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["allow_LAN"] . "' WHERE `options`.`field_name` = 'allow_LAN_peers' LIMIT 1";
  558. if(mysql_query($sql) == TRUE)
  559. {
  560. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["allow_ambient"] . "' WHERE `options`.`field_name` = 'allow_ambient_peer_restart' LIMIT 1";
  561. if(mysql_query($sql) == TRUE)
  562. {
  563. $server_code = '</br><font color="blue"><strong>Server Settings Updated...</strong></font></br></br>';
  564. }
  565. }
  566. }
  567. }
  568. }
  569. }
  570. }
  571. if($_GET["stop"] == "watchdog")
  572. {
  573. $watchdog_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_heartbeat_active' LIMIT 1"),0,"field_data");
  574. $watchdog_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'watchdog_last_heartbeat' LIMIT 1"),0,"field_data");
  575. if($watchdog_loop_active > 0)
  576. {
  577. // Watchdog should still be active
  578. if((time() - $watchdog_last_heartbeat) > 60) // Greater than double the loop time, something is wrong
  579. {
  580. // Watchdog stop was unexpected
  581. $sql = "UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'watchdog_heartbeat_active' LIMIT 1";
  582. if(mysql_query($sql) == TRUE)
  583. {
  584. $server_code = '</br><font color="red"><strong>Watchdog was already Stopped...</strong></font></br></br>';
  585. }
  586. }
  587. else
  588. {
  589. // Set database to flag watchdog to stop
  590. $sql = "UPDATE `main_loop_status` SET `field_data` = '3' WHERE `main_loop_status`.`field_name` = 'watchdog_heartbeat_active' LIMIT 1";
  591. if(mysql_query($sql) == TRUE)
  592. {
  593. $server_code = '</br><font color="blue"><strong>Watchdog Stopping...</strong></font></br></br>';
  594. }
  595. }
  596. }
  597. else
  598. {
  599. $server_code = '</br><font color="red"><strong>Watchdog was already Stopped...</strong></font></br></br>';
  600. }
  601. }
  602. if($_GET["stop"] == "main")
  603. {
  604. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"),0,"field_data");
  605. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_last_heartbeat' LIMIT 1"),0,"field_data");
  606. if($script_loop_active > 0)
  607. {
  608. // Main should still be active
  609. if((time() - $script_last_heartbeat) > 30) // Greater than triple the loop time, something is wrong
  610. {
  611. // Main stop was unexpected
  612. $sql = "UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
  613. if(mysql_query($sql) == TRUE)
  614. {
  615. $server_code = '</br><font color="red"><strong>Timekoin Main Processor was already Stopped...</strong></font></br></br>';
  616. // Clear transaction queue to avoid unnecessary peer confusion
  617. mysql_query("TRUNCATE TABLE `transaction_queue`");
  618. }
  619. }
  620. else
  621. {
  622. // Set database to flag watchdog to stop
  623. $sql = "UPDATE `main_loop_status` SET `field_data` = '3' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
  624. if(mysql_query($sql) == TRUE)
  625. {
  626. $server_code = '</br><font color="blue"><strong>Timekoin Main Processor Stopping...</strong></font></br></br>';
  627. // Clear transaction queue to avoid unnecessary peer confusion
  628. mysql_query("TRUNCATE TABLE `transaction_queue`");
  629. }
  630. }
  631. }
  632. else
  633. {
  634. $server_code = '</br><font color="red"><strong>Timekoin Main Processor was already Stopped...</strong></font></br></br>';
  635. // Clear transaction queue to avoid unnecessary peer confusion
  636. mysql_query("TRUNCATE TABLE `transaction_queue`");
  637. }
  638. }
  639. if($_GET["stop"] == "emergency")
  640. {
  641. $script_loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"),0,"field_data");
  642. $script_last_heartbeat = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'main_last_heartbeat' LIMIT 1"),0,"field_data");
  643. if($script_loop_active > 0)
  644. {
  645. // Main should still be active
  646. if((time() - $script_last_heartbeat) > 30) // Greater than triple the loop time, something is wrong
  647. {
  648. // Main stop was unexpected
  649. $sql = "UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
  650. if(mysql_query($sql) == TRUE)
  651. {
  652. $server_code = '</br><font color="red"><strong>Entire Timekoin System has been Halted!</strong></font></br></br>';
  653. activate(TIMEKOINSYSTEM, 0);
  654. }
  655. }
  656. else
  657. {
  658. // Set database to flag watchdog to stop
  659. $sql = "UPDATE `main_loop_status` SET `field_data` = '3' WHERE `main_loop_status`.`field_name` = 'main_heartbeat_active' LIMIT 1";
  660. if(mysql_query($sql) == TRUE)
  661. {
  662. $server_code = '</br><font color="red"><strong>Entire Timekoin System has been Halted!</strong></font></br></br>';
  663. activate(TIMEKOINSYSTEM, 0);
  664. }
  665. }
  666. }
  667. else
  668. {
  669. $server_code = '</br><font color="red"><strong>Entire Timekoin System has been Halted!</strong></font></br></br>';
  670. activate(TIMEKOINSYSTEM, 0);
  671. }
  672. }
  673. if($_GET["code"] == "1")
  674. {
  675. $server_code = '</br><font color="green"><strong>Main Timekoin Processing Started...</strong></font></br></br>';
  676. }
  677. if($_GET["code"] == "99")
  678. {
  679. $server_code = '</br><font color="blue"><strong>Timekoin Already Active...</strong></font></br></br>';
  680. }
  681. if($_GET["code"] == "2")
  682. {
  683. $server_code = '</br><font color="green"><strong>Watchdog Started...</strong></font></br></br>';
  684. }
  685. if($_GET["code"] == "89")
  686. {
  687. $server_code = '</br><font color="blue"><strong>Watchdog Already Active...</strong></font></br></br>';
  688. }
  689. if($_GET["time"] == "poll")
  690. {
  691. $context = stream_context_create(array('http' => array('header'=>'Connection: close'))); // Force close socket after complete
  692. ini_set('user_agent', 'Timekoin Server (GUI) v' . TIMEKOIN_VERSION);
  693. ini_set('default_socket_timeout', 3); // Timeout for request in seconds
  694. $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" >
  695. <tr><th>Peer</th><th>Time</th><th>Variance</th></tr>';
  696. // Add more possible peers to the new peer list by polling what the active peers have
  697. $sql = "SELECT * FROM `active_peer_list`";
  698. $sql_result = mysql_query($sql);
  699. $sql_num_results = mysql_num_rows($sql_result);
  700. $response_counter = 0;
  701. $variance_total = 0;
  702. for ($i = 0; $i < $sql_num_results; $i++)
  703. {
  704. $sql_row = mysql_fetch_array($sql_result);
  705. $ip_address = $sql_row["IP_Address"];
  706. $domain = $sql_row["domain"];
  707. $subfolder = $sql_row["subfolder"];
  708. $port_number = $sql_row["port_number"];
  709. if(empty($domain) == TRUE)
  710. {
  711. $site_address = $ip_address;
  712. }
  713. else
  714. {
  715. $site_address = $domain;
  716. }
  717. if($port_number == 443)
  718. {
  719. $ssl = "s";
  720. }
  721. else
  722. {
  723. $ssl = NULL;
  724. }
  725. //Use site address name to poll
  726. $poll_peer = filter_sql(file_get_contents("http$ssl://$site_address:$port_number/$subfolder/peerlist.php?action=polltime", FALSE, $context, NULL, 12));
  727. $my_time = time();
  728. if($my_time == $poll_peer && empty($poll_peer) == FALSE)
  729. {
  730. $variance = '0 seconds';
  731. $response_counter++;
  732. }
  733. else if(empty($poll_peer) == FALSE)
  734. {
  735. $variance = $my_time - $poll_peer;
  736. $response_counter++;
  737. $variance_total = $variance_total + abs($variance);
  738. if($variance > 1)
  739. {
  740. $variance = '+' . $variance . ' seconds';
  741. }
  742. else if($variance == 1)
  743. {
  744. $variance = '+' . $variance . ' second';
  745. }
  746. else if($variance == -1)
  747. {
  748. $variance = $variance . ' second';
  749. }
  750. else
  751. {
  752. $variance = $variance . ' seconds';
  753. }
  754. }
  755. else
  756. {
  757. $variance = 'No Response';
  758. }
  759. $body_string .= '<tr><td class="style2"><p style="word-wrap:break-word; font-size:12px;">' . $site_address . ':' . $port_number . '/' . $subfolder . '</p></td>';
  760. $body_string .= '<td class="style2"><p style="font-size:12px;">' . $poll_peer . '</p></td>';
  761. $body_string .= '<td class="style2"><p style="font-size:12px;">' . $variance . '</p></td></tr>';
  762. }
  763. $body_string .= '</table></div>';
  764. $variance_average = round($variance_total / $response_counter);
  765. if($variance_average > 15)
  766. {
  767. $variance_average = '<font color="red">' . $variance_average . '</font> seconds';
  768. }
  769. else if($variance_average == 1)
  770. {
  771. $variance_average = '<font color="green">' . $variance_average . '</font> second';
  772. }
  773. else if($variance_average <= 15 && $variance_average > 1)
  774. {
  775. $variance_average = '<font color="blue">' . $variance_average . '</font> seconds';
  776. }
  777. else
  778. {
  779. $variance_average = '<font color="green">' . $variance_average . '</font> seconds';
  780. }
  781. $body_string .= '<strong>Variance Average: ' . $variance_average . '</strong></br></br>';
  782. }
  783. else
  784. {
  785. $body_string = system_screen();
  786. $body_string .= $server_code;
  787. }
  788. $quick_info = '<strong>Start</strong> will activate all Timekoin Processing.</br></br>
  789. <strong>Stop</strong> will halt Timekoin from further processing.</br></br>
  790. <strong>Emergency Stop</strong> will halt Timekoin from further processing and Block all Peer Internet activity.</br></br>
  791. <strong>Max Peer Query</strong> is the per 10 seconds limit imposed on each individual peer before being banned for 24 hours.</br></br>
  792. <strong>Allow LAN Peers</strong> controls if LAN peers will be allowed to populate the peer list.</br></br>
  793. <strong>Allow Ambient Peer Restarts</strong> controls if other peers can restart Timekoin from unknown failures.</br></br>
  794. <strong>Variance</strong> of 15 seconds or less with the other peers is good.';
  795. home_screen('System Settings', system_service_bar(), $body_string , $quick_info);
  796. exit;
  797. }
  798. //****************************************************************************
  799. if($_GET["menu"] == "options")
  800. {
  801. if($_GET["menu"] == "options" && $_GET["password"] == "change")
  802. {
  803. if(empty($_POST["current_username"]) == FALSE && empty($_POST["new_username"]) == FALSE && empty($_POST["confirm_username"]) == FALSE)
  804. {
  805. // Attemping to change username
  806. if($_POST["current_username"] == $_SESSION["login_username"])
  807. {
  808. // Right username, does the new username match the confirmation username?
  809. if($_POST["new_username"] == $_POST["confirm_username"])
  810. {
  811. // Write new hash to database for username and change the session username
  812. $username_hash = hash('sha256', $_POST["confirm_username"]);
  813. $sql = "UPDATE `options` SET `field_data` = '$username_hash' WHERE `options`.`field_name` = 'username' LIMIT 1";
  814. if(mysql_query($sql) == TRUE)
  815. {
  816. // Update success, now change the session username
  817. $_SESSION["login_username"] = $_POST["confirm_username"];
  818. $username_change = TRUE;
  819. }
  820. }
  821. }
  822. }
  823. if(empty($_POST["current_password"]) == FALSE && empty($_POST["new_password"]) == FALSE && empty($_POST["confirm_password"]) == FALSE)
  824. {
  825. $password_hash = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'password' LIMIT 1"),0,"field_data");
  826. $current_password_hash = hash('sha256', $_POST["current_password"]);
  827. $new_password_hash = hash('sha256', $_POST["new_password"]);
  828. // Attemping to change password
  829. if($current_password_hash == $password_hash)
  830. {
  831. // Right password, does the new password match the confirmation password?
  832. if($_POST["new_password"] == $_POST["confirm_password"])
  833. {
  834. // Write new hash to database for username and change the session username
  835. $sql = "UPDATE `options` SET `field_data` = '$new_password_hash' WHERE `options`.`field_name` = 'password' LIMIT 1";
  836. if(mysql_query($sql) == TRUE)
  837. {
  838. $password_change = TRUE;
  839. }
  840. }
  841. }
  842. }
  843. $body_text = options_screen2();
  844. if($username_change == TRUE)
  845. {
  846. $body_text = $body_text . '<font color="blue"><strong>Username Change Complete!</strong></font></br>';
  847. }
  848. else
  849. {
  850. $body_text = $body_text . '<strong>Username Has Not Been Changed</strong></br>';
  851. }
  852. if($password_change == TRUE)
  853. {
  854. $body_text = $body_text . '<font color="blue"><strong>Password Change Complete!</strong></font>';
  855. }
  856. else
  857. {
  858. $body_text = $body_text . '<strong>Password Has Not Been Changed</strong>';
  859. }
  860. } // End username/password change check
  861. if($_GET["menu"] == "options" && $_GET["refresh"] == "change")
  862. {
  863. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["home_update"] . "' WHERE `options`.`field_name` = 'refresh_realtime_home' LIMIT 1";
  864. if(mysql_query($sql) == TRUE)
  865. {
  866. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["peerlist_update"] . "' WHERE `options`.`field_name` = 'refresh_realtime_peerlist' LIMIT 1";
  867. if(mysql_query($sql) == TRUE)
  868. {
  869. $sql = "UPDATE `options` SET `field_data` = '" . $_POST["queue_update"] . "' WHERE `options`.`field_name` = 'refresh_realtime_queue' LIMIT 1";
  870. if(mysql_query($sql) == TRUE)
  871. {
  872. $hash_code = $_POST["hash_code"];
  873. // Sanitization of message !#$%&'*+-/=?^_`{|}~@.[] allowed
  874. $hash_code = filter_var($hash_code, FILTER_SANITIZE_EMAIL);
  875. // Filter symbols that might lead to an HTML access error
  876. $symbols = array("'", "%", "*", "$", "`", "?", "=", "~", "&", "#", "/", "+",);
  877. $hash_code = str_replace($symbols, "", $hash_code);
  878. $sql = "UPDATE `options` SET `field_data` = '" . $hash_code . "' WHERE `options`.`field_name` = 'server_hash_code' LIMIT 1";
  879. if(mysql_query($sql) == TRUE)
  880. {
  881. $refresh_change = TRUE;
  882. }
  883. }
  884. }
  885. }
  886. $body_text = options_screen2();
  887. if($refresh_change == TRUE)
  888. {
  889. $body_text .= '<font color="blue"><strong>Refresh Settings & Hash Code Update Saved!</strong></font></br>';
  890. }
  891. else
  892. {
  893. $body_text .= '<strong>Refresh / Hash Code Update ERROR...</strong></br>';
  894. }
  895. } // End refresh update save
  896. else if(empty($_GET["password"]) == TRUE && empty($_GET["refresh"]) == TRUE)
  897. {
  898. $body_text = options_screen2();
  899. }
  900. $quick_info = 'You may change the username and password individually or at the same time.</br></br>
  901. Remember that usernames and passwords are Case Sensitive.
  902. </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.';
  903. home_screen("Options & Personal Settings", options_screen(), $body_text , $quick_info);
  904. exit;
  905. }
  906. //****************************************************************************
  907. if($_GET["menu"] == "generation")
  908. {
  909. if($_GET["generate"] == "enable")
  910. {
  911. $sql = "UPDATE `options` SET `field_data` = '1' WHERE `options`.`field_name` = 'generate_currency' LIMIT 1";
  912. mysql_query($sql);
  913. }
  914. else if($_GET["generate"] == "disable")
  915. {
  916. $sql = "UPDATE `options` SET `field_data` = '0' WHERE `options`.`field_name` = 'generate_currency' LIMIT 1";
  917. mysql_query($sql);
  918. }
  919. $sql = "SELECT * FROM `generating_peer_queue`";
  920. $generate_peer_queue = mysql_num_rows(mysql_query($sql));
  921. $generate_currency_enabled = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'generate_currency' LIMIT 1"),0,"field_data");
  922. $sql = "SELECT * FROM `generating_peer_list`";
  923. $sql_result = mysql_query($sql);
  924. $sql_num_results = mysql_num_rows($sql_result);
  925. $generating_peers_now = $sql_num_results;
  926. if($generate_currency_enabled == "1")
  927. {
  928. $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
  929. $join_peer_list = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `public_key` = '$my_public_key' LIMIT 1"),0,"join_peer_list");
  930. $last_generation = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `public_key` = '$my_public_key' LIMIT 1"),0,"last_generation");
  931. if(time() - $join_peer_list < 3600)
  932. {
  933. // Can't generate yet
  934. $generate_currency = 'Generation <font color="green"><strong>Enabled</strong></font>';
  935. $generate_rate = '@ <font color="green"><strong>' . peer_gen_amount($my_public_key) . '</strong></font> per Cycle';
  936. $continuous_production = '<font color="blue">Generation not allowed for ' . tk_time_convert(3600 - (time() - $join_peer_list)) . '</font>';
  937. }
  938. else if($join_peer_list === FALSE)
  939. {
  940. // Not elected to the generating peer list yet
  941. $generate_currency = 'Generation <font color="green"><strong>Enabled</strong></font>';
  942. $generate_rate = '@ <font color="green"><strong>' . peer_gen_amount($my_public_key) . '</strong></font> per Cycle';
  943. $continuous_production = '<font color="red"><strong>This Peer Has Not</br> Been Elected Yet</strong></font>';
  944. }
  945. else
  946. {
  947. $production_time = tk_time_convert(time() - $join_peer_list);
  948. $last_generation = tk_time_convert(time() - $last_generation);
  949. $generate_currency = 'Generation <font color="green"><strong>Enabled</strong></font>';
  950. $generate_rate = '@ <font color="green"><strong>' . peer_gen_amount($my_public_key) . '</strong></font> per Cycle';
  951. $continuous_production = 'Continuous Production for ' . $production_time . '</br>Last Generated ' . $last_generation . ' ago';
  952. }
  953. }
  954. else
  955. {
  956. $generate_currency = 'Generation <font color="red">Disabled</strong></font>';
  957. }
  958. $body_string = generation_body($generate_currency_enabled);
  959. if($_GET["generate"] == "showlist")
  960. {
  961. $default_public_key_font = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'public_key_font_size' LIMIT 1"),0,"field_data");
  962. $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
  963. $body_string = $body_string . '<hr></hr><strong>Current Generation List</strong>
  964. <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>';
  965. $sql = "SELECT * FROM `generating_peer_list` ORDER BY `join_peer_list` ASC";
  966. $sql_result = mysql_query($sql);
  967. $sql_num_results = mysql_num_rows($sql_result);
  968. for ($i = 0; $i < $sql_num_results; $i++)
  969. {
  970. $sql_row = mysql_fetch_array($sql_result);
  971. if($my_public_key == $sql_row["public_key"])
  972. {
  973. $public_key = '<p style="font-size:12px;"><font color="green"><strong>My Public Key</strong></font>';
  974. }
  975. else
  976. {
  977. $public_key = '<p style="word-wrap:break-word; width:325px; font-size:' . $default_public_key_font . 'px;">' . base64_encode($sql_row["public_key"]);
  978. }
  979. $body_string .= '<tr>
  980. <td class="style2">' . $public_key . '</p></td>
  981. <td class="style2"><p style="font-size:10px;">' . unix_timestamp_to_human($sql_row["join_peer_list"]) . '</p></td>
  982. <td class="style2"><p style="font-size:10px;">' . tk_time_convert(time() - $sql_row["last_generation"]) . ' ago</p></td></tr>';
  983. }
  984. $body_string .= '</table></div>';
  985. }
  986. if($_GET["generate"] == "showqueue")
  987. {
  988. $default_public_key_font = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'public_key_font_size' LIMIT 1"),0,"field_data");
  989. $my_public_key = mysql_result(mysql_query("SELECT * FROM `my_keys` WHERE `field_name` = 'server_public_key' LIMIT 1"),0,"field_data");
  990. $body_string .= '<hr></hr><strong>Election Queue List</strong>
  991. <div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" ><tr><th>Public Key</th><th>Join Queue</th></tr>';
  992. $sql = "SELECT * FROM `generating_peer_queue` ORDER BY `timestamp` ASC";
  993. $sql_result = mysql_query($sql);
  994. $sql_num_results = mysql_num_rows($sql_result);
  995. for ($i = 0; $i < $sql_num_results; $i++)
  996. {
  997. $sql_row = mysql_fetch_array($sql_result);
  998. if($my_public_key == $sql_row["public_key"])
  999. {
  1000. $public_key = '<p style="font-size:12px;"><font color="green"><strong>My Public Key</strong></font>';
  1001. }
  1002. else
  1003. {
  1004. $public_key = '<p style="word-wrap:break-word; width:425px; font-size:' . $default_public_key_font . 'px;">' . base64_encode($sql_row["public_key"]);
  1005. }
  1006. $body_string .= '<tr>
  1007. <td class="style2">' . $public_key . '</p></td>
  1008. <td class="style2"><p style="font-size:10px;">' . tk_time_convert(time() - $sql_row["timestamp"]) . ' ago</p></td></tr>';
  1009. }
  1010. $body_string .= '</table></div>';
  1011. }
  1012. // Next Election Calculator
  1013. // Determine when to run this by comparing the last digit the current block and
  1014. // the 3rd digit the generation time; when they match, run the gen key scoring.
  1015. $max_cycles_ahead = 200;
  1016. for ($i = 0; $i < $max_cycles_ahead; $i++)
  1017. {
  1018. $current_generation_cycle = transactio

Large files files are truncated, but you can click here to view the full file