Исправлено логирование ошибок

pull/11/head
Igor Belitskiy 3 years ago
parent 52915a3500
commit 0057ebdfe7

@ -167,6 +167,7 @@ void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path& path, const Gtk::
}
void MainWindow::get_download_mode(string cmd, std::map <string, string> &map_temp) {
int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
str_replace_all(res_response.response, "\"","");
@ -194,6 +195,9 @@ void MainWindow::get_download_mode(string cmd, std::map <string, string> &map_te
else if (res_response.error == 3) {
cmbDownloadMode->set_active(-1);
map_temp["GRUB_BOOT_SILENT"] = "";
if (start_error != index_error) {
index_error = start_error;
}
}
else {
cmbDownloadMode->set_active(-1);
@ -250,6 +254,7 @@ void MainWindow::set_security_login(string cmd="") {
}
void MainWindow::get_security_login(string cmd, std::map <string, string> &map_temp) {
int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd);
// TODO:
// Убрать в будущем
@ -277,6 +282,9 @@ void MainWindow::get_security_login(string cmd, std::map <string, string> &map_t
else if (res_response.error == 3) {
chbSecurityLogin->set_active(-1);
map_temp["GRUB_USER"] = "";
if (start_error != index_error) {
index_error = start_error;
}
}
else {
chbSecurityLogin->set_active(-1);
@ -315,8 +323,8 @@ void MainWindow::set_password_protec(string cmd = "", string cmd_remove = "") {
}
void MainWindow::get_password_protec(string cmd, std::map <string, string> &map_temp) {
int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd);
cout << res_response.response << " " << res_response.error << endl;
if (res_response.error == 0) {
str_replace_all(res_response.response, "\"","");
entryPasswordProtecc->set_text(res_response.response);
@ -340,6 +348,9 @@ void MainWindow::get_password_protec(string cmd, std::map <string, string> &map_
chbPasswordProtecc->set_active(2);
map_temp["GRUB_PASSWORD"] = "";
entryPasswordProtecc->set_text("");
if (start_error != index_error) {
index_error = start_error;
}
}
else {
map_temp["GRUB_PASSWORD"] = "";
@ -513,6 +524,7 @@ void MainWindow::localization(){
}
vector<string> MainWindow::get_setting_entry_all(string cmd, Gtk::Entry &entry_text, std::map <string, string> &map_temp) {
int start_error = index_error;
vector<string> vec_params;
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
@ -526,7 +538,9 @@ vector<string> MainWindow::get_setting_entry_all(string cmd, Gtk::Entry &entry_t
}
}
else if (res_response.error == 3) {
if (start_error != index_error) {
index_error = start_error;
}
}
else {
@ -538,6 +552,10 @@ bool MainWindow::focus_out_txt_password(GdkEventFocus*) {
if (entryPasswordProtecc->get_text().length() == 0) {
info_status_app("boxInfoMessError");
lblWarning->set_text(gettext("Enter your password"));
boxSave->set_sensitive(false);
}
else {
boxSave->set_sensitive(true);
}
return true;
}
@ -545,6 +563,10 @@ bool MainWindow::focus_out_txt_login(GdkEventFocus*) {
if (entrySecurityLogin->get_text().length() == 0) {
info_status_app("boxInfoMessError");
lblWarning->set_text(gettext("Enter login"));
boxSave->set_sensitive(false);
}
else {
boxSave->set_sensitive(true);
}
return true;
}
@ -578,13 +600,16 @@ void MainWindow::set_entry_to_tree_view(Glib::RefPtr<Gtk::ListStore> &list_store
flag_blocked_tree_view = false;
}
void MainWindow::get_menu_boot(string cmd, std::map <string, string> &map_temp) {
int start_error = index_error;
struct Result<string> res_response = this->wrapper_call(cmd);
if (res_response.error == 0) {
map_temp["GRUB_TIMEOUT"] = res_response.response;
spbSecond->set_value(atoi(res_response.response.c_str()));
}
else if (res_response.error == 3) {
if (start_error != index_error) {
index_error = start_error;
}
}
else {
@ -602,12 +627,17 @@ void MainWindow::set_menu_boot(string cmd="") {
}
void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings) {
void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove) {
string cmds = entry.get_text();
str_remove(cmds, ",");
cmd_settings += "\"" + cmds + "\"";
str_replace_all(cmd_settings, " \"", "\"");
this->wrapper_system(cmd_settings, "");
if (cmds.length() != 0) {
cmd_settings += "\"" + cmds + "\"";
str_replace_all(cmd_settings, " \"", "\"");
this->wrapper_system(cmd_settings, "");
}
else {
this->wrapper_system(cmd_remove, "");
}
}
void MainWindow::event(){
@ -647,14 +677,17 @@ void MainWindow::change_security_login() {
// Добавить заполнение логина по умолчанию
string default_login = "superadmin";
entrySecurityLogin->set_text(default_login);
boxSave->set_sensitive(true);
}
else if (index == 1) {
entrySecurityLogin->set_sensitive(true);
entrySecurityLogin->set_text("");
boxSave->set_sensitive(true);
}
else {
entrySecurityLogin->set_sensitive(false);
entrySecurityLogin->set_text("");
boxSave->set_sensitive(true);
}
}
@ -663,10 +696,15 @@ void MainWindow::change_password_protecc() {
if (index == 0 || index == 2 || index == -1) {
entryPasswordProtecc->set_sensitive(false);
entryPasswordProtecc->set_text("");
boxSave->set_sensitive(true);
}
else if (index == 1) {
entryPasswordProtecc->set_sensitive(true);
entryPasswordProtecc->set_text("");
boxSave->set_sensitive(true);
}
else {
boxSave->set_sensitive(true);
}
}
@ -709,17 +747,20 @@ bool MainWindow::save_global_cfg() {
}
if (this->check_save(flag_save, "GRUB_CMDLINE_LINUX")) {
string cmd_settings_kernel = "ubconfig --target global set boot GRUB_CMDLINE_LINUX=";
this->cmd_entry_all(*entryKernel, cmd_settings_kernel);
string cmd_remove = "ubconfig --target global remove boot GRUB_CMDLINE_LINUX";
this->cmd_entry_all(*entryKernel, cmd_settings_kernel, cmd_remove);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_TERMINAL_OUTPUT")) {
string cmd_settings_IPT = "ubconfig --target global set boot GRUB_TERMINAL_OUTPUT=";
this->cmd_entry_all(*entryIPT, cmd_settings_IPT);
string cmd_remove = "ubconfig --target global remove boot GRUB_TERMINAL_OUTPUT";
this->cmd_entry_all(*entryIPT, cmd_settings_IPT,cmd_remove);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_TERMINAL_INPUT")) {
string cmd_settings_OTT = "ubconfig --target global set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(*entryOTT, cmd_settings_OTT);
string cmd_remove = "ubconfig --target global remove boot GRUB_TERMINAL_INPUT";
this->cmd_entry_all(*entryOTT, cmd_settings_OTT, cmd_remove);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) {
@ -766,17 +807,20 @@ bool MainWindow::save_local_cfg() {
}
if (this->check_save(flag_save, "GRUB_CMDLINE_LINUX")) {
string cmd_settings_kernel = "ubconfig --target system set boot GRUB_CMDLINE_LINUX=";
this->cmd_entry_all(*entryKernel, cmd_settings_kernel);
string cmd_remove = "ubconfig --target system remove boot GRUB_CMDLINE_LINUX";
this->cmd_entry_all(*entryKernel, cmd_settings_kernel, cmd_remove);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_TERMINAL_OUTPUT")) {
string cmd_settings_IPT = "ubconfig --target system set boot GRUB_TERMINAL_OUTPUT=";
this->cmd_entry_all(*entryIPT, cmd_settings_IPT);
string cmd_remove = "ubconfig --target system remove boot GRUB_TERMINAL_OUTPUT";
this->cmd_entry_all(*entryIPT, cmd_settings_IPT, cmd_remove);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_TERMINAL_INPUT")) {
string cmd_settings_OTT = "ubconfig --target system set boot GRUB_TERMINAL_INPUT=";
this->cmd_entry_all(*entryOTT, cmd_settings_OTT);
string cmd_remove = "ubconfig --target system remove boot GRUB_TERMINAL_INPUT";
this->cmd_entry_all(*entryOTT, cmd_settings_OTT, cmd_remove);
flag_no_save = false;
}
if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) {
@ -870,8 +914,6 @@ void MainWindow::download_local_cfg() {
}
bool MainWindow::check_save(string flag_save, string key_name="") {
if (flag_save.empty() && key_name.empty()) {}
/*
std::map <string, string>:: iterator iter_map_data;
std::map <string, string>:: iterator iter_map_data_old;
std::map <string, string> map_config_data_old;
@ -909,7 +951,6 @@ bool MainWindow::check_save(string flag_save, string key_name="") {
return true;
}
cout << 7 << endl;
*/
return true;
}

@ -121,6 +121,7 @@ class MainWindow : public Gtk::ApplicationWindow {
bool flag_save_global = false;
bool flag_save_local = false;
bool flag_blocked_tree_view = false;
bool flag_save_block = false;
size_t size_kernel = 0;
size_t size_IPT = 0;
size_t size_OTT = 0;
@ -183,7 +184,7 @@ class MainWindow : public Gtk::ApplicationWindow {
void get_password_protec(string cmd, std::map <string, string> &map_temp);
void set_password_protec(string cmd, string cmd_remove);
vector<string> get_setting_entry_all(string cmd, Gtk::Entry &entry_text, std::map <string, string> &map_temp);
void cmd_entry_all(Gtk::Entry &entry, string cmd_settings);
void cmd_entry_all(Gtk::Entry &entry, string cmd_settings, string cmd_remove);
string dynamic_update_entry(std::map<string, string> &map_view, vector<string> &vec_allowed);
void item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&);
void item_selected_OTT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&);

@ -102,3 +102,84 @@ std::vector<std::string> split(std::string text, char delim) {
}
return vec;
}
unsigned short read_uid_min_max(string filename, string search) {
std::string line;
int uid = 0;
string remove_tab = "\t";
string remove_space = " ";
std::ifstream in(filename); // окрываем файл для чтения
if (in.is_open()){
while (getline(in, line)){
try{
if (line.find(search) != string::npos && (line.find("SYS_"+search) == string::npos)) {
str_remove(line, search);
str_remove(line, remove_space);
str_remove(line, remove_tab);
uid = atoi(line.c_str());
}
}
catch (int x) {
if (search == "UID_MIN"){
uid = 1000;
}
else{
uid = 65534;
}
}
}
}
else{
if (search == "UID_MIN") {
uid = 1000;
}
else{
uid = 65534;
}
}
in.close();
return uid;
}
vector <string> pars_users() {
vector <string> vec_users;
unsigned short uid_min = read_uid_min_max("/etc/login.defs", "UID_MIN");
unsigned short uid_max =read_uid_min_max("/etc/login.defs", "UID_MAX");
while (true) {
errno = 0;
passwd* entry = getpwent();
if (!entry) {
if (errno) {
break;
}
break;
}
if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
vec_users.push_back(string(entry->pw_name));
}
}
endpwent();
return vec_users;
}
string read_passwd(string username) {
string passwd = "";
std::string line;
std::ifstream in("/etc/shadow");
if (in.is_open()) {
while (getline(in, line)) {
if (line.find(username) != string::npos) {
size_t index_start = line.find(":");
if (index_start != string::npos) {
size_t index_end = line.find(":", index_start + 1);
passwd = line.substr(index_start+1, index_end - index_start-1);
break;
}
}
}
}
in.close();
return passwd;
}

@ -6,9 +6,16 @@
#include <array>
#include <vector>
#include <linux/limits.h>
#include <sys/types.h>
#include <pwd.h>
using namespace std;
struct Passwd {
string user;
int uid;
};
std::array<std::vector<std::string>, 5> read_csv(const std::string& filename);
std::string call(std::string cmd);
@ -16,3 +23,6 @@ vector<int> find_all(string &str_ntp, string substr);
void str_remove(std::string& source, std::string to_remove);
void str_replace_all(string &str_base, string str_find, string str_replace);
std::vector<std::string> split(std::string text, char delim);
unsigned short read_uid_min_max(string filename, string search);
vector <string> pars_users();
string read_passwd(string username);

Loading…
Cancel
Save