index.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. if (cfr('SYSCONF')) {
  3. //getting some editable configs presets
  4. $editableConfigsPresetsPath = DATA_PATH . '/documents/editableconfigs/settings.dat';
  5. if (file_exists($editableConfigsPresetsPath)) {
  6. //loading presets
  7. $editableConfigs = file_get_contents($editableConfigsPresetsPath);
  8. $editableConfigs = json_decode($editableConfigs, true);
  9. } else {
  10. //creating new default presets
  11. $editableConfigs = array(
  12. CONFIG_PATH . 'alter.ini' => 'alter.ini',
  13. CONFIG_PATH . 'mysql.ini' => 'mysql.ini',
  14. CONFIG_PATH . 'billing.ini' => 'billing.ini',
  15. CONFIG_PATH . 'ymaps.ini' => 'ymaps.ini',
  16. CONFIG_PATH . 'config.ini' => 'config.ini',
  17. 'userstats/config/userstats.ini' => 'userstats.ini',
  18. );
  19. file_put_contents($editableConfigsPresetsPath, json_encode($editableConfigs));
  20. }
  21. //deleting presets if required
  22. if (ubRouting::checkGet('delconfpath')) {
  23. $pathToDelete = base64_decode(ubRouting::get('delconfpath'));
  24. if (isset($editableConfigs[$pathToDelete])) {
  25. unset($editableConfigs[$pathToDelete]);
  26. file_put_contents($editableConfigsPresetsPath, json_encode($editableConfigs));
  27. log_register('SYSCONF DELETE PRESET `' . $pathToDelete . '`');
  28. ubRouting::nav('?module=sysconf');
  29. }
  30. }
  31. //creating some new presets
  32. if (ubRouting::checkPost(array('newconfpath', 'newconfname'))) {
  33. $createConfPath = ubRouting::post('newconfpath');
  34. $createConfName = ubRouting::post('newconfname');
  35. if (!isset($editableConfigs[$createConfPath])) {
  36. if (file_exists($createConfPath)) {
  37. $editableConfigs[$createConfPath] = $createConfName;
  38. file_put_contents($editableConfigsPresetsPath, json_encode($editableConfigs));
  39. log_register('SYSCONF CREATE PRESET `' . $createConfPath . '`');
  40. ubRouting::nav('?module=sysconf');
  41. } else {
  42. show_error(__('File not exist') . ': ' . $createConfPath);
  43. }
  44. }
  45. }
  46. $configsList = '';
  47. //appending crontab editor link
  48. if (cfr('ROOT')) {
  49. $configsList .= wf_Link(CrontabEditor::URL_ME, wf_img('skins/clock.png') . ' ' . __('Crontab editor'), false, 'ubButton');
  50. $configsList .= wf_Link(IpACLMgr::URL_ME, wf_img('skins/icon_ipaclmgr.png') . ' ' . __('IP Access restrictions'), false, 'ubButton');
  51. $configsList .= wf_delimiter(1);
  52. }
  53. //existing editable configs list
  54. if (!empty($editableConfigs)) {
  55. foreach ($editableConfigs as $eachConfigPath => $eachConfigName) {
  56. $configsList .= wf_Link('?module=sysconf&editconfig=' . base64_encode($eachConfigPath), web_edit_icon() . ' ' . $eachConfigName, false, 'ubButton') . ' ';
  57. }
  58. }
  59. //appending presets controls
  60. $configsList .= wf_modalAuto(web_icon_extended() . ' ' . __('Settings'), __('Settings'), web_RenderEditableConfigPresetsForm($editableConfigs), 'ubButton');
  61. show_window(__('Edit'), $configsList);
  62. if (ubRouting::checkGet('editconfig')) {
  63. $editingConfigPath = base64_decode(ubRouting::get('editconfig'));
  64. if (file_exists($editingConfigPath)) {
  65. if (ubRouting::checkPost(array('editfilepath', 'editfilecontent'))) {
  66. $changedFilePath = ubRouting::post('editfilepath');
  67. if (file_exists($changedFilePath)) {
  68. $canUpdate = false;
  69. if (!is_writable($changedFilePath)) {
  70. show_error(__('File is not writable') . ': ' . $changedFilePath);
  71. show_warning(__('Trying to set write permissions for') . ' ' . $changedFilePath . ' ' . __('to fix this issue'));
  72. zb_fixAccessRights($changedFilePath);
  73. if (is_writable($changedFilePath)) {
  74. $canUpdate = true;
  75. show_success(__('Success! Config file') . ' ' . $changedFilePath . ' ' . __('now is writable'));
  76. } else {
  77. $canUpdate = false;
  78. show_error(__('Seems like we failed with making this file writable'));
  79. }
  80. } else {
  81. $canUpdate = true;
  82. }
  83. //saving results into file
  84. if ($canUpdate) {
  85. $newFileContent = $_POST['editfilecontent'];
  86. $newFileContent = str_replace("\r\n", PHP_EOL, $newFileContent); // setting unix-line EOL.
  87. file_put_contents($changedFilePath, $newFileContent);
  88. log_register('SYSCONF UPDATE FILE `' . $changedFilePath . '`');
  89. } else {
  90. log_register('SYSCONF UPDATE FAIL `' . $changedFilePath . '`');
  91. }
  92. }
  93. }
  94. $editingConfigContent = file_get_contents($editingConfigPath);
  95. show_window(__('Change') . ' ' . basename($editingConfigPath), web_FileEditorForm($editingConfigPath, $editingConfigContent));
  96. } else {
  97. show_error(__('File not exist') . ': ' . $editingConfigPath);
  98. }
  99. show_window('', wf_BackLink('?module=sysconf'));
  100. } else {
  101. $alterconf = rcms_parse_ini_file(CONFIG_PATH . 'alter.ini');
  102. $alteropts = rcms_parse_ini_file(CONFIG_PATH . 'optsaltcfg');
  103. $dbconf = rcms_parse_ini_file(CONFIG_PATH . 'mysql.ini');
  104. $dbopts = rcms_parse_ini_file(CONFIG_PATH . 'optsdbcfg');
  105. $billingconf = rcms_parse_ini_file(CONFIG_PATH . 'billing.ini');
  106. $billopts = rcms_parse_ini_file(CONFIG_PATH . 'optsbillcfg');
  107. $ymconf = rcms_parse_ini_file(CONFIG_PATH . 'ymaps.ini');
  108. $ymopts = rcms_parse_ini_file(CONFIG_PATH . 'optsymcfg');
  109. $photoconf = rcms_parse_ini_file(CONFIG_PATH . 'photostorage.ini');
  110. $photoopts = rcms_parse_ini_file(CONFIG_PATH . 'optsphotocfg');
  111. if ($alterconf['PASSWORDSHIDE']) {
  112. $hide_passwords = true;
  113. } else {
  114. $hide_passwords = false;
  115. }
  116. $configOptionsMissed = '';
  117. $dbcell = web_ConfigEditorShow('mysqlini', $dbconf, $dbopts);
  118. $billcell = web_ConfigEditorShow('billingini', $billingconf, $billopts);
  119. $altercell = web_ConfigEditorShow('alterini', $alterconf, $alteropts);
  120. $ymcells = web_ConfigEditorShow('ymaps', $ymconf, $ymopts);
  121. $photocells = web_ConfigEditorShow('photostorage', $photoconf, $photoopts);
  122. $grid = wf_tag('script');
  123. $grid .= '$(function() {
  124. $( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
  125. $( "#tabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
  126. });';
  127. $grid .= wf_tag('script', true);
  128. $grid .= wf_tag('style');
  129. $grid .= file_get_contents('skins/tabs_v.css');
  130. $grid .= wf_tag('style', true);
  131. $grid .= wf_tag('div', false, '', 'id="tabs"');
  132. $grid .= wf_tag('ul');
  133. $grid .= web_ConfigGetTabsControls($dbopts) . web_ConfigGetTabsControls($billopts) . web_ConfigGetTabsControls($alteropts);
  134. $grid .= web_ConfigGetTabsControls($ymopts) . web_ConfigGetTabsControls($photoopts);
  135. $grid .= wf_tag('ul', true);
  136. $grid .= $dbcell . $billcell . $ymcells . $photocells . $altercell;
  137. $grid .= wf_tag('div', true) . wf_CleanDiv();
  138. if (!empty($configOptionsMissed)) {
  139. show_window('', $configOptionsMissed);
  140. }
  141. show_window(__('System settings'), $grid);
  142. }
  143. } else {
  144. show_error(__('You cant control this module'));
  145. }