This commit is contained in:
netbenix 2021-05-08 17:14:40 +02:00
parent 9caca5a4fb
commit f55aa94d84
10 changed files with 330 additions and 374 deletions

38
.gitignore vendored
View file

@ -1,20 +1,20 @@
.vscode
glade/test_window.glade~
netbenixCMD
output.log
main.o
logger.o
help.o
logo.o
sql_test.o
gtk_test.o
sys_info.o
show_dir.o
change_dir.o
update_check.o
man.o
<<<<<<< HEAD
math.o
=======
>>>>>>> f1cf6269f94065bfb8498dd7ef06bfbb61442b80
.vscode
glade/test_window.glade~
netbenixCMD
output.log
main.o
logger.o
help.o
logo.o
sql_test.o
gtk_test.o
sys_info.o
show_dir.o
change_dir.o
update_check.o
man.o
<<<<<<< HEAD
math.o
=======
>>>>>>> f1cf6269f94065bfb8498dd7ef06bfbb61442b80
your-reality.o

113
README.md
View file

@ -1,47 +1,66 @@
# **netbenixCMD**
A little project of mine to learn C.
Available for: *Linux*
Tested on: *Ubuntu, Debian, Arch*
Used libs for Linux: *gtk+3.0, libmysqlclient*
Version: *0.2.4*
## Features:
- A help page (OMG!!!)
- A little GTK Test
- Can detect if you're using linux or not and tell the Architecture you're running on
- Can give you a bit of information about your CPU (but just a little bit)
- Checks your client version on start with the server
## Building:
Install packages:
- Ubuntu: ```sudo apt-get install make gcc git libgtk-3-dev libmysqlclient-dev```
- Debian: ```sudo apt-get install make gcc git libgtk-3-dev libmariadbclient-dev libmariadb-dev-compat```
- Arch: ```sudo pacman -S make gcc git gtk3 mariadb-libs pkgconf```
Clone repository: ```git clone https://github.com/netbenix/netbenixCMD.git```
Go into the cloned directory: ```cd netbenixCMD```
Build program: ```make```
## Usage
After building use ```./netbenixCMD``` to start the program
If you want to use the testing arguments use ```./netbenixCMD <argument>```
## Arguments
- ```--help``` => Displays all arguments
- ```--gtk-test``` => Opens the GTK Test Window
- ```--sql-test``` => Makes a test connection to a mysql server
- ```--sys-info``` => Gives you information about your system
- ```--no-version-check``` => Skips the client version check
- ```--dev-mode``` => Starts the program in developer mode (right now it just skips version check)
## Known Bugs
- ```sql-test``` sha-256 passwords not working on Debian
# netbenixCMD
A little project of mine to learn C.
Available for: *Linux*
Tested on: *Ubuntu, Debian, Arch*
Used libs for Linux: *gtk+3.0, libmysqlclient*
Version: *0.2.4*
## Features:
- A help page (OMG!!!)
- A little GTK Test
- Can detect if you're using linux or not and tell the Architecture you're
running on
- Can give you a bit of information about your CPU (but just a little bit)
- Checks your client version on start with the server
## Building:
Install packages:
- Ubuntu: `sudo apt-get install make gcc git libgtk-3-dev libmysqlclient-dev`
- Debian: `sudo apt-get install make gcc git libgtk-3-dev libmariadbclient-dev
libmariadb-dev-compat`
- Arch: `sudo pacman -S make gcc git gtk3 mariadb-libs pkgconf`
Clone repository: `git clone https://github.com/netbenix/netbenixCMD.git`
Go into the cloned directory: `cd netbenixCMD`
Build program: `make`
## Usage
After building use `./netbenixCMD` to start the program
If you want to use the testing arguments use `./netbenixCMD <argument>`
## Arguments
- `--help` =\> Displays all arguments
- `--gtk-test` =\> Opens the GTK Test Window
- `--sql-test` =\> Makes a test connection to a mysql server
- `--sys-info` =\> Gives you information about your system
- `--no-version-check` =\> Skips the client version check
- `--dev-mode` =\> Starts the program in developer mode (right now it just
skips version check)
## Known Bugs
- `sql-test` sha-256 passwords not working on Debian

