Initial Commit

This commit is contained in:
nc5432 2025-05-28 19:48:23 -04:00
commit fd0856580f
7 changed files with 78 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@ -0,0 +1,15 @@
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
*.code-workspace

0
.secrets Normal file
View File

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Server Controller
This project will primarily be a web API for my main website, allowing it to preview the resource utilization of my server, but it will also function as an admin console for me to manage my self-hosted services from. All services will be able to be launched, shutdown, and monitored through it.

53
ServerController.c Normal file
View File

@ -0,0 +1,53 @@
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <microhttpd.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>
#include <stdlib.h>
#define CONFIG "config.cfg"
#define SECRETS ".secrets"
const int PORT;
void sigintHandler(int signal){
printf("Handled sigint\n");
exit(0);
}
void error(char *msg){
write(0, msg, strlen(msg));
exit(1);
}
void readConfig(){
FILE *file = fopen("config.cfg", "r");
char buf[1024];
while (fgets(buf, 1024, file) != NULL){
printf("Line: \n%s\n", buf);
char *newbuf = calloc(1024, 1);
for (int i = 0; i < 1024; i++){
if (buf[i] == '#') break;
else newbuf[i] = buf[i];
}
printf("Newbuf: %s\n", newbuf);
char buf1[512];
char buf2[512];
if (sscanf(newbuf, "%s %s", buf1, buf2) == 2){
printf("Values: %s %s\n", buf1, buf2);
}
free(newbuf);
}
}
int main(){
signal(SIGINT, sigintHandler);
readConfig();
return 0;
}

3
config.cfg Normal file
View File

@ -0,0 +1,3 @@
port 8888
# Minecraft is a cool game yep
program minecraft # still cool

BIN
controller Executable file

Binary file not shown.

5
makefile Normal file
View File

@ -0,0 +1,5 @@
controller:
gcc -Wall ServerController.c -o controller -lmicrohttpd -lyaml
clean:
rm controller