index.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2020
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //set a timeout
  22. set_time_limit(15*60); //15 minutes
  23. //includes
  24. require_once "root.php";
  25. require_once "resources/require.php";
  26. require_once "resources/check_auth.php";
  27. //check the permission
  28. if (
  29. !permission_exists('upgrade_source') &&
  30. !permission_exists('upgrade_schema') &&
  31. !permission_exists('upgrade_apps') &&
  32. !permission_exists('menu_restore') &&
  33. !permission_exists('group_edit')
  34. ) {
  35. echo "access denied";
  36. exit;
  37. }
  38. //add multi-lingual support
  39. $language = new text;
  40. $text = $language->get();
  41. //set a default message_timeout
  42. $message_timeout = 4*1000;
  43. //process the http post
  44. if (sizeof($_POST) > 0) {
  45. $do = $_POST['do'];
  46. // run source update
  47. if ($do["source"] && permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx")) {
  48. $cwd = getcwd();
  49. chdir($_SERVER["PROJECT_ROOT"]);
  50. exec("git pull 2>&1", $response_source_update);
  51. $update_failed = true;
  52. if (sizeof($response_source_update) > 0) {
  53. $_SESSION["response"]["upgrade_source"] = $response_source_update;
  54. foreach ($response_source_update as $response_line) {
  55. if (substr_count($response_line, "Updating ") > 0 || substr_count($response_line, "Already up-to-date.") > 0) {
  56. $update_failed = false;
  57. }
  58. if (substr_count($response_line, "error") > 0) {
  59. $update_failed = true;
  60. break;
  61. }
  62. }
  63. }
  64. chdir($cwd);
  65. if ($update_failed) {
  66. message::add($text['message-upgrade_source_failed'], 'negative', $message_timeout);
  67. }
  68. else {
  69. message::add($text['message-upgrade_source'], null, $message_timeout);
  70. }
  71. }
  72. // load an array of the database schema and compare it with the active database
  73. if ($do["schema"] && permission_exists("upgrade_schema")) {
  74. $upgrade_data_types = check_str($do["data_types"]);
  75. require_once "resources/classes/schema.php";
  76. $obj = new schema();
  77. $_SESSION["response"]["schema"] = $obj->schema("html");
  78. message::add($text['message-upgrade_schema'], null, $message_timeout);
  79. }
  80. // process the apps defaults
  81. if ($do["apps"] && permission_exists("upgrade_apps")) {
  82. require_once "resources/classes/domains.php";
  83. $domain = new domains;
  84. $domain->upgrade();
  85. message::add($text['message-upgrade_apps'], null, $message_timeout);
  86. }
  87. // restore defaults of the selected menu
  88. if ($do["menu"] && permission_exists("menu_restore")) {
  89. $sel_menu = explode('|', check_str($_POST["sel_menu"]));
  90. $menu_uuid = $sel_menu[0];
  91. $menu_language = $sel_menu[1];
  92. $included = true;
  93. require_once("core/menu/menu_restore_default.php");
  94. unset($sel_menu);
  95. message::add($text['message-upgrade_menu'], null, $message_timeout);
  96. }
  97. // restore default permissions
  98. if ($do["permissions"] && permission_exists("group_edit")) {
  99. $included = true;
  100. require_once("core/groups/permissions_default.php");
  101. message::add($text['message-upgrade_permissions'], null, $message_timeout);
  102. }
  103. header("Location: ".PROJECT_PATH."/core/upgrade/index.php");
  104. exit;
  105. }
  106. //include the header and set the title
  107. $document['title'] = $text['title-upgrade'];
  108. require_once "resources/header.php";
  109. //show the content
  110. echo "<form name='frm' method='post'>\n";
  111. echo "<div class='action_bar' id='action_bar'>\n";
  112. echo " <div class='heading'><b>".$text['header-upgrade']."</b></div>\n";
  113. echo " <div class='actions'>\n";
  114. echo button::create(['type'=>'submit','label'=>$text['button-upgrade_execute'],'icon'=>$_SESSION['theme']['button_icon_save'],'collapse'=>'never']);
  115. echo " </div>\n";
  116. echo " <div style='clear: both;'></div>\n";
  117. echo "</div>\n";
  118. echo $text['description-upgrade'];
  119. echo "<br /><br />";
  120. if (permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx") && is_writeable($_SERVER["PROJECT_ROOT"]."/.git")) {
  121. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  122. echo "<tr>\n";
  123. echo " <td width='30%' class='vncell' style='vertical-align:middle;'>\n";
  124. echo " ".$text['label-upgrade_source'];
  125. echo " </td>\n";
  126. echo " <td width='70%' class='vtable' style='height: 50px;'>\n";
  127. echo " <input type='checkbox' name='do[source]' id='do_source' value='1'> &nbsp;".$text['description-upgrade_source']."<br />\n";
  128. // show current git version info
  129. chdir($_SERVER["PROJECT_ROOT"]);
  130. exec("git rev-parse --abbrev-ref HEAD 2>&1", $git_current_branch, $branch_return_value);
  131. $git_current_branch = $git_current_branch[0];
  132. exec("git log --pretty=format:'%H' -n 1 2>&1", $git_current_commit, $commit_return_value);
  133. $git_current_commit = $git_current_commit[0];
  134. if (($branch_return_value == 0) && ($commit_return_value == 0)) {
  135. echo $text['label-git_branch'].' '.$git_current_branch." \n";
  136. //echo $text['label-git_commit'].' '." ";
  137. echo "<a href='https://github.com/fusionpbx/fusionpbx/compare/";
  138. echo $git_current_commit . "..." . "$git_current_branch' target='_blank'> \n";
  139. echo $git_current_commit . "</a><br />\n";
  140. echo "</a>";
  141. }
  142. echo " </td>\n";
  143. echo "</tr>\n";
  144. echo "</table>\n";
  145. }
  146. if (permission_exists("upgrade_schema")) {
  147. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  148. echo "<tr>\n";
  149. echo " <td width='30%' class='vncell' style='vertical-align:middle;'>\n";
  150. echo " ".$text['label-upgrade_schema'];
  151. echo " </td>\n";
  152. echo " <td width='70%' class='vtable' style='height: 50px;'>\n";
  153. echo " <input type='checkbox' name='do[schema]' id='do_schema' value='1' onchange=\"$('#do_data_types').prop('checked', false); $('#tr_data_types').slideToggle('fast');\"> &nbsp;".$text['description-upgrade_schema']."\n";
  154. echo " </td>\n";
  155. echo "</tr>\n";
  156. echo "</table>\n";
  157. echo "<div id='tr_data_types' style='display: none;'>\n";
  158. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  159. echo "<tr>\n";
  160. echo " <td width='30%' class='vncell' style='vertical-align:middle;'>\n";
  161. echo " ".$text['label-upgrade_data_types'];
  162. echo " </td>\n";
  163. echo " <td width='70%' class='vtable' style='height: 50px;'>\n";
  164. echo " <input type='checkbox' name='do[data_types]' id='do_data_types' value='true'> &nbsp;".$text['description-upgrade_data_types']."\n";
  165. echo " </td>\n";
  166. echo "</tr>\n";
  167. echo "</table>\n";
  168. echo "</div>\n";
  169. }
  170. if (permission_exists("upgrade_apps")) {
  171. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  172. echo "<tr>\n";
  173. echo " <td width='30%' class='vncell' style='vertical-align:middle;'>\n";
  174. echo " ".$text['label-upgrade_apps'];
  175. echo " </td>\n";
  176. echo " <td width='70%' class='vtable' style='height: 50px;'>\n";
  177. echo " <input type='checkbox' name='do[apps]' id='do_apps' value='1'> &nbsp;".$text['description-upgrade_apps']."\n";
  178. echo " </td>\n";
  179. echo "</tr>\n";
  180. echo "</table>\n";
  181. }
  182. if (permission_exists("menu_restore")) {
  183. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  184. echo "<tr>\n";
  185. echo " <td width='30%' class='vncell' style='vertical-align:middle;'>\n";
  186. echo " ".$text['label-upgrade_menu'];
  187. echo " </td>\n";
  188. echo " <td width='70%' class='vtable' style='height: 50px;'>\n";
  189. echo "<input type='checkbox' name='do[menu]' id='do_menu' value='1' onchange=\"$('#sel_menu').fadeToggle('fast');\">";
  190. echo "<select name='sel_menu' id='sel_menu' class='formfld' style='display: none; vertical-align: middle; margin-left: 5px;'>";
  191. $sql = "select * from v_menus ";
  192. $database = new database;
  193. $result = $database->select($sql, null, 'all');
  194. if (is_array($result) && sizeof($result) != 0) {
  195. foreach ($result as &$row) {
  196. echo "<option value='".$row["menu_uuid"]."|".$row["menu_language"]."'>".$row["menu_name"]."</option>";
  197. }
  198. }
  199. unset ($sql, $result);
  200. echo "</select>";
  201. echo " &nbsp;".$text['description-upgrade_menu'];
  202. echo " </td>\n";
  203. echo "</tr>\n";
  204. echo "</table>\n";
  205. }
  206. if (permission_exists("group_edit")) {
  207. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  208. echo "<tr>\n";
  209. echo " <td width='30%' class='vncell' style='vertical-align:middle;'>\n";
  210. echo " ".$text['label-upgrade_permissions'];
  211. echo " </td>\n";
  212. echo " <td width='70%' class='vtable' style='height: 50px;'>\n";
  213. echo " <input type='checkbox' name='do[permissions]' id='do_permissions' value='1'> &nbsp;".$text['description-upgrade_permissions']."\n";
  214. echo " </td>\n";
  215. echo "</tr>\n";
  216. echo "</table>\n";
  217. }
  218. echo "</form>\n";
  219. echo "<br /><br />";
  220. if (!empty($_SESSION["response"]) && is_array($_SESSION["response"])) {
  221. foreach($_SESSION["response"] as $part => $response){
  222. echo "<b>". $text["label-results"]." - ".$text["label-${part}"]."</b>";
  223. echo "<br /><br />";
  224. if (is_array($response)) {
  225. echo "<pre>";
  226. echo implode("\n", $response);
  227. echo "</pre>";
  228. }
  229. else {
  230. echo $response;
  231. }
  232. echo "<br /><br />";
  233. }
  234. unset($_SESSION["response"]);
  235. }
  236. //include the footer
  237. require_once "resources/footer.php";
  238. ?>