Добавил фильтры

pull/13/head
Igor Belitskiy 2 years ago
parent b4b9b967a6
commit 72c9bfb841

@ -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

@ -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();
}

@ -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<Gtk::Builder> const& builder);
Controller(Glib::RefPtr<Gtk::Builder> const& builder);

@ -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<string> 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<data_all_quotas> 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<data_all_quotas> 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<int> 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<int> 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;
}
}

@ -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<string, bool> 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<data_all_quotas> 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

@ -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<string>* vec_param_names) {
this->vec_param_names = vec_param_names;
}
void Ubconfig_quota::format_data() {
}

@ -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<string>* 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<string> users;
struct Size obj_size;
};
struct Group {
bool active;
string device;
vector<string> groups;
struct Size obj_size;
};
struct Prjquota {
bool active;
string device;
vector<string> 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<string>* vec_param_names);
void remove_key_to_vec(string key);
void add_key_to_vec(string key);
void format_data();
};
#endif

@ -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";
}
}

@ -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

@ -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();
}

@ -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();

@ -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<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterName));
&View_filters::set_map_flag), chbFilterName));
chbFilterQuotas->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterQuotas));
&View_filters::set_map_flag), chbFilterQuotas));
chbFilterSize->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterSize));
&View_filters::set_map_flag), chbFilterSize));
chbFilterSoftLimitSize->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterSoftLimitSize));
&View_filters::set_map_flag), chbFilterSoftLimitSize));
chbFilterHardLimitSize->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterHardLimitSize));
&View_filters::set_map_flag), chbFilterHardLimitSize));
chbFilterHardLimitSizeDelay->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterHardLimitSizeDelay));
&View_filters::set_map_flag), chbFilterHardLimitSizeDelay));
chbFilterFiles->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterFiles));
&View_filters::set_map_flag), chbFilterFiles));
chbFilterSoftLimitFile->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterSoftLimitFile));
&View_filters::set_map_flag), chbFilterSoftLimitFile));
chbFilterHardLimitFile->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (sigc::mem_fun(*this,
&MainWindow::set_map_flag), chbFilterHardLimitFile));
&View_filters::set_map_flag), chbFilterHardLimitFile));
chbFilterHardLimitFileDelay->signal_toggled().connect(
sigc::bind<Gtk::CheckButton*> (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<string, bool> 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;
}
}

@ -3,12 +3,14 @@
#include "../project_lib.h"
#include "../var.h"
using namespace std;
class View_filters
{
private:
std::map<string, bool> map_filters_flag;
map<string, bool> map_filters_flag;
private:
Glib::RefPtr<Gtk::Builder> const& builder;
Glib::RefPtr<Gtk::Builder> 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<string, bool> get_filters()
map<string, bool> get_filters();
};
#endif

Loading…
Cancel
Save