Files
hustoj/web/index.php
klarkxy 10278b55fb feat: add automatic git pull on homepage visit with rate limiting
Introduce a mechanism to automatically pull the latest changes from the git repository when the homepage is accessed. This ensures the application stays up-to-date without manual intervention. The feature includes a lock file (`/tmp/hustoj_git_pull.lock`) to prevent excessive pulls, limiting execution to at most once every 60 seconds. The git pull command runs in the background to avoid blocking the page load, with output logged to `/tmp/hustoj_git_pull.log`.
2026-03-13 15:16:29 +08:00

106 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
////////////////////////////Common head
$cache_time = 30;
$OJ_CACHE_SHARE = false;
// Auto git pull on homepage visit (at most once per 60 seconds)
$git_pull_lock = '/tmp/hustoj_git_pull.lock';
if (!file_exists($git_pull_lock) || (time() - filemtime($git_pull_lock)) > 60) {
touch($git_pull_lock);
$repo_dir = dirname(__DIR__);
exec("cd " . escapeshellarg($repo_dir) . " && git pull > /tmp/hustoj_git_pull.log 2>&1 &");
}
require_once( './include/cache_start.php' );
require_once( './include/db_info.inc.php' );
require_once( './include/memcache.php' );
require_once( './include/setlang.php' );
require_once( './include/bbcode.php' );
$view_title = "Welcome To Online Judge";
$result = false;
if ( isset( $OJ_ON_SITE_CONTEST_ID ) ) {
header( "location:contest.php?cid=" . $OJ_ON_SITE_CONTEST_ID );
exit();
}
///////////////////////////MAIN
//NOIP赛制比赛时暂时屏蔽本月之星
if(isset($OJ_NOIP_KEYWORD)&&$OJ_NOIP_KEYWORD){
$now = date('Y-m-d H:i', time());
$sql="select count(contest_id) from contest where start_time<'$now' and end_time>'$now' and title like '%$OJ_NOIP_KEYWORD%'";
$row=pdo_query($sql);
if(!empty($row)) $NOIP_flag=$row[0];
else $NOIP_flag=false;
}
$view_news = "";
$sql = "select * "
. "FROM `news` "
. "WHERE `defunct`!='Y' AND `title`!='faqs.$OJ_LANG'"
. "ORDER BY `importance` ASC,`time` DESC "
. "LIMIT 50";
$view_news .= "<div class='panel panel-default' style='width:80%;margin:0 auto;'>";
$view_news .= "<div class='panel-heading'><h3>" . $MSG_NEWS . "<h3></div>";
$view_news .= "<div class='panel-body'>";
$result = mysql_query_cache( $sql ); //mysql_escape_string($sql));
if ( !$result ) {
$view_news.= "";
} else {
foreach ( $result as $row ) {
$view_news .= "<div class='panel panel-default'>";
$view_news .= "<div class='panel-heading'><big>" . $row[ 'title' ] . "</big>-<small>" . $row[ 'user_id' ] . "</small></div>";
$view_news .= "<div class='panel-body'>" . bbcode_to_html($row[ 'content' ]) . "</div>";
$view_news .= "</div>";
}
}
$view_news .= "</div>";
$view_news .= "<div class='panel-footer'></div>";
$view_news .= "</div>";
$view_apc_info = "";
$last_1000_id=0;
$last_1000_id=pdo_query("select max(solution_id)-1000 from solution");
if(!empty($last_1000_id)) $last_1000_id=$last_1000_id[0][0];
if ($last_1000_id==NULL) $last_1000_id=0;
$sql = "SELECT UNIX_TIMESTAMP(date(in_date))*1000 md,count(1) c FROM (select * from solution where solution_id > $last_1000_id) solution where result<13 and solution_id > $last_1000_id group by md order by md desc limit 200";
$result = mysql_query_cache( $sql ); //mysql_escape_string($sql));
$chart_data_all = array();
//echo $sql;
if(!empty($result))
foreach ( $result as $row ) {
array_push( $chart_data_all, array( $row[ 'md' ], $row[ 'c' ] ) );
}
$sql = "SELECT UNIX_TIMESTAMP(date(in_date))*1000 md,count(1) c FROM (select * from solution where solution_id > $last_1000_id) solution where result=4 and solution_id > $last_1000_id group by md order by md desc limit 200";
$result = mysql_query_cache( $sql ); //mysql_escape_string($sql));
$chart_data_ac = array();
//echo $sql;
if(!empty($result))
foreach ( $result as $row ) {
array_push( $chart_data_ac, array( $row[ 'md' ], $row[ 'c' ] ) );
}
$speed=0;
if ( isset( $_SESSION[ $OJ_NAME . '_' . 'administrator' ] ) ) {
$sql = "select avg(sp) sp from (select avg(1) sp,judgetime DIV 3600 from solution where result>3 and solution_id >$last_1000_id group by (judgetime DIV 3600) order by sp) tt;";
$result = mysql_query_cache( $sql );
$speed = ( $result[ 0 ][ 0 ] ? $result[ 0 ][ 0 ] : 0 ) . '/min';
} else {
if(isset($chart_data_all[ 0 ])) $speed = ( isset($chart_data_all[ 0 ][ 1 ]) ? $chart_data_all[ 0 ][ 1 ] : 0 ) . '/day';
}
/////////////////////////Template
require( "template/" . $OJ_TEMPLATE . "/index.php" );
if( isset($OJ_LONG_LOGIN)
&& $OJ_LONG_LOGIN
&&(!isset($_SESSION[$OJ_NAME.'_user_id']))
&&isset($_COOKIE[$OJ_NAME."_user"])
&&isset($_COOKIE[$OJ_NAME."_check"])){
echo"<script>let xhr=new XMLHttpRequest();xhr.open('GET','login.php',true);xhr.send();setTimeout('location.reload()',800);</script>";
}
/////////////////////////Common foot
if ( file_exists( './include/cache_end.php' ) )
require_once( './include/cache_end.php' );
?>