diff --git a/.gitignore b/.gitignore index 7434929..6cd8f51 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,8 @@ output.log main.o logger.o help.o +logo.o +sql_test.o test_gtk.o os_info.o +netbenixCMD \ No newline at end of file diff --git a/README.md b/README.md index 3564707..f6edc8f 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,19 @@ A little project of mine to learn C. -Available for: *Linux, (Windows coming soon)* +Available for: *Linux* -Used Libs for Linux: *gtk+3.0* +Used Libs for Linux: *gtk+3.0, libmysqlclient* Version: *0.1.0* ## Features: - A help page (OMG!!!) - A little GTK Test +- Can detect if you're using linux or Windows and tell the Architecture you're running on ## Building: -### Linux -Install packages: make, gtk3, libgtk-3-dev, gcc +Install packages: make, gtk3, libgtk-3-dev, gcc, mysql Clone Repositroy: ```git clone https://github.com/netbenix/netbenixCMD.git``` @@ -22,13 +22,11 @@ Go into the just cloned directory Build with command: ```make``` -### Windows -*Coming soon...* - ## Usage After building use ```./netbenixCMD ``` to start the program ## Arguments - ```--help``` => Displays all arguments - ```--gtk-test``` => Opens the GTK Test Window +- ```--sql-test``` => Makes a test connection to a mysql server - ```--os-info``` => Outputs your OS Information \ No newline at end of file diff --git a/commands/test_gtk.c b/commands/gtk_test.c similarity index 83% rename from commands/test_gtk.c rename to commands/gtk_test.c index 65ef37b..bf2d81d 100644 --- a/commands/test_gtk.c +++ b/commands/gtk_test.c @@ -1,12 +1,13 @@ #include +#include "gtk_test.h" #include "../utils/logger.h" GtkWidget *window; GtkWidget *fixed1; GtkWidget *button1; GtkWidget *label; - GtkWidget *gay_check; + GtkWidget *check; GtkWidget *level; GtkBuilder *builder; @@ -22,7 +23,7 @@ void createGTKTestWindow(){ fixed1 = GTK_WIDGET(gtk_builder_get_object(builder, "fixed1")); button1 = GTK_WIDGET(gtk_builder_get_object(builder, "button1")); label = GTK_WIDGET(gtk_builder_get_object(builder, "label")); - gay_check = GTK_WIDGET(gtk_builder_get_object(builder, "gay_check")); + check = GTK_WIDGET(gtk_builder_get_object(builder, "check")); level = GTK_WIDGET(gtk_builder_get_object(builder, "level")); gtk_widget_show(window); @@ -52,11 +53,11 @@ void on_button1_clicked(GtkButton *b){ void on_gay_check_toggled(GtkToggleButton *t){ if(gtk_toggle_button_get_active(t)){ - gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Oh hey, I'm gay now."); - logger("[GTK] Toggle 'gay_check' changed to toggled."); + gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Toggle checked."); + logger("[GTK] Toggle 'check' changed to toggled."); } else { - gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Well, I'm not longer gay."); - logger("[GTK] Toggle 'gay_check' changed to untoggled."); + gtk_label_set_text(GTK_LABEL(label), (const gchar*) "Toggle unchecked."); + logger("[GTK] Toggle 'check' changed to untoggled."); } } diff --git a/commands/test_gtk.h b/commands/gtk_test.h similarity index 85% rename from commands/test_gtk.h rename to commands/gtk_test.h index 8f18578..4d93c39 100644 --- a/commands/test_gtk.h +++ b/commands/gtk_test.h @@ -1,5 +1,5 @@ -#ifndef _TEST_GTK_H_ -#define _TEST_GTK_H_ +#ifndef _GTK_TEST_H_ +#define _GTK_TEST_H_ #include void createGTKTestWindow(); diff --git a/commands/help.c b/commands/help.c index 20a5eea..c9ee0d9 100644 --- a/commands/help.c +++ b/commands/help.c @@ -1,13 +1,5 @@ -#ifdef _WIN32 || _WIN64 -#include -#include -#endif - -#ifdef linux #include #include -#define OS "LINUX" -#endif #include "help.h" @@ -15,6 +7,7 @@ void outputHelp(){ printf("usage: netbenixCMD [option]\n"); printf("Options:\n"); printf("--help : this help page\n"); - printf("--gtk-test : opens the gtk test ; LINUX ONLY\n"); + printf("--gtk-test : opens the gtk test\n"); + printf("--sql-test : make a test connection to a mysql server\n"); printf("--os-info : shows your os informations\n"); } \ No newline at end of file diff --git a/commands/sql_test.c b/commands/sql_test.c new file mode 100644 index 0000000..015d525 --- /dev/null +++ b/commands/sql_test.c @@ -0,0 +1,43 @@ +#include +#include +#include + +#include +#include "sql_test.h" +#include "../utils/logger.h" + + +void testSQLConnection(){ + + MYSQL *sql; + sql = mysql_init(NULL); + char hostname[200]; + unsigned int port; + char user[200]; + char* password; + char database[200]; + + printf("====== SQL TEST ======\n"); + printf("Hostname: "); + scanf("%s", &hostname); + printf("Port: "); + scanf("%u", &port); + printf("Database: "); + scanf("%s", &database); + printf("Username: "); + scanf("%s", &user); + password = getpass("Password: "); + + if(mysql_real_connect(sql, hostname, user, password, database, 33000, NULL, 0) == NULL){ + fprintf (stderr, "ERROR: mysql_real_connect():" + "%u (%s)\n",mysql_errno (sql), mysql_error (sql)); + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "[ERROR] mysql_read_connect(): %u (%s)\n", mysql_errno(sql), mysql_error(sql)); + logger(buffer); + mysql_close(sql); + } else { + printf("Successfully connected to: %s", hostname); + } + + mysql_close(sql); +} \ No newline at end of file diff --git a/commands/sql_test.h b/commands/sql_test.h new file mode 100644 index 0000000..432758d --- /dev/null +++ b/commands/sql_test.h @@ -0,0 +1,6 @@ +#ifndef _SQL_TEST_H_ +#define _SQL_TEST_H_ + +void testSQLConnection(); + +#endif \ No newline at end of file diff --git a/glade/test_window.glade b/glade/test_window.glade index 977c23a..b536e3c 100644 --- a/glade/test_window.glade +++ b/glade/test_window.glade @@ -54,8 +54,8 @@ - - I'm Gay. + + Toggle 107 24 True diff --git a/gtk_test.o b/gtk_test.o new file mode 100644 index 0000000..7d8265f Binary files /dev/null and b/gtk_test.o differ diff --git a/main.c b/main.c index 4cfc132..3a4e3c1 100644 --- a/main.c +++ b/main.c @@ -1,8 +1,3 @@ -#ifdef _WIN32 || _WIN64 -#include -#endif - -#ifdef linux #include #include #include @@ -10,14 +5,16 @@ #include #include #include -#include "commands/test_gtk.h" -#endif +#include "commands/gtk_test.h" #include "etc/logo.h" #include "utils/logger.h" #include "utils/os_info.h" #include "commands/help.h" +#include "commands/sql_test.h" + + #define VERSION "0.1.0" #define AUTHOR "netbenix" @@ -26,6 +23,7 @@ void exit_app(){ exit(0); } + int main(int argc, char *argv[]){ char buffer[1024]; logger("================================================"); @@ -46,15 +44,14 @@ int main(int argc, char *argv[]){ logger("Showing Help"); outputHelp(); } else if (!strcmp(argv[1], "--gtk-test")){ - #ifdef linux + logger("Stating GTK Test"); createGTKTestWindow(); - #else - printf("[ERROR] gtk-test is linux only.\n"); - logger("[ERROR] gtk-test is linux only."); - #endif } else if (!strcmp(argv[1], "--os-info")){ logger("Showing OS Information"); print_Specs(); + } else if (!strcmp(argv[1], "--sql-test")){ + logger("Starting SQL Test"); + testSQLConnection(); } else { printf("Argument unknown. Please use --help for more information.\n"); snprintf(buffer, sizeof(buffer), "[ERROR] Argument unknown. Given argument: %s", argv[1]); diff --git a/makefile b/makefile index b2545a0..bdb00b1 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,8 @@ CC= gcc ARGS= -export-dynamic -CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -LDLIBS= $(shell pkg-config --libs gtk+-3.0) -OBJ= main.o logo.o logger.o help.o os_info.o test_gtk.o +CFLAGS= $(shell pkg-config --cflags gtk+-3.0) -I/usr/include/mysql +LDLIBS= $(shell pkg-config --libs gtk+-3.0) -L/usr/lib/mysql -lmysqlclient +OBJ= main.o logo.o logger.o help.o os_info.o gtk_test.o sql_test.o netbenixCMD: $(OBJ) $(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS) @@ -16,5 +16,7 @@ help.o: commands/help.c $(CC) $(CFLAGS) -c commands/help.c os_info.o: utils/os_info.c $(CC) $(CFLAGS) -c utils/os_info.c -test_gtk.o: commands/test_gtk.c - $(CC) $(CFLAGS) -c commands/test_gtk.c $(LDLIBS) \ No newline at end of file +gtk_test.o: commands/gtk_test.c + $(CC) $(CFLAGS) -c commands/gtk_test.c +sql_test.o: commands/sql_test.c + $(CC) $(CFLAGS) -c commands/sql_test.c \ No newline at end of file diff --git a/netbenixCMD b/netbenixCMD deleted file mode 100644 index 7541c63..0000000 Binary files a/netbenixCMD and /dev/null differ diff --git a/utils/os_info.c b/utils/os_info.c index 47d5ce1..7c52133 100644 --- a/utils/os_info.c +++ b/utils/os_info.c @@ -1,26 +1,15 @@ -#ifdef _WIN32 || _WIN64 -#include -#endif - -#ifdef linux - -#endif - #include #include #include #include #include + #include "os_info.h" #include "logger.h" char* getOS(){ char *os; os = malloc(sizeof (char) * 20); - - #ifdef _WIN32 || _WIN64 - strcpy(os, "Windows"); - #endif #ifdef linux strcpy(os, "Linux"); #endif