View file

@ -26,7 +26,7 @@ void showDirectory(char *arg[]){
DIR *d;
struct dirent *dir;
char path[PATH_MAX];
;
d = opendir(arg[1]); //Try to open directory
if(d == NULL){ //Check if directory exists
printf("Folder not found.\n");

View file

@ -1,4 +1,3 @@
<<<<<<< HEAD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -47,52 +46,4 @@ void showManEntry(char *arg[]){
} else {
printf("Entry not found.\n");
}
=======
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Color Codes:
// Reset: \033[0m
// Red: \033[0;31m
// Green: \033[0;32m
// Yellow: \033[0;33m
// Blue: \033[0;34m
// Magenta: \033[0;35m
// Cyan: \033[0;36m
// BoldRed: \033[1;31m
// BoldGreen: \033[1;32m
// BoldYellow: \033[1;33m
// BoldBlue: \033[1;34m
// BoldMagenta: \033[1;35m
// BoldCyan: \033[1;36m
//Main function to start man is at the bottom
//MAN ENTRIES
//LS
void manEntry_ls(){
printf("\033[0;33m##################\033[0m\n");
printf("\033[0;33m# Manual of \033[0;36m'ls' \033[0;33m#\033[0m\n");
printf("\033[0;33m##################\033[0m\n\n");
printf("\033[0;33mNAME\033[0m\n");
printf("\t\033[0;36mls - list directory contents\033[0m\n\n");
printf("\033[0;33mUSAGE\033[0m\n");
printf("\t\033[0;36mls \033[0;35m[DIRECTORY]\033[0m\n\n");
printf("\033[0;33mDESCRIPTION\033[0m\n");
printf("\t\033[0;36mList files and directorys in the given directory. Sorts entries alphabetically.\033[0m\n\n");
}
//MAIN FUNCTION
void showManEntry(char *arg[]){
if(!strcmp(arg[1], "man")){
printf("Coming soon.\n");
} else if(!strcmp(arg[1], "ls")){
manEntry_ls();
} else {
printf("Entry not found.\n");
}
>>>>>>> f1cf6269f94065bfb8498dd7ef06bfbb61442b80
}

View file

@ -1,24 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../utils/logger.h"
#include "math.h"
double Add(double x, double y){
return(x + y);
}
double Sub(double x, double y){
return(x - y);
}
double Mul(double x, double y){
return(x * y);
}
double Div(double x, double y){
if (y == 0.0)
return 0.0;
else
return(x / y);
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../utils/logger.h"
#include "math.h"
double Add(double x, double y){
return(x + y);
}
double Sub(double x, double y){
return(x - y);
}
double Mul(double x, double y){
return(x * y);
}
double Div(double x, double y){
if (y == 0.0)
return 0.0;
else
return(x / y);
}

View file

@ -1,9 +1,9 @@
#ifndef _MATH_H_
#define _MATH_H_
double Add(double x, double y);
double Sub(double x, double y);
double Mul(double x, double y);
double Div(double x, double y);
#ifndef _MATH_H_
#define _MATH_H_
double Add(double x, double y);
double Sub(double x, double y);
double Mul(double x, double y);
double Div(double x, double y);
#endif

363
main.c
View file

@ -1,184 +1,179 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <gdk/gdk.h>
#include <gdk/gdkconfig.h>
#include <gtk/gtk.h>
#include <unistd.h>
#include <linux/limits.h>
#include "commands/help.h"
#include "commands/show_dir.h"
#include "commands/change_dir.h"
#include "utils/gtk_test.h"
#include "utils/sql_test.h"
#include "etc/logo.h"
#include "etc/man.h"
<<<<<<< HEAD
#include "etc/math.h"
=======
>>>>>>> f1cf6269f94065bfb8498dd7ef06bfbb61442b80
#include "etc/your-reality.h"
#include "utils/logger.h"
#include "utils/sys_info.h"
#include "utils/update_check.h"
#define VERSION "0.2.5"
bool VER_CHECK_ON_START = true;
bool DEV_MODE = false;
bool FUN_CONTENT = false;
// Color Codes:
// Reset: \033[0m
// Red: \033[0;31m
// Green: \033[0;32m
// Yellow: \033[0;33m
// Blue: \033[0;34m
// Magenta: \033[0;35m
// Cyan: \033[0;36m
// BoldRed: \033[1;31m
// BoldGreen: \033[1;32m
// BoldYellow: \033[1;33m
// BoldBlue: \033[1;34m
// BoldMagenta: \033[1;35m
// BoldCyan: \033[1;36m
//Handles the commands
int commandHandler(char *cmd){
char *token = strtok(cmd, " ");
int argc = 1;
char *arg[10];
int i = 0;
while( token != NULL ){
arg[i] = token;
token = strtok(NULL, " ");
if(token != NULL){
i++;
argc++;
}
}
char *p = arg[i];
p[strlen(p)-1] = 0;
arg[i] = p;
//Start to compare the command
if(!strcmp(arg[0], "help")){
printf("\033[1;34mcd \033[0;35m[dir]\033[0m : change directory\n");
printf("\033[1;34mls \033[0;35m[dir]\033[0m : show contents of directory\n");
printf("\033[1;34mhelp\033[0m : this help list\n");
printf("\033[1;34mman \033[0;35m[cmd]\033[0m : manual for the commands\n");
printf("\033[1;34mversion\033[0m : shows the version\n");
printf("\033[1;34mexit\033[0m : exit the program\n");
return 0;
} else if(!strcmp(arg[0], "version")){
printf("netbenixCMD (Version: \033[1;34m%s\033[0m)\n", VERSION);
printf("Author: \033[1;34m%s\033[0m\n", "netbenix");
printf("Github: \033[1;34mhttps://github.com/netbenix/netbenixCMD\033[0m\n");
logger("Showing program version.");
return 0;
} else if(!strcmp(arg[0], "exit")){
return 1;
} else if(!strcmp(arg[0], "ls")){
showDirectory(arg);
return 0;
} else if(!strcmp(arg[0], "cd")){
changeCurrentWorkDir(arg);
return 0;
} else if(!strcmp(arg[0], "man")){
showManEntry(arg);
return 0;
} else if(!strcmp(arg[0], "rainbow") && FUN_CONTENT){
while(1){
printf("\033[0;31m#####");
printf("\033[0;32m#####");
printf("\033[0;33m#####");
printf("\033[0;34m#####");
printf("\033[0;35m#####");
}
} else if(!strcmp(arg[0], "your-reality") && FUN_CONTENT){
yourReality();
} else {
printf("Unknown command. Please use 'help' for more information.\n");
logger("User entered unknown command.");
return 0;
}
}
//Action starts here
int main(int argc, char *argv[]){
char buffer[1024];
extern char loggerDirPath[PATH_MAX];
realpath("." , loggerDirPath);
logger("================================================");
snprintf(buffer, sizeof(buffer), "Starting netbenixCMD (Version: %s)", VERSION);
logger(buffer);
log_Specs(); //Log system specs
showLogo(); //Show the logo
logger("Logo Displayed.");
if(argc > 2){
printf("Too many arguments. Please use --help for more information.\n");
snprintf(buffer, sizeof(buffer), "[ERROR] Too many arguments. Argument count: %i", argc-1);
logger(buffer);
}
//Check the startup args
if(argc == 2){
if(!strcmp(argv[1], "--help")){
logger("Showing Help.");
outputHelp();
exit(0);
} else if (!strcmp(argv[1], "--gtk-test")){
logger("Stating GTK Test.");
createGTKTestWindow();
exit(0);
} else if (!strcmp(argv[1], "--sys-info")){
logger("Showing System Information.");
print_Specs();
exit(0);
} else if (!strcmp(argv[1], "--sql-test")){
logger("Starting SQL Test.");
testSQLConnection();
exit(0);
} else if (!strcmp(argv[1], "--no-version-check")){
VER_CHECK_ON_START = false;
logger("[INFO] Argument 'no-version-check' used.");
} else if (!strcmp(argv[1], "--dev-mode")){
VER_CHECK_ON_START = false;
DEV_MODE = true;
logger("[INFO] Starting in developer mode.");
} else if (!strcmp(argv[1], "--time-for-fun")){
FUN_CONTENT = true;
logger("[WARNING] It's time... TO PARTYY.");
} else {
printf("Argument unknown. Please use --help for more information.\n");
snprintf(buffer, sizeof(buffer), "[ERROR] Argument unknown. Given argument: %s", argv[1]);
logger(buffer);
exit(0);
}
}
if(VER_CHECK_ON_START){checkForUpdate(VERSION);} //Check for newer version of client
//If no startup arg is given, start command handler
int exit = 0;
char cmd[128];
logger("Starting Command Handler.");
while (!exit){
char cwp[255];
printf("\033[0;32m%s> \033[0m", getcwd(cwp, 255));
fgets(cmd, 128, stdin);
exit = commandHandler(cmd);
}
logger("Exiting Command Handler.");
printf("\n");
logger("Exiting.");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <gdk/gdk.h>
#include <gdk/gdkconfig.h>
#include <gtk/gtk.h>
#include <unistd.h>
#include <linux/limits.h>
#include "commands/help.h"
#include "commands/show_dir.h"
#include "commands/change_dir.h"
#include "utils/gtk_test.h"
#include "utils/sql_test.h"
#include "etc/logo.h"
#include "etc/man.h"
#include "etc/math.h"
#include "etc/your-reality.h"
#include "utils/logger.h"
#include "utils/sys_info.h"
#include "utils/update_check.h"
#define VERSION "0.2.5"
bool VER_CHECK_ON_START = true;
bool DEV_MODE = false;
bool FUN_CONTENT = false;
// Color Codes:
// Reset: \033[0m
// Red: \033[0;31m
// Green: \033[0;32m
// Yellow: \033[0;33m
// Blue: \033[0;34m
// Magenta: \033[0;35m
// Cyan: \033[0;36m
// BoldRed: \033[1;31m
// BoldGreen: \033[1;32m
// BoldYellow: \033[1;33m
// BoldBlue: \033[1;34m
// BoldMagenta: \033[1;35m
// BoldCyan: \033[1;36m
//Handles the commands
int commandHandler(char *cmd){
char *token = strtok(cmd, " ");
int argc = 1;
char *arg[10];
int i = 0;
while( token != NULL ){
arg[i] = token;
token = strtok(NULL, " ");
if(token != NULL){
i++;
argc++;
}
}
char *p = arg[i];
p[strlen(p)-1] = 0;
arg[i] = p;
//Start to compare the command
if(!strcmp(arg[0], "help")){
printf("\033[1;34mcd \033[0;35m[dir]\033[0m : change directory\n");
printf("\033[1;34mls \033[0;35m[dir]\033[0m : show contents of directory\n");
printf("\033[1;34mhelp\033[0m : this help list\n");
printf("\033[1;34mman \033[0;35m[cmd]\033[0m : manual for the commands\n");
printf("\033[1;34mversion\033[0m : shows the version\n");
printf("\033[1;34mexit\033[0m : exit the program\n");
return 0;
} else if(!strcmp(arg[0], "version")){
printf("netbenixCMD (Version: \033[1;34m%s\033[0m)\n", VERSION);
printf("Author: \033[1;34m%s\033[0m\n", "netbenix");
printf("Github: \033[1;34mhttps://github.com/netbenix/netbenixCMD\033[0m\n");
logger("Showing program version.");
return 0;
} else if(!strcmp(arg[0], "exit")){
return 1;
} else if(!strcmp(arg[0], "ls")){
showDirectory(arg);
return 0;
} else if(!strcmp(arg[0], "cd")){
changeCurrentWorkDir(arg);
return 0;
} else if(!strcmp(arg[0], "man")){
showManEntry(arg);
return 0;
} else if(!strcmp(arg[0], "rainbow") && FUN_CONTENT){
while(1){
printf("\033[0;31m#####");
printf("\033[0;32m#####");
printf("\033[0;33m#####");
printf("\033[0;34m#####");
printf("\033[0;35m#####");
}
} else if(!strcmp(arg[0], "your-reality") && FUN_CONTENT){
yourReality();
} else {
printf("Unknown command. Please use 'help' for more information.\n");
logger("User entered unknown command.");
return 0;
}
}
//Action starts here
int main(int argc, char *argv[]){
char buffer[1024];
extern char loggerDirPath[PATH_MAX];
realpath("." , loggerDirPath);
logger("================================================");
snprintf(buffer, sizeof(buffer), "Starting netbenixCMD (Version: %s)", VERSION);
logger(buffer);
log_Specs(); //Log system specs
showLogo(); //Show the logo
logger("Logo Displayed.");
if(argc > 2){
printf("Too many arguments. Please use --help for more information.\n");
snprintf(buffer, sizeof(buffer), "[ERROR] Too many arguments. Argument count: %i", argc-1);
logger(buffer);
}
//Check the startup args
if(argc == 2){
if(!strcmp(argv[1], "--help")){
logger("Showing Help.");
outputHelp();
exit(0);
} else if (!strcmp(argv[1], "--gtk-test")){
logger("Stating GTK Test.");
createGTKTestWindow();
exit(0);
} else if (!strcmp(argv[1], "--sys-info")){
logger("Showing System Information.");
print_Specs();
exit(0);
} else if (!strcmp(argv[1], "--sql-test")){
logger("Starting SQL Test.");
testSQLConnection();
exit(0);
} else if (!strcmp(argv[1], "--no-version-check")){
VER_CHECK_ON_START = false;
logger("[INFO] Argument 'no-version-check' used.");
} else if (!strcmp(argv[1], "--dev-mode")){
VER_CHECK_ON_START = false;
DEV_MODE = true;
logger("[INFO] Starting in developer mode.");
} else if (!strcmp(argv[1], "--time-for-fun")){
FUN_CONTENT = true;
logger("[WARNING] It's time... TO PARTYY.");
} else {
printf("Argument unknown. Please use --help for more information.\n");
snprintf(buffer, sizeof(buffer), "[ERROR] Argument unknown. Given argument: %s", argv[1]);
logger(buffer);
exit(0);
}
}
if(VER_CHECK_ON_START){checkForUpdate(VERSION);} //Check for newer version of client
//If no startup arg is given, start command handler
int exit = 0;
char cmd[128];
logger("Starting Command Handler.");
while (!exit){
char cwp[255];
printf("\033[0;32m%s> \033[0m", getcwd(cwp, 255));
fgets(cmd, 128, stdin);
exit = commandHandler(cmd);
}
logger("Exiting Command Handler.");
printf("\n");
logger("Exiting.");
return 0;
}

View file

@ -1,41 +1,33 @@
CC= gcc
ARGS= -export-dynamic -ansi -std=gnu99
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
<<<<<<< HEAD
OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o man.o your-reality.o math.o
=======
OBJ= main.o logo.o logger.o help.o sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o man.o your-reality.o
>>>>>>> f1cf6269f94065bfb8498dd7ef06bfbb61442b80
netbenixCMD: $(OBJ)
$(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS)
main.o: main.c
$(CC) $(CFLAGS) -c main.c
logo.o: etc/logo.c
$(CC) $(CFLAGS) -c etc/logo.c
logger.o: utils/logger.c
$(CC) $(CFLAGS) -c utils/logger.c
help.o: commands/help.c
$(CC) $(CFLAGS) -c commands/help.c
sys_info.o: utils/sys_info.c
$(CC) $(CFLAGS) $(ARGS) -c utils/sys_info.c
gtk_test.o: utils/gtk_test.c
$(CC) $(CFLAGS) -c utils/gtk_test.c
sql_test.o: utils/sql_test.c
$(CC) $(CFLAGS) -c utils/sql_test.c
show_dir.o: commands/show_dir.c
$(CC) $(CFLAGS) -c commands/show_dir.c
change_dir.o: commands/change_dir.c
$(CC) $(CFLAGS) -c commands/change_dir.c
update_check.o: utils/update_check.c
$(CC) $(CFLAGS) -c utils/update_check.c
man.o: etc/man.c
$(CC) $(CFLAGS) -c etc/man.c
<<<<<<< HEAD
math.o: etc/math.c
$(CC) $(CFLAGS) -c etc/math.c
=======
>>>>>>> f1cf6269f94065bfb8498dd7ef06bfbb61442b80
your-reality.o: etc/your-reality.c
CC= gcc
ARGS= -export-dynamic -ansi -std=gnu99
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 sys_info.o gtk_test.o sql_test.o show_dir.o change_dir.o update_check.o man.o your-reality.o math.o
netbenixCMD: $(OBJ)
$(CC) $(CFLAGS) $(ARGS) -o netbenixCMD $(OBJ) $(LDLIBS)
main.o: main.c
$(CC) $(CFLAGS) -c main.c
logo.o: etc/logo.c
$(CC) $(CFLAGS) -c etc/logo.c
logger.o: utils/logger.c
$(CC) $(CFLAGS) -c utils/logger.c
help.o: commands/help.c
$(CC) $(CFLAGS) -c commands/help.c
sys_info.o: utils/sys_info.c
$(CC) $(CFLAGS) $(ARGS) -c utils/sys_info.c
gtk_test.o: utils/gtk_test.c
$(CC) $(CFLAGS) -c utils/gtk_test.c
sql_test.o: utils/sql_test.c
$(CC) $(CFLAGS) -c utils/sql_test.c
show_dir.o: commands/show_dir.c
$(CC) $(CFLAGS) -c commands/show_dir.c
change_dir.o: commands/change_dir.c
$(CC) $(CFLAGS) -c commands/change_dir.c
update_check.o: utils/update_check.c
$(CC) $(CFLAGS) -c utils/update_check.c
man.o: etc/man.c
$(CC) $(CFLAGS) -c etc/man.c
math.o: etc/math.c
$(CC) $(CFLAGS) -c etc/math.c
your-reality.o: etc/your-reality.c
$(CC) $(CFLAGS) -c etc/your-reality.c

View file

@ -5,7 +5,7 @@
#include "update_check.h"
#include "logger.h"
#define SERVER_IP "127.0.0.1"
#define DEFAULT_IP "192.168.0.32"
int checkForUpdate(char ver[10]){
int sock;
@ -19,7 +19,7 @@ int checkForUpdate(char ver[10]){
logger("Error while creating socket");
}
server.sin_addr.s_addr = inet_addr(SERVER_IP); //Set the IP address of the server
server.sin_addr.s_addr = inet_addr(DEFAULT_IP); //Set the IP address of the server
server.sin_family = AF_INET;
server.sin_port = htons( 34000 ); //Set the server port

View file

@ -2,5 +2,4 @@
#define _UPDATE_CHECK_H_
int checkForUpdate(char ver[10]);
#endif