notification_edit.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (if_group('superadmin')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //connect to the database
  33. $database = new database;
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. // retrieve software uuid
  38. $sql = "select software_uuid, software_url, software_version from v_software";
  39. $row = $database->select($sql, null, 'row');
  40. if (is_array($row) && sizeof($row) != 0) {
  41. $software_uuid = $row["software_uuid"];
  42. $software_url = $row["software_url"];
  43. $software_version = $row["software_version"];
  44. }
  45. unset($sql, $row);
  46. if (count($_REQUEST) > 0) {
  47. //validate the token
  48. $token = new token;
  49. if (!$token->validate($_SERVER['PHP_SELF'])) {
  50. message::add($text['message-invalid_token'],'negative');
  51. header('Location: notification_edit.php');
  52. exit;
  53. }
  54. // prepare demographic information **********************************************
  55. // fusionpbx version
  56. $software_ver = $software_version;
  57. // php version
  58. $php_ver = phpversion();
  59. // webserver name & version
  60. $web_server = $_SERVER['SERVER_SOFTWARE'];
  61. // switch version
  62. $esl = event_socket::create();
  63. if ($esl->is_connected()) {
  64. $switch_result = event_socket::api('version');
  65. }
  66. $switch_ver = trim($switch_result);
  67. // database name & version
  68. switch ($db_type) {
  69. case "pgsql" : $sql = "select version();"; break;
  70. case "mysql" : $sql = "select version();"; break;
  71. case "sqlite" : $sql = "select sqlite_version();"; break;
  72. }
  73. $db_ver = $database->select($sql, null, 'column');
  74. unset($sql);
  75. // operating system name & version
  76. $os_platform = PHP_OS;
  77. $os_info_1 = php_uname("a");
  78. if ($os_platform == "Linux") {
  79. $os_info_2 = shell_exec("cat /etc/*{release,version}");
  80. $os_info_2 .= shell_exec("lsb_release -d -s");
  81. }
  82. else if (substr(strtoupper($os_platform), 0, 3) == "WIN") {
  83. $os_info_2 = trim(shell_exec("ver"));
  84. }
  85. // **************************************************************************
  86. // check for demographic only submit
  87. if (isset($_GET["demo"])) {
  88. // update remote server record with new values
  89. $url = "https://".$software_url."/app/notifications/notifications_manage.php";
  90. $url .= "?demo";
  91. $url .= "&id=".$software_uuid;
  92. $url .= "&software_ver=".urlencode($software_ver);
  93. $url .= "&php_ver=".urlencode($php_ver);
  94. $url .= "&web_server=".urlencode($web_server);
  95. $url .= "&switch_ver=".urlencode($switch_ver);
  96. $url .= "&db_type=".urlencode($db_type);
  97. $url .= "&db_ver=".urlencode($db_ver);
  98. $url .= "&os_platform=".urlencode($os_platform);
  99. $url .= "&os_info_1=".urlencode($os_info_1);
  100. $url .= "&os_info_2=".urlencode($os_info_2);
  101. if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) {
  102. $response = file_get_contents($url);
  103. }
  104. else if (function_exists('curl_version')) {
  105. $curl = curl_init();
  106. curl_setopt($curl, CURLOPT_URL, $url);
  107. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  108. $response = curl_exec($curl);
  109. curl_close($curl);
  110. }
  111. // parse response
  112. $response = json_decode($response, true);
  113. if ($response['result'] == 'submitted') {
  114. // set message
  115. message::add($text['message-demographics_submitted']);
  116. }
  117. header("Location: notification_edit.php");
  118. exit;
  119. }
  120. // retrieve submitted values
  121. $project_notifications = check_str($_POST["project_notifications"]);
  122. $project_security = check_str($_POST["project_security"]);
  123. $project_releases = check_str($_POST["project_releases"]);
  124. $project_events = check_str($_POST["project_events"]);
  125. $project_news = check_str($_POST["project_news"]);
  126. $project_notification_method = check_str($_POST["project_notification_method"]);
  127. $project_notification_recipient = check_str($_POST["project_notification_recipient"]);
  128. // get local project notification participation flag
  129. $sql = "select project_notifications from v_notifications";
  130. $current_project_notifications = $database->select($sql, null, 'row');
  131. unset($sql);
  132. // check if remote record should be removed
  133. if ($project_notifications == 'false') {
  134. if ($current_project_notifications == 'true') {
  135. // remove remote server record
  136. $url = "https://".$software_url."/app/notifications/notifications_manage.php?id=".$software_uuid."&action=delete";
  137. if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) {
  138. $response = file_get_contents($url);
  139. }
  140. else if (function_exists('curl_version')) {
  141. $curl = curl_init();
  142. curl_setopt($curl, CURLOPT_URL, $url);
  143. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  144. $response = curl_exec($curl);
  145. curl_close($curl);
  146. }
  147. // parse response
  148. $response = json_decode($response, true);
  149. if ($response['result'] == 'deleted') {
  150. // set local project notification participation flag to false
  151. $sql = "update v_notifications set project_notifications = 'false'";
  152. $database->execute($sql);
  153. unset($sql);
  154. }
  155. }
  156. // redirect
  157. message::add($text['message-update']);
  158. header("Location: notification_edit.php");
  159. exit;
  160. }
  161. // check for invalid values
  162. if ($project_notifications == 'true') {
  163. if (
  164. ($project_notification_method == 'email' && !valid_email($project_notification_recipient)) ||
  165. ($project_notification_method == 'email' && $project_notification_recipient == '')
  166. ) {
  167. $_SESSION["postback"] = $_POST;
  168. message::add($text['message-invalid_recipient'], 'negative');
  169. header("Location: notification_edit.php");
  170. exit;
  171. }
  172. }
  173. // update remote server record with new values
  174. $url = "https://".$software_url."/app/notifications/notifications_manage.php";
  175. $url .= "?id=".$software_uuid;
  176. $url .= "&security=".$project_security;
  177. $url .= "&releases=".$project_releases;
  178. $url .= "&events=".$project_events;
  179. $url .= "&news=".$project_news;
  180. $url .= "&method=".$project_notification_method;
  181. $url .= "&recipient=".urlencode($project_notification_recipient);
  182. $url .= "&software_ver=".urlencode($software_ver);
  183. $url .= "&php_ver=".urlencode($php_ver);
  184. $url .= "&web_server=".urlencode($web_server);
  185. $url .= "&switch_ver=".urlencode($switch_ver);
  186. $url .= "&db_type=".urlencode($db_type);
  187. $url .= "&db_ver=".urlencode($db_ver);
  188. $url .= "&os_platform=".urlencode($os_platform);
  189. $url .= "&os_info_1=".urlencode($os_info_1);
  190. $url .= "&os_info_2=".urlencode($os_info_2);
  191. if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) {
  192. $response = file_get_contents($url);
  193. }
  194. else if (function_exists('curl_version')) {
  195. $curl = curl_init();
  196. curl_setopt($curl, CURLOPT_URL, $url);
  197. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  198. $response = curl_exec($curl);
  199. curl_close($curl);
  200. }
  201. // parse response
  202. $response = json_decode($response, true);
  203. if ($response['result'] == 'updated' || $response['result'] == 'inserted') {
  204. // set local project notification participation flag to true
  205. $sql = "update v_notifications set project_notifications = 'true'";
  206. $database->execute($sql);
  207. unset($sql);
  208. // set message
  209. if (
  210. $project_security == 'false' &&
  211. $project_releases == 'false' &&
  212. $project_events == 'false' &&
  213. $project_news == 'false'
  214. ) {
  215. message::add($text['message-update']." - ".$text['message-no_channels'], 'alert');
  216. }
  217. else {
  218. message::add($text['message-update']);
  219. }
  220. // redirect
  221. header("Location: notification_edit.php");
  222. exit;
  223. }
  224. }
  225. // check postback session
  226. if (!isset($_SESSION["postback"])) {
  227. // check local project notification participation flag
  228. $sql = "select project_notifications from v_notifications";
  229. $row = $database->select($sql, null, 'row');
  230. if (is_array($row) && sizeof($row) != 0) {
  231. $setting["project_notifications"] = $row["project_notifications"];
  232. }
  233. unset($sql, $row);
  234. // if participation enabled
  235. if ($setting["project_notifications"] == 'true') {
  236. // get current project notification preferences
  237. $url = "https://".$software_url."/app/notifications/notifications_manage.php?id=".$software_uuid;
  238. if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) {
  239. $response = file_get_contents($url);
  240. }
  241. else if (function_exists('curl_version')) {
  242. $curl = curl_init();
  243. curl_setopt($curl, CURLOPT_URL, $url);
  244. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  245. $response = curl_exec($curl);
  246. curl_close($curl);
  247. }
  248. // parse response
  249. $setting = json_decode($response, true);
  250. $setting["project_notifications"] = 'true';
  251. }
  252. }
  253. else {
  254. // load postback variables
  255. $setting = fix_postback($_SESSION["postback"]);
  256. unset($_SESSION["postback"]);
  257. }
  258. //create token
  259. $object = new token;
  260. $token = $object->create($_SERVER['PHP_SELF']);
  261. require_once "resources/header.php";
  262. $document['title'] = $text['title-notifications'];
  263. // show the content
  264. echo "<form method='post' name='frm' id='frm'>\n";
  265. echo "<table cellpadding='0' cellspacing='0' width='100%' border='0'>\n";
  266. echo " <tr>\n";
  267. echo " <td align='left' nowrap='nowrap'><b>".$text['header-notifications']."</b><br><br></td>\n";
  268. echo " <td align='right'>";
  269. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  270. echo " <br><br>";
  271. echo " </td>\n";
  272. echo " </tr>\n";
  273. echo " <tr>\n";
  274. echo " <td align='left' colspan='2'>\n";
  275. echo " ".$text['description-notifications']."<br /><br />\n";
  276. echo " </td>\n";
  277. echo " </tr>\n";
  278. echo " <tr>\n";
  279. echo " <td width='30%' class='vncellreq' valign='top' align='left' nowrap>\n";
  280. echo $text['label-project_notifications']."\n";
  281. echo " </td>\n";
  282. echo " <td width='70%' class='vtable' align='left'>\n";
  283. echo " <select name='project_notifications' class='formfld' style='width: auto;' onchange=\"$('#notification_channels').slideToggle();\">\n";
  284. echo " <option value='false' ".(($setting["project_notifications"] == 'false') ? "selected='selected'" : null).">".$text['option-disabled']."</option>\n";
  285. echo " <option value='true' ".(($setting["project_notifications"] == 'true') ? "selected='selected'" : null).">".$text['option-enabled']."</option>\n";
  286. echo " </select><br />\n";
  287. echo $text['description-project_notifications']."\n";
  288. echo " </td>\n";
  289. echo " </tr>\n";
  290. echo "</table>\n";
  291. echo "<div id='notification_channels' ".(($setting["project_notifications"] != 'true') ? "style='display: none;'" : null).">\n";
  292. echo "<table cellpadding='0' cellspacing='0' width='100%' border='0'>\n";
  293. echo " <tr>\n";
  294. echo " <td width='30%' class='vncell' valign='top' align='left' nowrap>\n";
  295. echo $text['label-project_security']."\n";
  296. echo " </td>\n";
  297. echo " <td width='70%' class='vtable' align='left'>\n";
  298. echo " <select name='project_security' class='formfld' style='width: auto;'>\n";
  299. echo " <option value='false' ".(($setting["project_security"] == 'false') ? "selected='selected'" : null).">".$text['option-disabled']."</option>\n";
  300. echo " <option value='true' ".(($setting["project_security"] == 'true') ? "selected='selected'" : null).">".$text['option-enabled']."</option>\n";
  301. echo " </select><br />\n";
  302. echo $text['description-project_security']."\n";
  303. echo " </td>\n";
  304. echo " </tr>\n";
  305. echo " <tr>\n";
  306. echo " <td class='vncell' valign='top' align='left' nowrap>\n";
  307. echo $text['label-project_releases']."\n";
  308. echo " </td>\n";
  309. echo " <td class='vtable' align='left'>\n";
  310. echo " <select name='project_releases' class='formfld' style='width: auto;'>\n";
  311. echo " <option value='false' ".(($setting["project_releases"] == 'false') ? "selected='selected'" : null).">".$text['option-disabled']."</option>\n";
  312. echo " <option value='true' ".(($setting["project_releases"] == 'true') ? "selected='selected'" : null).">".$text['option-enabled']."</option>\n";
  313. echo " </select><br />\n";
  314. echo $text['description-project_releases']."\n";
  315. echo " </td>\n";
  316. echo " </tr>\n";
  317. echo " <tr>\n";
  318. echo " <td width='30%' class='vncell' valign='top' align='left' nowrap>\n";
  319. echo $text['label-project_events']."\n";
  320. echo " </td>\n";
  321. echo " <td width='70%' class='vtable' align='left'>\n";
  322. echo " <select name='project_events' class='formfld' style='width: auto;'>\n";
  323. echo " <option value='false' ".(($setting["project_events"] == 'false') ? "selected='selected'" : null).">".$text['option-disabled']."</option>\n";
  324. echo " <option value='true' ".(($setting["project_events"] == 'true') ? "selected='selected'" : null).">".$text['option-enabled']."</option>\n";
  325. echo " </select><br />\n";
  326. echo $text['description-project_events']."\n";
  327. echo " </td>\n";
  328. echo " </tr>\n";
  329. echo " <tr>\n";
  330. echo " <td class='vncell' valign='top' align='left' nowrap>\n";
  331. echo $text['label-project_news']."\n";
  332. echo " </td>\n";
  333. echo " <td class='vtable' align='left'>\n";
  334. echo " <select name='project_news' class='formfld' style='width: auto;'>\n";
  335. echo " <option value='false' ".(($setting["project_news"] == 'false') ? "selected='selected'" : null).">".$text['option-disabled']."</option>\n";
  336. echo " <option value='true' ".(($setting["project_news"] == 'true') ? "selected='selected'" : null).">".$text['option-enabled']."</option>\n";
  337. echo " </select><br />\n";
  338. echo $text['description-project_news']."\n";
  339. echo " </td>\n";
  340. echo " </tr>\n";
  341. echo " <input type='hidden' name='project_notification_method' value='email'>\n";
  342. /*
  343. echo " <tr>\n";
  344. echo " <td width='30%' class='vncell' valign='top' align='left' nowrap>\n";
  345. echo $text['label-project_notification_method']."\n";
  346. echo " </td>\n";
  347. echo " <td width='70%' class='vtable' align='left'>\n";
  348. echo " <select name='project_notification_method' class='formfld' style='width: auto;'>\n";
  349. echo " <option value='email' ".(($setting["project_notification_method"] == 'email') ? "selected='selected'" : null).">".$text['option-email']."</option>\n";
  350. echo " </select><br />\n";
  351. echo $text['description-project_notification_method']."\n";
  352. echo " </td>\n";
  353. echo " </tr>\n";
  354. */
  355. echo " <tr>\n";
  356. echo " <td class='vncellreq' valign='top' align='left' nowrap>\n";
  357. echo $text['label-project_notification_recipient']."\n";
  358. echo " </td>\n";
  359. echo " <td class='vtable' align='left'>\n";
  360. echo " <input class='formfld' type='text' name='project_notification_recipient' maxlength='50' value='".$setting["project_notification_recipient"]."'><br />\n";
  361. echo $text['description-project_notification_recipient']."\n";
  362. echo " </td>\n";
  363. echo " </tr>\n";
  364. echo "</table>\n";
  365. echo "</div>\n";
  366. echo "<table cellpadding='0' cellspacing='0' width='100%' border='0'>\n";
  367. echo " <tr>\n";
  368. echo " <td colspan='2' class='vtable' style='padding: 15px;' align='right'>\n";
  369. echo " ".$text['message-disclaimer']."\n";
  370. echo " <br /><br />\n";
  371. echo " ".$text['message-demographics']." <a href='?demo'>".$text['message-demographics_click_here']."</a>.\n";
  372. echo " </td>\n";
  373. echo " </tr>\n";
  374. echo "</table>\n";
  375. echo "<table cellpadding='0' cellspacing='0' width='100%' border='0'>\n";
  376. echo " <tr>\n";
  377. echo " <td align='right'>\n";
  378. echo " <input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  379. echo " <br>";
  380. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  381. echo " </td>\n";
  382. echo " </tr>";
  383. echo "</table>\n";
  384. echo "</form>\n";
  385. // include the footer
  386. require_once "resources/footer.php";
  387. ?>