EngineGP/system/library/acpsystem.php

707 lines
19 KiB
PHP
Raw Normal View History

2023-03-04 23:45:46 +00:00
<?php
2023-05-05 01:17:19 +00:00
if (!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://' . $_SERVER['SERVER_NAME'] . '/404'));
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
class sys
{
public static function url($all = true)
2023-03-05 13:59:34 +00:00
{
2023-05-05 01:17:19 +00:00
if ($_SERVER['REQUEST_URI'] == '/acp/')
return $all ? NULL : 'index';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$url = array();
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +00:00
array_shift($aUrl);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (!$all)
return $aUrl[0];
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
unset($aUrl[0]);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$i = 1;
$m = count($aUrl) + 1;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +00:00
return $url;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function int($data, $width = false)
{
if ($width)
return preg_replace("([^0-9]{0, " . $width . "})", '', $data);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return preg_replace("([^0-9])", '', $data);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function first($array = array())
{
return $array[0];
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function b64js($data)
{
return base64_encode(json_encode($data));
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function b64djs($data)
{
return json_decode(base64_decode($data), true);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function outjs($val, $cache = false)
{
global $mcache;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($cache)
$mcache->delete($cache);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
die(json_encode($val));
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function out($val = '', $cache = false)
{
global $mcache;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($cache)
$mcache->delete($cache);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
die('' . $val . '');
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function valid($val, $type, $preg = '')
{
$val = isset($val) ? $val : '';
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-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
case 'en':
if (!preg_match("/^[A-Za-z0-9]$/", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
case 'ru':
if (!preg_match("/^[А-Яа-я]$/u", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
case 'steamid3':
if (!preg_match("/^\[U:[01]:[0-9]{3,12}\]$/i", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
case 'num':
if (!preg_match('/[^0-9]/', $val))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
case 'md5':
if (!preg_match("/^[a-z0-9]{32,32}$/", $val))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
case 'other':
if (!preg_match($preg, $val))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
2023-03-05 13:59:34 +00:00
}
2023-05-05 01:17:19 +00:00
return true;
}
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
public static function page($page, $nums, $num)
{
$ceil = ceil($nums / $num);
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
if ($page > $ceil)
$page = $ceil;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$next = $page * $num;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($next <= $nums)
$next = $next - $num;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($next > $nums)
$next = $next - $num;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($next < 1)
$next = 0;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$num_go = $next;
if ($page == '')
$page = 1;
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
$aPage = array(
'page' => $page,
'num' => $num_go,
'ceil' => $ceil
);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $aPage;
}
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
public static function page_list($countnum, $actnum)
{
if ($countnum == 0 || $countnum == 1)
return array();
if ($countnum > 10) {
if ($actnum <= 4 || $actnum + 3 >= $countnum) {
for ($i = 0; $i <= 4; $i++)
$numlist[$i] = $i + 1;
$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-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
return $numlist;
}
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
public static function page_gen($ceil, $page, $actnum, $section)
{
global $cfg, $html;
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
$aNum = sys::page_list($ceil, $actnum);
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
$pages = '';
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
$html->get('pages');
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
if ($ceil) {
if ($page != 1) {
$next = $page - 1;
$pages .= '<a href="' . $cfg['http'] . $section . '/page/' . $next . '"><i class="fa fa-angle-double-left"></i></a>';
}
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
foreach ($aNum as $v) {
if ($v != $page && $v != '...')
$pages .= '<a href="' . $cfg['http'] . $section . '/page/' . $v . '">' . $v . '</a>';
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
if ($v == $page)
$pages .= '<a href="#" onclick="return false" class="active">' . $v . '</a>';
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
if ($v == '...')
$pages .= '<a href="#" onclick="return false">...</a>';
}
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
if ($ceil > $page) {
if ($page < $ceil) {
$next = $page + 1;
$pages .= '<a href="' . $cfg['http'] . $section . '/page/' . $next . '"><i class="fa fa-angle-double-right"></i></a>';
} else
$pages .= '<a href="#" onclick="return false;"><i class="fa fa-angle-double-right"></i></a>';
}
2023-03-05 13:59:34 +00:00
}
2023-05-05 01:17:19 +00:00
$html->set('pages', $pages);
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
$html->pack('pages');
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function ago($time, $brackets = false)
{
global $start_point;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$diff = $start_point - $time;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($diff < 0)
return '';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (!$diff)
$diff = 1;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$seconds = array('секунду', 'секунды', 'секунд');
$minutes = array('минуту', 'минуты', 'минут');
$hours = array('час', 'часа', 'часов');
$days = array('день', 'дня', 'дней');
$weeks = array('неделю', 'недели', 'недель');
$months = array('месяц', 'месяца', 'месяцев');
$years = array('год', 'года', 'лет');
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$phrase = array($seconds, $minutes, $hours, $days, $weeks, $months, $years);
$length = array(1, 60, 3600, 86400, 604800, 2630880, 31570560);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
for ($i = 6; ($i >= 0) and (($no = $diff / $length[$i]) <= 1); $i -= 1) ;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($i < 0)
$i = 0;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$_time = $start_point - ($diff % $length[$i]);
$no = ceil($no);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($brackets)
return '(' . $no . ' ' . sys::parse_ago($no, $phrase[$i]) . ' назад)';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $no . ' ' . sys::parse_ago($no, $phrase[$i]) . ' назад';
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
private static function parse_ago($number, $titles)
{
$cases = array(2, 0, 1, 1, 1, 2);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $titles[($number % 100 > 4 and $number % 100 < 20) ? 2 : $cases[min($number % 10, 5)]];
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function date($lenght, $date)
{
global $start_point;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$check_time = $date - $start_point;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($check_time < 1)
return 'время истекло.';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +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-05-05 01:17:19 +00:00
$text = '';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($days > 0)
$text .= sys::date_decl($days, $adata[$lenght]['days']);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +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-05-05 01:17:19 +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-05-05 01:17:19 +00:00
return $text;
}
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-05-05 01:17:19 +00:00
if (empty($expr[2]))
$expr[2] = $expr[1];
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$i = sys::int($digit) % 100;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($onlyword)
$digit = '';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($i > 4 and $i < 21)
$res = $digit . ' ' . $expr[2];
else
$i %= 10;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +00:00
return trim($res);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function today($time, $cp = false)
{
global $start_point;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$today = date('d.m.Y', $start_point);
$day = date('d.m.Y', $time);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($day == $today) {
if ($cp)
return 'Сегодня ' . date('H:i', $time);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return 'Сегодня ' . date('- H:i', $time);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +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-05-05 01:17:19 +00:00
return 'Вчера ' . date('- H:i', $time);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($cp)
return date('d.m.Y H:i', $time);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return date('d.m.Y - H:i', $time);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function browser($agent)
{
if (strpos($agent, 'Firefox') !== false)
return 'Mozilla Firefox';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (strpos($agent, 'Opera') !== false)
return 'Opera';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (strpos($agent, 'Chrome') !== false)
return 'Google Chrome';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (strpos($agent, 'MSIE') !== false)
return 'Internet Explorer';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (strpos($agent, 'Safari') !== false)
return 'Safari';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return 'Неизвестный';
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function whois($ip)
{
$stack = fsockopen('whois.ripe.net', 43, $errno, $errstr);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (!$stack)
return 'не определена';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
fputs($stack, $ip . "\r\n");
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$subnetwork = '';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
while (!feof($stack)) {
$str = fgets($stack, 128);
if (strpos($str, 'route:') !== FALSE) {
$subnetwork = trim(str_replace('route:', '', $str));
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
break;
}
2023-03-05 13:59:34 +00:00
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
fclose($stack);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return isset($subnetwork[0]) ? $subnetwork : 'не определена';
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function uptime_load($time)
{
$uptime = '';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$day = floor($time / 60 / 60 / 24);
if ($day)
$uptime .= $day . 'д. ';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$hour = (int)($time / 60 / 60) % 24;
if ($hour)
$uptime .= $hour . 'ч. ';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$min = (int)($time / 60) % 60;
if ($min)
$uptime .= $min . 'м. ';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $uptime . ($time % 60) . 'с.';
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function ram_load($data)
{
$aData = explode(' ', $data);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return ceil(($aData[0] - ($aData[1] + $aData[2] + $aData[3])) * 100 / $aData[0]);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function cpu_load($data)
{
$aData = explode(' ', $data);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$load = ceil($aData[0] / $aData[1]);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $load > 100 ? 100 : $load;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function cpu_idle($pros_stat = array(), $fcpu = false)
{
return sys::cpu_get_idle(sys::parse_cpu($pros_stat[0]), sys::parse_cpu($pros_stat[1]), $fcpu);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function cpu_get_idle($first, $second, $fcpu)
{
if (count($first) !== count($second))
return;
$cpus = array();
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);
2023-03-05 13:59:34 +00:00
$cpu = array();
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +00:00
$cpus['cpu' . $i] = $cpu;
2023-03-05 13:59:34 +00:00
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if ($fcpu)
return $cpus;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$threads = array();
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$l = count($first);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
for ($i = 0; $i < $l; $i += 1)
$threads[$i] = $cpus['cpu' . $i]['idle'];
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (count($first) > 1)
unset($threads[0]);
$max = max($threads);
return array_search($max, $threads);
}
public static function parse_cpu($data)
{
$data = explode("\n", $data);
$cpu = array();
foreach ($data as $line) {
if (preg_match('/^cpu[0-9]/', $line)) {
$info = explode(' ', $line);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$cpu[] = array(
'use' => $info[1],
'nice' => $info[2],
'sys' => $info[3],
'idle' => $info[4]
);
}
2023-03-05 13:59:34 +00:00
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $cpu;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function checkdate($time)
{
$time = explode(' ', $time);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (count($time) != 2)
sys::outjs(array('e' => 'Указанная дата неправильная.'));
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$aDate = explode('/', $time[0]);
$aTime = explode(':', $time[1]);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (!isset($aDate[1], $aDate[0], $aDate[2]) || !checkdate($aDate[1], $aDate[0], $aDate[2]))
sys::outjs(array('e' => 'Указанная дата неправильная.'));
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return mktime($aTime[0], $aTime[1], 0, $aDate[1], $aDate[0], $aDate[2]);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function passwdkey($passwd)
{
return md5($passwd);
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function mail($name, $text, $mail)
{
global $cfg;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
require_once(LIB . 'smtp.php');
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$tpl = file_get_contents(DATA . 'mail.ini', "r");
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +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-05-05 01:17:19 +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-05-05 01:17:19 +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-05-05 01:17:19 +00:00
if ($smtp->send($mail, $name, $text, $headers))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function country($address)
{
global $SxGeo;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (sys::valid($address, 'ip'))
return 'не определена';
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
$data = $SxGeo->getCityFull($address);
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $data['country']['name_ru'] != '' ? $data['country']['name_ru'] : 'не определена';
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function ipproxy()
{
global $_SERVER;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP']))
return $_SERVER['HTTP_CF_CONNECTING_IP'];
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return NULL;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function ip()
{
$ip = sys::ipproxy();
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
if (sys::valid($ip, 'ip'))
return $_SERVER['REMOTE_ADDR'];
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return $ip;
}
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
public static function status($data)
{
if (strpos($data, 'is running') || strpos($data, '(running)'))
return true;
2023-03-04 23:45:46 +00:00
2023-05-05 01:17:19 +00:00
return false;
}
2023-03-05 13:59:34 +00:00
2023-05-05 01:17:19 +00:00
public static function strlen($str)
{
return iconv_strlen($str, 'UTF-8');
}
2023-04-13 13:36:34 +00:00
2023-05-05 01:17:19 +00:00
public static function bbc($text)
{
global $cfg;
$lines = explode("\n", $text);
$str_search = array(
"#\[spoiler\](.+?)\[\/spoiler\]#is",
"#\[sp\](.+?)\[\/sp\]#is",
"#\[b\](.+?)\[\/b\]#is",
"#\[u\](.+?)\[\/u\]#is",
"#\[code\](.+?)\[\/code\]#is",
"#<code>(.+?)<\/code>#isUe",
"#\[quote\](.+?)\[\/quote\]#is",
"#\[url=(.+?)\](.+?)\[\/url\]#is",
"#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is"
);
$str_replace = array(
"<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>",
"'<code>'.htmlspecialchars('$1').'</code>'",
"<blockquote><p>\\1</p></blockquote>",
"<a href='\\1'>\\2</a>",
"<a href='\\2'>\\2</a>"
);
$uptext = '';
foreach ($lines as $line)
$uptext .= preg_replace($str_search, $str_replace, $line) . PHP_EOL;
return $uptext;
}
public static function text($section, $name)
{
global $cfg, $user;
$group = isset($user['group']) ? $user['group'] : 'user';
if ($section != 'error' || !$cfg['text_group'])
$group = 'all';
include(DATA . 'text/' . $section . '.php');
return isset($text[$name][$group]) ? $text[$name][$group] : $text[$name];
2023-03-05 13:59:34 +00:00
}
2023-05-05 01:17:19 +00:00
public static function updtext($text, $data)
{
foreach ($data as $name => $val)
$text = str_replace('[' . $name . ']', $val, $text);
return $text;
}
public static function logMessage($message, $logFile = 'enginegp_info', $context = [])
{
$logger = new \Monolog\Logger('EngineGP');
$logger->pushHandler(new \Monolog\Handler\StreamHandler(DIR . 'logs/' . $logFile . '.log'));
2023-05-05 01:17:19 +00:00
$logger->info($message, $context);
}
}
2023-03-04 23:45:46 +00:00
?>