Example #1
0
function MyMain($str)
{
    $str1 = $str;
    $str2 = $str1 . ", ktery jeste trochu obohatime";
    $x = put_string($str1, "\n", $str2, "\n");
    $p = find_string($str2, "text");
    $x = put_string("Pozice retezce \"text\" v \$str2: ", $p, "\n");
    $x = put_string("Zadejte posloupnost vsech malych pismen a-h, ");
    $x = put_string("aby se pismena v posloupnosti neopakovala:\n");
    $str1 = get_string();
    $str2 = sort_string($str1);
    while ($str2 !== "abcdefgh") {
        $x = put_string("Spatne zadana posloupnost, zkuste znovu:\n");
        $str1 = get_string();
        $str2 = sort_string($str1);
    }
    return 0;
}
Example #2
0
function check_crypt_balance_range($public_key, $block_start = 0, $block_end = 0)
{
    set_decrypt_mode();
    // Figure out which decrypt method can be best used
    //Initialize objects for Internal RSA decrypt
    if ($GLOBALS['decrypt_mode'] == 2) {
        require_once 'RSA.php';
        $rsa = new Crypt_RSA();
        $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
    }
    if ($block_start == 0 && $block_end == 0) {
        // Find every Time Koin sent to this public Key
        $sql = "SELECT public_key_from, public_key_to, crypt_data3, attribute FROM `transaction_history` WHERE `public_key_from` = '{$public_key}' OR `public_key_to` = '{$public_key}' ";
    } else {
        // Find every TimeKoin sent to and from this public Key in a certain time range.
        // Covert block to time.
        $start_time_range = TRANSACTION_EPOCH + $block_start * 300;
        $end_time_range = TRANSACTION_EPOCH + $block_end * 300;
        $sql = "SELECT public_key_from, public_key_to, crypt_data3, attribute FROM `transaction_history` WHERE (`public_key_from` = '{$public_key}' AND `timestamp` >= '{$start_time_range}' AND `timestamp` < '{$end_time_range}')\n\t\tOR (`public_key_to` = '{$public_key}' AND `timestamp` >= '{$start_time_range}' AND `timestamp` < '{$end_time_range}')";
    }
    $sql_result = mysql_query($sql);
    $sql_num_results = mysql_num_rows($sql_result);
    $crypto_balance = 0;
    $transaction_info;
    for ($i = 0; $i < $sql_num_results; $i++) {
        $sql_row = mysql_fetch_row($sql_result);
        $public_key_from = $sql_row[0];
        $public_key_to = $sql_row[1];
        $crypt3 = $sql_row[2];
        $attribute = $sql_row[3];
        if ($attribute == "G" && $public_key_from == $public_key_to) {
            // Currency Generation
            // Decrypt transaction information
            if ($GLOBALS['decrypt_mode'] == 2) {
                $rsa->loadKey($public_key_from);
                $transaction_info = $rsa->decrypt(base64_decode($crypt3));
            } else {
                $transaction_info = tk_decrypt($public_key_from, base64_decode($crypt3), TRUE);
            }
            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
            $crypto_balance += $transaction_amount_sent;
        }
        if ($attribute == "T" && $public_key_to == $public_key) {
            // Decrypt transaction information
            if ($GLOBALS['decrypt_mode'] == 2) {
                $rsa->loadKey($public_key_from);
                $transaction_info = $rsa->decrypt(base64_decode($crypt3));
            } else {
                $transaction_info = tk_decrypt($public_key_from, base64_decode($crypt3), TRUE);
            }
            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
            $crypto_balance += $transaction_amount_sent;
        }
        if ($attribute == "T" && $public_key_from == $public_key) {
            // Decrypt transaction information
            $transaction_info = tk_decrypt($public_key_from, base64_decode($crypt3));
            if ($GLOBALS['decrypt_mode'] == 2) {
                $rsa->loadKey($public_key_from);
                $transaction_info = $rsa->decrypt(base64_decode($crypt3));
            } else {
                $transaction_info = tk_decrypt($public_key_from, base64_decode($crypt3), TRUE);
            }
            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
            $crypto_balance -= $transaction_amount_sent;
        }
    }
    //
    // Unset variable to free up RAM
    unset($sql_result);
    return $crypto_balance;
}
Example #3
0
     }
     // End random time check
 }
 // End Transaction type G check
 if ($sql_row["attribute"] == "T") {
     // Check to make sure there is not a duplicate transaction already
     $found_public_key_queue = mysql_result(mysql_query("SELECT timestamp, public_key_from, hash FROM `transaction_history` WHERE `public_key_from` = '{$public_key}' AND `hash` = '{$hash_check}' LIMIT 1"), 0, "timestamp");
     if (empty($found_public_key_queue) == TRUE) {
         // Transaction isn't a duplicate, continue processing...
         $time_created = $sql_row["timestamp"];
         $crypt1 = $sql_row["crypt_data1"];
         $crypt2 = $sql_row["crypt_data2"];
         $crypt3 = $sql_row["crypt_data3"];
         // How much is this public key trying to send to another public key?
         $transaction_info = tk_decrypt($public_key, base64_decode($crypt3));
         $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
         $transaction_amount_sent_test = intval($transaction_amount_sent);
         if ($transaction_amount_sent_test == $transaction_amount_sent) {
             // Is a valid integer
             $amount_valid = TRUE;
         } else {
             // Is NOT a valid integer
             $amount_valid = FALSE;
         }
         // Validate transaction against known public key balance
         if (check_crypt_balance($public_key) >= $transaction_amount_sent && $transaction_amount_sent > 0 && $amount_valid == TRUE) {
             // Balance checks out
             // Check hash value for tampering of crypt1, crypt2, or crypt3 fields
             if (hash('sha256', $crypt1 . $crypt2 . $crypt3) == $hash_check) {
                 // Find destination public key
                 $public_key_to_1 = tk_decrypt($public_key, base64_decode($crypt1));
Example #4
0
 //************************************************************
 $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 2000000, "transclerk.php?action=transaction_data&block_number={$block_number}");
 $tc = 1;
 if (empty($poll_peer) == TRUE) {
     // Add failure points to the peer in case further issues
     modify_peer_grade($ip_address, $domain, $subfolder, $port_number, 4);
 }
 while (empty($poll_peer) == FALSE) {
     $transaction_timestamp = filter_sql(find_string("-----timestamp{$tc}=", "-----public_key_from{$tc}", $poll_peer));
     $transaction_public_key_from = find_string("-----public_key_from{$tc}=", "-----public_key_to{$tc}", $poll_peer);
     $transaction_public_key_to = find_string("-----public_key_to{$tc}=", "-----crypt1data{$tc}", $poll_peer);
     $transaction_crypt1 = filter_sql(find_string("-----crypt1data{$tc}=", "-----crypt2data{$tc}", $poll_peer));
     $transaction_crypt2 = filter_sql(find_string("-----crypt2data{$tc}=", "-----crypt3data{$tc}", $poll_peer));
     $transaction_crypt3 = filter_sql(find_string("-----crypt3data{$tc}=", "-----hash{$tc}", $poll_peer));
     $transaction_hash = filter_sql(find_string("-----hash{$tc}=", "-----attribute{$tc}", $poll_peer));
     $transaction_attribute = find_string("-----attribute{$tc}=", "-----end{$tc}", $poll_peer);
     if (empty($transaction_public_key_from) == TRUE && empty($transaction_public_key_to) == TRUE) {
         // No more data, break while loop
         break;
     }
     $transaction_public_key_from = filter_sql(base64_decode($transaction_public_key_from));
     $transaction_public_key_to = filter_sql(base64_decode($transaction_public_key_to));
     $found_duplicate = mysql_result(mysql_query("SELECT timestamp FROM `transaction_history` WHERE `timestamp` = '{$transaction_timestamp}' AND `public_key_from` = '{$transaction_public_key_from}' AND `hash` = '{$transaction_hash}' LIMIT 1"), 0, 0);
     // Check for valid attribute
     if ($transaction_attribute == "G" || $transaction_attribute == "T" || $transaction_attribute == "H") {
         if (empty($found_duplicate) == TRUE) {
             $sql = "INSERT INTO `transaction_history` (`timestamp`,`public_key_from`,`public_key_to`,`crypt_data1`,`crypt_data2`,`crypt_data3`, `hash`, `attribute`)\n\t\t\t\t\t\t\t\tVALUES ('{$transaction_timestamp}', '{$transaction_public_key_from}', '{$transaction_public_key_to}', '{$transaction_crypt1}', '{$transaction_crypt2}' , '{$transaction_crypt3}', '{$transaction_hash}' , '{$transaction_attribute}')";
             if (mysql_query($sql) == TRUE) {
                 // Flag for a re-check afterwards
                 $double_check_block = TRUE;
             }
Example #5
0
function check_crypt_balance_range($public_key, $block_start = 0, $block_end = 0)
{
    if ($block_start == 0 && $block_end == 0) {
        // Find every Time Koin sent to this public Key
        $sql = "SELECT public_key_from, public_key_to, crypt_data1, crypt_data2, crypt_data3, hash, attribute FROM `transaction_history` WHERE `public_key_to` = '{$public_key}'";
    } else {
        // Find every TimeKoin sent to this public Key in a certain time range.
        // Covert block to time.
        $start_time_range = TRANSACTION_EPOCH + $block_start * 300;
        $end_time_range = TRANSACTION_EPOCH + $block_end * 300;
        $sql = "SELECT * FROM `transaction_history` WHERE `public_key_to` = '{$public_key}' AND `timestamp` >= '{$start_time_range}' AND `timestamp` < '{$end_time_range}'";
    }
    $sql_result = mysql_query($sql);
    $sql_num_results = mysql_num_rows($sql_result);
    $crypto_balance = 0;
    for ($i = 0; $i < $sql_num_results; $i++) {
        $sql_row = mysql_fetch_row($sql_result);
        $public_key_from = $sql_row[1];
        $public_key_to = $sql_row[2];
        $crypt1 = $sql_row[3];
        $crypt2 = $sql_row[4];
        $crypt3 = $sql_row[5];
        $hash = $sql_row[6];
        $attribute = $sql_row[7];
        if ($attribute == "G" && $public_key_from == $public_key_to) {
            // Currency Generation
            // Decrypt transaction information
            openssl_public_decrypt(base64_decode($crypt3), $transaction_info, $public_key_from);
            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
            $crypto_balance += $transaction_amount_sent;
        }
        if ($attribute == "T") {
            // Decrypt transaction information
            openssl_public_decrypt(base64_decode($crypt3), $transaction_info, $public_key_from);
            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
            $crypto_balance += $transaction_amount_sent;
        }
    }
    //
    // Unset variable to free up RAM
    unset($sql_result);
    // END - Find every TimeKoin sent to this public Key
    // Find every TimeKoin sent FROM this public Key
    if ($block_start == 0 && $block_end == 0) {
        // Find every Time Koin sent to this public Key
        $sql = "SELECT public_key_from, public_key_to, crypt_data1, crypt_data2, crypt_data3, hash, attribute FROM `transaction_history` WHERE `public_key_from` = '{$public_key}'";
    } else {
        // Find every Time Koin sent to this public Key in a certain time range
        $sql = "SELECT * FROM `transaction_history` WHERE `public_key_from` = '{$public_key}' AND `timestamp` >= '{$start_time_range}' AND `timestamp` < '{$end_time_range}'";
    }
    $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_row($sql_result);
        $public_key_from = $sql_row[1];
        $public_key_to = $sql_row[2];
        $crypt1 = $sql_row[3];
        $crypt2 = $sql_row[4];
        $crypt3 = $sql_row[5];
        $hash = $sql_row[6];
        $attribute = $sql_row[7];
        if ($attribute == "T") {
            // Decrypt transaction information
            openssl_public_decrypt(base64_decode($crypt3), $transaction_info, $public_key_from);
            $transaction_amount_sent = find_string("AMOUNT=", "---TIME", $transaction_info);
            $crypto_balance -= $transaction_amount_sent;
        }
    }
    // END - Find every TimeKoin sent FROM this public Key
    return $crypto_balance;
}
Example #6
0
     call_script("main.php");
     // Use uPNP to map inbound ports for Windows systems
     if (getenv("OS") == "Windows_NT" && file_exists("utils\\upnpc.exe") == TRUE) {
         $server_port_number = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'server_port_number' LIMIT 1"), 0, "field_data");
         $server_IP = gethostbyname(trim(`hostname`));
         pclose(popen("start /B utils\\upnpc.exe -e Timekoin -a {$server_IP} {$server_port_number} {$server_port_number} TCP", "r"));
     }
     // Start any plugins
     $sql = "SELECT * FROM `options` WHERE `field_name` LIKE 'installed_plugins%' ORDER BY `options`.`field_name` 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);
         $plugin_file = find_string("---file=", "---enable", $sql_row["field_data"]);
         $plugin_enable = intval(find_string("---enable=", "---show", $sql_row["field_data"]));
         $plugin_service = find_string("---service=", "---end", $sql_row["field_data"]);
         if ($plugin_enable == TRUE && empty($plugin_service) == FALSE) {
             // Start Plugin Service
             call_script($plugin_file, 0, TRUE);
             // Log Service Start
             write_log("Started Plugin Service: {$plugin_service}", "MA");
         }
     }
     // Finish Starting Plugin Services
     header("Location: index.php?menu=system&code=1");
     exit;
 } else {
     // Something failed or database error
     header("Location: index.php?menu=system&code=99");
     exit;
 }
Example #7
0
                     if ($transaction_hash == $crypt_hash_check && $inside_transaction_hash == $final_hash_compare && strlen($transaction_public_key) > 300 && strlen($public_key_to) > 300 && $transaction_timestamp >= $current_transaction_cycle && $transaction_timestamp < $next_transaction_cycle && $valid_amount == TRUE) {
                         // Check for 100 public key limit in the transaction queue
                         $sql = "SELECT timestamp FROM `transaction_queue` WHERE `public_key` = '{$transaction_public_key}'";
                         $sql_result = mysql_query($sql);
                         $sql_num_results = mysql_num_rows($sql_result);
                         if ($sql_num_results < 100) {
                             // Transaction hash and real hash match.
                             mysql_query("INSERT INTO `transaction_queue` (`timestamp`,`public_key`,`crypt_data1`,`crypt_data2`,`crypt_data3`, `hash`, `attribute`)\n\t\t\t\t\t\t\tVALUES ('{$transaction_timestamp}', '{$transaction_public_key}', '{$transaction_crypt1}', '{$transaction_crypt2}' , '{$transaction_crypt3}', '{$transaction_hash}' , '{$transaction_attribute}')");
                         } else {
                             write_log("More Than 100 Transactions Trying to Queue for Key: " . base64_encode($transaction_public_key), "QC");
                         }
                     }
                 }
                 // End Empty Hash Check
                 $match_number++;
                 $current_hash = find_string("---queue{$match_number}=", "---end{$match_number}", $poll_peer);
             }
             // End While Loop
         }
         // End For Loop
         // Build queue hash after completion
         $transaction_queue_hash = queue_hash();
         // Store in database for quick reference from database
         mysql_query("UPDATE `options` SET `field_data` = '{$transaction_queue_hash}' WHERE `options`.`field_name` = 'transaction_queue_hash' LIMIT 1");
     }
     // End Compare Tallies
 }
 // If/then Check for valid times
 //***********************************************************************************
 //***********************************************************************************
 $loop_active = mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'queueclerk_heartbeat_active' LIMIT 1"), 0, 0);
