fusionpbx/core/permissions/app_defaults.php

66 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2020-02-23 04:38:49 +01:00
<?php
if ($domains_processed == 1) {
//add the permissions
$sql = "select * from v_permissions \n";
2020-02-23 04:38:49 +01:00
$database = new database;
$database_permissions = $database->select($sql, null, 'all');
2020-03-03 20:33:12 +01:00
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php");
$x = 0;
foreach ($config_list as &$config_path) {
include($config_path);
$x++;
}
2020-02-23 04:38:49 +01:00
2020-03-03 20:33:12 +01:00
//restore default permissions
$x = 0;
foreach ($apps as $app) {
2023-05-13 20:40:14 +02:00
if (!empty($app['permissions'])) {
foreach ($app['permissions'] as $app_permission) {
//check if the permission is in the database
$permission_found = false;
2023-05-13 20:40:14 +02:00
if (!empty($database_permissions)) {
foreach($database_permissions as $row) {
if ($row['permission_name'] == $app_permission['name']) {
$permission_found = true;
}
}
}
//add the permission to the array
if (!$permission_found) {
$array['permissions'][$x]['permission_uuid'] = uuid();
$array['permissions'][$x]['permission_name'] = $app_permission['name'];
$array['permissions'][$x]['application_name'] = $app['name'];
$array['permissions'][$x]['application_uuid'] = $app['uuid'];
$array['permissions'][$x]['insert_date'] = 'now()';
$x++;
}
2020-02-23 04:38:49 +01:00
}
2020-03-03 20:33:12 +01:00
}
}
2020-02-23 04:38:49 +01:00
2020-03-03 20:33:12 +01:00
//save the data to the database
2023-05-13 20:40:14 +02:00
if (!empty($array)) {
2020-03-03 20:33:12 +01:00
//grant temporary permissions
$p = new permissions;
$p->add('permission_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'permissions';
$database->app_uuid = 'ce1498a0-46e2-487d-85de-4eec7122a984';
2021-12-24 20:39:43 +01:00
$database->save($array, false);
2020-03-03 20:33:12 +01:00
unset($array);
//revoke temporary permissions
$p->delete('permission_add', 'temp');
2020-02-23 04:38:49 +01:00
}
}
?>