plugins.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. if(!DEFINED('EGP'))
  3. exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
  4. class plugins
  5. {
  6. public static function images($images, $plugin)
  7. {
  8. global $html;
  9. if(empty($images)) return NULL;
  10. if(isset($html->arr['images']))
  11. unset($html->arr['images']);
  12. $aImg = explode("\n", $images);
  13. foreach($aImg as $img)
  14. {
  15. $html->get('plugin_images', 'sections/control/servers/games/plugins');
  16. $html->set('id', $plugin);
  17. $html->set('img', $img);
  18. $html->pack('images');
  19. }
  20. return isset($html->arr['images']) ? $html->arr['images'] : '';
  21. }
  22. public static function status($status)
  23. {
  24. global $html;
  25. if(!$status)
  26. {
  27. $html->unit('unstable');
  28. $html->unit('stable', 1);
  29. $html->unit('testing');
  30. }elseif($status == 2){
  31. $html->unit('unstable');
  32. $html->unit('stable');
  33. $html->unit('testing', 1);
  34. }else{
  35. $html->unit('unstable', 1);
  36. $html->unit('stable');
  37. $html->unit('testing');
  38. }
  39. return NULL;
  40. }
  41. public static function required($id, $required, $choice, $mcache)
  42. {
  43. global $sql;
  44. if($required == '')
  45. return NULL;
  46. $aRequi = explode(':', $required);
  47. foreach($aRequi as $pl)
  48. {
  49. $sql->query('SELECT `id` FROM `control_plugins_install` WHERE `server`="'.$sid.'" AND `plugin`="'.$pl.'" LIMIT 1');
  50. if(!$sql->num())
  51. {
  52. $sql->query('SELECT `name` FROM `plugins` WHERE `id`="'.$pl.'" LIMIT 1');
  53. $plRequi = $sql->get();
  54. if($choice != '')
  55. {
  56. $aChoice = explode(' ', $choice);
  57. foreach($aChoice as $plugins)
  58. {
  59. $aPlugins = explode(':', $plugins);
  60. if(in_array($pl, $aPlugins))
  61. {
  62. $options = '';
  63. foreach($aPlugins as $plugin)
  64. {
  65. $sql->query('SELECT `name`, `upd` FROM `plugins` WHERE `id`="'.$plugin.'" LIMIT 1');
  66. $data = $sql->get();
  67. if($data['upd'])
  68. {
  69. $sql->query('SELECT `name` FROM `plugins_update` WHERE `plugin`="'.$plugin.'" ORDER BY `id` DESC LIMIT 1');
  70. $data = $sql->get();
  71. }
  72. $options .= '<option value="'.$plugin.'">'.strip_tags($data['name']).'</option>';
  73. }
  74. if($options != '')
  75. sys::outjs(array('e' => 'Для данного плагина требуется установка одного из родителя', 'required' => true, 'pid' => $pl, 'select' => $options), $mcache);
  76. }
  77. }
  78. }
  79. sys::outjs(array('e' => 'Для данного плагина требуется установка родителя', 'required' => true, 'pid' => $pl, 'pname' => htmlspecialchars_decode($plRequi['name'])), $mcache);
  80. }
  81. }
  82. return NULL;
  83. }
  84. public static function incompatible($id, $incompatible, $mcache)
  85. {
  86. global $sql;
  87. if($incompatible == '')
  88. return NULL;
  89. $aIncomp = explode(':', $incompatible);
  90. foreach($aIncomp as $pl)
  91. {
  92. $sql->query('SELECT `id` FROM `control_plugins_install` WHERE `server`="'.$sid.'" AND `plugin`="'.$pl.'" LIMIT 1');
  93. if($sql->num())
  94. {
  95. $sql->query('SELECT `name` FROM `plugins` WHERE `id`="'.$pl.'" LIMIT 1');
  96. $plIncomp = $sql->get();
  97. sys::outjs(array('e' => 'Данный плагин несовместим с уже установленным плагином', 'pid' => $pl, 'pname' => htmlspecialchars_decode($plIncomp['name'])), $mcache);
  98. }
  99. }
  100. return NULL;
  101. }
  102. public static function clear($clear, $uid, $dir)
  103. {
  104. global $ssh;
  105. // Если регулярное выражение
  106. if(isset($clear['regex']) AND $clear['regex'])
  107. {
  108. $file = preg_replace($clear['text'], '', $ssh->get('sudo -u server'.$uid.' cat '.$dir.$clear['file']));
  109. // Временный файл
  110. $temp = sys::temp($file);
  111. $ssh->setfile($temp, $dir.$clear['file'], 0644);
  112. unlink($temp);
  113. $query = 'chown server'.$uid.':servers '.$dir.$clear['file'].';';
  114. }else
  115. // Удаление текста из файла
  116. $query = 'sudo -u server'.$uid.' sed -i '."'s/".str_replace('/', '\/', htmlspecialchars_decode($clear['text']))."//g'".' '.$dir.$clear['file'].';';
  117. $ssh->set($query.'sudo -u server'.$uid.' sed -i '."'/./!d'".' '.$dir.$clear['file']);
  118. return NULL;
  119. }
  120. public static function write($write, $uid, $dir)
  121. {
  122. global $ssh;
  123. // Костыль (добавить пустую строку на всякий случай)
  124. $query = 'sudo -u server'.$uid.' echo "" >> '.$dir.$write['file'].';';
  125. // Исключить дублирование, путем удаления добавляемого текста
  126. $query .= 'sudo -u server'.$uid.' sed -i '."'s/".str_replace('/', '\/', htmlspecialchars_decode($write['text']))."//g'".' '.$dir.$write['file'].';';
  127. // Добавление текста в начало файла
  128. if($write['top'])
  129. $query .= 'sudo -u server'.$uid.' touch '.$dir.$write['file'].'; sudo -u server'.$uid.' sed -i '."'1i ".str_replace(array('/', "'", '\"'), array('\/', "\'", '"'), htmlspecialchars_decode($write['text']))."'".' '.$dir.$write['file'].';';
  130. else
  131. // Добавление текста в конец файла
  132. $query .= 'sudo -u server'.$uid.' touch '.$dir.$write['file'].'; sudo -u server'.$uid.' echo "'.str_replace('"', '\"', htmlspecialchars_decode($write['text'])).'" >> '.$dir.$write['file'].';';
  133. $ssh->set($query.'sudo -u server'.$uid.' sed -i '."'/./!d'".' '.$dir.$clear['file']);
  134. return NULL;
  135. }
  136. }
  137. ?>