1
0

functions.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2014 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. #functions go here
  25. //read_expire() converts a time stamp to a human readable form
  26. //Used as a count down to when the user's account expires
  27. //Example would be User's account expires in 200 days, 20 hours, 18 minutes
  28. function read_expire($endtime)
  29. {
  30. #Feed the user's expire time stamp to this, and it returns a human readable date
  31. if($endtime == 'X')
  32. {
  33. $timediff = 'X';
  34. return $timediff;
  35. }
  36. //Thanks to manhon824 at gmail dot com - found on http://us2.php.net/manual/en/function.mktime.php
  37. $starttime=time();
  38. // the start time can change to =strtotime($endtime);
  39. //$endtime=strtotime($expires);
  40. // $endtime = $expires;
  41. //$endtime can be any format as well as it can be converted to secs
  42. $timediff = $endtime-$starttime;
  43. $days=intval($timediff/86400);
  44. $remain=$timediff%86400;
  45. $hours=intval($remain/3600);
  46. $remain=$remain%3600;
  47. $mins=intval($remain/60);
  48. $secs=$remain%60;
  49. //this code is copied from the other note!thx to that guy!
  50. $stampdiff = $timediff;
  51. $timediff=$days.' days '.$hours.' hr '.$mins.' min ';
  52. return $timediff;
  53. }
  54. function genRandomString($length) {
  55. $characters = "0123456789abcdefghijklmnopqrstuvwxyz";
  56. $string = "";
  57. for ($p = 0; $p < $length; $p++) {
  58. $string .= $characters[mt_rand(0, strlen($characters)-1)];
  59. }
  60. return $string;
  61. }
  62. function get_map_path($query_name,$mod,$map) {
  63. $mod_gt = $mod;
  64. if($mod == "cstrike")
  65. {
  66. if ($query_name == "halflife")
  67. $mod_gt = "cs";
  68. elseif($query_name == "source")
  69. $mod_gt = "css";
  70. }
  71. if($mod == "tf")
  72. {
  73. if ($query_name == "halflife")
  74. $mod_gt = "tf";
  75. elseif($query_name == "source")
  76. $mod_gt = "tf2";
  77. }
  78. $mod_gt = $mod == "fof" ? "hl2dm" : $mod_gt;
  79. $mod_gt = $mod == "insurgency" ? "ins" : $mod_gt;
  80. $mod_gt = $mod == "redorchestra2" ? "ro2" : $mod_gt;
  81. $mod_gt = $mod == "killingfloor2" ? "kf2" : $mod_gt;
  82. $mod_gt = $query_name == "callofduty" ? "cod" : $mod_gt;
  83. $mod_gt = $query_name == "callofduty2" ? "cod2" : $mod_gt;
  84. $mod_gt = $query_name == "callofduty4" ? "cod4" : $mod_gt;
  85. $mod_gt = $query_name == "conanexiles" ? "conan" : $mod_gt;
  86. $map_paths= array(
  87. "https://image.gametracker.com/images/maps/160x120/$mod_gt/$map.jpg",
  88. "https://image.gametracker.com/images/maps/160x120/$query_name/$map.jpg",
  89. "protocol/lgsl/maps/$query_name/$mod/$map.jpg",
  90. "protocol/lgsl/maps/$query_name/$mod/$map.gif",
  91. "protocol/lgsl/maps/$query_name/$mod/$map.png",
  92. "protocol/lgsl/maps/$query_name/$map.jpg",
  93. "protocol/lgsl/maps/$query_name/$map.gif",
  94. "protocol/lgsl/maps/$query_name/$map.png",
  95. "images/online_big.png"
  96. );
  97. return get_first_existing_file($map_paths, 'http://gametracker.com', 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0');
  98. }
  99. // Thanks adjo (http://opengamepanel.org/forum/viewthread.php?thread_id=5209#post_25073)
  100. function curlCacheImage($cachePath, $resource){
  101. if(preg_match('/^(https?:\/\/)/', $resource)){
  102. $map = explode('/', $resource);
  103. if(!file_exists($cachePath . '/cache/' . end($map))){
  104. $ch = curl_init();
  105. curl_setopt($ch, CURLOPT_HEADER, 0);
  106. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  107. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0');
  108. curl_setopt($ch, CURLOPT_REFERER, 'http://gametracker.com');
  109. curl_setopt($ch, CURLOPT_URL, $resource);
  110. $result = curl_exec($ch);
  111. curl_close($ch);
  112. file_put_contents($cachePath . '/cache/' . end($map), $result);
  113. }
  114. return $cachePath . '/cache/' . end($map);
  115. }
  116. return $resource;
  117. }
  118. //Refreshed Div:
  119. //Below is under construction:
  120. // Usage: $data .= PopupData($id);
  121. // PopupBuild($data);
  122. function PopupTrigger($id){
  123. return "<a href='#' class='ex".$id."trigger'></a>";
  124. }
  125. function PopupData($id,$link){//Trigger: ex($id)trigger
  126. return "$('#ex".$id."').jqm({ajax: '$link', trigger: 'a.ex".$id."trigger'});";
  127. }
  128. function PopupBuild($data){
  129. return "<script type='text/javascript'>$(document).ready(function()\{".$data."\});</script>";
  130. }
  131. function create_home_selector($module, $subpage, $server_homes) {
  132. if ($server_homes == "show_all")
  133. {
  134. echo "<form method='GET' action=''>\n";
  135. echo "<input type='hidden' name='m' value='".$module."' />\n";
  136. if( $subpage ) echo "<input type='hidden' name='p' value='".$subpage."' />\n";
  137. echo "<input type='SUBMIT' value='" . get_lang('show_all') . "'/>\n";
  138. echo "</form>\n";
  139. }
  140. else
  141. {
  142. foreach ($server_homes as $key => $row) {
  143. $home_name[$key] = $row['home_name'];
  144. $home_id[$key] = $row['home_id'];
  145. $mod_id[$key] = $row['home_id'];
  146. $ip[$key] = $row['ip'];
  147. $port[$key] = $row['port'];
  148. }
  149. array_multisort($home_name, $ip, $port, $mod_id, $home_id, SORT_DESC, $server_homes);
  150. echo "<form method='GET' name='select' action=''>\n";
  151. echo "<input type='hidden' name='m' value='".$module."' />\n";
  152. if( $subpage ) echo "<input type='hidden' name='p' value='".$subpage."' />\n";
  153. echo "<select onchange=".'"this.form.submit()"'." name='home_id'>\n";
  154. echo "<option></option>\n";
  155. foreach ( $server_homes as $server_home )
  156. {
  157. if( isset( $_GET['home_id'] ) and $_GET['home_id'] == $server_home['home_id'] )
  158. $selected = 'selected="selected"';
  159. else
  160. $selected = '';
  161. echo "<option value='". $server_home['home_id'] . "' $selected >" . htmlentities($server_home['home_name']) . "</option>\n";
  162. }
  163. echo "</select>\n";
  164. echo "</form>";
  165. }
  166. }
  167. function create_home_selector_address($module, $subpage, $server_homes, $extra_inputs = FALSE, $method = "GET") {
  168. if( isset($_GET['home_id-mod_id-ip-port']) and $_GET['home_id-mod_id-ip-port'] != "" )
  169. {
  170. list($get_home_id,
  171. $get_mod_id,
  172. $get_ip,
  173. $get_port) = explode( "-", $_GET['home_id-mod_id-ip-port'] );
  174. }
  175. echo "<form method='$method' name='select' action=''>\n";
  176. echo "<input type='hidden' name='m' value='$module' />\n";
  177. if( $subpage ) echo "<input type='hidden' name='p' value='".$subpage."' />\n";
  178. if($extra_inputs)
  179. {
  180. foreach($extra_inputs as $input)
  181. {
  182. echo "<input type='$input[type]' name='$input[name]' value='$input[value]' />\n";
  183. }
  184. }
  185. echo "<select onchange=\"this.form.submit();\" name='home_id-mod_id-ip-port'>\n";
  186. echo "<option></option>\n";
  187. foreach ($server_homes as $key => $row) {
  188. if( !isset($row['ip']) or !isset($row['mod_id']) )
  189. {
  190. unset($server_homes[$key]);
  191. continue;
  192. }
  193. $home_name[$key] = $row['home_name'];
  194. $home_id[$key] = $row['home_id'];
  195. $mod_id[$key] = $row['home_id'];
  196. $ip[$key] = $row['ip'];
  197. $port[$key] = $row['port'];
  198. }
  199. array_multisort($home_name, $ip, $port, $mod_id,
  200. $home_id, SORT_DESC, $server_homes);
  201. foreach ( $server_homes as $server_home )
  202. {
  203. if(isset($_GET['home_id-mod_id-ip-port']) and
  204. $get_home_id == $server_home['home_id'] and
  205. $get_mod_id == $server_home['mod_id'] and
  206. $get_ip == $server_home['ip'] and
  207. $get_port == $server_home['port'])
  208. $selected = 'selected="selected"';
  209. else
  210. $selected = '';
  211. echo "<option value='". $server_home['home_id'] .
  212. "-" . $server_home['mod_id'] . "-" . $server_home['ip'] .
  213. "-" . $server_home['port'] . "' $selected >" .
  214. htmlentities($server_home['home_name']) . " - " . $server_home['ip'] .
  215. ":" . $server_home['port'] . "</option>\n";
  216. }
  217. echo "</select>\n";
  218. echo "</form>";
  219. }
  220. function create_home_selector_game_type($module, $subpage, $server_homes) {
  221. echo "<form method='GET' name='select' action=''>\n".
  222. "<input type='hidden' name='m' value='".$module."' />\n";
  223. if( $subpage != "" ) echo "<input type='hidden' name='p' value='".$subpage."' />\n";
  224. echo "<select onchange=".'"this.form.submit()"'." name='home_cfg_id'>\n".
  225. "<option>".get_lang('game_type')."</option>\n";
  226. $servers_by_game_name = array();
  227. foreach( $server_homes as $server_home )
  228. {
  229. if( !isset($server_home['ip']) or !isset($server_home['mod_id']) )
  230. continue;
  231. $servers_by_game_name["$server_home[game_name]"] = $server_home['home_cfg_id'];
  232. }
  233. ksort($servers_by_game_name);
  234. foreach( $servers_by_game_name as $game_name => $home_cfg_id )
  235. {
  236. $selected = (isset($_GET['home_cfg_id']) and $_GET['home_cfg_id'] == $home_cfg_id) ? 'selected="selected"' : "";
  237. echo "<option value='". $home_cfg_id . "' $selected >" . $game_name . "</option>\n";
  238. }
  239. echo "</select>\n</form>\n";
  240. }
  241. function mymail($email_address, $subject, $message, $panel_settings, $user_to_panel = FALSE){
  242. global $view;
  243. if( empty( $panel_settings['panel_name'] ) )
  244. $panel_name = "Open Game Panel";
  245. else
  246. $panel_name = $panel_settings['panel_name'];
  247. include('PHPMailer/class.phpmailer.php');
  248. // Create the mail object using the Mail::factory method
  249. $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  250. $mail->IsSMTP(); // telling the class to use SMTP
  251. $mymail = TRUE;
  252. try
  253. {
  254. $mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
  255. // 1 = errors and messages
  256. // 2 = messages only
  257. // SMTP server
  258. if (isset($panel_settings['smtp_server']) and !empty($panel_settings['smtp_server']))
  259. $mail->Host = $panel_settings['smtp_server'];
  260. else
  261. $mail->Host = 'localhost';
  262. // set the SMTP port
  263. if (isset($panel_settings['smtp_port']) and !empty($panel_settings['smtp_port']))
  264. $mail->Port = $panel_settings['smtp_port'];
  265. else
  266. $mail->Port = 25;
  267. // sets the prefix to the servier
  268. if (isset($panel_settings['smtp_ssl']) and $panel_settings['smtp_ssl'] == 1)
  269. $mail->SMTPSecure = "ssl";
  270. elseif (isset($panel_settings['smtp_tls']) and $panel_settings['smtp_tls'] == 1)
  271. $mail->SMTPSecure = "tls";
  272. if (isset($panel_settings['smtp_login']) and !empty($panel_settings['smtp_login']))
  273. {
  274. // enable SMTP authentication
  275. $mail->SMTPAuth = true;
  276. // SMTP username
  277. $mail->Username = $panel_settings['smtp_login'];
  278. if (isset($panel_settings['smtp_passw']) and !empty($panel_settings['smtp_passw']))
  279. {
  280. // SMTP password
  281. $mail->Password = $panel_settings['smtp_passw'];
  282. }
  283. }
  284. if(empty($panel_settings['panel_email_address'])){
  285. $panel_email = "[email protected]";
  286. }else{
  287. $panel_email = $panel_settings['panel_email_address'];
  288. }
  289. $email_addresses = explode( ",", $email_address );
  290. if( $user_to_panel )
  291. {
  292. $mail->AddAddress($panel_email);
  293. $user_to_panel = is_bool($user_to_panel) ? "" : $user_to_panel; // True boolean or user name string
  294. foreach ( $email_addresses as $address )
  295. {
  296. $mail->SetFrom($address,$user_to_panel);
  297. $mail->AddReplyTo($address,$user_to_panel);
  298. }
  299. }
  300. else // panel to user
  301. {
  302. foreach ( $email_addresses as $address )
  303. {
  304. $mail->AddAddress($address);
  305. }
  306. $mail->SetFrom($panel_email,$panel_name);
  307. $mail->AddReplyTo($panel_email,$panel_name);
  308. }
  309. $mail->CharSet = $view->charset;
  310. $mail->Subject = $subject;
  311. $mail->MsgHTML($message);
  312. $mail->Send();
  313. }
  314. catch (phpmailerException $e)
  315. {
  316. $mymail = FALSE;
  317. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  318. }
  319. catch (Exception $e)
  320. {
  321. $mymail = FALSE;
  322. echo $e->getMessage(); //Boring error messages from anything else!
  323. }
  324. return $mymail;
  325. }
  326. if( !function_exists("sys_get_temp_dir") )
  327. {
  328. function sys_get_temp_dir(){
  329. if ($temp = getenv('TMP') ) {
  330. if (file_exists($temp)) { return realpath($temp); }
  331. }
  332. if ($temp = getenv('TEMP') ) {
  333. if (file_exists($temp)) { return realpath($temp); }
  334. }
  335. if ($temp = getenv('TMPDIR') ) {
  336. if (file_exists($temp)) { return realpath($temp); }
  337. }
  338. // trick for creating a file in system's temporary dir
  339. // without knowing the path of the system's temporary dir
  340. $temp = tempnam(__FILE__, '');
  341. if (file_exists($temp)) {
  342. unlink($temp);
  343. return realpath(dirname($temp));
  344. }
  345. return null;
  346. }
  347. }
  348. function set_firewall($remote, $firewall_settings, $action, $port, $ip = FALSE)
  349. {
  350. if($action == "allow" or $action == "deny")
  351. {
  352. if($ip)
  353. $command = str_replace("%IP%",$ip,str_replace("%PORT%",$port,$firewall_settings[$action.'_ip_port_command']));
  354. else
  355. $command = str_replace("%PORT%",$port,$firewall_settings[$action.'_port_command']);
  356. }
  357. if(isset($command))
  358. return $remote->sudo_exec($command);
  359. else
  360. return FALSE;
  361. }
  362. function strip_real_escape_string($text)
  363. {
  364. $search = array('\"', "\'", "\\r", "\\n","\\\\");
  365. $replace = array('"', "'", "\r", "\n", '\\');
  366. $text = str_replace($search, $replace, $text);
  367. return $text;
  368. }
  369. function get_true_boolean($bool)
  370. {
  371. if ( (int) $bool > 0 )
  372. $ret = true;
  373. else
  374. {
  375. $lowered_bool = strtolower($bool); // that could be 'True' or 'true' or 'TRUE', etc...
  376. if( $lowered_bool === "true" || $lowered_bool === "on" || $lowered_bool === "yes" )
  377. $ret = true;
  378. else
  379. $ret = false;
  380. }
  381. return $ret;
  382. }
  383. function get_temp_dir($curdir)
  384. {
  385. $temp = sys_get_temp_dir();
  386. if( ini_get('open_basedir') )
  387. {
  388. $dirs = preg_split( "/:|;/", ini_get('open_basedir') , -1, PREG_SPLIT_NO_EMPTY );
  389. if( !in_array($temp, $dirs) )
  390. $temp = $curdir . DIRECTORY_SEPARATOR . 'temp';
  391. }
  392. if( $temp == null )
  393. $temp = $curdir . DIRECTORY_SEPARATOR . 'temp';
  394. if( !file_exists($temp) )
  395. if( is_writable( dirname($temp) ) ) mkdir($temp);
  396. return $temp;
  397. }
  398. // ### Escape some characters that could break the server startup or make the user capable to run other programs. ###
  399. // \ (backslash) -> At the end of the string, can scape the next quote,
  400. // and is commonly used to create Windows paths, must be escaped.
  401. // " (quote) -> Not escaped quote, without an ending quote, would break the startup command.
  402. // ' (single quote) -> same than quote.
  403. // | (pipe) -> Not escaped pipe would break the startup command and could use the next argument as new command.
  404. // & (ampersand) -> Same than pipe. If double ampersand is used it would run the command (if any) once the server process ends.
  405. // ; (semicolon) -> Same than double ampersand.
  406. // > (greater than) -> Could redirect the server output and ignore the next arguments.
  407. // < (lower than) -> Could send the content of a file to the server executable and ignore the the next arguments.
  408. // ` (apostrophe) -> Could get the return value of a given (system) command or variable.
  409. // $ (¿sigil?) -> Same than apostrophe.
  410. // ( and ) (parenthesis) -> starts or ends a bash/batch statement, could break the server startup
  411. // [ and ] (test) -> test is part of bash language, could break the server startup
  412. function clean_server_param_value($value, $cli_allow_chars) {
  413. $value = strip_real_escape_string($value);
  414. $escape_chars = array("\\", "\"", "'", "|", "&", ";", ">", "<", "`", "$", "(", ")", "[", "]");
  415. if($cli_allow_chars)
  416. {
  417. $cli_allow_chars = str_split($cli_allow_chars);
  418. $escape_chars = array_diff($escape_chars, $cli_allow_chars);
  419. }
  420. $find = array();
  421. $repl = array();
  422. foreach($escape_chars as $char)
  423. {
  424. $find[] = '%'.preg_quote($char).'%';
  425. $char = $char == '\\' ? preg_quote('\\\\') : $char;
  426. $repl[] = '\\'.$char;
  427. }
  428. return preg_replace($find, $repl, $value);
  429. }
  430. // ### Validate FTP user/password and control_protocol_password. ###
  431. function validate_login($value) {
  432. $value = strip_real_escape_string($value);
  433. $value = trim($value);
  434. $find = '%\\\\|"|\||&|;|>|<|`|\$|\s%';
  435. return preg_match($find, $value) ? FALSE : $value;
  436. }
  437. // Order a multidimensional array by keys. Source http://php.net/manual/es/function.array-multisort.php#100534
  438. function array_orderby()
  439. {
  440. $args = func_get_args();
  441. $data = array_shift($args);
  442. foreach ($args as $n => $field)
  443. {
  444. if (is_string($field))
  445. {
  446. $tmp = array();
  447. foreach ($data as $key => $row)
  448. $tmp[$key] = $row[$field];
  449. $args[$n] = $tmp;
  450. }
  451. }
  452. $args[] = &$data;
  453. call_user_func_array('array_multisort', $args);
  454. return array_pop($args);
  455. }
  456. // Escape a single quote or multiple single quotes
  457. // in a string that is passed to bash
  458. // and this string is single quoted
  459. function esc_squote($str)
  460. {
  461. return preg_replace("#('+)#", "'\"\${1}\"'", $str);
  462. }
  463. function get_game_selector($os, $game_cfgs, $home_cfg_id = FALSE)
  464. {
  465. if(preg_match("/64/", $os))
  466. {
  467. $arch_64_bit = true;
  468. }
  469. if(preg_match("/linux/i", $os))
  470. {
  471. if(preg_match("/wine/i", $os))
  472. {
  473. $os_match = $arch_64_bit ? '/(win|linux)(32|64)?$/i' : '/(win|linux)(32)?$/i';
  474. }
  475. else
  476. {
  477. $os_match = $arch_64_bit ? '/(linux)(32|64)?$/i' : '/(linux)(32)?$/i';
  478. }
  479. }
  480. elseif(preg_match("/cygwin/i", $os))
  481. {
  482. $os_match = $arch_64_bit ? '/(win)(32|64)?$/i' : '/(win)(32)?$/i';
  483. }
  484. else
  485. {
  486. $os_match = '/(win|linux)(32|64)?$/i';
  487. }
  488. $selector = "";
  489. foreach ( $game_cfgs as $row )
  490. {
  491. if ( preg_match($os_match, $row['game_key'], $matches) )
  492. {
  493. $selector .= "<option value='".$row['home_cfg_id']."' ".
  494. ($home_cfg_id == $row['home_cfg_id'] ? 'selected="selected"' : "").
  495. ">".$row['game_name'].
  496. (preg_match('/^linux$/i', $matches[1]) ? " (Linux" : " (Windows").
  497. ((isset($matches[2]) and $matches[2] == '64') ? " 64bit)" : ")").
  498. "</option>\n";
  499. }
  500. }
  501. return $selector;
  502. }
  503. function getClientIPAddress(){
  504. if(isset($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
  505. return $_SERVER['HTTP_CF_CONNECTING_IP'];
  506. }else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  507. return $_SERVER['HTTP_X_FORWARDED_FOR'];
  508. }else if(isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP'])){
  509. return $_SERVER['HTTP_X_REAL_IP'];
  510. }else{
  511. return $_SERVER['REMOTE_ADDR'];
  512. }
  513. }
  514. function getOGPSiteURL(){
  515. $url = '';
  516. $scheme = ( isset($_SERVER['HTTPS']) and get_true_boolean($_SERVER['HTTPS']) ) ? "https://" : "http://";
  517. $url .= $scheme . $_SERVER['HTTP_HOST'];
  518. if(!empty($_SERVER['REQUEST_URI'])){
  519. $lastSlash = strrpos($_SERVER['REQUEST_URI'], "/");
  520. if($lastSlash !== false){
  521. $url .= substr($_SERVER['REQUEST_URI'], 0, $lastSlash);
  522. }
  523. }
  524. if(!empty($url)){
  525. return $url;
  526. }
  527. return false;
  528. }
  529. ?>