Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

416 lines
16 KiB

2 years ago
  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 <markjcrane@fusionpbx.com>
  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 <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('var_add') || permission_exists('var_edit')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //set the action as an add or an update
  37. if (is_uuid($_REQUEST["id"])) {
  38. $action = "update";
  39. $var_uuid = $_REQUEST["id"];
  40. }
  41. else {
  42. $action = "add";
  43. }
  44. //set http values as php variables
  45. if (count($_POST) > 0) {
  46. $var_category = trim($_POST["var_category"]);
  47. $var_name = trim($_POST["var_name"]);
  48. $var_value = trim($_POST["var_value"]);
  49. $var_command = trim($_POST["var_command"]);
  50. $var_hostname = trim($_POST["var_hostname"]);
  51. $var_enabled = trim($_POST["var_enabled"]);
  52. $var_order = trim($_POST["var_order"]);
  53. $var_description = trim($_POST["var_description"]);
  54. $var_description = str_replace("''", "'", $var_description);
  55. if (strlen($_POST["var_category_other"]) > 0) {
  56. $var_category = trim($_POST["var_category_other"]);
  57. }
  58. }
  59. //process the post
  60. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  61. //get the uuid
  62. if ($action == "update") {
  63. $var_uuid = $_POST["var_uuid"];
  64. }
  65. //validate the token
  66. $token = new token;
  67. if (!$token->validate($_SERVER['PHP_SELF'])) {
  68. message::add($text['message-invalid_token'],'negative');
  69. header('Location: vars.php');
  70. exit;
  71. }
  72. //check for all required data
  73. $msg = '';
  74. //if (strlen($var_category) == 0) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
  75. if (strlen($var_name) == 0) { $msg .= $text['message-required'].$text['label-name']."<br>\n"; }
  76. //if (strlen($var_value) == 0) { $msg .= $text['message-required'].$text['label-value']."<br>\n"; }
  77. //if (strlen($var_command) == 0) { $msg .= $text['message-required'].$text['label-command']."<br>\n"; }
  78. if (strlen($var_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
  79. if (strlen($var_order) == 0) { $msg .= $text['message-required'].$text['label-order']."<br>\n"; }
  80. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  81. require_once "resources/header.php";
  82. require_once "resources/persist_form_var.php";
  83. echo "<div align='center'>\n";
  84. echo "<table><tr><td>\n";
  85. echo $msg."<br />";
  86. echo "</td></tr></table>\n";
  87. persistformvar($_POST);
  88. echo "</div>\n";
  89. require_once "resources/footer.php";
  90. return;
  91. }
  92. //add or update the database
  93. if ($_POST["persistformvar"] != "true") {
  94. if ($action == "add" && permission_exists('var_add')) {
  95. //begin insert array
  96. $var_uuid = uuid();
  97. $array['vars'][0]['var_uuid'] = $var_uuid;
  98. //set message
  99. message::add($text['message-add']);
  100. }
  101. if ($action == "update" && permission_exists('var_edit')) {
  102. //begin update array
  103. $array['vars'][0]['var_uuid'] = $var_uuid;
  104. //set message
  105. message::add($text['message-update']);
  106. }
  107. if (is_array($array) && @sizeof($array) != 0) {
  108. //add common fields to array
  109. $array['vars'][0]['var_category'] = $var_category;
  110. $array['vars'][0]['var_name'] = $var_name;
  111. $array['vars'][0]['var_value'] = $var_value;
  112. $array['vars'][0]['var_command'] = $var_command;
  113. $array['vars'][0]['var_hostname'] = $var_hostname != '' ? $var_hostname : null;
  114. $array['vars'][0]['var_enabled'] = $var_enabled;
  115. $array['vars'][0]['var_order'] = $var_order;
  116. $array['vars'][0]['var_description'] = base64_encode($var_description);
  117. //execute insert/update
  118. $database = new database;
  119. $database->app_name = 'vars';
  120. $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8';
  121. $database->save($array);
  122. unset($array);
  123. //unset the user defined variables
  124. $_SESSION["user_defined_variables"] = "";
  125. //synchronize the configuration
  126. save_var_xml();
  127. //redirect
  128. header("Location: vars.php");
  129. exit;
  130. }
  131. }
  132. }
  133. //pre-populate the form
  134. if (is_array($_GET) && is_uuid($_GET["id"]) && $_POST["persistformvar"] != "true") {
  135. $var_uuid = $_GET["id"];
  136. $sql = "select * from v_vars ";
  137. $sql .= "where var_uuid = :var_uuid ";
  138. $parameters['var_uuid'] = $var_uuid;
  139. $database = new database;
  140. $row = $database->select($sql, $parameters, 'row');
  141. if (is_array($row) && @sizeof($row) != 0) {
  142. $var_category = $row["var_category"];
  143. $var_name = $row["var_name"];
  144. $var_value = $row["var_value"];
  145. $var_command = $row["var_command"];
  146. $var_hostname = $row["var_hostname"];
  147. $var_enabled = $row["var_enabled"];
  148. $var_order = $row["var_order"];
  149. $var_description = base64_decode($row["var_description"]);
  150. }
  151. unset($sql, $parameters);
  152. }
  153. //create token
  154. $object = new token;
  155. $token = $object->create($_SERVER['PHP_SELF']);
  156. //include header
  157. $document['title'] = $text['title-variable'];
  158. require_once "resources/header.php";
  159. //show contents
  160. echo "<form method='post' name='frm' id='frm'>\n";
  161. echo "<div class='action_bar' id='action_bar'>\n";
  162. echo " <div class='heading'><b>".$text['header-variable']."</b></div>\n";
  163. echo " <div class='actions'>\n";
  164. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'vars.php']);
  165. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save']);
  166. echo " </div>\n";
  167. echo " <div style='clear: both;'></div>\n";
  168. echo "</div>\n";
  169. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  170. echo "<tr>\n";
  171. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  172. echo " ".$text['label-category']."\n";
  173. echo "</td>\n";
  174. echo "<td width='70%' class='vtable' align='left'>\n";
  175. $table_name = 'v_vars';
  176. $field_name = 'var_category';
  177. $sql_where_optional = "";
  178. $field_current_value = $var_category;
  179. echo html_select_other($table_name, $field_name, $sql_where_optional, $field_current_value);
  180. echo $text['description-category']."\n";
  181. echo "</td>\n";
  182. echo "</tr>\n";
  183. echo "<tr>\n";
  184. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  185. echo " ".$text['label-name']."\n";
  186. echo "</td>\n";
  187. echo "<td class='vtable' align='left'>\n";
  188. echo " <input class='formfld' type='text' name='var_name' maxlength='255' value=\"".escape($var_name)."\">\n";
  189. echo "<br />\n";
  190. echo $text['description-name']."\n";
  191. echo "</td>\n";
  192. echo "</tr>\n";
  193. echo "<tr>\n";
  194. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  195. echo " ".$text['label-value']."\n";
  196. echo "</td>\n";
  197. echo "<td class='vtable' align='left'>\n";
  198. echo " <input class='formfld' type='text' name='var_value' maxlength='255' value=\"".escape($var_value)."\">\n";
  199. echo "<br />\n";
  200. echo $text['description-value']."\n";
  201. echo "</td>\n";
  202. echo "</tr>\n";
  203. echo "<tr>\n";
  204. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  205. echo " ".$text['label-command']."\n";
  206. echo "</td>\n";
  207. echo "<td class='vtable' align='left'>\n";
  208. echo " <select class='formfld' name='var_command'>\n";
  209. if ($var_command == "set") {
  210. echo " <option value='set' selected='selected'>".$text['option-set']."</option>\n";
  211. }
  212. else {
  213. echo " <option value='set'>".$text['option-set']."</option>\n";
  214. }
  215. if ($var_command == "exec-set") {
  216. echo " <option value='exec-set' selected='selected'>".$text['option-exec-set']."</option>\n";
  217. }
  218. else {
  219. echo " <option value='exec-set'>".$text['option-exec-set']."</option>\n";
  220. }
  221. echo " </select>\n";
  222. echo "<br />\n";
  223. echo $text['description-command']."\n";
  224. echo "</td>\n";
  225. echo "</tr>\n";
  226. echo "<tr>\n";
  227. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  228. echo " ".$text['label-hostname']."\n";
  229. echo "</td>\n";
  230. echo "<td class='vtable' align='left'>\n";
  231. echo " <input class='formfld' type='text' name='var_hostname' maxlength='255' value=\"".escape($var_hostname)."\">\n";
  232. echo "<br />\n";
  233. echo $text['description-hostname']."\n";
  234. echo "</td>\n";
  235. echo "</tr>\n";
  236. echo "<tr>\n";
  237. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  238. echo " ".$text['label-enabled']."\n";
  239. echo "</td>\n";
  240. echo "<td class='vtable' align='left'>\n";
  241. echo " <select class='formfld' name='var_enabled'>\n";
  242. if ($var_enabled == "true") {
  243. echo " <option value='true' selected='selected'>".$text['option-true']."</option>\n";
  244. }
  245. else {
  246. echo " <option value='true'>".$text['option-true']."</option>\n";
  247. }
  248. if ($var_enabled == "false") {
  249. echo " <option value='false' selected='selected'>".$text['option-false']."</option>\n";
  250. }
  251. else {
  252. echo " <option value='false'>".$text['option-false']."</option>\n";
  253. }
  254. echo " </select>\n";
  255. echo "<br />\n";
  256. echo $text['description-enabled']."\n";
  257. echo "</td>\n";
  258. echo "</tr>\n";
  259. echo "<tr>\n";
  260. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  261. echo " ".$text['label-order']."\n";
  262. echo "</td>\n";
  263. echo "<td class='vtable' align='left'>\n";
  264. echo " <select name='var_order' class='formfld'>\n";
  265. $i = 0;
  266. while ($i <= 999) {
  267. $selected = ($var_order == $i) ? "selected='selected'" : null;
  268. if (strlen($i) == 1) {
  269. echo " <option value='00$i' ".$selected.">00$i</option>\n";
  270. }
  271. if (strlen($i) == 2) {
  272. echo " <option value='0$i' ".$selected.">0$i</option>\n";
  273. }
  274. if (strlen($i) == 3) {
  275. echo " <option value='$i' ".$selected.">$i</option>\n";
  276. }
  277. $i++;
  278. }
  279. echo " </select>\n";
  280. echo " <br />\n";
  281. echo $text['description-order']."\n";
  282. echo "</td>\n";
  283. echo "</tr>\n";
  284. echo "<tr>\n";
  285. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  286. echo " ".$text['label-description']."\n";
  287. echo "</td>\n";
  288. echo "<td class='vtable' align='left'>\n";
  289. echo " <textarea class='formfld' name='var_description' rows='17'>".$var_description."</textarea>\n";
  290. echo "<br />\n";
  291. echo $text['description-description']."\n";
  292. echo "</td>\n";
  293. echo "</tr>\n";
  294. //if variable is a code then show the codec info
  295. if ($var_name == "global_codec_prefs" || $var_name == "outbound_codec_prefs") {
  296. echo "<tr>\n";
  297. echo "<td align='left' colspan='2'>\n";
  298. echo "<br />\n";
  299. echo "<b>".$text['label-codec_information']."</b><br><br>\n";
  300. echo "Module must be compiled and loaded. &nbsp; &nbsp; codecname[@8000h|16000h|32000h[@XXi]]<br />\n";
  301. echo "<br />\n";
  302. echo "XX is the frame size must be multples allowed for the codec<br />\n";
  303. echo "10-120ms is supported on some codecs.<br />\n";
  304. echo "We do not support exceeding the MTU of the RTP packet.<br />\n";
  305. echo "<br />\n";
  306. echo " <table>\n";
  307. echo " <tr>\n";
  308. echo " <tr><td width='200'>opus@48000h@10i</td><td>Opus 48khz using 10 ms ptime (mono and stereo)</td></tr>\n";
  309. echo " <tr><td>opus@48000h@20i</td><td>Opus 48khz using 20 ms ptime (mono and stereo)</td></tr>\n";
  310. echo " <tr><td>opus@48000h@40i</td><td>Opus 48khz using 40 ms ptime</td></tr>\n";
  311. echo " <tr><td>opus@16000h@10i</td><td>Opus 16khz using 10 ms ptime (mono and stereo)</td></tr>\n";
  312. echo " <tr><td>opus@16000h@20i</td><td>Opus 16khz using 20 ms ptime (mono and stereo)</td></tr>\n";
  313. echo " <tr><td>opus@16000h@40i</td><td>Opus 16khz using 40 ms ptime</td></tr>\n";
  314. echo " <tr><td>opus@8000h@10i</td><td>Opus 8khz using 10 ms ptime (mono and stereo)</td></tr>\n";
  315. echo " <tr><td>opus@8000h@20i</td><td>Opus 8khz using 20 ms ptime (mono and stereo)</td></tr>\n";
  316. echo " <tr><td>opus@8000h@40i</td><td>Opus 8khz using 40 ms ptime</td></tr>\n";
  317. echo " <tr><td>opus@8000h@60i</td><td>Opus 8khz using 60 ms ptime</td></tr>\n";
  318. echo " <tr><td>opus@8000h@80i</td><td>Opus 8khz using 80 ms ptime</td></tr>\n";
  319. echo " <tr><td>opus@8000h@100i</td><td>Opus 8khz using 100 ms ptime</td></tr>\n";
  320. echo " <tr><td>opus@8000h@120i</td><td>Opus 8khz using 120 ms ptime</td></tr>\n";
  321. echo " <tr><td>iLBC@30i</td><td>iLBC using mode=30 which will win in all cases.</td></tr>\n";
  322. echo " <tr><td>DVI4@8000h@20i</td><td>IMA ADPCM 8kHz using 20ms ptime. (multiples of 10)</td></tr>\n";
  323. echo " <tr><td>DVI4@16000h@40i</td><td>IMA ADPCM 16kHz using 40ms ptime. (multiples of 10)</td></tr>\n";
  324. echo " <tr><td>speex@8000h@20i</td><td>Speex 8kHz using 20ms ptime.</td></tr>\n";
  325. echo " <tr><td>speex@16000h@20i</td><td>Speex 16kHz using 20ms ptime.</td></tr>\n";
  326. echo " <tr><td>speex@32000h@20i</td><td>Speex 32kHz using 20ms ptime.</td></tr>\n";
  327. echo " <tr><td>G7221@16000h</td><td>G722.1 16kHz (aka Siren 7)</td></tr>\n";
  328. echo " <tr><td>G7221@32000h</td><td>G722.1C 32kHz (aka Siren 14)</td></tr>\n";
  329. echo " <tr><td>CELT@32000h</td><td>CELT 32kHz, only 10ms supported</td></tr>\n";
  330. echo " <tr><td>CELT@48000h</td><td>CELT 48kHz, only 10ms supported</td></tr>\n";
  331. echo " <tr><td>GSM@40i</td><td>GSM 8kHz using 40ms ptime. (GSM is done in multiples of 20, Default is 20ms)</td></tr>\n";
  332. echo " <tr><td>G722</td><td>G722 16kHz using default 20ms ptime. (multiples of 10)</td></tr>\n";
  333. echo " <tr><td>PCMU</td><td>G711 8kHz ulaw using default 20ms ptime. (multiples of 10)</td></tr>\n";
  334. echo " <tr><td>PCMA</td><td>G711 8kHz alaw using default 20ms ptime. (multiples of 10)</td></tr>\n";
  335. echo " <tr><td>G726-16</td><td>G726 16kbit adpcm using default 20ms ptime. (multiples of 10)</td></tr>\n";
  336. echo " <tr><td>G726-24</td><td>G726 24kbit adpcm using default 20ms ptime. (multiples of 10)</td></tr>\n";
  337. echo " <tr><td>G726-32</td><td>G726 32kbit adpcm using default 20ms ptime. (multiples of 10)</td></tr>\n";
  338. echo " <tr><td>G726-40</td><td>G726 40kbit adpcm using default 20ms ptime. (multiples of 10)</td></tr>\n";
  339. echo " <tr><td>AAL2-G726-16</td><td>Same as G726-16 but using AAL2 packing. (multiples of 10)</td></tr>\n";
  340. echo " <tr><td>AAL2-G726-24</td><td>Same as G726-24 but using AAL2 packing. (multiples of 10)</td></tr>\n";
  341. echo " <tr><td>AAL2-G726-32</td><td>Same as G726-32 but using AAL2 packing. (multiples of 10)</td></tr>\n";
  342. echo " <tr><td>AAL2-G726-40</td><td>Same as G726-40 but using AAL2 packing. (multiples of 10)</td></tr>\n";
  343. echo " <tr><td>LPC</td><td>LPC10 using 90ms ptime (only supports 90ms at this time)</td></tr>\n";
  344. echo " <tr><td>L16</td><td>L16 isn't recommended for VoIP but you can do it. L16 can exceed the MTU rather quickly.</td></tr>\n";
  345. echo " <tr><td colspan='2'><br /></td></tr>\n";
  346. echo " <tr><td colspan='2'>These are the passthru audio codecs:</td></tr>\n";
  347. echo " <tr><td>G729</td><td>G729 in passthru mode. (mod_g729)</td></tr>\n";
  348. echo " <tr><td>G723</td><td>G723.1 in passthru mode. (mod_g723_1)</td></tr>\n";
  349. echo " <tr><td>AMR</td><td>AMR in passthru mode. (mod_amr)</td></tr>\n";
  350. echo " <tr><td colspan='2'><br /></td></tr>\n";
  351. echo " <tr><td colspan='2'>These are the passthru video codecs: (mod_h26x)</td></tr>\n";
  352. echo " <tr><td>H261</td><td>H.261 Video</td></tr>\n";
  353. echo " <tr><td>H263</td><td>H.263 Video</td></tr>\n";
  354. echo " <tr><td>H263-1998</td><td>H.263-1998 Video</td></tr>\n";
  355. echo " <tr><td>H263-2000</td><td>H.263-2000 Video</td></tr>\n";
  356. echo " <tr><td>H264</td><td>H.264 Video</td></tr>";
  357. echo " </td>\n";
  358. echo " </tr>\n";
  359. echo " </table>\n";
  360. echo "</td>";
  361. echo "</tr>";
  362. }
  363. echo "</table>";
  364. echo "<br><br>";
  365. if ($action == "update") {
  366. echo "<input type='hidden' name='var_uuid' value='".escape($var_uuid)."'>\n";
  367. }
  368. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  369. echo "</form>";
  370. //include header
  371. require_once "resources/footer.php";
  372. ?>