Exemple #1
0
 public function getScore()
 {
     $cache = new Cache('score');
     $cacheData = $cache->get($this->sid);
     if (time() - $cacheData['time'] <= \Hnust\Config::getConfig('score_cache_time')) {
         return $cacheData['data'];
     }
     try {
         $score = parent::getScore();
         //从成绩中获取个人信息
         $sid = $score['info']['sid'];
         $class = $score['info']['class'];
         $major = $score['info']['major'];
         $college = $score['info']['college'];
         $grade = $class[0] . $class[1] . "级";
         $time = $score['info']['time'];
         $score = $score['data'];
         //更新资料表
         $sql = 'UPDATE `student` SET `sid` = ?, `class` = ?, `major` = ?, `college` = ?, `grade` = ? WHERE `sid` = ?';
         Mysql::execute($sql, array($sid, $class, $major, $college, $grade, $this->sid));
         //更新成绩表
         $sql = "INSERT INTO `score`(`sid`, `score`, `time`) VALUES(?, ?, ?)\n                    ON DUPLICATE KEY UPDATE `score` = ?, `time` = ?";
         $jsonScore = json_encode($score, JSON_UNESCAPED_UNICODE);
         Mysql::execute($sql, array($sid, $jsonScore, $time, $jsonScore, $time));
         $cache->set($this->sid, array('time' => time(), 'data' => $score));
     } catch (\Exception $e) {
         if ($e->getCode() !== Config::RETURN_ERROR) {
             throw new \Exception($e->getMessage(), $e->getCode());
             //从数据库中获取成绩缓存
         } elseif (empty($cacheData)) {
             $sql = 'SELECT `score`, `time` FROM `score` WHERE `sid` = ?';
             $result = Mysql::execute($sql, array($this->sid));
             if (!empty($result)) {
                 $cacheData = array('time' => $result[0]['time'], 'data' => json_decode($result[0]['score'], true));
             }
         }
         //无缓存抛出异常
         if (empty($cacheData)) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
         $time = date('Y-m-d H:i:s', $cacheData['time']);
         $this->error = $e->getMessage() . "\n当前数据更新时间为:" . $time;
         $score = $cacheData['data'];
     }
     return $score;
 }
Exemple #2
0
 public function getTuition()
 {
     $cache = new Cache('tuition');
     //$cacheData = $cache->get($this->sid);
     if (time() - $cacheData['time'] <= Config::getConfig('tuition_cache_time')) {
         return $cacheData['data'];
     }
     try {
         $tuition = parent::getTuition();
         $cache->set($this->sid, array('time' => time(), 'data' => $tuition));
     } catch (\Exception $e) {
         if (empty($cacheData) || $e->getCode() !== Config::RETURN_ERROR) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
         $time = date('Y-m-d H:i:s', $cacheData['time']);
         $this->error = $e->getMessage() . "\n当前数据更新时间为:" . $time;
         $tuition = $cacheData['data'];
     }
     return $tuition;
 }
Exemple #3
0
 public function token()
 {
     $num = 0;
     $sql = 'SELECT `uid` FROM `user`';
     $users = Mysql::execute($sql);
     $cache = new Cache('auth');
     $remember = Config::getConfig('max_remember_time');
     foreach ($users as $user) {
         $tokens = $cache->smembers($user['uid']);
         if (empty($tokens)) {
             continue;
         }
         foreach ($tokens as $token) {
             $loginInfo = $cache->hget('token', $token);
             if (time() - $loginInfo['time'] > $remember) {
                 $num++;
                 $cache->hdelete('token', $token);
                 $cache->sdelete($user['uid'], $token);
             }
         }
     }
     return "删除Token{$num}条";
 }
Exemple #4
0
 public function getCredit()
 {
     //读取缓存
     $cache = new Cache('credit');
     $cacheData = $cache->get($this->sid);
     //判断缓存时间
     if (time() - $cacheData['time'] <= Config::getConfig('credit_cache_time')) {
         return $cacheData['data'];
     }
     try {
         //获取最新学分绩点
         $credit = parent::getCredit();
         $cache->set($this->sid, array('time' => time(), 'data' => $credit));
     } catch (\Exception $e) {
         if (empty($cacheData) || $e->getCode() !== Config::RETURN_ERROR) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
         //读取旧记录
         $time = date('Y-m-d H:i:s', $cacheData['time']);
         $this->error = $e->getMessage() . "\n当前数据更新时间为:" . $time;
         $credit = $cacheData['data'];
     }
     return $credit;
 }
