group_permissions.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. require_once "root.php";
  22. require_once "includes/require.php";
  23. require_once "includes/checkauth.php";
  24. if (permission_exists('group_permissions') || if_group("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. require_once "includes/header.php";
  32. require_once "includes/paging.php";
  33. //get the list of installed apps from the core and mod directories
  34. $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
  35. $x=0;
  36. foreach ($config_list as &$config_path) {
  37. include($config_path);
  38. $x++;
  39. }
  40. //if there are no permissions listed in v_group_permissions then set the default permissions
  41. $sql = "";
  42. $sql .= "select count(*) as count from v_group_permissions ";
  43. $prep_statement = $db->prepare(check_sql($sql));
  44. $prep_statement->execute();
  45. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  46. foreach ($result as &$row) {
  47. $group_permission_count = $row["count"];
  48. break; //limit to 1 row
  49. }
  50. unset ($prep_statement);
  51. if ($group_permission_count == 0) {
  52. //no permissions found add the defaults
  53. foreach($apps as $app) {
  54. foreach ($app['permissions'] as $row) {
  55. foreach ($row['groups'] as $group) {
  56. //add the record
  57. $sql = "insert into v_group_permissions ";
  58. $sql .= "(";
  59. $sql .= "group_permission_uuid, ";
  60. $sql .= "domain_uuid, ";
  61. $sql .= "permission_name, ";
  62. $sql .= "group_name ";
  63. $sql .= ")";
  64. $sql .= "values ";
  65. $sql .= "(";
  66. $sql .= "'".uuid()."', ";
  67. $sql .= "'$domain_uuid', ";
  68. $sql .= "'".$row['name']."', ";
  69. $sql .= "'".$group."' ";
  70. $sql .= ")";
  71. $db->exec(check_sql($sql));
  72. unset($sql);
  73. }
  74. }
  75. }
  76. }
  77. //get the http values and set them as php variables
  78. $group_name = $_REQUEST['group_name'];
  79. //get the permissions assigned to this group
  80. $sql = "";
  81. $sql .= " select * from v_group_permissions ";
  82. $sql .= "where domain_uuid = '$domain_uuid' ";
  83. $sql .= "and group_name = '$group_name' ";
  84. $prep_statement = $db->prepare(check_sql($sql));
  85. $prep_statement->execute();
  86. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  87. foreach ($result as &$row) {
  88. $permission_name = $row["permission_name"];
  89. $permissions_db[$permission_name] = "true";
  90. }
  91. //show the db checklist
  92. //echo "<pre>";
  93. //print_r($permissions_db);
  94. //echo "</pre>";
  95. //list all the permissions in the database
  96. foreach($apps as $app) {
  97. foreach ($app['permissions'] as $row) {
  98. if ($permissions_db[$row['name']] == "true") {
  99. $permissions_db_checklist[$row['name']] = "true";
  100. }
  101. else {
  102. $permissions_db_checklist[$row['name']] = "false";
  103. }
  104. }
  105. }
  106. //show the db checklist
  107. //echo "<pre>";
  108. //print_r($permissions_db_checklist);
  109. //echo "</pre>";
  110. //process the http post
  111. if (count($_POST)>0) {
  112. foreach($_POST['permissions_form'] as $permission) {
  113. $permissions_form[$permission] = "true";
  114. }
  115. //list all the permissions
  116. foreach($apps as $app) {
  117. foreach ($app['permissions'] as $row) {
  118. if ($permissions_form[$row['name']] == "true") {
  119. $permissions_form_checklist[$row['name']] = "true";
  120. }
  121. else {
  122. $permissions_form_checklist[$row['name']] = "false";
  123. }
  124. }
  125. }
  126. //show the form db checklist
  127. //echo "<pre>";
  128. //print_r($permissions_form_checklist);
  129. //echo "</pre>";
  130. //list all the permissions
  131. foreach($apps as $app) {
  132. foreach ($app['permissions'] as $row) {
  133. $permission = $row['name'];
  134. if ($permissions_db_checklist[$permission] == "true" && $permissions_form_checklist[$permission] == "true") {
  135. //matched do nothing
  136. }
  137. if ($permissions_db_checklist[$permission] == "false" && $permissions_form_checklist[$permission] == "false") {
  138. //matched do nothing
  139. }
  140. if ($permissions_db_checklist[$permission] == "true" && $permissions_form_checklist[$permission] == "false") {
  141. //delete the record
  142. $sql = "delete from v_group_permissions ";
  143. $sql .= "where domain_uuid = '$domain_uuid' ";
  144. $sql .= "and group_name = '$group_name' ";
  145. $sql .= "and permission_name = '$permission' ";
  146. $db->exec(check_sql($sql));
  147. unset($sql);
  148. //set the permission to false in the permissions_db_checklist
  149. $permissions_db_checklist[$permission] = "false";
  150. }
  151. if ($permissions_db_checklist[$permission] == "false" && $permissions_form_checklist[$permission] == "true") {
  152. //add the record
  153. $sql = "insert into v_group_permissions ";
  154. $sql .= "(";
  155. $sql .= "group_permission_uuid, ";
  156. $sql .= "domain_uuid, ";
  157. $sql .= "permission_name, ";
  158. $sql .= "group_name ";
  159. $sql .= ")";
  160. $sql .= "values ";
  161. $sql .= "(";
  162. $sql .= "'".uuid()."', ";
  163. $sql .= "'$domain_uuid', ";
  164. $sql .= "'$permission', ";
  165. $sql .= "'$group_name' ";
  166. $sql .= ")";
  167. $db->exec(check_sql($sql));
  168. unset($sql);
  169. //set the permission to true in the permissions_db_checklist
  170. $permissions_db_checklist[$permission] = "true";
  171. }
  172. }
  173. }
  174. }
  175. //show the content
  176. echo "<form method='post' name='frm' action=''>\n";
  177. echo "<div align='center'>";
  178. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  179. echo "<tr class='border'>\n";
  180. echo " <td align=\"center\">\n";
  181. echo " <br>";
  182. echo "<table width='100%' border='0'>\n";
  183. echo "<tr>\n";
  184. echo "<td width='50%' align=\"left\" nowrap=\"nowrap\"><b>Group Permission List for $group_name</b></td>\n";
  185. echo "<td width='50%' align=\"right\">\n";
  186. echo " <input type='button' class='btn' name='' alt='back' onclick=\"window.location='grouplist.php'\" value='Back'> ";
  187. echo "</td>\n";
  188. echo "</tr>\n";
  189. echo "<tr>\n";
  190. echo "<td align=\"left\" colspan='2'>\n";
  191. echo " Assign permissions to groups.<br /><br />\n";
  192. echo "</td>\n";
  193. echo "</tr>\n";
  194. echo "</tr></table>\n";
  195. echo "<br />\n";
  196. $c = 0;
  197. $row_style["0"] = "row_style0";
  198. $row_style["1"] = "row_style1";
  199. echo "<div align='left'>\n";
  200. //list all the permissions
  201. foreach($apps as $app) {
  202. $app_name = $app['name'];
  203. $description = $app['description']['en'];
  204. echo "<strong>".$app_name."</strong><br />\n";
  205. echo "".$description."<br /><br />";
  206. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  207. echo "<tr>\n";
  208. echo "<th>Permissions</th>\n";
  209. echo "<th>Description</th>\n";
  210. echo "<tr>\n";
  211. foreach ($app['permissions'] as $row) {
  212. echo "<tr >\n";
  213. echo " <td valign='top' style='width:250px' nowrap='nowrap' class='".$row_style[$c]."'>\n";
  214. if ($permissions_db_checklist[$row['name']] == "true") {
  215. echo " <input type='checkbox' name='permissions_form[]' checked='checked' value='".$row['name']."'>\n";
  216. }
  217. else {
  218. echo " <input type='checkbox' name='permissions_form[]' value='".$row['name']."'>\n";
  219. }
  220. echo " &nbsp; ".$row['name']."\n";
  221. echo " </td>\n";
  222. echo " <td valign='top' class='".$row_style[$c]."'>\n";
  223. echo " &nbsp; ".$row['description']."\n";
  224. echo " </td>\n";
  225. echo "</tr>\n";
  226. if ($c==0) { $c=1; } else { $c=0; }
  227. }
  228. echo "<tr>\n";
  229. echo " <td colspan='3' align='right'>\n";
  230. echo " <input type='submit' name='submit' class='btn' value='Save'>\n";
  231. echo " </td>\n";
  232. echo "</tr>\n";
  233. echo "</table>";
  234. echo "<br />\n";
  235. } //end foreach
  236. unset($sql, $result, $row_count);
  237. echo "</div>";
  238. echo "<br><br>";
  239. echo "<br><br>";
  240. echo "</td>";
  241. echo "</tr>";
  242. echo "</table>";
  243. echo "</div>";
  244. echo "<form>\n";
  245. echo "<br><br>";
  246. //show the footer
  247. require_once "includes/footer.php";
  248. ?>