#include "ubl-settings-bootloader.h" using namespace std; string path_app = "/usr/bin/"; string path_glade= "/usr/share/ubl-settings-bootloader/ui/ubl-settings-bootloader.glade"; string path_css = "/usr/share/ubl-settings-bootloader/css/ubl-settings-bootloader.css"; string app_name = "ubl-settings-bootloader"; string path_resources = "/usr/share/ubl-settings-bootloader"; const string path_img_head_background = "/usr/share/ubl-settings-bootloader/images/logo-background.png"; int socket_ext_id_I = 0; int socket_trd_id_I = 0; string version_application = "1.0"; CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) : Glib::OptionGroup{p_name, p_description, p_help} { Glib::OptionEntry socketIDArg; socketIDArg.set_long_name("socket-id"); socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketIDArg.set_description("Settings manager socket"); Glib::OptionEntry socketExtId; socketExtId.set_long_name("socket-ext-id"); socketExtId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketExtId.set_description("Settings manager secondary socket"); Glib::OptionEntry socketTrdId; socketTrdId.set_long_name("socket-trd-id"); socketTrdId.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketTrdId.set_description("Settings manager secondary socket"); add_entry(socketIDArg, m_socketID); add_entry(socketExtId, socket_ext_id_I); add_entry(socketTrdId, socket_trd_id_I); } ::Window CmdArgParser::GetSocketID() const{ return m_socketID; } SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr builder) : Gtk::Plug{p_socketID} { MainWindow* wnd = nullptr; builder->get_widget_derived("window", wnd); builder->get_widget("plugBox", plugBox); plugBox->get_parent()->remove(*plugBox); add(*plugBox); show_all_children(); } int MainWindow::check_root() { if (geteuid() != 0) { //lblMessageSudo->set_text(gettext("The program must be run with \nsuperuser privileges!")); //mess_sudo->show(); return 1; } return 0; } MainWindow::MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder) : Gtk::ApplicationWindow(obj), builder{builder} { this->builder = builder; this->settings(); } MainWindow::MainWindow(Glib::RefPtr const& builder) { this->builder = builder; this->settings(); } void MainWindow::settings(){ map_cmd_error[""] = ""; this->get_builder(); this->localization(); this->add_CSS(); Gtk::Widget *boxWidget; builder->get_widget("boxColor", boxWidget); overHead->add_overlay(*boxWidget); btnBoxAboutDialog->set_visible(false); ubl_make_plugs(boxSave,boxButton, socket_ext_id_I, socket_trd_id_I); if (this->check_root() == 0) { spbSecond->set_range(1, 60); spbSecond->set_increments(1.0, 1.0); this->fill_in_view(); this->download_local_cfg(); this->download_globl_cfg(); entrySecurityLogin->set_sensitive(false); this->set_active_boot_second(); this->change_password_protecc(); this->event(); } else{ boxWidgetAll->set_sensitive(false); btnLoad->set_sensitive(false); boxSave->set_sensitive(false); imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.warning", Gtk::ICON_SIZE_MENU); info_status_app("boxInfoMessError"); lblWarning->set_text(gettext("The program must be run as root")); this->set_active_boot_second(); this->event(); } } void MainWindow::fill_in_view() { list_store_kernel = Gtk::ListStore::create(m_columns); list_store_IPT = Gtk::ListStore::create(m_columns); list_store_OTT = Gtk::ListStore::create(m_columns); treeViewKernel->set_model(list_store_kernel); treeViewIPT->set_model(list_store_IPT); treeViewOTT->set_model(list_store_OTT); vec_Option_kernel = this->read_file_and_view("boot-options.csv", row_kernel, list_store_kernel); vec_Option_IPT = this->read_file_and_view("input-options.csv", row_IPT, list_store_IPT); vec_Option_OTT = this->read_file_and_view("output-options.csv", row_OTT, list_store_OTT); size_kernel = vec_Option_kernel.size(); size_IPT = vec_Option_IPT.size(); size_OTT = vec_Option_OTT.size(); this->view_add_colums(*treeViewKernel); this->view_add_colums(*treeViewIPT); this->view_add_colums(*treeViewOTT); } void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { auto selection_IPT = treeViewIPT->get_selection(); auto selection_OTT = treeViewOTT->get_selection(); selection_IPT->unselect_all(); selection_OTT->unselect_all(); flag_save_local = true; flag_save_global = true; flag_save_all = true; if (flag_blocked_tree_view == false) { template_item_selected(map_cmd_selection, path, list_store_kernel); string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_kernel); entryKernel->set_text(str_flags); } } void MainWindow::item_selected_OTT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { auto selection_kernel = treeViewKernel->get_selection(); auto selection_IPT = treeViewIPT->get_selection(); selection_kernel->unselect_all(); selection_IPT->unselect_all(); flag_save_local = true; flag_save_global = true; flag_save_all = true; if (flag_blocked_tree_view == false) { template_item_selected(map_cmd_selection , path, list_store_OTT); string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_OTT); entryOTT->set_text(str_flags); } } void MainWindow::item_selected_IPT(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { auto selection_kernel = treeViewKernel->get_selection(); auto selection_OTT = treeViewOTT->get_selection(); selection_kernel->unselect_all(); selection_OTT->unselect_all(); flag_save_local = true; flag_save_global = true; flag_save_all = true; if (flag_blocked_tree_view == false) { template_item_selected(map_cmd_selection , path, list_store_IPT); string str_flags = this->dynamic_update_entry(map_cmd_selection, vec_Option_IPT); entryIPT->set_text(str_flags); } } void MainWindow::get_download_mode(string cmd, std::map &map_temp) { struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { str_replace_all(res_response.response, "\"",""); if (res_response.response == "splash") { cmbDownloadMode->set_active(0); map_temp["GRUB_BOOT_SILENT"] = "splash"; } else if (res_response.response == "splash quiet ub.silent") { cmbDownloadMode->set_active(1); map_temp["GRUB_BOOT_SILENT"] = "splash quiet ub.silent"; } else if (res_response.response == "quiet ub.silent") { cmbDownloadMode->set_active(2); map_temp["GRUB_BOOT_SILENT"] = "quiet ub.silent"; } else if (res_response.response == "plymouth.enable=0") { cmbDownloadMode->set_active(3); map_temp["GRUB_BOOT_SILENT"] = "plymouth.enable=0"; } else{ cmbDownloadMode->set_active(-1); map_temp["GRUB_BOOT_SILENT"] = ""; } } else if (res_response.error == 3) { cmbDownloadMode->set_active(-1); map_temp["GRUB_BOOT_SILENT"] = ""; } else { cmbDownloadMode->set_active(-1); map_temp["GRUB_BOOT_SILENT"] = ""; } } void MainWindow::set_download_mode(string cmd="") { int index = cmbDownloadMode->get_active_row_number(); string key = ""; if (index == 0) { key = "splash"; } else if (index == 1) { key = "splash quiet ub.silent"; } else if (index == 2) { key = "quiet ub.silent"; } else if (index == 3) { key = "plymouth.enable=0"; } else{ return; } if (cmd.length() !=0 ) { cmd +="\"" + key + "\""; wrapper_system(cmd, ""); } map_cmd_selection["GRUB_BOOT_SILENT"] = key; } void MainWindow::set_security_login(string cmd="") { int index = chbSecurityLogin->get_active_row_number(); string key = ""; if (index == 0){ // TODO: // Не правильно key = "superadmin"; } else if (index == 1) { key = string(getlogin()); } else { return; } if (cmd.length() != 0) { entrySecurityLogin->set_text(key); cmd = cmd + key; wrapper_system(cmd, ""); } map_cmd_selection["GRUB_USER"] = key; } void MainWindow::get_security_login(string cmd, std::map &map_temp) { struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { str_replace_all(res_response.response, "\"",""); entrySecurityLogin->set_text(res_response.response); if (res_response.response == getlogin()) { chbSecurityLogin->set_active(1); map_temp["GRUB_USER"] = getlogin(); } else if (res_response.response.length() != 0) { chbSecurityLogin->set_active(0); map_temp["GRUB_USER"] = res_response.response; } else{ chbSecurityLogin->set_active(-1); map_temp["GRUB_USER"] = ""; } } else if (res_response.error == 3) { chbSecurityLogin->set_active(-1); map_temp["GRUB_USER"] = ""; } else { chbSecurityLogin->set_active(-1); map_temp["GRUB_USER"] = ""; } } void MainWindow::set_password_protec(string cmd = "", string cmd_remove= "") { // TODO: // Не работает int index = chbSecurityLogin->get_active_row_number(); string key = ""; if (index == 0){ key = ""; } else if (index == 1) { key = entryPasswordProtecc->get_text(); } else if (index == 2) { key = "remove"; if (cmd.length() != 0 && cmd_remove.length() != 0) { wrapper_system(cmd_remove, ""); } cmd = ""; } else { return; } if (cmd.length() != 0 && cmd_remove.length() != 0) { entrySecurityLogin->set_text(key); cmd = cmd + key; wrapper_system(cmd, ""); } map_cmd_selection["GRUB_PASSWORD"] = key; } void MainWindow::get_password_protec(string cmd, std::map &map_temp) { // TODO: // Не работает struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { str_replace_all(res_response.response, "\"",""); entrySecurityLogin->set_text(res_response.response); if (res_response.response == getlogin()) { chbSecurityLogin->set_active(0); map_temp["GRUB_PASSWORD"] = ""; } else if (res_response.response.length() != 0) { chbSecurityLogin->set_active(1); map_temp["GRUB_PASSWORD"] = ""; } else if (res_response.response.length() != 0) { chbSecurityLogin->set_active(2); map_temp["GRUB_PASSWORD"] = ""; } else{ map_temp["GRUB_PASSWORD"] = ""; chbSecurityLogin->set_active(-1); } } else if (res_response.error == 3) { map_temp["GRUB_PASSWORD"] = ""; chbSecurityLogin->set_active(-1); } else { map_temp["GRUB_PASSWORD"] = ""; chbSecurityLogin->set_active(-1); } } void MainWindow::template_item_selected(std::map &map_view, const Gtk::TreeModel::Path& path, Glib::RefPtr &list_store) { const auto iter = list_store->get_iter(path); if(iter) { const auto row = *iter; Glib::ustring cmd; bool check_btn = row[m_columns.check_button]; if (check_btn) { cmd = "1"; } else { cmd = "0"; } Glib::ustring name = row[m_columns.name]; map_view[name] = cmd; } } string MainWindow::dynamic_update_entry(std::map &map_view, vector &vec_allowed) { string keys = ""; for (auto &key: vec_allowed) { if (map_view.find(key) != map_view.end()) { if (map_view[key] == "1") { keys += string(key) + ", "; } } } return keys; } vector MainWindow::read_file_and_view(string file_name ,Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m) { std::array, 5> arr_view = read_csv(path_resources + "/" + file_name); std::vector vec_Option = arr_view[0]; for (size_t index = 0; index < vec_Option.size(); index++) { this->view_add_cell(row, list_store_m , arr_view, index); } return vec_Option; } void MainWindow::view_add_colums(Gtk::TreeView &treeView) { treeView.append_column_editable(gettext("Active"), m_columns.check_button); treeView.append_column(gettext("Option"), m_columns.name); treeView.append_column(gettext("Description"), m_columns.description); } void MainWindow::view_add_cell(Gtk::TreeModel::Row &row, Glib::RefPtr list_store_m , std::array, 5> &arr_view , size_t index) { row = *(list_store_m->append()); bool flag_chb = false; string name = arr_view[0][index]; row[m_columns.check_button] = flag_chb; row[m_columns.name] = gettext(name.c_str()); row[m_columns.description] = gettext(arr_view[1][index].c_str()); } void MainWindow::get_builder(){ builder->get_widget("chbLoadVariantSelectionTimer", chbLoadVariantSelectionTimer); builder->get_widget("chbLastSelectionWillBecome", chbLastSelectionWillBecome); builder->get_widget("lblInfoCommand", lblInfoCommand); builder->get_widget("lblInfoCommand1", lblInfoCommand1); builder->get_widget("lblInfoCommand2", lblInfoCommand2); builder->get_widget("lblInfoDefaultDonw", lblInfoDefaultDonw); builder->get_widget("lblInfoSeconds", lblInfoSeconds); builder->get_widget("lblLoadMenu", lblLoadMenu); builder->get_widget("lblInfoInputTerminal", lblInfoInputTerminal); builder->get_widget("lblInfoOutputTerminal", lblInfoOutputTerminal); builder->get_widget("lblInfoSeconds", lblInfoSeconds); builder->get_widget("lblHeaderName", lblHeaderName); builder->get_widget("lblInfoHead", lblInfoHead); builder->get_widget("spbSecond", spbSecond); builder->get_widget("entryKernel", entryKernel); builder->get_widget("entryIPT", entryIPT); builder->get_widget("entryOTT", entryOTT); builder->get_widget("boxColor", boxColor); builder->get_widget("boxWidgetAll", boxWidgetAll); builder->get_widget("aboutWindows", aboutWindows); builder->get_widget("btnSynopsis", btnSynopsis); builder->get_widget("btnAbout", btnAbout); builder->get_widget("btnLoadLocal", btnLoadLocal); builder->get_widget("btnLoadGlob", btnLoadGlob); builder->get_widget("btnSaveLocalGlob", btnSaveLocalGlob); builder->get_widget("btnSaveLocal", btnSaveLocal); builder->get_widget("btnSaveGlob", btnSaveGlob); builder->get_widget("btnSettings", btnSettings); builder->get_widget("btnLoad", btnLoad); builder->get_widget("btnSave", btnSave); builder->get_widget("boxButton", boxButton); builder->get_widget("boxSave", boxSave); builder->get_widget("boxInfoError", boxInfoError); builder->get_widget("lblWarning", lblWarning); builder->get_widget("imgInfo", imgInfo); builder->get_widget("btnBoxAboutDialog", btnBoxAboutDialog); builder->get_widget("treeViewKernel", treeViewKernel); builder->get_widget("treeViewOTT", treeViewOTT); builder->get_widget("treeViewIPT", treeViewIPT); builder->get_widget("imgBG", imgBG); builder->get_widget("overHead", overHead); builder->get_widget("lblDownloadMode", lblDownloadMode); builder->get_widget("lblSecurityLogin", lblSecurityLogin); builder->get_widget("lblPasswordProtec", lblPasswordProtec); builder->get_widget("cmbDownloadMode", cmbDownloadMode); builder->get_widget("chbSecurityLogin", chbSecurityLogin); builder->get_widget("chbPasswordProtecc", chbPasswordProtecc); builder->get_widget("entryPasswordProtecc", entryPasswordProtecc); builder->get_widget("entrySecurityLogin", entrySecurityLogin); } void MainWindow::localization(){ time_t now = time(0); tm *ltm = localtime(&now); unsigned int year = 1900+ ltm->tm_year; string str_authors = string(gettext("Copyright © UBSoft LLC, 2022 - ")) + to_string(year); aboutWindows->set_copyright(str_authors); aboutWindows->set_comments(gettext("ubl-settings-bootloader")); aboutWindows->set_website(gettext("https://wiki.ublinux.com")); aboutWindows->set_version(gettext(version_application.c_str())); aboutWindows->set_website_label(gettext("Project Home Page")); lblInfoHead->set_text(gettext("Configuring system boot parameters")); lblHeaderName->set_text(gettext("ubl-settings-bootloader")); aboutWindows->set_comments(gettext("Setting bootloader")); aboutWindows->set_website_label(gettext("Project Home Page")); lblInfoCommand->set_text(gettext("Command line parameters:")); lblInfoCommand1->set_text(gettext("Command line parameters:")); lblInfoCommand2->set_text(gettext("Command line parameters:")); lblInfoDefaultDonw->set_text(gettext("Default download")); lblInfoSeconds->set_text(gettext("Seconds")); lblLoadMenu->set_text(gettext("Download menu")); lblInfoInputTerminal->set_text(gettext("Terminal for input")); lblInfoOutputTerminal->set_text(gettext("Terminal for output")); chbLoadVariantSelectionTimer->set_label(gettext("Load variant selection timer")); chbLastSelectionWillBecome->set_label(gettext("The last selection will become the default boot choice")); btnSynopsis->set_label(gettext("Help")); btnAbout->set_label(gettext("About")); btnSaveLocalGlob->set_label(gettext("Save to global and local configuration")); btnSaveLocal->set_label(gettext("Save local configuration")); btnSaveGlob->set_label(gettext("Save global configuration")); btnLoadGlob->set_label(gettext("Load global configuration")); btnLoadLocal->set_label(gettext("Load local configuration")); btnSave->set_label(gettext("Save")); btnLoad->set_label(gettext("Load")); this->set_title(gettext("ubl-settings-bootloader")); lblDownloadMode->set_text(gettext("Download mode:")); lblSecurityLogin->set_text(gettext("Security login:")); lblPasswordProtec->set_text(gettext("Password protection:")); chbSecurityLogin->append(gettext("Default")); chbSecurityLogin->append(gettext("Mine")); chbPasswordProtecc->append(gettext("Default")); chbPasswordProtecc->append(gettext("Mine")); chbPasswordProtecc->append(gettext("Disabled")); cmbDownloadMode->append(gettext("Loading animation, full log")); cmbDownloadMode->append(gettext("Loading animation, no log")); cmbDownloadMode->append(gettext("No loading animation, full log.")); cmbDownloadMode->append(gettext("No loading animation, minimal log.")); } vector MainWindow::get_setting_entry_all(string cmd, Gtk::Entry &entry_text, std::map &map_temp) { vector vec_params; struct Result res_response = this->wrapper_call(cmd); if (res_response.error == 0) { str_replace_all(res_response.response, "\"", ""); vec_params = split(res_response.response, ' '); str_replace_all(res_response.response, " ", ", "); entry_text.set_text(res_response.response); for (auto ¶m: vec_params) { map_cmd_selection[param] = "1"; map_temp[param] = "1"; } } else if (res_response.error == 3) { } else { } return vec_params; } bool MainWindow::focus_out_txt_password(GdkEventFocus*) { info_status_app("boxInfoMessError"); lblWarning->set_text(gettext("Enter your password")); return true; } bool MainWindow::focus_out_txt_kernel(GdkEventFocus*) { this->set_entry_to_tree_view(list_store_kernel, *entryKernel, vec_Option_kernel, size_kernel); return true; } bool MainWindow::focus_out_txt_IPT(GdkEventFocus*) { this->set_entry_to_tree_view(list_store_IPT, *entryIPT, vec_Option_IPT, size_IPT); return true; } bool MainWindow::focus_out_txt_OTT(GdkEventFocus*) { this->set_entry_to_tree_view(list_store_OTT, *entryOTT, vec_Option_OTT, size_OTT); return true; } void MainWindow::set_entry_to_tree_view(Glib::RefPtr &list_store, Gtk::Entry &entry, std::vector &vec_Option, int size) { flag_blocked_tree_view = true; vector vec_params; std::string text = entry.get_text(); str_replace_all(text, " ", ""); vec_params = split(text, ','); for (auto &name: vec_Option) { this->set_row(list_store, size, name, false); } for (auto &name: vec_params) { this->set_row(list_store, size, name, true); } flag_blocked_tree_view = false; } void MainWindow::get_menu_boot(string cmd, std::map &map_temp) { struct Result 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) { } else { } } void MainWindow::set_menu_boot(string cmd="") { int value = spbSecond->get_value(); std::string seconds = to_string(value); cmd += seconds; if (cmd.length() != 0) { this->wrapper_system(cmd, ""); } map_cmd_selection["GRUB_TIMEOUT"] = to_string(value); } void MainWindow::cmd_entry_all(Gtk::Entry &entry, string cmd_settings) { string cmds = entry.get_text(); str_remove(cmds, ","); cmd_settings += "\"" + cmds + "\""; str_replace_all(cmd_settings, " \"", "\""); this->wrapper_system(cmd_settings, ""); } void MainWindow::event(){ btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show)); btnAbout->signal_activate().connect([&]() {aboutWindows->show();}); btnLoadLocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_local_cfg)); btnLoadGlob->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_globl_cfg)); btnSaveLocalGlob->signal_activate().connect([&]() {wrapper_save_all_cfg();}); btnSaveLocal->signal_activate().connect([&]() {wrapper_save_local_cfg();}); btnSaveGlob->signal_activate().connect([&]() {wrapper_save_global_cfg();}); entryKernel->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_kernel)); entryIPT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_IPT)); entryOTT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_OTT)); entryPasswordProtecc->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_password)); chbPasswordProtecc->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::change_password_protecc)); if (this->check_root() == 0) { Glib::RefPtr treeViewKernelModel = treeViewKernel->get_model(); treeViewKernelModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_kernel)); Glib::RefPtr treeViewIPTModel = treeViewIPT->get_model(); treeViewIPTModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_IPT)); Glib::RefPtr treeViewOTTModel = treeViewOTT->get_model(); treeViewOTTModel->signal_row_changed().connect(sigc::mem_fun(*this, &MainWindow::item_selected_OTT)); entryKernel->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_kernel)); entryIPT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_IPT)); entryOTT->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_OTT)); } chbLoadVariantSelectionTimer->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_active_boot_second)); } void MainWindow::change_password_protecc() { int index = chbPasswordProtecc->get_active_row_number(); if (index == 0 || index == 2 || index == -1) { entryPasswordProtecc->set_sensitive(false); } else if (index == 1) { entryPasswordProtecc->set_sensitive(true); } } void MainWindow::set_active_boot_second() { spbSecond->set_sensitive(chbLoadVariantSelectionTimer->get_active()); lblInfoSeconds->set_sensitive(chbLoadVariantSelectionTimer->get_active()); } void MainWindow::wrapper_save_all_cfg() { if (this->save_global_cfg() && this->save_local_cfg()) { info_status_app("boxInfoMessOK"); lblWarning->set_text(gettext("Nothing to save!")); } else { info_warning_error(4); } } void MainWindow::wrapper_save_global_cfg() { if (this->save_global_cfg()) { info_status_app("boxInfoMessOK"); lblWarning->set_text(gettext("Nothing to save!")); } else { info_warning_error(3); } } bool MainWindow::save_global_cfg() { string flag_save = "global"; bool flag_no_save = true; if (flag_save_global) { if (flag_save_all) { this->set_data_cfg(); if (this->check_save(flag_save, "GRUB_TIMEOUT")) { std::string cmd_boot_time = "ubconfig --target global set boot GRUB_TIMEOUT="; this->set_menu_boot(cmd_boot_time); flag_no_save = false; } 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); 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); 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); flag_no_save = false; } if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) { this->set_download_mode("ubconfig --target global set boot GRUB_BOOT_SILENT="); flag_no_save = false; } if (this->check_save(flag_save, "GRUB_USER")) { this->set_security_login("ubconfig --target global set boot GRUB_USER="); flag_no_save = false; } if (this->check_save(flag_save, "GRUB_PASSWORD")) { string cmd_password = "ubconfig --target global set boot GRUB_PASSWORD="; string cmd_password_remove = "ubconfig --target global remove boot GRUB_PASSWORD="; this->set_password_protec(cmd_password, cmd_password_remove); flag_no_save = false; } } } else { flag_no_save = true; } map_global_cmd_selection = map_cmd_selection; return flag_no_save; } void MainWindow::wrapper_save_local_cfg() { if (this->save_local_cfg()){ info_status_app("boxInfoMessOK"); lblWarning->set_text(gettext("Nothing to save!")); } else { info_warning_error(2); } } bool MainWindow::save_local_cfg() { string flag_save = "local"; bool flag_no_save = true; if (flag_save_local) { if (flag_save_all) { this->set_data_cfg(); if (this->check_save(flag_save, "GRUB_TIMEOUT")) { std::string cmd_boot_time = "ubconfig --target system set boot GRUB_TIMEOUT="; this->set_menu_boot(cmd_boot_time); flag_no_save = false; } 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); 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); 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); flag_no_save = false; } if (this->check_save(flag_save, "GRUB_BOOT_SILENT")) { this->set_download_mode("ubconfig --target system set boot GRUB_BOOT_SILENT="); flag_no_save = false; } if (this->check_save(flag_save, "GRUB_USER")) { this->set_security_login("ubconfig --target system set boot GRUB_USER="); flag_no_save = false; } if (this->check_save(flag_save, "GRUB_PASSWORD")) { string cmd_password = "ubconfig --target system set boot GRUB_PASSWORD="; string cmd_password_remove = "ubconfig --target system remove boot GRUB_PASSWORD="; this->set_password_protec(cmd_password, cmd_password_remove); flag_no_save = false; } } } else { flag_no_save = true; } map_local_cmd_selection = map_cmd_selection; return flag_no_save; } void MainWindow::set_data_cfg() { this->set_security_login(); this->set_download_mode(); this->set_password_protec(); this->set_menu_boot(); string str_flags = entryKernel->get_text(); str_remove(str_flags, ","); str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_CMDLINE_LINUX"] = str_flags; str_flags = entryIPT->get_text(); str_remove(str_flags, ","); str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_TERMINAL_INPUT"] = str_flags; str_flags = entryOTT->get_text(); str_remove(str_flags, ","); str_replace_all(str_flags, " \"", "\""); map_cmd_selection["GRUB_TERMINAL_OUTPUT"] = str_flags; } void MainWindow::download_globl_cfg() { entryKernel->set_text(""); entryOTT->set_text(""); entryIPT->set_text(""); flag_save_local = false; flag_save_global = false; flag_save_all = false; flag_load = true; std::string cmd_boot_time = "ubconfig --default --source global get boot GRUB_TIMEOUT"; this->get_menu_boot(cmd_boot_time, map_global_cmd_selection); string cmd_kernel_entry = "ubconfig --default --source global get boot GRUB_CMDLINE_LINUX"; this->get_setting_entry_all(cmd_kernel_entry, *entryKernel, map_global_cmd_selection); string cmd_ipt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_INPUT"; this->get_setting_entry_all(cmd_ipt_entry, *entryIPT, map_global_cmd_selection); string cmd_opt_entry = "ubconfig --default --source global get boot GRUB_TERMINAL_OUTPUT"; this->get_setting_entry_all(cmd_opt_entry, *entryOTT, map_global_cmd_selection); this->set_row_all(map_global_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel); this->set_row_all(map_global_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT); this->set_row_all(map_global_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT); this->get_download_mode("ubconfig --default --source global get boot GRUB_BOOT_SILENT", map_global_cmd_selection); this->get_security_login("ubconfig --default --source global get boot GRUB_USER", map_global_cmd_selection); this->get_password_protec("ubconfig --default --source global get boot GRUB_PASSWORD", map_global_cmd_selection); info_warning_error(1); map_cmd_selection = map_global_cmd_selection; } void MainWindow::download_local_cfg() { entryKernel->set_text(""); entryOTT->set_text(""); entryIPT->set_text(""); flag_save_local = false; flag_save_global = false; flag_save_all = false; flag_load = false; std::string cmd_boot_time = "ubconfig --default --source system get boot GRUB_TIMEOUT"; this->get_menu_boot(cmd_boot_time, map_local_cmd_selection); string cmd_kernel_entry = "ubconfig --default --source system get boot GRUB_CMDLINE_LINUX"; this->get_setting_entry_all(cmd_kernel_entry, *entryKernel, map_local_cmd_selection); string cmd_ipt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_INPUT"; this->get_setting_entry_all(cmd_ipt_entry, *entryIPT, map_local_cmd_selection); string cmd_opt_entry = "ubconfig --default --source system get boot GRUB_TERMINAL_OUTPUT"; this->get_setting_entry_all(cmd_opt_entry, *entryOTT, map_local_cmd_selection); this->set_row_all(map_local_cmd_selection, list_store_kernel, vec_Option_kernel, size_kernel); this->set_row_all(map_local_cmd_selection, list_store_IPT, vec_Option_IPT, size_IPT); this->set_row_all(map_local_cmd_selection, list_store_OTT, vec_Option_OTT, size_OTT); this->get_download_mode("ubconfig --default --source system get boot GRUB_BOOT_SILENT", map_local_cmd_selection); this->get_security_login("ubconfig --default --source system get boot GRUB_USER", map_local_cmd_selection); this->get_password_protec("ubconfig --default --source system get boot GRUB_PASSWORD", map_local_cmd_selection); info_warning_error(0); map_cmd_selection = map_local_cmd_selection; } bool MainWindow::check_save(string flag_save, string key_name="") { std::map :: iterator iter_map_data; std::map :: iterator iter_map_data_old; std::map map_config_data_old; if (flag_save == "local") { map_config_data_old = map_local_cmd_selection; } else if (flag_save == "global") { map_config_data_old = map_global_cmd_selection; } iter_map_data = map_cmd_selection.find(key_name); iter_map_data_old = map_config_data_old.find(key_name); if (iter_map_data == map_cmd_selection.end()) { cout << 1 << endl; return true; } else if (iter_map_data_old == map_config_data_old.end()) { cout << 2 << endl; return true; } else if (iter_map_data->second != iter_map_data_old->second) { cout << 3 << endl; return true; } else if (iter_map_data->second.length() == 0 || iter_map_data_old->second.length() == 0) { cout << 4 << " " << key_name << endl; return false; } else if (iter_map_data->second == iter_map_data_old->second) { cout << 5 << " " << key_name << endl; return false; } else { cout << 6 << endl; return true; } cout << 7 << endl; return true; } void MainWindow::set_row_all(std::map &map_cmd, Glib::RefPtr &list_store, vector &list_params, size_t size) { for (auto &name: list_params) { if (map_cmd.find(name) != map_cmd.end()){ this->set_row(list_store, size, name, true); } else { this->set_row(list_store, size, name, false); } } } void MainWindow::set_row(Glib::RefPtr &list_store, int size, std::string name, bool flag_chbox) { for (int index = 0; index < size; index++) { Gtk::TreeModel::Row row = list_store->children()[index]; if(row) { if (row[m_columns.name] == name) { row[m_columns.check_button] = flag_chbox; } } } } void MainWindow::synopsis_show() { string cmd = "xdg-open " + string(gettext("https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/")) + app_name + " &"; if (geteuid() == 0) { string response_user = getlogin(); cmd = "su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \""; } wrapper_system(cmd, "&"); } void MainWindow::wrapper_system(string cmd, string thread_str = "") { string cmd_new = cmd + " " + thread_str; int response_cmd = system(cmd_new.c_str()); if (response_cmd != 0) { index_error += 1; this->log_mess_error(cmd); } } void MainWindow::info_status_app(string stule) { Glib::RefPtr boxInfo = boxInfoError->get_style_context(); boxInfo->remove_class("boxInfoMessOK"); boxInfo->remove_class("boxInfoMessError"); boxInfo->add_class(stule); } void MainWindow::info_warning_error(int mess) { if (index_error > 0) { info_status_app("boxInfoMessError"); imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.warning", Gtk::ICON_SIZE_MENU); index_error = 0; string mess_error = ""; if (mess == 0) { mess_error = string(gettext("Local configuration reading error")) + str_cmd_error; lblWarning->set_text(mess_error); } else if (mess == 1) { mess_error = string(gettext("Global configuration read error")) + str_cmd_error; lblWarning->set_text(mess_error); } else if (mess == 2) { mess_error = string(gettext("Local configuration write error")) + str_cmd_error; lblWarning->set_text(mess_error); } else if (mess == 3) { mess_error = string(gettext("Global configuration write error")) + str_cmd_error; lblWarning->set_text(mess_error); } else if (mess == 4) { mess_error = string(gettext("Error saved local and global configuration")) + str_cmd_error; lblWarning->set_text(mess_error); } str_cmd_error = ""; } else { info_status_app("boxInfoMessOK"); imgInfo->set_from_icon_name("com.ublinux.ubl-settings-bootloader.checked", Gtk::ICON_SIZE_MENU); if (mess == 0) { lblWarning->set_text(gettext("Local configuration downloaded successfully")); } else if (mess == 1) { lblWarning->set_text(gettext("Global configuration downloaded successfully")); } else if (mess == 2) { lblWarning->set_text(gettext("Local configuration successfully written")); } else if (mess == 3) { lblWarning->set_text(gettext("Global configuration successfully written")); } else if (mess == 4) { lblWarning->set_text(gettext("Successfully saved local and global configuration")); } } } struct MainWindow::Result MainWindow::wrapper_call(string cmd) { struct Result obj_result; string response = call(cmd); if ((response.find("(null)") == std::string::npos) && (response.length() != 0 )) { if (response.find("=") != std::string::npos) { if (response.find("\n") != std::string::npos) { response = response.substr(response.find("=")+1,response.length()); response = response.substr(0,response.find("\n")); obj_result.response = response; obj_result.error = 0; } else { obj_result.response = response; obj_result.error = 1; index_error += 1; this->log_mess_error(cmd); } } else { obj_result.response = response; obj_result.error = 2; index_error += 1; str_cmd_error = cmd; this->log_mess_error(cmd); } } else { obj_result.response = response; obj_result.error = 3; index_error += 1; str_cmd_error = cmd; this->log_mess_error(cmd); } return obj_result; } void MainWindow::log_mess_error(string &cmd) { string key = ""; if (map_cmd_error.find(cmd) != map_cmd_error.end()){ str_cmd_error = map_cmd_error[cmd]; } else { for ( const auto &map_iter: map_cmd_error ) { key = map_iter.first; if (cmd.find(key) != std::string::npos){ str_cmd_error = map_iter.second; break; } } } } void MainWindow::fn_event_intelMax1(){ chbintelMax4->set_active(false); } void MainWindow::fn_event_intelMax4(){ chbintelMax1->set_active(false); } void MainWindow::add_CSS(){ Glib::RefPtr cssProvider = Gtk::CssProvider::create(); cssProvider->load_from_path(path_css); Glib::RefPtr styleContext = Gtk::StyleContext::create(); Glib::RefPtr screen = Gdk::Screen::get_default();//get default screen styleContext->add_provider_for_screen(screen, cssProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);//add provider for screen in all application Glib::RefPtr lblInfoHead_css = lblInfoHead->get_style_context(); Glib::RefPtr boxButton_css = boxButton->get_style_context(); Glib::RefPtr boxSave_css = boxSave->get_style_context(); imgBG->set(path_img_head_background); if (socket_trd_id_I == 0 && socket_ext_id_I == 0){ boxButton_css->add_class("bkim_no_plug"); boxSave_css->add_class("bkim_no_plug"); } lblInfoHead_css->add_class("textHead"); } void help() { string version = string(gettext("ubl-settings-bootloader version: ")) + version_application + "\n"; cout << version.c_str(); string help; help = "GTK settings bootloader for UBLinux\n\n" "Usage: ubl-settings-bootloader [OPTIONS...]\n" "Options:\n" " -h, --help Show this help\n" " -V, --version Show package version\n"; cout << gettext(help.c_str()); }