diff --git a/cli/Makefile b/cli/Makefile index 6c115c4..22c1965 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -34,8 +34,6 @@ install: all @# Uninstaller @install -v -o root -g root -m 555 uninstall.sh /opt/gawake/ # src destination @install -v -o root -g root -m 644 gawake /etc/cron.d/ # src destination - @# Folders: /var/gawake for the database; /var/gawake/logs for logs - @mkdir -p -m 664 /var/gawake/logs/ @echo "Adding Gawake user" -@useradd -M gawake @echo "Gawake installed successfully!" diff --git a/cli/install.sh b/cli/install.sh index d0d1fe0..afd7b60 100755 --- a/cli/install.sh +++ b/cli/install.sh @@ -19,10 +19,6 @@ echo "Installing the cron service to /etc/cron.d" install -v -o root -g root -m 644 gawake /etc/cron.d/ # src destination err_counter=$(($? + $err_counter)) -# Folders: /var/gawake for the database; /var/gawake/logs for logs -mkdir -p -m 664 /var/gawake/logs/ -err_counter=$(($? + $err_counter)) - # Adding Gawake user useradd -M gawake diff --git a/cli/src/cron_toff.c b/cli/src/cron_toff.c index 69209ab..926abd7 100644 --- a/cli/src/cron_toff.c +++ b/cli/src/cron_toff.c @@ -21,13 +21,17 @@ #include #include #include +#include #include "include/gawake.h" #include "include/get_time.h" #include "include/wday.h" +// Apdend with ">> path/turn_off.log 2>&1" +#define LOGS_OUTPUT " >> " LOGS "turn_off.log 2>&1" + int main (void) { - int rc, now, db_time = 1, id_match = -1, alloc = 192, cmd_stat = 0, gawake_stat = 0; + int rc, now, db_time = 1, id_match = -1, alloc = 230, cmd_stat = 0, gawake_stat = 0; struct tm *timeinfo; // Default structure, see documentation struct sqlite3_stmt *stmt; @@ -75,7 +79,7 @@ int main (void) { // DO NOTHING IF GAWAKE IS DISABLED if (gawake_stat == 0) { - fprintf(stdout, "Gawake is disabled, exiting..."); + fprintf(stdout, "Gawake is disabled, exiting...\n"); return EXIT_SUCCESS; } @@ -193,9 +197,10 @@ int main (void) { if (stat != 0) fprintf(stderr, "[!] >>>>>>>>> Command(set by user) exited with error\n"); } - snprintf(rtcwake_cmd, alloc, "rtcwake --date %s%s %s -m %s", date, time, options, mode); + snprintf(rtcwake_cmd, alloc, "sudo rtcwake --date %s%s %s -m %s", date, time, options, mode); fprintf(stdout, "Running rtcwake: %s\n", rtcwake_cmd); - system(rtcwake_cmd); + strcat(rtcwake_cmd, LOGS_OUTPUT); // Sending rtcwake output to the log + stat = system(rtcwake_cmd); if (stat != 0) fprintf(stderr, "[!] >>>>>>>>> rtcwake failed scheduling\n"); return EXIT_SUCCESS; diff --git a/cli/src/db_checker.c b/cli/src/db_checker.c index a629447..1741ad8 100644 --- a/cli/src/db_checker.c +++ b/cli/src/db_checker.c @@ -75,7 +75,7 @@ int main(void) { "VALUES ('Example', '10:00:00', 0, 0, 0, 0, 0, 0, 0);"\ "INSERT INTO rules_turnoff (rule_name, time, sun, mon, tue, wed, thu, fri, sat, command, mode)"\ "VALUES ('Example', '11:30:00', 0, 0, 0, 0, 0, 0, 0, 'dnf update -y', 'mem');"\ - "INSERT INTO config (options, status, version, commands, localtime, def_mode, boot_time) VALUES ('-a', 1, '" VERSION "', 0, 1, 'off', 300);"; + "INSERT INTO config (options, status, version, commands, localtime, def_mode, boot_time) VALUES ('-a -v', 1, '" VERSION "', 0, 1, 'off', 300);"; printf("Opening database...\n"); // If the database doesn't exist, create and configure it @@ -88,8 +88,11 @@ int main(void) { struct stat dir; if (stat(DIR, &dir) == -1) { // Directory doesn't exist, creating it - if (mkdir(DIR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) == -1) + if (mkdir(DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) return EXIT_FAILURE; + + // Creating logs directory + mkdir(LOGS, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); } printf("[2/5] Creating empty file for the database.\n"); @@ -102,16 +105,11 @@ int main(void) { // Redundancy printf("[3/5] Setting directory and file permissions.\n"); - if (chown(DIR, 0, 0) == -1 - || chown(PATH, 0, 0) == -1 - || chmod(DIR, 0664) == -1 - || chmod(PATH, 0660) == -1 - ) { + if (chown(DIR, 0, 0) == -1 || chown(PATH, 0, 0) == -1) { fprintf(stderr, ANSI_COLOR_RED "ERROR: %s\n" ANSI_COLOR_RESET, strerror(errno)); return EXIT_FAILURE; } - printf("[4/5] Creating database.\n"); // Try to open it rc = sqlite3_open_v2(PATH, &db, SQLITE_OPEN_READWRITE, NULL); diff --git a/cli/src/include/gawake.h b/cli/src/include/gawake.h index a285536..0e59967 100644 --- a/cli/src/include/gawake.h +++ b/cli/src/include/gawake.h @@ -15,9 +15,10 @@ */ #define DIR "/var/gawake/" #define PATH DIR "gawake-cli.db" +#define LOGS DIR "logs/" -#define VERSION "3.0" // Gawake version -#define CMD_LEN 129 // Allowed length for commands +#define VERSION "3.0.1" // Gawake version +#define CMD_LEN 129 // Allowed length for commands #endif /* GAWAKE_H_ */ diff --git a/cli/src/main.c b/cli/src/main.c index d8482c1..4b160f0 100644 --- a/cli/src/main.c +++ b/cli/src/main.c @@ -16,12 +16,14 @@ * along with this program. If not, see */ -/* - * Possible implementations: - * Updater function - * Run commands as other user besides root - * Very input when receiveing rtwake options/arguments (on function config) - * Allow changing boot_time +/*! TODO: + * (Possible implementations) + * @Gawake updater function + * @Run commands as other users, besides root + * @Verify user input when receiveing rtwake options/arguments (on function config) + * @Allow changing boot_time + * @Fix output log + * @Add manual schedule output to logs */ #include @@ -561,7 +563,7 @@ int config(sqlite3 **db) { // Computer time struct tm *timeinfo; get_time(&timeinfo); - printf("Time information:\n%-35s %d-%02d-%02d %02d:%d:%02d\n", + printf("Time information:\n%-35s %d-%02d-%02d %02d:%02d:%02d\n", "Current local time and date:", timeinfo -> tm_year + 1900, timeinfo -> tm_mon + 1, timeinfo -> tm_mday, timeinfo -> tm_hour, timeinfo -> tm_min, timeinfo -> tm_sec);