device_log_edit.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. /*
  3. Copyright (c) 2019-2022 Mark J Crane <[email protected]>
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
  13. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  16. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  18. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  19. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. SUCH DAMAGE.
  23. */
  24. //set the include path
  25. $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
  26. set_include_path(parse_ini_file($conf[0])['document.root']);
  27. //includes files
  28. require_once "resources/require.php";
  29. require_once "resources/check_auth.php";
  30. //check permissions
  31. if (permission_exists('device_log_add') || permission_exists('device_log_edit')) {
  32. //access granted
  33. }
  34. else {
  35. echo "access denied";
  36. exit;
  37. }
  38. //add multi-lingual support
  39. $language = new text;
  40. $text = $language->get();
  41. //action add or update
  42. if (is_uuid($_REQUEST["id"])) {
  43. $action = "update";
  44. $device_log_uuid = $_REQUEST["id"];
  45. $id = $_REQUEST["id"];
  46. }
  47. else {
  48. $action = "add";
  49. }
  50. //get http post variables and set them to php variables
  51. if (is_array($_POST)) {
  52. $device_log_uuid = $_POST["device_log_uuid"];
  53. $device_uuid = $_POST["device_uuid"];
  54. $timestamp = $_POST["timestamp"];
  55. $device_mac_address = $_POST["device_mac_address"];
  56. $request_scheme = $_POST["request_scheme"];
  57. $http_host = $_POST["http_host"];
  58. $server_port = $_POST["server_port"];
  59. $server_protocol = $_POST["server_protocol"];
  60. $query_string = $_POST["query_string"];
  61. $remote_address = $_POST["remote_address"];
  62. $http_user_agent = $_POST["http_user_agent"];
  63. $http_status = $_POST["http_status"];
  64. $http_status_code = $_POST["http_status_code"];
  65. $http_content_body = $_POST["http_content_body"];
  66. }
  67. //process the user data and save it to the database
  68. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  69. //delete the bridge
  70. if (permission_exists('bridge_delete')) {
  71. if ($_POST['action'] == 'delete' && is_uuid($device_log_uuid)) {
  72. //prepare
  73. $array[0]['checked'] = 'true';
  74. $array[0]['uuid'] = $device_log_uuid;
  75. //delete
  76. $obj = new device_logs;
  77. $obj->delete($array);
  78. //redirect
  79. header('Location: device_logs.php');
  80. exit;
  81. }
  82. }
  83. //get the uuid from the POST
  84. if ($action == "update") {
  85. $device_log_uuid = $_POST["device_log_uuid"];
  86. }
  87. //validate the token
  88. $token = new token;
  89. if (!$token->validate($_SERVER['PHP_SELF'])) {
  90. message::add($text['message-invalid_token'],'negative');
  91. header('Location: device_logs.php');
  92. exit;
  93. }
  94. //check for all required data
  95. $msg = '';
  96. //if (strlen($device_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-device_uuid']."<br>\n"; }
  97. if (strlen($timestamp) == 0) { $msg .= $text['message-required']." ".$text['label-timestamp']."<br>\n"; }
  98. if (strlen($device_mac_address) == 0) { $msg .= $text['message-required']." ".$text['label-device_mac_address']."<br>\n"; }
  99. if (strlen($request_scheme) == 0) { $msg .= $text['message-required']." ".$text['label-request_scheme']."<br>\n"; }
  100. if (strlen($http_host) == 0) { $msg .= $text['message-required']." ".$text['label-http_host']."<br>\n"; }
  101. if (strlen($server_port) == 0) { $msg .= $text['message-required']." ".$text['label-server_port']."<br>\n"; }
  102. if (strlen($server_protocol) == 0) { $msg .= $text['message-required']." ".$text['label-server_protocol']."<br>\n"; }
  103. if (strlen($query_string) == 0) { $msg .= $text['message-required']." ".$text['label-query_string']."<br>\n"; }
  104. if (strlen($remote_address) == 0) { $msg .= $text['message-required']." ".$text['label-remote_address']."<br>\n"; }
  105. if (strlen($http_user_agent) == 0) { $msg .= $text['message-required']." ".$text['label-http_user_agent']."<br>\n"; }
  106. if (strlen($http_status) == 0) { $msg .= $text['message-required']." ".$text['label-http_status']."<br>\n"; }
  107. if (strlen($http_status_code) == 0) { $msg .= $text['message-required']." ".$text['label-http_status_code']."<br>\n"; }
  108. //if (strlen($http_content_body) == 0) { $msg .= $text['message-required']." ".$text['label-http_content_body']."<br>\n"; }
  109. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  110. require_once "resources/header.php";
  111. require_once "resources/persist_form_var.php";
  112. echo "<div align='center'>\n";
  113. echo "<table><tr><td>\n";
  114. echo $msg."<br />";
  115. echo "</td></tr></table>\n";
  116. persistformvar($_POST);
  117. echo "</div>\n";
  118. require_once "resources/footer.php";
  119. return;
  120. }
  121. //add the device_log_uuid
  122. if (!is_uuid($_POST["device_log_uuid"])) {
  123. $device_log_uuid = uuid();
  124. }
  125. //prepare the array
  126. $array['device_logs'][0]['device_log_uuid'] = $device_log_uuid;
  127. $array['device_logs'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
  128. $array['device_logs'][0]['device_uuid'] = $device_uuid;
  129. $array['device_logs'][0]['timestamp'] = $timestamp;
  130. $array['device_logs'][0]['device_mac_address'] = $device_mac_address;
  131. $array['device_logs'][0]['request_scheme'] = $request_scheme;
  132. $array['device_logs'][0]['http_host'] = $http_host;
  133. $array['device_logs'][0]['server_port'] = $server_port;
  134. $array['device_logs'][0]['server_protocol'] = $server_protocol;
  135. $array['device_logs'][0]['query_string'] = $query_string;
  136. $array['device_logs'][0]['remote_address'] = $remote_address;
  137. $array['device_logs'][0]['http_user_agent'] = $http_user_agent;
  138. $array['device_logs'][0]['http_status'] = $http_status;
  139. $array['device_logs'][0]['http_status_code'] = $http_status_code;
  140. $array['device_logs'][0]['http_content_body'] = $http_content_body;
  141. //save the data
  142. $database = new database;
  143. $database->app_name = 'device logs';
  144. $database->app_uuid = '78b1e5c7-5028-43e7-a05b-a36b44f87087';
  145. $database->save($array);
  146. //$message = $database->message;
  147. //redirect the user
  148. if (isset($action)) {
  149. if ($action == "add") {
  150. $_SESSION["message"] = $text['message-add'];
  151. }
  152. if ($action == "update") {
  153. $_SESSION["message"] = $text['message-update'];
  154. }
  155. header('Location: device_logs.php');
  156. //header('Location: device_log_edit.php?id='.urlencode($device_log_uuid));
  157. return;
  158. }
  159. }
  160. //pre-populate the form
  161. if (is_array($_GET) && $_POST["persistformvar"] != "true") {
  162. $device_log_uuid = $_GET["id"];
  163. $sql = "select * from v_device_logs ";
  164. $sql .= "where device_log_uuid = :device_log_uuid ";
  165. //$sql .= "and domain_uuid = :domain_uuid ";
  166. //$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  167. $parameters['device_log_uuid'] = $device_log_uuid;
  168. $database = new database;
  169. $row = $database->select($sql, $parameters, 'row');
  170. if (is_array($row) && sizeof($row) != 0) {
  171. $device_uuid = $row["device_uuid"];
  172. $timestamp = $row["timestamp"];
  173. $device_mac_address = $row["device_mac_address"];
  174. $request_scheme = $row["request_scheme"];
  175. $http_host = $row["http_host"];
  176. $server_port = $row["server_port"];
  177. $server_protocol = $row["server_protocol"];
  178. $query_string = $row["query_string"];
  179. $remote_address = $row["remote_address"];
  180. $http_user_agent = $row["http_user_agent"];
  181. $http_status = $row["http_status"];
  182. $http_status_code = $row["http_status_code"];
  183. $http_content_body = $row["http_content_body"];
  184. }
  185. unset($sql, $parameters, $row);
  186. }
  187. //create token
  188. $object = new token;
  189. $token = $object->create($_SERVER['PHP_SELF']);
  190. //show the header
  191. $document['title'] = $text['title-device_log'];
  192. require_once "resources/header.php";
  193. //show the content
  194. echo "<form name='frm' id='frm' method='post' action=''>\n";
  195. echo "<div class='action_bar' id='action_bar'>\n";
  196. echo " <div class='heading'><b>".$text['title-device_log']."</b></div>\n";
  197. echo " <div class='actions'>\n";
  198. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'device_logs.php']);
  199. if ($action == 'update' && permission_exists('device_log_delete')) {
  200. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  201. }
  202. if ($action == 'update' && permission_exists('device_log_copy')) {
  203. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'name'=>'btn_copy','style'=>'margin-right: 15px;','link'=>'device_log_copy.php']);
  204. }
  205. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','name'=>'action','value'=>'save']);
  206. echo " </div>\n";
  207. echo " <div style='clear: both;'>".$text['description-device_logs']."</div>\n";
  208. echo "</div>\n";
  209. if ($action == 'update' && permission_exists('device_log_delete')) {
  210. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
  211. }
  212. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  213. echo "<tr>\n";
  214. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  215. echo " ".$text['label-device_uuid']."\n";
  216. echo "</td>\n";
  217. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  218. echo " <input class='formfld' type='text' name='device_uuid' maxlength='255' value='".escape($device_uuid)."'>\n";
  219. echo "<br />\n";
  220. echo $text['description-device_uuid']."\n";
  221. echo "</td>\n";
  222. echo "</tr>\n";
  223. echo "<tr>\n";
  224. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  225. echo " ".$text['label-timestamp']."\n";
  226. echo "</td>\n";
  227. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  228. echo " <input class='formfld' type='text' name='timestamp' maxlength='255' value='".escape($timestamp)."'>\n";
  229. echo "<br />\n";
  230. echo $text['description-timestamp']."\n";
  231. echo "</td>\n";
  232. echo "</tr>\n";
  233. echo "<tr>\n";
  234. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  235. echo " ".$text['label-device_mac_address']."\n";
  236. echo "</td>\n";
  237. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  238. echo " <input class='formfld' type='text' name='device_mac_address' maxlength='255' value='".escape($device_mac_address)."'>\n";
  239. echo "<br />\n";
  240. echo $text['description-device_mac_address']."\n";
  241. echo "</td>\n";
  242. echo "</tr>\n";
  243. echo "<tr>\n";
  244. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  245. echo " ".$text['label-request_scheme']."\n";
  246. echo "</td>\n";
  247. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  248. echo " <input class='formfld' type='text' name='request_scheme' maxlength='255' value='".escape($request_scheme)."'>\n";
  249. echo "<br />\n";
  250. echo $text['description-request_scheme']."\n";
  251. echo "</td>\n";
  252. echo "</tr>\n";
  253. echo "<tr>\n";
  254. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  255. echo " ".$text['label-http_host']."\n";
  256. echo "</td>\n";
  257. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  258. echo " <input class='formfld' type='text' name='http_host' maxlength='255' value='".escape($http_host)."'>\n";
  259. echo "<br />\n";
  260. echo $text['description-http_host']."\n";
  261. echo "</td>\n";
  262. echo "</tr>\n";
  263. echo "<tr>\n";
  264. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  265. echo " ".$text['label-server_port']."\n";
  266. echo "</td>\n";
  267. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  268. echo " <input class='formfld' type='text' name='server_port' maxlength='255' value='".escape($server_port)."'>\n";
  269. echo "<br />\n";
  270. echo $text['description-server_port']."\n";
  271. echo "</td>\n";
  272. echo "</tr>\n";
  273. echo "<tr>\n";
  274. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  275. echo " ".$text['label-server_protocol']."\n";
  276. echo "</td>\n";
  277. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  278. echo " <input class='formfld' type='text' name='server_protocol' maxlength='255' value='".escape($server_protocol)."'>\n";
  279. echo "<br />\n";
  280. echo $text['description-server_protocol']."\n";
  281. echo "</td>\n";
  282. echo "</tr>\n";
  283. echo "<tr>\n";
  284. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  285. echo " ".$text['label-query_string']."\n";
  286. echo "</td>\n";
  287. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  288. echo " <input class='formfld' type='text' name='query_string' maxlength='255' value='".escape($query_string)."'>\n";
  289. echo "<br />\n";
  290. echo $text['description-query_string']."\n";
  291. echo "</td>\n";
  292. echo "</tr>\n";
  293. echo "<tr>\n";
  294. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  295. echo " ".$text['label-remote_address']."\n";
  296. echo "</td>\n";
  297. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  298. echo " <input class='formfld' type='text' name='remote_address' maxlength='255' value='".escape($remote_address)."'>\n";
  299. echo "<br />\n";
  300. echo $text['description-remote_address']."\n";
  301. echo "</td>\n";
  302. echo "</tr>\n";
  303. echo "<tr>\n";
  304. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  305. echo " ".$text['label-http_user_agent']."\n";
  306. echo "</td>\n";
  307. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  308. echo " <input class='formfld' type='text' name='http_user_agent' maxlength='255' value='".escape($http_user_agent)."'>\n";
  309. echo "<br />\n";
  310. echo $text['description-http_user_agent']."\n";
  311. echo "</td>\n";
  312. echo "</tr>\n";
  313. echo "<tr>\n";
  314. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  315. echo " ".$text['label-http_status']."\n";
  316. echo "</td>\n";
  317. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  318. echo " <input class='formfld' type='text' name='http_status' maxlength='255' value='".escape($http_status)."'>\n";
  319. echo "<br />\n";
  320. echo $text['description-http_status']."\n";
  321. echo "</td>\n";
  322. echo "</tr>\n";
  323. echo "<tr>\n";
  324. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  325. echo " ".$text['label-http_status_code']."\n";
  326. echo "</td>\n";
  327. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  328. echo " <input class='formfld' type='text' name='http_status_code' maxlength='255' value='".escape($http_status_code)."'>\n";
  329. echo "<br />\n";
  330. echo $text['description-http_status_code']."\n";
  331. echo "</td>\n";
  332. echo "</tr>\n";
  333. echo "<tr>\n";
  334. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  335. echo " ".$text['label-http_content_body']."\n";
  336. echo "</td>\n";
  337. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  338. echo " <textarea class='formfld' name='http_content_body' style='width: 100%; height: 300px; max-width: 5000px;'>".$http_content_body."</textarea>\n";
  339. echo "<br />\n";
  340. echo $text['description-http_content_body']."\n";
  341. echo "</td>\n";
  342. echo "</tr>\n";
  343. echo "</table>";
  344. echo "<br /><br />";
  345. if ($action == "update") {
  346. echo "<input type='hidden' name='device_log_uuid' value='".escape($device_log_uuid)."'>\n";
  347. }
  348. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  349. echo "</form>";
  350. //include the footer
  351. require_once "resources/footer.php";
  352. ?>