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.

144 lines
5.4 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) 2016 - 2022
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //if the number of rows is 0 then read the acl xml into the database
  22. if ($domains_processed == 1) {
  23. //add the access control list to the database
  24. $sql = "select count(*) from v_access_controls ";
  25. $database = new database;
  26. $num_rows = $database->select($sql, null, 'column');
  27. if ($num_rows == 0) {
  28. //set the directory
  29. $xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
  30. $xml_file = $xml_dir."/acl.conf.xml";
  31. $xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/acl.conf';
  32. //load the xml and save it into an array
  33. if (file_exists($xml_file)) {
  34. $xml_string = file_get_contents($xml_file);
  35. }
  36. elseif (file_exists($xml_file_alt)) {
  37. $xml_string = file_get_contents(xml_file_alt);
  38. }
  39. else {
  40. $xml_string = "<configuration name=\"acl.conf\" description=\"Network Lists\">\n";
  41. $xml_string .= " <network-lists>\n";
  42. $xml_string .= " <list name=\"rfc1918\" default=\"deny\">\n";
  43. $xml_string .= " <node type=\"allow\" cidr=\"10.0.0.0/8\"/>\n";
  44. $xml_string .= " <node type=\"allow\" cidr=\"172.16.0.0/12\"/>\n";
  45. $xml_string .= " <node type=\"allow\" cidr=\"192.168.0.0/16\"/>\n";
  46. $xml_string .= " </list>\n";
  47. $xml_string .= " <list name=\"providers\" default=\"deny\">\n";
  48. //$xml_string .= " <node type=\"allow\" domain=\"".$_SESSION['domain_name']."\"/>\n";
  49. $xml_string .= " </list>\n";
  50. $xml_string .= " </network-lists>\n";
  51. $xml_string .= "</configuration>\n";
  52. }
  53. $xml_object = simplexml_load_string($xml_string);
  54. $json = json_encode($xml_object);
  55. $conf_array = json_decode($json, true);
  56. //process the array
  57. foreach($conf_array['network-lists']['list'] as $list) {
  58. //get the attributes
  59. $access_control_name = $list['@attributes']['name'];
  60. $access_control_default = $list['@attributes']['default'];
  61. //insert the name, description
  62. $access_control_uuid = uuid();
  63. $array['access_controls'][0]['access_control_uuid'] = $access_control_uuid;
  64. $array['access_controls'][0]['access_control_name'] = $access_control_name;
  65. $array['access_controls'][0]['access_control_default'] = $access_control_default;
  66. $p = new permissions;
  67. $p->add('access_control_add', 'temp');
  68. $database = new database;
  69. $database->app_name = 'access_controls';
  70. $database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
  71. $database->save($array, false);
  72. unset($array);
  73. $p->delete('access_control_add', 'temp');
  74. //normalize the array - needed because the array is inconsistent when there is only one row vs multiple
  75. if (strlen($list['node']['@attributes']['type']) > 0) {
  76. $list['node'][]['@attributes'] = $list['node']['@attributes'];
  77. unset($list['node']['@attributes']);
  78. }
  79. //add the nodes
  80. foreach ($list['node'] as $row) {
  81. //get the name and value pair
  82. $node_type = $row['@attributes']['type'];
  83. $node_cidr = $row['@attributes']['cidr'];
  84. $node_domain = $row['@attributes']['domain'];
  85. $node_description = $row['@attributes']['description'];
  86. //replace $${domain}
  87. if (strlen($node_domain) > 0) {
  88. $node_domain = str_replace("\$\${domain}", $domain_name, $node_domain);
  89. }
  90. //add the profile settings into the database
  91. $access_control_node_uuid = uuid();
  92. $array['access_control_nodes'][0]['access_control_node_uuid'] = $access_control_node_uuid;
  93. $array['access_control_nodes'][0]['access_control_uuid'] = $access_control_uuid;
  94. $array['access_control_nodes'][0]['node_type'] = $node_type;
  95. $array['access_control_nodes'][0]['node_cidr'] = $node_cidr;
  96. $array['access_control_nodes'][0]['node_domain'] = $node_domain;
  97. $array['access_control_nodes'][0]['node_description'] = $node_description;
  98. $p = new permissions;
  99. $p->add('access_control_node_add', 'temp');
  100. $database = new database;
  101. $database->app_name = 'access_controls';
  102. $database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
  103. $database->save($array, false);
  104. unset($array);
  105. $p->delete('access_control_node_add', 'temp');
  106. }
  107. }
  108. //rename the file
  109. if (file_exists($xml_dir.'/acl.conf.xml')) {
  110. rename($xml_dir.'/acl.conf.xml', $xml_dir.'/acl.conf');
  111. }
  112. }
  113. unset($sql, $num_rows);
  114. //remove orphaned access control nodes
  115. $sql = "delete from v_access_control_nodes ";
  116. $sql .= "where access_control_uuid not in ( ";
  117. $sql .= " select access_control_uuid from v_access_controls ";
  118. $sql .= ")";
  119. $database = new database;
  120. $database->execute($sql, null);
  121. unset($sql);
  122. }
  123. ?>