public function error() { $content = \Hnust\input('content'); if (!empty($content)) { Log::file('android', $content); } }
public function score() { $sid = \Hnust\input('sid'); $name = \Hnust\input('name'); $idcard = \Hnust\input('idcard'); $score = new \Hnust\Analyse\Score($sid, $name, $idcard); echo $score->getScore() && !$score->error ? 'success' : 'error'; }
public function achieve() { $id = \Hnust\input('id/d', -1); $push = new \Hnust\Analyse\Push(); if ($push->achieve($this->uid, $id)) { $this->code = Config::RETURN_NORMAL; } else { $this->msg = '修改失败'; } }
public function __construct($module, $method) { parent::__construct($module, $method); //初始化数据 $this->key = \Hnust\input('key'); $this->uid = \Hnust\input('uid'); $this->sid = \Hnust\input('sid'); $this->secret = \Hnust\input('secret'); $this->passwd = \Hnust\input('passwd'); //权限验证 $this->auth(); }
public function logs() { $file = \Hnust\input('file', null); $files = $this->getList(); if (in_array($file, $files)) { echo '<pre>' . $this->getContent($file) . '</pre>'; } else { foreach ($files as $file) { echo "<a href='/logs?file={$file}'>{$file}</a><br/>\n"; } } }
public function scoreAll($scope, $course, $re = true) { if (empty($this->sid) || empty($course)) { throw new \Exception('参数有误', Config::RETURN_ERROR); } //获取学生信息 $sql = 'SELECT `class`, `major`, `grade`, `school` FROM `student` WHERE `sid` = ? LIMIT 1'; $result = Mysql::execute($sql, array($this->sid)); $this->class = $result[0]['class']; $this->major = $result[0]['major']; $this->grade = $result[0]['grade']; $this->school = $result[0]['school']; //获取所有学生列表 if ('class' === $scope) { $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`idcard`,\n IF(`b`.`score` IS NULL, '[]', `b`.`score`) `score`\n FROM `student` `a`\n LEFT JOIN `score` `b` ON `a`.`sid` = `b`.`sid`\n WHERE `a`.`class` = ?"; $students = Mysql::execute($sql, array($this->class)); $this->scoreName = $this->class; } else { $sql = "SELECT `a`.`sid`, `a`.`name`, `a`.`idcard`,\n IF(`b`.`score` IS NULL, '[]', `b`.`score`) `score`\n FROM `student` `a`\n LEFT JOIN `score` `b` ON `a`.`sid` = `b`.`sid`\n WHERE `a`.`major` = ? AND `a`.`grade` = ? AND `a`.`school` = ?"; $students = Mysql::execute($sql, array($this->major, $this->grade, $this->school)); $this->scoreName = $this->major; } $failures = array(); foreach ($students as $student) { $score = json_decode($student['score'], true); foreach ($score as $termScore) { foreach ($termScore as $courseScore) { if ($courseScore['course'] == $course) { $this->credit = empty($this->credit) ? $courseScore['credit'] : $this->credit; $data[] = array("sid" => $student['sid'], "name" => $student['name'], "score" => $courseScore['mark'], 'resit' => $courseScore['resit']); } } } $temp = empty($data) ? array() : end($data); if ($temp['sid'] != $student['sid']) { $failures[] = array('sid' => $student['sid'], 'name' => $student['name'], 'idcard' => $student['idcard']); } } //多线程与多进程更新成绩 if (\Hnust\input('re\\b', false)) { $failures = $students; } if (!empty($failures) && $re) { $url = Config::getConfig('local_base_url') . 'Update/score'; Http::multi($url, $failures); return $this->scoreAll($scope, $course, false); } elseif (!empty($failures)) { foreach ($failures as $student) { $data[] = array('sid' => $student['sid'], 'name' => $student['name'], 'score' => '-1', 'resit' => false); } } return $data; }
public function update() { $oldPasswd = \Hnust\input('oldPasswd'); $newPasswd = \Hnust\input('newPasswd'); $mail = \Hnust\input('mail'); $phone = \Hnust\input('phone'); //修改密码 if (!empty($oldPasswd) && !empty($newPasswd)) { //验证旧密码 $sql = 'SELECT * FROM `user` WHERE `uid` = ? AND `passwd` = ? LIMIT 1'; $result = Mysql::execute($sql, array($this->uid, \Hnust\passwdEncrypt($this->uid, $oldPasswd))); //原密码错误 if (empty($result)) { //错误次数加1 $sql = 'UPDATE `user` SET `error` = (`error` + 1) WHERE `uid` = ? LIMIT 1'; Mysql::execute($sql, array($this->uid)); $this->code = Config::RETURN_ALERT; $this->msg = '原密码错误'; return false; } //检查弱密码 $sql = 'SELECT COUNT(*) `count` FROM `weak` WHERE `md5` = ? LIMIT 1'; $result = Mysql::execute($sql, array($newPasswd)); if ('0' != $result[0]['count']) { $this->code = Config::RETURN_ALERT; $this->msg = '您的密码过于简单'; return false; } //修改密码 $sql = 'UPDATE `user` SET `passwd` = ?, `error` = 0 WHERE `uid` = ?'; Mysql::execute($sql, array(\Hnust\passwdEncrypt($this->uid, $newPasswd), $this->uid)); //删除其他登陆设备 $tokens = $this->authCache->smembers($this->uid); foreach ($tokens as $token) { if ($token === $this->token) { continue; } $this->authCache->hdelete('token', $token); $this->authCache->sdelete($this->uid, $token); } $this->data = '修改成功,请牢记您的密码'; } //修改其他数据 $sql = "UPDATE `user` `u`,`student` `s`\n SET `s`.`mail` = IF(? = '', `s`.`mail`, ?),\n `s`.`phone` = IF(length(?) <> 11, `s`.`phone`, ?)\n WHERE `s`.`sid` = `u`.`uid` AND `u`.`uid` = ?"; Mysql::execute($sql, array($mail, $mail, $phone, $phone, $this->uid)); Wechat::updateUser($this->uid); $this->msg = '系统提示'; $this->data = empty($this->data) ? '已保存您的修改' : $this->data; $this->code = Config::RETURN_CONFIRM; return true; }
public function electiveQueue() { //设置日志文件 $this->logFileName = 'elective'; if ('是' !== Config::getConfig('is_elective')) { return false; } //全负荷运行 Config::fullLoad(); $id = \Hnust\input('id/d', null); //获取未完成队列列表 if (is_null($id)) { $sql = "SELECT `id` FROM `elective_queue`\n WHERE `result` = '' OR `result` IS NULL\n AND `upTime` < DATE_SUB(NOW(), INTERVAL 3 MINUTE) LIMIT 50"; if ($result = Mysql::execute($sql)) { $baseUrl = Config::getConfig('local_base_url'); foreach ($result as $item) { try { $http = new Http(array(CURLOPT_URL => $baseUrl . 'remind/electiveQueue?id=' . $item['id'], CURLOPT_TIMEOUT => 1)); } catch (\Exception $e) { //pass } } $this->record("=== 执行未处理的选课队列" . count($result) . '条'); } return true; } //执行单个队列 $sql = 'SELECT `s`.`sid`, `s`.`name`, `s`.`mail`, `e`.`title`, `e`.`url` FROM `elective_queue` `e` LEFT JOIN `student` `s` ON `e`.`sid` = `s`.`sid` WHERE `id` = ? LIMIT 1'; if ($queue = Mysql::execute($sql, array($id))) { $queue = $queue[0]; $elective = new \Hnust\Analyse\Elective($queue['sid']); for ($i = 0; $i < 3; $i++) { try { $queue['result'] = $elective->doAction($queue['url']); break; } catch (\Exception $e) { //pass } } //执行成功 if (!empty($queue['result'])) { //更新队列 $sql = 'UPDATE `elective_queue` SET `result` = ? WHERE `id` = ? LIMIT 1'; $sqlArr = array($queue['result'], $id); Mysql::execute($sql, $sqlArr); //推送 $this->remind($queue, $queue['title'], $queue['result'], '#/elective', '1100'); } } }
public function rank() { $by = \Hnust\input('by', 'term'); $scope = \Hnust\input('scope', 'class'); $term = \Hnust\input('term'); if (empty($term) || !in_array(strlen($term), array(9, 11))) { $term = Config::getConfig('current_term'); } elseif ('term' === $by && 11 !== strlen($term)) { $term = Config::getConfig('current_term'); } $term = 'term' !== $by ? substr($term, 0, 9) : $term; $isDownload = \Hnust\input('download/b', false); $rank = new \Hnust\Analyse\Rank($this->sid); if ($isDownload) { $rank->getExcel($this->uid, $term, $scope, $by); } else { $this->data = $rank->getRank($term, $scope, $by); $this->info = array('sid' => $this->sid, 'by' => $by, 'scope' => $scope, 'term' => $term, 'class' => $rank->class, 'major' => $rank->major, 'terms' => $rank->terms, 'courses' => $rank->courses, 'rankName' => $rank->rankName); } }
public function time() { $week = \Hnust\input('week/d'); $gid = \Hnust\input('group/d'); $list = \Hnust\input('list'); //判断周次 if ($week < 1 || $week > 20) { $this->msg = '周次有误,请重新选择'; $this->code = Config::RETURN_ERROR; return; } $student = array(); //群组中获取 if ($gid) { $group = new Group(); $result = $group->getMember($gid); if ($result) { foreach ($result as $item) { $student[] = $item['sid']; } } } //输入框中获取 $list = trim($list); if ($list) { $list = explode("\n", $list); if ($list) { $student = array_merge($student, $list); } } $student = array_unique($student); //判断学号 if (empty($student)) { $this->msg = '学号不能为空,请选择群组或者输入学号'; $this->code = Config::RETURN_ERROR; return; } //正常 $schedule = new \Hnust\Analyse\Schedule('1301010101'); $result = $schedule->getFreeTime($student, $week); $this->data = $result['data']; $this->info = array('week' => $week, 'list' => $list, 'error' => $result['error']); }
public function login() { $passwd = \Hnust\input('passwd'); //获取用户信息 $sql = 'SELECT `error`, `passwd`, `rank` FROM `user` WHERE `uid` = ?'; $result = Mysql::execute($sql, array($this->uid)); //未查找到用户 if (empty($result)) { $this->code = Config::RETURN_ERROR; $this->msg = '该用户不存在,请检查用户名是否正确或长期未使用(长期未使用账号会被系统自动清理)'; return false; } //密码错误次数过多 if ($result[0]['error'] >= Config::getConfig('max_passwd_error')) { $this->code = Config::RETURN_ERROR; $this->msg = '您的错误次数过多,已被限制使用'; return false; } //密码不正确 if ($result[0]['passwd'] !== \Hnust\passwdEncrypt($this->uid, $passwd)) { //错误次数加1 $sql = 'UPDATE `user` SET `error` = (`error` + 1) WHERE `uid` = ? LIMIT 1'; Mysql::execute($sql, array($this->uid)); $this->code = Config::RETURN_ERROR; $this->msg = '您输入的密码有误'; return false; } //选取不重复的token $loginInfo = array('uid' => $this->uid, 'time' => time(), 'ua' => $_SERVER['HTTP_USER_AGENT']); do { $this->token = \Hnust\randStr(32); } while (!$this->authCache->hadd('token', $this->token, $loginInfo)); $this->authCache->sadd($this->uid, $this->token); //更新用户信息 $sql = 'UPDATE `user` SET `error` = 0, `lastTime` = CURRENT_TIMESTAMP WHERE `uid` = ?'; Mysql::execute($sql, array($this->uid)); //设置cookies $cookieTime = time() + Config::getConfig('max_remember_time'); setcookie('token', $this->token, $cookieTime, Config::WEB_PATH . '/'); $this->msg = '登陆成功'; $this->code = Config::RETURN_RECORD_PAGE; $this->info = $this->user(); return true; }
public function deleteMember() { $gid = \Hnust\input('gid'); if (empty($gid)) { $this->code = Config::RETURN_ERROR; $this->msg = '参数不能为空'; return false; } $this->group->deleteMember($gid, $this->sid); $this->msg = "已删除学号{$this->sid}"; }
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 = '已加入更新队列,请通过实时日志查看更新进度'; }