aboutsummaryrefslogtreecommitdiffstats
path: root/toj/php/event.inc.php
diff options
context:
space:
mode:
authorpzread <netfirewall@gmail.com>2013-03-01 22:30:00 +0800
committerpzread <netfirewall@gmail.com>2013-03-01 22:30:00 +0800
commit56688ed6d0b18f68ac8ddd82c4944c5d2777d20a (patch)
treebb943e164f82b4a826f1d9ce253bfabf912c0004 /toj/php/event.inc.php
parent69d7b55a1c9d3100d42b9c91ab995de44b13d73b (diff)
downloadtaiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.tar
taiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.tar.gz
taiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.tar.bz2
taiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.tar.lz
taiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.tar.xz
taiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.tar.zst
taiwan-online-judge-56688ed6d0b18f68ac8ddd82c4944c5d2777d20a.zip
Taiwan Online Judge Alpha 1
Diffstat (limited to 'toj/php/event.inc.php')
-rw-r--r--toj/php/event.inc.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/toj/php/event.inc.php b/toj/php/event.inc.php
new file mode 100644
index 0000000..9d2a23c
--- /dev/null
+++ b/toj/php/event.inc.php
@@ -0,0 +1,71 @@
+<?php
+class event
+{
+ private static $white_list;
+
+ private static function init()
+ {
+ event::$white_list = array('10.8.0.2');
+ }
+
+ // execute function $name in file $fname
+ // if want to call a function of a class, have 2 choice:
+ // 1. pass an array as $name, put every level of class in it, like:
+ // A::B::C() should be passed like array("A", "B", "C").
+ // 2. pass a string with :: directly, it will be automatically
+ // translated.
+ // return value will be FALSE on failure, return value of target
+ // function otherwise. NULL when no return value.
+ public static function exec_func($fname, $name, $arg)
+ {
+ if(!file_exists($fname))
+ {
+ return false;
+ }
+ require_once($fname);
+ if(is_string($name) && strpos($name, ":") !== FALSE)
+ {
+ $name = preg_split("/::/", $name);
+ }
+ if(is_string($name) && !is_callable($name))
+ {
+ return false;
+ }
+ if(is_array($name) && !is_callable(join($name, "::")))
+ {
+ return false;
+ }
+ if($arg == NULL)
+ {
+ $res = call_user_func($name);
+ }
+ else
+ {
+ $res = call_user_func_array($name, $arg);
+ }
+ if($res === false)
+ {
+ return false;
+ }
+ return $res;
+ }
+
+ public static function validate_ip()
+ {
+ event::init();
+ if (!empty($_SERVER['HTTP_CLIENT_IP']))
+ {
+ $ip=$_SERVER['HTTP_CLIENT_IP'];
+ }
+ else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
+ {
+ $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
+ }
+ else
+ {
+ $ip=$_SERVER['REMOTE_ADDR'];
+ }
+ return in_array($ip, event::$white_list);
+ }
+}
+?>