From b50f83abb950bcee52e0a4fcc2d36521f83618aa Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Tue, 24 Oct 2023 18:08:31 +0600 Subject: [PATCH] Logrotate saving has been partially implemented --- source/ubl-settings-logging.c | 189 ++++++++++++++++++++++++++- source/ubl-utils.c | 5 +- ubl-settings-logging-journald.glade | 2 + ubl-settings-logging-logrotate.glade | 30 ++++- 4 files changed, 214 insertions(+), 12 deletions(-) diff --git a/source/ubl-settings-logging.c b/source/ubl-settings-logging.c index 50f8252..44bc85d 100644 --- a/source/ubl-settings-logging.c +++ b/source/ubl-settings-logging.c @@ -296,6 +296,129 @@ void on_logrotate_configuration_path_remove(GtkWidget *self, logrotate_configure } } +void on_logrotate_save(GtkWidget *self, logrotate_configure_window *window){ + char *paths=""; + char *period=""; + char *size=""; + char *rotate_count=""; + char *olddir=""; + char *su=""; + char *missingok=""; + char *ifempty=""; + char *notifempty=""; + char *minage=""; + char *maxage=""; + char *minsize=""; + char *maxsize=""; + char *create=""; + char *copytruncate=""; + char *compress=""; + char *delaycompress=""; + char *extension=""; + char *dateext=""; + char *start=""; + char *mail=""; + char *mailfirst=""; + char *sharedscripts=""; + char *firstaction=""; + char *lastaction=""; + char *prerotate=""; + char *postrotate=""; + char *preremove=""; + char *endscript=""; + + GtkTreeIter iter; + int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(window->list),&iter); + for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(window->list),&iter)){ + char *cur_path; + gtk_tree_model_get(GTK_TREE_MODEL(window->list),&iter,0,&cur_path,-1); + paths = yon_char_unite(paths,strcmp(paths,"") ? "," : "", cur_path,NULL); + } + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->RotationPeriodCheck))){ + int active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->RotationPeriodMainCombo)); + switch (active){ + case 0: period = "hourly"; + break; + case 2: period = "daily"; + break; + case 3: period = "weekly"; + 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)); + break; + case 4: period = "monthly"; + break; + case 5: period = "yearly"; + break; + } + } + + 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)); + } + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->FileAmountCheck))){ + long fileamount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->FileAmountSpin)); + int active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->FileAmountCombo)); + if (active==2){ + const char *text = gtk_entry_get_text(GTK_ENTRY(window->FileAmountEntry)); + rotate_count=yon_char_unite("olddir",",",text,NULL); + } + } + + 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)) + 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) { + error_processing=1; + missingok = "missingok"; + } else { + missingok = "nomissingok"; + } + + int empty_journal = gtk_combo_box_get_active(window->JournalEmptyCombo); + if (empty_journal==0||empty_journal==1) { + empty_journal = 1; + ifempty = "ifempty"; + } + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DoNotRotateYoungerCheck))){ + long younger = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DoNotRotateYoungerSpin)); + minage = yon_char_append("minage ",yon_char_from_long(younger)); + } + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->DeleteOlderCheck))){ + long older = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->DeleteOlderSpin)); + maxage = yon_char_append("maxage ", yon_char_from_long(older)); + } + + 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)); + } + + 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)); + } + + // int create_log_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->CreateLogCombo)); + // if (create_log_active){ + // if (create_log_active==2) + // } + + copytruncate = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->CutCheck)) ? "copytruncate" : ""; + +} + logrotate_configure_window *yon_logrotate_window_new(){ logrotate_configure_window *window = malloc(sizeof(logrotate_configure_window)); GtkBuilder *builder = gtk_builder_new_from_resource(glade_logrotate_path); @@ -356,7 +479,7 @@ logrotate_configure_window *yon_logrotate_window_new(){ window->PathCell=GTK_CELL_RENDERER(gtk_builder_get_object(builder,"PathCell")); 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_close_subwindow),NULL); + g_signal_connect(G_OBJECT(window->SaveButton),"clicked",G_CALLBACK(on_logrotate_save),NULL); 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); @@ -517,11 +640,11 @@ void on_journald_save(GtkWidget *self, journald_window *window){ char *storage; int storage_active = gtk_combo_box_get_active(GTK_COMBO_BOX(window->LogStorageCombo)); switch (storage_active){ - case 1: storage="auto"; + case 1: storage="volatile"; break; - case 2: storage="volatile"; + case 2: storage="persistent"; break; - case 3: storage="persistent"; + case 3: storage="auto"; break; case 4: storage="none"; break; @@ -557,9 +680,10 @@ void on_journald_save(GtkWidget *self, journald_window *window){ interval = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->LogIntervalSpin)); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(window->LogIntervalAmountCheck))){ amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(window->LogIntervalAmountSpin)); - yon_config_register(JOURNALD("RateLimitBurst"),"logging",yon_char_from_long(amount)); + if (amount>0) + yon_config_register(JOURNALD("RateLimitBurst"),"logging",yon_char_from_long(amount)); } - if (amount>0) + if (interval>0) yon_config_register(JOURNALD("RateLimitIntervalSec"),"logging",yon_char_from_long(interval)); } else { yon_config_remove_by_key(JOURNALD("RateLimitBurst")); @@ -697,6 +821,59 @@ journald_window *yon_journald_open(GtkWidget *self, main_window *widgets){ g_signal_connect(G_OBJECT(window->LogFreeSpaceCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button),window->LogFreeSpaceCombo); g_signal_connect(G_OBJECT(window->RedirectCombo),"changed",G_CALLBACK(yon_gtk_widget_set_sensitive_from_combo_box_inversed),window->RedirectTTYEntry); + int size=0; + config_str settings = yon_config_get_all_by_key("JOURNALD",&size); + for (int i=0;iLogStorageCombo),1); + else if (!strcmp(settings[i],"persistent")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogStorageCombo),2); + else if (!strcmp(settings[i],"auto")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogStorageCombo),3); + else if (!strcmp(settings[i],"none")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogStorageCombo),4); + + }else if (!strcmp(JOURNALD("Compress"),name)){ + if (!strcmp(settings[i],"yes")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogCompressionCombo),1); + else if (!strcmp(settings[i],"no")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogCompressionCombo),2); + else { + gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogCompressionCombo),3); + char last = settings[i][strlen(settings[i])-1]; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->LogCompressionEntry),atoi(settings[i])); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogCompressionSizeCombo),yon_size_get_int_from_letter(last)); + } + + }else if (!strcmp(JOURNALD("SplitMode"),name)){ + if (!strcmp(settings[i],"uid")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->DivideJournalFilesCombo),1); + else if (!strcmp(settings[i],"none")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->DivideJournalFilesCombo),2); + }else if (!strcmp(JOURNALD("RateLimitIntervalSec"),name)){ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->LogIntervalSpin),atol(settings[i])); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->LogIntervalCheck),1); + }else if (!strcmp(JOURNALD("RateLimitBurst"),name)){ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->LogIntervalAmountSpin),atol(settings[i])); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->LogIntervalAmountCheck),1); + }else if (!strcmp(JOURNALD("SystemMaxUse"),name)){ + char last = settings[i][strlen(settings[i])-1]; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->LogSizeMaxSpin),atol(settings[i])); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogSizeMaxCombo),yon_size_get_int_from_letter(last)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->LogSizeMaxCheck),1); + }else if (!strcmp(JOURNALD("SystemKeepFree"),name)){ + char last = settings[i][strlen(settings[i])-1]; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->LogFreeSpaceSpin),atol(settings[i])); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->LogFreeSpaceCombo),yon_size_get_int_from_letter(last)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->LogFreeSpaceCheck),1); + }else if (!strcmp(JOURNALD("SystemMaxFileSize"),name)){ + char last = settings[i][strlen(settings[i])-1]; + gtk_spin_button_set_value(GTK_SPIN_BUTTON(window->RotationSizeMaxSpin),atol(settings[i])); + gtk_combo_box_set_active(GTK_COMBO_BOX(window->RotationSizeMaxCombo),yon_size_get_int_from_letter(last)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->RotationSizeMaxCheck),1); + }else if (!strcmp(JOURNALD("ForwardToConsole"),name)){ + if (!strcmp(settings[i],"yes")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->RedirectCombo),1); + else if (!strcmp(settings[i],"no")) gtk_combo_box_set_active(GTK_COMBO_BOX(window->RedirectCombo),2); + }else if (!strcmp(JOURNALD("TTYPath"),name)){ + gtk_entry_set_text(GTK_ENTRY(window->RedirectTTYEntry), settings[i]); + }else if (!strcmp(JOURNALD("MaxLevelConsole"),name)){ + gtk_combo_box_set_active(GTK_COMBO_BOX(window->ForwardedTypeCombo),atoi(settings[i])+1); + } + } g_signal_connect(G_OBJECT(window->LogCompressionCombo),"changed",G_CALLBACK(yon_combo_compress_check),window); return window; diff --git a/source/ubl-utils.c b/source/ubl-utils.c index 27d75ac..3ed0e09 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -1187,8 +1187,9 @@ void *yon_config_get_all_by_key(char *key, int *size){ dictionary *dict = NULL; for_dictionaries(dict, (dictionary*)__yon__config__strings){ if (strstr(dict->key,key)) { - if (ret_data) ret_data = yon_char_parsed_append(ret_data,size,dict->key); - else ret_data = yon_char_parsed_new(size,dict->key,NULL); + char *ret_string = yon_char_unite(dict->key,"=",(char*)dict->data,NULL); + if (ret_data) ret_data = yon_char_parsed_append(ret_data,size,ret_string); + else ret_data = yon_char_parsed_new(size,ret_string,NULL); } } return ret_data; diff --git a/ubl-settings-logging-journald.glade b/ubl-settings-logging-journald.glade index 3db6728..43c4722 100644 --- a/ubl-settings-logging-journald.glade +++ b/ubl-settings-logging-journald.glade @@ -272,6 +272,7 @@ Default RAM Drive + Auto None @@ -326,6 +327,7 @@ True + False True adjustment11 diff --git a/ubl-settings-logging-logrotate.glade b/ubl-settings-logging-logrotate.glade index b870edd..d324d06 100644 --- a/ubl-settings-logging-logrotate.glade +++ b/ubl-settings-logging-logrotate.glade @@ -445,9 +445,11 @@ False 0 - Week - Month - Year + Hourly + Daily + Weekly + Monthly + Yearly @@ -461,6 +463,15 @@ True False False + + Monday + Tuesday + Wednesday + Thursday + Friday + Saturday + Sunday + False @@ -621,6 +632,8 @@ 0 Default + Same directory + Separate directory @@ -683,6 +696,9 @@ True False + + root* + False @@ -706,6 +722,9 @@ True False + + root* + False @@ -780,7 +799,9 @@ False 0 - Output errors if log file does not exist + Default + Output errors if log file does not exist* + Do not output errors if log file does not exist @@ -819,6 +840,7 @@ False 0 + Default On Off