Пример #1
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');
 }
Пример #2
0
 protected function monitor_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;
     $adjustdt = Adjust::period($beforebefore_tp, $before_tp);
     $res = Variables::chartjs_line_one_inited_with_time($beforebefore_tp, $step_secord, $stepNum);
     foreach ($adjustdt as $adj) {
         $updated = $adj->updated;
         #$updated = $adj['updated'];
         $i = (int) (($updated - $beforebefore_tp - 10) / $step_secord);
         if ($i == $stepNum) {
             $i -= 1;
         }
         $res['datasets'][0]['data'][$i] += 1;
     }
     $res = json_encode($res);
     $url = action('AdjustController@mstep', ['']);
     return compact('res', 'from_secord', 'to_secord', 'url');
 }
Пример #3
0
 public function circle_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;
     $slist = AccountC::period($beforebefore_tp, $before_tp);
     $res = Variables::chartjs_line_one_inited_with_time($beforebefore_tp, $step_secord, $stepNum);
     foreach ($slist as $sone) {
         $time = $sone['time'];
         $i = (int) (($time - $beforebefore_tp - 10) / $step_secord);
         $res['datasets'][0]['data'][$i] += 1;
     }
     $res = json_encode($res);
     $url = action('AccountController@cstep', ['']);
     return compact('res', 'from_secord', 'to_secord', 'url');
 }
Пример #4
0
 protected function cheating_core($from_secord, $to_secord)
 {
     #$period_secord > 3600s, 1h.
     #$stepNum for now 60, never > 100.
     #so, $step_secord > 36s.
     $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;
     $res = Variables::chartjs_line_four_inited_with_time($beforebefore_tp, $step_secord, $stepNum, 'try', 'fine', 'cheating', 'other');
     $tasks = Task::period3($beforebefore_tp, $before_tp, 4);
     $cheatings = array();
     foreach ($tasks as $tk) {
         #$task_tp = $tk['time'];
         #$task_code = $tk['code'];
         #$task_zid = $tk['zid'];
         $task_tp = $tk->time;
         $task_code = $tk->code;
         $task_zid = $tk->zid;
         $i = (int) (($task_tp - $beforebefore_tp) / $step_secord);
         if ($i == $stepNum) {
             $i -= 1;
         }
         if ($task_code == -1) {
             $res['datasets'][0]['data'][$i] += 1;
         } elseif ($task_code == 0) {
             $res['datasets'][1]['data'][$i] += 1;
         } elseif ($task_code == 1) {
             $res['datasets'][2]['data'][$i] += 1;
             $cheatings[] = $task_zid;
         } else {
             $res['datasets'][3]['data'][$i] += 1;
         }
     }
     $res = json_encode($res);
     $url = action('TaskController@ccstep', ['']);
     return compact('res', 'from_secord', 'to_secord', 'url', 'cheatings');
 }
Пример #5
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');
 }