Example #8
0
 /**
  * Function used to get file information using FFMPEG
  * @param FILE_PATH
  */
 function get_file_info($file_path = NULL)
 {
     if (!$path_source) {
         $path_source = $this->input_file;
     }
     $info['format'] = 'N/A';
     $info['duration'] = 'N/A';
     $info['size'] = 'N/A';
     $info['bitrate'] = 'N/A';
     $info['video_width'] = 'N/A';
     $info['video_height'] = 'N/A';
     $info['video_wh_ratio'] = 'N/A';
     $info['video_codec'] = 'N/A';
     $info['video_rate'] = 'N/A';
     $info['video_bitrate'] = 'N/A';
     $info['video_color'] = 'N/A';
     $info['audio_codec'] = 'N/A';
     $info['audio_bitrate'] = 'N/A';
     $info['audio_rate'] = 'N/A';
     $info['audio_channels'] = 'N/A';
     $info['path'] = $path_source;
     $cmd = FFPROBE . " -v quiet -print_format json -show_format -show_streams '" . $path_source . "' ";
     logData($cmd, 'command');
     $output = shell_output($cmd);
     logData($cmd, 'output');
     //$output = trim($output);
     //$output = preg_replace('/(\n]+){/', '', $output);
     $output = preg_replace('/([a-zA-Z 0-9\\r\\n]+){/', '{', $output, 1);
     $data = json_decode($output, true);
     if ($data['streams'][0]['codec_type'] == 'video') {
         $video = $data['streams'][0];
         $audio = $data['streams'][1];
     } else {
         $video = $data['streams'][1];
         $audio = $data['streams'][0];
     }
     $info['format'] = $data['format']['format_name'];
     $info['duration'] = (double) round($video['duration'], 2);
     $info['bitrate'] = (int) $data['format']['bit_rate'];
     $info['video_bitrate'] = (int) $video['bit_rate'];
     $info['video_width'] = (int) $video['width'];
     $info['video_height'] = (int) $video['height'];
     if ($video['height']) {
         $info['video_wh_ratio'] = (int) $video['width'] / (int) $video['height'];
     }
     $info['video_codec'] = $video['codec_name'];
     $info['video_rate'] = $video['r_frame_rate'];
     $info['size'] = filesize($path_source);
     $info['audio_codec'] = $audio['codec_name'];
     $info['audio_bitrate'] = (int) $audio['bit_rate'];
     $info['audio_rate'] = (int) $audio['sample_rate'];
     $info['audio_channels'] = (double) $audio['channels'];
     $info['rotation'] = (double) $video['tags']['rotate'];
     if (!$info['duration'] || 1) {
         $CMD = MEDIAINFO_BINARY . "   '--Inform=General;%Duration%'  '" . $path_source . "' 2>&1 ";
         logData($CMD, 'command');
         $duration = $info['duration'] = round(shell_output($CMD) / 1000, 2);
     }
     $this->raw_info = $info;
     $video_rate = explode('/', $info['video_rate']);
     $int_1_video_rate = (int) $video_rate[0];
     $int_2_video_rate = (int) $video_rate[1];
     $CMD = MEDIAINFO_BINARY . "   '--Inform=Video;'  " . $path_source;
     logData($CMD, 'command');
     $results = shell_output($CMD);
     $needle_start = "Original height";
     $needle_end = "pixels";
     $original_height = find_string($needle_start, $needle_end, $results);
     $original_height[1] = str_replace(' ', '', $original_height[1]);
     if (!empty($original_height) && $original_height != false) {
         $o_height = trim($original_height[1]);
         $o_height = (int) $o_height;
         if ($o_height != 0 && !empty($o_height)) {
             $info['video_height'] = $o_height;
         }
         //logData(,'height');
     }
     $needle_start = "Original width";
     $needle_end = "pixels";
     $original_width = find_string($needle_start, $needle_end, $results);
     $original_width[1] = str_replace(' ', '', $original_width[1]);
     if (!empty($original_width) && $original_width != false) {
         $o_width = trim($original_width[1]);
         $o_width = (int) $o_width;
         if ($o_width != 0 && !empty($o_width)) {
             $info['video_width'] = $o_width;
         }
     }
     if ($int_2_video_rate != 0) {
         $info['video_rate'] = $int_1_video_rate / $int_2_video_rate;
     }
     logData(json_encode($info), $this->file_name . '_configs');
     return $info;
 }
