|
|
|
@ -2519,12 +2519,6 @@ void on_main_window_tree_selection_changed(GtkWidget *,main_window *widgets){
|
|
|
|
|
void on_main_window_services_tree_selection_changed(GtkWidget *,main_window *widgets){
|
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->ServicesList);
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
if (getuid()!=0){
|
|
|
|
|
gtk_widget_set_sensitive(widgets->ServicesEditButton,0);
|
|
|
|
|
gtk_widget_set_sensitive(widgets->ServicesEnableDisableButton,0);
|
|
|
|
|
gtk_widget_set_sensitive(widgets->ServicesStartStopButton,0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->ServicesTree)),&model,&iter)){
|
|
|
|
|
gboolean is_active;
|
|
|
|
@ -2576,12 +2570,12 @@ void on_start_stop_clicked(GtkButton *self, main_window *widgets){
|
|
|
|
|
gboolean is_started;
|
|
|
|
|
gtk_tree_model_get(model,&iter,0,&is_started,4,&start_command,5,&stop_command,-1);
|
|
|
|
|
if (is_started){
|
|
|
|
|
yon_launch(stop_command);
|
|
|
|
|
g_spawn_command_line_sync(yon_debug_output("%s\n",stop_command),NULL,NULL,NULL,NULL);
|
|
|
|
|
gtk_list_store_set(widgets->ServicesList,&iter,0,0,-1);
|
|
|
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(self)),start_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
|
|
|
gtk_widget_set_tooltip_text(widgets->ServicesStartStopButton,START_SERVICE_LABEL);
|
|
|
|
|
} else {
|
|
|
|
|
yon_launch(start_command);
|
|
|
|
|
g_spawn_command_line_sync(yon_debug_output("%s\n",start_command),NULL,NULL,NULL,NULL);
|
|
|
|
|
gtk_list_store_set(widgets->ServicesList,&iter,0,1,-1);
|
|
|
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(self)),stop_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
|
|
|
gtk_widget_set_tooltip_text(widgets->ServicesStartStopButton,STOP_SERVICE_LABEL);
|
|
|
|
@ -2589,6 +2583,14 @@ void on_start_stop_clicked(GtkButton *self, main_window *widgets){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue_func *yon_queue_add_function(GSourceFunc func,void *data);
|
|
|
|
|
queue_func *yon_queue_add_function(GSourceFunc func,void *data){
|
|
|
|
|
queue_func *queue = malloc(sizeof(queue_func));
|
|
|
|
|
queue->func=func;
|
|
|
|
|
queue->data=data;
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void on_enable_disable_clicked(GtkButton *self, main_window *widgets){
|
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL(widgets->ServicesList);
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
@ -2603,6 +2605,12 @@ void on_enable_disable_clicked(GtkButton *self, main_window *widgets){
|
|
|
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(self)),enable_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
|
|
|
gtk_widget_set_tooltip_text(widgets->ServicesEnableDisableButton,AUTOSTART_ON_LABEL);
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
g_mutex_lock(&main_config.authorized_mutex);
|
|
|
|
|
main_config.queue_size += 1;
|
|
|
|
|
main_config.queue = yon_remalloc(main_config.queue,sizeof(queue_func**)*(main_config.queue_size));
|
|
|
|
|
main_config.queue[main_config.queue_size-1] = yon_queue_add_function(G_SOURCE_FUNC(system),start_command);
|
|
|
|
|
g_mutex_unlock(&main_config.authorized_mutex);*/
|
|
|
|
|
yon_launch(start_command);
|
|
|
|
|
gtk_list_store_set(widgets->ServicesList,&iter,1,1,-1);
|
|
|
|
|
gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(self)),disable_icon_name,GTK_ICON_SIZE_BUTTON);
|
|
|
|
@ -2612,56 +2620,72 @@ void on_enable_disable_clicked(GtkButton *self, main_window *widgets){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// standard functions
|
|
|
|
|
gboolean on_unelevate(main_window* widgets);
|
|
|
|
|
gboolean on_unelevate(main_window* widgets){
|
|
|
|
|
yon_ubl_status_box_render(UNAUTHTORIZED_LABEL,BACKGROUND_IMAGE_INFO_TYPE);
|
|
|
|
|
gtk_widget_set_sensitive(widgets->UpgradePermissionsMenuItem,1);
|
|
|
|
|
g_object_unref(main_config.authorization_result);
|
|
|
|
|
main_config.authorization_result=NULL;
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
gboolean yon_timeoutcheck_authtorization(gpointer widgets);
|
|
|
|
|
gboolean yon_timeoutcheck_authtorization(gpointer widgets){
|
|
|
|
|
|
|
|
|
|
void on_permissions_changed(){
|
|
|
|
|
if (g_permission_get_allowed(main_config.permissions)){
|
|
|
|
|
PolkitAuthority *auth = polkit_authority_get_sync(NULL,NULL);
|
|
|
|
|
PolkitSubject *subject;
|
|
|
|
|
pid_t parent_pid;
|
|
|
|
|
parent_pid = getppid ();
|
|
|
|
|
subject = polkit_unix_process_new_for_owner (parent_pid,0,getuid());
|
|
|
|
|
PolkitDetails *dets = polkit_details_new();
|
|
|
|
|
if (polkit_authority_check_authorization_sync(auth,subject,"com.ublinux.ubl-settings-logging",dets,POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,NULL,NULL)){
|
|
|
|
|
printf("Allowed\n");
|
|
|
|
|
char *command[] = {"/bin/pkexec","/bin/echo","1", NULL};
|
|
|
|
|
gchar *standard_output = NULL;
|
|
|
|
|
gchar *standard_error = NULL;
|
|
|
|
|
gint exit_status = -1;
|
|
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
gboolean success = g_spawn_sync(
|
|
|
|
|
NULL,
|
|
|
|
|
command,
|
|
|
|
|
NULL,
|
|
|
|
|
G_SPAWN_DEFAULT,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
&standard_output,
|
|
|
|
|
&standard_error,
|
|
|
|
|
NULL,
|
|
|
|
|
&error
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
if (standard_output != NULL) {
|
|
|
|
|
printf("Output: %s\n", standard_output);
|
|
|
|
|
g_free(standard_output);
|
|
|
|
|
if (!polkit_authorization_result_get_is_authorized(main_config.authorization_result)){
|
|
|
|
|
gdk_threads_add_idle((GSourceFunc)on_unelevate,widgets);
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
if (standard_error != NULL) {
|
|
|
|
|
printf("Error output: %s\n", standard_error);
|
|
|
|
|
g_free(standard_error);
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *yon_authorized_loop(void*);
|
|
|
|
|
void *yon_authorized_loop(void*){
|
|
|
|
|
while (polkit_authorization_result_get_is_authorized(main_config.authorization_result)){
|
|
|
|
|
g_mutex_lock(&main_config.authorized_mutex);
|
|
|
|
|
if (main_config.queue){
|
|
|
|
|
for (int i=0;i<main_config.queue_size;i++){
|
|
|
|
|
G_SOURCE_FUNC(main_config.queue[i]->func)(main_config.queue[i]->data);
|
|
|
|
|
}
|
|
|
|
|
printf("Exit status: %d\n", exit_status);
|
|
|
|
|
} else {
|
|
|
|
|
g_printerr("Error running command: %s\n", error->message);
|
|
|
|
|
g_error_free(error);
|
|
|
|
|
free(main_config.queue);
|
|
|
|
|
main_config.queue=NULL;
|
|
|
|
|
main_config.queue_size=0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (g_permission_get_can_acquire(main_config.permissions)){
|
|
|
|
|
g_permission_acquire(main_config.permissions,NULL,NULL);
|
|
|
|
|
g_mutex_unlock(&main_config.authorized_mutex);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void authorize_callback(GObject *source, GAsyncResult *res, main_window *widgets);
|
|
|
|
|
void authorize_callback(GObject *source, GAsyncResult *res, main_window *widgets){
|
|
|
|
|
GError *err = NULL;
|
|
|
|
|
main_config.authorization_result = polkit_authority_check_authorization_finish(POLKIT_AUTHORITY(source),res,&err);
|
|
|
|
|
if (err){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_thread_new("auth_loop",(GThreadFunc)yon_authorized_loop,NULL);
|
|
|
|
|
yon_ubl_status_box_render(AUTHTORIZED_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
|
|
|
g_timeout_add(10000, (GSourceFunc)yon_timeoutcheck_authtorization,widgets);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void on_permissions_changed(GtkMenuItem *,main_window *widgets){
|
|
|
|
|
PolkitAuthority *authority;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
authority = polkit_authority_get_sync(NULL,&error);
|
|
|
|
|
if (!authority){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
polkit_authority_check_authorization(
|
|
|
|
|
authority,
|
|
|
|
|
main_config.process,
|
|
|
|
|
"org.freedesktop.policykit.exec",
|
|
|
|
|
NULL,
|
|
|
|
|
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
|
|
|
|
|
NULL,
|
|
|
|
|
(GAsyncReadyCallback)authorize_callback,
|
|
|
|
|
widgets
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void config_init(){
|
|
|
|
@ -2677,18 +2701,15 @@ void config_init(){
|
|
|
|
|
main_config.remove_thread=-1;
|
|
|
|
|
main_config.load_mode=1;
|
|
|
|
|
main_config.save_config=1;
|
|
|
|
|
|
|
|
|
|
PolkitSubject *subject = NULL;
|
|
|
|
|
|
|
|
|
|
main_config.queue=NULL;
|
|
|
|
|
main_config.queue_size=0;
|
|
|
|
|
main_config.process = polkit_unix_process_new_for_owner(getpid(),0,getuid());
|
|
|
|
|
pid_t parent_pid;
|
|
|
|
|
parent_pid = getppid ();
|
|
|
|
|
if (parent_pid == 1)
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("Parent process was reaped by init(1)\n");
|
|
|
|
|
}
|
|
|
|
|
subject = polkit_unix_process_new_for_owner (parent_pid,0,getuid());
|
|
|
|
|
main_config.permissions = polkit_permission_new_sync("com.ublinux.ubl-settings-logging",subject,NULL,NULL);
|
|
|
|
|
g_signal_connect(G_OBJECT(main_config.permissions),"notify::allowed",G_CALLBACK(on_permissions_changed),NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void yon_main_window_complete(template_main_window **window){
|
|
|
|
@ -2712,15 +2733,13 @@ void yon_main_window_complete(template_main_window **window){
|
|
|
|
|
widgets->ServicesList = GTK_LIST_STORE(gtk_builder_get_object(builder,"ServicesList"));
|
|
|
|
|
|
|
|
|
|
widgets->UpgradePermissionsMenuItem = yon_gtk_builder_get_widget(builder,"UpgradePermissionsMenuItem");
|
|
|
|
|
gtk_menu_shell_prepend(GTK_MENU_SHELL(gtk_widget_get_parent(widgets->AboutMenuItem)),widgets->UpgradePermissionsMenuItem);
|
|
|
|
|
|
|
|
|
|
widgets->MainTree = yon_gtk_builder_get_widget(builder,"MainTree");
|
|
|
|
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(widgets->Window),TITLE_LABEL);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// GtkWidget *menu = yon_gtk_builder_get_widget(builder,"menu2");
|
|
|
|
|
// gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->DocumentationMenuItem);
|
|
|
|
|
// gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->AboutMenuItem);
|
|
|
|
|
|
|
|
|
|
if (main_config.lock_load_global == 1){
|
|
|
|
|
gtk_widget_set_sensitive(widgets->LoadGlobalMenuItem,0);
|
|
|
|
@ -2868,7 +2887,7 @@ void yon_main_window_complete(template_main_window **window){
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->LoadLocalMenuItem),"activate",G_CALLBACK(on_load_local),NULL);
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->LoadCustomMenuItem),"activate",G_CALLBACK(on_config_custom_load),NULL);
|
|
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->UpgradePermissionsMenuItem),"activate",G_CALLBACK(on_permissions_changed),NULL);
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->UpgradePermissionsMenuItem),"activate",G_CALLBACK(on_permissions_changed),widgets);
|
|
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->MainTree),"cursor-changed",G_CALLBACK(on_main_window_tree_selection_changed),widgets);
|
|
|
|
|
g_signal_connect(G_OBJECT(widgets->ServicesTree),"cursor-changed",G_CALLBACK(on_main_window_services_tree_selection_changed),widgets);
|
|
|
|
@ -2894,6 +2913,7 @@ void yon_main_window_complete(template_main_window **window){
|
|
|
|
|
}
|
|
|
|
|
yon_load_proceed(YON_CONFIG_LOCAL);
|
|
|
|
|
update_loaded_logrotate();
|
|
|
|
|
gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
|