service_edit.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. James Rose <[email protected]>
  21. */
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. if (permission_exists('service_add') || permission_exists('service_edit')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //action add or update
  36. if (isset($_REQUEST["id"])) {
  37. $action = "update";
  38. $service_uuid = check_str($_REQUEST["id"]);
  39. }
  40. else {
  41. $action = "add";
  42. }
  43. //get http post and set it to php variables
  44. if (count($_POST)>0) {
  45. $service_name = check_str($_POST["service_name"]);
  46. $service_type = check_str($_POST["service_type"]);
  47. $service_data = check_str($_POST["service_data"]);
  48. $service_cmd_start = check_str($_POST["service_cmd_start"]);
  49. $service_cmd_stop = check_str($_POST["service_cmd_stop"]);
  50. $service_description = check_str($_POST["service_description"]);
  51. }
  52. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  53. $msg = '';
  54. if ($action == "update") {
  55. $service_uuid = check_str($_POST["service_uuid"]);
  56. }
  57. //check for all required data
  58. //if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
  59. if (strlen($service_name) == 0) { $msg .= "Please provide: Name<br>\n"; }
  60. //if (strlen($service_type) == 0) { $msg .= "Please provide: Type<br>\n"; }
  61. //if (strlen($service_data) == 0) { $msg .= "Please provide: Data<br>\n"; }
  62. //if (strlen($service_cmd_start) == 0) { $msg .= "Please provide: Start Command<br>\n"; }
  63. //if (strlen($service_cmd_stop) == 0) { $msg .= "Please provide: Stop Command<br>\n"; }
  64. //if (strlen($service_description) == 0) { $msg .= "Please provide: Description<br>\n"; }
  65. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  66. require_once "resources/header.php";
  67. require_once "resources/persist_form_var.php";
  68. echo "<div align='center'>\n";
  69. echo "<table><tr><td>\n";
  70. echo $msg."<br />";
  71. echo "</td></tr></table>\n";
  72. persistformvar($_POST);
  73. echo "</div>\n";
  74. require_once "resources/footer.php";
  75. return;
  76. }
  77. //add or update the database
  78. if ($_POST["persistformvar"] != "true") {
  79. if ($action == "add" && permission_exists('service_add')) {
  80. $service_uuid = uuid();
  81. $sql = "insert into v_services ";
  82. $sql .= "(";
  83. $sql .= "domain_uuid, ";
  84. $sql .= "service_uuid, ";
  85. $sql .= "service_name, ";
  86. $sql .= "service_type, ";
  87. $sql .= "service_data, ";
  88. $sql .= "service_cmd_start, ";
  89. $sql .= "service_cmd_stop, ";
  90. $sql .= "service_description ";
  91. $sql .= ")";
  92. $sql .= "values ";
  93. $sql .= "(";
  94. $sql .= "'$domain_uuid', ";
  95. $sql .= "'$service_uuid', ";
  96. $sql .= "'$service_name', ";
  97. $sql .= "'$service_type', ";
  98. $sql .= "'$service_data', ";
  99. $sql .= "'$service_cmd_start', ";
  100. $sql .= "'$service_cmd_stop', ";
  101. $sql .= "'$service_description' ";
  102. $sql .= ")";
  103. $db->exec(check_sql($sql));
  104. unset($sql);
  105. message::add($text['message-add']);
  106. header("Location: services.php");
  107. return;
  108. } //if ($action == "add")
  109. if ($action == "update" && permission_exists('service_edit')) {
  110. $sql = "update v_services set ";
  111. $sql .= "service_name = '$service_name', ";
  112. $sql .= "service_type = '$service_type', ";
  113. $sql .= "service_data = '$service_data', ";
  114. $sql .= "service_cmd_start = '$service_cmd_start', ";
  115. $sql .= "service_cmd_stop = '$service_cmd_stop', ";
  116. $sql .= "service_description = '$service_description' ";
  117. $sql .= "where service_uuid = '$service_uuid' ";
  118. // $sql .= "and domain_uuid = '$domain_uuid'";
  119. $db->exec(check_sql($sql));
  120. unset($sql);
  121. message::add($text['message-update']);
  122. header("Location: services.php");
  123. return;
  124. } //if ($action == "update")
  125. } //if ($_POST["persistformvar"] != "true")
  126. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  127. //pre-populate the form
  128. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  129. $service_uuid = $_GET["id"];
  130. $sql = "select * from v_services ";
  131. $sql .= "where service_uuid = '$service_uuid' ";
  132. $prep_statement = $db->prepare(check_sql($sql));
  133. $prep_statement->execute();
  134. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  135. foreach ($result as &$row) {
  136. $domain_uuid = $row["domain_uuid"];
  137. $service_name = $row["service_name"];
  138. $service_type = $row["service_type"];
  139. $service_data = $row["service_data"];
  140. $service_cmd_start = $row["service_cmd_start"];
  141. $service_cmd_stop = $row["service_cmd_stop"];
  142. $service_description = $row["service_description"];
  143. break; //limit to 1 row
  144. }
  145. unset ($prep_statement);
  146. }
  147. //show the header
  148. require_once "resources/header.php";
  149. //begin the content
  150. echo "<form method='post' name='frm' action=''>\n";
  151. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  152. echo "<tr>\n";
  153. if ($action == "add") {
  154. echo "<td align='left' width='30%' nowrap><b>".$text['title']."</b></td>\n";
  155. }
  156. if ($action == "update") {
  157. echo "<td align='left' width='30%' nowrap><b>Service Edit</b></td>\n";
  158. }
  159. echo "<td width='70%' align='right'>";
  160. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='services.php'\" value='".$text['button-back']."'>";
  161. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  162. echo "</td>\n";
  163. echo "</tr>\n";
  164. echo "<tr>\n";
  165. echo "<td align='left' colspan='2'>\n";
  166. echo $text['description']."<br /><br />\n";
  167. echo "</td>\n";
  168. echo "</tr>\n";
  169. echo "<tr>\n";
  170. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  171. echo " ".$text['label-name']."\n";
  172. echo "</td>\n";
  173. echo "<td class='vtable' align='left'>\n";
  174. echo " <input class='formfld' type='text' name='service_name' maxlength='255' value=\"".escape($service_name)."\">\n";
  175. echo "<br />\n";
  176. echo $text['description-name']."\n";
  177. echo "</td>\n";
  178. echo "</tr>\n";
  179. echo "<tr>\n";
  180. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  181. echo " ".$text['label-type']."\n";
  182. echo "</td>\n";
  183. echo "<td class='vtable' align='left'>\n";
  184. echo " <select class='formfld' name='service_type'>\n";
  185. echo " <option value=''></option>\n";
  186. if ($service_type == "pid" || $service_type == "pid_file") {
  187. echo " <option value='pid' selected='selected'>pid</option>\n";
  188. }
  189. else {
  190. echo " <option value='pid'>pid</option>\n";
  191. }
  192. //if ($service_type == "php") {
  193. // echo " <option value='php' selected='selected'>php</option>\n";
  194. //}
  195. //else {
  196. // echo " <option value='php'>php</option>\n";
  197. //}
  198. if ($service_type == "file") {
  199. echo " <option value='file' selected='selected'>file</option>\n";
  200. }
  201. else {
  202. echo " <option value='file'>file</option>\n";
  203. }
  204. if ($service_type == "svc") {
  205. echo " <option value='svc' selected='selected'>svc</option>\n";
  206. }
  207. else {
  208. echo " <option value='svc'>svc</option>\n";
  209. }
  210. echo " </select>\n";
  211. echo "<br />\n";
  212. echo $text['description-type']."\n";
  213. echo "</td>\n";
  214. echo "</tr>\n";
  215. echo "<tr>\n";
  216. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  217. echo " ".$text['label-data']."\n";
  218. echo "</td>\n";
  219. echo "<td class='vtable' align='left'>\n";
  220. echo " <input class='formfld' type='text' name='service_data' maxlength='255' value=\"" . htmlspecialchars($service_data) . "\">\n";
  221. //echo " <textarea class='formfld' name='service_data' rows='4'>$service_data</textarea>\n";
  222. echo "<br />\n";
  223. echo $text['description-data']."\n";
  224. echo "</td>\n";
  225. echo "</tr>\n";
  226. echo "<tr>\n";
  227. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  228. echo " ".$text['label-start_command']."\n";
  229. echo "</td>\n";
  230. echo "<td class='vtable' align='left'>\n";
  231. echo " <input class='formfld' type='text' name='service_cmd_start' maxlength='255' value=\"" . htmlspecialchars($service_cmd_start) . "\">\n";
  232. echo "<br />\n";
  233. echo $text['description-start_command']."\n";
  234. echo "</td>\n";
  235. echo "</tr>\n";
  236. echo "<tr>\n";
  237. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  238. echo " ".$text['label-stop_command']."\n";
  239. echo "</td>\n";
  240. echo "<td class='vtable' align='left'>\n";
  241. echo " <input class='formfld' type='text' name='service_cmd_stop' maxlength='255' value=\"" . htmlspecialchars($service_cmd_stop) . "\">\n";
  242. echo "<br />\n";
  243. echo $text['description-stop_command']."\n";
  244. echo "</td>\n";
  245. echo "</tr>\n";
  246. echo "<tr>\n";
  247. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  248. echo " ".$text['label-description']."\n";
  249. echo "</td>\n";
  250. echo "<td class='vtable' align='left'>\n";
  251. echo " <textarea class='formfld' name='service_description' rows='4'>".escape($service_description)."</textarea>\n";
  252. echo "<br />\n";
  253. echo $text['description-description']."\n";
  254. echo "</td>\n";
  255. echo "</tr>\n";
  256. echo " <tr>\n";
  257. echo " <td colspan='2' align='right'>\n";
  258. if ($action == "update") {
  259. echo " <input type='hidden' name='service_uuid' value='".escape($service_uuid)."'>\n";
  260. }
  261. echo " <br>";
  262. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  263. echo " </td>\n";
  264. echo " </tr>";
  265. echo "</table>";
  266. echo "<br><br>";
  267. echo "</form>";
  268. //show the footer
  269. require_once "resources/footer.php";
  270. ?>