Command building redone

pull/51/head
parent 0425101365
commit aea00ad6c3

@ -120,7 +120,6 @@ install: check uninstall
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/icons/hicolor/scalable/apps/" "com.ublinux.${PKGNAME}.svg"
@install -Dm644 -t "${DESTDIR}${PREFIX}/share/applications/" "${PKGNAME}.desktop"
@install -Dm755 -t "${DESTDIR}${PREFIX}/bin/" "${CMAKE_BUILD_DIR}/${PKGNAME}"
@install -Dm755 -t "${DESTDIR}/usr/share/${PKGNAME}/csv/" "${PKGNAME}_terminals.csv"
@install -Dm644 "com.ublinux.${PKGNAME}.policy" "${DESTDIR}/usr/share/polkit-1/actions/com.ublinux.${PKGNAME}${PKGIDENT}.policy"
@sed -e '\|annotate key=|s|/usr/bin|${PREFIX}/bin|' -e '/action id=/s/\.run/${PKGIDENT}\.run/' -i ${DESTDIR}/usr/share/polkit-1/actions/com.ublinux.${PKGNAME}${PKGIDENT}.policy
@if [ -z ${DESTDIR} ]; then \

@ -638,11 +638,11 @@ char *yon_char_replace(char *source, char *find, char*replace){
char *temp=NULL;
if(!strstr(replace,find)){
while ((final=strstr(source,find))){
temp=malloc(strlen(source)-strlen(final));
memset(temp,0,strlen(source)-strlen(final)+strlen(replace));
temp=malloc(strlen(source)-strlen(final))+1;
memset(temp,0,strlen(source)-strlen(final)+strlen(replace)+1);
memcpy(temp,source,strlen(source)-strlen(final));
temp=yon_char_append(temp,replace);
source=yon_char_append(temp,final+1);
source=yon_char_append(temp,final+strlen(find));
}
}

@ -171,68 +171,28 @@ void on_setup_command(GtkWidget *self, main_window *widgets){
char *target = (char*)gtk_entry_get_text(GTK_ENTRY(widgets->TargetNameEntry));
if (target&&strcmp(target,"")){
char *final_command;
char *terminal_exec = yon_dictionary_get_data(yon_dictionary_get(&main_config.terminals,(char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithTerminalCombo))),terminal_info*)->exec_file;
char *terminal_hold = yon_dictionary_get_data(main_config.terminals,terminal_info*)->hold;
char *terminal_exec_arg = yon_dictionary_get_data(main_config.terminals,terminal_info*)->exec_arg;
int terminal_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck));
int chosen_terminal = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo));
terminal_info *terminal = yon_dictionary_get_data(yon_dictionary_get_nth(main_config.terminals,chosen_terminal),terminal_info*);
int user_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserCheck));
char *user = (char*)gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widgets->runWithUserCombo));
char *priority = yon_char_append("nice -n ",yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->prioritySpin))));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserCheck))){
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserPkexecCheck))){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ",!strstr(target,".") ? terminal_hold : ""," ",terminal_exec_arg," ",NULL) : "", "pkexec ", NULL);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))==0){ //root
final_command = yon_char_unite(final_command, " --user root env HOME=$HOME DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR SESSION_MANAGER=$SESSION_MANAGER GNOME_DESKTOP_SESSION_ID=$GNOME_DESKTOP_SESSION_ID KDE_FULL_SESSION=$KDE_FULL_SESSION ",NULL);
} else {
final_command = yon_char_unite(final_command, " --user ",user," env HOME=$HOME DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE ",NULL);
}
if (strstr(target,".")){
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "xdg-open ",target,NULL);
} else {
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority," ") : "",target,NULL);
}
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck))){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ",!strstr(target,".") ? terminal_hold : ""," ",terminal_exec_arg," ",NULL) : "", "su ", NULL);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))==0){ //root
final_command = yon_char_unite(final_command, " --preserve-environment --command \"setsid ",NULL);
} else {
final_command = yon_char_unite("xhost +SI:localuser:",user,"; ",final_command, " --login ",user," --command \"setsid env DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE ",NULL);
}
if (strstr(target,".")){
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "xdg-open ",target,"\"",NULL);
} else {
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority," ") : "",target,"\"",NULL);
}
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))){
final_command = yon_char_unite(final_command,"; sleep 10 && xhost -SI:localuser:",user,NULL);
}
} else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck))){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ",!strstr(target,".") ? terminal_hold : ""," ",terminal_exec_arg," ",NULL) : "", "sudo ", NULL);
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))==0){ //root
final_command = yon_char_unite(final_command, " --preserve-env setsid ",NULL);
} else {
final_command = yon_char_unite("xhost +SI:localuser:",user,"; ",final_command, " --user ",user," setsid env DISPLAY=$DISPLAY WAYLAND_DISPLAY=$WAYLAND_DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS XDG_SESSION_TYPE=$XDG_SESSION_TYPE ",NULL);
}
if (strstr(target,".")){
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "xdg-open '",target,"'",NULL);
} else {
final_command = yon_char_unite(final_command,gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority," '") : "'",target,"'",NULL);
}
if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->runWithUserCombo))){
final_command = yon_char_unite(final_command,"; sleep 10 && xhost -SI:localuser:",user,NULL);
}
}
} else {
if (strstr(target,".")){
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ", !strstr(target,".") ? terminal_hold : "",!strstr(target,".") ? " " : "", terminal_exec_arg, " ",NULL) : "",gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "", "setsid xdg-open ",target,NULL);
} else {
final_command = yon_char_unite(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithTerminalCheck)) ? yon_char_unite(terminal_exec," ", !strstr(target,".") ? terminal_hold : "",!strstr(target,".") ? " " : "", terminal_exec_arg, " ",NULL) : "",gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck)) ? yon_char_append(priority, " ") : "",target,NULL);
}
}
int pkexec_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserPkexecCheck));
int su_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSuCheck));
int sudo_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->runWithUserSudoCheck));
int priority_check = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->priorityCheck));
char *priority = priority_check ? yon_char_append(" -p ",yon_char_from_long(gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->prioritySpin)))) : "";
int size;
char *command = yon_char_unite(get_run_command_command,
terminal_check ? yon_char_append(" -t ", terminal->name_simple) : "",
user_check ? yon_char_append(" -u ", user) : "",
user_check&&pkexec_check ? " -e pkexec" : "",
user_check&&su_check ? " -e su" : "",
user_check&&sudo_check ? " -e sudo" : "",
priority_check ? priority : "",
yon_char_append(" ",target),
NULL);
config_str gotten_command = yon_config_load(command,&size);
final_command = yon_char_divide_search(*gotten_command,"\n",-1);
gtk_entry_set_text(GTK_ENTRY(widgets->commandEntry),final_command);
free(final_command);
}
@ -362,18 +322,16 @@ main_window *setup_window(){
config_str terminals = yon_config_load(get_terminals_info_command,&size);
for (int i=0;i<size;i++){
for (int i=1;i<size;i++){
int parsed_size;
terminals[i] = yon_char_divide_search(terminals[i],"\n",-1);
config_str terminal_parsed = yon_char_parse(terminals[i], &parsed_size,":");
if (!access(terminal_parsed[1],F_OK)){
terminal_info *term = g_malloc0(sizeof(terminal_info));
term->name = terminal_parsed[0];
term->exec_file = terminal_parsed[1];
term->hold = terminal_parsed[2];
term->exec_arg = terminal_parsed[3];
term->exec = terminal_parsed[0];
term->name_simple = terminal_parsed[1];
term->name = terminal_parsed[2];
if (!access(term->exec,F_OK)) {gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithTerminalCombo),term->name);
yon_dictionary_add_or_create_if_exists_with_data(main_config.terminals,term->name,term);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widgets->runWithTerminalCombo),term->name);
}
}
gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->runWithTerminalCombo),0);

