diff --git a/source/ubl-settings-logging.c b/source/ubl-settings-logging.c index 44bc85d..2d3f6c0 100644 --- a/source/ubl-settings-logging.c +++ b/source/ubl-settings-logging.c @@ -345,7 +345,7 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ int weekday = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RotationPeriodAdditionalCombo)); weekday++; if (weekday==7) weekday=0; - period = yon_char_unite(period,", ",yon_char_from_int(weekday)); + period = yon_char_unite(period,", ",yon_char_from_int(weekday),NULL); break; case 4: period = "monthly"; break; @@ -357,7 +357,7 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->JournalMaxSizeCheck))){ int last = gtk_combo_box_get_active(GTK_COMBO_BOX(window->JournalMaxSizeCombo)); long maxsize = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->JournalMaxSizeSpin)); - size = yon_char_unite(yon_char_from_long(maxsize),yon_size_get_letter_from_int(last)); + size = yon_char_unite("size ",yon_char_from_long(maxsize),yon_size_get_letter_from_int(last),NULL); } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->FileAmountCheck))){ @@ -371,8 +371,11 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ char *user_rotate = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->RotationAtUserCombo)); char *group_rotate = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(window->RotationAtGroupCombo)); - if (!yon_char_is_empty(user_rotate)&&!yon_char_is_empty(group_rotate)) + if (!yon_char_is_empty(user_rotate)&&!yon_char_is_empty(group_rotate)){ + if (gtk_combo_box_get_active(GTK_COMBO_BOX(window->RotationAtUserCombo))==0) user_rotate = "root"; + if (gtk_combo_box_get_active(GTK_COMBO_BOX(window->RotationAtGroupCombo))==0) group_rotate = "root"; su = yon_char_unite("su ",user_rotate," ",group_rotate,NULL); + } int error_processing = gtk_combo_box_get_active(GTK_COMBO_BOX(window->ErrorProcessingCombo)); if (error_processing==0|| error_processing==1) { @@ -382,7 +385,7 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ missingok = "nomissingok"; } - int empty_journal = gtk_combo_box_get_active(window->JournalEmptyCombo); + int empty_journal = gtk_combo_box_get_active(GTK_COMBO_BOX(window->JournalEmptyCombo)); if (empty_journal==0||empty_journal==1) { empty_journal = 1; ifempty = "ifempty"; @@ -401,13 +404,13 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->RotateSizeMaxAfterTimeCheck))){ long value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->RotateSizeMaxAfterTimeSpin)); int last = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RotateSizeMaxAfterTimeCombo)); - minsize = yon_char_unite("minsize ",yon_char_from_long(value),yon_size_get_letter_from_int(last)); + minsize = yon_char_unite("minsize ",yon_char_from_long(value),yon_size_get_letter_from_int(last),NULL); } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->RotateSizeMaxBeforeTimeCheck))){ long value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->RotateSizeMaxBeforeTimeSpin)); int last = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RotateSizeMaxBeforeTimeCombo)); - maxsize = yon_char_unite("maxsize ", yon_char_from_long(value),yon_size_get_letter_from_int(last)); + maxsize = yon_char_unite("maxsize ", yon_char_from_long(value),yon_size_get_letter_from_int(last),NULL); } // int create_log_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->CreateLogCombo)); @@ -416,7 +419,88 @@ void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ // } copytruncate = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CutCheck)) ? "copytruncate" : ""; + + int compression_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->CompressionCombo)); + if (compression_active){ + switch (compression_active){ + case 1: compress = "compress"; + break; + case 2: compress = "nocompress"; + break; + } + } + + int compression_delay_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->QueueCombo)); + if (compression_delay_active){ + switch (compression_delay_active){ + case 1: delaycompress = "delaycompress"; + break; + case 2: delaycompress = "nodelaycompress"; + break; + } + } + + int original_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->SaveOriginalCombo)); + if (original_active==1){ + char *ext_file = (char*)gtk_entry_get_text(GTK_ENTRY(window->SaveOriginalEntry)); + extension = yon_char_append("extension ",ext_file); + } + + if (gtk_combo_box_get_active(GTK_COMBO_BOX(window->AddDateCombo))==1){ + dateext = "dateext"; + } + if (gtk_combo_box_get_active(GTK_COMBO_BOX(window->OldNumberCombo))==1){ + long value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->OldNumberEntry)); + if (value>0) + start = yon_char_append("start ",yon_char_from_long(value)); + } + + int email_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->EmailCombo)); + if (email_active){ + switch(email_active){ + case 1: + char *adress = (char*)gtk_entry_get_text(GTK_ENTRY(window->EmailEntry)); + if (!yon_char_is_empty(adress)) + mail=yon_char_append("mail ", adress); + int contents_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->EmailContentsCombo)); + if (contents_active==1) + mailfirst = "mailfirst"; + else if (contents_active==2) + mailfirst = "maillast"; + break; + case 2: mail = "nomail"; + break; + } + } + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->SharedScenariosCheck))){ + char *before_once = (char*)gtk_entry_get_text(GTK_ENTRY(window->CommandBeforeOnceEntry)); + char *after_once = (char*)gtk_entry_get_text(GTK_ENTRY(window->CommandAfterOnceEntry)); + char *before = (char*)gtk_entry_get_text(GTK_ENTRY(window->CommandBeforeEntry)); + char *after = (char*)gtk_entry_get_text(GTK_ENTRY(window->CommandAfterEntry)); + char *endwork = (char*)gtk_entry_get_text(GTK_ENTRY(window->EndworkCommandEntry)); + sharedscripts = "sharedscripts"; + if (!yon_char_is_empty(before_once)) + firstaction = yon_char_append("firstaction ",before_once); + if (!yon_char_is_empty(after_once)) + lastaction = yon_char_append("lastaction ",after_once); + if (!yon_char_is_empty(before)) + prerotate = yon_char_append("prerotate ",before); + if (!yon_char_is_empty(after)) + postrotate = yon_char_append("postrotate ",after); + if (!yon_char_is_empty(endwork)) + endscript = yon_char_append("endscript ",endwork); + } + + char *commandline = yon_char_unite(period,yon_add_space_if_exists(size),yon_add_space_if_exists(rotate_count),yon_add_space_if_exists(olddir),yon_add_space_if_exists(su),yon_add_space_if_exists(missingok),yon_add_space_if_exists(ifempty),yon_add_space_if_exists(notifempty),yon_add_space_if_exists(minage),yon_add_space_if_exists(maxage),yon_add_space_if_exists(minsize),yon_add_space_if_exists(maxsize),yon_add_space_if_exists(create),yon_add_space_if_exists(copytruncate),yon_add_space_if_exists(compress),yon_add_space_if_exists(delaycompress),yon_add_space_if_exists(extension),yon_add_space_if_exists(dateext),yon_add_space_if_exists(start),yon_add_space_if_exists(mail),yon_add_space_if_exists(mailfirst),yon_add_space_if_exists(sharedscripts),yon_add_space_if_exists(firstaction),yon_add_space_if_exists(lastaction),yon_add_space_if_exists(prerotate),yon_add_space_if_exists(postrotate),yon_add_space_if_exists(preremove),yon_add_space_if_exists(endscript),NULL); + if (commandline[0]==' '){ + free(yon_char_divide_search(commandline," ",-1)); + } + if(!yon_char_is_empty(paths)){ + yon_config_register(LOGROTATE(paths),"logging",commandline); + on_close_subwindow(window->MainWindow); + } } logrotate_configure_window *yon_logrotate_window_new(){ @@ -477,9 +561,15 @@ logrotate_configure_window *yon_logrotate_window_new(){ window->LogPathRemoveButton=yon_gtk_builder_get_widget(builder,"LogPathRemoveButton"); window->list=GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore1")); window->PathCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"PathCell")); + window->SharedScenariosCheck=yon_gtk_builder_get_widget(builder,"SharedScenariosCheck"); + window->CommandBeforeOnceEntry=yon_gtk_builder_get_widget(builder,"CommandBeforeOnceEntry"); + window->CommandAfterOnceEntry=yon_gtk_builder_get_widget(builder,"CommandAfterOnceEntry"); + window->CommandBeforeEntry=yon_gtk_builder_get_widget(builder,"CommandBeforeEntry"); + window->CommandAfterEntry=yon_gtk_builder_get_widget(builder,"CommandAfterEntry"); + window->EndworkCommandEntry=yon_gtk_builder_get_widget(builder,"EndworkCommandEntry"); gtk_window_set_title(GTK_WINDOW(window->MainWindow),TITLE_LABEL); g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_close_subwindow),NULL); - g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_logrotate_save),NULL); + g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_logrotate_save),window); g_signal_connect(G_OBJECT(window->PathCell),"edited",G_CALLBACK(on_path_editing_done),window); g_signal_connect(G_OBJECT(window->PathCell),"editing-canceled",G_CALLBACK(on_path_editing_cancel),window); g_signal_connect(G_OBJECT(window->LogPathAddButton),"clicked",G_CALLBACK(on_logrotate_configuration_path_add),window); @@ -511,6 +601,9 @@ logrotate_configure_window *yon_logrotate_window_new(){ g_signal_connect(G_OBJECT(window->CreateLogCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box_inversed),window->CreateGroupCombo); g_signal_connect(G_OBJECT(window->CreateLogCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box_inversed),window->CreateLogEntry); g_signal_connect(G_OBJECT(window->CreateLogCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box_inversed),window->CreateLogButton); + + + return window; } diff --git a/source/ubl-settings-logging.h b/source/ubl-settings-logging.h index ec704e8..ac762ff 100644 --- a/source/ubl-settings-logging.h +++ b/source/ubl-settings-logging.h @@ -37,12 +37,15 @@ #define LocaleName "ubl-settings-logging" #define JOURNALD(key) yon_char_unite("JOURNALD[",key,"]",NULL) +#define LOGROTATE(key) yon_char_unite("LOGROTATE[",key,"]",NULL) #define get_journal_output_command "journalctl --no-pager" #define get_journal_output_since_boot_command "journalctl --no-pager -b" #define get_journal_output_followed_command "journalctl --no-pager -f" #define get_journal_output_kernel_command "journalctl --no-pager -k" #define get_journal_output_prioritied_command "journalctl --no-pager -p err..alert" + +#define yon_add_space_if_exists(string) yon_char_is_empty(string) ? "" : yon_char_append(" ",string) typedef char* string; string version_application; @@ -299,6 +302,12 @@ typedef struct { GtkWidget *headerTopic; GtkListStore *list; GtkCellRenderer *PathCell; + GtkWidget *SharedScenariosCheck; + GtkWidget *CommandBeforeOnceEntry; + GtkWidget *CommandAfterOnceEntry; + GtkWidget *CommandBeforeEntry; + GtkWidget *CommandAfterEntry; + GtkWidget *EndworkCommandEntry; } logrotate_configure_window; main_window *setup_window(); \ No newline at end of file diff --git a/source/ubl-utils.h b/source/ubl-utils.h index 8261a80..e6e2fdf 100644 --- a/source/ubl-utils.h +++ b/source/ubl-utils.h @@ -123,7 +123,7 @@ void *yon_dictionary_free_all(dictionary *dictionary,void (data_manipulation)(vo #define yon_char_divide_search_self(str,find,delete_divider) {char *temp = str; str = yon_char_divide_search(str,find,delete_divider); free(temp);} -#define yon_char_is_empty(string) !string||!strcmp(string,"") +#define yon_char_is_empty(string) !(string&&strcmp(string,"")) int yon_char_find_last(char *source, char find); diff --git a/ubl-settings-logging-logrotate.glade b/ubl-settings-logging-logrotate.glade index d324d06..20e0047 100644 --- a/ubl-settings-logging-logrotate.glade +++ b/ubl-settings-logging-logrotate.glade @@ -8,6 +8,11 @@ 1 10 + + 100 + 1 + 10 + 1024 1 @@ -463,6 +468,7 @@ True False False + 0 Monday Tuesday @@ -696,6 +702,7 @@ True False + 0 root* @@ -722,6 +729,7 @@ True False + 0 root* @@ -1359,6 +1367,7 @@ False 0 + Default On Off @@ -1389,6 +1398,8 @@ 0 Default + Yes + No @@ -1570,11 +1581,10 @@ - + True - False True - digits + adjustment10 False @@ -1650,6 +1660,8 @@ 0 Default + Send Email + Don't send email @@ -1702,6 +1714,8 @@ 0 Default + First rotated copy + Last rotated copy @@ -1755,7 +1769,7 @@ vertical 5 - + Scenarios are running for each rotated journal True True @@ -1787,7 +1801,7 @@ - + True True @@ -1823,7 +1837,7 @@ - + True True @@ -1859,7 +1873,7 @@ - + True True @@ -1895,7 +1909,7 @@ - + True True @@ -1912,6 +1926,42 @@ 4 + + + True + False + 5 + + + True + False + Endwork command: + 0 + + + False + True + 0 + + + + + True + True + + + True + True + 1 + + + + + False + True + 5 + + @@ -1932,7 +1982,6 @@ - True False 5