Example #9
0
     // Valid Crypt2 field check
 }
 // Check for existing public key
 if (empty($public_key_found_peer) == FALSE) {
     // This peer is already in the generation list, so normally it would
     // not be sending another election request unless to update the
     // IP address from which it generates currency from.
     $transaction_info = tk_decrypt($public_key, base64_decode($crypt1));
     if ($transaction_info == $crypt2) {
         // Check the IP/Domain field and poll the IP to see if
         // there is a valid Timekoin server at the address.
         $crypt3_data = tk_decrypt($public_key, base64_decode($crypt3));
         $peer_ip = find_string("---ip=", "---domain", $crypt3_data);
         $peer_domain = find_string("---domain=", "---subfolder", $crypt3_data);
         $peer_subfolder = find_string("---subfolder=", "---port", $crypt3_data);
         $peer_port_number = find_string("---port=", "---end", $crypt3_data);
         // Check if IP is already in the generation peer list
         $IP_exist1 = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `IP_Address` = '{$peer_ip}' LIMIT 1"), 0, 1);
         // Calculate public key half-crypt-hash
         $arr1 = str_split($public_key, 181);
         // Poll the address that was encrypted to check for valid Timekoin server
         $gen_key_crypt = base64_decode(poll_peer($peer_ip, $peer_domain, $peer_subfolder, $peer_port_number, 256, "genpeer.php?action=gen_key_crypt"));
         $gen_key_crypt = tk_decrypt($public_key, $gen_key_crypt);
         if (empty($peer_domain) == FALSE) {
             // Check if the hostname and IP fields actually match
             // and not made up or unrelated.
             if (gethostbyname($peer_domain) != $peer_ip) {
                 $domain_fail = TRUE;
             } else {
                 $domain_fail = FALSE;
             }
Example #10
0
function db_cache_balance($my_public_key)
{
    $cache_refresh_time = 30;
    // Refresh TTL in seconds
    // Check server balance via cache
    $billfold_balance = mysql_result(mysql_query("SELECT * FROM `data_cache` WHERE `field_name` = 'billfold_balance' LIMIT 1"), 0, "field_data");
    $timestamp_cache = intval(find_string("---time=", "---data", $billfold_balance));
    if (time() - $cache_refresh_time <= $timestamp_cache) {
        // Return Cache Data
        return intval(find_string("---data=", "---end", $billfold_balance));
    }
    $balance = check_crypt_balance($my_public_key);
    // Cache stale, refresh and update cache
    mysql_query("UPDATE `data_cache` SET `field_data` = '---time=" . time() . "---data={$balance}---end' WHERE `data_cache`.`field_name` = 'billfold_balance' LIMIT 1");
    return $balance;
}
Example #11
0
<?php

$x = "https://github.com/ifjprojekt12/IFJ-Projekt-2013/new/master/testy";
$a = find_string($x, "h");
$b = put_string($a, "\n");
$a = find_string($x, "x");
$b = put_string($a, "\n");
$a = find_string($x, ":");
$b = put_string($a, "\n");
$a = find_string($x, "ttps");
$b = put_string($a, "\n");
$a = find_string($x, "t1");
$b = put_string($a, "\n");
Example #12
0
function options_screen5()
{
    $sql = "SELECT * FROM `options` WHERE `field_name` LIKE 'installed_plugins%' ORDER BY `options`.`field_name` ASC";
    $sql_result = mysql_query($sql);
    $sql_num_results = mysql_num_rows($sql_result);
    $plugin_output;
    for ($i = 0; $i < $sql_num_results; $i++) {
        $sql_row = mysql_fetch_array($sql_result);
        $plugin_file = find_string("---file=", "---enable", $sql_row["field_data"]);
        $plugin_enable = intval(find_string("---enable=", "---show", $sql_row["field_data"]));
        $plugin_name = find_string("---name=", "---tab", $sql_row["field_data"]);
        $plugin_tab = find_string("---tab=", "---service", $sql_row["field_data"]);
        $plugin_service = find_string("---service=", "---end", $sql_row["field_data"]);
        if (empty($plugin_service) == TRUE) {
            $plugin_service = '<font color="red">NA</font>';
        }
        if ($plugin_enable == TRUE) {
            $plugin_toggle = '<FORM ACTION="index.php?menu=options&amp;plugin=disable" METHOD="post"><font color="blue"><strong>Enabled</strong></font><br><input type="submit" name="Submit' . $i . '" value="Disable Here" />
				<input type="hidden" name="pluginfile" value="' . $plugin_file . '"></FORM>';
        } else {
            $plugin_toggle = '<FORM ACTION="index.php?menu=options&amp;plugin=enable" METHOD="post"><font color="red">Disabled</font><br><input type="submit" name="Submit' . $i . '" value="Enable Here" />
				<input type="hidden" name="pluginfile" value="' . $plugin_file . '"></FORM>';
        }
        $plugin_output .= '<tr><td>' . $plugin_name . '</td><td>' . $plugin_tab . '</td><td>' . $plugin_file . '</td><td>' . $plugin_service . '</td>
		<td valign="top" align="center">' . $plugin_toggle . '</td>
		<td><FORM ACTION="index.php?menu=options&amp;remove=plugin" METHOD="post" onclick="return confirm(\'Delete ' . $plugin_name . '?\');"><input type="image" src="img/hr.gif" title="Delete ' . $plugin_name . '" name="remove' . $i . '" border="0">
		<input type="hidden" name="pluginfile" value="' . $plugin_file . '"></FORM></td></tr>
		<tr><td colspan="6"><hr></td></tr>';
    }
    return '<table border="0" cellpadding="2" cellspacing="10"><tr><td valign="bottom" align="center" colspan="6"><strong>Plugin Information</strong>
	</td></tr>
	<tr><td align="center"><strong>Name</strong></td><td align="center"><strong>Tab</strong></td><td align="center"><strong>File</strong></td>
	<td align="center"><strong>Service</strong></td><td align="center"><strong>Status</strong></td><td></td></tr>
	' . $plugin_output . '
	<tr><td align="right" colspan="6"><FORM ACTION="index.php?menu=options&amp;plugin=new" METHOD="post"><input type="submit" name="SubmitNew" value="Install New Plugin" /></FORM></td></tr>
	</table>
	';
}
Example #13
0
 /**
  * 城市映射,通过城市名,获取城市id
  * @param String $city_name		//市级城市名
  */
 protected function get_city_id($city_name)
 {
     $City = D('City');
     //店铺模型表
     $all_city = $City->get_city_cache();
     //读取城市缓存数据
     foreach ($all_city as $val) {
         //获取匹配后的城市id
         if (find_string($val['name'], $city_name)) {
             $city = $val['id'];
             break;
         }
     }
     return $city;
 }
Example #14
0
function peer_list()
{
    ini_set('user_agent', 'Timekoin Client (Peerlist) v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 2);
    // Timeout for request in seconds
    $max_active_peers = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'max_active_peers' LIMIT 1"), 0, "field_data");
    $max_new_peers = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'max_new_peers' LIMIT 1"), 0, "field_data");
    // How many active peers do we have?
    $active_peers = mysql_result(mysql_query("SELECT COUNT(join_peer_list) FROM `active_peer_list`"), 0);
    $new_peers = mysql_result(mysql_query("SELECT COUNT(poll_failures) FROM `new_peers_list`"), 0);
    if ($active_peers == 0) {
        // No active or new peers to poll from, start with the first contact servers
        // and copy them to the new peer list
        $sql = "SELECT * FROM `options` WHERE `field_name` = 'first_contact_server'";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        write_log("Peer List Empty. Adding First Contact Servers.", "PL");
        // First Contact Server Format
        //---ip=192.168.0.1---domain=timekoin.com---subfolder=timekoin---port=80---code=guest---end
        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=", "---code", $sql_row["field_data"]);
            $peer_code = find_string("---code=", "---end", $sql_row["field_data"]);
            // Insert into database as first contact server(s)
            $sql = "INSERT INTO `active_peer_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`last_heartbeat`, `join_peer_list`, `failed_sent_heartbeat`, `code`)\n\t\t\tVALUES ('{$peer_ip}', '{$peer_domain}', '{$peer_subfolder}', '{$peer_port_number}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '{$peer_code}');";
            mysql_query($sql);
            $active_peers++;
        }
    }
    if ($active_peers < $max_active_peers) {
        //Start polling peers from the new peers list
        $sql = "SELECT * FROM `new_peers_list` ORDER BY RAND() LIMIT 10";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        // Peer difference
        $peer_difference_count = $max_active_peers - $active_peers;
        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"];
            $poll_failures = $sql_row["poll_failures"];
            $code = $sql_row["code"];
            // Check to make sure that this peer is not already in our active peer list
            $duplicate_check1 = mysql_result(mysql_query("SELECT * FROM `active_peer_list` WHERE `IP_Address` = '{$ip_address}' LIMIT 1"), 0, 0);
            $duplicate_check2 = mysql_result(mysql_query("SELECT * FROM `active_peer_list` WHERE `domain` LIKE '{$domain}' LIMIT 1"), 0, 1);
            if (empty($ip_address) == TRUE) {
                //Don't have an IP address, check for duplicate domain or my own domain
                if (empty($duplicate_check2) == TRUE) {
                    // Neither IP nor Domain exist
                    $duplicate_peer = FALSE;
                } else {
                    $duplicate_peer = TRUE;
                }
            } else {
                // Using IP only, is there a duplicate IP or Domain
                if (empty($duplicate_check1) == TRUE && empty($duplicate_check2) == TRUE) {
                    $duplicate_peer = FALSE;
                } else {
                    $duplicate_peer = TRUE;
                }
            }
            if ($duplicate_peer == FALSE) {
                // Poll Peer for Access
                if (empty($code) == TRUE) {
                    // Try guest access
                    $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=tk_hash_status&hash=guest");
                } else {
                    // Using custom code for peer
                    $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=tk_hash_status&hash={$code}");
                }
                if ($poll_peer == TRUE) {
                    // Add this peer to the active list
                    // Insert this peer into our active peer table
                    // Save only domain name if both IP and Domain exist
                    if (empty($domain) == FALSE) {
                        $ip_address = NULL;
                    }
                    if (empty($code) == TRUE) {
                        $code = "guest";
                    }
                    // Store new peer in active list
                    $sql = "INSERT INTO `active_peer_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`last_heartbeat` ,`join_peer_list` ,`failed_sent_heartbeat` ,`code`)\n\t\t\tVALUES ('{$ip_address}', '{$domain}', '{$subfolder}', '{$port_number}', '" . time() . "', '" . time() . "', '0', '{$code}');";
                    if (mysql_query($sql) == TRUE) {
                        // Subtract 1 from the peer difference count
                        $peer_difference_count--;
                        write_log("Joined with Peer {$ip_address}:{$domain}:{$port_number}/{$subfolder}", "PL");
                    }
                } else {
                    //No response, record polling failure for future reference
                    $poll_failures++;
                    mysql_query("UPDATE `new_peers_list` SET `poll_failures` = '{$poll_failures}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
                }
            } else {
                // Active response will remove poll failures
                mysql_query("UPDATE `new_peers_list` SET `poll_failures` = 0 WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
            }
            // Check to see if enough peers have been added
            if ($peer_difference_count <= 0) {
                // Break out of loop
                break;
            }
        }
        // End For Loop
    }
    // End Active vs Max Peer Check
    //***********************************************************************************
    // Add more peers to the new peers list to satisfy new peer limit
    // How many new peers do we have now?
    $sql = "SELECT * FROM `new_peers_list`";
    $new_peers_numbers = mysql_num_rows(mysql_query($sql));
    if ($new_peers_numbers < $max_new_peers && rand(1, 3) == 2) {
        // Add more possible peers to the new peer list by polling what the active peers have
        $sql = "SELECT * FROM `active_peer_list` ORDER BY RAND() LIMIT 10";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        $new_peer_difference = $max_new_peers - $new_peers_numbers;
        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"];
            $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 10000, "peerlist.php?action=new_peers");
            $peer_counter = 1;
            // Reset peer counter
            while ($peer_counter <= 15) {
                $peer_IP = NULL;
                $peer_domain = NULL;
                $peer_subfolder = NULL;
                $peer_port_number = NULL;
                // Sort Data
                $peer_IP = find_string("-----IP{$peer_counter}=", "-----domain{$peer_counter}", $poll_peer);
                $peer_domain = find_string("-----domain{$peer_counter}=", "-----subfolder{$peer_counter}", $poll_peer);
                $peer_subfolder = find_string("-----subfolder{$peer_counter}=", "-----port_number{$peer_counter}", $poll_peer);
                $peer_port_number = find_string("-----port_number{$peer_counter}=", "-----", $poll_peer);
                if (is_domain_valid($peer_domain) == FALSE) {
                    // Someone is using an IP address or Localhost :p
                    $peer_domain = NULL;
                }
                if (empty($peer_port_number) == TRUE && empty($peer_subfolder) == TRUE) {
                    // No more peers, end this loop early
                    break;
                }
                if (empty($peer_IP) == TRUE && empty($peer_domain) == TRUE) {
                    $duplicate_peer == TRUE;
                    // Flag to avoid putting blank entry in database
                } else {
                    // Check to make sure that this peer is not already in our new peer list
                    $duplicate_check1 = mysql_result(mysql_query("SELECT * FROM `new_peers_list` WHERE `IP_Address` = '{$peer_IP}' LIMIT 1"), 0, 0);
                    $duplicate_check2 = mysql_result(mysql_query("SELECT * FROM `new_peers_list` WHERE `domain` LIKE '{$peer_domain}' LIMIT 1"), 0, 1);
                    if (empty($peer_IP) == TRUE) {
                        //Don't have an IP address, check for duplicate domain
                        if (empty($duplicate_check2) == TRUE) {
                            // Neither IP nor Domain exist
                            $duplicate_peer = FALSE;
                        } else {
                            $duplicate_peer = TRUE;
                        }
                    } else {
                        // Using IP only, is there a duplicate
                        if (empty($duplicate_check1) == TRUE) {
                            if (empty($duplicate_check2) == FALSE) {
                                $duplicate_peer = TRUE;
                            } else {
                                $duplicate_peer = TRUE;
                            }
                        } else {
                            $duplicate_peer = TRUE;
                        }
                    }
                }
                if ($duplicate_peer == FALSE) {
                    // Save only domain name if both IP and Domain exist
                    if (empty($peer_domain) == FALSE) {
                        $peer_IP = NULL;
                    }
                    if (empty($peer_IP) == FALSE || empty($peer_domain) == FALSE) {
                        // This is a fresh new peer, add it to the database list
                        $sql = "INSERT INTO `new_peers_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`poll_failures` ,`code`)\n\t\t\t\tVALUES ('{$peer_IP}', '{$peer_domain}', '{$peer_subfolder}', '{$peer_port_number}', '0', 'guest')";
                        if (mysql_query($sql) == TRUE) {
                            // Subtract one from total left to find
                            $new_peer_difference--;
                        }
                    }
                }
                if ($new_peer_difference <= 0) {
                    // Enough new peers saved, break out of while loop early
                    break;
                }
                $peer_counter++;
            }
            // End While loop check
            if ($new_peer_difference <= 0) {
                // Enough new peers saved, break out of for loop early
                break;
            }
        }
        // End For loop check
    }
    // End New Peers vs Max New Peers check
    //***********************************************************************************
    // Send a heartbeat to all active peers in our list to make sure they are still online
    $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 (rand(1, 3) == 2) {
            $ip_address = $sql_row["IP_Address"];
            $domain = $sql_row["domain"];
            $subfolder = $sql_row["subfolder"];
            $port_number = $sql_row["port_number"];
            $last_heartbeat = $sql_row["last_heartbeat"];
            $join_peer_list = $sql_row["join_peer_list"];
            $failed_sent_heartbeat = $sql_row["failed_sent_heartbeat"];
            $code = $sql_row["code"];
            $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=tk_hash_status&hash={$code}");
            if ($poll_peer == TRUE) {
                //Got a response from an active Timekoin server
                mysql_query("UPDATE `active_peer_list` SET `last_heartbeat` = '" . time() . "', `failed_sent_heartbeat` = 0 WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
            } else {
                //No response, record polling failure for future reference
                $failed_sent_heartbeat++;
                mysql_query("UPDATE `active_peer_list` SET `failed_sent_heartbeat` = '{$failed_sent_heartbeat}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
            }
        }
        // End Randomize Check
    }
    // End for Loop
    // Remove all active peers that are offline for more than 5 minutes
    if (rand(1, 2) == 2) {
        mysql_query("DELETE QUICK FROM `active_peer_list` WHERE `last_heartbeat` < " . (time() - 300) . " AND `join_peer_list` != 0");
    }
    //***********************************************************************************
    // Send a heartbeat to all reserve peers in our list to make sure they are still online
    $sql = "SELECT * FROM `new_peers_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 (rand(1, 3) == 2) {
            $ip_address = $sql_row["IP_Address"];
            $domain = $sql_row["domain"];
            $subfolder = $sql_row["subfolder"];
            $port_number = $sql_row["port_number"];
            $poll_failures = $sql_row["poll_failures"];
            // Query Server for valid Hashcode
            $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=tk_hash_status&hash={$code}");
            if ($poll_peer == TRUE) {
                //Got a response from an active Timekoin server
                mysql_query("UPDATE `new_peers_list` SET `poll_failures` = 0 WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
            } else {
                //No response, record polling failure for future reference
                $poll_failures++;
                mysql_query("UPDATE `new_peers_list` SET `poll_failures` = '{$poll_failures}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
            }
        }
        // End Randomize Check
    }
    // End for Loop
    // Clean up reserve peer list by removing those that have no responded for over 6 poll attempts
    if (rand(1, 2) == 2) {
        mysql_query("DELETE QUICK FROM `new_peers_list` WHERE `poll_failures` > 6");
    }
    return;
}
Example #15
0
 $domain = $sql_row["domain"];
 $subfolder = $sql_row["subfolder"];
 $port_number = $sql_row["port_number"];
 $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 10000, "peerlist.php?action=new_peers");
 $peer_counter = 1;
 // Reset peer counter
 while ($peer_counter <= 15) {
     $peer_IP = NULL;
     $peer_domain = NULL;
     $peer_subfolder = NULL;
     $peer_port_number = NULL;
     // Sort Data
     $peer_IP = find_string("-----IP{$peer_counter}=", "-----domain{$peer_counter}", $poll_peer);
     $peer_domain = find_string("-----domain{$peer_counter}=", "-----subfolder{$peer_counter}", $poll_peer);
     $peer_subfolder = find_string("-----subfolder{$peer_counter}=", "-----port_number{$peer_counter}", $poll_peer);
     $peer_port_number = find_string("-----port_number{$peer_counter}=", "-----", $poll_peer);
     if (is_domain_valid($peer_domain) == FALSE) {
         // Someone is using an IP address or Localhost :p
         $peer_domain = NULL;
     }
     if (empty($peer_port_number) == TRUE && empty($peer_subfolder) == TRUE) {
         // No more peers, end this loop early
         break;
     }
     if (empty($peer_IP) == TRUE && empty($peer_domain) == TRUE) {
         $duplicate_peer == TRUE;
         // Flag to avoid putting blank entry in database
     } else {
         // Check to make sure that this peer is not already in our new peer list
         $duplicate_check1 = mysql_result(mysql_query("SELECT * FROM `new_peers_list` WHERE `IP_Address` = '{$peer_IP}' LIMIT 1"), 0, 0);
         $duplicate_check2 = mysql_result(mysql_query("SELECT * FROM `new_peers_list` WHERE `domain` LIKE '{$peer_domain}' LIMIT 1"), 0, 1);
Example #16
0
 }
 // Check for existing public key
 if (empty($public_key_found_peer) == FALSE) {
     // This peer is already in the generation list, so normally it would
     // not be sending another election request unless to update the
     // IP address from which it generates currency from.
     $transaction_info = tk_decrypt($public_key, base64_decode($crypt1));
     if ($transaction_info == $crypt2) {
         // Check the IP/Domain field and poll the IP to see if
         // there is a valid Timekoin server at the address.
         $crypt3_data = tk_decrypt($public_key, base64_decode($crypt3));
         $peer_ip = find_string("---ip=", "---domain", $crypt3_data);
         $peer_domain = find_string("---domain=", "---subfolder", $crypt3_data);
         $peer_subfolder = find_string("---subfolder=", "---port", $crypt3_data);
         $peer_port_number = find_string("---port=", "---end", $crypt3_data);
         $delete_request = find_string("---end=", "---end2", $crypt3_data);
         // Check if IP is already in the generation peer list
         $IP_exist1 = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `IP_Address` = '{$peer_ip}' LIMIT 1"), 0, 1);
         // Calculate public key half-crypt-hash
         $arr1 = str_split($public_key, 181);
         // Poll the address that was encrypted to check for valid Timekoin server
         $gen_key_crypt = base64_decode(poll_peer($peer_ip, $peer_domain, $peer_subfolder, $peer_port_number, 256, "genpeer.php?action=gen_key_crypt"));
         $gen_key_crypt = tk_decrypt($public_key, $gen_key_crypt);
         $domain_fail = FALSE;
         // Reset Variable
         if (empty($peer_domain) == FALSE) {
             // Check if the hostname and IP fields actually match
             // and not made up or unrelated.
             $dns_ip = gethostbyname($peer_domain);
             if ($dns_ip != $peer_ip) {
                 // No match between Domain IP and Encoded IP
Example #17
0
    function autotx_home()
    {
        $default_public_key_font = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'public_key_font_size' LIMIT 1"), 0, "field_data");
        $sql = "SELECT * FROM `options` WHERE `field_name` LIKE 'auto_currency_transfer_%' ORDER BY `options`.`field_name` ASC";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        $plugin_output;
        for ($i = 0; $i < $sql_num_results; $i++) {
            $sql_row = mysql_fetch_array($sql_result);
            $tx_record_name = $sql_row["field_name"];
            $tx_name = find_string("---name=", "---enable", $sql_row["field_data"]);
            $tx_enable = intval(find_string("---enable=", "---type", $sql_row["field_data"]));
            $tx_type = find_string("---type=", "---key1", $sql_row["field_data"]);
            $tx_key2 = find_string("---key2=", "---key3", $sql_row["field_data"]);
            $tx_key2 = base64_encode(mysql_result(mysql_query("SELECT field_data FROM `my_keys` WHERE `field_name` = '{$tx_key2}' LIMIT 1"), 0, 0));
            if ($tx_type == "onedelay") {
                $tx_key3 = find_string("---key3=", "---delay", $sql_row["field_data"]);
                $tx_key3 = base64_encode(mysql_result(mysql_query("SELECT field_data FROM `my_keys` WHERE `field_name` = '{$tx_key3}' LIMIT 1"), 0, 0));
                $tx_delay = find_string("---delay=", "---amount", $sql_row["field_data"]);
                $tx_amount = find_string("---amount=", "---end", $sql_row["field_data"]);
                $tx_type = "One Time<br>Delay";
                if ($tx_delay == 0) {
                    $tx_conditions = "Finished";
                } else {
                    $tx_conditions = tk_time_convert($tx_delay) . " Remain";
                }
            }
            if ($tx_type == "repeatdelay") {
                $tx_key3 = find_string("---key3=", "---delay_start", $sql_row["field_data"]);
                $tx_key3 = base64_encode(mysql_result(mysql_query("SELECT field_data FROM `my_keys` WHERE `field_name` = '{$tx_key3}' LIMIT 1"), 0, 0));
                $tx_delay = find_string("---delay=", "---amount", $sql_row["field_data"]);
                $tx_amount = find_string("---amount=", "---end", $sql_row["field_data"]);
                $tx_type = "Repeating<br>Delay";
                $tx_conditions = tk_time_convert($tx_delay) . " Remain";
            }
            if ($tx_type == "oneamount") {
                $tx_key3 = find_string("---key3=", "---amount", $sql_row["field_data"]);
                $tx_key3 = base64_encode(mysql_result(mysql_query("SELECT field_data FROM `my_keys` WHERE `field_name` = '{$tx_key3}' LIMIT 1"), 0, 0));
                $tx_amount = find_string("---amount=", "---amount_match", $sql_row["field_data"]);
                $amount_match = find_string("---amount_match=", "---end", $sql_row["field_data"]);
                $tx_type = "One Time<br>Amount Match";
                if ($tx_amount == 0) {
                    $tx_conditions = "Finished";
                } else {
                    $tx_conditions = "Amount >= {$amount_match}";
                }
            }
            if ($tx_type == "repeatamount") {
                $tx_key3 = find_string("---key3=", "---amount", $sql_row["field_data"]);
                $tx_key3 = base64_encode(mysql_result(mysql_query("SELECT field_data FROM `my_keys` WHERE `field_name` = '{$tx_key3}' LIMIT 1"), 0, 0));
                $tx_amount = find_string("---amount=", "---amount_match", $sql_row["field_data"]);
                $amount_match = find_string("---amount_match=", "---end", $sql_row["field_data"]);
                $tx_type = "Repeating<br>Amount Match";
                $tx_conditions = "Amount >= {$amount_match}";
            }
            if ($tx_enable == TRUE) {
                $tx_toggle = '<FORM ACTION="autotransfer.php?task=disable" METHOD="post"><font color="blue"><strong>Enabled</strong></font><br><input type="submit" name="Submit' . $i . '" value="Disable Here" />
				<input type="hidden" name="tx_record_name" value="' . $tx_record_name . '"></FORM>';
            } else {
                $tx_toggle = '<FORM ACTION="autotransfer.php?task=enable" METHOD="post"><font color="red">Disabled</font><br><input type="submit" name="Submit' . $i . '" value="Enable Here" />
				<input type="hidden" name="tx_record_name" value="' . $tx_record_name . '"></FORM>';
            }
            $plugin_output .= '<tr><td>' . $tx_name . '</td><td>' . $tx_type . '</td><td>' . $tx_conditions . '</td><td><p style="word-wrap:break-word; width:90px; font-size:' . $default_public_key_font . 'px;">' . $tx_key2 . '</p></td>
		<td><p style="word-wrap:break-word; width:90px; font-size:' . $default_public_key_font . 'px;">' . $tx_key3 . '</p></td><td align="center">' . $tx_amount . '</td><td valign="top" align="center">' . $tx_toggle . '</td>
		<td><FORM ACTION="autotransfer.php?task=delete_task" METHOD="post" onclick="return confirm(\'Delete ' . $tx_name . '?\');"><input type="image" src="../img/hr.gif" title="Delete ' . $tx_name . '" name="remove' . $i . '" border="0">
		<input type="hidden" name="tx_record_name" value="' . $tx_record_name . '"></FORM></td></tr>
		<tr><td colspan="8"><hr></td></tr>';
        }
        return '<table border="0" cellpadding="2" cellspacing="10"><tr><td valign="bottom" align="center" colspan="8"><strong>Auto Currency Transfer Task List</strong>
</td></tr>
<tr><td align="center"><strong>Name</strong></td><td align="center"><strong>Type</strong></td><td align="center"><strong>Conditions</strong></td>
<td align="center"><strong>Key From</strong></td><td align="center"><strong>Key To</strong></td><td align="center"><strong>Transfer<br>Amount</strong></td>
<td align="center"><strong>Status</strong></td><td></td></tr>' . $plugin_output . '
<tr><td align="right" colspan="8"><FORM ACTION="autotransfer.php?task=new" METHOD="post"><input type="submit" name="SubmitNew" value="Create New Task" /></FORM></td></tr>
</table>';
    }
Example #18
0
function home_screen($contents, $select_bar, $body, $quick_info, $refresh = 0)
{
    $home;
    $options;
    $address;
    $peerlist;
    $refresh_header;
    $send;
    $history;
    $queue;
    $script_headers;
    $balance_history;
    $counter;
    $amount;
    $graph_data_range_sent;
    $graph_data_range_recv;
    $graph_data_trans_total;
    $graph_data_amount_total;
    $largest_sent = 10;
    $largest_recv = 10;
    $last = 20;
    $cache_refresh_time = 60;
    // How many seconds for cache to remain valid before refresh is required
    if ($refresh != 0) {
        $refresh_header = '<meta http-equiv="refresh" content="' . $refresh . '" />';
    }
    switch ($_GET["menu"]) {
        case "home":
            $home = 'class="active"';
            $graph_data_range_recv = mysql_result(mysql_query("SELECT * FROM `data_cache` WHERE `field_name` = 'graph_data_range_recv' LIMIT 1"), 0, "field_data");
            $timestamp_cache = intval(find_string("---time=", "---max", $graph_data_range_recv));
            if (time() - $cache_refresh_time > $timestamp_cache) {
                // Old data needs to be refreshed
                $history_data_to = transaction_history_query(1, $last);
                $counter = 1;
                $graph_data_range_recv = NULL;
                while ($counter <= $last) {
                    $amount = find_string("---AMOUNT{$counter}=", "---VERIFY", $history_data_to);
                    if ($amount == "") {
                        // No more data to search
                        break;
                    }
                    $counter++;
                    if ($counter <= $last + 1) {
                        if ($amount > $largest_recv) {
                            $largest_recv = $amount + 2;
                        }
                        $graph_data_range_recv .= ",{$amount}";
                    }
                }
                // Update data cache
                if (empty($graph_data_range_recv) == FALSE) {
                    mysql_query("UPDATE `data_cache` SET `field_data` = '---time=" . time() . "---max={$largest_recv}---data={$graph_data_range_recv}---end' WHERE `data_cache`.`field_name` = 'graph_data_range_recv' LIMIT 1");
                }
            } else {
                // Use cached data
                $largest_recv = find_string("---max=", "---data", $graph_data_range_recv);
                $graph_data_range_recv = find_string("---data=", "---end", $graph_data_range_recv);
            }
            $graph_data_range_sent = mysql_result(mysql_query("SELECT * FROM `data_cache` WHERE `field_name` = 'graph_data_range_sent' LIMIT 1"), 0, "field_data");
            $timestamp_cache = intval(find_string("---time=", "---max", $graph_data_range_sent));
            if (time() - $cache_refresh_time > $timestamp_cache) {
                // Old data needs to be refreshed
                $history_data_to = transaction_history_query(2, $last);
                $counter = 1;
                $graph_data_range_sent = NULL;
                while ($counter <= $last) {
                    $amount = find_string("---AMOUNT{$counter}=", "---VERIFY", $history_data_to);
                    if ($amount == "") {
                        // No more data to search
                        break;
                    }
                    $counter++;
                    if ($counter <= $last + 1) {
                        if ($amount > $largest_sent) {
                            $largest_sent = $amount + 2;
                        }
                        $graph_data_range_sent .= ",{$amount}";
                    }
                }
                // Update data cache
                if (empty($graph_data_range_sent) == FALSE) {
                    mysql_query("UPDATE `data_cache` SET `field_data` = '---time=" . time() . "---max={$largest_sent}---data={$graph_data_range_sent}---end' WHERE `data_cache`.`field_name` = 'graph_data_range_sent' LIMIT 1");
                }
            } else {
                // Use cached data
                $largest_sent = find_string("---max=", "---data", $graph_data_range_sent);
                $graph_data_range_sent = find_string("---data=", "---end", $graph_data_range_sent);
            }
            $graph_data_trans_total = mysql_result(mysql_query("SELECT * FROM `data_cache` WHERE `field_name` = 'graph_data_trans_total' LIMIT 1"), 0, "field_data");
            $graph_data_amount_total = mysql_result(mysql_query("SELECT * FROM `data_cache` WHERE `field_name` = 'graph_data_amount_total' LIMIT 1"), 0, "field_data");
            $timestamp_cache = intval(find_string("---time=", "---max", $graph_data_trans_total));
            if (time() - $cache_refresh_time > $timestamp_cache) {
                // Old data needs to be refreshed
                $total_trans_last = 25;
                $total_network_amounts_last = 20;
                $tk_trans_total_data = tk_trans_total($total_trans_last);
                $counter = 1;
                $graph_data_trans_total = NULL;
                $graph_data_amount_total = NULL;
                $max_amount = 10;
                $max_transactions = 10;
                while ($counter <= $total_trans_last) {
                    $timestamp = find_string("---TIMESTAMP{$counter}=", "---NUM{$counter}", $tk_trans_total_data);
                    $total_transactions = find_string("---NUM{$counter}=", "---AMOUNT{$counter}", $tk_trans_total_data);
                    $total_amount = find_string("---AMOUNT{$counter}=", "---END{$counter}", $tk_trans_total_data);
                    if (empty($timestamp) == TRUE) {
                        // No more data to search
                        break;
                    }
                    $counter++;
                    if ($counter <= $total_trans_last + 1) {
                        if ($total_transactions > $max_transactions) {
                            $max_transactions = $total_transactions + 2;
                        }
                        $graph_data_trans_total .= ",{$total_transactions}";
                    }
                    if ($counter <= $total_network_amounts_last + 1) {
                        if ($total_amount > $max_amount) {
                            $max_amount = $total_amount + 2;
                        }
                        $graph_data_amount_total .= ",{$total_amount}";
                    }
                }
                // Update data cache
                if (empty($graph_data_trans_total) == FALSE && empty($graph_data_amount_total) == FALSE) {
                    mysql_query("UPDATE `data_cache` SET `field_data` = '---time=" . time() . "---max={$max_transactions}---data={$graph_data_trans_total}---end' WHERE `data_cache`.`field_name` = 'graph_data_trans_total' LIMIT 1");
                    mysql_query("UPDATE `data_cache` SET `field_data` = '---time=" . time() . "---max={$max_amount}---data={$graph_data_amount_total}---end' WHERE `data_cache`.`field_name` = 'graph_data_amount_total' LIMIT 1");
                }
            } else {
                // Use cached data
                $max_transactions = find_string("---max=", "---data", $graph_data_trans_total);
                $graph_data_trans_total = find_string("---data=", "---end", $graph_data_trans_total);
                $max_amount = find_string("---max=", "---data", $graph_data_amount_total);
                $graph_data_amount_total = find_string("---data=", "---end", $graph_data_amount_total);
            }
            // Cap largest chart values
            if ($largest_recv > 5999) {
                $largest_recv = 5999;
            }
            if ($largest_sent > 5999) {
                $largest_sent = 5999;
            }
            if ($max_transactions > 999) {
                $max_transactions = 999;
            }
            if ($max_amount > 7999) {
                $max_amount = 7999;
            }
            // Cap ranges
            $largest_recv_grid = $largest_recv * 0.1;
            if ($largest_recv_grid > 300) {
                $largest_recv_grid = 300;
            }
            $largest_sent_grid = $largest_sent * 0.1;
            if ($largest_sent_grid > 300) {
                $largest_sent_grid = 300;
            }
            $max_transactions_grid = $max_transactions * 0.12;
            $max_amount_grid = $max_amount * 0.075;
            if ($max_amount_grid > 300) {
                $max_amount_grid = 300;
            }
            $script_headers = '<script type="text/javascript" src="js/tkgraph.js"></script>
<script type="text/javascript">
window.onload = function() {
	
g_graph = new Graph(
{
\'id\': "recv_graph",
\'strokeStyle\': "#FFA500",
\'fillStyle\': "rgba(0,127,0,0.20)",
\'grid\': [' . $largest_recv_grid . ',10],
\'range\': [0,' . $largest_recv . '],
\'data\': [' . $graph_data_range_recv . ']
});

g_graph = new Graph(
{
\'id\': "sent_graph",
\'strokeStyle\': "#FFA500",
\'fillStyle\': "rgba(0,0,255,0.20)",
\'grid\': [' . $largest_sent_grid . ',10],
\'range\': [0,' . $largest_sent . '],
\'data\': [' . $graph_data_range_sent . ']
});

g_graph = new Graph(
{
\'id\': "trans_total",
\'strokeStyle\': "#FFA500",
\'fillStyle\': "rgba(187,217,238,0.65)",
\'grid\': [' . $max_transactions_grid . ',10],
\'range\': [0,' . $max_transactions . '],
\'data\': [' . $graph_data_trans_total . ']
});

g_graph = new Graph(
{
\'id\': "amount_total",
\'strokeStyle\': "#FFA500",
\'fillStyle\': "rgba(130,127,0,0.20)",
\'grid\': [' . $max_amount_grid . ',10],
\'range\': [0,' . $max_amount . '],
\'data\': [' . $graph_data_amount_total . ']
});

}
</script>';
            break;
        case "address":
            $address = 'class="active"';
            break;
        case "queue":
            $queue = 'class="active"';
            break;
        case "send":
            $send = 'class="active"';
            break;
        case "history":
            $history = 'class="active"';
            break;
        case "options":
            $options = 'class="active"';
            break;
        case "peerlist":
            $peerlist = 'class="active"';
            break;
        case "tools":
            $tools = 'class="active"';
            break;
        case "backup":
            $backup = 'class="active"';
            break;
    }
    ?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
    function showWait(val){
    var oDiv = document.getElementById('overlay')
    oDiv.style.display='block'
    oDiv.style.opacity = 10;
    oDiv.style.filter = 'alpha(opacity=' + val*10 + ')';
    document.body.style.cursor = "wait";
    }
</script>
<title>Timekoin Client Billfold</title>
<link rel="icon" type="image/x-icon" href="img/favicon.ico" />
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link  href="css/admin.css" rel="stylesheet" type="text/css" />
<?php 
    echo $refresh_header;
    echo $script_headers;
    ?>
</head>
<body>
<div id='overlay' style="font-weight:900; background-color:powderblue; position:absolute; text-decoration:blink; top:0; left:0; display:none">
&nbsp;Please Wait...&nbsp;</div>
<div id="main">
<div id="header">
<ul id="top-navigation">
<li><a href="index.php?menu=home" onclick="showWait()" <?php 
    echo $home;
    ?>
>Home</a></li>
<li><a href="index.php?menu=address" onclick="showWait()" <?php 
    echo $address;
    ?>
>Address Book</a></li>
<li><a href="index.php?menu=peerlist" onclick="showWait()" <?php 
    echo $peerlist;
    ?>
>Peerlist</a></li>
<li><a href="index.php?menu=queue" onclick="showWait()" <?php 
    echo $queue;
    ?>
>Queue</a></li>
<li><a href="index.php?menu=send" onclick="showWait()" <?php 
    echo $send;
    ?>
>Send</a></li>
<li><a href="index.php?menu=history" onclick="showWait()" <?php 
    echo $history;
    ?>
>History</a></li>
<li><a href="index.php?menu=options" onclick="showWait()" <?php 
    echo $options;
    ?>
>Options</a></li>
<li><a href="index.php?menu=backup" onclick="showWait()" <?php 
    echo $backup;
    ?>
>Backup</a></li>
<li><a href="index.php?menu=tools" onclick="showWait()" <?php 
    echo $tools;
    ?>
>Tools</a></li>
<li><a href="index.php?menu=logoff" onclick="showWait()" >Log Out</a></li>					 
</ul>
</div>
<div id="middle">
<div id="left-column">
<img src="img/timekoin_logo.png" width="125" height="125" alt="" />
</div>
<div id="center-column">
<div class="top-bar">
<h1><?php 
    echo $contents;
    ?>
</h1>
</div>
<div class="select-bar">
<?php 
    echo $select_bar;
    ?>
</div>
<?php 
    echo $body;
    ?>
</div>
<div id="right-column">
<strong class="h">Quick Info</strong>
<div class="box"><?php 
    echo $quick_info;
    ?>
</div>
</div>
</div>
<div id="footer"><p>Timekoin Crypto Currency Client v<?php 
    echo TIMEKOIN_VERSION;
    ?>
 - <a href="http://timekoin.org">http://timekoin.org</a> &copy; 2010&mdash;<?php 
    echo date('Y');
    ?>
 - ( You are logged in as <strong><?php 
    echo $_SESSION["login_username"];
    ?>
</strong> )</p>
 </div>
</div>
</body>
</html>
<?php 
}