From 72c9bfb841ce7f5d0b606284dda0b5d57a9aaf8a Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Tue, 16 May 2023 11:53:08 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/CMakeLists.txt | 8 +- source/controller.cc | 1 + source/controller.h | 2 + source/view/model/system_quotas.cc | 262 -------------------------- source/view/model/system_quotas.h | 35 ---- source/view/model/ubconfig_quota.cc | 39 ++++ source/view/model/ubconfig_quota.h | 58 ++++++ source/view/model/ubconfig_quotas.cc | 27 --- source/view/model/ubconfig_quotas.h | 25 --- source/view/ubl-settings-diskquota.cc | 5 + source/view/ubl-settings-diskquota.h | 3 + source/view/view_filters.cc | 36 ++-- source/view/view_filters.h | 13 +- 13 files changed, 135 insertions(+), 379 deletions(-) delete mode 100644 source/view/model/system_quotas.cc delete mode 100644 source/view/model/system_quotas.h create mode 100644 source/view/model/ubconfig_quota.cc create mode 100644 source/view/model/ubconfig_quota.h delete mode 100644 source/view/model/ubconfig_quotas.cc delete mode 100644 source/view/model/ubconfig_quotas.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 2f1ce76..87f1658 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -30,12 +30,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissin -fstack-clash-protection -fcf-protection -g") set(SOURCE_FILES + view/view_filters.cc + view/view_filters.h view/ubl-settings-diskquota.h view/ubl-settings-diskquota.cc - view/model/ubconfig_quotas.cc - view/model/ubconfig_quotas.h - view/model/system_quotas.h - view/model/system_quotas.cc + view/model/ubconfig_quota.cc + view/model/ubconfig_quota.h view/model/my_device.h view/model/my_device.cc view/model/save.h diff --git a/source/controller.cc b/source/controller.cc index 047e97d..20015bf 100644 --- a/source/controller.cc +++ b/source/controller.cc @@ -26,6 +26,7 @@ void Controller::settings() { obj_main_window->set_map_gui(&map_gui_cfg); obj_main_window->set_map_global(&map_global_cfg); obj_main_window->set_map_local(&map_system_cfg); + obj_main_window->set_obj_view_filters(&obj_view_filters); obj_main_window->settings(); } diff --git a/source/controller.h b/source/controller.h index e0d9854..5df2011 100644 --- a/source/controller.h +++ b/source/controller.h @@ -5,6 +5,7 @@ #include "view/view_about.h" #include "view/ubl-settings-diskquota.h" #include "view/model/wrapper_load_save.h" +#include "view/view_filters.h" extern int socket_ext_id_I; extern int socket_trd_id_I; @@ -24,6 +25,7 @@ public: View_about* obj_view_about = new View_about(); MainWindow* obj_main_window; Wrapper_load_save *obj_wrapper_load_save = new Wrapper_load_save(); + View_filters obj_view_filters = View_filters(); Controller(BaseObjectType* obj, Glib::RefPtr const& builder); Controller(Glib::RefPtr const& builder); diff --git a/source/view/model/system_quotas.cc b/source/view/model/system_quotas.cc deleted file mode 100644 index 254de2f..0000000 --- a/source/view/model/system_quotas.cc +++ /dev/null @@ -1,262 +0,0 @@ -#include "system_quotas.h" - -namespace Quotas_sys { - -Quotas_sys::Quotas_sys() { - map_hw_or_sw["ext2"] = "hw"; - map_hw_or_sw["ext3"] = "hw"; - map_hw_or_sw["nfs"] = "sw"; - map_hw_or_sw["NFS"] = "sw"; -} - -void Quotas_sys::set_map_device(map_str_str &map_device) { - this->map_device = &map_device; - this->check_partition_mount(); -} - -void Quotas_sys::set_map_gui(map_str_str &map_gui) { - map_gui_cfg = &map_gui; -} - -void Quotas_sys::check_partition_mount() { - string key = ""; - string response = Utils::file_read("/proc/mounts"); - for (const auto& iter: (*map_device)) { - key = iter.first; - if (response.find(key) != string::npos) { - disk_mount[key] = true; - } - } -} - -string Quotas_sys::wrapper_hw_sw(string partition) { - - if ((*map_device).find(partition) != (*map_device).end()) { - string fsystem = (*map_device)[partition]; - if ((*map_device).find(fsystem) != (*map_device).end()) { - return map_hw_or_sw[fsystem]; - } - } - return ""; - -} - -bool Quotas_sys::check_on_quotas_system(string cmd) { - string response = obj_process_call.call_all_sections(cmd); - if (response.length() > 0) { - return true; - } - else { - return false; - } -} - -struct status_quotas Quotas_sys::check_on_quotas_system_2_hw(string params) { - string cmd = "quotaon -ugPvp " + params; - string response = obj_process_call.call_all_sections(cmd); - struct status_quotas status; - if (response.length() > 0 && response.find("Cannot find mountpoint for device ") == string::npos) { - status.status = true; - vector vec_str = Utils::split(response, '\n'); - string array_str[3] = {"group", "user", "project"}; - for (int index = 0; index < 3; index++) { - string u_g_p = array_str[index]; - for (const string& vec_u_g_p : vec_str) { - if (vec_u_g_p.find(u_g_p) != string::npos && vec_u_g_p.find("accounting") != string::npos ) { - if (index == 0) { - status.group = true; - } - else if (index == 1) { - status.user = true; - } - else if (index == 2) { - status.project = true; - } - } - else if (vec_u_g_p.find(u_g_p) != string::npos && vec_u_g_p.find("enforced") != string::npos){ - if (index == 0) { - status.group = false; - } - else if (index == 1) { - status.user = false; - } - else if (index == 2) { - status.project = false; - } - } - } - } - } - else { - status.group = false; - status.user = false; - status.project = false; - status.status = false; - } - return status; - -} - -bool Quotas_sys::wrapper_on_quotas(string partition, string flag_mode) { - // Todo - // Добавить выключение квот в зависимости от диска - cout << partition << "" << flag_mode << endl; - if (disk_mount.find(partition) == disk_mount.end()) { - - } - else { - - } - return true; - } - -bool Quotas_sys::on_quota_hw(string partition, string cmd_hw, string cmd_sw) { - /* - Включить квоты, только для HW ext2,3,4: - Если ФС, уже существует и без HW атрибут квот ext2,3,4 - Раздел должен быть отмонтирован - */ - if (this->wrapper_hw_sw(partition) == "hw") { - obj_process_system.call(cmd_hw, ""); - obj_process_system.call("ubconfig set config SERVICESSTART+=,quotaon.service", ""); - return true; - } - else if (this->wrapper_hw_sw(partition) == "sw") { - obj_process_system.call(cmd_sw, ""); - obj_process_system.call("ubconfig set config SERVICESSTART+=,quotaon.service", ""); - return true; - } - else{ - return false; - } - return false; -} - -bool Quotas_sys::on_quota_sw(string partition, int mode) { - /* - Включить квоты, только для SW, другие ФС и сетевые NFS: - У этого исполнения квот отсутствуют проектные квоты prjquota - Раздел должен быть примонтирован - */ - if (map_hw_or_sw.find(partition) != map_hw_or_sw.end()) { - string cmd = ""; - if (mode == 0) { - cmd += "mount -vo remount,usrquota " + partition; - cmd += "; quotacheck -ucm " + partition; - cmd += "; quotaon -uv " + partition; - } - else if (mode == 1) { - cmd += "; mount -vo remount,grpquota " + partition; - cmd += "; quotacheck -gcm " + partition; - cmd += "; quotaon -gv " + partition; - } - else if (mode == 2) { - cmd += "; quotaon -ugPv " + partition; - } - else if (mode == 3) { - cmd += "; quotaon -augPv"; - } - else { - return false; - } - cmd += "; ubconfig set config SERVICESSTART+=,quotaon.service"; - obj_process_system.call(cmd, ""); - return true; - } - return false; -} - -bool Quotas_sys::off_quota(string partition, string quota_hw, string quota_sw) { - string cmd = ""; - if (map_hw_or_sw.find(partition) != map_hw_or_sw.end()) { - if (this->wrapper_hw_sw(partition) == "hw") { - cmd = quota_hw + " " + partition; - obj_process_system.call(cmd, ""); - return true; - } - else if (this->wrapper_hw_sw(partition) == "sw") { - cmd = quota_sw + " " + partition; - obj_process_system.call(cmd, ""); - return true; - } - } - return false; - -} - -vector Quotas_sys::pars_data(string cmd) { - string start_pars = "------\n"; - string response = obj_process_call.call_all_sections(cmd); - size_t index_start = response.find(start_pars); - string line_pars = ""; - struct data_all_quotas struct_data; - vector vec_struct_data; - int index = 0; - int old_index = index; - if (index_start != string::npos) { - response = response.substr(index_start+start_pars.length(), response.length()); - vector vec_index_sep = Utils::find_all(response, "\n"); - for (size_t i = 0; i < vec_index_sep.size(); i++) { - old_index = index; - index = vec_index_sep[i]; - if (index-1 == old_index) { - break; - } - line_pars = response.substr(old_index, index); - struct_data = part_quotas_line(line_pars); - vec_struct_data.push_back(struct_data); - } - } - return vec_struct_data; -} - -struct data_all_quotas Quotas_sys::part_quotas_line(string line) { - struct data_all_quotas struct_data; - vector vec_index_sep = Utils::find_all(line, " "); - int old_index = 0; - string buff = ""; - int index_data = 0; - for (int& index: vec_index_sep) { - if ((index - old_index) >= 2) { - buff = line.substr(old_index, index - old_index); - cout << buff << endl; - if (index_data == 0) { - struct_data.username = buff; - } - else if (index_data == 1) { - struct_data.status = buff; - } - else if (index_data == 2) { - struct_data.block_used = buff; - } - else if (index_data == 3) { - struct_data.block_soft = buff; - } - else if (index_data == 4) { - struct_data.block_hard = buff; - } - else if (index_data == 5) { - struct_data.block_grace = buff; - } - else if (index_data == 6) { - struct_data.file_used = buff; - } - else if (index_data == 7) { - struct_data.file_soft = buff; - } - else if (index_data == 8) { - struct_data.file_hard = buff; - } - else if (index == 9) { - struct_data.file_grace = buff; - } - index_data += 1; - } - old_index = index; - } - if (index_data != 0) {struct_data.is_validate = true; } - else {struct_data.is_validate = false; } - return struct_data; -} - -} \ No newline at end of file diff --git a/source/view/model/system_quotas.h b/source/view/model/system_quotas.h deleted file mode 100644 index 65b2b5e..0000000 --- a/source/view/model/system_quotas.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef SYSTEM_CMD_QUOTAS -#define SYSTEM_CMD_QUOTAS -#include "../../project_lib.h" -#include "../../my_type.h" -#include "my_process.h" -#include "util.h" - -namespace Quotas_sys { -class Quotas_sys { - public: - map_str_str map_hw_or_sw; - map_str_str* map_device; - map_str_str* map_gui_cfg; - map disk_mount; - My_Process::My_Process_system obj_process_system = My_Process::My_Process_system(); - My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); - public: - Quotas_sys(); - void set_map_gui(map_str_str &map_gui); - void check_partition_mount(); - void format_cmd_quotas_system(struct struct_quotas& _struct_quota); - bool off_quota(string partition, string quota_hw, string quota_sw); - bool check_on_quotas_system(string cmd); - struct status_quotas check_on_quotas_system_2_hw(string params); - bool on_quota_hw(string partition, string cmd_hw, string cmd_sw); - bool on_quota_sw(string partition, int mode); - vector pars_data(string cmd); - void set_map_device(map_str_str &map_device); - string wrapper_hw_sw(string partition); - bool wrapper_on_quotas(string partition, string flag_mode); - protected: - struct data_all_quotas part_quotas_line(string line); -}; -} -#endif \ No newline at end of file diff --git a/source/view/model/ubconfig_quota.cc b/source/view/model/ubconfig_quota.cc new file mode 100644 index 0000000..653ff88 --- /dev/null +++ b/source/view/model/ubconfig_quota.cc @@ -0,0 +1,39 @@ +#include "ubconfig_quota.h" + + + +Ubconfig_quota::Ubconfig_quota(/* args */) +{ +} + +Ubconfig_quota::~Ubconfig_quota() +{ +} + +void Ubconfig_quota::set_map_global(map_str_str* map_global_cfg) { + this->map_global_cfg = map_global_cfg; +} + +void Ubconfig_quota::set_map_local(map_str_str* map_system_cfg) { + this->map_system_cfg = map_system_cfg; +} + +void Ubconfig_quota::remove_key_to_vec(string key) { + cout << key << endl; +} + +void Ubconfig_quota::add_key_to_vec(string key) { + cout << key << endl; +} + +void Ubconfig_quota::set_vec_key(vector* vec_param_names) { + this->vec_param_names = vec_param_names; +} + +void Ubconfig_quota::format_data() { + +} + + + + diff --git a/source/view/model/ubconfig_quota.h b/source/view/model/ubconfig_quota.h new file mode 100644 index 0000000..08d63ce --- /dev/null +++ b/source/view/model/ubconfig_quota.h @@ -0,0 +1,58 @@ +#ifndef UBCONFIG_QUOTAS_H +#define UBCONFIG_QUOTAS_H + +#include "../../my_type.h" +#include "../../project_lib.h" + +class Ubconfig_quota +{ +private: + map_str_str* map_gui_cfg = NULL; + map_str_str* map_global_cfg = NULL; + map_str_str* map_system_cfg = NULL; + vector* vec_param_names = NULL; + struct Size { + int size_0; + int size_1; + int size_2; + int size_3; + int size_4; + int size_5; + }; + struct User { + bool active; + string device; + vector users; + struct Size obj_size; + }; + struct Group { + bool active; + string device; + vector groups; + struct Size obj_size; + }; + struct Prjquota { + bool active; + string device; + vector prjquota_name; + struct Size obj_size; + }; + struct Quotas { + struct User obj_user; + struct Group obj_group; + struct Prjquota obj_prjquota; + }; +public: + Ubconfig_quota(/* args */); + ~Ubconfig_quota(); + void set_map_gui(map_str_str* map_gui_cfg); + void set_map_global(map_str_str* map_global_cfg); + void set_map_local(map_str_str* map_system_cfg); + void set_vec_key(vector* vec_param_names); + void remove_key_to_vec(string key); + void add_key_to_vec(string key); + void format_data(); + +}; + +#endif \ No newline at end of file diff --git a/source/view/model/ubconfig_quotas.cc b/source/view/model/ubconfig_quotas.cc deleted file mode 100644 index 88bcb30..0000000 --- a/source/view/model/ubconfig_quotas.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "ubconfig_quotas.h" - -namespace Quotas_ubconfig { - -void Quotas_ubconfig::format_cmd_quotas(struct struct_quotas& _struct_quota) { - string key = "DISK_QUOTA["; - key += ":" + _struct_quota.device + "]"; - string value = _struct_quota.name + ":" + _struct_quota.cmd; - (*map_gui_cfg)[key] = value; -} - -bool Quotas_ubconfig::off_quota(string partition, string quota_type, string state) { - string key = "DISK_QUOTA[" + quota_type + ":" + partition + "]"; - string value = "disable"; - (*map_gui_cfg)[key] = state; - return true; -} -void Quotas_ubconfig::set_map_gui(map_str_str &map_gui) { - map_gui_cfg = &map_gui; -} -Quotas_ubconfig::Quotas_ubconfig() { - map_hw_or_sw["ext2"] = "hw"; - map_hw_or_sw["ext3"] = "hw"; - map_hw_or_sw["nfs"] = "sw"; - map_hw_or_sw["NFS"] = "sw"; -} -} \ No newline at end of file diff --git a/source/view/model/ubconfig_quotas.h b/source/view/model/ubconfig_quotas.h deleted file mode 100644 index 8ace1ad..0000000 --- a/source/view/model/ubconfig_quotas.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef UBCONFIG_QUOTAS -#define UBCONFIG_QUOTAS - -#include "../../project_lib.h" -#include "../../my_type.h" -#include "my_process.h" -#include "util.h" - -namespace Quotas_ubconfig { - - -class Quotas_ubconfig{ - public: - map_str_str map_hw_or_sw; - - map_str_str* map_gui_cfg; - My_Process::My_Process_system obj_process_system = My_Process::My_Process_system(); - My_Process::My_Process_call obj_process_call = My_Process::My_Process_call(); - Quotas_ubconfig(); - bool off_quota(string partition, string quota_type, string state); - void format_cmd_quotas(struct struct_quotas& _struct_quota); - void set_map_gui(map_str_str &map_gui); -}; -} -#endif diff --git a/source/view/ubl-settings-diskquota.cc b/source/view/ubl-settings-diskquota.cc index a5c9952..50026f2 100755 --- a/source/view/ubl-settings-diskquota.cc +++ b/source/view/ubl-settings-diskquota.cc @@ -36,6 +36,10 @@ void MainWindow::set_obj_wrapper_load_save(Wrapper_load_save* obj_wrapper_load_s this->obj_wrapper_load_save = obj_wrapper_load_save; } +void MainWindow::set_obj_view_filters(View_filters* obj_view_filters) { + this->obj_view_filters = obj_view_filters; +} + void MainWindow::settings() { this->get_builder(); this->lacalization(); @@ -512,6 +516,7 @@ void MainWindow::mode_switch_quota() { } void MainWindow::filters_show() { + obj_view_filters->show(); } diff --git a/source/view/ubl-settings-diskquota.h b/source/view/ubl-settings-diskquota.h index 67deb20..6319693 100644 --- a/source/view/ubl-settings-diskquota.h +++ b/source/view/ubl-settings-diskquota.h @@ -8,6 +8,7 @@ #include "ubl-util-standard.c" #include "../var.h" #include "model/wrapper_load_save.h" +#include "view_filters.h" using namespace std; @@ -166,6 +167,7 @@ class MainWindow { map_str_str* map_global_cfg = NULL; map_str_str* map_system_cfg = NULL; Wrapper_load_save* obj_wrapper_load_save = NULL; + View_filters* obj_view_filters = NULL; //Devices::Parted obj_device = Devices::Parted(); //Quotas_sys::Quotas_sys obj_quotas_sys = Quotas_sys::Quotas_sys(); //Quotas_ubconfig::Quotas_ubconfig obj_quotas_ubconfig = Quotas_ubconfig::Quotas_ubconfig(); @@ -233,6 +235,7 @@ class MainWindow { void wrapper_save_all(); void wrapper_save_system(); void wrapper_save_global(); + void set_obj_view_filters(View_filters* obj_view_filters); }; void wrapper_help_show(GtkWidget *self, char* link, gpointer user_data); void help(); diff --git a/source/view/view_filters.cc b/source/view/view_filters.cc index bd29f58..c26ecc2 100644 --- a/source/view/view_filters.cc +++ b/source/view/view_filters.cc @@ -1,4 +1,4 @@ -#include "View_filters.h" +#include "view_filters.h" View_filters::View_filters(/* args */){ builder = Gtk::Builder::create_from_file(path_glade); @@ -25,10 +25,6 @@ void View_filters::settings() { this->event(); } -void View_filters::set_path_glade(string path_glade) { - this->path_glade = path_glade; -} - void View_filters::get_builder() { builder->get_widget("wndFilters", wndFilters); builder->get_widget("chbFilterName", chbFilterName); @@ -68,49 +64,49 @@ void View_filters::lacalization() { void View_filters::event() { chbFilterName->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterName)); + &View_filters::set_map_flag), chbFilterName)); chbFilterQuotas->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterQuotas)); + &View_filters::set_map_flag), chbFilterQuotas)); chbFilterSize->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterSize)); + &View_filters::set_map_flag), chbFilterSize)); chbFilterSoftLimitSize->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterSoftLimitSize)); + &View_filters::set_map_flag), chbFilterSoftLimitSize)); chbFilterHardLimitSize->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterHardLimitSize)); + &View_filters::set_map_flag), chbFilterHardLimitSize)); chbFilterHardLimitSizeDelay->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterHardLimitSizeDelay)); + &View_filters::set_map_flag), chbFilterHardLimitSizeDelay)); chbFilterFiles->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterFiles)); + &View_filters::set_map_flag), chbFilterFiles)); chbFilterSoftLimitFile->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterSoftLimitFile)); + &View_filters::set_map_flag), chbFilterSoftLimitFile)); chbFilterHardLimitFile->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterHardLimitFile)); + &View_filters::set_map_flag), chbFilterHardLimitFile)); chbFilterHardLimitFileDelay->signal_toggled().connect( sigc::bind (sigc::mem_fun(*this, - &MainWindow::set_map_flag), chbFilterHardLimitFileDelay)); + &View_filters::set_map_flag), chbFilterHardLimitFileDelay)); btnFiltersSave->signal_clicked().connect(sigc::mem_fun(*this, - &MainWindow::save)); + &View_filters::btn_save)); btnFiltersCancel->signal_clicked().connect(sigc::mem_fun(*this, - &MainWindow::cancel)); + &View_filters::btn_cancel)); } void View_filters::set_map_flag(Gtk::CheckButton* check_button) { map_filters_flag[check_button->get_label()] = check_button->get_active(); } -void View_filters::save() { +void View_filters::btn_save() { wndFilters->hide(); } -void View_filters::cancel() { +void View_filters::btn_cancel() { wndFilters->hide(); } @@ -119,7 +115,7 @@ map View_filters::get_filters() { } void View_filters::set_map_flag_false() { - for (auto& [key: value]: map_filters_flag) { + for (auto& [key, value]: map_filters_flag) { map_filters_flag[key] = false; } } \ No newline at end of file diff --git a/source/view/view_filters.h b/source/view/view_filters.h index 79085c3..58a026b 100644 --- a/source/view/view_filters.h +++ b/source/view/view_filters.h @@ -3,12 +3,14 @@ #include "../project_lib.h" #include "../var.h" +using namespace std; + class View_filters { private: - std::map map_filters_flag; + map map_filters_flag; private: - Glib::RefPtr const& builder; + Glib::RefPtr builder; Gtk::Window *wndFilters; Gtk::CheckButton *chbFilterName; Gtk::CheckButton *chbFilterQuotas; @@ -32,13 +34,12 @@ public: void get_builder(); void settings(); void show(); - void set_path_glade(string str_path_glade) private: void set_map_flag(Gtk::CheckButton* check_button); - void save(); - void cancel(); + void btn_save(); + void btn_cancel(); void set_map_flag_false(); - map get_filters() + map get_filters(); }; #endif