Exemple #5
0
 public function network()
 {
     //设置日志文件
     $this->logFileName = 'network';
     //获取最新数据
     $net = file_get_contents('/proc/net/dev');
     $pattern = "/eth1:\\s*(\\d+)\\s+(\\d+)\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+(\\d+)\\s+(\\d+)/";
     preg_match($pattern, $net, $matches);
     $newRes = array('in' => array('bytes' => $matches[1], 'packets' => $matches[2]), 'out' => array('bytes' => $matches[3], 'packets' => $matches[4]), 'time' => time());
     //处理缓存数据
     $cache = new Cache('remind_network');
     $oldRes = $cache->get('res');
     $cache->set('res', $newRes);
     if (empty($oldRes)) {
         return;
     }
     //判断是否提醒
     $minutes = number_format(($newRes['time'] - $oldRes['time']) / 60, 2);
     $bytes = $newRes['out']['bytes'] - $oldRes['out']['bytes'];
     $currentSize = \Hnust\sizeFormat($bytes);
     $totalSize = \Hnust\sizeFormat($newRes['out']['bytes']);
     $remindValue = Config::getConfig('network_remind_value');
     $remindUser = Config::getConfig('network_remind_user');
     if ($bytes > $remindValue) {
         $sql = 'SELECT `sid`, `name`, `mail` FROM `student` WHERE `sid` = ?';
         $result = Mysql::execute($sql, array($remindUser));
         $student = $result[0];
         $title = '服务器流量异常提醒 -- Tick团队';
         $content = "尊敬的管理员您好,系统检测服务器出网流量在 {$minutes} 分钟内共消耗了 {$currentSize},累计使用 {$totalSize},请及时处理!";
         $this->remind($student, $title, $content, '', '0100');
     }
     $this->record("{$minutes} 分钟内共消耗出网流量 {$currentSize},累计使用 {$totalSize}");
 }
Exemple #6
0
 public function getSchdule($sid, $term, $type = 0, $week = -1)
 {
     $cache = new Cache('schedule');
     $cacheData = $cache->get($sid);
     $cacheData = empty($cacheData) ? array() : $cacheData;
     if (time() - $cacheData[$term]['time'] <= \Hnust\Config::getConfig('schedule_cache_time')) {
         return $this->type($cacheData[$term]['data'], $type, $week);
     }
     try {
         $schedule = parent::getSchdule($sid, $term);
         //更新课表数据库
         if ($term === Config::getConfig('current_term')) {
             $sql = "INSERT INTO `schedule`(`sid`, `schedule`, `term`, `time`) VALUES(?, ?, ?, ?)\n                        ON DUPLICATE KEY UPDATE `schedule` = ?, `time` = ?";
             $jsonSchedule = json_encode($schedule, JSON_UNESCAPED_UNICODE);
             Mysql::execute($sql, array($sid, $jsonSchedule, $term, $time, $jsonSchedule, $time));
         }
         //设置缓存
         $cacheData[$term] = array('time' => time(), 'data' => $schedule);
         $cache->set($sid, $cacheData);
     } catch (\Exception $e) {
         if (empty($cacheData[$term]) || $e->getCode() !== Config::RETURN_ERROR) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
         $time = date('Y-m-d H:i:s', $cacheData[$term]['time']);
         $this->error = $e->getMessage() . "\n当前数据更新时间为:" . $time;
         $schedule = $cacheData[$term]['data'];
     }
     return $this->type($schedule, $type, $week);
 }
Exemple #7
0
 public function update()
 {
     $type = \Hnust\input('type');
     $start = \Hnust\input('start');
     $cookie = \Hnust\input('cookie');
     $cache = new Cache('update');
     //更新缓存数据
     $cacheData = $cache->get($type);
     $cacheData = empty($cacheData) ? array() : $cacheData;
     if (!empty($start)) {
         $cacheData['start'] = $start;
     }
     if (!empty($cookie)) {
         $cacheData['cookie'] = $cookie;
     }
     $cache->set($type, $cacheData);
     $url = Config::getConfig('local_base_url') . 'update/' . $type;
     try {
         new Http(array(CURLOPT_URL => $url, CURLOPT_TIMEOUT => 1));
     } catch (\Exception $e) {
         //pass
     }
     $this->msg = '已加入更新队列,请通过实时日志查看更新进度';
 }