EngineGP/system/library/system.php

1464 lines
34 KiB
PHP
Raw Normal View History

2023-03-04 23:45:46 +00:00
<?php
2023-11-11 20:56:12 +00:00
if(!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
class sys
{
public static function url($all = true)
{
if($_SERVER['REQUEST_URI'] == '/')
return $all ? NULL : 'index';
2023-03-05 08:15:39 +00:00
2023-11-11 20:56:12 +00:00
$url = array();
2023-03-05 08:15:39 +00:00
2023-11-11 20:56:12 +00:00
$string = str_replace('//', '/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$aUrl = explode('/', trim($string, ' /'));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$all)
return $aUrl[0];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
unset($aUrl[0]);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$i = 1;
$m = count($aUrl)+1;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
for($i; $i < $m; $i+=1)
$url[$aUrl[$i]] = isset($aUrl[++$i]) ? $aUrl[$i] : true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $url;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function user($user)
{
global $sql, $start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($user['time']+10 < $start_point)
$sql->query('UPDATE `users` set `time`="'.$start_point.'" WHERE `id`="'.$user['id'].'" LIMIT 1');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function users($users, $user, $authkey, $del = false)
{
global $mcache;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($del)
unset($users[md5($user['login'].$user['authkey'].$user['passwd'])]);
else
$users[md5($user['login'].$user['authkey'].$user['passwd'])] = $user;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
$mcache->set('users_auth', $users, false, 1000);
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function nav($server, $sid, $active)
{
global $cfg, $html, $sql, $mcache, $start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$notice_sid = $mcache->get('notice_'.$sid);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$notice = is_array($notice_sid) ? $notice_sid : $mcache->get('notice_'.$server['unit']);
2023-11-11 20:56:12 +00:00
if(!is_array($notice))
{
$sql->query('SELECT `server`, `text`, `color` FROM `notice` WHERE `server`="'.$sid.'" AND `time`>"'.$start_point.'" ORDER BY `id` DESC LIMIT 1');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$sql->num())
$sql->query('SELECT `unit`, `text`, `color` FROM `notice` WHERE `unit`="'.$server['unit'].'" AND `time`>"'.$start_point.'" ORDER BY `id` DESC LIMIT 1');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($sql->num())
{
$notice = $sql->get();
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
$nmc = $notice['server'] ? 'notice_'.$sid : 'notice_'.$server['unit'];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$mcache->set('notice_'.$nmc, $notice, false, 10);
}else
$mcache->set('notice_'.$server['unit'], NULL, false, 10);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$aUnit = array('index', 'console', 'settings', 'plugins', 'maps', 'owners', 'filetp', 'tarif', 'copy', 'graph', 'web', 'boost');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('gmenu', 'sections/servers/'.$server['game']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $sid);
$html->set('home', $cfg['http']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(is_array($notice))
{
global $device;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($device == '!mobile')
$html->set('notice', '<div class="informer '.$notice['color'].' topifon">'.$notice['text'].'</div><div class="space"></div>');
else
$html->set('notice', '<div class="heading-style-1 container"><div class="smaller-text color-'.$notice['color'].'-light">'.$notice['text'].'</div><div class="heading-decoration bg-'.$notice['color'].'-light" style="margin-top: 0px"></div></div>');
}else
$html->set('notice', '');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($server['console_use']) $html->unit('console_use', 1); else $html->unit('console_use');
if($server['plugins_use']) $html->unit('plugins_use', 1); else $html->unit('plugins_use');
if($server['ftp_use']) $html->unit('ftp_use', 1); else $html->unit('ftp_use');
if($server['stats_use']) $html->unit('graph_use', 1); else $html->unit('graph_use');
if($server['web_use']) $html->unit('web_use', 1); else $html->unit('web_use');
if($server['copy_use']) $html->unit('copy_use', 1); else $html->unit('copy_use');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($aUnit as $unit)
if($unit == $active) $html->unit($unit, 1); else $html->unit($unit);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('main');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('vmenu', 'sections/servers/'.$server['game']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $sid);
$html->set('home', $cfg['http']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($server['console_use']) $html->unit('console_use', 1); else $html->unit('console_use');
if($server['plugins_use']) $html->unit('plugins_use', 1); else $html->unit('plugins_use');
if($server['ftp_use']) $html->unit('ftp_use', 1); else $html->unit('ftp_use');
if($server['stats_use']) $html->unit('graph_use', 1); else $html->unit('graph_use');
if($server['web_use']) $html->unit('web_use', 1); else $html->unit('web_use');
if($server['copy_use']) $html->unit('copy_use', 1); else $html->unit('copy_use');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($aUnit as $unit)
if($unit == $active) $html->unit($unit, 1); else $html->unit($unit);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('vmenu');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function route($server, $inc, $go, $all = false)
{
global $device, $start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$dir = $device == '!mobile' ? '' : 'megp/';
$use = true;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
if(in_array($inc, array('plugins', 'ftp', 'console', 'graph', 'copy', 'web')))
{
$server['graph_use'] = $server['stats_use'];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$server[$inc.'_use'])
$use = false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$use || $server['time'] < $start_point || in_array($server['status'], array('install', 'reinstall', 'update', 'recovery', 'blocked')))
{
if($go)
sys::out('Раздел недоступен');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$use)
return SEC.$dir.'servers/'.$server['game'].'/index.php';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return SEC.$dir.'servers/noaccess.php';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($all)
return SEC.'servers/games/'.$inc.'.php';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!file_exists(SEC.$dir.'servers/'.$server['game'].'/'.$inc.'.php'))
return SEC.$dir.'servers/'.$server['game'].'/index.php';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return SEC.$dir.'servers/'.$server['game'].'/'.$inc.'.php';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function int($data, $width = false)
{
if($width)
return preg_replace("([^0-9]{0, ".$width."})", '', $data);
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return preg_replace("([^0-9])", '', $data);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function b64js($data)
{
return base64_encode(json_encode($data));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function b64djs($data)
{
return json_decode(base64_decode($data), true);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function hb64($data)
{
return base64_encode(htmlspecialchars($data));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function hb64d($data)
{
return htmlspecialchars_decode(base64_decode($data));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function outjs($val, $cache = false)
{
global $mcache;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($cache)
$mcache->delete($cache);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
die(json_encode($val));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function out($val = '', $cache = false)
{
global $mcache;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($cache)
$mcache->delete($cache);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
die(''.$val.'');
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function outhtml($text, $time = 3, $url = false, $cache = false)
{
global $device, $mcache, $html, $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($cache)
$mcache->delete($cache);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$tpl = $device == '!mobile' ? '' : '/megp';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('out');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('title', $cfg['name']);
$html->set('home', $cfg['http']);
$html->set('css', $cfg['http'].'template'.$tpl.'/css/');
$html->set('js', $cfg['http'].'template'.$tpl.'/js/');
$html->set('img', $cfg['http'].'template'.$tpl.'/images/');
$html->set('text', $text);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('out');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$url)
$url = $cfg['http'];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
header('Refresh: '.$time.'; URL='.$url);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
die($html->arr['out']);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function valid($val, $type, $preg = '')
{
switch($type)
{
case 'promo':
if(!preg_match("/^[A-Za-z0-9]{2,20}$/", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'en':
if(!preg_match("/^[A-Za-z0-9]$/", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'ru':
if(!preg_match("/^[А-Яа-я]$/u", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'wm':
if(!preg_match('/^R[0-9]{12,12}$|^Z[0-9]{12,12}$|^U[0-9]{12,12}$/m', $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'ip':
if(!preg_match("/^(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{2}|[0-9])(\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[0-9]{2}|[0-9])){3}$/", $val))
return true;
2023-11-11 20:56:12 +00:00
return false;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
case 'steamid':
if(!preg_match("/^STEAM_[0-9]:[0-9]:[0-9]{6,12}$|^HLTV$|^STEAM_ID_LAN$|^STEAM_ID_PENDING$|^VALVE_ID_LAN$|^VALVE_ID_PENDING$|^STEAM_666:88:666$/", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'steamid3':
if(!preg_match("/^\[U:[01]:[0-9]{3,12}\]$/i", $val))
return true;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'num':
if(!preg_match('/[^0-9]/', $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'md5':
if(!preg_match("/^[a-z0-9]{32,32}$/", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'other':
if(!preg_match($preg, $val))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return true;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function mail($name, $text, $mail)
{
global $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
require_once(LIB.'smtp.php');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$tpl = file_get_contents(DATA.'mail.ini', "r");
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$text = str_replace(
array('[name]', '[text]', '[http]', '[img]', '[css]'),
array($cfg['name'], $text, $cfg['http'], $cfg['http'].'template/images/', $cfg['http'].'template/css/'),
$tpl
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$smtp = new smtp($cfg['smtp_login'], $cfg['smtp_passwd'], $cfg['smtp_url'], $cfg['smtp_mail'], 465);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: ".$cfg['smtp_name']." <".$cfg['smtp_mail'].">\r\n";
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($smtp->send($mail, $name, $text, $headers))
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function mail_domain($mail)
{
$domain = explode('@', $mail);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$domain = end($domain);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(in_array($domain, array('list.ru', 'bk.ru', 'inbox.ru')))
$domain = 'mail.ru';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
switch($domain)
{
case 'mail.ru':
return $domain;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'yandex.ru':
return 'mail.yandex.ru';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'google.com':
return 'mail.google.com';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
default:
return '';
}
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function domain($domain)
{
$domain = explode('.', $domain);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
unset($domain[0]);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return implode('.', $domain);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function updtext($text, $data)
{
foreach($data as $name => $val)
$text = str_replace('['.$name.']', $val, $text);
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return $text;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function login($mail, $lchar)
{
if(!$lchar)
return str_replace(array('.', '_', '+', '-'), '', sys::first(explode('@', $mail)));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$list = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz0123456789';
$a = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz';
$selections = strlen($list)-1;
$start = strlen($a)-1;
$b = rand(0, $start);
$start = $a[$b];
$login = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$i = 0;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
for($i; $i <= 10; $i+=1)
{
$n = rand(0, $selections);
$login[] = $list[$n];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $start.implode('', $login);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function passwd($length = 8)
{
$list = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz0123456789';
$a = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz';
$selections = strlen($list)-1;
$start = strlen($a)-1;
$b = rand(0, $start);
$start = $a[$b];
$passwd = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$i = 0;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
for($i; $i <= $length-2; $i+=1)
{
$n = rand(0, $selections);
$passwd[] = $list[$n];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $start.implode('', $passwd);
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function passwdkey($passwd)
{
return md5($passwd);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function cookie($name, $value, $expires)
{
$expires = time() + ($expires * 86400);
setcookie($name, $value, $expires, "/", $_SERVER['SERVER_NAME'], null, true);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function auth()
{
global $auth, $go, $text, $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($auth)
{
if($go)
sys::outjs(array('e' => sys::text('output', 'auth')));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
global $device;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$link = $device == '!mobile' ? 'user/section/lk' : '';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
exit(header('Refresh: 0; URL='.$cfg['http'].$link));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function noauth()
{
global $auth, $go, $text, $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$auth)
{
if($go)
sys::outjs(array('e' => sys::text('output', 'noauth')));
2023-03-05 08:15:39 +00:00
2023-11-11 20:56:12 +00:00
global $device;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$link = $device == '!mobile' ? 'user/section/auth' : 'auth';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
exit(header('Refresh: 0; URL='.$cfg['http'].$link));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function browser($agent)
{
if(strpos($agent, 'Firefox') !== false)
return 'Mozilla Firefox';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(strpos($agent, 'Opera') !== false)
return 'Opera';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(strpos($agent, 'Chrome') !== false)
return 'Google Chrome';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(strpos($agent, 'MSIE') !== false)
return 'Internet Explorer';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(strpos($agent, 'Safari') !== false)
return 'Safari';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Неизвестный';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function date($lenght, $date)
{
global $start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$check_time = $date-$start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($check_time < 1)
return 'время истекло.';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$days = floor($check_time/86400);
$hours = floor(($check_time%86400)/3600);
$minutes = floor(($check_time%3600)/60);
$seconds = $check_time%60;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$adata = array(
'min' => array(
'days' => array('день', 'дня', 'дней'),
'hours' => array('ч.', 'ч.', 'ч.'),
'minutes' => array('мин.', 'мин.', 'мин.'),
'seconds' => array('сек.', 'сек.', 'сек.')
),
'max' => array(
'days' => array('день', 'дня', 'дней'),
'hours' => array('час', 'часа', 'часов'),
'minutes' => array('минуту','минуты','минут'),
'seconds' => array('секунду','секунды','секунд')
)
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$text = '';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($days > 0)
$text .= sys::date_decl($days, $adata[$lenght]['days']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($days < 1 AND $hours > 0)
$text .= ' '.sys::date_decl($hours, $adata[$lenght]['hours']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($days < 1 AND $minutes > 0)
$text .= ' '.sys::date_decl($minutes, $adata[$lenght]['minutes']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($days < 1 AND $seconds > 0)
$text .= ' '.sys::date_decl($seconds, $adata[$lenght]['seconds']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $text;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function date_decl($digit, $expr, $onlyword = false)
{
if(!is_array($expr))
$expr = array_filter(explode(' ', $expr));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(empty($expr[2]))
$expr[2] = $expr[1];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$i = sys::int($digit)%100;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($onlyword)
$digit = '';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($i > 4 AND $i < 21)
$res = $digit.' '.$expr[2];
else
$i%=10;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($i == 1)
$res = $digit.' '.$expr[0];
elseif($i > 1 AND $i < 5)
$res = $digit.' '.$expr[1];
else
$res = $digit.' '.$expr[2];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return trim($res);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function today($time, $cp = false)
{
global $start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$today = date('d.m.Y', $start_point);
$day = date('d.m.Y', $time);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($day == $today)
{
if($cp)
return 'Сегодня '.date('H:i', $time);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Сегодня '.date('- H:i', $time);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$yesterday_first = sys::int(sys::first(explode('.', $today)))-1;
$yesterday_full = date('m.Y', $time);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($day == $yesterday_first.'.'.$yesterday_full AND !$yesterday_first)
{
if($cp)
return 'Вчера '.date('H:i', $time);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Вчера '.date('- H:i', $time);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($cp)
return date('d.m.Y H:i', $time);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return date('d.m.Y - H:i', $time);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function day($time)
{
$days = array('день', 'дня', 'дней');
$time = $time % 100;
if($n > 10 AND $n < 20)
return $days[2];
$time = $time % 10;
if($time > 1 AND $time < 5)
return $days[1];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($time == 1)
return $days[0];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $days[2];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function bbc($text)
{
global $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$lines = explode("\n", $text);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$str_search = array(
"#\\\n#is",
"#\[spoiler\](.+?)\[\/spoiler\]#is",
"#\[sp\](.+?)\[\/sp\]#is",
"#\[b\](.+?)\[\/b\]#is",
"#\[u\](.+?)\[\/u\]#is",
"#\[code\](.+?)\[\/code\]#is",
"#\[quote\](.+?)\[\/quote\]#is",
"#\[url=(.+?)\](.+?)\[\/url\]#is",
"#\[img=(.+?)\] \[\/img\]#is",
"#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is"
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$str_replace = array(
"<br />",
"<div><b class='spoiler'>Посмотреть содержимое</b><div class='spoiler_main'>\\1</div></div>",
"<div><b class='spoiler'>Посмотреть содержимое</b><div class='spoiler_main'>\\1</div></div>",
"<b>\\1</b>",
"<u>\\1</u>",
"<div><b class='spoiler'>Посмотреть содержимое</b><div class='spoiler_main'><pre><code>\\1</code></pre></div></div>",
"<blockquote><p>\\1</p></blockquote>",
"<a href='\\1' target='_blank'>\\2</a>",
"<a href='\\1' target='_blank' style='display: block;'><img src='".$cfg['url']."template/images/help_screenshot.png' alt='Изображение'></a>",
"<a href='\\2' target='_blank'> \\2</a>"
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$uptext = '';
foreach($lines as $line)
$uptext .= preg_replace($str_search, $str_replace, $line)."<br>";
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return $uptext;
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function first($array = array())
{
return $array[0];
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function back($url)
{
exit(header('Refresh: 0; URL='.$url));
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function strlen($str)
{
return iconv_strlen($str, 'UTF-8');
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function text($section, $name)
{
global $cfg, $user;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
$group = isset($user['group']) ? $user['group'] : 'user';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($section != 'error' || !$cfg['text_group'])
$group = 'all';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
include(DATA.'text/'.$section.'.php');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return isset($text[$name][$group]) ? $text[$name][$group] : $text[$name];
}
public static function key($param = 'defegp')
{
return md5(sha1(rand(1, 15).$param.rand(16, 30).rand(200, 1000).rand(1, 100)));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function captcha($type, $ip)
{
global $mcache;
$cod = '';
$width = 100;
$height = 45;
$font_size = 16;
$symbols = 3;
$symbols_fon = 20;
$font = LIB.'captcha/text.ttf';
$chars = array('a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z','2','3','4','5','6','7','9');
$colors = array('20','50','80','100');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$src = imagecreatetruecolor($width, $height);
$fon = imagecolorallocate($src, 255, 255, 255);
imagefill($src, 0, 0, $fon);
$i = 0;
for($i; $i < $symbols_fon; $i+=1)
{
$color = imagecolorallocatealpha($src, rand(0,255), rand(0,255), rand(0,255), 100);
$char = $chars[rand(0, sizeof($chars)-1)];
$size = rand($font_size-2, $font_size+2);
imagettftext($src, $size, rand(0,45), rand($width*0.1,$width-$width*0.1), rand($height*0.2,$height), $color, $font, $char);
}
$i = 0;
for($i; $i < $symbols; $i+=1)
{
$color = imagecolorallocatealpha($src, $colors[rand(0,sizeof($colors)-1)], $colors[rand(0,sizeof($colors)-1)], $colors[rand(0,sizeof($colors)-1)], rand(20,40));
$char = $chars[rand(0, sizeof($chars)-1)];
$size = rand($font_size*2.1-2, $font_size*2.1+2);
$x = ($i+1)*$font_size + rand(6,8);
$y = (($height*2)/3) + rand(3,7);
$cod .= $char;
imagettftext($src, $size, rand(0,15), $x, $y, $color, $font, $char);
}
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
$mcache->set($type.'_captcha_'.$ip, $cod, false, 120);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
header("Content-type: image/gif");
imagegif($src);
imagedestroy($src);
exit;
}
2023-11-11 20:56:12 +00:00
public static function captcha_check($type, $ip, $cod = '')
{
global $cfg, $mcache;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
// Если повтор ввода капчи выключен и в кеше есть подтвержденный сеанс
if(!$cfg['recaptcha'] AND $mcache->get($type.'_captcha_valid_'.$ip))
return false;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($mcache->get($type.'_captcha_'.$ip) != strtolower($cod))
{
$mcache->set($type.'_captcha_valid_'.$ip, true, false, 60);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return true;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function ismail($data)
{
$aData = explode('@', $data);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(count($aData) > 1)
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function smscode()
{
return rand(1,9).rand(100,500).rand(10,99);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function code($length = 8)
{
$list = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz0123456789';
$a = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwXxYyZz';
$selections = strlen($list)-1;
$start = strlen($a)-1;
$b = rand(0, $start);
$start = $a[$b];
$code = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$i = 0;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
for($i; $i <= $length-2; $i+=1)
{
$n = rand(0, $selections);
$code[] = $list[$n];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $start.implode('', $code);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function sms($text, $phone)
{
global $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$out = file_get_contents($cfg['sms_gateway'].'&'.$cfg['sms_to'].'='.$phone.'&'.$cfg['sms_text'].'='.urlencode($text));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$aOut = explode("\n", $out);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(trim($aOut[0]) == $cfg['sms_ok'])
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function find($text, $find)
{
$words = explode(' ', $find);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($words as $word)
if(strlen($word) >= 2)
$text = preg_replace('#'.quotemeta($word).'#iu', '<span style="color: #F66A6A;">$0</span>', $text);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $text;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function str_first_replace($search, $replace, $text)
{
$pos = strpos($text, $search);
return $pos!==false ? substr_replace($text, $replace, $pos, strlen($search)) : $text;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function cmd($command)
{
$text = preg_replace('/\\$/', '$ы', trim($command));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
mb_internal_encoding('UTF-8');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(mb_substr($text, -1) == 'ы')
$text = quotemeta(substr($text, 0, -2));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $text;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function map($map)
{
$name = quotemeta(trim($map));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(substr($name, -1) == '$')
$name = substr($name, 0, -2).'$';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return str_replace(array('\.', '\*'), array('.', '*'), $name);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function temp($text)
{
$temp = TEMP.md5(time().rand(5, 100).rand(10, 20).rand(1, 20).rand(40, 80));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$file = fopen($temp, "w");
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
fputs($file, $text);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
fclose($file);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $temp;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function size($val)
{
$aSize = array(' Байт', ' Кб', ' Мб', ' Гб', ' Тб', ' Пб');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $val ? round($val/pow(1024, ($i = floor(log($val, 1024)))), 2) . $aSize[$i] : '0 Байт';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function unidate($date)
{
$aDate = explode('-', $date);
$aFirst = explode(' ', $aDate[2]);
return $aFirst[1].' - '.$aFirst[0].'.'.$aDate[1].'.'.$aDate[0];
}
public static function page($page, $nums, $num)
{
$ceil = ceil($nums/$num);
if($page > $ceil)
$page = $ceil;
$next = $page*$num;
if($next <= $nums)
$next = $next-$num;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($next > $nums)
$next = $next-$num;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($next < 1)
$next = 0;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$num_go = $next;
if($page == '')
$page = 1;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$aPage = array(
'page' => $page,
'num' => $num_go,
'ceil' => $ceil
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $aPage;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function page_list($countnum, $actnum)
{
if($countnum == 0 || $countnum == 1)
return array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($countnum > 10)
{
if($actnum <= 4 || $actnum + 3 >= $countnum)
{
for($i = 0; $i <= 4; $i++)
$numlist[$i] = $i + 1;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$numlist[5] = '...';
for($j = 6, $k = 4; $j <= 10; $j+=1, $k-=1)
$numlist[$j] = $countnum - $k;
}else{
$numlist[0] = 1;
$numlist[1] = 2;
$numlist[2] = '...';
$numlist[3] = $actnum - 2;
$numlist[4] = $actnum - 1;
$numlist[5] = $actnum;
$numlist[6] = $actnum + 1;
$numlist[7] = $actnum + 2;
$numlist[8] = '...';
$numlist[9] = $countnum - 1;
$numlist[10] = $countnum;
}
}else
for($n = 0; $n < $countnum; $n+=1)
$numlist[$n] = $n + 1;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $numlist;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function page_gen($ceil, $page, $actnum, $section)
{
global $cfg, $html;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$aNum = sys::page_list($ceil, $actnum);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$pages = '';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('pages');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($ceil)
{
if($page != 1)
{
$next = $page-1;
$pages .= '<a href="'.$cfg['http'].$section.'/page/'.$next.'"><span>Предыдущая</span></a>';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($aNum as $v)
{
if($v != $page && $v != '...')
$pages .= '<a href="'.$cfg['http'].$section.'/page/'.$v.'">'.$v.'</a>';
if($v == $page)
$pages .= '<a href="#" onclick="return false" class="active">'.$v.'</a>';
if($v == '...')
$pages .= '<a href="#" onclick="return false">...</a>';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($ceil > $page)
{
if($page < $ceil)
{
$next = $page+1;
$pages .= '<a href="'.$cfg['http'].$section.'/page/'.$next.'"><span class="num_right">Следующая</span></a>';
}else
$pages .= '<a href="#" onclick="return false;"><span class="num_right">Следующая</span></a>';
}
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('pages', $pages);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('pages');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function country($name)
{
global $cfg;
$fileimg = file_exists(TPL.'/images/country/'.$name.'.png');
if($fileimg)
return $cfg['http'].'template/images/country/'.$name.'.png';
return $cfg['http'].'template/images/country/none.png';
}
public static function ipproxy()
{
global $_SERVER;
if(isset($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP']))
return $_SERVER['HTTP_CF_CONNECTING_IP'];
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function ip()
{
$ip = sys::ipproxy();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(sys::valid($ip, 'ip'))
return $_SERVER['REMOTE_ADDR'];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $ip;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function whois($ip)
{
$stack = fsockopen('whois.ripe.net', 43, $errno, $errstr);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$stack)
return 'не определена';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
fputs($stack, $ip."\r\n");
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$subnetwork = '';
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
while(!feof($stack))
{
$str = fgets($stack, 128);
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
if(strpos($str, 'route:') !== FALSE)
{
$subnetwork = trim(str_replace('route:', '', $str));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
break;
}
}
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
fclose($stack);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return isset($subnetwork{0}) ? $subnetwork : 'не определена';
}
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
public static function rep_act($name, $time = 20)
{
global $go, $mcache;
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
if(!$go)
return NULL;
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
if($mcache->get($name))
sys::outjs(array('e' => sys::text('other', 'mcache')));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$mcache->set($name, true, false, $time);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $name;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function check_php_config($file, &$error)
{
exec('php -l '.$file, $error, $code);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$code)
return true;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function cpu_idle($pros_stat = array(), $unit, $fcpu = false, $ctrl = false)
{
return sys::cpu_get_idle(sys::parse_cpu($pros_stat[0]), sys::parse_cpu($pros_stat[1]), $unit, $fcpu, $ctrl);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function cpu_get_idle($first, $second, $unit, $fcpu, $ctrl)
{
global $sql;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(count($first) !== count($second))
return;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$cpus = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
for($i = 0, $l = count($first); $i < $l; $i+=1)
{
$dif = array();
$dif['use'] = $second[$i]['use']-$first[$i]['use'];
$dif['nice'] = $second[$i]['nice']-$first[$i]['nice'];
$dif['sys'] = $second[$i]['sys']-$first[$i]['sys'];
$dif['idle'] = $second[$i]['idle']-$first[$i]['idle'];
$total = array_sum($dif);
$cpu = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($dif as $x => $y)
$cpu[$x] = $y ? round($y/$total*100, 1) : 0;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$cpus['cpu'.$i] = $cpu;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($fcpu)
return $cpus;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$threads = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$l = count($first);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
for($i = 0; $i < $l; $i+=1)
$threads[$i] = $cpus['cpu'.$i]['idle'];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(count($first) > 1)
unset($threads[0]);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$max = max($threads);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($threads as $idle)
{
$core = array_search($max, $threads);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($ctrl)
$sql->query('SELECT `id` FROM `control_servers` WHERE `unit`="'.$unit.'" AND `core_fix`="'.($core+1).'" LIMIT 1');
else
$sql->query('SELECT `id` FROM `servers` WHERE `unit`="'.$unit.'" AND `core_fix`="'.($core+1).'" AND `core_fix_one`="1" LIMIT 1');
if($sql->num())
{
unset($threads[$core]);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!count($threads))
return NULL;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$max = max($threads);
}
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return array_search($max, $threads);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function parse_cpu($data)
{
$data = explode("\n", $data);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$cpu = array();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($data as $line)
{
if(preg_match('/^cpu[0-9]/', $line))
{
$info = explode(' ', $line);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$cpu[] = array(
'use' => $info[1],
'nice' => $info[2],
'sys' => $info[3],
'idle' => $info[4]
);
}
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $cpu;
}
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
public static function reset_mcache($nmch, $id, $data = array(), $ctrl = false)
{
global $mcache;
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
$cache = array(
'name' => $data['name'],
'status' => sys::status($data['status'], $data['game']),
'online' => $data['online'],
'image' => '<img src="'.sys::status($data['status'], $data['game'], '', 'img').'">',
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$cache = $ctrl ? sys::buttons($id, $data['status'], $data['game'], $ctrl) : sys::buttons($id, $data['status'], $data['game']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(isset($data['players']))
$cache['players'] = $data['players'];
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$mcache->set($nmch, $cache, false, 5);
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function status($status, $game, $map = '', $get = 'text')
{
global $cfg;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
switch($status)
{
case 'working':
if($get == 'img')
{
if(in_array($game, array('samp', 'crmp', 'mta', 'mc')))
$map = $game;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return sys::img($map, $game);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Карта: '.($map == '' ? '-' : $map);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'off':
if($get == 'img')
return $cfg['http'].'template/images/status/off.jpg';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #C46666;">выключен</span>';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'start':
if($get == 'img')
return $cfg['http'].'template/images/status/start.gif';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #22B93C;">запускается</span>';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'restart':
if($get == 'img')
return $cfg['http'].'template/images/status/restart.gif';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #22B93C;">перезапускается</span>';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'change':
if($get == 'img')
return $cfg['http'].'template/images/status/change.gif';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #52BEFC;">меняется карта</span>';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'install':
if($get == 'img')
return $cfg['http'].'template/images/status/install.gif';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #22B93C;">устанавливается</span>';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'reinstall':
if($get == 'img')
return $cfg['http'].'template/images/status/reinstall.gif';
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #22B93C;">переустанавливается</span>';
2023-03-05 13:59:34 +00:00
2023-11-11 20:56:12 +00:00
case 'update':
if($get == 'img')
return $cfg['http'].'template/images/status/update.gif';
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #F2CF41;">обновляется</span>';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'recovery':
if($get == 'img')
return $cfg['http'].'template/images/status/recovery.gif';
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: <span style="color: #22B93C;">восстанавливается</span>';
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
case 'overdue':
if($get == 'img')
return $cfg['http'].'template/images/status/overdue.jpg';
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: просрочен';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
case 'blocked':
if($get == 'img')
return $cfg['http'].'template/images/status/blocked.jpg';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return 'Статус: заблокирован';
}
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function img($name, $game)
{
global $cfg;
$filename = 'http://cdn.enginegp.ru/maps/'.$game.'/'.$name.'.jpg';
$file_headers = @get_headers($filename) ;
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://";
if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found' ||trim($file_headers[0]) == 'HTTP/1.1 403 Forbidden') {
return $cfg['http'].'template/images/status/none.jpg';
}
else {
return '' . $protocol .'cdn.enginegp.ru/maps/'.$game.'/'.$name.'.jpg';
}
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function buttons($id, $status, $game = false, $ctrl = false)
{
global $html;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(isset($html->arr['buttons']))
unset($html->arr['buttons']);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$other = in_array($game, array('samp', 'crmp', 'mta', 'mc'));
2023-05-05 01:17:19 +00:00
2023-11-11 20:56:12 +00:00
$dir = $ctrl ? 'control/servers' : 'servers';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(in_array($status, array('working', 'change', 'start', 'restart')))
{
$html->get('stop', 'sections/'.$dir.'/buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $id);
if($ctrl)
$html->set('ctrl', $ctrl);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('restart', 'sections/'.$dir.'/buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $id);
if($ctrl)
$html->set('ctrl', $ctrl);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$other)
{
$html->get('change', 'sections/'.$dir.'/buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $id);
if($ctrl)
$html->set('ctrl', $ctrl);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('buttons');
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $html->arr['buttons'];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($status == 'off')
{
$html->get('start', 'sections/'.$dir.'/buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $id);
if($ctrl)
$html->set('ctrl', $ctrl);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('reinstall', 'sections/'.$dir.'/buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $id);
if($ctrl)
$html->set('ctrl', $ctrl);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(!$other)
{
$html->get('update', 'sections/'.$dir.'/buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->set('id', $id);
if($ctrl)
$html->set('ctrl', $ctrl);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->pack('buttons');
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $html->arr['buttons'];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$html->get('other', 'sections/'.$dir.'/buttons');
$html->pack('buttons');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $html->arr['buttons'];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function entoru($month)
{
$ru = array(
1 => 'Янв', 2 => 'Фев', 3 => 'Мар', 4 => 'Апр',
5 => 'Май', 6 => 'Июн', 7 => 'Июл', 8 => 'Авг',
9 => 'Сен', 10 => 'Окт', 11 => 'Ноя', 12 => 'Дек'
);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $ru[$month];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function head($head)
{
global $route, $header;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($head == 'description')
{
global $description;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(isset($description))
{
$text = str_replace(array('"', '-'), array('', '—'), strip_tags($description));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(strlen($text) > 160)
{
mb_internal_encoding('UTF-8');
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$text = mb_substr($text, 0, 157).'...';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return $text;
}
}else{
global $keywords;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if(isset($keywords))
return str_replace(array('"', '-'), array('', '—'), strip_tags($keywords));
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return array_key_exists($route, $header) ? $header[$route][$head] : $header['index'][$head];
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function tags($tags)
{
$aTags = explode(',', $tags);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
$text = '';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
foreach($aTags as $tag)
$text .= '<strong>'.trim($tag).'</strong>, ';
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return isset($text{0}) ? substr($text, 0, -2) : 'отсутствуют';
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
public static function benefitblock($id, $nmch = false)
{
global $cfg, $sql, $start_point;
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($cfg['benefitblock'])
{
$sql->query('SELECT `benefit` FROM `servers` WHERE `id`="'.$id.'" LIMIT 1');
$info = $sql->get();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($info['benefit'] > $start_point)
sys::outjs(array('e' => 'Операция недоступна до '.date('d.m.Y - H:i:s', $info['benefit'])), $nmch);
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
function outfile($file, $name, $del = false)
{
if(file_exists($file))
{
if(ob_get_level())
ob_end_clean();
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: '.filesize($file));
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
readfile($file);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
if($del)
unlink($file);
2023-03-04 23:45:46 +00:00
2023-11-11 20:56:12 +00:00
exit;
}
}
}
?>