Просмотр файла admin/modules/import.php

Размер файла: 4.44Kb
  1. <?php
  2. include '../../engine/includes/start.php';
  3. if (!$creator)
  4. Core::stop();
  5.  
  6. $set_mod = parse_ini_file(H . 'engine/files/data/modules.ini');
  7. $set['title'] = 'Импорт модуля';
  8. include incDir.'head.php';
  9.  
  10. empty($_POST['url']) && !empty($_GET['url']) ? $_POST['url'] = $_GET['url'] : null;
  11.  
  12. if (!empty($_POST['url']))
  13. {
  14. $headers = @get_headers($_POST['url'], 1);
  15.  
  16. if (!$headers)
  17. $error = 'Не удалось получить заголовки по указанному адресу';
  18. elseif (empty($_GET['url']) && !empty($headers['Content-Length']) && $headers['Content-Length'] >= 2097152)
  19. $error = 'Размер архива превышает 2 мб, <a href="?url='.htmlspecialchars($_POST['url']).'">продолжить</a>';
  20.  
  21. elseif ($headers['Content-Type'] != 'application/zip')
  22. $error = 'Только zip архивы';
  23. else
  24. {
  25. $modul = pathinfo($_POST['url'], PATHINFO_FILENAME);
  26.  
  27. if (file_exists(H . 'engine/files/modules/archives/' . $modul))
  28. $error = 'Такой архив уже есть в списке архивов';
  29. else
  30. {
  31. file_put_contents(tmpDir . $modul, file_get_contents($_POST['url']));
  32. Core::get('zip');
  33. $zip = new Pclzip(tmpDir . $modul);
  34. $name = pathinfo($modul, PATHINFO_FILENAME);
  35. $contents = $zip->listContent();
  36.  
  37. function get_ini($event, &$file)
  38. {
  39. Global $name;
  40. Return Rename($file['filename'], H.'engine/files/modules/configs/'.$name.'.app');
  41. //Return 1;
  42. }
  43.  
  44. function get_icon($event, &$file)
  45. {
  46. Global $name;
  47. Rename($file['filename'], H.'style/icons/modules/'.$name.'.png');
  48. Return 1;
  49. }
  50. if ($contents == 0)
  51. $error = 'Архив поврежден или пуст';
  52. else
  53. {
  54. $config = $zip->extract(PCLZIP_OPT_BY_NAME, 'module.ini', PCLZIP_CB_POST_EXTRACT, 'get_ini');
  55. if (empty($config))
  56. $error = 'module.ini не найден';
  57. else
  58. {
  59. $icon = $zip->extract(PCLZIP_OPT_BY_NAME, 'icon.png', PCLZIP_CB_POST_EXTRACT, 'get_icon');
  60. $config = parse_ini_file(H.'engine/files/modules/configs/'.$name.'.app');
  61. $dir_install = empty($config['dir_install']) || strtolower($config['dir_install']) == 'корень' ? null : $config['dir_install'] . '/';
  62.  
  63. if (empty($icon))
  64. Core::msg_show('Не найдена иконка модуля');
  65. if (empty($config['module_name']) || empty($config['author_name']))
  66. $error = 'Название модуля или имя автора не указана. Загрузка модуля невозможна';
  67. elseif ($set_mod['req_un_file'] && (empty($config['file_uninstaller']) || (!array_key_exists(str_replace($dir_install, '', strtok($config['file_uninstaller'], '?')), $contents) && !array_key_exists(strtok($config['file_uninstaller'], '?'), $contents))))
  68. $error = 'Файл удаления не найден';
  69. if (!empty($config['secwind_version']) && version_compare($config['secwind_version'], Core::Secwind('version'), '>')) // если версия SecWind не соответстует требованиям модуля
  70. $error = 'Модуль подходит для версии SecWind с '.$config['secwind_version'] .', ваша версия - '. Core::Secwind('version');
  71. }
  72. }
  73.  
  74. if (isset($error))
  75. {
  76. if (file_exists(H.'engine/files/modules/configs/'.$name.'.app'))
  77. unlink(H.'engine/files/modules/configs/'.$name.'.app');
  78. if (!empty($icon) && file_exists(H.'style/icons/modules/'.$name.'.png'))
  79. unlink(H.'style/icons/modules/'.$name.'.png');
  80. }
  81. else
  82. {
  83. $zip->delete(PCLZIP_OPT_BY_NAME, 'module.ini');
  84. $zip->delete(PCLZIP_OPT_BY_NAME, 'icon.png');
  85. Rename(tmpDir . $modul, H.'engine/files/modules/archives/'.$modul);
  86. Core::msg_show('Модуль "'.$name.'" успешно загружен, теперь нужно его <a href="install.php?select='.$name.'">установить</a>', 'menu_razd');
  87. }
  88. unset($zip, $config, $headers);
  89. }
  90. }
  91. if (isset($error))
  92. Core::msg_show($error);
  93. }
  94.  
  95. ?>
  96. <form method = "post">
  97. Путь к zip архиву:<br />
  98. <input type="text" name="url" value="http://"/><br />
  99. <input value = "Импорт" type="submit" />
  100. </form>
  101. <a href='/admin/'><div class="menu_razd">Админка</div></a>
  102. <?php
  103. include incDir.'foot.php';