Example #1
0
 protected function health_core($from_secord, $to_secord)
 {
     $stepNum = Variables::getStepNum();
     $period_secord = $from_secord - $to_secord;
     $step_secord = (int) ($period_secord / $stepNum);
     $now = time();
     #_tp means time point.
     $beforebefore_tp = $now - $from_secord;
     $before_tp = $now - $to_secord;
     $account_time = array();
     $usage_rate = array('success' => 0, 'all' => 0);
     $usage_rate_exact = array('success' => 0, 'all' => 0);
     $aliving = array();
     $codedist = array(300 => array(), 3600 => array(), 14400 => array(), 'MORE' => array());
     $aset = array();
     $codeset = array();
     $slist = Account::period($beforebefore_tp, $before_tp);
     $total = 0.0;
     $interval = array();
     $last = array();
     $interval_count = array();
     foreach ($slist as $account) {
         $username = $account['username'];
         $time = $account['time'];
         $code = $account['code'];
         if ($code == -1) {
             $usage_rate['all'] += 1;
             if (isset($last[$username])) {
                 $interval[$username] += $last[$username] - $time;
                 $last[$username] = $time;
                 $interval_count[$username] += 1;
             } else {
                 $interval[$username] = 0;
                 $last[$username] = $time;
                 $interval_count[$username] = 0;
             }
         } elseif ($code == 0) {
             $usage_rate['success'] += 1;
         }
         if (isset($aset[$username])) {
             if ($code == -1) {
                 unset($aset[$username]);
                 unset($codeset[$username]);
                 $usage_rate_exact['all'] += 1;
             } elseif ($code == 0) {
                 $keep = $aset[$username] - $time;
                 $account_time[] = $keep;
                 $total += $keep;
                 $usage_rate_exact['success'] += 1;
                 if ($keep <= 300) {
                     $keep = 300;
                 } elseif ($keep <= 3600) {
                     $keep = 3600;
                 } elseif ($keep <= 14400) {
                     $keep = 14400;
                 } else {
                     $keep = 'MORE';
                 }
                 if (isset($codedist[$keep][$codeset[$username]])) {
                     $codedist[$keep][$codeset[$username]] += 1;
                 } else {
                     $codedist[$keep][$codeset[$username]] = 1;
                 }
             } else {
                 return redirect('/');
             }
         } else {
             if ($code == -1) {
                 continue;
             } elseif ($code == 0) {
                 $aliving[$username] = Variables::secordtoHMS($now - $time);
             } else {
                 $aset[$username] = $time;
                 $codeset[$username] = $code;
             }
         }
     }
     $res = Variables::chartjs_line_one_inited_with_timedist('account');
     foreach ($account_time as $time) {
         $id = Variables::timedist_getindex($time);
         $res['datasets'][0]['data'][$id] += 1;
     }
     $res = json_encode($res);
     $all_interval = 0;
     $all_interval_count = 0;
     foreach ($interval as $username => $alltime) {
         $all_interval += $alltime;
         $all_interval_count += $interval_count[$username];
     }
     if ($all_interval_count != 0) {
         $ave_interval = Variables::secordtoHMS($all_interval / $all_interval_count);
     } else {
         $ave_interval = 0;
     }
     $sus = $usage_rate['success'];
     $all = $usage_rate['all'];
     $sus_e = $usage_rate_exact['success'];
     $all_e = $usage_rate_exact['all'];
     if ($all != 0) {
         $value = number_format(100 * $sus / $all, 2);
     } else {
         $value = 0;
     }
     if (count($account_time)) {
         $ave = Variables::secordtoHMS($total / count($account_time));
     } else {
         $ave = 0;
     }
     $usage = "{$sus}" . '/' . "{$all}" . ' (' . "{$sus_e}" . '/' . "{$all_e}" . ') ' . "{$value}" . '%. Average reuse interval: ' . "{$ave_interval}" . '. Average alive duration: ' . "{$ave}" . '.';
     $cnt = count($aliving);
     $usage .= " Aliving account: {$cnt}.";
     $code_res_a = array();
     $paes = Variables::paerror();
     foreach ($codedist as $time => $codes) {
         $rest = Variables::chartjs_line_one('one');
         arsort($codes);
         foreach ($codes as $code => $count) {
             $rest['labels'][] = $paes[$code];
             $rest['datasets'][0]['data'][] = $count;
         }
         $code_res_a[$time] = json_encode($rest);
     }
     $url = action('AccountController@hstep', ['']);
     return compact('res', 'code_res_a', 'from_secord', 'to_secord', 'usage', 'aliving', 'url');
 }
