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.

103 lines
3.8 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-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. //destroy session
  25. session_unset();
  26. session_destroy();
  27. //check for login return preference
  28. if ($_SESSION["user_uuid"] != '') {
  29. if (isset($_SESSION['login']['destination_last']) && ($_SESSION['login']['destination_last']['boolean'] == 'true')) {
  30. if ($_SERVER['HTTP_REFERER'] != '') {
  31. //convert to relative path
  32. $referrer = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER["HTTP_HOST"]) + strlen($_SERVER["HTTP_HOST"]));
  33. //check if destination url already exists
  34. $sql = "select count(*) from v_user_settings ";
  35. $sql .= "where domain_uuid = :domain_uuid ";
  36. $sql .= "and user_uuid = :user_uuid ";
  37. $sql .= "and user_setting_category = 'login' ";
  38. $sql .= "and user_setting_subcategory = 'destination' ";
  39. $sql .= "and user_setting_name = 'url' ";
  40. $paramters['domain_uuid'] = $_SESSION['domain_uuid'];
  41. $paramters['user_uuid'] = $_SESSION['user_uuid'];
  42. $database = new database;
  43. $num_rows = $database->select($sql, $parameters, 'column');
  44. $exists = ($num_rows > 0) ? true : false;
  45. unset($sql, $parameters, $num_rows);
  46. //if exists, update
  47. if ($exists) {
  48. $sql = "update v_user_settings set ";
  49. $sql .= "user_setting_value = :user_setting_value ";
  50. $sql .= "user_setting_enabled = 'true' ";
  51. $sql .= "where domain_uuid = :domain_uuid ";
  52. $sql .= "and user_uuid = :user_uuid ";
  53. $sql .= "and user_setting_category = 'login' ";
  54. $sql .= "and user_setting_subcategory = 'destination' ";
  55. $sql .= "and user_setting_name = 'url' ";
  56. $parameters['user_setting_value'] = $referrer;
  57. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  58. $parameters['user_uuid'] = $_SESSION["user_uuid"];
  59. $database = new database;
  60. $database->execute($sql, $parameters);
  61. unset($sql, $parameters);
  62. }
  63. //otherwise, insert
  64. else {
  65. //build insert array
  66. $user_setting_uuid = uuid();
  67. $array['user_settings'][0]['user_setting_uuid'] = $user_setting_uuid;
  68. $array['user_settings'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
  69. $array['user_settings'][0]['user_uuid'] = $_SESSION["user_uuid"];
  70. $array['user_settings'][0]['user_setting_category'] = 'login';
  71. $array['user_settings'][0]['user_setting_subcategory'] = 'destination';
  72. $array['user_settings'][0]['user_setting_name'] = 'url';
  73. $array['user_settings'][0]['user_setting_value'] = $referrer;
  74. $array['user_settings'][0]['user_setting_enabled'] = 'true';
  75. //grant temporary permissions
  76. $p = new permissions;
  77. $p->add('user_setting_add', 'temp');
  78. //execute insert
  79. $database = new database;
  80. $database->app_name = 'logout';
  81. $database->app_uuid = 'e9f24006-5da2-417f-94fb-7458348bae29';
  82. $database->save($array);
  83. unset($array);
  84. //revoke temporary permissions
  85. $p->delete('user_setting_add', 'temp');
  86. }
  87. }
  88. }
  89. }
  90. //redirect the user to the index page
  91. header("Location: ".PROJECT_PATH."/login.php");
  92. exit;
  93. ?>