From 3e5960678dd565a7d243fecdada39fa0229fa7a5 Mon Sep 17 00:00:00 2001 From: zhaohui Date: Thu, 25 Dec 2025 17:36:42 +0800 Subject: [PATCH] init --- .gitignore | 5 +- README.md | 6 +- api/get_user_cookie.php | 12 +++ crontab/crosscheck_auto_shell.php | 98 ++++++++++++++++++++ lib/mCrossCheck.php | 190 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 309 insertions(+), 2 deletions(-) create mode 100644 api/get_user_cookie.php create mode 100644 crontab/crosscheck_auto_shell.php create mode 100644 lib/mCrossCheck.php diff --git a/.gitignore b/.gitignore index 84adb3f..75d099e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* - +.vscode/ +cookie_file/* +logs/* +crosscheck_auto_shell/ diff --git a/README.md b/README.md index ef00822..effa0b8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # crosscheck_auto_shell -crosscheck自动登录脚本 \ No newline at end of file +crosscheck自动登录脚本 + +crosscheck网站登录监控很严,服务器经常被ban掉。 + +此程序用于在可用服务器做自动登录,海外服务器可远程获取到cookie字串 diff --git a/api/get_user_cookie.php b/api/get_user_cookie.php new file mode 100644 index 0000000..fb54a41 --- /dev/null +++ b/api/get_user_cookie.php @@ -0,0 +1,12 @@ +getCrossCheckAccount(); + + // 测试数据 + // $list[] = [ + // 'user' => 'mayi001', + // 'passwd' => 'Eg98*!f@42', + // 'ext_info' => 'crossref-26027,zzz', + // ]; + + if (empty($list)){ + throw new Exception('获取crosscheck账号列表为空'); + } + foreach($list as $v){ + // 获得crosscheck账号密码 + $user = trim($v['user']); + $passwd = $v['passwd']; + + $extdata = explode(',', $v['ext_info']); + $tenant = $extdata[0]; + // 账号cookie文件路径 + $cookie_path = __DIR__ . '/../cookie_file/'.$user.'.txt'; + $obj->cookie_path = $cookie_path ; + if (file_exists($cookie_path)) { + chown($cookie_path, 'nobody'); + chgrp($cookie_path, 'nobody'); + chmod($cookie_path, 0777); + } + // 检测账号cookie是否有效 + $res = $obj->islogin(); + if ($res) { + // 账号cookie有效,无需登录 + //exit('账号cookie有效,无需登录'.$user.PHP_EOL); + $str_log = date('Y-m-d H:i:s')."|验证成功|".$user; + file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); + }else{ + //exit('账号cookie过期,无需登录'.$user.PHP_EOL); + // 账号cookie过期,需要重新登录 + unlink($cookie_path); // 删除过期cookie + + // 执行java登录脚本,获取脚本运行的时间 + $start_time = time(true); + $cmd = 'java -jar /datacenter/java/crossrefLogin.jar "' . $user.'" "'.$passwd.'" "'.$cookie_path.'"'; + $console_str = trim(shell_exec($cmd)); + + // 计算脚本运行时间 + $end_time = time(true); + $run_time = $end_time - $start_time; + $run_time_str = date('i:s', $run_time); + $str_log = date('Y-m-d H:i:s')."|登录信息|".$console_str."|运行时间:".$run_time_str; + file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); + // 判断登录是否成功 + if (strpos($console_str, '登录成功') === false) { // 登录失败 + // 记录日志 + $str_log = date('Y-m-d H:i:s')."|登录失败|".$user."|运行时间:".$run_time_str; + file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); + + }else{ + // 记录日志 + $str_log = date('Y-m-d H:i:s')."|登录成功|".$user."|运行时间:".$run_time_str; + file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); + // 推送cookie到正式服务器 + } + system("pkill -9 chrome"); + } + } + sleep(5); + // 删除锁文件 + unlink($lock_file); + + +}catch(Exception $e){ + $str_log = date('Y-m-d H:i:s')."|异常退出|异常信息:".$e->getMessage(); + file_put_contents($log_file, $str_log . PHP_EOL, FILE_APPEND); + // 删除锁文件 + unlink($lock_file); +} \ No newline at end of file diff --git a/lib/mCrossCheck.php b/lib/mCrossCheck.php new file mode 100644 index 0000000..1b0bca6 --- /dev/null +++ b/lib/mCrossCheck.php @@ -0,0 +1,190 @@ + '345d65ddcd3df70d', + '_token' => '6965268557309513', + 'type' => '60', + ); + // 快乐论文左侧导航“开放平台”添加请求IP白名单8.154.43.224 + + // 设置要访问的URL + curl_setopt($ch, CURLOPT_URL, "http://{$domain}/get_turnitin_account"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // 设置CURLOPT_RESOLVE参数 + // 格式:域名:端口:IP地址 + //curl_setopt($ch, CURLOPT_RESOLVE, ["{$domain}:443:{$ip}"]); + curl_setopt($ch, CURLOPT_RESOLVE, ["{$domain}:80:{$ip}"]); + // HTTPS相关设置 + //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 正常验证主机名 + // 传get参数 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + + // 如果需要设置SNI(服务器名称指示) + curl_setopt($ch, CURLOPT_SSLKEY, "{$domain}"); + + // 执行请求 + $response = curl_exec($ch); + print_r($response); + if (curl_errno($ch)) { + //echo 'cURL错误: ' . curl_error($ch); + return false; + } else { + // $info = curl_getinfo($ch); + // echo "实际连接IP: " . $info['primary_ip'] . "\n"; + // echo "HTTP状态码: " . $info['http_code'] . "\n"; + $res = json_decode($response, true); + if (!$res['status']) return false; + $list = $res['data']; + return $list; + } + + curl_close($ch); + } + + /** + * 检查crosscheck账号cookie是否有效 + * @return bool + */ + public function islogin() { + $curl_headers = [ + 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', + 'accept-language: zh-CN,zh;q=0.9,ar;q=0.8', + 'cache-control: max-age=0', + 'priority: u=0, i', + 'sec-ch-ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"', + 'sec-ch-ua-mobile: ?0', + 'sec-ch-ua-platform: "Windows"', + 'sec-fetch-dest: document', + 'sec-fetch-mode: navigate', + 'sec-fetch-site: none', + 'sec-fetch-user: ?1', + 'upgrade-insecure-requests: 1', + 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36' + ]; + $url = 'https://external-production.au.turnitin.com/sms-namespace/sms/sms-serviceName/admin-console-server/sessions'; + $jsonres = $this->requestUrlGet($url,[],$curl_headers); + // {"success":false,"status":401,"reason":"Failed to provide authorization token","message":"AdminException.AdminException"} + // {"success":true} + //var_dump($jsonres); + $res = json_decode($jsonres, true); + //print_r($res); + if ($res['success'] != true) return false; + + return true; + } + + + + /** + * curl GET 请求 + * @param string $url + * @param array $data + * @param array $headers + * @param number $timeout + */ + private function requestUrlGet($url, $data=array(), $headers=array(), $timeout=100) { + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, false); + + $ssl = substr($url, 0, 8) == 'https://' ? true : false; + if ($ssl) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 + } + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, $url); + + curl_setopt($ch, CURLOPT_HEADER, false); + if(!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path); + curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path); + + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + + $result = curl_exec($ch); + curl_close($ch); + + if ($result !== false) return $result; + + return false; + } + + /** + * curl POST请求 + * @param string $url + * @param array $data + * @param array $headers + * @param number $timeout + */ + private function requestUrlPost($url, $data, $headers=array(), $timeout=300) { + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + + $ssl = substr($url, 0, 8) == 'https://' ? true : false; + if ($ssl) { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 + } + + //if($this->part_cookie) curl_setopt($ch, CURLOPT_COOKIE, $this->part_cookie); + if ($this->cookie_path) { + curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path); + curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path); + } + + curl_setopt($ch, CURLOPT_HEADER, true); + if(!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, $url); + + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_AUTOREFERER, true); + + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + + //curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($ch, CURLOPT_NOBODY, false); + $result = curl_exec($ch); + curl_close($ch); + + if (file_exists($this->cookie_path)) { + chown($this->cookie_path, 'nobody'); + chgrp($this->cookie_path, 'nobody'); + } + + if ($result !== false) return $result; + + return false; + } + +}