Example #2
0
 protected function chartjs_line_one_inited_with_timedist($one)
 {
     $secord_x = Variables::timedist();
     $res = Variables::chartjs_line_one($one);
     foreach ($secord_x as $key => $time) {
         $time = Variables::secordtoHMS($time);
         $res['labels'][$key] = $time;
         $res['datasets'][0]['data'][$key] = 0;
     }
     $res['labels'][count($secord_x)] = 'MORE';
     $res['datasets'][0]['data'][count($secord_x)] = 0;
     return $res;
 }
Example #3
0
 protected function health_core($from_secord, $to_secord)
 {
     $stepNum = Variables::getStepNum();
     $period_secord = $from_secord - $to_secord;
     $step_secord = (int) ($period_secord / $stepNum);
     $now = time();
     #_tp means time point.
     $beforebefore_tp = $now - $from_secord;
     $before_tp = $now - $to_secord;
     $source_kind = array(8 => 'freeproxylists', 9 => 'hidemyass', 10 => 'pachong');
     $source_time = array();
     $source_usage_rate = array('success' => array(), 'all' => array());
     $source_usage_rate_exact = array('success' => array(), 'all' => array());
     $aliving = array();
     foreach ($source_kind as $sk => $st) {
         $source_usage_rate['success'][$sk] = 0;
         $source_usage_rate['all'][$sk] = 0;
         $source_usage_rate_exact['success'][$sk] = 0;
         $source_usage_rate_exact['all'][$sk] = 0;
         $source_time[$sk] = array();
         $aliving[$st] = array();
     }
     $codedist = array(300 => array(), 3600 => array(), 14400 => array(), 'MORE' => array());
     $ipportset = array();
     $codeset = array();
     $slist = Proxy::period($beforebefore_tp, $before_tp);
     foreach ($slist as $proxy) {
         $ipport = $proxy['ipv4_port'];
         $time = $proxy['time'];
         $code = $proxy['code'];
         $source = $proxy['source'];
         if ($code == -1) {
             $source_usage_rate['all'][$source] += 1;
         } elseif ($code == 0) {
             $source_usage_rate['success'][$source] += 1;
         }
         if (isset($ipportset[$ipport])) {
             if ($code == -1) {
                 unset($ipportset[$ipport]);
                 unset($codeset[$ipport]);
                 $source_usage_rate_exact['all'][$source] += 1;
             } elseif ($code == 0) {
                 $keep = $ipportset[$ipport] - $time;
                 $source_time[$source][] = $keep;
                 $source_usage_rate_exact['success'][$source] += 1;
                 if ($keep <= 300) {
                     $keep = 300;
                 } elseif ($keep <= 3600) {
                     $keep = 3600;
                 } elseif ($keep <= 14400) {
                     $keep = 14400;
                 } else {
                     $keep = 'MORE';
                 }
                 if (isset($codedist[$keep][$codeset[$ipport]])) {
                     $codedist[$keep][$codeset[$ipport]] += 1;
                 } else {
                     $codedist[$keep][$codeset[$ipport]] = 1;
                 }
             } else {
                 return redirect('/');
             }
         } else {
             if ($code == -1) {
                 continue;
             } elseif ($code == 0) {
                 $aliving[$source_kind[$source]][$ipport] = Variables::secordtoHMS($now - $time);
             } else {
                 $ipportset[$ipport] = $time;
                 $codeset[$ipport] = $code;
             }
         }
     }
     $res_a = array();
     $avet = array();
     foreach ($source_time as $source => $times) {
         $res = Variables::chartjs_line_one_inited_with_timedist($source_kind[$source]);
         $totalt = 0.0;
         foreach ($times as $time) {
             $id = Variables::timedist_getindex($time);
             $res['datasets'][0]['data'][$id] += 1;
             $totalt += $time;
         }
         if (count($times)) {
             $avet[$source] = Variables::secordtoHMS($totalt / count($times));
         } else {
             $avet[$source] = 0;
         }
         $res_a[$source_kind[$source]] = json_encode($res);
     }
     $usage = array();
     foreach ($source_kind as $sourceid => $sourcestring) {
         $sus = $source_usage_rate['success'][$sourceid];
         $all = $source_usage_rate['all'][$sourceid];
         $sus_e = $source_usage_rate_exact['success'][$sourceid];
         $all_e = $source_usage_rate_exact['all'][$sourceid];
         if ($all != 0) {
             $value = number_format(100 * $sus / $all, 2);
         } else {
             $value = 0;
         }
         $ave = $avet[$sourceid];
         $usage[$sourcestring] = "{$sus}" . '/' . "{$all}" . ' (' . "{$sus_e}" . '/' . "{$all_e}" . ') ' . "{$value}" . '%. Average alive duration: ' . "{$ave}" . '.';
         $cnt = count($aliving[$sourcestring]);
         $usage[$sourcestring] .= " Aliving connections: {$cnt}.";
     }
     $code_res_a = array();
     $paes = Variables::paerror();
     foreach ($codedist as $time => $codes) {
         $rest = Variables::chartjs_line_one('one');
         arsort($codes);
         foreach ($codes as $code => $count) {
             $rest['labels'][] = $paes[$code];
             $rest['datasets'][0]['data'][] = $count;
         }
         $code_res_a[$time] = json_encode($rest);
     }
     $url = action('ProxyController@hstep', ['']);
     return compact('res_a', 'code_res_a', 'from_secord', 'to_secord', 'usage', 'aliving', 'url');
 }
