You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ubl-settings-diskquota/source/system_cmd_quotas.cc

159 lines
5.2 KiB

#include "system_cmd_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::format_cmd_quotas_ubconfig(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_sys::format_cmd_quotas_system(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_sys::off_quota_ubconfig(Gtk::ComboBoxText* combo_box, string quota_type) {
string partition = combo_box->get_active_text();
string key = "DISK_QUOTA[" + quota_type + ":" + partition + "]";
string value = "disable";
(*map_gui_cfg)[key] = value;
}
void Quotas_sys::set_map_gui(map_str_str &map_gui) {
map_gui_cfg = &map_gui;
}
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::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") {
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") {
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) {
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;
}
void Quotas_sys::off_quota_system(Gtk::ComboBoxText* combo_box, string quota_type) {
string partition = combo_box->get_active_text();
string cmd = "";
if (map_hw_or_sw.find(partition) != map_hw_or_sw.end()) {
if (map_hw_or_sw[partition] == "hw") {
cmd = "tune2fs -Q ^" + quota_type + " " + partition;
}
else if (map_hw_or_sw[partition] == "sw") {
cmd = "quotaoff -u " + quota_type.substr(0,1) + " " + partition;
}
else {
// TODO:
// Убрать после тестирования
throw "Опа цэ!";
}
obj_process_system.call(cmd, "");
}
}
}