logout.php 4.1 KB

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