Example #4
0
 protected function fixaccountrecord($from_secord, $to_secord)
 {
     $stepNum = Variables::getStepNum();
     $period_secord = $from_secord - $to_secord;
     $step_secord = (int) ($period_secord / $stepNum);
     $now = time();
     #_tp means time point.
     $beforebefore_tp = $now - $from_secord;
     $before_tp = $now - $to_secord;
     $begin = array();
     $success = array();
     $error = array();
     $ids = array();
     $userset = array();
     $slist = Account::period($beforebefore_tp, $before_tp);
     foreach ($slist as $one) {
         $id = $one['id'];
         $username = $one['username'];
         $code = $one['code'];
         $time = $one['time'];
         if (isset($userset[$username])) {
             if ($code == -1) {
                 unset($userset[$username]);
             } elseif ($code == 0) {
                 continue;
             } else {
                 $error[$id] = array($time, $username);
                 unset($userset[$username]);
             }
         } else {
             if ($code == -1) {
                 $begin[$username] = $time;
                 $ids[] = $id;
             } elseif ($code == 0) {
                 $success[$username] = $time;
                 $ids[] = $id;
             } else {
                 $userset[$username] = 1;
             }
         }
     }
     $beginlist = array();
     foreach ($begin as $username => $time) {
         $time = Variables::secordtoHMS($now - $time);
         $one = "{$username}" . ' => ' . "{$time}";
         if (isset($success[$username])) {
             $time = Variables::secordtoHMS($now - $success[$username]);
             $one .= ' (' . "{$time}" . ')';
         }
         $beginlist[] = $one;
     }
     $errorlist = array();
     foreach ($error as $id => $one) {
         $username = $one[1];
         $time = Variables::secordtoHMS($now - $one[0]);
         $errorlist[$id] = "{$username}" . ' => ' . "{$time}";
     }
     return compact('beginlist', 'errorlist', 'ids');
 }