From 3cbeeef59b956d1af97312d05ff6598cc03b9c8b Mon Sep 17 00:00:00 2001 From: root Date: Thu, 28 Apr 2022 06:38:22 -0500 Subject: [PATCH] Fixes in data.php and calc_data_usage.php to write to log file --- bin/calc_data_usage.php | 8 ++-- bin/data.php | 11 ++--- bin/disable_users.php | 89 ++++++++++++++++++++++++++++++++++++++ bin/group_folders.php | 95 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 9 deletions(-) create mode 100755 bin/disable_users.php create mode 100755 bin/group_folders.php diff --git a/bin/calc_data_usage.php b/bin/calc_data_usage.php index 4aa0a6e..025a334 100755 --- a/bin/calc_data_usage.php +++ b/bin/calc_data_usage.php @@ -2,7 +2,7 @@ send_log("Data Usage: Start"); + $log_file->send_log("Data Usage: Start"); + var_dump($log_file); $directories = data_functions::get_all_directories($db); foreach ($directories as $directory) { $data_dir = new data_dir($db,$directory['data_dir_id']); diff --git a/bin/disable_users.php b/bin/disable_users.php new file mode 100755 index 0000000..cb2ec98 --- /dev/null +++ b/bin/disable_users.php @@ -0,0 +1,89 @@ +#!/usr/bin/env php +getMessage()); + } + //Sets up ldap connection + $ldap = new \IGBIllinois\ldap(settings::get_ldap_host(), + settings::get_ldap_base_dn(), + settings::get_ldap_port(), + settings::get_ldap_ssl(), + settings::get_ldap_tls()); + $log_file = new \IGBIllinois\log(settings::get_log_enabled(),settings::get_log_file()); + $users = User::getUsers($db,User::DISABLED); + + $devices = Device::getAllDevices($db); + foreach ($users as $user) { + $user_obj = new User($db); + $user_obj->load($user['id']); + $user_obj->setGroupIds(array()); + $device_access = array(); + foreach ($devices as $device) { + if ($user_obj->hasAccessTo($device['id'])) { + $user_obj->removeAccessTo($device['id']); + } + } + + } + + $groups = Group::getAllGroups($db); + foreach ($groups as $group) { + $group_obj = new Group($db); + $group_obj->load($group['id']); + $members = $group_obj->getMembers(); + if (!count($members)) { + $group_obj->delete(); + } + + } +} +?> + diff --git a/bin/group_folders.php b/bin/group_folders.php new file mode 100755 index 0000000..afe91ab --- /dev/null +++ b/bin/group_folders.php @@ -0,0 +1,95 @@ +#!/usr/bin/env php +getMessage()); + } + //Sets up ldap connection + $ldap = new \IGBIllinois\ldap(settings::get_ldap_host(), + settings::get_ldap_base_dn(), + settings::get_ldap_port(), + settings::get_ldap_ssl(), + settings::get_ldap_tls()); + $log_file = new \IGBIllinois\log(settings::get_log_enabled(),settings::get_log_file()); + + $handle = fopen("group_folders.csv","r"); + $all_users = User::getUsers($db); + if ($handle) { + while (($line = fgets($handle)) !== false) { + $user_name = trim(rtrim($line)); + $path = "/core-server/groups/" . $user_name; + echo $path . "\n"; + $user_obj = new user($db); + $sql = "SELECT id FROM users where user_name=:user_name LIMIT 1"; + $query = $db->prepare($sql); + $query->execute(array(':user_name'=>$user_name)); + $result = $query->fetch(PDO::FETCH_ASSOC); + $user_id = $result['id']; + echo "User ID: " . $user_id . "\n"; + $group_sql = "SELECT id FROM groups WHERE netid=:user_name LIMIT 1"; + $group_query = $db->prepare($group_sql); + $group_query->execute(array(':user_name'=>$user_name)); + $group_result = $group_query->fetch(PDO::FETCH_ASSOC); + $group_id = $group_result['id']; + echo "Group ID: " . $group_id . "\n"; + if (!data_dir::get_id_by_directory($db,$path)) { + $insert_sql = "INSERT INTO data_dir(data_dir_group_id,data_dir_user_id,data_dir_path) VALUES(:group_id,:user_id,:path)"; + + $insert_query = $db->prepare($insert_sql); + $insert_query->execute(array(':group_id'=>$group_id,':user_id'=>$user_id,':path'=>$path)); + } + + + } + + } +} +?> +