2024-10-10
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPMailer Exception class.
|
||||
* PHP Version 5.5.
|
||||
*
|
||||
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
|
||||
*
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
* @author Brent R. Matzelle (original founder)
|
||||
* @copyright 2012 - 2020 Marcus Bointon
|
||||
* @copyright 2010 - 2012 Jim Jagielski
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html GNU Lesser General Public License
|
||||
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
namespace PHPMailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* PHPMailer exception handler.
|
||||
*
|
||||
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Prettify error message output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage()
|
||||
{
|
||||
return '<strong>' . htmlspecialchars($this->getMessage(), ENT_COMPAT | ENT_HTML401) . "</strong><br />\n";
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 数据库备份还原类
|
||||
* @author
|
||||
* Class DatabaseTool
|
||||
*/
|
||||
class DatabaseTool
|
||||
{
|
||||
private $handler;
|
||||
private $config = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 3306,
|
||||
'user' => 'root',
|
||||
'password' => '',
|
||||
'database' => 'lk2',
|
||||
'charset' => 'utf-8',
|
||||
'target' => 'sql.sql'
|
||||
);
|
||||
private $tables = array();
|
||||
private $error;
|
||||
private $begin; //开始时间
|
||||
|
||||
/**
|
||||
* 架构方法
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->begin = microtime(true);
|
||||
$config = is_array($config) ? $config : array();
|
||||
$this->config = $config;
|
||||
//启动PDO连接
|
||||
if (!$this->handler instanceof PDO) {
|
||||
try {
|
||||
$this->handler = new PDO("mysql:host={$this->config['host']}:{$this->config['port']};dbname={$this->config['database']}", $this->config['user'], $this->config['password']);
|
||||
} catch (PDOException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
echo $this->error;
|
||||
return false;
|
||||
} catch (Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
echo $this->error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份
|
||||
* @param array $tables
|
||||
* @return bool
|
||||
*/
|
||||
public function backup($tables = array())
|
||||
{
|
||||
//存储表定义语句的数组
|
||||
$ddl = array();
|
||||
//存储数据的数组
|
||||
$data = array();
|
||||
$this->setTables($tables);
|
||||
|
||||
if (!empty($this->tables)) {
|
||||
foreach ($this->tables as $table) {
|
||||
$ddl[] = $this->getDDL($table);
|
||||
$data[] = $this->getData($table);
|
||||
}
|
||||
//开始写入
|
||||
|
||||
//var_dump($data);
|
||||
$this->writeToFile($this->tables, $ddl, $data);
|
||||
} else {
|
||||
$this->error = '数据库中没有表!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置要备份的表
|
||||
* @param array $tables
|
||||
*/
|
||||
private function setTables($tables = array())
|
||||
{
|
||||
if (!empty($tables) && is_array($tables)) {
|
||||
//备份指定表
|
||||
$this->tables = $tables;
|
||||
} else {
|
||||
//备份全部表
|
||||
$this->tables = $this->getTables();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* @param string $sql
|
||||
* @return mixed
|
||||
*/
|
||||
private function query($sql = '')
|
||||
{
|
||||
$stmt = $this->handler->query($sql);
|
||||
$stmt->setFetchMode(PDO::FETCH_NUM);
|
||||
$list = $stmt->fetchAll();
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部表
|
||||
* @return array
|
||||
*/
|
||||
private function getTables()
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
$list = $this->query($sql);
|
||||
$tables = array();
|
||||
foreach ($list as $value) {
|
||||
$tables[] = $value[0];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表定义语句
|
||||
* @param string $table
|
||||
* @return mixed
|
||||
*/
|
||||
private function getDDL($table = '')
|
||||
{
|
||||
$sql = "SHOW CREATE TABLE `{$table}`";
|
||||
$ddl = $this->query($sql)[0][1] . ';';
|
||||
return $ddl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表数据
|
||||
* @param string $table
|
||||
* @return mixed
|
||||
*/
|
||||
private function getData($table = '')
|
||||
{
|
||||
$sql = "SHOW COLUMNS FROM `{$table}`";
|
||||
$list = $this->query($sql);
|
||||
//字段
|
||||
$columns = '';
|
||||
//需要返回的SQL
|
||||
$query = '';
|
||||
foreach ($list as $value) {
|
||||
$columns .= "`{$value[0]}`,";
|
||||
}
|
||||
$columns = substr($columns, 0, -1);
|
||||
$data = $this->query("SELECT * FROM `{$table}`");
|
||||
foreach ($data as $value) {
|
||||
$dataSql = '';
|
||||
foreach ($value as $v) {
|
||||
$dataSql .= "'{$v}',";
|
||||
}
|
||||
$dataSql = substr($dataSql, 0, -1);
|
||||
$query .= "INSERT INTO `{$table}` ({$columns}) VALUES ({$dataSql});\r\n";
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入文件
|
||||
* @param array $tables
|
||||
* @param array $ddl
|
||||
* @param array $data
|
||||
*/
|
||||
private function writeToFile($tables = array(), $ddl = array(), $data = array())
|
||||
{
|
||||
$str = "/*\r\nMySQL Database Backup Tools\r\n";
|
||||
$str .= "Server:{$this->config['host']}:{$this->config['port']}\r\n";
|
||||
$str .= "Database:{$this->config['database']}\r\n";
|
||||
$str .= "Data:" . date('Y-m-d H:i:s', time()) . "\r\n*/\r\n";
|
||||
$str .= "SET FOREIGN_KEY_CHECKS=0;\r\n";
|
||||
$i = 0;
|
||||
foreach ($tables as $table) {
|
||||
$str .= "-- ----------------------------\r\n";
|
||||
$str .= "-- Table structure for {$table}\r\n";
|
||||
$str .= "-- ----------------------------\r\n";
|
||||
$str .= "DROP TABLE IF EXISTS `{$table}`;\r\n";
|
||||
$str .= $ddl[$i] . "\r\n";
|
||||
$str .= "-- ----------------------------\r\n";
|
||||
$str .= "-- Records of {$table}\r\n";
|
||||
$str .= "-- ----------------------------\r\n";
|
||||
$str .= $data[$i] . "\r\n";
|
||||
$i++;
|
||||
}
|
||||
echo file_put_contents($this->config['target'], $str) ? 'Backup Finished! Time' . (microtime(true) - $this->begin) . 'ms' : 'Fail!';
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
* @return mixed
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function restore($path = '')
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
$this->error('SQL文件不存在!');
|
||||
return false;
|
||||
} else {
|
||||
$sql = $this->parseSQL($path);
|
||||
try {
|
||||
$this->handler->exec($sql);
|
||||
echo '还原成功!花费时间', (microtime(true) - $this->begin) . 'ms';
|
||||
} catch (PDOException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析SQL文件为SQL语句数组
|
||||
* @param string $path
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
private function parseSQL($path = '')
|
||||
{
|
||||
$sql = file_get_contents($path);
|
||||
$sql = explode("\r\n", $sql);
|
||||
//先消除--注释
|
||||
$sql = array_filter($sql, function ($data) {
|
||||
if (empty($data) || preg_match('/^--.*/', $data)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
$sql = implode('', $sql);
|
||||
//删除/**/注释
|
||||
$sql = preg_replace('/\/\*.*\*\//', '', $sql);
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
var keyStr = "3WiPZ+xr/yKf5OdQ6UATHYItebL8B0njk192cJRNagGm7hoECvFVpqw4DsMlzuXS=";
|
||||
//将Ansi编码的字符串进行Base64编码
|
||||
function encode64(input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3 = "";
|
||||
var enc1, enc2, enc3, enc4 = "";
|
||||
var i = 0;
|
||||
do {
|
||||
chr1 = input.charCodeAt(i++);
|
||||
chr2 = input.charCodeAt(i++);
|
||||
chr3 = input.charCodeAt(i++);
|
||||
enc1 = chr1 >> 2;
|
||||
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
||||
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
||||
enc4 = chr3 & 63;
|
||||
if (isNaN(chr2)) {
|
||||
enc3 = enc4 = 64;
|
||||
} else if (isNaN(chr3)) {
|
||||
enc4 = 64;
|
||||
}
|
||||
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)
|
||||
+ keyStr.charAt(enc3) + keyStr.charAt(enc4);
|
||||
chr1 = chr2 = chr3 = "";
|
||||
enc1 = enc2 = enc3 = enc4 = "";
|
||||
} while (i < input.length);
|
||||
return output;
|
||||
}
|
||||
//将Base64编码字符串转换成Ansi编码的字符串
|
||||
function decode64(input) {
|
||||
var output = "";
|
||||
var chr1, chr2, chr3 = "";
|
||||
var enc1, enc2, enc3, enc4 = "";
|
||||
var i = 0;
|
||||
if (input.length % 4 != 0) {
|
||||
return "";
|
||||
}
|
||||
var base64test = /[^A-Za-z0-9\+\/\=]/g;
|
||||
if (base64test.exec(input)) {
|
||||
return "";
|
||||
}
|
||||
do {
|
||||
enc1 = keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = keyStr.indexOf(input.charAt(i++));
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
output = output + String.fromCharCode(chr1);
|
||||
if (enc3 != 64) {
|
||||
output += String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 != 64) {
|
||||
output += String.fromCharCode(chr3);
|
||||
}
|
||||
chr1 = chr2 = chr3 = "";
|
||||
enc1 = enc2 = enc3 = enc4 = "";
|
||||
} while (i < input.length);
|
||||
return output;
|
||||
}
|
||||
function utf16to8(str) {
|
||||
var out, i, len, c;
|
||||
out = "";
|
||||
len = str.length;
|
||||
for(i = 0; i < len; i++) {
|
||||
c = str.charCodeAt(i);
|
||||
if ((c >= 0x0001) && (c <= 0x007F)) {
|
||||
out += str.charAt(i);
|
||||
} else if (c > 0x07FF) {
|
||||
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
|
||||
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
|
||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
||||
} else {
|
||||
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
|
||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function utf8to16(str) {
|
||||
var out, i, len, c;
|
||||
var char2, char3;
|
||||
out = "";
|
||||
len = str.length;
|
||||
i = 0;
|
||||
while(i < len) {
|
||||
c = str.charCodeAt(i++);
|
||||
switch(c >> 4) {
|
||||
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
||||
// 0xxxxxxx
|
||||
out += str.charAt(i-1);
|
||||
break;
|
||||
case 12: case 13:
|
||||
// 110x xxxx 10xx xxxx
|
||||
char2 = str.charCodeAt(i++);
|
||||
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
||||
break;
|
||||
case 14:
|
||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||
char2 = str.charCodeAt(i++);
|
||||
char3 = str.charCodeAt(i++);
|
||||
out += String.fromCharCode(((c & 0x0F) << 12) |
|
||||
((char2 & 0x3F) << 6) |
|
||||
((char3 & 0x3F) << 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
//
|
||||
//var de = encode64(utf16to8("source"));
|
||||
//document.writeln(de+"<br>");
|
||||
//var ee = utf8to16(decode64(de))
|
||||
//document.writeln(ee);
|
||||
//
|
||||
//-->
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* base64编码
|
||||
* @author :xia0ji233
|
||||
*/
|
||||
function decode64($input) {
|
||||
$keyStr = "3WiPZ+xr/yKf5OdQ6UATHYItebL8B0njk192cJRNagGm7hoECvFVpqw4DsMlzuXS=";//换表
|
||||
$output = "";
|
||||
$chr1="";
|
||||
$chr2="";
|
||||
$chr3="";
|
||||
$enc1=$enc2=$enc3=$enc4="";
|
||||
$i = 0;
|
||||
if (strlen($input) % 4 != 0) {
|
||||
return "";
|
||||
}
|
||||
$len=strlen($input);
|
||||
do {
|
||||
$enc1 = strpos($keyStr,$input[$i++]);
|
||||
$enc2 = strpos($keyStr,$input[$i++]);
|
||||
$enc3 = strpos($keyStr,$input[$i++]);
|
||||
$enc4 = strpos($keyStr,$input[$i++]);
|
||||
$chr1 = ($enc1 << 2) | ($enc2 >> 4);
|
||||
$chr2 = (($enc2 & 15) << 4) | ($enc3 >> 2);
|
||||
$chr3 = (($enc3 & 3) << 6) | $enc4;
|
||||
$output = $output.chr($chr1);
|
||||
|
||||
if ($enc3 != 64) {
|
||||
$output .= chr($chr2);
|
||||
}
|
||||
if ($enc4 != 64) {
|
||||
$output .= chr($chr3);
|
||||
}
|
||||
$chr1 = $chr2 = $chr3 = "";
|
||||
$enc1 = $enc2 = $enc3 = $enc4 = "";
|
||||
} while ($i < $len);
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
php-bbcode
|
||||
BBCode to HTML conversion, in PHP7.
|
||||
Greg Kennedy <kennedy.greg@gmail.com>, 2018
|
||||
https://github.com/greg-kennedy/php-bbcode
|
||||
This is public domain software. Please see LICENSE for more details.
|
||||
******************************************************************************/
|
||||
|
||||
class BBCode
|
||||
{
|
||||
// Tag aliases. Item on left translates to item on right.
|
||||
const TAG_ALIAS = [
|
||||
'url' => 'a',
|
||||
'code' => 'pre',
|
||||
'quote' => 'blockquote',
|
||||
'*' => 'li',
|
||||
'list' => 'ul'
|
||||
];
|
||||
|
||||
// helper function: normalize a potential "tag"
|
||||
// convert to lowercase and check against the alias list
|
||||
// returns a named array with details about the tag
|
||||
static private function decode_tag($input) : array
|
||||
{
|
||||
// first determine if it's opening on closing tag, then substr out the inner portion
|
||||
if ($input[1] === '/') {
|
||||
$open = 0;
|
||||
$inner = substr($input, 2, -1);
|
||||
} else {
|
||||
$open = 1;
|
||||
$inner = substr($input, 1, -1);
|
||||
}
|
||||
|
||||
// oneliner to burst inner by spaces, then burst each of those by equals signs
|
||||
$params = array_map(
|
||||
function($a) { return explode('=', $a, 2); },
|
||||
explode(' ', $inner));
|
||||
|
||||
// first "param" is special - it's the tag name and (optionally) the default arg
|
||||
$first = array_shift($params);
|
||||
|
||||
// tag name
|
||||
$name = strtolower($first[0]);
|
||||
if (isset(self::TAG_ALIAS[$name])) {
|
||||
$name = self::TAG_ALIAS[$name];
|
||||
}
|
||||
|
||||
// "default" (unnamed) argument
|
||||
$args = null;
|
||||
if (isset ($first[1])) {
|
||||
$args['default'] = $first[1];
|
||||
//echo $first[1];
|
||||
}
|
||||
|
||||
// finally, put the rest of the args in the list
|
||||
//array_walk( $params, function(&$a, $i, &$args) { print_r($args); $args[strtolower($a[1])] = $a[0]; }, $args);
|
||||
foreach ($params as &$param) {
|
||||
$k = isset($param[0]) ? strtolower($param[0]) : '';
|
||||
$v = isset($param[1]) ? $param[1] : '';
|
||||
$args[$k] = $v;
|
||||
}
|
||||
|
||||
return [ 'name' => $name, 'open' => $open, 'args' => $args ];
|
||||
}
|
||||
|
||||
// helper function: normalize HTML entities, with newline handling
|
||||
static private function encode($input) : string
|
||||
{
|
||||
return $input;
|
||||
// break substring into individual unicode chars
|
||||
$characters = preg_split('//u', $input, null, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// append each one-at-a-time to create output
|
||||
$lf = 0;
|
||||
$output = '';
|
||||
foreach ($characters as &$ch)
|
||||
{
|
||||
if ($ch === "\n") {
|
||||
$lf ++;
|
||||
} elseif ($ch === "\r") {
|
||||
continue;
|
||||
} else {
|
||||
if ($lf === 1) {
|
||||
$output .= "\n<br>";
|
||||
$lf = 0;
|
||||
} elseif ($lf > 1) {
|
||||
$output .= "\n\n<p>";
|
||||
$lf = 0;
|
||||
}
|
||||
|
||||
if ($ch === '<') {
|
||||
$output .= '<';
|
||||
} elseif ($ch === '>') {
|
||||
$output .= '>';
|
||||
} elseif ($ch === '&') {
|
||||
$output .= '&';
|
||||
} elseif ($ch === "\u{00A0}") {
|
||||
$output .= ' ';
|
||||
} else {
|
||||
$output .= $ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// trailing linefeed handle
|
||||
if ($lf === 1) {
|
||||
$output .= "\n<br>";
|
||||
} elseif ($lf > 1) {
|
||||
$output .= "\n\n<p>";
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Renders a BBCode string to HTML, for inclusion into a document.
|
||||
static public function bbcode_to_html($input) : string
|
||||
{
|
||||
global $MSG_TOTAL;
|
||||
global $MSG_NUMBER_OF_PROBLEMS;
|
||||
|
||||
// split input string into array using regex, UTF-8 aware
|
||||
// this should give us tokens to work with
|
||||
|
||||
// The regex is: one or more characters within square brackets,
|
||||
// where the characters are any in this list (allowable URI chars):
|
||||
// ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -._~:/?#@!$&'()*+,;=%
|
||||
// Square brackets are technically allowed, but excluded here, because they interfere.
|
||||
$match_count = preg_match_all("/\[[A-Za-z0-9 \-._~:\/?#@!$&'()*+,;=%]+\]/u",
|
||||
$input, $matches, PREG_OFFSET_CAPTURE);
|
||||
if ($match_count === FALSE) {
|
||||
throw new RuntimeException('Fatal error in preg_match_all for BBCode tags');
|
||||
}
|
||||
|
||||
// begin with the empty string
|
||||
$output = '';
|
||||
$input_ptr = 0;
|
||||
$plist_color = Array('panel-success','panel-info','panel-warning','panel-danger');
|
||||
global $colorIndex;
|
||||
|
||||
$stack = [];
|
||||
for ($match_idx = 0; $match_idx < $match_count; $match_idx ++)
|
||||
{
|
||||
list($match, $offset) = $matches[0][$match_idx];
|
||||
|
||||
// pick up chars between tags and HTML-encode them
|
||||
$output .= self::encode(substr($input, $input_ptr, $offset - $input_ptr));
|
||||
// advance input_ptr to just past the current tag
|
||||
$input_ptr = $offset + strlen($match);
|
||||
|
||||
// decode the tag 7.0 do not supported (16.04)
|
||||
//list('name' => $name, 'open' => $open, 'args' => $args) = self::decode_tag($match);
|
||||
$decode_data= self::decode_tag($match);
|
||||
$name=$decode_data['name'];
|
||||
$open=$decode_data['open'];
|
||||
$args=$decode_data['args'];
|
||||
if (! $open) {
|
||||
// CLOSING TAG
|
||||
|
||||
// Search the tag stack and see if the opening tag was pushed into it
|
||||
if (array_search($name, $stack, TRUE) === FALSE) {
|
||||
// Attempted to close a tag that was not on the stack!
|
||||
$output = $output . self::encode($match);
|
||||
} else {
|
||||
//pop repeatedly until we pop the tag, and close everything on the way
|
||||
do {
|
||||
$popped_name = array_pop($stack);
|
||||
$output = $output . '</' . $popped_name . '>';
|
||||
} while ($name !== $popped_name);
|
||||
}
|
||||
} else {
|
||||
// OPENING TAG
|
||||
|
||||
// Big if / elseif ladder to handle each tag
|
||||
if ($name === 'b' || $name === 'u' || $name === 'sup' || $name === 'sub' ||
|
||||
$name === 'blockquote' ||
|
||||
$name === 'ol' || $name === 'ul' ||
|
||||
$name === 'table') {
|
||||
// Simple tags (no validation or alternate modes)
|
||||
$stack[] = $name;
|
||||
$output = $output . '<' . $name . '>';
|
||||
} elseif ($name === 'li') {
|
||||
// Disallow [li] outside of [ol] or [ul]
|
||||
if (array_search('ol', $stack, TRUE) !== FALSE ||
|
||||
array_search('ul', $stack, TRUE) !== FALSE) {
|
||||
$stack[] = 'li';
|
||||
$output .= '<li>';
|
||||
} else {
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
} elseif ($name === 'tr') {
|
||||
// Disallow [tr] outside of [table]
|
||||
if (array_search('table', $stack, TRUE) !== FALSE) {
|
||||
$stack[] = 'tr';
|
||||
$output .= '<tr>';
|
||||
} else {
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
} elseif ($name === 'td' || $name === 'th') {
|
||||
// Disallow [th] / [td] outside of [tr] outside of [table]
|
||||
$tr_index = array_search('tr', $stack, TRUE);
|
||||
$table_index = array_search('table', $stack, TRUE);
|
||||
if ($tr_index !== FALSE && $table_index !== FALSE && $table_index < $tr_index) {
|
||||
$stack[] = $name;
|
||||
$output = $output . '<' . $name . '>';
|
||||
} else {
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
|
||||
} elseif ($name === 'font') {
|
||||
// Font size adjustment. This requires an argument, one of "size" or "color" (or both).
|
||||
$font_param = [];
|
||||
|
||||
if (isset ($args['size'])) {
|
||||
//TODO: size validation
|
||||
$font_param['font-size'] = $args['size'];
|
||||
}
|
||||
if (isset ($args['color'])) {
|
||||
//TODO: color validation
|
||||
$font_param['color'] = $args['color'];
|
||||
}
|
||||
//TODO: handle bad settings
|
||||
|
||||
if (! empty($font_param)) {
|
||||
$stack[] = 'font';
|
||||
|
||||
// append all css_style params
|
||||
$css_style = [];
|
||||
foreach ($font_param as $name=>$value) {
|
||||
$css_style[] = $name . ': ' . $value;
|
||||
}
|
||||
$output = $output . '<span style="' . implode(';', $css_style) . '">';
|
||||
} else {
|
||||
// Font tag without good args is useless.
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
|
||||
// SPECIAL TAG HANDLING
|
||||
} elseif ($name === 'pre') {
|
||||
// [pre] / [code] put us into RAW mode, where nothing is parsed except [/code]
|
||||
|
||||
for ($i = $match_idx + 1; $i < $match_count; $i ++)
|
||||
{
|
||||
list($search_match, $search_offset) = $matches[0][$i];
|
||||
$search_tag = self::decode_tag($search_match);
|
||||
if (! $search_tag['open'] && $search_tag['name'] === 'pre') { break; }
|
||||
}
|
||||
|
||||
if ($i < $match_count) {
|
||||
// successfully found ending tag
|
||||
|
||||
// encode everything contained between here and there
|
||||
$output = $output . '<pre>' . self::encode(substr($input, $input_ptr, $search_offset - $input_ptr)) . '</pre>';
|
||||
// advance ptr (again)
|
||||
$input_ptr = $search_offset + strlen($search_match);
|
||||
// update search position
|
||||
$match_idx = $i;
|
||||
} else {
|
||||
// Unrecognized type!
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
} elseif ($name === 'md') {
|
||||
// markdown handling. : [md]title[/md] .
|
||||
|
||||
$buffer = null;
|
||||
$i = $match_idx + 1;
|
||||
if ($i < $match_count) {
|
||||
list($search_match, $search_offset) = $matches[0][$i];
|
||||
$search_tag = self::decode_tag($search_match);
|
||||
if (! $search_tag['open'] && $search_tag['name'] === 'md') {
|
||||
$buffer = substr($input, $input_ptr, $search_offset - $input_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// matched something in the middle
|
||||
if (isset($buffer)) {
|
||||
//var_dump($colorIndex);
|
||||
$output = $output . '<div class="md" >'.$buffer.'</div>';
|
||||
// emit the tag
|
||||
// advance ptr (again)
|
||||
$input_ptr = $search_offset + strlen($search_match);
|
||||
// update search position
|
||||
$match_idx = $i;
|
||||
} else {
|
||||
// Unrecognized type!
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
} elseif ($name === 'plist') {
|
||||
// Problem list handling. modes: [plist=1000,1001,1002]title[/plist].
|
||||
// Verify enclosing value first.
|
||||
$buffer = null;
|
||||
$i = $match_idx + 1;
|
||||
if ($i < $match_count) {
|
||||
list($search_match, $search_offset) = $matches[0][$i];
|
||||
$search_tag = self::decode_tag($search_match);
|
||||
if (! $search_tag['open'] && $search_tag['name'] === 'plist') {
|
||||
$buffer = substr($input, $input_ptr, $search_offset - $input_ptr);
|
||||
}
|
||||
}
|
||||
// matched something in the middle
|
||||
if (isset($buffer)) {
|
||||
if (isset($args['default'])) {
|
||||
// $buffer is the title
|
||||
$url = $args['default'];
|
||||
} else {
|
||||
// $buffer is the url
|
||||
$url = $buffer;
|
||||
}
|
||||
if(!isset($colorIndex)) $colorIndex =0;
|
||||
$plist=html_entity_decode($url);
|
||||
$pnum= count(explode(",",html_entity_decode($url)));
|
||||
//var_dump($colorIndex);
|
||||
// emit the tag 如果希望题单显示2列,修改下面的col-lg-12为col-lg-6
|
||||
$output = $output . '<div class="col-xs-12 col-lg-12"><div class="panel '.$plist_color[$colorIndex%count($plist_color)].'">'
|
||||
.'<div class="panel-heading" onclick="$(\'#plist'.$colorIndex.'\').load(\'problemset.php?ajax=1&list='.$url.'\').toggle()" style="cursor: pointer" >'
|
||||
.'<h4 class="panel-title" ><a class="collapsed" href="problemset.php?list=' . $url . '" target="_blank">'
|
||||
. self::encode($buffer) . '</a> <span class="pull-right">'.$MSG_TOTAL.' '.$pnum.' '.$MSG_NUMBER_OF_PROBLEMS.'</span> </h4> '
|
||||
.' </div><div id="plist'.$colorIndex.'" style="display:none" > </div></div></div>';
|
||||
$colorIndex++;
|
||||
// advance ptr (again)
|
||||
$input_ptr = $search_offset + strlen($search_match);
|
||||
// update search position
|
||||
$match_idx = $i;
|
||||
} else {
|
||||
// Unrecognized type!
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
} elseif ($name === 'a') {
|
||||
// URL handling. Two modes: [a=url]title[/a] and [a]url[/a].
|
||||
// Verify enclosing value first.
|
||||
$buffer = null;
|
||||
$i = $match_idx + 1;
|
||||
if ($i < $match_count) {
|
||||
list($search_match, $search_offset) = $matches[0][$i];
|
||||
$search_tag = self::decode_tag($search_match);
|
||||
if (! $search_tag['open'] && $search_tag['name'] === 'a') {
|
||||
$buffer = substr($input, $input_ptr, $search_offset - $input_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// matched something in the middle
|
||||
if (isset($buffer)) {
|
||||
if (isset($args['default'])) {
|
||||
// $buffer is the title
|
||||
$url = $args['default'];
|
||||
} else {
|
||||
// $buffer is the url
|
||||
$url = $buffer;
|
||||
}
|
||||
// emit the tag
|
||||
$output = $output . '<a href="' . $url . '">' . self::encode($buffer) . '</a>';
|
||||
// advance ptr (again)
|
||||
$input_ptr = $search_offset + strlen($search_match);
|
||||
// update search position
|
||||
$match_idx = $i;
|
||||
} else {
|
||||
// Unrecognized type!
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
|
||||
} elseif ($name === 'img') {
|
||||
// image handling. [img (optional=args go=here)]url[/img].
|
||||
// Verify enclosing value first.
|
||||
$buffer = null;
|
||||
$i = $match_idx + 1;
|
||||
if ($i < $match_count) {
|
||||
list($search_match, $search_offset) = $matches[0][$i];
|
||||
$search_tag = self::decode_tag($search_match);
|
||||
if (! $search_tag['open'] && $search_tag['name'] === 'img') {
|
||||
$buffer = substr($input, $input_ptr, $search_offset - $input_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// matched something in the middle
|
||||
if (isset($buffer)) {
|
||||
// Image size adjustment - accepts width and height
|
||||
$img_param = [];
|
||||
|
||||
if (isset ($args['width'])) {
|
||||
//TODO: size validation
|
||||
$img_param['width'] = $args['width'];
|
||||
}
|
||||
if (isset ($args['height'])) {
|
||||
//TODO: size validation
|
||||
$img_param['height'] = $args['height'];
|
||||
}
|
||||
//TODO: handle bad settings
|
||||
|
||||
// emit the tag
|
||||
$output = $output . '<img src="' . $buffer . '"';
|
||||
foreach ($img_param as $name=>$value) {
|
||||
$output = $output . ' ' . $name . '="' . $value . '"';
|
||||
}
|
||||
$output .= '>';
|
||||
|
||||
// advance ptr (again)
|
||||
$input_ptr = $search_offset + strlen($search_match);
|
||||
// update search position
|
||||
$match_idx = $i;
|
||||
} else {
|
||||
// Unrecognized type!
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
|
||||
// ADD CUSTOM TAGS HERE
|
||||
|
||||
} else {
|
||||
// Unrecognized type!
|
||||
$output .= self::encode($match);
|
||||
}
|
||||
}
|
||||
}
|
||||
// pick up any stray chars and HTML-encode them
|
||||
$output .= self::encode(substr($input, $input_ptr));
|
||||
// Close any remaining stray tags left on the stack
|
||||
while ($stack)
|
||||
{
|
||||
$tag = array_pop($stack);
|
||||
$output = $output . '</' . $tag . '>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
function filterDIV($input){
|
||||
$count1=substr_count($input,"<div");
|
||||
$count2=substr_count($input,"</div>");
|
||||
// echo $count1."-".$count2."=".($count1-$count2)."<br>";
|
||||
if($count1!=$count2){
|
||||
$value=mb_ereg_replace("<[dD][iI][vV][a-zA-Z -_=\"\']*>","",$input);
|
||||
$value=mb_ereg_replace("</[dD][iI][vV]>","",$value);
|
||||
$value=mb_ereg_replace("<([^>]+)<","<\\1<",$value); //fixing 0<m<7000
|
||||
$value=mb_ereg_replace(">([^<]+)>",">\\1>",$value); //fixing 7000>m>7000
|
||||
}else{
|
||||
$value=$input;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
// procedural
|
||||
function bbcode_to_html($input) : string
|
||||
{
|
||||
global $OJ_DIV_FILTER;
|
||||
if(isset($OJ_DIV_FILTER)&&$OJ_DIV_FILTER) $input=filterDIV($input);
|
||||
return BBCode::bbcode_to_html($input);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
//cache foot start
|
||||
if(isset($file)){
|
||||
if($OJ_MEMCACHE){
|
||||
$mem->set($file,ob_get_contents(),0,$cache_time);
|
||||
}else{
|
||||
// if(!file_exists("cache")) mkdir("cache");
|
||||
// file_put_contents($file,ob_get_contents());
|
||||
}
|
||||
}
|
||||
//cache foot stop
|
||||
?>
|
||||
<!--not cached-->
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/db_info.inc.php");
|
||||
//cache head start
|
||||
if(!isset($cache_time)) $cache_time=10;
|
||||
$sid=$OJ_NAME.$_SERVER["HTTP_HOST"];
|
||||
$OJ_CACHE_SHARE=(isset($OJ_CACHE_SHARE)&&$OJ_CACHE_SHARE)&&!isset($_SESSION[$OJ_NAME.'_'.'administrator']);
|
||||
if (!$OJ_CACHE_SHARE&&isset($_SESSION[$OJ_NAME.'_'.'user_id'])){
|
||||
$ip = ($_SERVER['REMOTE_ADDR']);
|
||||
if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
|
||||
$REMOTE_ADDR = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$tmp_ip=explode(',',$REMOTE_ADDR);
|
||||
$ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
|
||||
}
|
||||
$sid.=session_id().$ip;
|
||||
}
|
||||
if (isset($_SERVER["REQUEST_URI"])){
|
||||
$sid.=$_SERVER["REQUEST_URI"];
|
||||
}
|
||||
|
||||
$sid=md5($sid);
|
||||
$file = "cache/cache_$sid.html";
|
||||
|
||||
if($OJ_MEMCACHE ){
|
||||
$mem = new Memcache;
|
||||
if($OJ_SAE)
|
||||
$mem=memcache_init();
|
||||
else{
|
||||
$mem->connect($OJ_MEMSERVER, $OJ_MEMPORT);
|
||||
}
|
||||
$content=$mem->get($file);
|
||||
if($content){
|
||||
echo $content;
|
||||
exit();
|
||||
}else{
|
||||
$use_cache=false;
|
||||
$write_cache=true;
|
||||
}
|
||||
}else{
|
||||
|
||||
if (file_exists ( $file ))
|
||||
$last = filemtime ( $file );
|
||||
else
|
||||
$last =0;
|
||||
$use_cache=(time () - $last < $cache_time);
|
||||
|
||||
}
|
||||
if ($use_cache) {
|
||||
//header ( "Location: $file" );
|
||||
include ($file);
|
||||
exit ();
|
||||
} else {
|
||||
ob_start ();
|
||||
}
|
||||
//cache head stop
|
||||
?>
|
||||
@@ -0,0 +1,159 @@
|
||||
function ceinfo(){
|
||||
var i=0;
|
||||
var pats=new Array();
|
||||
var exps=new Array();
|
||||
pats[0]=/System\.out\.print.*%.*/;
|
||||
exps[0]="Java中System.out.print用法跟C语言printf不同,请试用System.out.format";
|
||||
pats[1]=/.*没有那个文件或目录.*/;
|
||||
exps[1]="服务器为Linux系统,不能使用windows下特有的非标准头文件。";
|
||||
pats[2]=/not a statement/;
|
||||
exps[2]="检查大括号{}匹配情况,eclipse整理代码快捷键Ctrl+Shift+F";
|
||||
pats[3]=/class, interface, or enum expected/;
|
||||
exps[3]="请不要将java函数(方法)放置在类声明外部,注意大括号的结束位置}";
|
||||
pats[4]=/asm.*java/;
|
||||
exps[4]="请不要将java程序提交为C语言";
|
||||
pats[5]=/package .* does not exist/;
|
||||
exps[5]="检测拼写,如:系统对象System为大写S开头";
|
||||
pats[6]=/possible loss of precision/;
|
||||
exps[6]="赋值将会失去精度,检测数据类型,如确定无误可以使用强制类型转换";
|
||||
pats[7]=/incompatible types/;
|
||||
exps[7]="Java中不同类型的数据不能互相赋值,整数不能用作布尔值";
|
||||
pats[8]=/illegal start of expression/;
|
||||
exps[8]="字符串应用英文双引号(\")引起";
|
||||
pats[9]=/cannot find symbol/;
|
||||
exps[9]="拼写错误或者缺少调用函数所需的对象如println()需对System.out调用";
|
||||
pats[10]=/';' expected/;
|
||||
exps[10]="缺少分号。";
|
||||
pats[11]=/should be declared in a file named/;
|
||||
exps[11]="Java必须使用public class Main。";
|
||||
pats[12]=/expected ‘.*’ at end of input/;
|
||||
exps[12]="代码没有结束,缺少匹配的括号或分号,检查复制时是否选中了全部代码。";
|
||||
pats[13]=/invalid conversion from ‘.*’ to ‘.*’/;
|
||||
exps[13]="隐含的类型转换无效,尝试用显示的强制类型转换如(int *)malloc(....)";
|
||||
pats[14]=/warning.*declaration of 'main' with no type/;
|
||||
exps[14]="C++标准中,main函数必须有返回值";
|
||||
pats[15]=/'.*' was not declared in this scope/;
|
||||
exps[15]="变量没有声明过,检查下是否拼写错误!";
|
||||
pats[16]=/main’ must return ‘int’/;
|
||||
exps[16]="在标准C语言中,main函数返回值类型必须是int,教材和VC中使用void是非标准的用法";
|
||||
pats[17]=/printf.*was not declared in this scope/;
|
||||
exps[17]="printf函数没有声明过就进行调用,检查下是否导入了stdio.h或cstdio头文件";
|
||||
pats[18]=/warning: ignoring return value of/;
|
||||
exps[18]="警告:忽略了函数的返回值,可能是函数用错或者没有考虑到返回值异常的情况";
|
||||
pats[19]=/:.*__int64’ undeclared/;
|
||||
exps[19]="__int64没有声明,在标准C/C++中不支持微软VC中的__int64,请使用long long来声明64位变量";
|
||||
pats[20]=/:.*expected ‘;’ before/;
|
||||
exps[20]="前一行缺少分号";
|
||||
pats[21]=/ .* undeclared \(first use in this function\)/;
|
||||
exps[21]="变量使用前必须先进行声明,也有可能是拼写错误,注意大小写区分。";
|
||||
pats[22]=/scanf.*was not declared in this scope/;
|
||||
exps[22]="scanf函数没有声明过就进行调用,检查下是否导入了stdio.h或cstdio头文件";
|
||||
pats[23]=/memset.*was not declared in this scope/;
|
||||
exps[23]="memset函数没有声明过就进行调用,检查下是否导入了stdlib.h或cstdlib头文件";
|
||||
pats[24]=/malloc.*was not declared in this scope/;
|
||||
exps[24]="malloc函数没有声明过就进行调用,检查下是否导入了stdlib.h或cstdlib头文件";
|
||||
pats[25]=/puts.*was not declared in this scope/;
|
||||
exps[25]="puts函数没有声明过就进行调用,检查下是否导入了stdio.h或cstdio头文件";
|
||||
pats[26]=/gets.*was not declared in this scope/;
|
||||
exps[26]="gets函数没有声明过就进行调用,检查下是否导入了stdio.h或cstdio头文件";
|
||||
pats[27]=/str.*was not declared in this scope/;
|
||||
exps[27]="string类函数没有声明过就进行调用,检查下是否导入了string.h或cstring头文件";
|
||||
pats[28]=/‘import’ does not name a type/;
|
||||
exps[28]="不要将Java语言程序提交为C/C++,提交前注意选择语言类型。";
|
||||
pats[29]=/asm’ undeclared/;
|
||||
exps[29]="不允许在C/C++中嵌入汇编语言代码。";
|
||||
pats[30]=/redefinition of/;
|
||||
exps[30]="函数或变量重复定义,看看是否多次粘贴代码。";
|
||||
pats[31]=/expected declaration or statement at end of input/;
|
||||
exps[31]="程序好像没写完,看看是否复制粘贴时漏掉代码。";
|
||||
pats[32]=/warning: unused variable/;
|
||||
exps[32]="警告:变量声明后没有使用,检查下是否拼写错误,误用了名称相似的变量。";
|
||||
pats[33]=/implicit declaration of function/;
|
||||
exps[33]="函数隐性声明,检查下是否导入了正确的头文件。或者缺少了题目要求的指定名称的函数。";
|
||||
pats[34]=/too .* arguments to function/;
|
||||
exps[34]="函数调用时提供的参数数量不对,检查下是否用错参数。";
|
||||
pats[35]=/expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’/;
|
||||
exps[35]="不要将C++语言程序提交为C,提交前注意选择语言类型。";
|
||||
pats[36]=/stray ‘\\[0123456789]*’ in program/;
|
||||
exps[36]="中文空格、标点等不能出现在程序中注释和字符串以外的部分。编写程序时请关闭中文输入法。请不要使用网上复制来的代码。";
|
||||
pats[37]=/division by zero/;
|
||||
exps[37]="除以零将导致浮点溢出。";
|
||||
pats[38]=/cannot be used as a function/;
|
||||
exps[38]="变量不能当成函数用,检查变量名和函数名重复的情况,也可能是拼写错误。";
|
||||
pats[39]=/format .* expects type .* but argument .* has type .*/;
|
||||
exps[39]="scanf/printf的格式描述和后面的参数表不一致,检查是否多了或少了取址符“&”,也可能是拼写错误。";
|
||||
pats[40]=/类.*是公共的,应在名为 .*java 的文件中声明/;
|
||||
exps[40]="Java语言提交只能有一个public类,并且类名必须是Main,其他类请不要用public关键词";
|
||||
pats[41]=/expected ‘\)’ before ‘.*’ token/;
|
||||
exps[41]="缺少右括号";
|
||||
pats[42]=/找不到符号/;
|
||||
exps[42]="使用了未定义的函数或变量,检出拼写是否有误,不要使用不存在的函数,Java调用方法通常需要给出对象名称如list1.add(...)。Java方法调用时对参数类型敏感,如:不能将整数(int)传送给接受字符串对象(String)的方法";
|
||||
pats[43]=/需要为 class、interface 或 enum/;
|
||||
exps[43]="缺少关键字,应当声明为class、interface 或 enum";
|
||||
pats[44]=/符号: 类 .*List/;
|
||||
exps[44]="使用教材上的例子,必须将相关类的代码一并提交,同时去掉其中的public关键词";
|
||||
pats[45]=/方法声明无效;需要返回类型/;
|
||||
exps[45]="只有跟类名相同的方法为构造方法,不写返回值类型。如果将类名修改为Main,请同时修改构造方法名称。";
|
||||
pats[46]=/expected.*before.*&.*token/;
|
||||
exps[46]="不要将C++语言程序提交为C,提交前注意选择语言类型。";
|
||||
pats[47]=/非法的表达式开始/;
|
||||
exps[47]="请注意函数、方法的声明前后顺序,不能在一个方法内出现另一个方法的声明。";
|
||||
pats[48]=/需要 ';'/;
|
||||
exps[48]="上面标注的这一行,最后缺少分号。";
|
||||
pats[49]=/extra tokens at end of #include directive/;
|
||||
exps[49]="include语句必须独立一行,不能与后面的语句放在同一行";
|
||||
pats[50]=/int.*hasNext/;
|
||||
exps[50]="hasNext() 应该改为nextInt()";
|
||||
pats[51]=/unterminated comment/;
|
||||
exps[51]="注释没有结束,请检查“/*”对应的结束符“*/”是否正确";
|
||||
pats[52]=/expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token/;
|
||||
exps[52]="函数声明缺少小括号(),如int main()写成了int main";
|
||||
pats[53]=/进行语法解析时已到达文件结尾/;
|
||||
exps[53]="检查提交的源码是否没有复制完整,或者缺少了结束的大括号";
|
||||
pats[54]=/subscripted value is neither array nor pointer/;
|
||||
exps[54]="不能对非数组或指针的变量进行下标访问";
|
||||
pats[55]=/expected expression before ‘%’ token/;
|
||||
exps[55]="scanf的格式部分需要用双引号引起";
|
||||
pats[56]=/ expected expression before ‘.*’ token/;
|
||||
exps[56]="参数或表达式没写完";
|
||||
pats[57]=/expected but/;
|
||||
exps[57]="错误的标点或符号";
|
||||
pats[58]=/redefinition of ‘main’/;
|
||||
exps[58]="这道题目可能是附加代码题,请重新审题,看清题意,不要提交系统已经定义的main函数,而应提交指定格式的某个函数。";
|
||||
pats[59]=/iostream: No such file or directory/;
|
||||
exps[59]="请不要将C++程序提交为C";
|
||||
pats[60]=/expected unqualified-id before ‘\[’ token/;
|
||||
exps[60]="留意数组声明后是否少了分号";
|
||||
pats[61]=/解析时已到达文件结尾/;
|
||||
exps[61]="程序末尾缺少大括号";
|
||||
pats[62]=/非法字符/;
|
||||
exps[62]="检查是否使用了中文标点或空格";
|
||||
pats[63]=/variably modified/;
|
||||
exps[63]="数组大小不能用变量,C 语言中不能使用变量作为全局数组的维度大小,包括 const 变量";
|
||||
pats[64]=/was not declared in this scope/;
|
||||
exps[64]="调用了没有声明的函数,看看是不是拼写错误,或者忘记include正确的头文件";
|
||||
pats[65]=/#include expects "FILENAME"/;
|
||||
exps[65]="include语句需要给出文件名,从百度结果中复制来的代码很可能缺少正确的文件名,因为<>被识别为HTML标记";
|
||||
pats[66]=/找不到符号/;
|
||||
exps[66]="使用的类名似乎没有定义过,检查下是否拼写错误或者忘记了引入正确的包名,比如java.util.*";
|
||||
pats[67]=/错误: 需要';'/;
|
||||
exps[67]="每行语句的末尾都需要分号,并且是英文的分号,请再次确认;";
|
||||
|
||||
//alert("asdf");
|
||||
var errmsg=$("#errtxt").text();
|
||||
var expmsg="辅助解释:";
|
||||
let keyword=$("#errtxt").find(".number1").text();
|
||||
//console.log(keyword);
|
||||
keyword=encodeURIComponent(keyword);
|
||||
//console.log(keyword);
|
||||
expmsg+="<br><a target='_blank' href='https://www.baidu.com/s?wd="+keyword+"'>问问度娘</a><hr>\n";
|
||||
for(var i=0;i<pats.length;i++){
|
||||
var pat=pats[i];
|
||||
var exp=exps[i];
|
||||
var ret=pat.exec(errmsg);
|
||||
if(ret){
|
||||
expmsg+=ret+":"+exp+"<hr>\n";
|
||||
}
|
||||
}
|
||||
$("#errexp").html(expmsg);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
if ($_SESSION[$OJ_NAME.'_'.'getkey']!=$_GET['getkey']){
|
||||
?>
|
||||
<script language=javascript>
|
||||
history.go(-1);
|
||||
</script>
|
||||
<?php
|
||||
exit(1);
|
||||
}
|
||||
else{
|
||||
unset($_SESSION[$OJ_NAME.'_'.'getkey']);
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
if (!isset($_SESSION[$OJ_NAME.'_'.'postkey'])||!isset($_POST['postkey'])||$_SESSION[$OJ_NAME.'_'.'postkey']!=$_POST['postkey'])
|
||||
exit(1);
|
||||
?>
|
||||
@@ -0,0 +1,46 @@
|
||||
function checkIsChinese(str){
|
||||
//如果值为空,通过校验
|
||||
if (str == "")
|
||||
return false;
|
||||
var pattern = /([\u4E00-\u9FA5]|[\uFE30-\uFFA0])+/gi;
|
||||
if (pattern.test(str))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function checksource(src){
|
||||
if (document.getElementById("language").value>"3")
|
||||
return true;
|
||||
var keys=new Array();
|
||||
var errs=new Array();
|
||||
var msg="";
|
||||
keys[0]="void main";
|
||||
errs[0]="main函数返回值不能为void,否则会编译出错,请使用int main(),并在最后return 0。\n虽然VC等windows下的编译器支持,C/C++标准中不允许使用void main()!!!";
|
||||
if (document.getElementById("language").value=="3"){
|
||||
keys[0]="int main";
|
||||
errs[0]="java要求有public static void main函数";
|
||||
}
|
||||
keys[1]="Please";
|
||||
errs[1]="除非题目要求,否则不要使用类似‘Please input’这样的提示";
|
||||
keys[2]="请";
|
||||
errs[2]="除非题目要求,否则不要使用类似‘请输入’这样的提示";
|
||||
keys[3]="输入";
|
||||
errs[3]="除非题目要求,否则不要使用类似‘请输入’这样的提示";
|
||||
keys[3]="input";
|
||||
errs[3]="除非题目要求,否则不要使用类似‘Please input’这样的提示";
|
||||
keys[4]="max=%d";
|
||||
errs[4]="除非题目要求,否则不要使用类似‘max=’这样的提示";
|
||||
keys[5]="mian";
|
||||
errs[5]="是不是把main打成mian了?";
|
||||
for(var i=0;i<keys.length;i++){
|
||||
if(src.indexOf(keys[i])!=-1){
|
||||
msg+=errs[i]+"\n";
|
||||
}
|
||||
}
|
||||
if(checkIsChinese(src))
|
||||
msg+="程序中有中文字符!注意,一般来说本系统中的题目都不会要求输出提示,特别是中文提示。\n请先使用SampleInput做输入,对比输出和SampleOutput,有任何多余的输出(包括提示、多出的逗号、等号空格等等)都会被判错误!\n如有任何程序内容出现中文的括号、分号、引号、空格都会编译出错。";
|
||||
if(msg.length>0)
|
||||
return confirm(msg+"\n 代码可能有错误,确定要提交么?\n建议先使用题目的SampleInput做测试,看看你的程序输出是否与SampleOutput完全一致。\n多个空格,标点都会被认为是错误答案(WrongAnswer)。\n如果出现编译错误(CompileError),请点击CompileError字样,查看具体编译报错,以便纠正。");
|
||||
else
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php if(file_exists("include/db_info.inc.php")){
|
||||
require_once("include/db_info.inc.php");
|
||||
if(isset($OJ_LANG)){
|
||||
require_once("./lang/$OJ_LANG.php");
|
||||
}
|
||||
}
|
||||
//新华社:新闻媒体和网站应当禁用的38个不文明用语
|
||||
$bad_words=Array("装逼","草泥马","特么的","撕逼","玛拉戈壁","爆菊","JB","呆逼","本屌","齐B短裙","法克鱿","丢你老母","达菲鸡","装13","逼格","蛋疼","傻逼","绿茶婊","你妈的","表砸","屌爆了","买了个婊","已撸","吉跋猫","妈蛋","逗比","我靠","碧莲","碧池","然并卵","日了狗","屁民","吃翔","XX狗","淫家","你妹","浮尸国","滚粗");
|
||||
$judge_result=Array($MSG_Pending,$MSG_Pending_Rejudging,$MSG_Compiling,$MSG_Running_Judging,$MSG_Accepted,$MSG_Presentation_Error,$MSG_Wrong_Answer,$MSG_Time_Limit_Exceed,$MSG_Memory_Limit_Exceed,$MSG_Output_Limit_Exceed,$MSG_Runtime_Error,$MSG_Compile_Error,$MSG_Compile_OK,$MSG_TEST_RUN,$MSG_MANUAL_CONFIRMATION,$MSG_SUBMITTING,$MSG_REMOTE_PENDING,$MSG_REMOTE_JUDGING);
|
||||
$jresult=Array($MSG_PD,$MSG_PR,$MSG_CI,$MSG_RJ,$MSG_AC,$MSG_PE,$MSG_WA,$MSG_TLE,$MSG_MLE,$MSG_OLE,$MSG_RE,$MSG_CE,$MSG_CO,$MSG_TR,$MSG_MC,$MSG_SUBMITTING,$MSG_RP,$MSG_RJ);
|
||||
$judge_color = Array("label gray","label label-info","label label-warning","label label-warning","label label-success","label label-danger","label label-danger","label label-warning","label label-warning","label label-warning","label label-warning","label label-warning","label label-warning","label label-info","label label-success","label lable-gray","label label-info","label label-warning");
|
||||
$language_name=Array("C","C++","Pascal","Java","Ruby","Bash","Python","PHP","Perl","C#","Obj-C","FreeBasic","Scheme","Clang","Clang++","Lua","JavaScript","Go","SQL","Fortran","Matlab","Cobol","R","Scratch3","UnknownLanguage");
|
||||
$language_ext=Array( "c", "cc", "pas", "java", "rb", "sh", "py", "php","pl", "cs","m","bas","scm","c","cc","lua","js","go","sql","f95","m","cob","R","sb3" );
|
||||
$PID=Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK","AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU","AV","AW","AX","AY","AZ","BA","BB","BC","BD","BE","BF","BG","BH","BI","BJ","BK","BL","BM","BN","BO","BP","BQ","BR","BS","BT","BU","BV","BW","BX","BY","BZ","CA","CB","CC","CD","CE","CF","CG","CH","CI","CJ","CK","CL","CM","CN","CO","CP","CQ","CR","CS","CT","CU","CV","CW","CX","CY","CZ","DA","DB","DC","DD","DE","DF","DG","DH","DI","DJ","DK","DL","DM","DN","DO","DP","DQ","DR","DS","DT","DU","DV","DW","DX","DY","DZ","EA","EB","EC","ED","EE","EF","EG","EH","EI","EJ","EK","EL","EM","EN","EO","EP","EQ","ER","ES","ET","EU","EV","EW","EX","EY","EZ","FA","FB","FC","FD","FE","FF","FG","FH","FI","FJ","FK","FL","FM","FN","FO","FP","FQ","FR","FS","FT","FU","FV","FW","FX","FY","FZ","GA","GB","GC","GD","GE","GF","GG","GH","GI","GJ","GK","GL","GM","GN","GO","GP","GQ","GR","GS","GT","GU","GV","GW","GX","GY","GZ","HA","HB","HC","HD","HE","HF","HG","HH","HI","HJ","HK","HL","HM","HN","HO","HP","HQ","HR","HS","HT","HU","HV","HW","HX","HY","HZ","IA","IB","IC","ID","IE","IF","IG","IH","II","IJ","IK","IL","IM","IN","IO","IP","IQ","IR","IS","IT","IU","IV","IW","IX","IY","IZ","JA","JB","JC","JD","JE","JF","JG","JH","JI","JJ","JK","JL","JM","JN","JO","JP","JQ","JR","JS","JT","JU","JV","JW","JX","JY","JZ","KA","KB","KC","KD","KE","KF","KG","KH","KI","KJ","KK","KL","KM","KN","KO","KP","KQ","KR","KS","KT","KU","KV","KW","KX","KY","KZ","LA","LB","LC","LD","LE","LF","LG","LH","LI","LJ","LK","LL","LM","LN","LO","LP","LQ","LR","LS","LT","LU","LV","LW","LX","LY","LZ","MA","MB","MC","MD","ME","MF","MG","MH","MI","MJ","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NB","NC","ND","NE","NF","NG","NH","NI","NJ","NK","NL","NM","NN","NO","NP","NQ","NR","NS","NT","NU","NV","NW","NX","NY","NZ","OA","OB","OC","OD","OE","OF","OG","OH","OI","OJ","OK","OL","OM","ON","OO","OP","OQ","OR","OS","OT","OU","OV","OW","OX","OY","OZ","PA","PB","PC","PD","PE","PF","PG","PH","PI","PJ","PK","PL","PM","PN","PO","PP","PQ","PR","PS","PT","PU","PV","PW","PX","PY","PZ","QA","QB","QC","QD","QE","QF","QG","QH","QI","QJ","QK","QL","QM","QN","QO","QP","QQ","QR","QS","QT","QU","QV","QW","QX","QY","QZ","RA","RB","RC","RD","RE","RF","RG","RH","RI","RJ","RK","RL","RM","RN","RO","RP","RQ","RR","RS","RT","RU","RV","RW","RX","RY","RZ","SA","SB","SC","SD","SE","SF","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SP","SQ","SR","SS","ST","SU","SV","SW","SX","SY","SZ","TA","TB","TC","TD","TE","TF","TG","TH","TI","TJ","TK","TL","TM","TN","TO","TP","TQ","TR","TS","TT","TU","TV","TW","TX","TY","TZ","UA","UB","UC","UD","UE","UF","UG","UH","UI","UJ","UK","UL","UM","UN","UO","UP","UQ","UR","US","UT","UU","UV","UW","UX","UY","UZ","VA","VB","VC","VD","VE","VF","VG","VH","VI","VJ","VK","VL","VM","VN","VO","VP","VQ","VR","VS","VT","VU","VV","VW","VX","VY","VZ","WA","WB","WC","WD","WE","WF","WG","WH","WI","WJ","WK","WL","WM","WN","WO","WP","WQ","WR","WS","WT","WU","WV","WW","WX","WY","WZ","XA","XB","XC","XD","XE","XF","XG","XH","XI","XJ","XK","XL","XM","XN","XO","XP","XQ","XR","XS","XT","XU","XV","XW","XX","XY","XZ","YA","YB","YC","YD","YE","YF","YG","YH","YI","YJ","YK","YL","YM","YN","YO","YP","YQ","YR","YS","YT","YU","YV","YW","YX","YY","YZ","ZA","ZB","ZC","ZD","ZE","ZF","ZG","ZH","ZI","ZJ","ZK","ZL","ZM","ZN","ZO","ZP","ZQ","ZR","ZS","ZT","ZU","ZV","ZW","ZX","ZY","ZZ");
|
||||
$ball_color=Array('#66cccc','red','green','pink','yellow','violet','magenta','maroon','olive','chocolate');
|
||||
$ball_name=Array('蒂芙妮蓝','红','green','pink','yellow','violet','magenta','maroon','olive','chocolate');
|
||||
$color_theme=Array("default","primary","success","info","warning","danger");
|
||||
?>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
if(isset($OJ_NO_CONTEST_WATCHER)&&$OJ_NO_CONTEST_WATCHER) require_once("contest-check.php");
|
||||
if($OJ_MEMCACHE){
|
||||
$sql="SELECT
|
||||
user_id,nick,solution.result,solution.num,solution.in_date,solution.pass_rate
|
||||
FROM
|
||||
solution where solution.contest_id='$cid' and num>=0 and problem_id>0
|
||||
ORDER BY user_id,solution_id";
|
||||
$result = mysql_query_cache($sql);
|
||||
if($result) $rows_cnt=count($result);
|
||||
else $rows_cnt=0;
|
||||
}else{
|
||||
$sql="SELECT
|
||||
user_id,nick,solution.result,solution.num,solution.in_date,solution.pass_rate
|
||||
FROM
|
||||
solution where solution.contest_id=? and num>=0 and problem_id>0
|
||||
ORDER BY user_id,solution_id";
|
||||
$result = pdo_query($sql,$cid);
|
||||
if($result) $rows_cnt=count($result);
|
||||
else $rows_cnt=0;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
@session_start();
|
||||
if( $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
if( !isset($_SESSION[$OJ_NAME.'_'.'csrf_keys'])
|
||||
|| !is_array($_SESSION[$OJ_NAME.'_'.'csrf_keys'])
|
||||
|| !isset($_POST['csrf'])
|
||||
|| !in_array($_POST['csrf'], $_SESSION[$OJ_NAME.'_'.'csrf_keys'])
|
||||
){
|
||||
http_response_code(403);
|
||||
echo "Invalid csrf token";
|
||||
exit;
|
||||
} else {
|
||||
$index = array_search($_POST['csrf'],$_SESSION[$OJ_NAME.'_'.'csrf_keys']);
|
||||
array_splice($_SESSION[$OJ_NAME.'_'.'csrf_keys'], $index, 1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
if (!function_exists('str_contains')) {
|
||||
function str_contains (string $haystack, string $needle)
|
||||
{
|
||||
return empty($needle) || strpos($haystack, $needle) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
function getPartByMark($html,$mark1,$mark2){
|
||||
$i=strpos($html,$mark1);
|
||||
if($i===false) return $html;
|
||||
$start=$i+strlen($mark1)+1;
|
||||
if($i>=0&&$start<=strlen($html)) $j=strpos($html,$mark2,$start);
|
||||
else return $html;
|
||||
$descriptionHTML=substr($html,$i+ strlen($mark1),$j-($i+ strlen($mark1)));
|
||||
return $descriptionHTML;
|
||||
}
|
||||
|
||||
function getPartByMarkMB($html,$mark1,$mark2){
|
||||
$i=mb_strpos($html,$mark1);
|
||||
$start=$i+mb_strlen($mark1)+1;
|
||||
if($i>=0&&$start<=mb_strlen($html)) $j=mb_strpos($html,$mark2,$start);
|
||||
else return $html;
|
||||
$descriptionHTML=mb_substr($html,$i+ mb_strlen($mark1),$j-($i+ mb_strlen($mark1)));
|
||||
return $descriptionHTML;
|
||||
}
|
||||
function get_domain($url){
|
||||
$pieces = parse_url($url);
|
||||
$domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
|
||||
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
|
||||
return $regs['domain'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function curl_get($url){
|
||||
global $curl,$OJ_DATA,$remote_cookie;
|
||||
if(function_exists('curl_init')){
|
||||
$curl = curl_init($url);
|
||||
//curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=buiebpv91e0cdhpmm6a320j1l7; path=/');
|
||||
//curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($curl, CURLOPT_COOKIEFILE, $remote_cookie); // use saved cookies
|
||||
curl_setopt($curl, CURLOPT_COOKIEJAR, $remote_cookie); // save coockies
|
||||
curl_setopt($curl, CURLOPT_REFERER, "$url");
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||
$data = curl_exec($curl);
|
||||
return $data;
|
||||
}else{
|
||||
echo "PHP-curl missing (apt-get install php-curl)";
|
||||
return "PHP-curl missing (apt-get install php-curl)";
|
||||
}
|
||||
}
|
||||
|
||||
function curl_post_urlencoded($url,$form){
|
||||
global $curl,$OJ_DATA,$remote_cookie;
|
||||
$curl = curl_init($url);
|
||||
//curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=buiebpv91e0cdhpmm6a320j1l7; path=/');
|
||||
//// 设置header
|
||||
// curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($curl, CURLOPT_COOKIEFILE, $remote_cookie); // use saved cookies
|
||||
curl_setopt($curl, CURLOPT_COOKIEJAR, $remote_cookie); // save coockies
|
||||
curl_setopt($curl, CURLOPT_REFERER, "$url");
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 不要打印内容
|
||||
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||
// 设置 post 方式提交
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
// 设置 post 数据
|
||||
$data="";
|
||||
foreach($form as $key => $value){
|
||||
$data.="$key=".urlencode($value)."&";
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$data = curl_exec($curl);
|
||||
|
||||
return $data;
|
||||
}
|
||||
function curl_post($url,$form){
|
||||
global $curl,$OJ_DATA,$remote_cookie;
|
||||
$curl = curl_init($url);
|
||||
//curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=buiebpv91e0cdhpmm6a320j1l7; path=/');
|
||||
//// 设置header
|
||||
//curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($curl, CURLOPT_COOKIEFILE, $remote_cookie); // use saved cookies
|
||||
curl_setopt($curl, CURLOPT_COOKIEJAR, $remote_cookie); // save coockies
|
||||
curl_setopt($curl, CURLOPT_REFERER, "http://poj.org/");
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:'));
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 不要打印内容
|
||||
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||
// 设置 post 方式提交
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
// 设置 post 数据
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $form);
|
||||
$data = curl_exec($curl);
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
@import url(../../bootstrap/css/bootstrap.css);
|
||||
a {
|
||||
color: #00ff00;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
color: orange;
|
||||
text-decoration: underline;
|
||||
}
|
||||
h2 {
|
||||
color: 00ff00;
|
||||
}
|
||||
.toprow {
|
||||
background-color: #1A5CC8;
|
||||
color: #FFFFFF;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.toprow a {
|
||||
color: #FFFFFF;
|
||||
font-family: Arial;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 15px;
|
||||
}
|
||||
.toprow a:hover {
|
||||
color: orange;
|
||||
font-family: Arial;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 15px;
|
||||
}
|
||||
.oddrow {
|
||||
background-color: 999999;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.evenrow {
|
||||
background-color: 777777;
|
||||
white-space: nowrap;
|
||||
}
|
||||
body {
|
||||
background-color: #000000;
|
||||
//background-image: url("../image/background.jpg");
|
||||
color: #00ff00;
|
||||
}
|
||||
.hd {
|
||||
color: #FFFFFF;
|
||||
font-weight: bold;
|
||||
}
|
||||
.time {
|
||||
text-align: right;
|
||||
}
|
||||
.ip {
|
||||
padding-right: 5px;
|
||||
text-align: right;
|
||||
}
|
||||
tr.userinfo {
|
||||
background-color: #444440;
|
||||
font-size: 16px;
|
||||
}
|
||||
span.yes {
|
||||
color: green;
|
||||
font-weight: bolder;
|
||||
}
|
||||
span.no {
|
||||
color: red;
|
||||
font-weight: bolder;
|
||||
}
|
||||
.green {
|
||||
color: green;
|
||||
}
|
||||
.red {
|
||||
color: red;
|
||||
}
|
||||
.blue {
|
||||
color: blue;
|
||||
}
|
||||
.gray {
|
||||
color: gray;
|
||||
}
|
||||
.orange {
|
||||
color: orange;
|
||||
}
|
||||
.navy {
|
||||
color: navy;
|
||||
}
|
||||
span.exadmin {
|
||||
color: gray;
|
||||
}
|
||||
#center {
|
||||
text-align: center;
|
||||
}
|
||||
div.content {
|
||||
background: none repeat scroll 0 0 #444048;
|
||||
font-family: Times New Roman;
|
||||
font-size: 14px;
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 0 20px;
|
||||
text-align: left;
|
||||
}
|
||||
.sampledata {
|
||||
background: none repeat scroll 0 0 #5D585F;
|
||||
font-family: Monospace;
|
||||
font-size: 18px;
|
||||
white-space: pre;
|
||||
}
|
||||
#head {
|
||||
height: 53px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
#menu {
|
||||
font-weight: bold;
|
||||
height: 32px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 2;
|
||||
}
|
||||
.menu_item {
|
||||
display: inline;
|
||||
}
|
||||
#profile {
|
||||
font-weight: bold;
|
||||
height: 32px;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
text-align: right;
|
||||
top: 0;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 3;
|
||||
}
|
||||
#broadcast {
|
||||
color: red;
|
||||
height: 50px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 4;
|
||||
}
|
||||
#main {
|
||||
height: auto;
|
||||
position: static;
|
||||
width: 100%;
|
||||
z-index: 6;
|
||||
}
|
||||
#foot {
|
||||
height: 133px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 7;
|
||||
}
|
||||
#logo {
|
||||
position: static;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
//ini_set("display_errors", "Off"); //set this to "On" for debugging ,especially when no reason blank shows up.
|
||||
//error_reporting(E_ALL);
|
||||
//header('X-Frame-Options:SAMEORIGIN');
|
||||
//for people using hustoj out of China , try using translator program with the comments
|
||||
// 本文件是系统配置文件,全局包含,修改时请慎重保存,千万不要少分号,少引号,出现语法错误可导致全站无法打开。
|
||||
// 若遇到此种情况,可以备份后删除本文件,用/home/judge/src/install/fixing.sh脚本修复生成。
|
||||
// connect db
|
||||
static $DB_HOST="localhost"; //数据库服务器ip或域名
|
||||
static $DB_NAME="jol"; //数据库名
|
||||
static $DB_USER="debian-sys-maint"; //数据库账户
|
||||
static $DB_PASS="GJfFMuAmScKHHa32"; //数据库密码
|
||||
|
||||
static $OJ_NAME="JieerOJ"; //左上角显示的系统名称
|
||||
static $OJ_HOME="./"; //主页目录
|
||||
static $OJ_ADMIN="278370456@qq.com"; //管理员email
|
||||
static $SMTP_SERVER = "smtp.qq.com"; //SMTP服务器,通常在邮箱的smtp/pop3设置中可以查询到,推荐用企业邮箱发信,避免被识别为垃圾邮件
|
||||
static $SMTP_PORT =587; //SMTP服务器端口,通常是25,有的服务器支持80(阿里云)、465(网易)、587(QQ)以适应不同的网络防火墙配置
|
||||
static $SMTP_USER = "278370456@qq.com"; //SMTP服务器的用户名(通常就是发件人的邮箱地址), 这里修改后视为邮件配置生效,若配置不当可能导致部分页面超时。
|
||||
static $SMTP_PASS = "your_smpt_auth_password"; //由邮箱系统生成的口令 (SMTP服务器的密码)
|
||||
|
||||
static $OJ_DATA="/home/judge/data"; //测试数据目录
|
||||
static $OJ_BBS=false; //设为"discuss3" 启用, "bbs" for phpBB3 bridge or "discuss" for mini-forum or false for close any
|
||||
static $OJ_ONLINE=false; //是否记录在线情况
|
||||
static $OJ_LANG="cn"; //默认语言
|
||||
static $OJ_SIM=false; //显示相似度,注意只是显示,启动检测的开关在judge.conf,且自己抄自己不计为抄袭
|
||||
static $OJ_DICT=false; //显示在线翻译
|
||||
static $OJ_LANGMASK=4194224; //TIOBE index top 10, calculator : https://pigeon-developer.github.io/hustoj-langmask/ -524288 to get matlab(octave)
|
||||
static $OJ_ACE_EDITOR=true; // 是否启用有高亮提示的提交代码输入框
|
||||
static $OJ_AUTO_SHARE=false; //true: One can view all AC submit if he/she has ACed it once.
|
||||
static $OJ_CSS="white.css"; // bing.css kawai.css black.css blue.css green.css hznu.css
|
||||
static $OJ_SAE=false; //using sina application engine
|
||||
static $OJ_VCODE=false; //验证码
|
||||
static $OJ_REG_SPEED=60 ; //限制每小时同ip注册个数,0不限制
|
||||
static $OJ_APPENDCODE=false; // 代码预定模板
|
||||
if (!$OJ_APPENDCODE) ini_set("session.cookie_httponly", 1); // APPENDCODE模式需要允许javascript操作cookie保存当前语言。
|
||||
@session_start();
|
||||
static $OJ_CE_PENALTY=false; // 编译错误是否罚时
|
||||
static $OJ_PRINTER=false; //启用打印服务
|
||||
static $OJ_MAIL=false; //内邮
|
||||
static $OJ_MARK="mark"; // "mark" 显示正确得分, "percent" 显示错误比率
|
||||
static $OJ_MEMCACHE=false; //使用内存缓存
|
||||
static $OJ_MEMSERVER="127.0.0.1";
|
||||
static $OJ_MEMPORT=11211;
|
||||
static $OJ_UDP=true; //使用UDP通知
|
||||
static $OJ_UDPSERVER="127.0.0.1"; // 多个判题机可用逗号分隔,有非标端口可以用冒号 如 $OJ_UDPSERVER="192.168.0.1,192.168.0.2,192.168.0.3:1537";
|
||||
static $OJ_UDPPORT=1536;
|
||||
static $OJ_JUDGE_HUB_PATH="../judge"; // UDP 发给给JudgeHub的子路径
|
||||
static $OJ_REDIS=false; //使用REDIS队列
|
||||
static $OJ_REDISSERVER="127.0.0.1";
|
||||
static $OJ_REDISPORT=6379;
|
||||
static $OJ_REDISQNAME="hustoj";
|
||||
static $SAE_STORAGE_ROOT="http://hustoj-web.stor.sinaapp.com/"; //新浪云存储引擎
|
||||
static $OJ_CDN_URL=""; // 如果服务器带宽较小,可选用他人同版本的OJ作为静态资源来源 http://cdn.m.hustoj.com:8090/
|
||||
static $OJ_TEMPLATE="syzoj"; //使用的默认模板,template目录下的每个子目录都是一个模板, [bs3 mdui sweet syzoj sidebar bshark] work with discuss3
|
||||
static $OJ_BG="/image/background.jpg"; //双引号里面填写背景图片的url。
|
||||
// $OJ_BG="/image/bing".date('H').".jpg"; //每个整点更换壁纸,例如准备bing[00~23].jpg在image目录。
|
||||
static $OJ_LOGIN_MOD="hustoj"; //需要在include目录下配置login-xxxx.php来调用其他登录模块。
|
||||
static $OJ_REGISTER=false; //允许注册新用户
|
||||
static $OJ_REG_NEED_CONFIRM=false; //新注册用户需要审核
|
||||
static $OJ_NEED_LOGIN=true; //需要登录才能访问
|
||||
static $OJ_LONG_LOGIN=false; //启用长时间登录信息保留
|
||||
static $OJ_KEEP_TIME="30"; //登录Cookie有效时间(单位:天(day),仅在上一行为true时生效)
|
||||
static $OJ_AUTO_SHOW_OFF = false;//打开题目默认开启编辑器
|
||||
static $OJ_RANK_LOCK_PERCENT=0; //比赛封榜时间比例,例如设0.2,则5小时的比赛,最后一小时为封榜时间。
|
||||
static $OJ_RANK_LOCK_DELAY=3600; //赛后封榜持续时间,单位秒。根据实际情况调整,在闭幕式颁奖结束后设为0即可立即解封。
|
||||
static $OJ_SHOW_METAL=true; //榜单上是否按比例显示奖牌
|
||||
|
||||
static $OJ_SHOW_DIFF=true; //是否显示WA的对比说明
|
||||
static $OJ_HIDE_RIGHT_ANSWER=true; // 隐藏选择填空的正确答案
|
||||
static $OJ_DL_1ST_WA_ONLY=false; //是否只允许下载第一个WA的测试数据(前提需开启$OJ_DOWNLOAD)
|
||||
static $OJ_DOWNLOAD=false; //是否允许下载所有WA的测试数据
|
||||
static $OJ_TEST_RUN=false; //提交界面是否允许测试运行
|
||||
static $OJ_MATHJAX=true; // 激活mathjax
|
||||
static $OJ_BLOCKLY=false; //是否启用Blockly界面 , remember to execute `wget http://dl.hustoj.com/blockly.tar.gz; tar xzf blockly.tar.gz` in /home/judge/src/web
|
||||
static $OJ_ENCODE_SUBMIT=false; //是否启用base64编码提交的功能,用来回避WAF防火墙误拦截。
|
||||
static $OJ_OI_1_SOLUTION_ONLY=false; //比赛是否采用noip中的仅保留最后一次提交的规则。true则在新提交发生时,将本场比赛该题老的提交删除。
|
||||
static $OJ_OI_MODE=false; //是否开启OI比赛模式,禁用排名、状态、统计、用户信息、内邮、论坛等。
|
||||
|
||||
static $OJ_BENCHMARK_MODE=false; //此选项仅供测试用,不是正常功能,将影响代码提交,不确定请不要使用,修改提交间隔限制去设后面的OJ_SUBMIT_COOLDOWN_TIME
|
||||
static $OJ_CONTEST_RANK_FIX_HEADER=false; //比赛排名水平滚动时固定名单
|
||||
static $OJ_NOIP_KEYWORD="noip"; // 标题包含此关键词,激活noip模式,赛中不显示结果,仅保留最后一次提交。
|
||||
static $OJ_BEIAN=false; // 如果有备案号,填写备案号
|
||||
static $OJ_RANK_HIDDEN="'admin','super','szx','sen'"; // 管理员不显示在排名中
|
||||
static $OJ_FRIENDLY_LEVEL=0; //系统友好级别,暂定0-9级,级别越高越傻瓜,系统易用度高的同时将降低安全性,仅供非专业用途,造成泄题、抄袭概不负责。
|
||||
static $OJ_FREE_PRACTICE=false; //自由练习,不受比赛作业用题限制
|
||||
static $OJ_SUBMIT_COOLDOWN_TIME=1; //提交冷却时间,连续两次提交的最小间隔,单位秒。
|
||||
static $OJ_MARKDOWN=false; // 开启MARKDOWN,开启后在后台编辑题目时默认为源码模式,用[md] # Markdown [/md] 格式插入markdown代码, 如果需要用到[]也可以用<div class='md'> </div>。
|
||||
static $OJ_INDEX_NEWS_TITLE='HelloWorld!'; // 在syzoj的首页显示哪一篇标题的文章(可以有多个相同标题)
|
||||
static $OJ_DIV_FILTER=true; // 过滤题面中的div,修复显示异常,特别是来自其他OJ系统的题面。
|
||||
static $OJ_LIMIT_TO_1_IP=true; // 限制用户同一时刻只能在一个IP地址登录
|
||||
static $OJ_REMOTE_JUDGE=false; //是否启用Remote Judge ,启用哪些模块请在remote.php中设置
|
||||
static $OJ_NO_CONTEST_WATCHER=false ; //是否禁止无权限用户观战私有比赛
|
||||
static $OJ_CONTEST_TOTAL_100=false; //是否让比赛按100分计分
|
||||
static $OJ_OLD_FASHINED=false; //是否在状态页的编辑按钮、管理页的预览模式等方面保留原始版本的习惯。
|
||||
static $OJ_AI_HTML=false; // 若想开启AI链接,可设为 '<a class="desktop-only item active" target="_blank" href="http://ai.hustoj.com"><i class="help icon"></i> 问问狗蛋</a>';
|
||||
static $OJ_PUBLIC_STATUS=true; //是否公开所有人的判题结果,设为false则除source_browser外,其他人只能看到自己提交的记录。
|
||||
static $OJ_FANCY_RESULT=false; //是否在AC时显示fancy.php里的动画
|
||||
static $OJ_FANCY_MP3='http://cdn.hustoj.com/mp3.php'; // 答案正确时的音效
|
||||
|
||||
//static $OJ_EXAM_CONTEST_ID=1000; // 启用考试状态,填写考试比赛ID
|
||||
//static $OJ_ON_SITE_CONTEST_ID=1000; //启用现场赛状态,填写现场赛比赛ID
|
||||
|
||||
|
||||
|
||||
/* share code */
|
||||
static $OJ_SHARE_CODE=false; // 代码分享功能
|
||||
/* recent contest */
|
||||
static $OJ_RECENT_CONTEST=true; // "http://algcontest.rainng.com/contests.json" ; // 名校联赛
|
||||
|
||||
//$OJ_ON_SITE_TEAM_TOTAL用于根据比例的计算奖牌的队伍总数
|
||||
//0表示根据榜单上的出现的队伍总数计算,不计打星队伍
|
||||
static $OJ_ON_SITE_TEAM_TOTAL=0;
|
||||
|
||||
static $OJ_OPENID_PWD='8a367fe87b1e406ea8e94d7d508dcf01';
|
||||
|
||||
/* weibo config here */
|
||||
static $OJ_WEIBO_AUTH=false;
|
||||
static $OJ_WEIBO_AKEY='1124518951';
|
||||
static $OJ_WEIBO_ASEC='df709a1253ef8878548920718085e84b';
|
||||
static $OJ_WEIBO_CBURL='http://192.168.0.108/JudgeOnline/login_weibo.php';
|
||||
|
||||
/* renren config here */
|
||||
static $OJ_RR_AUTH=false;
|
||||
static $OJ_RR_AKEY='d066ad780742404d85d0955ac05654df';
|
||||
static $OJ_RR_ASEC='c4d2988cf5c149fabf8098f32f9b49ed';
|
||||
static $OJ_RR_CBURL='http://192.168.0.108/JudgeOnline/login_renren.php';
|
||||
/* qq config here */
|
||||
static $OJ_QQ_AUTH=false;
|
||||
static $OJ_QQ_AKEY='1124518951';
|
||||
static $OJ_QQ_ASEC='df709a1253ef8878548920718085e84b';
|
||||
static $OJ_QQ_CBURL='192.168.0.108';
|
||||
|
||||
/* log */
|
||||
static $OJ_LOG_ENABLED=false;
|
||||
static $OJ_LOG_DATETIME_FORMAT="Y-m-d H:i:s";
|
||||
static $OJ_LOG_PID_ENABLED=false;
|
||||
static $OJ_LOG_USER_ENABLED=false;
|
||||
static $OJ_LOG_URL_ENABLED=false;
|
||||
static $OJ_LOG_URL_HOST_ENABLED=false;
|
||||
static $OJ_LOG_URL_PARAM_ENABLED=false;
|
||||
static $OJ_LOG_TRACE_ENABLED=false;
|
||||
|
||||
|
||||
static $OJ_SaaS_ENABLE=false;
|
||||
static $OJ_MENU_NEWS=true;
|
||||
|
||||
require_once(dirname(__FILE__) . "/pdo.php");
|
||||
require_once(dirname(__FILE__) . "/init.php");
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require dirname(__FILE__).'/Exception.php';
|
||||
require dirname(__FILE__).'/PHPMailer.php';
|
||||
require dirname(__FILE__).'/SMTP.php';
|
||||
|
||||
function email($address,$mailtitle,$mailcontent,$html=""){
|
||||
|
||||
global $OJ_NAME,$SMTP_SERVER,$SMTP_PORT,$SMTP_USER,$SMTP_PASS;
|
||||
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
//未经配置的系统,跳过发信步骤。
|
||||
if( $SMTP_USER != "mailer@qq.com") { // 不要修改这个检测标记
|
||||
try {
|
||||
//Server settings
|
||||
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
|
||||
$mail->isSMTP(); //Send using SMTP
|
||||
$mail->Host = $SMTP_SERVER; //Set the SMTP server to send through
|
||||
$mail->SMTPAuth = true; //Enable SMTP authentication
|
||||
$mail->Username = $SMTP_USER; //SMTP username
|
||||
$mail->Password = $SMTP_PASS; //SMTP password
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
|
||||
$mail->Port = $SMTP_PORT; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
||||
|
||||
//Recipients
|
||||
$mail->setFrom($SMTP_USER, $OJ_NAME );
|
||||
$mail->addAddress($address, $OJ_NAME.' User'); //Add a recipient
|
||||
// $mail->addAddress('ellen@example.com'); //Name is optional
|
||||
// $mail->addReplyTo('info@example.com', 'Information');
|
||||
// $mail->addCC('cc@example.com');
|
||||
// $mail->addBCC('bcc@example.com');
|
||||
//Attachments
|
||||
//$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
|
||||
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
|
||||
//Content
|
||||
if($html!=""){
|
||||
$mail->Body= $html;
|
||||
$mail->isHTML(true); //Set email format to HTML
|
||||
}else{
|
||||
$mail->Body= $mailcontent;
|
||||
$mail->isHTML(false);
|
||||
}
|
||||
$mail->AltBody = $mailcontent;
|
||||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
|
||||
a{ color:#1a5cc8; text-decoration:none }
|
||||
a:hover { color:orange; text-decoration:underline }
|
||||
|
||||
h2{color:blue}
|
||||
|
||||
.toprow{
|
||||
background-color:#1a5cc8;
|
||||
color:#FFFFFF;
|
||||
font-weight:bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.toprow a{ font-family: Arial; font-weight: bold; font-size: 18px; color: #FFFFFF; margin: 15px }
|
||||
.toprow a:hover{ font-family: Arial; font-weight: bold; font-size: 18px; color:orange; margin: 15px }
|
||||
|
||||
.oddrow{background-color:#E5ECF9;white-space: nowrap;}
|
||||
.evenrow{background-color:#FFFFFF;white-space: nowrap;}
|
||||
body{
|
||||
background-color:#FFFFFF;
|
||||
background-image: url(../image/background.jpg);
|
||||
}
|
||||
.hd{
|
||||
color:#FFFFFF;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
|
||||
.time{
|
||||
text-align: right;
|
||||
}
|
||||
.ip{
|
||||
text-align: right;
|
||||
padding-right: 5px;
|
||||
}
|
||||
tr.userinfo{
|
||||
background-color:#FFFFF0;
|
||||
font-size: 16px;
|
||||
}
|
||||
span.yes,.green {
|
||||
color:green;
|
||||
font-weight: bolder;
|
||||
}
|
||||
span.no,.red{
|
||||
color:red;
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
span.exadmin{
|
||||
color:gray;
|
||||
}
|
||||
#center{
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
div.content {
|
||||
height: auto;
|
||||
background:#e4f0f8;
|
||||
margin: 0;
|
||||
padding: 0 20px;
|
||||
font-size: 14px;
|
||||
font-family: Times New Roman;
|
||||
text-align: left
|
||||
}
|
||||
.sampledata{
|
||||
white-space:pre;
|
||||
background:#8db8ff;
|
||||
font-size: 18px;
|
||||
font-family:Monospace;
|
||||
}
|
||||
|
||||
#menu{
|
||||
position:absolute;
|
||||
left:20px; top:120px;width:215px; height:54px;z-index:1; visibility:visible;
|
||||
text-align:left;
|
||||
}
|
||||
.menu_item{
|
||||
// display:inline;
|
||||
font-weight :bold;
|
||||
}
|
||||
#profile{
|
||||
position:absolute;
|
||||
left:0px; top:0px;width:100%; height:54px;z-index:2; visibility:visible;
|
||||
text-align:right;
|
||||
}
|
||||
|
||||
|
||||
#head{
|
||||
position:absolute;
|
||||
left:0px; top:40px;width:163px; height:66px;z-index:3; visibility:visible;
|
||||
font-size:10;
|
||||
color:red;
|
||||
}
|
||||
#logo{
|
||||
position:absolute;
|
||||
left:10px;
|
||||
top:-40px;
|
||||
}
|
||||
#broadcast{
|
||||
position:absolute;
|
||||
left:150px; top:20px;width:expression(documentElement.clientWidth-150); height:120px;z-index:6; visibility:visible;
|
||||
//background:#eeeeff;
|
||||
}
|
||||
|
||||
#main{
|
||||
position:absolute;
|
||||
left:150px; top:163px;width:expression(documentElement.clientWidth-150); height:600px;z-index:4; visibility:visible;
|
||||
text-align:left;
|
||||
}
|
||||
|
||||
#main div{
|
||||
text-align:center;
|
||||
}
|
||||
#submenu{
|
||||
position:absolute;
|
||||
left:0px; top:120px;width:150px; height:169px;z-index:5; visibility:visible;
|
||||
}
|
||||
|
||||
#foot{
|
||||
position:relative;
|
||||
left:0px;
|
||||
top:auto;
|
||||
width:width:expression(documentElement.clientWidth-150);
|
||||
z-index:7;
|
||||
visibility:visible
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
@import url(../bootstrap/css/bootstrap.css);
|
||||
input{
|
||||
height:24px;
|
||||
}
|
||||
a {
|
||||
color: #1A5CC8;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
color: orange;
|
||||
text-decoration: underline;
|
||||
}
|
||||
h2 {
|
||||
color: blue;
|
||||
}
|
||||
#wrapper {
|
||||
width: 95%;
|
||||
position: relative;
|
||||
left: 2.5%;
|
||||
}
|
||||
|
||||
.toprow {
|
||||
background-color: #1A5CC8;
|
||||
color: #FFFFFF;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
background: url("../image/menu_bg.png");
|
||||
}
|
||||
.toprow a {
|
||||
color: #FFFFFF;
|
||||
font-family: Arial;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 15px;
|
||||
}
|
||||
.toprow a:hover {
|
||||
color: orange;
|
||||
font-family: Arial;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 15px;
|
||||
}
|
||||
.oddrow {
|
||||
background-color: #E5ECF9;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.evenrow {
|
||||
background-color: #FFFFFF;
|
||||
white-space: nowrap;
|
||||
}
|
||||
body {
|
||||
background-color: #FFFFFF;
|
||||
background-image: url("../image/background.jpg");
|
||||
font-size:24px;
|
||||
line-height:48px;
|
||||
}
|
||||
.hd {
|
||||
color: #FFFFFF;
|
||||
font-weight: bold;
|
||||
}
|
||||
.time {
|
||||
text-align: right;
|
||||
}
|
||||
.ip {
|
||||
padding-right: 5px;
|
||||
text-align: right;
|
||||
}
|
||||
tr.userinfo {
|
||||
background-color: #FFFFF0;
|
||||
font-size: 16px;
|
||||
}
|
||||
span.yes {
|
||||
color: green;
|
||||
font-weight: bolder;
|
||||
}
|
||||
span.no {
|
||||
color: red;
|
||||
font-weight: bolder;
|
||||
}
|
||||
.green {
|
||||
color: green;
|
||||
}
|
||||
.red {
|
||||
color: red;
|
||||
}
|
||||
.blue {
|
||||
color: blue;
|
||||
}
|
||||
.gray {
|
||||
color: gray;
|
||||
}
|
||||
.orange {
|
||||
color: orange;
|
||||
}
|
||||
.navy {
|
||||
color: navy;
|
||||
}
|
||||
span.exadmin {
|
||||
color: gray;
|
||||
}
|
||||
#center {
|
||||
text-align: center;
|
||||
}
|
||||
div.content {
|
||||
background: none repeat scroll 0 0 #E4F0F8;
|
||||
font-family: Times New Roman;
|
||||
font-size: 14px;
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 0 20px;
|
||||
text-align: left;
|
||||
white-space:normal;
|
||||
}
|
||||
.sampledata {
|
||||
background: none repeat scroll 0 0 #8DB8FF;
|
||||
font-family: Monospace;
|
||||
font-size: 18px;
|
||||
white-space: pre;
|
||||
}
|
||||
#head {
|
||||
height: 53px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
#menu {
|
||||
background: url("../image/menu_bg.png") repeat scroll 0 0 transparent;
|
||||
font-weight: bold;
|
||||
height: 35px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 2;
|
||||
}
|
||||
.menu_item {
|
||||
display: inline;
|
||||
position: relative;
|
||||
top: 5px;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
.menu_item a {
|
||||
color: #FFFFFF;
|
||||
font-size: 20px;
|
||||
top: 2px;
|
||||
}
|
||||
#profile {
|
||||
font-weight: bold;
|
||||
height: 32px;
|
||||
left: 0;
|
||||
position: absolute;
|
||||
text-align: right;
|
||||
top: 0;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 3;
|
||||
}
|
||||
#broadcast {
|
||||
color: red;
|
||||
height: 50px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 4;
|
||||
}
|
||||
#main {
|
||||
height: auto;
|
||||
position: static;
|
||||
width: 100%;
|
||||
z-index: 6;
|
||||
}
|
||||
#foot {
|
||||
height: 133px;
|
||||
position: static;
|
||||
text-align: center;
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
z-index: 7;
|
||||
}
|
||||
#logo {
|
||||
position: static;
|
||||
vertical-align: middle;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/pdo.php");
|
||||
require_once(dirname(__FILE__)."/memcache.php");
|
||||
|
||||
//自动切换夜间模式
|
||||
//if(date('H')<5||date('H')>21||isset($_GET['dark'])) $OJ_CSS="dark.css";
|
||||
|
||||
//允许用参数tp临时切换皮肤
|
||||
/*
|
||||
if(in_array($_GET['tp'],$OJ_TP)){
|
||||
$OJ_TEMPLATE=$_GET['tp'];
|
||||
setcookie("tp", $_GET['tp'], time()+3600);
|
||||
}else if (in_array($_COOKIE['tp'],$OJ_TP)){
|
||||
$OJ_TEMPLATE=$_COOKIE['tp'];
|
||||
}
|
||||
*/
|
||||
|
||||
//自动识别语言
|
||||
if (isset($_SESSION[$OJ_NAME . '_' . 'OJ_LANG'])) {
|
||||
$OJ_LANG=$_SESSION[$OJ_NAME . '_' . 'OJ_LANG'];
|
||||
} else if (isset($_COOKIE['lang']) && in_array($_COOKIE['lang'], array("cn", "ug", "en", 'fa', 'ko', 'th'))) {
|
||||
$OJ_LANG=$_COOKIE['lang'];
|
||||
} else if (isset($_GET['lang']) && in_array($_GET['lang'], array("cn", "ug", "en", 'fa', 'ko', 'th'))) {
|
||||
$OJ_LANG=$_GET['lang'];
|
||||
} else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && $OJ_LANG != "cn") {
|
||||
$userLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
foreach ($userLanguages as $userLang) {
|
||||
$langParts = explode(';', $userLang);
|
||||
$lang = strtolower(substr($langParts[0], 0, 2));
|
||||
if (in_array($lang, array("zh", "ug", "en", 'fa', 'ko', 'th'))) {
|
||||
$OJ_LANG = $lang;
|
||||
if($lang=="zh") $OJ_LANG="cn";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
require(dirname(__FILE__)."/../lang/$OJ_LANG.php");
|
||||
|
||||
$domain=basename($_SERVER["HTTP_HOST"]);
|
||||
|
||||
if($OJ_SaaS_ENABLE){
|
||||
$DOMAIN="my.hustoj.com"; // 如启用,需要替换为SaaS服务的主域名。
|
||||
$OJ_SaaS_CONF=realpath(dirname(__FILE__)."/..")."/SaaS/".basename($_SERVER["HTTP_HOST"]).".php";
|
||||
if(file_exists($OJ_SaaS_CONF)){
|
||||
require_once($OJ_SaaS_CONF);
|
||||
}else{
|
||||
// echo $OJ_SaaS_CONF;
|
||||
}
|
||||
if($domain==$DOMAIN) $MSG_REG_INFO.="/初始化MyOJ";
|
||||
}else{
|
||||
$DOMAIN=$domain;
|
||||
}
|
||||
|
||||
if(isset($_SERVER["HTTP_USER_AGENT"])&&strpos($_SERVER["HTTP_USER_AGENT"],"MSIE")){ // 360 or IE use bs3 instead
|
||||
$OJ_TEMPLATE="bs3";
|
||||
}
|
||||
|
||||
|
||||
if(isset($_SESSION[$OJ_NAME.'_user_id'])&&isset($OJ_LIMIT_TO_1_IP)&& $OJ_LIMIT_TO_1_IP){
|
||||
$ip = ($_SERVER['REMOTE_ADDR']);
|
||||
if( isset($_SERVER['HTTP_X_FORWARDED_FOR'] )&&!empty( trim( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ){
|
||||
$REMOTE_ADDR = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$tmp_ip=explode(',',$REMOTE_ADDR);
|
||||
$ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
|
||||
} else if(isset($_SERVER['HTTP_X_REAL_IP'])&& !empty( trim( $_SERVER['HTTP_X_REAL_IP'] ) ) ){
|
||||
$REMOTE_ADDR = $_SERVER['HTTP_X_REAL_IP'];
|
||||
$tmp_ip=explode(',',$REMOTE_ADDR);
|
||||
$ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
|
||||
}
|
||||
$sql="select ip from loginlog where user_id=? order by time desc";
|
||||
$rows=pdo_query($sql,$_SESSION[$OJ_NAME.'_user_id'] );
|
||||
$lastip=$rows[0][0];
|
||||
if($ip!=$lastip){
|
||||
unset($_SESSION[$OJ_NAME.'_'.'user_id']);
|
||||
setcookie($OJ_NAME."_user","");
|
||||
setcookie($OJ_NAME."_check","");
|
||||
session_destroy();
|
||||
$view_errors="Logged in another ip address:$lastip, auto logout!";
|
||||
require("template/$OJ_TEMPLATE/error.php");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$OJ_LOG_FILE="/var/log/hustoj/{$OJ_NAME}.log";
|
||||
require_once(dirname(__FILE__) . "/logger.php");
|
||||
|
||||
$logger=new Logger(isset($_SESSION[$OJ_NAME . '_' . 'user_id'])?$_SESSION[$OJ_NAME . '_' . 'user_id']:"guest",
|
||||
$OJ_LOG_FILE,
|
||||
$OJ_LOG_DATETIME_FORMAT,
|
||||
$OJ_LOG_ENABLED,
|
||||
$OJ_LOG_PID_ENABLED,
|
||||
$OJ_LOG_USER_ENABLED,
|
||||
$OJ_LOG_URL_ENABLED,
|
||||
$OJ_LOG_URL_HOST_ENABLED,
|
||||
$OJ_LOG_URL_PARAM_ENABLED,
|
||||
$OJ_LOG_TRACE_ENABLED);
|
||||
$logger->info();
|
||||
// these lines can help you make a SaaS platform of HUSTOJ with the help of JudgeHub
|
||||
// 傻瓜级保姆配置系统
|
||||
switch($OJ_FRIENDLY_LEVEL) {
|
||||
case 9:
|
||||
$OJ_GUEST=true;
|
||||
case 8:
|
||||
$OJ_DOWNLOAD=true;
|
||||
case 7:
|
||||
$OJ_BBS="discuss3";
|
||||
$OJ_FREE_PRACTICE=true;
|
||||
case 6:
|
||||
$OJ_LONG_LOGIN=true;
|
||||
case 5:
|
||||
$OJ_TEST_RUN=true;
|
||||
case 4:
|
||||
$OJ_MAIL=true;
|
||||
$OJ_AUTO_SHARE=true;
|
||||
case 3:
|
||||
$OJ_SHOW_DIFF=true;
|
||||
$OJ_VCODE=false;
|
||||
case 2:
|
||||
$OJ_LANG="cn";
|
||||
case 1:
|
||||
date_default_timezone_set("Asia/Shanghai");
|
||||
pdo_query("SET time_zone ='+8:00'");
|
||||
case 0:
|
||||
break;
|
||||
case -1:
|
||||
$OJ_NEED_LOGIN=true;
|
||||
$OJ_REGISTER=false;
|
||||
|
||||
}
|
||||
if(!isset($OJ_SUBMIT_COOLDOWN_TIME)) $OJ_SUBMIT_COOLDOWN_TIME=3;
|
||||
// if using EXAM or ON site auto turn off free practice
|
||||
if(isset($OJ_ON_SITE_CONTEST_ID) || isset($OJ_EXAM_CONTEST_ID)) $OJ_FREE_PRACTICE=false;
|
||||
|
||||
// $OJ_BG="/image/bg".date('H').".jpg"; //每个整点更换壁纸,需要准备bg[0~23].jpg在image目录
|
||||
// if OJ_BG==bing ,using bing.com for daily change background
|
||||
if(isset($OJ_BG)&&$OJ_BG=="bing"){
|
||||
$logfile="/dev/shm/bing.log";
|
||||
$history=@file_get_contents($logfile);
|
||||
if($history!=""){
|
||||
$history=json_decode($history);
|
||||
}else{
|
||||
$history=array();
|
||||
}
|
||||
$bg_file=dirname(dirname(__FILE__))."/image/bg.url";
|
||||
if(!file_exists($bg_file)) touch($bg_file);
|
||||
if(time()-fileatime($bg_file)>3600*24){
|
||||
require_once(dirname(__FILE__)."/curl.php");
|
||||
$data=curl_get("https://cn.bing.com/");
|
||||
$OJ_BG=getPartByMark($data,"<link rel=\"preload\" href=\"","\" as=\"image\" id=\"preloadBg\"");
|
||||
if(strpos($OJ_BG,"http")!=0)$OJ_BG="https://cn.bing.com/".$OJ_BG;
|
||||
//echo $OJ_BG;
|
||||
if($OJ_BG){
|
||||
file_put_contents($bg_file,$OJ_BG);
|
||||
if(!in_array($OJ_BG,$history)){
|
||||
array_push($history,$OJ_BG);
|
||||
if(count($history)>30) array_shift($history);
|
||||
file_put_contents($logfile,json_encode($history));
|
||||
}
|
||||
}
|
||||
else touch($bg_file);
|
||||
}else{
|
||||
$OJ_BG=file_get_contents($bg_file);
|
||||
if(!empty($history)){
|
||||
$OJ_BG=$history[rand(0,count($history)-1)];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!empty($OJ_CDN_URL)) {
|
||||
header('Access-Control-Allow-Origin:'.$OJ_CDN_URL);
|
||||
}
|
||||
Executable
+212
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* @author 马秉尧
|
||||
*/
|
||||
class IpLocation {
|
||||
/**
|
||||
* QQWry.Dat文件指针
|
||||
* @var resource
|
||||
*/
|
||||
var $fp;
|
||||
/**
|
||||
* 第一条IP记录的偏移地址
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $firstip;
|
||||
/**
|
||||
* 最后一条IP记录的偏移地址
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $lastip;
|
||||
/**
|
||||
* IP记录的总条数(不包含版本信息记录)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $totalip;
|
||||
/**
|
||||
* 返回读取的长整型数
|
||||
*
|
||||
* @access private
|
||||
* @return int
|
||||
*/
|
||||
function getlong() {
|
||||
//将读取的little-endian编码的4个字节转化为长整型数
|
||||
$result = unpack('Vlong', fread($this->fp, 4));
|
||||
return $result['long'];
|
||||
}
|
||||
/**
|
||||
* 返回读取的3个字节的长整型数
|
||||
*
|
||||
* @access private
|
||||
* @return int
|
||||
*/
|
||||
function getlong3() {
|
||||
//将读取的little-endian编码的3个字节转化为长整型数
|
||||
$result = unpack('Vlong', fread($this->fp, 3).chr(0));
|
||||
return $result['long'];
|
||||
}
|
||||
/**
|
||||
* 返回压缩后可进行比较的IP地址
|
||||
*
|
||||
* @access private
|
||||
* @param string $ip
|
||||
* @return string
|
||||
*/
|
||||
function packip($ip) {
|
||||
// 将IP地址转化为长整型数,如果在PHP5中,IP地址错误,则返回False,
|
||||
// 这时intval将Flase转化为整数-1,之后压缩成big-endian编码的字符串
|
||||
return pack('N', intval(ip2long($ip)));
|
||||
}
|
||||
/**
|
||||
* 返回读取的字符串
|
||||
*
|
||||
* @access private
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
function getstring($data = "") {
|
||||
$char = fread($this->fp, 1);
|
||||
while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束
|
||||
$data .= $char; // 将读取的字符连接到给定字符串之后
|
||||
$char = fread($this->fp, 1);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* 返回地区信息
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function getarea() {
|
||||
$byte = fread($this->fp, 1); // 标志字节
|
||||
switch (ord($byte)) {
|
||||
case 0: // 没有区域信息
|
||||
$area = "";
|
||||
break;
|
||||
case 1:
|
||||
case 2: // 标志字节为1或2,表示区域信息被重定向
|
||||
fseek($this->fp, $this->getlong3());
|
||||
$area = $this->getstring();
|
||||
break;
|
||||
default: // 否则,表示区域信息没有被重定向
|
||||
$area = $this->getstring($byte);
|
||||
break;
|
||||
}
|
||||
return $area;
|
||||
}
|
||||
/**
|
||||
* 根据所给 IP 地址或域名返回所在地区信息
|
||||
*
|
||||
* @access public
|
||||
* @param string $ip
|
||||
* @return array
|
||||
*/
|
||||
function getlocation($ip) {
|
||||
if (!$this->fp) return 'not found!';//null; // 如果数据文件没有被正确打开,则直接返回空
|
||||
$location['ip'] = gethostbyname($ip); // 将输入的域名转化为IP地址
|
||||
$ip = $this->packip($location['ip']); // 将输入的IP地址转化为可比较的IP地址
|
||||
// 不合法的IP地址会被转化为255.255.255.255
|
||||
// 对分搜索
|
||||
$l = 0; // 搜索的下边界
|
||||
$u = $this->totalip; // 搜索的上边界
|
||||
$findip = $this->lastip; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息)
|
||||
while ($l <= $u) { // 当上边界小于下边界时,查找失败
|
||||
$i = floor(($l + $u) / 2); // 计算近似中间记录
|
||||
fseek($this->fp, $this->firstip + $i * 7);
|
||||
$beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址
|
||||
// strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式
|
||||
// 以便用于比较,后面相同。
|
||||
if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时
|
||||
$u = $i - 1; // 将搜索的上边界修改为中间记录减一
|
||||
}
|
||||
else {
|
||||
fseek($this->fp, $this->getlong3());
|
||||
$endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址
|
||||
if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时
|
||||
$l = $i + 1; // 将搜索的下边界修改为中间记录加一
|
||||
}
|
||||
else { // 用户的IP在中间记录的IP范围内时
|
||||
$findip = $this->firstip + $i * 7;
|
||||
break; // 则表示找到结果,退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取查找到的IP地理位置信息
|
||||
fseek($this->fp, $findip);
|
||||
$location['beginip'] = long2ip($this->getlong()); // 用户IP所在范围的开始地址
|
||||
$offset = $this->getlong3();
|
||||
fseek($this->fp, $offset);
|
||||
$location['endip'] = long2ip($this->getlong()); // 用户IP所在范围的结束地址
|
||||
$byte = fread($this->fp, 1); // 标志字节
|
||||
switch (ord($byte)) {
|
||||
case 1: // 标志字节为1,表示国家和区域信息都被同时重定向
|
||||
$countryOffset = $this->getlong3(); // 重定向地址
|
||||
fseek($this->fp, $countryOffset);
|
||||
$byte = fread($this->fp, 1); // 标志字节
|
||||
switch (ord($byte)) {
|
||||
case 2: // 标志字节为2,表示国家信息又被重定向
|
||||
fseek($this->fp, $this->getlong3());
|
||||
$location['country'] = $this->getstring();
|
||||
fseek($this->fp, $countryOffset + 4);
|
||||
$location['area'] = $this->getarea();
|
||||
break;
|
||||
default: // 否则,表示国家信息没有被重定向
|
||||
$location['country'] = $this->getstring($byte);
|
||||
$location['area'] = $this->getarea();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 2: // 标志字节为2,表示国家信息被重定向
|
||||
fseek($this->fp, $this->getlong3());
|
||||
$location['country'] = $this->getstring();
|
||||
fseek($this->fp, $offset + 8);
|
||||
$location['area'] = $this->getarea();
|
||||
break;
|
||||
default: // 否则,表示国家信息没有被重定向
|
||||
$location['country'] = $this->getstring($byte);
|
||||
$location['area'] = $this->getarea();
|
||||
break;
|
||||
}
|
||||
if ($location['country'] == " CZ88.NET") { // CZ88.NET表示没有有效信息
|
||||
$location['country'] = "未知";
|
||||
}
|
||||
if ($location['area'] == " CZ88.NET") {
|
||||
$location['area'] = "";
|
||||
}
|
||||
$location['country'] = iconv("GB2312","UTF-8",$location['country']);
|
||||
$location['area'] = iconv("GB2312","UTF-8",$location['area']);
|
||||
return $location;
|
||||
}
|
||||
/**
|
||||
* 构造函数,打开 QQWry.Dat 文件并初始化类中的信息
|
||||
*
|
||||
* @param string $filename
|
||||
* @return IpLocation
|
||||
*/
|
||||
function __construct($filename = "./include/QQWry.Dat")
|
||||
{
|
||||
$this->init($filename);
|
||||
}
|
||||
function init($filename){
|
||||
if (($this->fp = @fopen($filename, 'rb')) !== false) {
|
||||
$this->firstip = $this->getlong();
|
||||
$this->lastip = $this->getlong();
|
||||
$this->totalip = ($this->lastip - $this->firstip) / 7;
|
||||
//注册析构函数,使其在程序执行结束时执行
|
||||
register_shutdown_function(array(&$this, '_IpLocation'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 析构函数,用于在页面执行结束后自动关闭打开的文件。
|
||||
*
|
||||
*/
|
||||
function _IpLocation() {
|
||||
fclose($this->fp);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Vendored
+2
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
class Logger
|
||||
{
|
||||
private $user;
|
||||
private $logfile;
|
||||
private $datetime_format;
|
||||
private $enabled;
|
||||
private $pid_enabled;
|
||||
private $user_enabled;
|
||||
private $url_enabled;
|
||||
private $url_host_enabled;
|
||||
private $url_param_enabled;
|
||||
private $trace_enabled;
|
||||
private $trace_id;
|
||||
|
||||
public function __construct(
|
||||
$user,
|
||||
$logfile,
|
||||
$datetime_format,
|
||||
$enabled,
|
||||
$pid_enabled,
|
||||
$user_enabled,
|
||||
$url_enabled,
|
||||
$url_host_enabled,
|
||||
$url_param_enabled,
|
||||
$trace_enabled
|
||||
) {
|
||||
$this->user = $user;
|
||||
$this->logfile = $logfile;
|
||||
$this->datetime_format = $datetime_format;
|
||||
$this->enabled = $enabled;
|
||||
$this->pid_enabled = $pid_enabled;
|
||||
$this->user_enabled = $user_enabled;
|
||||
$this->url_enabled = $url_enabled;
|
||||
$this->url_host_enabled = $url_host_enabled;
|
||||
$this->url_param_enabled = $url_param_enabled;
|
||||
$this->trace_enabled = $trace_enabled;
|
||||
if ($this->trace_enabled)
|
||||
$this->trace_id = uniqid();
|
||||
}
|
||||
|
||||
public function info($message = "", array $data = [])
|
||||
{
|
||||
$this->delegrate_logging("info", $message, $data);
|
||||
}
|
||||
|
||||
public function warn($message = "", array $data = [])
|
||||
{
|
||||
$this->delegrate_logging("warn", $message, $data);
|
||||
}
|
||||
|
||||
protected function delegrate_logging($level, $message = "", array $data = [])
|
||||
{
|
||||
if ($this->enabled) {
|
||||
$this->logging($level, $message, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function logging($level, $message = "", array $data = [])
|
||||
{
|
||||
$datetime = new DateTime();
|
||||
$datetime = $datetime->format($this->datetime_format);
|
||||
$user = $this->user;
|
||||
$trace_id = $this->trace_id;
|
||||
$prefix = "$datetime $level ";
|
||||
if ($this->pid_enabled) {
|
||||
$pid = getmypid();
|
||||
$prefix = $prefix . "$pid ";
|
||||
}
|
||||
if ($this->user_enabled)
|
||||
$prefix = $prefix . "[$user] ";
|
||||
if ($this->trace_enabled)
|
||||
$prefix = $prefix . "[$trace_id] ";
|
||||
if ($this->url_enabled) {
|
||||
$script = $_SERVER['SCRIPT_NAME'];
|
||||
$url = $script;
|
||||
if ($this->url_host_enabled) {
|
||||
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'https') === FALSE ? 'http' : 'https';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$url = $protocol . '://' . $host . $url;
|
||||
}
|
||||
if ($this->url_param_enabled) {
|
||||
$params = $_SERVER['QUERY_STRING'];
|
||||
if (!empty($params))
|
||||
$url = $url . "?" . $params;
|
||||
}
|
||||
$prefix = $prefix . "$url ";
|
||||
}
|
||||
if (empty($message))
|
||||
$message = $prefix;
|
||||
else
|
||||
$message = "$prefix --- $message";
|
||||
foreach ($data as $key => $val)
|
||||
$message = str_replace("%{$key}%", $val, $message);
|
||||
$message .= PHP_EOL;
|
||||
$handle = fopen($this->logfile, "a");
|
||||
fwrite($handle, $message);
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once("./include/my_func.inc.php");
|
||||
|
||||
function check_login($user_id,$password){
|
||||
session_destroy();
|
||||
session_start();
|
||||
$discuz_host="127.0.0.1";
|
||||
$discuz_port="3306";
|
||||
$discuz_user="root";
|
||||
$discuz_db="discuz";
|
||||
$discuz_pass="root";
|
||||
$discuz_conn=mysql_connect($discuz_host.":".$discuz_port,$discuz_user,$discuz_pass);
|
||||
|
||||
$ret=false;
|
||||
pdo_query("set names utf8");
|
||||
$sql="select password,salt,username from ".$discuz_db.".uc_members where username='$user_id'";
|
||||
$result=pdo_query($sql);
|
||||
$row = $result[0];
|
||||
if($discuz_conn){
|
||||
mysql_select_db($discuz_db,$discuz_conn);
|
||||
$result=pdo_query($sql,$discuz_conn);
|
||||
|
||||
if($row['password']==md5(md5($password).$row['salt'])){
|
||||
|
||||
$_SESSION[$OJ_NAME.'_'.'user_id']=$row['username'];
|
||||
$ret=$_SESSION[$OJ_NAME.'_'.'user_id'];
|
||||
// $sql="insert into jol.users(user_id,ip,nick,school) values('".$_SESSION[$OJ_NAME.'_'.'user_id']."','','','') on DUPLICATE KEY UPDATE nick='".$row['username']."'";
|
||||
// pdo_query($sql);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
require_once("./include/my_func.inc.php");
|
||||
|
||||
function check_login($user_id,$password){
|
||||
global $view_errors,$OJ_EXAM_CONTEST_ID,$MSG_WARNING_DURING_EXAM_NOT_ALLOWED,$MSG_WARNING_LOGIN_FROM_DIFF_IP;
|
||||
$pass2 = 'No Saved';
|
||||
if(isset($_SESSION))session_destroy();
|
||||
session_start();
|
||||
$sql="SELECT `user_id`,`password` FROM `users` WHERE `user_id`=? and defunct='N' ";
|
||||
$result=pdo_query($sql,$user_id);
|
||||
if(count($result)==1){
|
||||
$row = $result[0];
|
||||
if( pwCheck($password,$row['password'])){
|
||||
$user_id=$row['user_id'];
|
||||
$ip = ($_SERVER['REMOTE_ADDR']);
|
||||
if( isset($_SERVER['HTTP_X_FORWARDED_FOR'] )&&!empty( trim( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ){
|
||||
$REMOTE_ADDR = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
$tmp_ip=explode(',',$REMOTE_ADDR);
|
||||
$ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
|
||||
} else if(isset($_SERVER['HTTP_X_REAL_IP'])&& !empty( trim( $_SERVER['HTTP_X_REAL_IP'] ) ) ){
|
||||
$REMOTE_ADDR = $_SERVER['HTTP_X_REAL_IP'];
|
||||
$tmp_ip=explode(',',$REMOTE_ADDR);
|
||||
$ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
|
||||
}
|
||||
if(isset($OJ_EXAM_CONTEST_ID)&&intval($OJ_EXAM_CONTEST_ID)>0){ //考试模式
|
||||
$ccid=$OJ_EXAM_CONTEST_ID;
|
||||
$sql="select min(start_time) from contest where start_time<=now() and end_time>=now() and contest_id>=?";
|
||||
$rows=pdo_query($sql,$ccid);
|
||||
$start_time=$rows[0][0];
|
||||
$sql="select ip from loginlog where user_id=? and time>? order by time desc limit 1";
|
||||
$rows=pdo_query($sql,$user_id,$start_time);
|
||||
$lastip=$rows[0][0];
|
||||
$sql="select count(1) from `privilege` where `user_id`=? and `rightstr`='administrator' limit 1";
|
||||
$rows=pdo_query($sql, $user_id);
|
||||
$isAdministrator=($rows[0][0]>0);
|
||||
if((!empty($lastip))&&$lastip!=$ip&&!($isAdministrator)) { //如果考试开后曾经登陆过,则之后登陆所用ip必须保持一致。
|
||||
$view_errors="$MSG_WARNING_LOGIN_FROM_DIFF_IP($lastip/$ip) $MSG_WARNING_DURING_EXAM_NOT_ALLOWED!";
|
||||
return false;
|
||||
}//如遇机器故障,可经管理员后台指定新的ip来允许登陆。
|
||||
}
|
||||
$sql="INSERT INTO `loginlog`(user_id,password,ip,time) VALUES(?,'login ok',?,NOW())";
|
||||
pdo_query($sql,$user_id,$ip);
|
||||
$sql="UPDATE users set accesstime=now(),ip=? where user_id=?";
|
||||
pdo_query($sql,$ip,$user_id);
|
||||
return $user_id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require_once("./include/my_func.inc.php");
|
||||
|
||||
function check_login($user_id,$password){
|
||||
session_destroy();
|
||||
session_start();
|
||||
$ldap_host="ldap://127.0.0.1";
|
||||
$ldap_port="389";
|
||||
$ldap_conn=ldap_connect($ldap_host,$ldap_port);
|
||||
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
|
||||
$dn="uid=$user_id,ou=people,dc=example,dc=com";
|
||||
$ret=false;
|
||||
if($ldap_conn){
|
||||
$login=ldap_bind($ldap_conn,$dn,$password);
|
||||
if($login){
|
||||
$ret=$user_id;
|
||||
}
|
||||
}
|
||||
ldap_unbind($ldap_conn);
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once("./include/my_func.inc.php");
|
||||
|
||||
function check_login($user_id,$password){
|
||||
session_destroy();
|
||||
session_start();
|
||||
$moodle_host="127.0.0.1";
|
||||
$moodle_port="3306";
|
||||
$moodle_user="root";
|
||||
$moodle_db="moodle";
|
||||
$moodle_pass="";
|
||||
//$moodle_conn=mysql_connect($moodle_host.":".$moodle_port,$moodle_user,$moodle_pass);
|
||||
$moodle_dbh=new PDO("mysql:host=".$moodle_host.';dbname='.$moodle_db, $moodle_user, $moodle_pass,array(PDO::ATTR_PERSISTENT=>true,PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8mb4"));
|
||||
$moodle_dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$moodle_salt= '-Y9-h0;),c@<i)D~*i/j7.pD6lh/,B';
|
||||
$password=md5($password.$moodle_salt);
|
||||
$ret=false;
|
||||
$moodle_pre="mdl_";
|
||||
$sql="select password from ".$moodle_db.".".$moodle_pre."user where username=?";
|
||||
if($moodle_dbh){
|
||||
$sth = $moodle_dbh->prepare($sql);
|
||||
$args=array();
|
||||
$args[0]=$user_id;
|
||||
$sth->execute($args);
|
||||
$result=$sth->fetchAll();
|
||||
// $result=pdo_query($sql,$user_id);
|
||||
$row=$result[0];
|
||||
if($row&&$password==$row[0]){
|
||||
$ret=$user_id;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
* Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for more info.
|
||||
*/
|
||||
var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}return a}function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}return a}function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}return Array(o,n,m,l)}function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__)."/db_info.inc.php");
|
||||
# Connect to memcache:
|
||||
global $memcache;
|
||||
if ($OJ_MEMCACHE){
|
||||
$memcache = new Memcache;
|
||||
if($OJ_SAE){
|
||||
$memcache=memcache_init();
|
||||
}else{
|
||||
$memcache->connect($OJ_MEMSERVER, $OJ_MEMPORT);
|
||||
}
|
||||
}
|
||||
|
||||
//下面两个函数首先都会判断是否有使用memcache,如果有使用,就会调用memcached的set/get命令来保存和获取数据
|
||||
//否则简单地返回false
|
||||
# Gets key / value pair into memcache … called by mysql_query_cache()
|
||||
function getCache($key) {
|
||||
global $memcache;
|
||||
// if ($memcache->get($key)) echo "true";
|
||||
return ($memcache) ? $memcache->get($key) : false;
|
||||
}
|
||||
|
||||
# Puts key / value pair into memcache … called by mysql_query_cache()
|
||||
function setCache($key, $object, $timeout = 60) {
|
||||
global $memcache;
|
||||
return ($memcache) ? $memcache->set($key,$object,MEMCACHE_COMPRESSED,$timeout) : false;
|
||||
}
|
||||
|
||||
# Caching version of pdo_query()
|
||||
function mysql_query_cache($sql){
|
||||
global $OJ_NAME,$OJ_MEMCACHE;
|
||||
$linkIdentifier = false;
|
||||
$timeout = 60;
|
||||
//首先调用上面的getCache函数,如果返回值不为false的话,就说明是从memcached服务器获取的数据
|
||||
//如果返回false,此时就需要直接从数据库中获取数据了。
|
||||
//需要注意的是这里使用操作的命令加上sql语句的md5码作为一个特定的key,可能大家觉得使用数据项的
|
||||
//名称作为key会比较自然一点。运行memcached加上"-vv"参数,并且不作为daemon运行的话,可以看见
|
||||
//memcached处理时输出的相关信息
|
||||
$num_args = func_num_args();
|
||||
$args = func_get_args(); //获得传入的所有参数的数组
|
||||
$args = array_slice($args,1,--$num_args);
|
||||
$key=md5($OJ_NAME.$_SERVER['HTTP_HOST']."mysql_query" . $sql.implode(" ",$args));
|
||||
if (!($cache = getCache($key))) {
|
||||
$cache = false;
|
||||
$cache =pdo_query($sql,$args);
|
||||
|
||||
//将数据放入memcached服务器中,如果memcached服务器没有开的话,此语句什么也不会做
|
||||
//如果开启了服务器的话,数据将会被缓存到memcached服务器中
|
||||
if (!setCache($key, $cache, $timeout)) {
|
||||
# If we get here, there isn’t a memcache daemon running or responding
|
||||
if($OJ_MEMCACHE) echo "You can run these command to get faster speed:<br>sudo apt-get install memcached<br>sudo apt-get install php5-memcache<br>sudo apt-get install php-memcache";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $cache;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__)."/db_info.inc.php");
|
||||
require_once(dirname(__FILE__)."/curl.php");
|
||||
require_once(dirname(__FILE__)."/const.inc.php");
|
||||
function has_bad_words($words){
|
||||
global $bad_words;
|
||||
foreach($bad_words as $bad){
|
||||
if(stristr($words,$bad) === FALSE){
|
||||
continue;
|
||||
}else{
|
||||
// echo $bad;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function starred($user_id){
|
||||
$stars=pdo_query("select starred from users where user_id=?",$user_id);
|
||||
if(!empty($stars)&& $stars[0][0]>0 ) return true;
|
||||
$stars=json_decode(curl_get("https://api.github.com/users/$user_id/starred?per_page=100"));
|
||||
foreach( $stars as $star){
|
||||
if($star->full_name=="zhblue/hustoj"){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function create_subdomain($user_id,$template="bs3",$friendly="0"){
|
||||
$user_id=strtolower($user_id);
|
||||
global $DB_NAME,$DB_USER,$DB_PASS,$DOMAIN;
|
||||
$NEW_USER="hustoj_".$user_id;
|
||||
$NEW_PASS=substr(pwGen($user_id),10);
|
||||
$FARMBASE="/home/saas";
|
||||
$templates=array("bs3","mdui","bshark","sweet","syzoj","sidebar");
|
||||
if(!in_array($template,$templates)) $template="bs3";
|
||||
pdo_query("create database `jol_$user_id`;\n");
|
||||
pdo_query("drop USER '$NEW_USER'@'localhost';");
|
||||
pdo_query("create USER '$NEW_USER'@'localhost' identified by '$NEW_PASS';");
|
||||
pdo_query("grant all privileges on `jol\\_".str_replace("_","\\_",$user_id)."`.* to '$NEW_USER'@'localhost' ;");
|
||||
pdo_query("flush privileges;\n");
|
||||
$sql="use `jol_$user_id`;\n";
|
||||
$csql=file_get_contents("/home/judge/src/install/db.sql");
|
||||
$sql.=mb_substr($csql,64);
|
||||
pdo_query($sql);
|
||||
$CONF_STR="<?php \$OJ_NAME='$user_id';\n";
|
||||
$CONF_STR.="\$DB_HOST='localhost';\n"; //数据库服务器ip或域名
|
||||
$CONF_STR.="\$DB_NAME='jol_$user_id';\n"; //数据库名
|
||||
$CONF_STR.="\$DB_USER='$NEW_USER';\n"; //数据库名
|
||||
$CONF_STR.="\$DB_PASS='$NEW_PASS';\n"; //数据库名
|
||||
$CONF_STR.="\$OJ_DATA='$FARMBASE/$user_id/data';\n"; //:测试数据目录
|
||||
$CONF_STR.="\$OJ_JUDGE_HUB_PATH='$user_id';\n"; //:OJ在farmpath中的子目录名
|
||||
$CONF_STR.="\$OJ_LANGMASK=2097084;\n"; //:语言类型
|
||||
$CONF_STR.="\$OJ_TEMPLATE='$template';\n"; //:模板名
|
||||
$CONF_STR.="\$OJ_REG_NEED_CONFIRM=false;\n"; //:允许注册
|
||||
$CONF_STR.="\$OJ_FRIENDLY_LEVEL=$friendly;\n"; //友善级别
|
||||
|
||||
$CONF_FILE=realpath(dirname(__FILE__)."/../")."/SaaS/$user_id.".$DOMAIN.".php";
|
||||
//if ($user_id=="zhblue") echo "<textarea>".$sql."</textarea>";
|
||||
// echo "<pre>".htmlentities($CONF_STR);
|
||||
// echo "</pre>".$CONF_FILE;
|
||||
mkdir($FARMBASE."/$user_id/run0",0755,true);
|
||||
mkdir($FARMBASE."/$user_id/data",0700,true);
|
||||
mkdir($FARMBASE."/$user_id/etc",0700,true);
|
||||
mkdir($FARMBASE."/$user_id/log",0700,true);
|
||||
mkdir(dirname($CONF_FILE),0700,true);
|
||||
file_put_contents($CONF_FILE,$CONF_STR);
|
||||
$CONF_STR="OJ_HOST_NAME=127.0.0.1\n";
|
||||
$CONF_STR.="OJ_DB_NAME=jol_".$user_id."\n";
|
||||
$CONF_STR.="OJ_USER_NAME=".$NEW_USER."\n";
|
||||
$CONF_STR.="OJ_PASSWORD=".$NEW_PASS."\n";
|
||||
$CONF_STR.="OJ_USE_DOCKER=1\n";
|
||||
$CONF_STR.="OJ_HTTP_USERNAME=CF-T8\n";
|
||||
$CONF_STR.="OJ_LANG_SET=0,1,6\n";
|
||||
$CONF_STR.="OJ_OI_MODE=1\n";
|
||||
|
||||
|
||||
$CONF_FILE=$FARMBASE."/".$user_id."/etc/judge.conf";
|
||||
// echo "<pre>".htmlentities($CONF_STR);
|
||||
// echo "</pre>".$CONF_FILE;
|
||||
file_put_contents($CONF_FILE,$CONF_STR);
|
||||
|
||||
$CONF_STR='
|
||||
grant {
|
||||
permission java.io.FilePermission "./-", "read,write";
|
||||
permission java.io.FilePermission "/usr/lib/jvm", "read";
|
||||
};
|
||||
';
|
||||
|
||||
$CONF_FILE=$FARMBASE."/".$user_id."/etc/java0.policy";
|
||||
// echo "<pre>".htmlentities($CONF_STR);
|
||||
// echo "</pre>".$CONF_FILE;
|
||||
file_put_contents($CONF_FILE,$CONF_STR);
|
||||
$DB_NAME="jol_".$user_id;
|
||||
$sql="delete from jol_".$user_id.".privilege where user_id='".$user_id."'; ";
|
||||
pdo_query($sql);
|
||||
$sql="INSERT INTO jol_".$user_id.".privilege(user_id,rightstr,valuestr,defunct) values('".$user_id."', 'administrator', 'true', 'N');";
|
||||
pdo_query($sql);
|
||||
$sql="INSERT INTO jol_".$user_id.".privilege(user_id,rightstr,valuestr,defunct) values('".$user_id."', 'source_browser', 'true', 'N');";
|
||||
pdo_query($sql);
|
||||
|
||||
}
|
||||
function mb_trim($string, $trim_chars = '\s'){
|
||||
return preg_replace('/^['.$trim_chars.']*(?U)(.*)['.$trim_chars.']*$/u', '\\1',$string);
|
||||
}
|
||||
function send_udp_message($host, $port, $message)
|
||||
{
|
||||
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
@socket_connect($socket, $host, $port);
|
||||
|
||||
$num = 0;
|
||||
$length = strlen($message);
|
||||
do
|
||||
{
|
||||
$buffer = substr($message, $num);
|
||||
$ret = @socket_write($socket, $buffer);
|
||||
$num += $ret;
|
||||
} while ($num < $length);
|
||||
|
||||
socket_close($socket);
|
||||
|
||||
// UDP ............, ............
|
||||
return true;
|
||||
}
|
||||
function trigger_judge($solution_id=0){
|
||||
global $OJ_UDPSERVER,$OJ_UDPPORT,$OJ_JUDGE_HUB_PATH;
|
||||
$JUDGE_SERVERS = explode(",",$OJ_UDPSERVER);
|
||||
$JUDGE_TOTAL = count($JUDGE_SERVERS);
|
||||
|
||||
$select = $solution_id%$JUDGE_TOTAL;
|
||||
$JUDGE_HOST = $JUDGE_SERVERS[$select];
|
||||
|
||||
if (strstr($JUDGE_HOST,":")!==false) {
|
||||
$JUDGE_SERVERS = explode(":",$JUDGE_HOST);
|
||||
$JUDGE_HOST = $JUDGE_SERVERS[0];
|
||||
$OJ_UDPPORT = $JUDGE_SERVERS[1];
|
||||
}
|
||||
if(isset($OJ_JUDGE_HUB_PATH))
|
||||
send_udp_message($JUDGE_HOST, $OJ_UDPPORT, $OJ_JUDGE_HUB_PATH);
|
||||
else
|
||||
send_udp_message($JUDGE_HOST, $OJ_UDPPORT, $solution_id );
|
||||
}
|
||||
function crypto_rand_secure($min, $max) {
|
||||
$range = $max - $min;
|
||||
if ($range < 0) return $min; // not so random...
|
||||
$log = log($range, 2);
|
||||
$bytes = (int) ($log / 8) + 1; // length in bytes
|
||||
$bits = (int) $log + 1; // length in bits
|
||||
$filter = (int) (1 << $bits) - 1; // set all lower bits to 1
|
||||
do {
|
||||
if(function_exists("openssl_random_pseudo_bytes")){
|
||||
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
|
||||
}else{
|
||||
$rnd = hexdec(bin2hex(rand()."_".rand()));
|
||||
}
|
||||
$rnd = $rnd & $filter; // discard irrelevant bits
|
||||
} while ($rnd >= $range);
|
||||
return $min + $rnd;
|
||||
}
|
||||
|
||||
function getToken($length=32){
|
||||
$token = "";
|
||||
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
|
||||
$codeAlphabet.= "0123456789";
|
||||
for($i=0;$i<$length;$i++){
|
||||
$token .= $codeAlphabet[crypto_rand_secure(0,strlen($codeAlphabet))];
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
function pwGen($password,$md5ed=False)
|
||||
{
|
||||
if (!$md5ed) $password=md5($password);
|
||||
$salt = sha1(rand());
|
||||
$salt = substr($salt, 0, 4);
|
||||
$hash = base64_encode( sha1($password . $salt, true) . $salt );
|
||||
return $hash;
|
||||
}
|
||||
|
||||
function pwCheck($password,$saved)
|
||||
{
|
||||
if (isOldPW($saved)){
|
||||
if(!isOldPW($password)) $mpw = md5($password);
|
||||
else $mpw=$password;
|
||||
if ($mpw==$saved) return True;
|
||||
else return False;
|
||||
}
|
||||
$svd=base64_decode($saved);
|
||||
$salt=substr($svd,20);
|
||||
if(!isOldPW($password)) $password=md5($password);
|
||||
$hash = base64_encode( sha1(($password) . $salt, true) . $salt );
|
||||
if (strcmp($hash,$saved)==0) return True;
|
||||
else return False;
|
||||
}
|
||||
|
||||
function isOldPW($password)
|
||||
{
|
||||
if(strlen($password)!=32) return false;
|
||||
for ($i=strlen($password)-1;$i>=0;$i--)
|
||||
{
|
||||
$c = $password[$i];
|
||||
if ('0'<=$c && $c<='9') continue;
|
||||
if ('a'<=$c && $c<='f') continue;
|
||||
if ('A'<=$c && $c<='F') continue;
|
||||
return False;
|
||||
}
|
||||
return True;
|
||||
}
|
||||
|
||||
/*
|
||||
如果希望允许用户名是中文,可以替换下面的is_valid_user_name函数为这个版本
|
||||
|
||||
function is_valid_user_name($user_name){
|
||||
$res = preg_match('/^[\x{4e00}-\x{9fa5}A-Za-z0-9 _::,,.。…\/、~`@#¥%&×+|{}=-*^$~!@#$%^&*()\+-—=()!¥{}【】\[\]\|;;《》<>\?\?\·]+$/u', $user_name);
|
||||
return $res ? TRUE : FALSE;
|
||||
|
||||
}
|
||||
*/
|
||||
function is_valid_user_name($user_name){
|
||||
$len=strlen($user_name);
|
||||
for ($i=0;$i<$len;$i++){
|
||||
if (
|
||||
($user_name[$i]>='a' && $user_name[$i]<='z') ||
|
||||
($user_name[$i]>='A' && $user_name[$i]<='Z') ||
|
||||
($user_name[$i]>='0' && $user_name[$i]<='9') ||
|
||||
$user_name[$i]=='-'||
|
||||
$user_name[$i]=='_'||
|
||||
($i==0 && $user_name[$i]=='*')
|
||||
);
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function sec2str($sec){
|
||||
return sprintf("%02d:%02d:%02d",$sec/3600,$sec%3600/60,$sec%60);
|
||||
}
|
||||
function is_running($cid){
|
||||
$now=date('Y-m-d H:i', time());
|
||||
$sql="SELECT count(*) FROM `contest` WHERE `contest_id`=? AND `end_time`>?";
|
||||
$result=pdo_query($sql,$cid,$now);
|
||||
$row=$result[0];
|
||||
$cnt=intval($row[0]);
|
||||
return $cnt>0;
|
||||
}
|
||||
function check_ac($cid,$pid,$noip){
|
||||
//require_once("./include/db_info.inc.php");
|
||||
global $OJ_NAME;
|
||||
if($noip){
|
||||
$sql="SELECT count(*) FROM `solution` WHERE `contest_id`=? AND `num`=? and `problem_id`!=0 AND `user_id`=?";
|
||||
$result=pdo_query($sql,$cid,$pid,$_SESSION[$OJ_NAME.'_'.'user_id']);
|
||||
$row=$result[0];
|
||||
$sub=intval($row[0]);
|
||||
if ($sub>0) return "<div class='label label-default'>?</div>";
|
||||
else return "";
|
||||
|
||||
}
|
||||
$sql="SELECT count(*) FROM `solution` WHERE `contest_id`=? AND `num`=? AND `result`='4' AND `user_id`=?";
|
||||
$result=pdo_query($sql,$cid,$pid,$_SESSION[$OJ_NAME.'_'.'user_id']);
|
||||
$row=$result[0];
|
||||
$ac=intval($row[0]);
|
||||
if ($ac>0) return "<div class='label label-success'>Y</div>";
|
||||
|
||||
$sql="SELECT count(*) FROM `solution` WHERE `contest_id`=? AND `num`=? AND `result`!=4 and `problem_id`!=0 AND `user_id`=?";
|
||||
$result=pdo_query($sql,$cid,$pid,$_SESSION[$OJ_NAME.'_'.'user_id']);
|
||||
$row=$result[0];
|
||||
$sub=intval($row[0]);
|
||||
|
||||
if ($sub>0) return "<div class='label label-danger'>N</div>";
|
||||
else return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
function RemoveXSS($val) {
|
||||
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
|
||||
// this prevents some character re-spacing such as <java\0script>
|
||||
// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
|
||||
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);
|
||||
|
||||
// straight replacements, the user should never need these since they're normal characters
|
||||
// this prevents like <IMG SRC=@avascript:alert('XSS')>
|
||||
$search = 'abcdefghijklmnopqrstuvwxyz';
|
||||
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$search .= '1234567890!@#$%^&*()';
|
||||
$search .= '~`";:?+/={}[]-_|\'\\';
|
||||
for ($i = 0; $i < strlen($search); $i++) {
|
||||
// ;? matches the ;, which is optional
|
||||
// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
|
||||
|
||||
// @ @ search for the hex values
|
||||
$val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
|
||||
// @ @ 0{0,7} matches '0' zero to seven times
|
||||
$val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
|
||||
}
|
||||
|
||||
// now the only remaining whitespace attacks are \t, \n, and \r //, 'style'
|
||||
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'script', 'embed', 'object', 'frameset', 'ilayer', 'bgsound');
|
||||
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
|
||||
$ra = array_merge($ra1, $ra2);
|
||||
|
||||
$found = true; // keep replacing as long as the previous round replaced something
|
||||
while ($found == true) {
|
||||
$val_before = $val;
|
||||
for ($i = 0; $i < sizeof($ra); $i++) {
|
||||
$pattern = '/';
|
||||
for ($j = 0; $j < strlen($ra[$i]); $j++) {
|
||||
if ($j > 0) {
|
||||
$pattern .= '(';
|
||||
$pattern .= '(&#[xX]0{0,8}([9ab]);)';
|
||||
$pattern .= '|';
|
||||
$pattern .= '|(�{0,8}([9|10|13]);)';
|
||||
$pattern .= ')*';
|
||||
}
|
||||
$pattern .= $ra[$i][$j];
|
||||
}
|
||||
$pattern .= '/i';
|
||||
$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
|
||||
$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
|
||||
if ($val_before == $val) {
|
||||
// no replacements were made, so exit the loop
|
||||
$found = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/*
|
||||
数据库
|
||||
CREATE TABLE `online` (
|
||||
`hash` varchar(32) collate utf8_unicode_ci NOT NULL,
|
||||
`ip` varchar(20) character set utf8 NOT NULL default '',
|
||||
`ua` varchar(255) character set utf8 NOT NULL default '',
|
||||
`refer` varchar(255) collate utf8_unicode_ci default NULL,
|
||||
`lastmove` int(10) NOT NULL,
|
||||
`firsttime` int(10) default NULL,
|
||||
`uri` varchar(255) collate utf8_unicode_ci default NULL,
|
||||
PRIMARY KEY (`hash`),
|
||||
UNIQUE KEY `hash` (`hash`)
|
||||
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
*/
|
||||
/**
|
||||
* 判定多久未响应的用户为已经离开的用户
|
||||
* @var int
|
||||
*/
|
||||
|
||||
define('ONLINE_DURATION', 600);
|
||||
|
||||
/**
|
||||
*
|
||||
* 本类用来对在线用户进行统计
|
||||
*
|
||||
* @package online
|
||||
* @author freefcw
|
||||
* @link http://www.missway.cn
|
||||
*
|
||||
*/
|
||||
class online{
|
||||
/**
|
||||
* database connect
|
||||
* @var databse link
|
||||
*/
|
||||
protected $db;
|
||||
/**
|
||||
* current user ip
|
||||
* @var string
|
||||
*/
|
||||
protected $ip;
|
||||
/**
|
||||
* current user agent
|
||||
* @var string
|
||||
*/
|
||||
protected $ua;
|
||||
/**
|
||||
* cureent user visit web uri
|
||||
* @var string
|
||||
*/
|
||||
protected $uri;
|
||||
/**
|
||||
* session id
|
||||
* @var string
|
||||
*/
|
||||
protected $hash;
|
||||
/**
|
||||
* cureent user refer uri
|
||||
* @var string
|
||||
*/
|
||||
protected $refer;
|
||||
//can add function:
|
||||
//example click number count
|
||||
protected $click;
|
||||
|
||||
/**
|
||||
* construct fuction,init database link
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
global $OJ_NAME;
|
||||
|
||||
$this->ip = ($_SERVER['REMOTE_ADDR']);
|
||||
|
||||
|
||||
if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
|
||||
|
||||
$REMOTE_ADDR = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
|
||||
$tmp_ip=explode(',',$REMOTE_ADDR);
|
||||
|
||||
$this->ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
|
||||
|
||||
}
|
||||
|
||||
if(isset($_SESSION[$OJ_NAME.'_'.'user_id']))
|
||||
$this->ua = htmlentities($_SESSION[$OJ_NAME.'_'.'user_id'],ENT_QUOTES,"UTF-8");
|
||||
else
|
||||
$this->ua ="guest";
|
||||
$this->ua .= "@".htmlentities($_SERVER['HTTP_USER_AGENT'],ENT_QUOTES,"UTF-8");
|
||||
$this->uri = ($_SERVER['PHP_SELF']);
|
||||
if(isset($_SERVER['HTTP_REFERER'])){
|
||||
$this->refer = (htmlentities($_SERVER['HTTP_REFERER'],ENT_QUOTES,"UTF-8"));
|
||||
}
|
||||
$this->hash = md5(session_id().$this->ip);
|
||||
|
||||
//check user existed!
|
||||
if($this->exist()){
|
||||
//update databse
|
||||
$this->update();
|
||||
}else if(!(strstr($this->ua,"bot")||strstr($this->ua,"spider"))){
|
||||
//if none, add this record
|
||||
$this->addRecord();
|
||||
}
|
||||
//clean the user who leave our site
|
||||
$this->clean();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* return all record!
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getAll()
|
||||
{
|
||||
|
||||
$sql = 'SELECT * FROM online';
|
||||
$ret = pdo_query($sql);
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* return specfy record
|
||||
* @var string ip
|
||||
* @return object
|
||||
*/
|
||||
function getRecord($ip)
|
||||
{
|
||||
$sql = "SELECT * FROM online WHERE ip = ?";
|
||||
$res = pdo_query($sql,$ip);
|
||||
if(count($res)){
|
||||
$ret = ($res[0]);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get total count
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function get_num()
|
||||
{
|
||||
|
||||
$sql = 'SELECT count(ip) as nums FROM online';
|
||||
$res = pdo_query($sql);
|
||||
$ret = 0;
|
||||
if($res){
|
||||
$ret = $res[0];
|
||||
$ret = $ret['nums'];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* check the record exist
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function exist()
|
||||
{
|
||||
|
||||
$sql = "SELECT count(1) FROM online WHERE hash = ?";
|
||||
$res = pdo_query($sql,$this->hash);
|
||||
return $res[0][0];
|
||||
|
||||
}
|
||||
/**
|
||||
* add a record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function addRecord()
|
||||
{
|
||||
|
||||
$now = time();
|
||||
$sql = "INSERT INTO online(hash, ip, ua, uri, refer, firsttime, lastmove)
|
||||
VALUES (?, ?,?, ?, ?, ?, ?)";
|
||||
pdo_query($sql,$this->hash,$this->ip, $this->ua,$this->uri,$this->refer,$now,$now);
|
||||
}
|
||||
|
||||
/**
|
||||
* update a record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function update()
|
||||
{
|
||||
|
||||
$sql = "UPDATE online
|
||||
SET
|
||||
ua = ?,
|
||||
uri = ?,
|
||||
refer = ?,
|
||||
lastmove = ?,
|
||||
ip = ?
|
||||
WHERE
|
||||
hash = ?
|
||||
";
|
||||
pdo_query($sql,$this->ua,$this->uri,$this->refer,time(),$this->ip,$this->hash);
|
||||
}
|
||||
/**
|
||||
* clean the duration user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function clean()
|
||||
{
|
||||
|
||||
$sql = 'DELETE FROM online WHERE lastmove<?';
|
||||
pdo_query($sql,(time()-ONLINE_DURATION));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
function pdo_query($sql){
|
||||
$num_args = func_num_args();
|
||||
$args = func_get_args(); //获得传入的所有参数的数组
|
||||
$args = array_slice($args,1,--$num_args);
|
||||
if(isset($args[0])&&is_array($args[0])) $args=$args[0];
|
||||
global $DB_HOST,$DB_NAME,$DB_USER,$DB_PASS,$dbh,$OJ_SAE,$OJ_TEMPLATE;
|
||||
try{
|
||||
if(!$dbh||stripos($sql,"create") === 0||stripos($sql,"drop") === 0|| stripos($sql,"grant") === 0){
|
||||
|
||||
if(isset($OJ_SAE)&&$OJ_SAE) {
|
||||
$OJ_DATA="saestor://data/";
|
||||
// for sae.sina.com.cn
|
||||
$DB_NAME=SAE_MYSQL_DB;
|
||||
$dbh=new PDO("mysql:host=".SAE_MYSQL_HOST_M.';dbname='.SAE_MYSQL_DB, SAE_MYSQL_USER, SAE_MYSQL_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8mb4"));
|
||||
}else{
|
||||
|
||||
if(stripos($sql,"create") === 0||stripos($sql,"drop") === 0|| stripos($sql,"grant") === 0){
|
||||
$dbh=new PDO("mysql:host=".$DB_HOST, $DB_USER, $DB_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8mb4;"));
|
||||
// echo "General SQL";
|
||||
$sql="use $DB_NAME; ".$sql;
|
||||
}else{
|
||||
$dbh=new PDO("mysql:host=".$DB_HOST.';dbname='.$DB_NAME, $DB_USER, $DB_PASS,array(PDO::ATTR_PERSISTENT=>true,PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8mb4"));
|
||||
// echo "$DB_NAME SQL";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute($args);
|
||||
$result=array();
|
||||
if(stripos($sql,"select") === 0){
|
||||
$result=$sth->fetchAll();
|
||||
}else if(stripos($sql,"insert") === 0){
|
||||
$result=$dbh->lastInsertId();
|
||||
}else{
|
||||
$result=$sth->rowCount();
|
||||
}
|
||||
//print($sql);
|
||||
$sth->closeCursor();
|
||||
return $result;
|
||||
}catch(PDOException $e){
|
||||
// echo "<span class=red>".$e->getMessage()."</span>"; // open this line to debug SQL fail problems
|
||||
// $view_errors="SQL:".$sql."\n".$e->getMessage();
|
||||
// echo htmlentities($view_errors."\n\n");
|
||||
GLOBAL $MSG_UPDATE_DATABASE,$MSG_HELP_UPDATE_DATABASE;
|
||||
GLOBAL $POP_UPED,$OJ_NAME,$_SESSION;
|
||||
if(!$POP_UPED&&isset($_SESSION[$OJ_NAME.'_administrator'])){
|
||||
echo " $MSG_HELP_UPDATE_DATABASE <a href='/admin/update_db.php'>$MSG_UPDATE_DATABASE</a>。";
|
||||
$view_errors="SQL:".$sql."\n".$e->getMessage();
|
||||
echo htmlentities($view_errors."\n\n");
|
||||
$POP_UPED=true;
|
||||
}
|
||||
|
||||
if(stripos($sql,"create") === 0||stripos($sql,"drop") === 0) echo "continue\n";
|
||||
//else exit(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
function Pie(_div)
|
||||
{
|
||||
var piejg = new jsGraphics(_div);
|
||||
var colors = new Array();
|
||||
colors[9] = "#0066FF";
|
||||
colors[5] = "#996633";
|
||||
colors[2] = "#80bb80";
|
||||
colors[3] = "#FF0066";
|
||||
colors[4] = "#9900FF";
|
||||
colors[6] = "#006633";
|
||||
colors[1] = "#8080FF";
|
||||
colors[7] = "#000000";
|
||||
colors[8] ="#CCFFFF";
|
||||
colors[0] = "#FF8080";
|
||||
colors[10] = "#066600";
|
||||
colors[11] ="#666666";
|
||||
|
||||
this.start_x = 0;
|
||||
this.start_y = 0;
|
||||
this.width= 100;
|
||||
this.height= 100;
|
||||
this.desc_distance = 80;
|
||||
this.desc_width = 10;
|
||||
this.desc_height= 10;
|
||||
this.IsShowPercentage =true;
|
||||
this.IsShowShadow =true;
|
||||
this.IsDescRight=true;
|
||||
this.nextRow = 2;
|
||||
|
||||
this.drawPie =function (y_value,x_value)
|
||||
{
|
||||
if(this.IsShowShadow)
|
||||
{
|
||||
piejg.setColor("#666666");
|
||||
piejg.fillEllipse(this.start_x+5, this.start_y+5, this.width, this.height);
|
||||
piejg.setColor("#CCFFFF");
|
||||
piejg.fillEllipse(this.start_x, this.start_y, this.width, this.height);
|
||||
}
|
||||
var Percentage = new Array();
|
||||
var y_len = y_value.length;
|
||||
var x_len = x_value.length;
|
||||
var sum = 0;
|
||||
var perspective = new Array();
|
||||
var begin_perspective = 0;
|
||||
var end_perspective = 0;
|
||||
|
||||
if(y_len != x_len)
|
||||
{
|
||||
alert("X and Y length of inconsistencies, errors parameters.");
|
||||
return;
|
||||
}
|
||||
for(var i = 0; i<y_len;i++)
|
||||
{
|
||||
sum+=y_value[i];
|
||||
}
|
||||
for (var i = 0; i<y_len;i++)
|
||||
{
|
||||
if(isNaN(y_value[i]))
|
||||
{
|
||||
alert("y is not a number!");
|
||||
return;
|
||||
}
|
||||
perspective[i] = Math.max(Math.round(360*y_value[i]/sum),1);
|
||||
Percentage[i] =Math.round(100*y_value[i]/sum);
|
||||
end_perspective +=perspective[i];
|
||||
if(i==0)
|
||||
{
|
||||
piejg.setColor(colors[i]);
|
||||
piejg.fillArc(this.start_x,this.start_y,this.width,this.height, 0, end_perspective);
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_perspective += perspective[i-1];
|
||||
piejg.setColor(colors[i]);
|
||||
piejg.fillArc(this.start_x,this.start_y,this.width,this.height, begin_perspective, end_perspective);
|
||||
}
|
||||
|
||||
}
|
||||
var temp_x = 0;
|
||||
var temp_y = 0;
|
||||
if(this.IsDescRight)
|
||||
{
|
||||
for(var i = 0 ;i<x_len;i++)
|
||||
{
|
||||
temp_x = this.width+10+this.start_y;
|
||||
temp_y = this.start_y+(i-x_len/2+1/2)*(this.height/x_len)+this.height/2;
|
||||
//temp_y = this.start_y+(i+1)*(this.height/x_len);
|
||||
piejg.setColor(colors[i]);
|
||||
piejg.fillRect(temp_x,temp_y,this.desc_width,this.desc_height);
|
||||
if(this.IsShowPercentage)
|
||||
{
|
||||
piejg.drawString(x_value[i]+"["+Percentage[i]+"%]",temp_x+this.desc_width,temp_y);
|
||||
}else
|
||||
{
|
||||
piejg.drawString(x_value[i],temp_x+this.desc_width,temp_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(var i = 0 ;i<x_len;i++)
|
||||
{
|
||||
temp_x = i*this.desc_distance+this.start_x;
|
||||
temp_y = this.height+10+this.start_y;
|
||||
if(i-this.nextRow>=0)
|
||||
{
|
||||
temp_x = (i-this.nextRow)*this.desc_distance+this.start_x;
|
||||
temp_y=this.height+10+30+this.start_y;
|
||||
|
||||
}
|
||||
if(i-this.nextRow*2>=0)
|
||||
{
|
||||
temp_x = (i-this.nextRow*2)*this.desc_distance+this.start_x;
|
||||
temp_y=this.height+10+60+this.start_y;
|
||||
|
||||
}
|
||||
if(i-this.nextRow*3>=0)
|
||||
{
|
||||
temp_x = (i-this.nextRow*3)*this.desc_distance+this.start_x;
|
||||
temp_y=this.height+10+90+this.start_y;
|
||||
|
||||
}
|
||||
piejg.setColor(colors[i]);
|
||||
piejg.fillRect(temp_x,temp_y,this.desc_width,this.desc_height);
|
||||
if(this.IsShowPercentage)
|
||||
{
|
||||
piejg.drawString(x_value[i]+"["+Percentage[i]+"%]",this.desc_width+3+temp_x,temp_y);
|
||||
}else
|
||||
{
|
||||
piejg.drawString(x_value[i],this.desc_width+3+temp_x,temp_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
piejg.paint();
|
||||
|
||||
};
|
||||
this.clearPie= function()
|
||||
{
|
||||
piejg.clear();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
function addproblem($title, $time_limit, $memory_limit, $description, $input, $output, $sample_input, $sample_output, $hint, $source, $spj, $OJ_DATA) {
|
||||
//$spj=($spj);
|
||||
$sql = "INSERT INTO `problem` (`title`,`time_limit`,`memory_limit`,`description`,`input`,`output`,`sample_input`,`sample_output`,`hint`,`source`,`spj`,`in_date`,`defunct`) VALUES(?,?,?,?,?,?,?,?,?,?,?,NOW(),'Y')";
|
||||
//echo $sql;
|
||||
$pid = pdo_query($sql, $title, $time_limit, $memory_limit, $description, $input, $output, $sample_input, $sample_output, $hint, $source, $spj);
|
||||
|
||||
echo "New Problem:<a target=_blank href='../problem.php?id=$pid'>$pid ".htmlentities($title,ENT_QUOTES)."</a> added!<br>";
|
||||
|
||||
if (isset($_POST['contest_id']) && intval($_POST['contest_id'])>0) {
|
||||
$cid = intval($_POST['contest_id']);
|
||||
$sql = "SELECT count(*) FROM `contest_problem` WHERE `contest_id`=?";
|
||||
$result = pdo_query($sql, $cid);
|
||||
$row = $result[0];
|
||||
$num = $row[0];
|
||||
|
||||
echo " - Contest Problem Num = ".$num.":";
|
||||
|
||||
$sql = "INSERT INTO `contest_problem` (`problem_id`,`contest_id`,`num`) VALUES(?,?,?)";
|
||||
pdo_query($sql, $pid, $cid, $num);
|
||||
}
|
||||
|
||||
$basedir = "$OJ_DATA/$pid";
|
||||
|
||||
if (!isset($OJ_SAE) || !$OJ_SAE) {
|
||||
//echo "[$title]data in $basedir";
|
||||
}
|
||||
return $pid;
|
||||
}
|
||||
|
||||
function mkdata($pid, $filename, $input, $OJ_DATA) {
|
||||
$basedir = "$OJ_DATA/$pid";
|
||||
|
||||
$fp = @fopen($basedir."/$filename","w");
|
||||
|
||||
if ($fp) {
|
||||
fputs($fp, preg_replace("(\r\n)", "\n", $input));
|
||||
fclose($fp);
|
||||
}
|
||||
else {
|
||||
echo "- Error while opening".$basedir."/$filename ,try [chgrp -R www-data $OJ_DATA] and [chmod -R 771 $OJ_DATA ] ";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-cache");
|
||||
header("Pragma: no-cache");
|
||||
require_once("./db_info.inc.php");
|
||||
if(isset($OJ_LANG)){
|
||||
require_once("../lang/$OJ_LANG.php");
|
||||
}else{
|
||||
require_once("./lang/en.php");
|
||||
}
|
||||
function checkmail(){
|
||||
global $OJ_NAME;
|
||||
|
||||
$sql="SELECT count(1) FROM `mail` WHERE
|
||||
new_mail=1 AND `to_user`=?";
|
||||
$result=pdo_query($sql,$_SESSION[$OJ_NAME.'_'.'user_id']);
|
||||
if(!$result) return false;
|
||||
$row=$result[0];
|
||||
$retmsg="<span id=red>(".$row[0].")</span>";
|
||||
|
||||
return $retmsg;
|
||||
}
|
||||
$profile="";
|
||||
if (isset($_SESSION[$OJ_NAME.'_'.'user_id'])){
|
||||
$sid=$_SESSION[$OJ_NAME.'_'.'user_id'];
|
||||
$profile.= "<i class=icon-user></i><a href=./modifypage.php>$MSG_USERINFO</a> <a href='./userinfo.php?user=$sid'><span id=red>$sid</span></a>";
|
||||
$mail=checkmail();
|
||||
if ($mail)
|
||||
$profile.= " <i class=icon-envelope></i><a href=./mail.php>$mail</a>";
|
||||
$profile.=" <a href='./status.php?user_id=$sid'><span id=red>Recent</span></a>";
|
||||
|
||||
$profile.= " <a href='./logout.php' target='_top' >$MSG_LOGOUT</a> ";
|
||||
}else{
|
||||
if ($OJ_WEIBO_AUTH){
|
||||
$profile.= "<a href=./login_weibo.php>$MSG_LOGIN(WEIBO)</a> ";
|
||||
}
|
||||
if ($OJ_RR_AUTH){
|
||||
$profile.= "<a href=./login_renren.php>$MSG_LOGIN(RENREN)</a> ";
|
||||
}
|
||||
if ($OJ_QQ_AUTH){
|
||||
$profile.= "<a href=./login_qq.php>$MSG_LOGIN(QQ)</a> ";
|
||||
}
|
||||
$profile.= "<a href=./loginpage.php>$MSG_LOGIN</a> ";
|
||||
if($OJ_LOGIN_MOD=="hustoj"){
|
||||
$profile.= "<a href=./registerpage.php>$MSG_REGISTER</a> ";
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION[$OJ_NAME.'_'.'administrator'])||isset($_SESSION[$OJ_NAME.'_'.'contest_creator'])||isset($_SESSION[$OJ_NAME.'_'.'problem_editor'])){
|
||||
$profile.= "<a href=./admin/>$MSG_ADMIN</a> ";
|
||||
|
||||
}
|
||||
?>
|
||||
document.write("<?php echo ( $profile);?>");
|
||||
@@ -0,0 +1,40 @@
|
||||
function reinfo(){
|
||||
var pats=new Array();
|
||||
var exps=new Array();
|
||||
pats[0]=/A Not allowed system call.* /;
|
||||
exps[0]="使用了系统禁止的操作系统调用,看看是否越权访问了文件或进程等资源。<br>如果你是管理员,确认答案无误,或者是在增加新的语言支持<a href='https://zhuanlan.zhihu.com/p/24498599'>点击这里。</a>";
|
||||
pats[1]=/Segmentation fault/;
|
||||
exps[1]="段错误,检查是否有数组越界,指针异常,访问到不应该访问的内存区域";
|
||||
pats[2]=/Floating point exception/;
|
||||
exps[2]="浮点错误,检查是否有除以零的情况";
|
||||
pats[3]=/buffer overflow detected/;
|
||||
exps[3]="缓冲区溢出,检查是否有字符串长度超出数组的情况";
|
||||
pats[4]=/Killed/;
|
||||
exps[4]="进程因为内存或时间原因被杀死,检查是否有死循环";
|
||||
pats[5]=/Alarm clock/;
|
||||
exps[5]="进程因为时间原因被杀死,检查是否有死循环,本错误等价于超时TLE";
|
||||
pats[6]=/CALLID:20/;
|
||||
exps[6]="可能存在数组越界,检查题目描述的数据量与所申请数组大小关系";
|
||||
pats[7]=/NoSuchElementException/;
|
||||
exps[7]="可能对输入数据的格式理解有误,输入的数据类型和数量与预期不符";
|
||||
pats[8]=/ArrayIndexOutOfBoundsException/;
|
||||
exps[8]="数组下标越界,请检查循环变量的上下界范围是否合适,对于特殊值可能需要特殊处理";
|
||||
pats[9]=/NoClassDefFoundError: Main/;
|
||||
exps[9]="Java语言的提交,主类public class必须是Main";
|
||||
|
||||
//alert("asdf");
|
||||
var errmsg=$("#errtxt").text();
|
||||
var expmsg="辅助解释:<br><hr>";
|
||||
for(var i=0;i<pats.length;i++){
|
||||
var pat=pats[i];
|
||||
var exp=exps[i];
|
||||
var ret=pat.exec(errmsg);
|
||||
if(ret){
|
||||
expmsg+=ret+":"+exp+"<br><hr />";
|
||||
}
|
||||
}
|
||||
document.getElementById("errexp").innerHTML=expmsg;
|
||||
//alert(expmsg);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
// 接口描述参考文件末尾注释
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/db_info.inc.php");
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/init.php");
|
||||
require_once(dirname(__FILE__)."/curl.php");
|
||||
function do_submit_one($remote_site,$username,$password,$sid){
|
||||
$langMap= array(
|
||||
0 => 7, //C
|
||||
1 => 7, //C++
|
||||
6 => 5 //Python
|
||||
);
|
||||
$problem_id=3001;
|
||||
$language=7;
|
||||
$source="";
|
||||
$sql="select * from solution where result=16 and solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
if(isset($langMap[ $row['language']])) $language=$langMap[ $row['language']];
|
||||
$problem_id=$row['problem_id'];
|
||||
$sql="select remote_oj,remote_id from problem where problem_id=?";
|
||||
$data=pdo_query($sql,$problem_id);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$problem_id=$row['remote_id'];
|
||||
if ($problem_id<=0) {
|
||||
echo "请修复题目的remote_id,否则无法评测。";
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
$sql="select * from source_code where solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$source=$row['source'];
|
||||
if(strlen($source)>20000){
|
||||
$source=substr($source,0,19999);
|
||||
}
|
||||
}
|
||||
$form=array(
|
||||
'user_id' => $username,
|
||||
'password' => $password,
|
||||
'problem_id' => $problem_id,
|
||||
'language' => "$language",
|
||||
'data_id' => "bas",
|
||||
'source' => $source,
|
||||
'submit' => '提交'
|
||||
);
|
||||
$data=curl_post($remote_site."/acx.php",$form);
|
||||
if(str_contains($data,"-2")) {
|
||||
$sid=0;
|
||||
echo "too frequently";
|
||||
}else{
|
||||
$sid=explode("\n",$data);
|
||||
$sid=intval($sid[1]);
|
||||
echo htmlentities($data)."--".$sid;
|
||||
}
|
||||
return $sid;
|
||||
}
|
||||
function do_submit($remote_site,$remote_user,$remote_pass){
|
||||
global $remote_oj;
|
||||
$sql="select solution_id from solution where result=16 and remote_oj=? order by solution_id";
|
||||
$tasks=pdo_query($sql,$remote_oj);
|
||||
foreach($tasks as $task){
|
||||
//echo $task[0]."<br>";
|
||||
$sid=$task[0];
|
||||
$rid=do_submit_one($remote_site,$remote_user,$remote_pass,$sid);
|
||||
if($rid>0){
|
||||
$sql="update solution set remote_oj=?,remote_id=?,result=17 where solution_id=?";
|
||||
pdo_query($sql,$remote_oj,$rid,$sid);
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
usleep(500);
|
||||
}
|
||||
}
|
||||
function getResult($short){
|
||||
//echo "short:$short<br>";
|
||||
$map=array(
|
||||
"AC" => 4, "RE" => 10, "CE" => 11,
|
||||
"WA" => 6, "PE" => 5, "TLE" => 7,
|
||||
"MLE" => 8, "OLE" => 9, "RF" => 10,
|
||||
);
|
||||
return $map[$short];
|
||||
}
|
||||
function do_result_one($remote_site,$username,$password,$sid,$rid){
|
||||
$form=array(
|
||||
'user_id' => $username,
|
||||
'password' => $password,
|
||||
'runid' => $rid,
|
||||
'submit' => '提交'
|
||||
);
|
||||
$html=curl_post($remote_site."/stux.php",$form);
|
||||
$data=explode("\n",$html);
|
||||
if ( intval($data[0])<0) return intval($data[0]);
|
||||
$reinfo="";
|
||||
$ac=0;
|
||||
$result=5;
|
||||
$time=0;
|
||||
$memory=0;
|
||||
if(substr($html,3)=="-1"){
|
||||
pdo_query("update solution set result=16,remote_id=0 where solution_id=?",$sid);
|
||||
echo "previous submission failed , pending another submiting ";
|
||||
return -1;
|
||||
}
|
||||
echo "<br>==".htmlentities($html)."==";
|
||||
if($data[2]=="Waiting"||$data[2]=="Judging"){
|
||||
$sql="update solution set result=17,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$sid);
|
||||
return -1;
|
||||
}else if($data[2]=="Compile Error"){
|
||||
$reinfo=$html;
|
||||
$sql="insert into compileinfo(solution_id,error) values(?,?) on duplicate key update error=? ";
|
||||
pdo_query($sql,$sid,$reinfo,$reinfo);
|
||||
$result=11;
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,0,$time,$memory,$sid);
|
||||
return $result;
|
||||
}else if(str_contains($data[2],"Accepted")){
|
||||
$result=4;
|
||||
}else if(str_contains($data[2],"Unaccepted")){
|
||||
$result=5;
|
||||
}
|
||||
|
||||
|
||||
$summary=explode(":",$data[2]);
|
||||
$detail=explode(",",$summary[1]);
|
||||
$total=count($detail)-1;
|
||||
$i=0;
|
||||
foreach($detail as $line){
|
||||
if ($line=="") continue;
|
||||
$i++;
|
||||
$re=explode("|",$line);
|
||||
echo $re[0]."<br>";
|
||||
if($re[0]=="AC") $ac++;
|
||||
else $result=getResult($re[0]);
|
||||
$m_t=explode("_",$re[1]);
|
||||
$memory+=intval($m_t[0]);
|
||||
$time+=intval($m_t[1]);
|
||||
$reinfo.= $i.": ". $re[0]." ".intval($m_t[0])."kb ".intval($m_t[1])."ms \n";
|
||||
}
|
||||
if($ac==$i) {
|
||||
$result=4;
|
||||
}
|
||||
if($result==4&&$time==0&&$memory==0) return -1;
|
||||
//get user_id
|
||||
$data=pdo_query("select user_id from solution where solution_id=?",$sid);
|
||||
$user_id=$data[0]['user_id'];
|
||||
//update user
|
||||
$sql="UPDATE `users` SET `submit`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? ) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
|
||||
$sql="insert into runtimeinfo(solution_id,error) values(?,?) on duplicate key update error=? ";
|
||||
pdo_query($sql,$sid,$reinfo,$reinfo);
|
||||
if($total>0)
|
||||
$pass_rate=floatval($ac)/$total;
|
||||
else if ($result==4)
|
||||
$pass_rate=1;
|
||||
else $pass_rate=0;
|
||||
//echo "$sid : $pass_rate<br>";
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid);
|
||||
//echo "$sql,$result,$pass_rate,$time,$memory,$sid";
|
||||
if($result==4){
|
||||
$pc=pdo_query("select problem_id,contest_id from solution where solution_id=?",$sid)[0];
|
||||
$pid=$pc[0];
|
||||
$cid=$pc[1];
|
||||
$sql="update problem set accepted=(select count(1) from solution where result=4 and problem_id=?) where problem_id=?";
|
||||
pdo_query($sql,$pid,$pid);
|
||||
if($cid>0){
|
||||
$sql="UPDATE `contest_problem` SET `c_accepted`=(SELECT count(*) FROM `solution` WHERE `problem_id`=? AND `result`=4 and contest_id=?) WHERE `problem_id`=? and contest_id=?";
|
||||
pdo_query($sql,$pid,$cid, $pid,$cid);
|
||||
}
|
||||
$sql="UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? AND `result`=4) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
function do_result($remote_site,$remote_user,$remote_pass){
|
||||
global $remote_oj;
|
||||
$sql="select solution_id,remote_id from solution where remote_oj=? and result=17 order by solution_id ";
|
||||
$data=pdo_query($sql,$remote_oj);
|
||||
foreach($data as $row){
|
||||
$sid=$row['solution_id'];
|
||||
$rid=$row['remote_id'];
|
||||
echo "$sid=>$rid";
|
||||
$ret=do_result_one($remote_site,$remote_user,$remote_pass,$sid,$rid);
|
||||
if($ret<0) {
|
||||
echo "error code:".$ret;
|
||||
break;
|
||||
}else{
|
||||
usleep(150000);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 本组件由一本通系列教材作者董永建老师委托开发,以GPL v2形式开源,参考本组件的代码进行二次开发,请注意遵守开源协议。
|
||||
// 判题API由一本通系列OJ开发维护者文仲友老师提供,使用时请遵守基本的互联网礼仪,若出现访问频率过快,提交恶意程序,可能会禁用相关测试账号,敬请谅解。
|
||||
|
||||
$remote_oj="bas";
|
||||
$remote_site="http://www.ssoier.cn:18087/pubtest/"; //备用地址:"http://117.176.123.236:18087/pubtest/"
|
||||
$remote_user='用户名'; //测试期到2024-8-1结束,一个机构一个账号,请勿外借。
|
||||
$remote_pass='密码'; //账号、密码加群23361372,找群主登记: 学校或机构 email 手机 后可以申请。
|
||||
$remote_cookie=$OJ_DATA.'/'.get_domain($remote_site).'.cookie';
|
||||
$remote_delay=1;
|
||||
if(time()-fileatime($remote_cookie.".sub")>$remote_delay){
|
||||
touch($remote_cookie.".sub");
|
||||
do_submit($remote_site,$remote_user,$remote_pass);
|
||||
}
|
||||
if(isset($_SESSION[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}
|
||||
if(time()-fileatime(__FILE__)>$remote_delay){
|
||||
touch(__FILE__);
|
||||
do_result($remote_site,$remote_user,$remote_pass);
|
||||
}
|
||||
if(isset($_GET['check'])){
|
||||
$remote_delay*=2;
|
||||
echo "<meta http-equiv='refresh' content='$remote_delay'>";
|
||||
echo "$remote_oj<br>";
|
||||
}
|
||||
chmod($remote_cookie,0600);
|
||||
|
||||
/*
|
||||
以下接口描述,由文老师提供,供其他OJ系统开发者参考。
|
||||
-----------------------------------
|
||||
题面前台:
|
||||
http://bas.ssoier.cn:8086/problem_list.php?page=10,10
|
||||
一、程序提交:
|
||||
网址:http://www.ssoier.cn:8087/pubtest/index1.php
|
||||
返回值:
|
||||
-2:访问频繁(低于50Ms访问一次)
|
||||
-1:访问出错
|
||||
0:提交成功(首行为0,第二行为运行结果id,即runid,为一个正整数)
|
||||
二、获取结果:
|
||||
网址:http://www.ssoier.cn:8087/pubtest/index2.php
|
||||
返回值:
|
||||
-2:访问频繁(低于50Ms访问一次)
|
||||
-1:访问出错
|
||||
首行为0:访问成功,第2行是runid,第3行开始有以下情况:
|
||||
(1)Waiting(等待评测)
|
||||
(2)Judging(正在评测)
|
||||
(3)"Compile Error",第4行开始为具体的编译信息
|
||||
(4)Accepted...(通过,具体评测信息)
|
||||
(5)Unaccepted...(未通过,具体评测信息)
|
||||
*/
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/db_info.inc.php");
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/init.php");
|
||||
require_once(dirname(__FILE__)."/curl.php");
|
||||
function is_login($remote_site){
|
||||
$html=curl_get($remote_site.'/control_panel.php');
|
||||
//echo $html;
|
||||
if (str_contains($html,"Sign Out")) return true;
|
||||
else return false;
|
||||
}
|
||||
function show_vcode($remote_site){
|
||||
$url = $remote_site.'/submit';
|
||||
$imgData=curl_get($url);
|
||||
//$pos=mb_strpos($imgData,"lighttpd/1.4.35")+19;
|
||||
//$imgBase64 = base64_encode(mb_substr($imgData,$pos,mb_strlen($imgData)-$pos));
|
||||
$imgBase64 = base64_encode($imgData);
|
||||
return '<img width=200px src="data:image/jpg;base64,'.$imgBase64.'" />';
|
||||
}
|
||||
function do_login($remote_site,$username,$password){
|
||||
$form= array(
|
||||
'username' => $username,
|
||||
'userpass' => $password
|
||||
);
|
||||
//echo "try login...";
|
||||
$data=curl_post_urlencoded($remote_site.'/userloginex.php?action=login&cid=0¬ice=0',$form);
|
||||
//echo htmlentities($remote_site.'/login');
|
||||
if(str_contains($data,"No such user or wrong password.")) return false;
|
||||
else return true;
|
||||
}
|
||||
function do_submit_one($remote_site,$username,$sid){
|
||||
|
||||
$langMap= array(
|
||||
0 => 1, //C
|
||||
1 => 0, //C++
|
||||
2 => 4, //Pascal
|
||||
3 => 5, //Java
|
||||
);
|
||||
$problem_id=1000;
|
||||
$language=1;
|
||||
$source="";
|
||||
|
||||
$sql="select * from solution where result=16 and solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$language=$langMap[ $row['language']];
|
||||
$problem_id=$row['problem_id'];
|
||||
$sql="select remote_oj,remote_id from problem where problem_id=?";
|
||||
$data=pdo_query($sql,$problem_id);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$problem_id=$row['remote_id'];
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
$sql="select * from source_code where solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$source=$row['source'];
|
||||
}
|
||||
while(strlen($source)<50) $source.="\n \n"; // hdu要求至少50
|
||||
$form=array(
|
||||
'problemid' => $problem_id,
|
||||
'language' => $language,
|
||||
'usercode' => ($source),
|
||||
'_usercode' => base64_encode(rawurlencode($source)),
|
||||
'check' => '0'
|
||||
);
|
||||
//var_dump($form);
|
||||
$data=curl_get($remote_site."/status.php?first=&pid=&user=".$username."&lang=0&status=0");
|
||||
echo (getPartByMark($data,"<td height=22px>","</td>"));
|
||||
$vid=intval(getPartByMark($data,"<td height=22px>","</td>"));
|
||||
sleep(5);
|
||||
echo "last id:".$vid;
|
||||
$data=curl_post_urlencoded($remote_site."/submit.php?action=submit",$form);
|
||||
echo ($data);
|
||||
if(str_contains($data,"ERROR")) {
|
||||
$sid=0;
|
||||
}else{
|
||||
$data=curl_get($remote_site."/status.php?first=&pid=&user=".$username."&lang=0&status=0");
|
||||
$sid=intval(getPartByMark($data,"<td height=22px>","</td>"));
|
||||
if($sid==$vid) $sid=-1;
|
||||
}
|
||||
echo "rid:".intval($sid);
|
||||
return $sid;
|
||||
|
||||
}
|
||||
function do_submit($remote_site,$remote_user){
|
||||
global $remote_oj;
|
||||
//$sid=4496;
|
||||
$sql="select solution_id from solution where result=16 and remote_oj=? order by solution_id";
|
||||
$tasks=pdo_query($sql,$remote_oj);
|
||||
foreach($tasks as $task){
|
||||
//echo $task[0]."<br>";
|
||||
$sid=$task[0];
|
||||
$rid=do_submit_one($remote_site,$remote_user,$sid);
|
||||
if($rid>0){
|
||||
$sql="update solution set remote_oj=?,remote_id=?,result=17 where solution_id=?";
|
||||
pdo_query($sql,$remote_oj,$rid,$sid);
|
||||
}else{
|
||||
//40s once
|
||||
break;
|
||||
}
|
||||
usleep(150000);
|
||||
}
|
||||
|
||||
}
|
||||
function getResult($short){
|
||||
//echo "short:$short<br>";
|
||||
$map=array(
|
||||
"Queuing" => 17,
|
||||
"Accepted" => 4,
|
||||
"Runtime Error" => 10,
|
||||
"Runtime Error<br>(ACCESS_VIOLATION)" => 10,
|
||||
"Compilation Error" => 11,
|
||||
"Wrong Answer" => 6,
|
||||
"Presentation Error" => 5,
|
||||
"Time Limit Exceeded" => 7,
|
||||
"Memory Limit Exceeded" => 8,
|
||||
"Output Limit Exceeded" => 9,
|
||||
"System Error" => 10,
|
||||
"Validator Error" => 10,
|
||||
);
|
||||
if(isset($map[$short])){
|
||||
return $map[$short];
|
||||
}else if(mb_strpos($short,"Error")>0){
|
||||
return 10;
|
||||
}else{
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
|
||||
function do_result_one($remote_site,$sid,$rid){
|
||||
$html=curl_get($remote_site."/status.php?first=".$rid);
|
||||
$data=getPartByMark($html,"</center></form></td></tr>","</tr>");
|
||||
//echo $data;
|
||||
$reinfo="";
|
||||
$ac=0;
|
||||
$result=getPartByMark($data,"<font color","/font>");
|
||||
$result=getPartByMark($result,">","<");
|
||||
echo "RawResult:".$result;
|
||||
$result=getResult($result);
|
||||
$time=intval(getPartByMark($data,"</a></td><td>","MS"));
|
||||
$memory=intval(getPartByMark($data,"MS</td><td>","K"));
|
||||
echo "$sid : $result<br>";
|
||||
if($result==11) {
|
||||
$reinfo=curl_get($remote_site."/viewerror.php?rid=".$rid);
|
||||
$reinfo=getPartByMark($reinfo,"<pre>","</pre>");
|
||||
$sql="insert into compileinfo(solution_id,error) values(?,?) on duplicate key update error=? ";
|
||||
pdo_query($sql,$sid,$reinfo,$reinfo);
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,0,$time,$memory,get_domain($remote_site),$sid);
|
||||
return $result;
|
||||
}
|
||||
if($result==4){
|
||||
$pass_rate=1;
|
||||
}else{
|
||||
$pass_rate=0;
|
||||
}
|
||||
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid);
|
||||
echo $sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid;
|
||||
if($result==4){
|
||||
$pc=pdo_query("select problem_id,contest_id from solution where solution_id=?",$sid)[0];
|
||||
$pid=$pc[0];
|
||||
$cid=$pc[1];
|
||||
$sql="update problem set accepted=(select count(1) from solution where result=4 and problem_id=?) where problem_id=?";
|
||||
pdo_query($sql,$pid,$pid);
|
||||
if($cid>0){
|
||||
$sql="UPDATE `contest_problem` SET `c_accepted`=(SELECT count(*) FROM `solution` WHERE `problem_id`=? AND `result`=4 and contest_id=?) WHERE `problem_id`=? and contest_id=?";
|
||||
pdo_query($sql,$pid,$cid, $pid,$cid);
|
||||
}
|
||||
}
|
||||
//get user_id
|
||||
$data=pdo_query("select user_id from solution where solution_id=?",$sid);
|
||||
$user_id=$data[0]['user_id'];
|
||||
//update user
|
||||
$sql="UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? AND `result`=4) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
$sql="UPDATE `users` SET `submit`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? ) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
function do_result($remote_site){
|
||||
global $remote_oj;
|
||||
$sql="select solution_id,remote_id from solution where remote_oj=? and result=17 order by solution_id ";
|
||||
$data=pdo_query($sql,$remote_oj);
|
||||
foreach($data as $row){
|
||||
$sid=$row['solution_id'];
|
||||
$rid=$row['remote_id'];
|
||||
// echo "$sid=>$rid";
|
||||
$ret=do_result_one($remote_site,$sid,$rid);
|
||||
if($ret<0) {
|
||||
echo "error code:".$ret;
|
||||
break;
|
||||
}else{
|
||||
usleep(150000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//---------------------账号配置---------------------------
|
||||
$remote_oj="hdu";
|
||||
$remote_site="https://acm.hdu.edu.cn";
|
||||
$remote_user='hustoj'; //// 请修改为你在acm.hdu.edu.cn注册的机器人账号
|
||||
$remote_pass='freeproblemset'; // 请修改为你注册的机器人账号的密码
|
||||
$remote_cookie=$OJ_DATA.'/'.get_domain($remote_site).'.cookie';
|
||||
$remote_delay=15;
|
||||
//--------------------------------------------------------
|
||||
if(isset($_POST[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}else{
|
||||
if(time()-fileatime($remote_cookie.".sub")>$remote_delay && is_login($remote_site) ){
|
||||
touch($remote_cookie.".sub");
|
||||
do_submit($remote_site,$remote_user);
|
||||
}
|
||||
|
||||
//echo (htmlentities(curl_get($remote_site."/login0.php")));
|
||||
if (!is_login($remote_site)){
|
||||
var_dump(do_login($remote_site,$remote_user,$remote_pass));
|
||||
}else{
|
||||
echo "logined...";
|
||||
}
|
||||
if(isset($_SESSION[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}
|
||||
}
|
||||
if(time()-fileatime(__FILE__)>$remote_delay){
|
||||
touch(__FILE__);
|
||||
do_result($remote_site);
|
||||
}
|
||||
if(isset($_GET['check'])){
|
||||
$remote_delay*=2;
|
||||
echo "<meta http-equiv='refresh' content='$remote_delay'>";
|
||||
echo "$remote_oj<br>";
|
||||
}
|
||||
chmod($remote_cookie,0600);
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
// by Baoshuo <i@baoshuo.ren> ( https://baoshuo.ren )
|
||||
|
||||
// alter table solution modify `remote_id` varchar(32) DEFAULT NULL;
|
||||
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/db_info.inc.php");
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/init.php");
|
||||
require_once(dirname(__FILE__)."/curl.php");
|
||||
function is_login($remote_site){
|
||||
return true;
|
||||
}
|
||||
function show_vcode($remote_site){
|
||||
return '';
|
||||
}
|
||||
function do_login($remote_site,$username,$password){
|
||||
// $form= array(
|
||||
// 'username' => $username,
|
||||
// 'userpass' => $password,
|
||||
// );
|
||||
//echo "try login...";
|
||||
// $data=curl_post_urlencoded($remote_site.'/userloginex.php?action=login&cid=0¬ice=0',$form);
|
||||
//echo htmlentities($remote_site.'/login');
|
||||
// if(str_contains($data,"No such user or wrong password.")) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function rmj_lg_curl_post_urlencoded($url,$form){
|
||||
global $curl,$OJ_DATA,$remote_cookie,$remote_user,$remote_pass;
|
||||
$curl = curl_init($url);
|
||||
//curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=buiebpv91e0cdhpmm6a320j1l7; path=/');
|
||||
//// 设置header
|
||||
// curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, $remote_user . ":" . $remote_pass);
|
||||
curl_setopt($curl, CURLOPT_COOKIEFILE, $remote_cookie); // use saved cookies
|
||||
curl_setopt($curl, CURLOPT_COOKIEJAR, $remote_cookie); // save coockies
|
||||
curl_setopt($curl, CURLOPT_REFERER, "$url");
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, "HUSTOJ RemoteJudge (By baoshuo)");
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, ["X-Requested-With: HUSTOJ RemoteJudge (By baoshuo)"]);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 不要打印内容
|
||||
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||
// 设置 post 方式提交
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
// 设置 post 数据
|
||||
$data="";
|
||||
foreach($form as $key => $value){
|
||||
$data.="$key=".urlencode($value)."&";
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$data = curl_exec($curl);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function rmj_lg_curl_get($url){
|
||||
global $curl,$OJ_DATA,$remote_cookie,$remote_user,$remote_pass;
|
||||
$curl = curl_init($url);
|
||||
//curl_setopt($curl, CURLOPT_COOKIE, 'PHPSESSID=buiebpv91e0cdhpmm6a320j1l7; path=/');
|
||||
//curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, $remote_user . ":" . $remote_pass);
|
||||
curl_setopt($curl, CURLOPT_COOKIEFILE, $remote_cookie); // use saved cookies
|
||||
curl_setopt($curl, CURLOPT_COOKIEJAR, $remote_cookie); // save coockies
|
||||
curl_setopt($curl, CURLOPT_REFERER, "$url");
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, "HUSTOJ RemoteJudge (By baoshuo)");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, ["X-Requested-With: HUSTOJ RemoteJudge (By baoshuo)"]);
|
||||
$data = curl_exec($curl);
|
||||
return $data;
|
||||
}
|
||||
function do_submit_one($remote_site,$username,$sid){
|
||||
global $curl;
|
||||
$langMap= array(
|
||||
0 => 'c/99/gcc', // C
|
||||
1 => 'cxx/noi/202107', // C++
|
||||
2 => 'pascal/fpc', // Pascal
|
||||
3 => 'java/8', // Java
|
||||
);
|
||||
$problem_id=1000;
|
||||
$language=1;
|
||||
$source="";
|
||||
|
||||
$sql="select * from solution where result=16 and solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row = $data[0];
|
||||
$language = $langMap[$row['language']];
|
||||
$problem_id = $row['problem_id'];
|
||||
$sql = "select remote_oj,remote_id from problem where problem_id=?";
|
||||
$data = pdo_query($sql,$problem_id);
|
||||
if (count($data)>0) {
|
||||
$row=$data[0];
|
||||
$problem_id=$row['remote_id'];
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
$sql="select * from source_code where solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$source=$row['source'];
|
||||
}
|
||||
$form=array(
|
||||
'pid' => $problem_id,
|
||||
'lang' => $language,
|
||||
'o2' => '1',
|
||||
'code' => ($source),
|
||||
'trackId' => $sid,
|
||||
);
|
||||
var_dump($form);
|
||||
$data=rmj_lg_curl_post_urlencoded($remote_site."/judge/problem",$form);
|
||||
echo ($data), curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if (curl_errno($curl) || curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
|
||||
$sid=-1;
|
||||
}else{
|
||||
$data=json_decode($data,true);
|
||||
echo ($data);
|
||||
$sid=$data['requestId'];
|
||||
}
|
||||
echo "rid:".($sid);
|
||||
return $sid;
|
||||
}
|
||||
function do_submit($remote_site,$remote_user){
|
||||
global $remote_oj;
|
||||
//$sid=4496;
|
||||
$sql="select solution_id from solution where result=16 and remote_oj=? order by solution_id";
|
||||
$tasks=pdo_query($sql,$remote_oj);
|
||||
foreach($tasks as $task){
|
||||
//echo $task[0]."<br>";
|
||||
$sid=$task[0];
|
||||
$rid=do_submit_one($remote_site,$remote_user,$sid);
|
||||
if($rid>0){
|
||||
$sql="update solution set remote_oj=?,remote_id=?,result=17 where solution_id=?";
|
||||
pdo_query($sql,$remote_oj,$rid,$sid);
|
||||
} elseif ($rid<0) {
|
||||
$sql="update solution set remote_oj=?,remote_id=?,result=10 where solution_id=?";
|
||||
pdo_query($sql,$remote_oj,$rid,$sid);
|
||||
}
|
||||
//40s once
|
||||
break;
|
||||
}
|
||||
}
|
||||
function getResult($short){
|
||||
//echo "short:$short<br>";
|
||||
$map=array(
|
||||
// "Accepted" => 4,
|
||||
12 => 4,
|
||||
// "Runtime Error<br>(ACCESS_VIOLATION)" => 10,
|
||||
7 => 10,
|
||||
// "Compilation Error" => 11,
|
||||
2 => 11,
|
||||
// "Wrong Answer" => 6,
|
||||
6 => 6,
|
||||
14 => 6,
|
||||
// "Presentation Error" => 5,
|
||||
// (none)
|
||||
// "Time Limit Exceeded" => 7,
|
||||
5 => 7,
|
||||
// "Memory Limit Exceeed" => 8,
|
||||
4 => 8,
|
||||
// "Output Limit Exceeded" => 9,
|
||||
3 => 9,
|
||||
// "System Error" => 10,
|
||||
// "Validator Error" => 10,
|
||||
);
|
||||
return $map[$short];
|
||||
}
|
||||
function do_result_one($remote_site,$sid,$rid){
|
||||
global $curl;
|
||||
$html=rmj_lg_curl_get($remote_site."/judge/result?id=".$rid);
|
||||
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 204) return 17; // judging
|
||||
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,10,0,0,0,get_domain($remote_site),$sid);
|
||||
|
||||
return 10;
|
||||
}
|
||||
$data=json_decode($html, true);
|
||||
//echo $data;
|
||||
$reinfo="";
|
||||
$ac=0;
|
||||
if (!isset($data['data']) || !isset($data['data']['judge']) || !isset($data['data']['judge']['status'])) return 17;
|
||||
$result=$data['data']['judge']['status'];
|
||||
echo "RawResult:".$result;
|
||||
$result=getResult($result);
|
||||
$time=$data['data']['judge']['time'];
|
||||
$memory=$data['data']['judge']['memory'];
|
||||
echo "$sid : $result<br>";
|
||||
if($result==11) {
|
||||
$reinfo=$data['data']['compile']['message'];
|
||||
$sql="insert into compileinfo(solution_id,error) values(?,?) on duplicate key update error=? ";
|
||||
pdo_query($sql,$sid,$reinfo,$reinfo);
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,0,$time,$memory,get_domain($remote_site),$sid);
|
||||
return $result;
|
||||
}
|
||||
if($result==4){
|
||||
$pass_rate=1;
|
||||
}else $pass_rate=0;
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid);
|
||||
// echo $sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid;
|
||||
//get user_id
|
||||
$data=pdo_query("select user_id from solution where solution_id=?",$sid);
|
||||
$user_id=$data[0]['user_id'];
|
||||
if($result==4){
|
||||
$pid=pdo_query("select problem_id from solution where solution_id=?",$sid)[0][0];
|
||||
$sql="update problem set accepted=(select count(1) from solution where result=4 and problem_id=?) where problem_id=?";
|
||||
pdo_query($sql,$pid,$pid);
|
||||
$sql="UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? AND `result`=4) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
}
|
||||
//update user
|
||||
$sql="UPDATE `users` SET `submit`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? ) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
function do_result($remote_site){
|
||||
global $remote_oj;
|
||||
$sql="select solution_id,remote_id from solution where remote_oj=? and result=17 order by solution_id ";
|
||||
$data=pdo_query($sql,$remote_oj);
|
||||
foreach($data as $row){
|
||||
$sid=$row['solution_id'];
|
||||
$rid=$row['remote_id'];
|
||||
// echo "$sid=>$rid";
|
||||
do_result_one($remote_site,$sid,$rid);
|
||||
}
|
||||
}
|
||||
//---------------------账号配置---------------------------
|
||||
$remote_oj="luogu";
|
||||
$remote_site="https://open-v1.lgapi.cn";
|
||||
$remote_user='baoshuo'; // 请修改为你在洛谷开放平台获取的账号
|
||||
$remote_pass='passw0rd'; // 请修改为你在洛谷开放平台获取的密码
|
||||
$remote_cookie=$OJ_DATA.'/'.get_domain($remote_site).'.cookie';
|
||||
$remote_delay=5;
|
||||
//--------------------------------------------------------
|
||||
if(isset($_POST[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}else{
|
||||
if(time()-fileatime($remote_cookie.".sub")>$remote_delay){
|
||||
touch($remote_cookie.".sub");
|
||||
do_submit($remote_site,$remote_user);
|
||||
}
|
||||
|
||||
//echo (htmlentities(curl_get($remote_site."/login0.php")));
|
||||
if (!is_login($remote_site)){
|
||||
var_dump(do_login($remote_site,$remote_user,$remote_pass));
|
||||
}else{
|
||||
echo "logined...";
|
||||
}
|
||||
if(isset($_SESSION[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}
|
||||
}
|
||||
if(time()-fileatime(__FILE__)>$remote_delay){
|
||||
touch(__FILE__);
|
||||
do_result($remote_site);
|
||||
}
|
||||
if(isset($_GET['check'])){
|
||||
// $remote_delay*=2;
|
||||
echo "<meta http-equiv='refresh' content='$remote_delay'>";
|
||||
echo "$remote_oj<br>";
|
||||
}
|
||||
chmod($remote_cookie,0600);
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/db_info.inc.php");
|
||||
require_once(realpath(dirname(__FILE__)."/..")."/include/init.php");
|
||||
require_once(dirname(__FILE__)."/curl.php");
|
||||
|
||||
function is_login($remote_site){
|
||||
$html=curl_get($remote_site.'/login');
|
||||
//echo $html;
|
||||
if (str_contains($html,">Log Out</a>")) return true;
|
||||
else return false;
|
||||
}
|
||||
function show_vcode($remote_site){
|
||||
$url = $remote_site.'/submit';
|
||||
$imgData=curl_get($url);
|
||||
//$pos=mb_strpos($imgData,"lighttpd/1.4.35")+19;
|
||||
//$imgBase64 = base64_encode(mb_substr($imgData,$pos,mb_strlen($imgData)-$pos));
|
||||
$imgBase64 = base64_encode($imgData);
|
||||
return '<img width=200px src="data:image/jpg;base64,'.$imgBase64.'" />';
|
||||
}
|
||||
function do_login($remote_site,$username,$password){
|
||||
$form= array(
|
||||
'user_id1' => $username,
|
||||
'password1' => $password,
|
||||
'B1' => 'login',
|
||||
'url' => '/'
|
||||
);
|
||||
//echo "try login...";
|
||||
$data=curl_post_urlencoded($remote_site.'/login',$form);
|
||||
//echo htmlentities($remote_site.'/login');
|
||||
if(str_contains($data,"Password")) return false;
|
||||
else return true;
|
||||
}
|
||||
function do_submit_one($remote_site,$username,$sid){
|
||||
|
||||
$langMap= array(
|
||||
0 => 1, //C
|
||||
1 => 0, //C++
|
||||
3 => 2, //Java
|
||||
2 => 3, //Pascal
|
||||
);
|
||||
$problem_id=1000;
|
||||
$language=1;
|
||||
$source="";
|
||||
|
||||
$sql="select * from solution where result=16 and solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$language=$langMap[ $row['language']];
|
||||
$problem_id=$row['problem_id'];
|
||||
$sql="select remote_oj,remote_id from problem where problem_id=?";
|
||||
$data=pdo_query($sql,$problem_id);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$problem_id=$row['remote_id'];
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
$sql="select * from source_code where solution_id=?";
|
||||
$data=pdo_query($sql,$sid);
|
||||
if(count($data)>0){
|
||||
$row=$data[0];
|
||||
$source=$row['source'];
|
||||
}
|
||||
$form=array(
|
||||
'problem_id' => $problem_id,
|
||||
'language' => $language,
|
||||
'source' => ($source),
|
||||
'encoded' => '0'
|
||||
);
|
||||
//var_dump($form);
|
||||
$data=curl_get($remote_site."/status?user_id=".$username);
|
||||
$vid=intval(getPartByMark($data,"Submit Time</td></tr>\n<tr align=center><td>","</td><td><a href=userstatus"));
|
||||
sleep(5);
|
||||
$data=curl_post_urlencoded($remote_site."/submit",$form);
|
||||
if(str_contains($data,"Error Occurred")) {
|
||||
$sid=0;
|
||||
}else{
|
||||
$data=curl_get($remote_site."/status?user_id=".$username);
|
||||
$sid=intval(getPartByMark($data,"Submit Time</td></tr>\n<tr align=center><td>","</td><td><a href=userstatus"));
|
||||
if($vid==$sid) $sid=0;
|
||||
}
|
||||
echo intval($sid);
|
||||
return $sid;
|
||||
}
|
||||
function do_submit($remote_site,$remote_user){
|
||||
global $remote_oj;
|
||||
//$sid=4496;
|
||||
$sql="select solution_id from solution where result=16 and remote_oj=? order by solution_id";
|
||||
$tasks=pdo_query($sql,$remote_oj);
|
||||
foreach($tasks as $task){
|
||||
//echo $task[0]."<br>";
|
||||
$sid=$task[0];
|
||||
$rid=do_submit_one($remote_site,$remote_user,$sid);
|
||||
if($rid>0){
|
||||
$sql="update solution set remote_oj=?,remote_id=?,result=17 where solution_id=?";
|
||||
pdo_query($sql,$remote_oj,$rid,$sid);
|
||||
}else{
|
||||
//40s once
|
||||
break;
|
||||
}
|
||||
usleep(150000);
|
||||
}
|
||||
|
||||
}
|
||||
function getResult($short){
|
||||
//echo "short:$short<br>";
|
||||
$map=array(
|
||||
"Accepted" => 4,
|
||||
"Runtime Error" => 10,
|
||||
"Compile Error" => 11,
|
||||
"Wrong Answer" => 6,
|
||||
"Presentation Error" => 5,
|
||||
"Time Limit Exceeded" => 7,
|
||||
"Memory Limit Exceeded" => 8,
|
||||
"Output Limit Exceeded" => 9,
|
||||
"System Error" => 10,
|
||||
"Validator Error" => 10,
|
||||
"Compiling" => 17,
|
||||
|
||||
);
|
||||
if(isset($map[$short])){
|
||||
return $map[$short];
|
||||
}else if(mb_strpos($short,"Error")>0){
|
||||
return 10;
|
||||
}else{
|
||||
return 17;
|
||||
}
|
||||
|
||||
}
|
||||
function do_result_one($remote_site,$sid,$rid){
|
||||
$html=curl_get($remote_site."/showsource?solution_id=".$rid);
|
||||
$data=getPartByMark($html,"User","Source Code");
|
||||
$reinfo="";
|
||||
$ac=0;
|
||||
$result=getPartByMark($data,"Result:</b>","</td>");
|
||||
$result=getPartByMark($result,"<font","/font>");
|
||||
$result=getPartByMark($result,">","<");
|
||||
$result=getResult($result);
|
||||
$time=intval(getPartByMark($data,"<b>Time:</b>","MS"));
|
||||
$memory=intval(getPartByMark($data,"<b>Memory:</b>","K"));
|
||||
echo "$sid : $result<br>";
|
||||
if($result==11) {
|
||||
$reinfo=curl_get($remote_site."/showcompileinfo?solution_id=".$rid);
|
||||
$reinfo=getPartByMark($reinfo,"<pre>","</pre>");
|
||||
$sql="insert into compileinfo(solution_id,error) values(?,?) on duplicate key update error=? ";
|
||||
pdo_query($sql,$sid,$reinfo,$reinfo);
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,0,$time,$memory,$sid);
|
||||
return $result;
|
||||
}
|
||||
if($result==4) $pass_rate=1;else $pass_rate=0;
|
||||
$sql="update solution set result=?,pass_rate=?,time=?,memory=?,judger=?,judgetime=now() where solution_id=?";
|
||||
pdo_query($sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid);
|
||||
//echo $sql,$result,$pass_rate,$time,$memory,get_domain($remote_site),$sid;
|
||||
//get user_id
|
||||
$data=pdo_query("select user_id from solution where solution_id=?",$sid);
|
||||
$user_id=$data[0]['user_id'];
|
||||
if($result==4){
|
||||
$pc=pdo_query("select problem_id,contest_id from solution where solution_id=?",$sid)[0];
|
||||
$pid=$pc[0];
|
||||
$cid=$pc[1];
|
||||
$sql="update problem set accepted=(select count(1) from solution where result=4 and problem_id=?) where problem_id=?";
|
||||
pdo_query($sql,$pid,$pid);
|
||||
if($cid>0){
|
||||
$sql="UPDATE `contest_problem` SET `c_accepted`=(SELECT count(*) FROM `solution` WHERE `problem_id`=? AND `result`=4 and contest_id=?) WHERE `problem_id`=? and contest_id=?";
|
||||
pdo_query($sql,$pid,$cid, $pid,$cid);
|
||||
}
|
||||
$sql="UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? AND `result`=4) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
}
|
||||
$sql="UPDATE `users` SET `submit`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? ) WHERE `user_id`=?";
|
||||
pdo_query($sql,$user_id,$user_id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
function do_result($remote_site){
|
||||
global $remote_oj;
|
||||
$sql="select solution_id,remote_id from solution where remote_oj=? and result=17 order by solution_id ";
|
||||
$data=pdo_query($sql,$remote_oj);
|
||||
foreach($data as $row){
|
||||
$sid=$row['solution_id'];
|
||||
$rid=$row['remote_id'];
|
||||
// echo "$sid=>$rid";
|
||||
$ret=do_result_one($remote_site,$sid,$rid);
|
||||
if($ret<0) {
|
||||
echo "error code:".$ret;
|
||||
break;
|
||||
}else{
|
||||
usleep(150000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$remote_oj="pku";
|
||||
$remote_site="http://poj.org";
|
||||
$remote_user='hustoj'; // 请修改为你在poj.org注册的机器人账号
|
||||
$remote_pass='freeproblemset'; // 请修改为你在poj.org注册的机器人账号的密码
|
||||
$remote_cookie=$OJ_DATA.'/'.get_domain($remote_site).'.cookie';
|
||||
$remote_delay=15;
|
||||
if(isset($_POST[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}else{
|
||||
if(time()-fileatime($remote_cookie.".sub")>$remote_delay && is_login($remote_site) ){
|
||||
touch($remote_cookie.".sub");
|
||||
do_submit($remote_site,$remote_user);
|
||||
}
|
||||
|
||||
if (!is_login($remote_site)){
|
||||
var_dump(do_login($remote_site,$remote_user,$remote_pass));
|
||||
}else if(isset($_SESSION[$OJ_NAME.'_refer'])){
|
||||
header("location:".$_SESSION[$OJ_NAME.'_refer']);
|
||||
unset($_SESSION[$OJ_NAME.'_refer']);
|
||||
}
|
||||
}
|
||||
if(time()-fileatime(__FILE__)>$remote_delay){
|
||||
touch(__FILE__);
|
||||
do_result($remote_site);
|
||||
}
|
||||
if(isset($_GET['check'])){
|
||||
$remote_delay*=2;
|
||||
echo "<meta http-equiv='refresh' content='$remote_delay'>";
|
||||
echo "$remote_oj<br>";
|
||||
}
|
||||
chmod($remote_cookie,0600);
|
||||
@@ -0,0 +1 @@
|
||||
<?php $_SESSION[$OJ_NAME.'_'.'getkey']=strtoupper(substr(MD5($_SESSION[$OJ_NAME.'_'.'user_id'].rand(0,9999999)),0,10));?>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php $_SESSION[$OJ_NAME.'_'.'postkey']=strtoupper(substr(MD5($_SESSION[$OJ_NAME.'_'.'user_id'].rand(0,9999999)),0,10));?>
|
||||
<input type=hidden name="postkey" value="<?php echo $_SESSION[$OJ_NAME.'_'.'postkey']?>">
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php if(isset($OJ_LANG)){
|
||||
require_once(dirname(__FILE__)."/../lang/$OJ_LANG.php");
|
||||
if(file_exists("./faqs.$OJ_LANG.php")){
|
||||
$OJ_FAQ_LINK="./faqs.$OJ_LANG.php";
|
||||
}
|
||||
}else{
|
||||
require_once("./lang/en.php");
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
||||
//table sort from http://dennis-zane.javaeye.com/blog/58864
|
||||
//类型转换器,将列的字段类型转换为可以排序的类型:String,int,float
|
||||
function convert(sValue, sDataType) {
|
||||
switch(sDataType) {
|
||||
case "int":
|
||||
return parseInt(sValue);
|
||||
case "float":
|
||||
return parseFloat(sValue);
|
||||
case "date":
|
||||
return new Date(Date.parse(sValue));
|
||||
default:
|
||||
return sValue.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//排序函数产生器,iCol表示列索引,sDataType表示该列的数据类型
|
||||
function generateCompareTRs(iCol, sDataType) {
|
||||
|
||||
return function compareTRs(oTR1, oTR2) {
|
||||
var td1=oTR1.cells[iCol].firstChild;
|
||||
var td2=oTR2.cells[iCol].firstChild;
|
||||
|
||||
td1=td1.innerText || td1.textContent;
|
||||
td2=td2.innerText || td2.textContent;
|
||||
|
||||
|
||||
var vValue1 = convert(td1, sDataType);
|
||||
var vValue2 = convert(td2, sDataType);
|
||||
|
||||
if (vValue1 < vValue2) {
|
||||
return -1;
|
||||
} else if (vValue1 > vValue2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//排序方法
|
||||
function sortTable(sTableID, iCol, sDataType) {
|
||||
var oTable = document.getElementById(sTableID);
|
||||
var oTBody = oTable.tBodies[0];
|
||||
var colDataRows = oTBody.rows;
|
||||
var aTRs = new Array;
|
||||
|
||||
//将所有列放入数组
|
||||
for (var i=0; i < colDataRows.length; i++) {
|
||||
aTRs[i] = colDataRows[i];
|
||||
}
|
||||
|
||||
//判断最后一次排序的列是否与现在要进行排序的列相同,是的话,直接使用reverse()逆序
|
||||
if (oTable.sortCol == iCol) {
|
||||
aTRs.reverse();
|
||||
} else {
|
||||
//使用数组的sort方法,传进排序函数
|
||||
aTRs.sort(generateCompareTRs(iCol, sDataType));
|
||||
}
|
||||
|
||||
var oFragment = document.createDocumentFragment();
|
||||
for (var i=0; i < aTRs.length; i++) {
|
||||
if(i%2==0)
|
||||
aTRs[i].className='evenrow';
|
||||
else
|
||||
aTRs[i].className='oddrow';
|
||||
oFragment.appendChild(aTRs[i]);
|
||||
}
|
||||
|
||||
oTBody.appendChild(oFragment);
|
||||
//记录最后一次排序的列索引
|
||||
oTable.sortCol = iCol;
|
||||
}
|
||||
@@ -0,0 +1,708 @@
|
||||
function _dictInit(){
|
||||
if(_dict_init==1){
|
||||
_dictUpdateStatus();
|
||||
return true;
|
||||
}
|
||||
if(! document || ! document.body || !document.body.firstChild){
|
||||
setTimeout("_dictInit()",800);
|
||||
return true;
|
||||
}
|
||||
var agt = navigator.userAgent.toLowerCase();
|
||||
var b='border:none;padding:0px;margin:0px;';
|
||||
var f='font-weight:normal;font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;';
|
||||
_dict_is_ie = (agt.indexOf("msie")!=-1 && document.all);
|
||||
_dict_opera = (agt.indexOf('opera')!=-1 && window.opera && document.getElementById);
|
||||
var h = '<table width="300" border="0" cellspacing="0" cellpadding="0" ';
|
||||
h += 'style="border-top:1px solid #7E98D6;border-left:1px solid #7E98D6;';
|
||||
h += 'border-right:1px solid #7E98D6;border-bottom:1px solid #7E98D6;';
|
||||
h += '"><tr><td width="100%" style="'+b+'">';
|
||||
h += '<div style="width:300px;height:20px;cursor:move;background-color:#C8DAF3;display:inline;'+b+'" onmouseover="_dict_onmove=1;" onmouseout="_dict_onmove=0;">' ;
|
||||
h += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" width="60%" height="20" style="background-color:#C8DAF3;color:#1A9100;font-size:14px;line-height:20px;border:none;padding:0 3px;margin:0px;'+f+'" id="_dict_title" name="_dict_title">';
|
||||
h += '划词翻译 - Dict.CN';
|
||||
h += '</td>';
|
||||
h += '<td align="right" height="20" style="width:35%;text-align:right;background-color:#C8DAF3;line-height:20px;border:none;padding:0 3px;margin:0px;'+f+'" valign="middle">';
|
||||
h += '<a href="javascript:_dictClose()" title="关闭" target="_self" style="'+b+f+'">';
|
||||
h += '<img src="'+_dict_host+'img/close.gif" border="0" style="border:none;display:inline;'+b+'" align="absmiddle">';
|
||||
h += '</a>';
|
||||
h += '</td></tr></table>';
|
||||
h += '</div>';
|
||||
|
||||
h += '<table border="0" cellspacing="4" cellpadding="3" width="100%" align="center" onmouseover="_dict_onlayer=1;" onmouseout="_dict_onlayer=0;" style="'+b+'">';
|
||||
h += '<tr><td style="'+b+'"><fieldset color="#00c0ff" style="padding:0 2px;margin:0px;'+f+'">';
|
||||
h += '<legend align="center" style="padding:0px;margin:0px;"></legend>';
|
||||
h += '<table border="0" cellspacing="0" cellpadding="0" align="center" style="'+b+'">';
|
||||
h += '<tr><td width="100%" height="120" style="'+b+'" id="_dictContent" name="_dictContent">';
|
||||
h += '<iframe id="_dictFrame" name="_dictFrame" HEIGHT="120" src="about:blank" FRAMEBORDER="0" width="100%"></iframe>';
|
||||
h += '</td></tr><tr align="center"><td width="100%" height="18" style="color:#999999;font-size:10px;line-height:18px;'+b+f+'" valign="bottom">';
|
||||
h += '©2003-2010 ';
|
||||
h += '</td></tr></table></fieldset></td></tr></table>';
|
||||
h += '</td></tr></table>';
|
||||
try{
|
||||
var els=document.getElementsByTagName("*");
|
||||
var zmax=97;
|
||||
for(var i=0;i<els.length;i++){
|
||||
if(zmax< els[i].style.zIndex) zmax=els[i].style.zIndex
|
||||
}
|
||||
var el = document.createElement('div');
|
||||
el.id='_dict_layer';
|
||||
if(typeof el.style == "undefined") return;
|
||||
el.style.position='absolute';
|
||||
el.style.display='none';
|
||||
el.style.padding='0px';
|
||||
el.style.margin='0px';
|
||||
el.style.width='300px';
|
||||
el.style.zIndex=zmax+1;
|
||||
el.style.backgroundColor='#FFF';
|
||||
el.style.filter='Alpha(Opacity=96)';
|
||||
|
||||
document.body.insertBefore(el,document.body.firstChild);
|
||||
_dictSet(el, h);
|
||||
|
||||
|
||||
el = document.createElement('div');
|
||||
el.id='_dict_status';
|
||||
if(typeof el.style == "undefined") return;
|
||||
el.style.position='absolute';
|
||||
el.style.backgroundColor='#e7f7f7';
|
||||
el.style.padding='1px';
|
||||
el.style.margin='0px';
|
||||
el.style.filter='Alpha(Opacity=80)';
|
||||
el.style.fontSize='14px';
|
||||
el.style.left = '3px';
|
||||
el.style.top = '3px';
|
||||
el.style.width='138px';
|
||||
el.style.height='22px';
|
||||
el.style.textAlign='center';
|
||||
el.style.zIndex=zmax+2;
|
||||
el.style.border = '1px solid #7E98D6';
|
||||
el.style.display='none';
|
||||
document.body.insertBefore(el,document.body.firstChild);
|
||||
}catch(x){
|
||||
_dict_init = 2;
|
||||
return;
|
||||
}
|
||||
_dictClose();
|
||||
|
||||
|
||||
if(document.addEventListener){
|
||||
document.addEventListener("mousemove", _dictMove, true);
|
||||
document.addEventListener("dblclick", _dictQuery, true);
|
||||
document.addEventListener("mouseup", _dictQuery, true);
|
||||
document.addEventListener("mousedown", _dictCheck, true);
|
||||
document.addEventListener("keydown", _dictKey, true);
|
||||
document.addEventListener("load", _dictUpdateStatus, true);
|
||||
}else if (document.attachEvent) {
|
||||
document.attachEvent("onmousemove", _dictMove);
|
||||
document.attachEvent("ondblclick", _dictQuery);
|
||||
document.attachEvent("onmouseup", _dictQuery);
|
||||
document.attachEvent("onmousedown", _dictCheck);
|
||||
document.attachEvent("onkeydown", _dictKey);
|
||||
document.attachEvent("onload", _dictUpdateStatus);
|
||||
}else{
|
||||
var oldmove = (document.onmousemove) ? document.onmousemove : function () {};
|
||||
document.onmousemove = function () {oldmove(); _dictMove();};
|
||||
var olddblclick = (document.ondblclick) ? document.ondblclick : function () {};
|
||||
document.ondblclick = function () {olddblclick(); _dictQuery();};
|
||||
var oldmouseup = (document.onmouseup) ? document.onmouseup : function () {};
|
||||
document.onmouseup = function () {oldmouseup(); _dictQuery();};
|
||||
var oldmousedown = (document.onmousedown) ? document.onmousedown : function () {};
|
||||
document.onmousedown = function () {oldmousedown(); _dictCheck();};
|
||||
var oldkeydown = (document.onkeydown) ? document.onkeydown : function () {};
|
||||
document.onkeydown = function () {oldkeydown(); _dictKey();};
|
||||
var oldload = (document.onload) ? document.onload : function () {};
|
||||
document.onload = function () {oldload(); _dictUpdateStatus();};
|
||||
}
|
||||
_dict_oldselectstart = (document.onselectstart) ? document.onselectstart : function () {};
|
||||
document.onselectstart = function () {if(_dict_moving == 2) return false; else return true;};
|
||||
_dict_onselect = 1;
|
||||
var img = new Image();
|
||||
img.src = _dict_host+"imgs/loading.gif";
|
||||
_dict_layer = _dict_getObj('_dict_layer');
|
||||
_dict_status = _dict_getObj('_dict_status');
|
||||
_dict_iframe = _dict_getObj('_dictFrame');
|
||||
_dict_mode = 1;
|
||||
if( _dict_GetCookie("dicthuaci") == "off"){
|
||||
_dict_enable = false;
|
||||
}
|
||||
setTimeout("_dictUpdateStatus()",1000);
|
||||
_dictUpdateStatus();
|
||||
_dict_init = 1;
|
||||
}
|
||||
function _dict_SetCookie(name,value,day) {
|
||||
try{
|
||||
var domain = document.domain + ":";
|
||||
domain = domain.toLowerCase();
|
||||
var arydomain = new Array(".com",".com.cn",".net",".net.cn",".cc",".org",".org.cn",".gov.cn",".info",".biz",".tv",".name");
|
||||
var tmpdomain = "";
|
||||
var strdomain = "";
|
||||
for(var i=0;i<arydomain.length; i++){
|
||||
tmpdomain = arydomain[i]+":";
|
||||
if(domain.indexOf(tmpdomain)!=-1){
|
||||
domain = domain.replace(tmpdomain,"");
|
||||
domain = domain.substring(domain.lastIndexOf(".")+1,domain.length);
|
||||
domain = domain + tmpdomain;
|
||||
strdomain = "; domain=." + domain.replace(":","");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(domain.indexOf("dict.cn:")!=-1){
|
||||
strdomain = "; domain=.dict.cn";
|
||||
}
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime()+(day*24*60*60*1000));
|
||||
var expires = "; expires="+date.toGMTString();
|
||||
document.cookie = name+"="+value+expires+"; path=/"+strdomain;
|
||||
}catch(x){;}
|
||||
}
|
||||
function _dict_GetCookie(name)
|
||||
{
|
||||
var cookie=String(document.cookie);
|
||||
var pos=cookie.indexOf(name+"=");
|
||||
if(pos!=-1){
|
||||
var end=cookie.indexOf("; ",pos);
|
||||
return cookie.substring(pos+name.length+1,end==-1?cookie.length:end);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function _dict_getObj(id) {
|
||||
if (document.getElementById) return document.getElementById(id);
|
||||
else if (document.all) return document.all[id];
|
||||
else if (document.layers) return document.layers[id];
|
||||
else {return null;}
|
||||
}
|
||||
var _dict_hexchars = "0123456789ABCDEF";
|
||||
function _dict_toHex(n) {
|
||||
return _dict_hexchars.charAt(n>>4)+_dict_hexchars.charAt(n & 0xF);
|
||||
}
|
||||
|
||||
var _dict_okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
function _dict_toutf8(wide) {
|
||||
var c, s;
|
||||
var enc = "";
|
||||
var i = 0;
|
||||
while(i<wide.length) {
|
||||
c= wide.charCodeAt(i++);
|
||||
// handle UTF-16 surrogates
|
||||
|
||||
if (c>=0xDC00 && c<0xE000) continue;
|
||||
if (c>=0xD800 && c<0xDC00) {
|
||||
if (i>=wide.length) continue;
|
||||
s= wide.charCodeAt(i++);
|
||||
if (s<0xDC00 || c>=0xDE00) continue;
|
||||
c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
|
||||
}
|
||||
// output value
|
||||
if (c<0x80) enc += String.fromCharCode(c);
|
||||
else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
|
||||
else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
|
||||
else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
|
||||
}
|
||||
return enc;
|
||||
}
|
||||
function _dict_encodeURIComponentNew(s) {
|
||||
s = _dict_toutf8(s);
|
||||
var c;
|
||||
var enc = "";
|
||||
for (var i= 0; i<s.length; i++) {
|
||||
if (_dict_okURIchars.indexOf(s.charAt(i))==-1)
|
||||
enc += "%"+_dict_toHex(s.charCodeAt(i));
|
||||
else
|
||||
enc += s.charAt(i);
|
||||
}
|
||||
return enc;
|
||||
}
|
||||
|
||||
function _dict_URL(w)
|
||||
{
|
||||
var s = "";
|
||||
if (typeof encodeURIComponent == "function")
|
||||
{
|
||||
s = encodeURIComponent(w);
|
||||
}
|
||||
else
|
||||
{
|
||||
s = _dict_encodeURIComponentNew(w);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
function _dictSet(el, htmlCode) {
|
||||
if(!el || 'undefined' == typeof el) return;
|
||||
var ua = navigator.userAgent.toLowerCase();
|
||||
if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
|
||||
el.innerHTML = '<div style="display:none">for IE</div>' + htmlCode;
|
||||
el.removeChild(el.firstChild);
|
||||
}
|
||||
else {
|
||||
var el_next = el.nextSibling;
|
||||
var el_parent = el.parentNode;
|
||||
el_parent.removeChild(el);
|
||||
el.innerHTML = htmlCode;
|
||||
if (el_next) {
|
||||
el_parent.insertBefore(el, el_next)
|
||||
} else {
|
||||
el_parent.appendChild(el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _dictGetSel()
|
||||
{
|
||||
if (window.getSelection) return window.getSelection();
|
||||
else if (document.getSelection) return document.getSelection();
|
||||
else if (document.selection) return document.selection.createRange().text;
|
||||
else return '';
|
||||
}
|
||||
|
||||
function _dictGetPos(event){
|
||||
try{
|
||||
if(_dict_opera){
|
||||
_dict_x = event.clientX + window.pageXOffset;;
|
||||
_dict_y = event.clientY + window.pageYOffset;;
|
||||
}else if (_dict_is_ie) {
|
||||
_dict_x = window.event.clientX + document.documentElement.scrollLeft
|
||||
+ document.body.scrollLeft;
|
||||
_dict_y = window.event.clientY + document.documentElement.scrollTop
|
||||
+ document.body.scrollTop;
|
||||
}else {
|
||||
_dict_x = event.clientX + window.scrollX;
|
||||
_dict_y = event.clientY + window.scrollY;
|
||||
}
|
||||
}catch(x){}
|
||||
if(!_dict_isInteger(_dict_x)) _dict_x = 200;
|
||||
if(!_dict_isInteger(_dict_y)) _dict_y = 200;
|
||||
}
|
||||
|
||||
function _dictKey(e){
|
||||
_dictClose();
|
||||
return true;
|
||||
}
|
||||
function _dictCheck(e) {
|
||||
if(window.Event){
|
||||
if(e.which == 2 || e.which == 3) {_dictClose(); return true;}
|
||||
}else{
|
||||
if(event.button == 2 || event.button == 3) {_dictClose(); return true;}
|
||||
}
|
||||
var cx = 0;
|
||||
var cy = 0;
|
||||
var obj = _dict_layer;
|
||||
if (obj.offsetParent){
|
||||
while (obj.offsetParent){
|
||||
cx += obj.offsetLeft;
|
||||
cy += obj.offsetTop;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
}else if (obj.x){
|
||||
cx += obj.x;
|
||||
cy += obj.y;
|
||||
}
|
||||
|
||||
_dictGetPos(e);
|
||||
if(_dict_moving>0){
|
||||
_dict_startx = _dict_x;
|
||||
_dict_starty = _dict_y;
|
||||
if(_dict_onmove == 1){
|
||||
_dict_moving = 2;
|
||||
}else if(_dict_x < cx || _dict_x > (cx + 300) || _dict_y < cy || (!_dict_onlayer && _dict_y > (cy + 100) ) ){
|
||||
_dictClose();
|
||||
}else{
|
||||
_dict_moving = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function _dictQuery(e) {
|
||||
if(window.Event){
|
||||
if(e.which == 2 || e.which == 3) {_dictClose(); return true;}
|
||||
}else{
|
||||
if(event.button == 2 || event.button == 3) {_dictClose(); return true;}
|
||||
}
|
||||
if(_dict_moving == 1){
|
||||
if (_dict_is_ie) {
|
||||
window.event.cancelBubble = true;
|
||||
window.event.returnValue = false;
|
||||
}else{
|
||||
e.preventDefault();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_dictGetPos(e);
|
||||
if(_dict_moving == 2) {
|
||||
_dict_moving = 1;
|
||||
_dict_cx = _dict_nx;
|
||||
_dict_cy = _dict_ny;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_dict_enable) return true;
|
||||
|
||||
var word = _dictGetSel();
|
||||
if(document.f && document.f.q && document.f.q.value && word == document.f.q.value) return true;
|
||||
word=""+word;
|
||||
word=word.replace(/^\s*|\s*$/g,"");
|
||||
if(word == "" || word.length > 76 || _dict_old_word == word) return true;
|
||||
|
||||
_dictShow(word);
|
||||
|
||||
}
|
||||
|
||||
function _dictDisplay(){
|
||||
var dx=262;
|
||||
var dy=264;
|
||||
_dict_startx = _dict_x;
|
||||
_dict_starty = _dict_y;
|
||||
_dict_y += 8;
|
||||
_dict_x += 16;
|
||||
if(_dict_opera){
|
||||
_dict_x -= 4;
|
||||
}else if(_dict_is_ie){
|
||||
if (document.documentElement.offsetHeight && document.body.scrollTop+document.documentElement.scrollTop+document.documentElement.offsetHeight - _dict_y < dy){
|
||||
_dict_y = document.body.scrollTop+document.documentElement.scrollTop + document.documentElement.offsetHeight - dy;
|
||||
_dict_x += 14;
|
||||
}
|
||||
if (document.documentElement.offsetWidth && document.body.scrollLeft+document.documentElement.scrollLeft+document.documentElement.offsetWidth - _dict_x < dx){
|
||||
_dict_x = document.body.scrollLeft+document.documentElement.scrollLeft + document.documentElement.offsetWidth - dx;
|
||||
}
|
||||
}else{
|
||||
dx-=1;
|
||||
dy+=11;
|
||||
if (self.innerHeight && document.body.scrollTop+document.documentElement.scrollTop + self.innerHeight - _dict_y < dy) {
|
||||
_dict_y = document.body.scrollTop+document.documentElement.scrollTop + self.innerHeight - dy;
|
||||
_dict_x += 14;
|
||||
}
|
||||
if (self.innerWidth && document.body.scrollLeft+document.documentElement.scrollLeft + self.innerWidth - _dict_x < dx) {
|
||||
_dict_x = document.body.scrollLeft+document.documentElement.scrollLeft + self.innerWidth - dx;
|
||||
}
|
||||
}
|
||||
_dict_nx = _dict_cx = _dict_x;
|
||||
_dict_ny = _dict_cy = _dict_y;
|
||||
_dict_layer.style.left = _dict_nx+'px';
|
||||
_dict_layer.style.top = _dict_ny+'px';
|
||||
_dict_layer.style.filter="Alpha(Opacity=96)";
|
||||
_dict_layer.style.opacity = 0.96;
|
||||
_dict_layer.style.display = "inline";
|
||||
_dict_moving = 1;
|
||||
}
|
||||
function _dict_isInteger(s) {
|
||||
return (s.toString().search(/^-?[0-9]+$/) == 0);
|
||||
}
|
||||
|
||||
function dictShow(q){
|
||||
if(_dict_mode != 1){
|
||||
_dictSet(_dict_getObj('_dict_title'), '划词翻译 - Dict.CN');
|
||||
_dict_mode = 1;
|
||||
}
|
||||
var d = _dict_getObj('_dict_add');
|
||||
if(d){
|
||||
d.href = _dict_host + 'scb/?utf8=1&word=' + q;
|
||||
d.onclick = function(){ _dictScb(q); return false; };
|
||||
}
|
||||
d = _dict_getObj('_dict_detail');
|
||||
if(d) d.href = _dict_host + 'search.php?q='+q;
|
||||
if(_dict_moving==0)_dictDisplay();
|
||||
_dict_iframe.src = _dict_host+'mini.php?utf8=1&q='+q;
|
||||
}
|
||||
function _dictShow(word){
|
||||
var q = _dict_URL(word);
|
||||
if(_dict_mode != 1){
|
||||
_dictSet(_dict_getObj('_dict_title'), '划词翻译 - Dict.CN');
|
||||
_dict_mode = 1;
|
||||
}
|
||||
var d = _dict_getObj('_dict_add');
|
||||
if(d){
|
||||
d.href = _dict_host + 'scb/?utf8=1&word=' + q;
|
||||
d.onclick = function(){ _dictScb(q); return false; };
|
||||
}
|
||||
d = _dict_getObj('_dict_detail');
|
||||
if(d) d.href = _dict_host + 'search.php?q='+q;
|
||||
if(_dict_moving==0)_dictDisplay();
|
||||
_dict_old_word = word;
|
||||
_dict_iframe = false;
|
||||
_dict_geturl(_dict_host+'mini.php?utf8=1&q='+q,word);
|
||||
}
|
||||
|
||||
function _dict_geturl(u,word){
|
||||
try{
|
||||
if(_dict_frametimer){clearTimeout(_dict_frametimer);_dict_frametimer = 0;}
|
||||
if(!_dict_iframe){
|
||||
_dict_frameid ++;
|
||||
_dictSet(_dict_getObj('_dictContent'),'<iframe id="_dictFrame'+_dict_frameid+'" name="_dictFrame'+_dict_frameid+'" HEIGHT="120" src="about:blank" FRAMEBORDER="0" width="100%"></iframe>');
|
||||
_dict_iframe = _dict_getObj('_dictFrame'+_dict_frameid);
|
||||
if(!_dict_iframe){
|
||||
_dict_frametimer = setTimeout(function(){_dict_geturl(u,word)},1000);
|
||||
return;
|
||||
}
|
||||
var iframeWin = window.frames['_dictFrame'+_dict_frameid];
|
||||
// alert(iframeWin);
|
||||
iframeWin.document.open();
|
||||
iframeWin.document.write('<html><body><div><span style="color:#666666;font-weight:bold;">Define </span><span style="color:green;font-weight:bold;">'+word+'</span> :<br /></div><center><img src="'+_dict_host+'imgs/loading.gif" width="80" height="62" /></center></body></html>');
|
||||
iframeWin.document.close();
|
||||
}
|
||||
}catch(x){
|
||||
}
|
||||
_dict_iframe.src = u;
|
||||
}
|
||||
function dictAdd(word,autoclose){
|
||||
autoclose = (typeof autoclose == 'undefined') ? 0 : 1;
|
||||
var q = _dict_URL(word.replace("%27","'"))
|
||||
_dictScb(q, autoclose);
|
||||
}
|
||||
function _dictScb(word,autoclose){
|
||||
if(word == "") return false;
|
||||
autoclose = (typeof autoclose == 'undefined') ? 0 : 1;
|
||||
if(_dict_mode != 2){
|
||||
_dictSet(_dict_getObj('_dict_title'), '添加生词 - Dict.CN');
|
||||
_dict_mode = 2;
|
||||
}
|
||||
var d = _dict_getObj('_dict_add');
|
||||
if(d){
|
||||
d.href = _dict_host + 'scb/';
|
||||
d.onclick = function(){return true;};
|
||||
}
|
||||
d = _dict_getObj('_dict_detail');
|
||||
if(d) d.href = _dict_host + 'search.php?utf8=1&q='+word;
|
||||
if(_dict_moving ==0) _dictDisplay();
|
||||
if(autoclose){
|
||||
_dict_iframe.src = _dict_host+'scb/add.php?utf8=1&autoclose=1&word='+word;
|
||||
}else{
|
||||
_dict_iframe.src = _dict_host+'scb/add.php?utf8=1&word='+word;
|
||||
}
|
||||
}
|
||||
|
||||
function _dictScbclose(){
|
||||
_dict_scbtimer = 0;
|
||||
if(_dict_mode==2 && _dict_moving >0){
|
||||
_dictClose();
|
||||
}
|
||||
}
|
||||
var _dict_addscb_fade = {
|
||||
'_timer':false,
|
||||
'setopacity':function(el,opaval){
|
||||
if(opaval<0 || opaval>100 || !el)return false;
|
||||
try{
|
||||
el.style.filter="Alpha(Opacity="+opaval+")";
|
||||
el.style.opacity = opaval/100;
|
||||
}
|
||||
catch(e){}
|
||||
return true;
|
||||
},
|
||||
'fading':function(el,opacity_start,step){
|
||||
var now = opacity_start + step;
|
||||
if(_dict_addscb_fade.setopacity(el,now))
|
||||
_dict_addscb_fade._timer = setTimeout(function(){_dict_addscb_fade.fading(el,now,step)},100);
|
||||
else {
|
||||
_dictScbclose();
|
||||
}
|
||||
}
|
||||
}
|
||||
function _dictMove(e){
|
||||
try{
|
||||
if(_dict_moving==2) {
|
||||
_dictGetPos(e);
|
||||
_dict_nx = _dict_x-_dict_startx+_dict_cx;
|
||||
_dict_ny = _dict_y-_dict_starty+_dict_cy;
|
||||
if (!_dict_opera && document.documentElement.scrollWidth && document.documentElement.scrollWidth - _dict_nx < 262) {
|
||||
_dict_nx = document.documentElement.scrollWidth - 262;
|
||||
}
|
||||
if(_dict_nx<0) _dict_nx = 0;
|
||||
if(_dict_ny<0) _dict_ny = 0;
|
||||
_dict_layer.style.left = _dict_nx+'px';
|
||||
_dict_layer.style.top = _dict_ny+'px';
|
||||
_dict_layer.focus();
|
||||
_dict_layer.blur();
|
||||
}
|
||||
}catch (x)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
function _dictClose() {
|
||||
if(_dict_addscb_fade._timer){
|
||||
clearTimeout(_dict_addscb_fade._timer);
|
||||
_dict_addscb_fade._timer=false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if(_dict_moving){
|
||||
var scrOfY = 0;
|
||||
if( document.body && document.body.scrollTop ) {
|
||||
scrOfY = document.body.scrollTop;
|
||||
} else if( document.documentElement && document.documentElement.scrollTop) {
|
||||
scrOfY = document.documentElement.scrollTop;
|
||||
}
|
||||
if(scrOfY < 50 &&_dict_mode == 2 && document.f && document.f.q && document.f.q.value) document.f.q.focus();
|
||||
_dict_moving = 0;
|
||||
_dict_onmove = 0;
|
||||
_dict_onlayer = 0;
|
||||
_dict_mode = 0;
|
||||
_dict_layer.style.display="none";
|
||||
setTimeout(function(){_dict_old_word = "";},500);
|
||||
}
|
||||
}
|
||||
catch (x)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function _dictRemove() {
|
||||
try
|
||||
{
|
||||
_dict_moving = 0;
|
||||
_dict_onmove = 0;
|
||||
_dict_onlayer = 0;
|
||||
_dict_mode = 0;
|
||||
if(_dict_onselect){
|
||||
document.onselectstart = _dict_oldselectstart;
|
||||
_dict_onselect = 0;
|
||||
}
|
||||
_dict_enable = false;
|
||||
_dict_layer.style.display="none";
|
||||
_dict_status.style.display="none";
|
||||
}
|
||||
catch (x)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
function _dictDisable(){
|
||||
_dict_SetCookie("dicthuaci","off",30);
|
||||
_dict_enable = false;
|
||||
_dictUpdateStatus();
|
||||
}
|
||||
|
||||
function _dictEnable(){
|
||||
if (_dict_enable){
|
||||
_dict_SetCookie("dicthuaci","off",30);
|
||||
_dict_enable = false;
|
||||
}else{
|
||||
_dict_enable = true;
|
||||
_dict_SetCookie("dicthuaci","",-1);
|
||||
}
|
||||
_dictUpdateStatus();
|
||||
}
|
||||
|
||||
function dictRemove(){
|
||||
_dictRemove();
|
||||
}
|
||||
function dictDisable(){
|
||||
_dict_enable = false;
|
||||
_dict_SetCookie("dicthuaci","off",30);
|
||||
_dictUpdateStatus();
|
||||
}
|
||||
|
||||
function dictEnable(){
|
||||
_dict_enable = true;
|
||||
_dict_SetCookie("dicthuaci","",-1);
|
||||
_dictUpdateStatus();
|
||||
}
|
||||
|
||||
function _dictUpdateStatus(){
|
||||
var d = _dict_getObj('dict_status');
|
||||
if(d){
|
||||
if (_dict_enable){
|
||||
_dictSet(d,'[划词翻译 <a href="javascript:dictDisable()" title="我要禁用划词翻译">开启</a>]');
|
||||
}else{
|
||||
_dictSet(d,'[划词翻译 <a href="javascript:dictEnable()" title="我要开启划词翻译">禁用</a>]');
|
||||
}
|
||||
}
|
||||
var h = _dict_getObj('huaci_status');
|
||||
if(h){
|
||||
if(_dict_enable){
|
||||
h.href = "javascript:dictDisable()";
|
||||
// h.onclick = function() {dictDisable();return false;};
|
||||
h.innerHTML = "划词畢开";
|
||||
}else{
|
||||
h.href = "javascript:dictEnable()";
|
||||
// h.onclick = function() {dictEnable();return false;};
|
||||
h.innerHTML ="划词畢关";
|
||||
}
|
||||
}
|
||||
h = _dict_getObj('huaci0_status');
|
||||
if(h && h.tagName && h.tagName.toLowerCase() == "a"){
|
||||
if(_dict_enable){
|
||||
h.href = "javascript:dictDisable()";
|
||||
// h.onclick = function() {dictDisable();return false;};
|
||||
h.innerHTML = "划词畢开";
|
||||
}else{
|
||||
h.href = "javascript:dictEnable()";
|
||||
// h.onclick = function() {dictEnable();return false;};
|
||||
h.innerHTML ="划词畢关";
|
||||
}
|
||||
}
|
||||
if(0){
|
||||
_dict_status.style.display="inline";
|
||||
_dictSet(_dict_status, _dictStatus());
|
||||
}
|
||||
}
|
||||
|
||||
function _dictStatus(){
|
||||
var b='line-height:20px;background-color:#e7f7f7;font-weight:normal;padding:0px;margin:0px;font-size:14px;text-decoration:none;font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;';
|
||||
var h='<span style="color:#000000;'+b+'">[<a href="'+_dict_help+'" title="我要查看划词帮助" target="_blank" style="color:#1A9100;'+b+'">划词翻译</a>畢';
|
||||
if (_dict_enable){
|
||||
h += '<a href="javascript:dictDisable()" title="我要禁用划词翻译" target="_self" style="color:#1A9100;'+b+'">开启</a>';
|
||||
}else{
|
||||
h += '<a href="javascript:dictEnable()" title="我要开启划词翻译" target="_self" style="color:#1A9100;'+b+'">禁用</a>';
|
||||
}
|
||||
h +='] <a href="javascript:dictRemove();" target="_self" style="'+b+'"><img src='+_dict_host+'img/close.gif border=0 align=absmiddle style="padding:0px;margin:0px;"></a>';
|
||||
return h;
|
||||
}
|
||||
function _dict_load(){
|
||||
if(! document || ! document.body || !document.body.firstChild){
|
||||
if(document.addEventListener){
|
||||
window.addEventListener("load", _dictInit, true);
|
||||
}else if (document.attachEvent) {
|
||||
window.attachEvent("onload", _dictInit);
|
||||
}else{
|
||||
var oldload = (document.onload) ? document.onload : function () {};
|
||||
window.onload = function () {oldload(); _dictInit();};
|
||||
}
|
||||
}else{
|
||||
_dictInit();
|
||||
}
|
||||
}
|
||||
function dictInit(){
|
||||
_dictInit();
|
||||
}
|
||||
if(typeof(_dict_loaded) != "string" || _dict_loaded != "yes"){
|
||||
var _dict_is_ie = true;
|
||||
var _dict_host = 'http://dict.cn/';
|
||||
var _dict_help = "http://dict.cn/foot/help.htm";
|
||||
var _dict_old_word = "";
|
||||
var _dict_oldselectstart = function () {};
|
||||
var _dict_onselect = 0;
|
||||
var _dict_opera = 0;
|
||||
var _dict_frameid = 0;
|
||||
var _dict_frametimer = 0;
|
||||
var _dict_scbtimer = 0;
|
||||
var _dict_moving = 0;
|
||||
var _dict_onmove = 0;
|
||||
var _dict_onlayer = 0;
|
||||
var _dict_startx = 0;
|
||||
var _dict_starty = 0;
|
||||
var _dict_cx = 0;
|
||||
var _dict_cy = 0;
|
||||
var _dict_x = 0;
|
||||
var _dict_y = 0;
|
||||
var _dict_nx = 0;
|
||||
var _dict_ny = 0;
|
||||
var _dict_enable = true;
|
||||
var _dict_layer = null;
|
||||
var _dict_status = null;
|
||||
var _dict_iframe = null;
|
||||
var _dict_mode = 0;
|
||||
var _dict_init = 0;
|
||||
var _dict_loaded = "yes";
|
||||
_dict_load();
|
||||
}else{
|
||||
try{
|
||||
_dict_enable = true;
|
||||
_dictUpdateStatus();
|
||||
if(_dict_onselect == 0){
|
||||
document.onselectstart = function () {if (_dict_moving == 2) return false;};
|
||||
_dict_onselect = 1;
|
||||
}
|
||||
}catch(x){;}
|
||||
}
|
||||
dict_enable = false;
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user