|
|
|
|
@ -1,11 +1,13 @@
|
|
|
|
|
#include "ublexec.h"
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const string path_app = "/usr/bin/";
|
|
|
|
|
const string path_glade = "/usr/share/ublexec/ui/ublexec.glade";
|
|
|
|
|
const string path_css = "/usr/share/ublexec/css/style.css";
|
|
|
|
|
const string app_name = "ublexec";
|
|
|
|
|
int socket_ext_id_I = 0;
|
|
|
|
|
int socket_trd_id_I = 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;
|
|
|
|
|
@ -135,8 +137,12 @@ void MainWindow::add_CSS() {
|
|
|
|
|
styleContext->add_provider_for_screen(screen, cssProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);//add provider for screen in all application
|
|
|
|
|
Glib::RefPtr<Gtk::StyleContext> context_box = boxColor->get_style_context();
|
|
|
|
|
Glib::RefPtr<Gtk::StyleContext> context_lbl_head = lblInfoHead->get_style_context();
|
|
|
|
|
Glib::RefPtr<Gtk::StyleContext> boxAbout_css = boxAbout->get_style_context();
|
|
|
|
|
context_box->add_class("cssboxColor1");
|
|
|
|
|
context_lbl_head->add_class("textHead");
|
|
|
|
|
if (socket_ext_id_I == 0){
|
|
|
|
|
boxAbout_css->add_class("bkim_no_plug");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::localization() {
|
|
|
|
|
@ -177,14 +183,15 @@ void MainWindow::localization() {
|
|
|
|
|
lblOther->set_text(_("Other"));
|
|
|
|
|
lblDevelopment->set_text(_("Development"));
|
|
|
|
|
lblSystem->set_text(_("System"));
|
|
|
|
|
|
|
|
|
|
btnListApp->set_tooltip_text(_("Application Overview"));
|
|
|
|
|
btnFilemaneg->set_tooltip_text(_("File Overview"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::event() {
|
|
|
|
|
btnFilemaneg->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::open_filemaneg));
|
|
|
|
|
btnListApp->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::open_list_app));
|
|
|
|
|
btnStart->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::entry_app));
|
|
|
|
|
chbTerminal->signal_toggled().connect([&]() {cmbTerminal->set_sensitive(chbTerminal->get_active());this->denamic_cmd();});
|
|
|
|
|
chbTerminal->signal_toggled().connect([&]() {cmbTerminal->set_sensitive(chbTerminal->get_active());denamic_cmd();});
|
|
|
|
|
chbAnotherUser->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::activ_or_block_other_user));
|
|
|
|
|
spinPriority->signal_value_changed().connect(sigc::mem_fun(*this, &MainWindow::change_scale_priority));
|
|
|
|
|
scalePriority->signal_value_changed().connect(sigc::mem_fun(*this, &MainWindow::change_spin_priority));
|
|
|
|
|
@ -207,13 +214,14 @@ void MainWindow::event() {
|
|
|
|
|
iconSystem->signal_selection_changed().connect(sigc::mem_fun(*this,&MainWindow::select_System));
|
|
|
|
|
btnSynopsis->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::synopsis_show));
|
|
|
|
|
btnAbout->signal_activate().connect([&]() {aboutWindows->show();});
|
|
|
|
|
cmbUser->signal_changed().connect([&]() {changed_user();denamic_cmd();});
|
|
|
|
|
cmbUser->signal_changed().connect([&]() {changed_user();this->denamic_cmd();});
|
|
|
|
|
rbSudo->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::sudo_nice));
|
|
|
|
|
txtCmd->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_out_txt_cmd));
|
|
|
|
|
txtCmd->signal_focus_in_event().connect(sigc::mem_fun(*this, &MainWindow::focus_in_txt_cmd));
|
|
|
|
|
txtCmd->signal_delete_text().connect(sigc::mem_fun(*this, &MainWindow::delete_cmd));
|
|
|
|
|
rbSu->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::sudo_nice));
|
|
|
|
|
rbPkexec->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::sudo_nice));
|
|
|
|
|
cmbTerminal->signal_changed().connect([&]() {this->denamic_cmd();});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -289,8 +297,10 @@ bool MainWindow::focus_in_txt_cmd(GdkEventFocus* event) {
|
|
|
|
|
if (user_cmd.length() != 0) {
|
|
|
|
|
}
|
|
|
|
|
else if (name_app.length() != 0) {
|
|
|
|
|
name_app = "";
|
|
|
|
|
}
|
|
|
|
|
else if (path_file.length() != 0) {
|
|
|
|
|
path_file = "";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
user_cmd = txtCmd->get_text();
|
|
|
|
|
@ -605,19 +615,20 @@ string MainWindow::start_cmd(string user_cmd) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
if (chbTerminal->get_active() == true) {
|
|
|
|
|
string name_terminal_arr = "";
|
|
|
|
|
string name_terminal = cmbTerminal->get_active_text();
|
|
|
|
|
if (name_terminal.length() != 0) {
|
|
|
|
|
if (name_terminal == "xfce4-terminal") {
|
|
|
|
|
str_cmd_terminal = "xfce4-terminal -x ";
|
|
|
|
|
int len_termunal_cmd = sizeof(termunal_cmd)/sizeof(*termunal_cmd);
|
|
|
|
|
for (int index = 0; index<len_termunal_cmd; index++) {
|
|
|
|
|
name_terminal_arr = termunal_cmd[index];
|
|
|
|
|
size_t index_term = name_terminal_arr.find(" ");
|
|
|
|
|
if (index_term != string::npos) {
|
|
|
|
|
name_terminal_arr =name_terminal_arr.substr(0, index_term);
|
|
|
|
|
if (name_terminal == name_terminal_arr) {
|
|
|
|
|
str_cmd_terminal = termunal_cmd[index];
|
|
|
|
|
}
|
|
|
|
|
else if (name_terminal == "konsole") {
|
|
|
|
|
str_cmd_terminal = "konsole -e ";
|
|
|
|
|
}
|
|
|
|
|
else if (name_terminal == "xterm") {
|
|
|
|
|
str_cmd_terminal = "xterm -e ";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
str_cmd_terminal = "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
@ -684,6 +695,7 @@ void MainWindow::denamic_cmd() {
|
|
|
|
|
else if (name_app.length() != 0) {
|
|
|
|
|
txtCmd->set_text(this->start_cmd(user_cmd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -722,7 +734,6 @@ void MainWindow::entry_app() {
|
|
|
|
|
|
|
|
|
|
void MainWindow::activ_or_block_other_user() {
|
|
|
|
|
bool flag = chbAnotherUser->get_active();
|
|
|
|
|
cmbUser->set_active(0);
|
|
|
|
|
cmbUser->set_sensitive(flag);
|
|
|
|
|
lblInfoUserName->set_sensitive(flag);
|
|
|
|
|
if (flag_pkexec == true) {
|
|
|
|
|
@ -772,18 +783,20 @@ void MainWindow::pars_dir_terminal() {
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
std::string path = "/bin";
|
|
|
|
|
string file_name = "";
|
|
|
|
|
string name_terminal = "";
|
|
|
|
|
for (const auto & entry: fs::directory_iterator(path)) {
|
|
|
|
|
file_name = entry.path().filename().string();
|
|
|
|
|
if (file_name == "konsole") {
|
|
|
|
|
cmbTerminal->append("konsole");
|
|
|
|
|
cmbTerminal->set_active_text("konsole");
|
|
|
|
|
int len_termunal_cmd = sizeof(termunal_cmd)/sizeof(*termunal_cmd);
|
|
|
|
|
for (int index = 0; index < len_termunal_cmd; ++index) {
|
|
|
|
|
name_terminal = termunal_cmd[index];
|
|
|
|
|
size_t index_term = name_terminal.find(" ");
|
|
|
|
|
if (index_term != string::npos){
|
|
|
|
|
name_terminal = name_terminal.substr(0, index_term);
|
|
|
|
|
if (name_terminal == file_name) {
|
|
|
|
|
cmbTerminal->append(name_terminal);
|
|
|
|
|
cmbTerminal->set_active_text(name_terminal);
|
|
|
|
|
}
|
|
|
|
|
else if (file_name == "xfce4-terminal") {
|
|
|
|
|
cmbTerminal->append("xfce4-terminal");
|
|
|
|
|
cmbTerminal->set_active_text("xfce4-terminal");
|
|
|
|
|
}
|
|
|
|
|
else if (file_name == "xterm") {
|
|
|
|
|
cmbTerminal->append("xterm");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -800,15 +813,50 @@ void MainWindow::is_user_wheel(){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned short MainWindow::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)) {
|
|
|
|
|
this->str_remove(line, search);
|
|
|
|
|
this->str_remove(line, remove_space);
|
|
|
|
|
this->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;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pars_users() {
|
|
|
|
|
//string str_uid_max = this->call("grep \"^UID_MAX\" /etc/login.defs | xargs | cut -d ' ' -f 2)");
|
|
|
|
|
//int uid_max = 0;
|
|
|
|
|
//if (str_uid_max.length() > 3){
|
|
|
|
|
// int uid_max = stoi(str_uid_max);
|
|
|
|
|
//}
|
|
|
|
|
//else{
|
|
|
|
|
int uid_max = 65534;
|
|
|
|
|
//}
|
|
|
|
|
unsigned short uid_min = this->read_uid_min_max("/etc/login.defs", "UID_MIN");
|
|
|
|
|
unsigned short uid_max = this->read_uid_min_max("/etc/login.defs", "UID_MAX");
|
|
|
|
|
while (true) {
|
|
|
|
|
errno = 0;
|
|
|
|
|
passwd* entry = getpwent();
|
|
|
|
|
@ -818,7 +866,7 @@ void MainWindow::pars_users() {
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((entry->pw_uid >= 1000 && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
|
|
|
|
|
if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) {
|
|
|
|
|
cmbUser->append(entry->pw_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -835,7 +883,7 @@ vector<std::string> MainWindow::split(const std::string &s, char delim) {
|
|
|
|
|
return elems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::str_remove(std::string& source, std::string & to_remove) {
|
|
|
|
|
void MainWindow::str_remove(std::string& source, std::string to_remove) {
|
|
|
|
|
string::size_type n = to_remove.length();
|
|
|
|
|
for (string::size_type i = source.find(to_remove);
|
|
|
|
|
i != string::npos;
|
|
|
|
|
|