admins.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. if (!DEFINED('EGP'))
  3. exit(header('Refresh: 0; URL=http://' . $_SERVER['SERVER_NAME'] . '/404'));
  4. $html->nav('Управление администраторами');
  5. if ($go) {
  6. $sql->query('SELECT `address`, `passwd` FROM `units` WHERE `id`="' . $server['unit'] . '" LIMIT 1');
  7. $unit = $sql->get();
  8. $sql->query('SELECT `install` FROM `tarifs` WHERE `id`="' . $server['tarif'] . '" LIMIT 1');
  9. $tarif = $sql->get();
  10. include(LIB . 'ssh.php');
  11. if (!$ssh->auth($unit['passwd'], $unit['address']))
  12. sys::outjs(array('e' => sys::text('error', 'ssh')), $nmch);
  13. $aData = array();
  14. $aData['active'] = isset($_POST['active']) ? $_POST['active'] : '';
  15. $aData['value'] = isset($_POST['value']) ? $_POST['value'] : '';
  16. $aData['passwd'] = isset($_POST['passwd']) ? $_POST['passwd'] : '';
  17. $aData['flags'] = isset($_POST['flags']) ? $_POST['flags'] : '';
  18. $aData['immunity'] = isset($_POST['immunity']) ? sys::int($_POST['immunity']) : '';
  19. $aData['time'] = isset($_POST['time']) ? $_POST['time'] : '';
  20. $aData['info'] = isset($_POST['info']) ? $_POST['info'] : '';
  21. // Удаление текущих записей
  22. $sql->query('DELETE FROM `admins_' . $server['game'] . '` WHERE `server`="' . $id . '"');
  23. $usini = '';
  24. foreach ($aData['value'] as $index => $val) {
  25. if ($val != '') {
  26. $aDate = isset($aData['time'][$index]) ? explode('.', $aData['time'][$index]) : explode('.', date('d.m.Y', $start_point));
  27. if (!isset($aDate[1], $aDate[0], $aDate[2]) || !checkdate($aDate[1], $aDate[0], $aDate[2]))
  28. $aDate = explode('.', date('d.m.Y', $start_point));
  29. $time = mktime(0, 0, 0, $aDate[1], $aDate[0], $aDate[2]);
  30. $aData['active'][$index] = isset($aData['active'][$index]) ? 1 : 0;
  31. $aData['passwd'][$index] = isset($aData['passwd'][$index]) ? $aData['passwd'][$index] : '';
  32. $aData['flags'][$index] = isset($aData['flags'][$index]) ? $aData['flags'][$index] : '';
  33. $aData['info'][$index] = isset($aData['info'][$index]) ? $aData['info'][$index] : '';
  34. $text = '"' . $val . '" "' . $aData['immunity'][$index] . ':' . $aData['flags'][$index] . '" "' . $aData['passwd'][$index] . '"';
  35. $sql->query('INSERT INTO `admins_' . $server['game'] . '` set'
  36. . '`server`="' . $id . '",'
  37. . '`value`="' . htmlspecialchars($val) . '",'
  38. . '`active`="' . $aData['active'][$index] . '",'
  39. . '`passwd`="' . htmlspecialchars($aData['passwd'][$index]) . '",'
  40. . '`flags`="' . htmlspecialchars($aData['flags'][$index]) . '",'
  41. . '`immunity`="' . $aData['immunity'][$index] . '",'
  42. . '`time`="' . $time . '",'
  43. . '`text`="' . htmlspecialchars($text) . '",'
  44. . '`info`="' . htmlspecialchars($aData['info'][$index]) . '"');
  45. if ($aData['active'][$index])
  46. $usini .= $text . PHP_EOL;
  47. }
  48. }
  49. $temp = sys::temp($usini);
  50. $ssh->setfile($temp, $tarif['install'] . $server['uid'] . '/game/csgo/addons/sourcemod/configs/admins_simple.ini', 0644);
  51. unlink($temp);
  52. $ssh->set('chown server' . $server['uid'] . ':servers ' . $tarif['install'] . $server['uid'] . '/game/csgo/addons/sourcemod/configs/admins_simple.ini');
  53. $ssh->set("sudo -u server" . $server['uid'] . " screen -p 0 -S s_" . $server['uid'] . " -X eval 'stuff \" sm_reloadadmins\"\015'");
  54. sys::outjs(array('s' => 'ok'), $nmch);
  55. }
  56. // Построение списка добавленных админов
  57. $sql->query('SELECT `id`, `value`, `active`, `passwd`, `flags`, `immunity`, `time`, `info` FROM `admins_' . $server['game'] . '` WHERE `server`="' . $id . '" ORDER BY `id` ASC');
  58. while ($admin = $sql->get()) {
  59. $html->get('list', 'sections/servers/' . $server['game'] . '/settings/admins');
  60. if ($admin['active'])
  61. $html->unit('active', 1);
  62. else
  63. $html->unit('active');
  64. $html->set('id', $admin['id']);
  65. $html->set('value', $admin['value']);
  66. $html->set('passwd', $admin['passwd']);
  67. $html->set('flags', $admin['flags']);
  68. $html->set('immunity', $admin['immunity']);
  69. $html->set('time', date('d.m.y', $admin['time']));
  70. $html->set('info', $admin['info']);
  71. $html->pack('admins');
  72. }
  73. $sql->query('SELECT `id` FROM `admins_' . $server['game'] . '` WHERE `server`="' . $id . '" ORDER BY `id` DESC LIMIT 1');
  74. $max = $sql->get();
  75. $html->get('admins', 'sections/servers/' . $server['game'] . '/settings');
  76. $html->set('id', $id);
  77. $html->set('admins', isset($html->arr['admins']) ? $html->arr['admins'] : '');
  78. $html->set('index', $max['id'] < 1 ? 0 : $max['id']);
  79. $html->pack('main');
  80. ?>