File diff suppressed because it is too large Load Diff

@ -26,7 +26,8 @@
#define get_user_id_min_command "grep \"^UID_MIN\" /etc/login.defs |grep -vE '(nologin|false)$' | sed -e 's/\t/ /g' -e 's/ */ /g'|grep -oE \"[0-9]{1,}\""
#define get_user_id_max_command "grep \"^UID_MAX\" /etc/login.defs | sed -e 's/\t/ /g' -e 's/ */ /g'|grep -oE \"[0-9]{1,}\""
#define get_users_command "getent passwd |cut -d: -f1,3"
#define get_terminals_info_command "grep \"\" /usr/share/ublexec/csv/ublexec_terminals.csv"
#define get_terminals_info_command "ublexec-cli -l|sed -e 's/\t/ /g' -e 's/^ *//g' -e 's/ */:/g'|cut -d':' -f1,2,3"
#define get_run_command_command "ublexec-cli -q -o"
#define LocalePath "/usr/share/locale"
#define LocaleName "ublexec"
@ -58,9 +59,8 @@ typedef struct {
typedef struct {
char *name;
char *exec_file;
char *hold;
char *exec_arg;
char *name_simple;
char *exec;
} terminal_info;
typedef struct {

File diff suppressed because it is too large Load Diff

@ -1,7 +0,0 @@
XTerm (xterm emulator):/usr/bin/xterm:-hold:-e
XFCE (xfce4-terminal emulator):/usr/bin/xfce4-terminal:--hold:-x
Mate (mate-terminal emulator):/usr/bin/mate-terminal:--window-with-profile=HoldOpen:-e
Gnome (gnome-terminal emulator):/usr/bin/gnome-terminal:--window-with-profile=HoldOpen:-e
KDE (konsole emulator):/usr/bin/konsole:-hold:-e
Enlightenment (terminology emulator):/usr/bin/terminology:--hold:-e
LXDE (lxterminal emulator):/usr/bin/lxterminal::-e
1 XTerm (xterm emulator):/usr/bin/xterm:-hold:-e
2 XFCE (xfce4-terminal emulator):/usr/bin/xfce4-terminal:--hold:-x
3 Mate (mate-terminal emulator):/usr/bin/mate-terminal:--window-with-profile=HoldOpen:-e
4 Gnome (gnome-terminal emulator):/usr/bin/gnome-terminal:--window-with-profile=HoldOpen:-e
5 KDE (konsole emulator):/usr/bin/konsole:-hold:-e
6 Enlightenment (terminology emulator):/usr/bin/terminology:--hold:-e
7 LXDE (lxterminal emulator):/usr/bin/lxterminal::-e
Loading…
Cancel
Save