Начал работу над обвёрткой классов работающих с бэкендом

pull/3/head
Igor Belitskiy 2 years ago
parent fd1001e359
commit 66c3eb5a41

@ -22,8 +22,6 @@ set(SOURCE_FILES
ubconfig_quotas.cc
system_quotas.h
system_quotas.cc
controler.h
controler.cc
my_device.h
my_device.cc
project_lib.h

@ -1,2 +1,45 @@
#include "controler.h"
Back_Back::Back_Back() {}
void Back_Back::set_mode(string flag_mode) {
this->flag_mode = flag_mode;
}
void Back_Back::set_partition(string partition) {
this->partition = partition;
}
void Back_Back::set_sys_flag(string sys_flag) {
this->sys_flag = sys_flag;
}
bool Back_Back::wrapper_off_quotas(string quotas_type) {
bool flag_status = false;
quotas_type = this->handler_quotas_type(quotas_type);
if (flag_mode == "system") {
string cmd_hw = "";
string cmd_sw = "";
flag_status = obj_quotas_sys.off_quota(partition, cmd_hw, cmd_sw);
}
else if (flag_mode == "ubconfig") {
flag_status = obj_quotas_ubconfig.off_quota(partition, quotas_type);
}
return flag_status;
}
bool Back_Back::wrapper_on_quotas(string quotas_type) {
bool flag_status = false;
quotas_type = this->handler_quotas_type(quotas_type);
if (flag_mode == "system") {
string cmd_hw = "";
string cmd_sw = "";
flag_status = obj_quotas_sys.on_quota_hw(partition, cmd_hw, cmd_sw);
flag_status = obj_quotas_sys.wrapper_on_quotas(partition, quotas_type);
}
else if (flag_mode == "ubconfig") {
flag_status = obj_quotas_ubconfig.format_cmd_quotas();
}
return flag_status;
}
string Back_Back::handler_quotas_type(string quotas_type) {
return quotas_type;
}

@ -2,6 +2,18 @@
#include "ubconfig_quotas.h"
class Back_Back{
public:
string flag_mode;
string partition;
string sys_flag;
Quotas_sys::Quotas_sys obj_quotas_sys = Quotas_sys::Quotas_sys();
Quotas_ubconfig::Quotas_ubconfig obj_quotas_ubconfig = Quotas_ubconfig::Quotas_ubconfig();
public:
Back_Back();
void set_mode(string flag_mode);
void set_partition(string partition);
void set_sys_flag(string sys_flag);
bool wrapper_off_quotas(string quotas_type);
string handler_quotas_type(string quotas_type);
bool wrapper_on_quotas(string quotas_type);
};

@ -57,6 +57,7 @@ struct data_all_quotas {
string file_soft;
string file_hard;
string file_grace;
bool is_validate;
};
typedef struct users_grups USER_GRUPS;

@ -10,10 +10,40 @@ Quotas_sys::Quotas_sys() {
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 = "";
// Todo:
// Заменить на чтение файла средствами с++
string response = obj_process_call.call_all_sections("cat /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) {
@ -70,14 +100,31 @@ struct status_quotas Quotas_sys::check_on_quotas_system_2_hw(string params) {
}
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) {
if (map_hw_or_sw.find(partition) != map_hw_or_sw.end()) {
if (map_hw_or_sw[partition] == "hw") {
/*
Включить квоты, только для 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 (map_hw_or_sw[partition] == "sw") {
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;
@ -85,11 +132,15 @@ bool Quotas_sys::on_quota_hw(string partition, string cmd_hw, string cmd_sw) {
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) {
@ -118,7 +169,7 @@ bool Quotas_sys::on_quota_sw(string partition, int mode) {
return false;
}
bool Quotas_sys::off_quota_system(string partition, string quota_hw, string quota_sw) {
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 (map_hw_or_sw[partition] == "hw") {
@ -176,6 +227,7 @@ struct data_all_quotas Quotas_sys::part_quotas_line(string line) {
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;
}
@ -210,6 +262,8 @@ struct data_all_quotas Quotas_sys::part_quotas_line(string line) {
}
old_index = index;
}
if (index_data != 0) {struct_data.is_validate = true; }
else {struct_data.is_validate = false; }
return struct_data;
}

@ -9,20 +9,25 @@ 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_system(string partition, string quota_hw, string quota_sw);
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);
};

@ -2,17 +2,18 @@
namespace Quotas_ubconfig {
void Quotas_ubconfig::format_cmd_quotas_ubconfig(struct struct_quotas& _struct_quota) {
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;
}
void Quotas_ubconfig::off_quota_ubconfig(string partition, string quota_type) {
bool Quotas_ubconfig::off_quota(string partition, string quota_type) {
string key = "DISK_QUOTA[" + quota_type + ":" + partition + "]";
string value = "disable";
(*map_gui_cfg)[key] = value;
return true;
}
void Quotas_ubconfig::set_map_gui(map_str_str &map_gui) {
map_gui_cfg = &map_gui;

@ -17,8 +17,8 @@ class Quotas_ubconfig{
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();
void off_quota_ubconfig(string partition, string quota_type);
void format_cmd_quotas_ubconfig(struct struct_quotas& _struct_quota);
bool off_quota(string partition, string quota_type);
void format_cmd_quotas(struct struct_quotas& _struct_quota);
void set_map_gui(map_str_str &map_gui);
};
}

@ -480,8 +480,8 @@ void MainWindow::get_builder() {
void MainWindow::event() {
quotegroupSaveButton->signal_clicked().connect([&]() {});
btnDeleteGroupQuota->signal_clicked().connect([&]() {obj_quotas_ubconfig.off_quota_ubconfig(groupsDeviceCombo->get_active_text(), "grpquota");});
btnDeleteUserQuota->signal_clicked().connect([&]() {obj_quotas_ubconfig.off_quota_ubconfig(usersDeviceCombo->get_active_text(), "usrquota");});
btnDeleteGroupQuota->signal_clicked().connect([&]() {});
btnDeleteUserQuota->signal_clicked().connect([&]() {});
btnLoadGlob->signal_activate().connect([&]() {this->load_global_cfg();});
btnLoadLocal->signal_activate().connect([&]() {this->load_system_cfg();});
btnSynopsis->signal_activate().connect([&]() {this->synopsis_show();});
@ -532,7 +532,7 @@ void MainWindow::wrapper_settings_quotas_temp(string save_user_or_group) {
_struct_quota.cmd = cmd;
_struct_quota.type_quotas = type_quotas;
_struct_quota.name = user;
obj_quotas_ubconfig.format_cmd_quotas_ubconfig(_struct_quota);
obj_quotas_ubconfig.format_cmd_quotas(_struct_quota);
}

Loading…
Cancel
Save