feat(server): Add Embedded HTTP Server & REST API, Systemd Service Manager, Multi-User Auth, Syslog, Crond, and Server Metrics

This commit is contained in:
subhobhai943 committed 2026-08-17 13:05:44 +05:30
1 parent 2f1f785cee
commit eb71ebfefb
18 files changed
+1091 -41

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
#include <block/block.h>
#define RAMDISK_SIZE (4 * 1024 * 1024) // 4 MB Ramdisk
#define RAMDISK_SIZE (512 * 1024) // 512 KB Ramdisk (1024 sectors)
#define RAMDISK_SECTOR_SIZE 512
void ramdisk_init(void);
+44
View File
@@ -0,0 +1,44 @@
#ifndef _INIT_SERVICE_H
#define _INIT_SERVICE_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define MAX_SERVICES 16
typedef enum {
SERVICE_STATE_STOPPED = 0,
SERVICE_STATE_STARTING,
SERVICE_STATE_RUNNING,
SERVICE_STATE_STOPPING,
SERVICE_STATE_FAILED
} service_state_t;
typedef int (*service_func_t)(void);
typedef struct service_unit {
uint32_t id;
char name[32];
char description[64];
service_state_t state;
bool enabled;
uint32_t pid;
uint64_t start_time;
uint32_t restart_count;
service_func_t start_fn;
service_func_t stop_fn;
bool in_use;
} service_unit_t;
void service_manager_init(void);
int service_register(const char* name, const char* desc, service_func_t start_fn, service_func_t stop_fn, bool enable_at_boot);
int service_start(const char* name);
int service_stop(const char* name);
int service_restart(const char* name);
service_state_t service_get_state(const char* name);
size_t service_get_count(void);
const service_unit_t* service_get_by_index(size_t index);
#endif // _INIT_SERVICE_H
+28
View File
@@ -0,0 +1,28 @@
#ifndef _KERNEL_CRON_H
#define _KERNEL_CRON_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define MAX_CRON_JOBS 16
typedef struct cron_job {
uint32_t id;
char command[128];
uint32_t interval_sec;
uint64_t last_run_tick;
uint32_t run_count;
bool enabled;
bool in_use;
} cron_job_t;
void cron_init(void);
int cron_add_job(const char* command, uint32_t interval_sec);
int cron_remove_job(uint32_t id);
void cron_tick(void);
size_t cron_get_job_count(void);
const cron_job_t* cron_get_job(size_t index);
#endif // _KERNEL_CRON_H
+25
View File
@@ -0,0 +1,25 @@
#ifndef _KERNEL_METRICS_H
#define _KERNEL_METRICS_H
#include <stdint.h>
#include <stddef.h>
typedef struct system_metrics {
uint32_t cpu_user_pct;
uint32_t cpu_system_pct;
uint32_t cpu_idle_pct;
uint64_t mem_total_kb;
uint64_t mem_used_kb;
uint64_t mem_free_kb;
uint64_t net_rx_bytes;
uint64_t net_tx_bytes;
uint64_t net_rx_packets;
uint64_t net_tx_packets;
uint64_t disk_read_sectors;
uint64_t disk_written_sectors;
} system_metrics_t;
void metrics_init(void);
void metrics_sample(system_metrics_t* out);
#endif // _KERNEL_METRICS_H
+39
View File
@@ -0,0 +1,39 @@
#ifndef _KERNEL_SYSLOG_H
#define _KERNEL_SYSLOG_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
#define LOG_KERN (0<<3)
#define LOG_USER (1<<3)
#define LOG_DAEMON (3<<3)
#define LOG_AUTH (4<<3)
#define LOG_SYSLOG (5<<3)
#define SYSLOG_BUFFER_SIZE 128
#define SYSLOG_MSG_MAX 128
typedef struct syslog_entry {
uint64_t timestamp;
uint8_t priority;
char facility_str[12];
char ident[24];
char message[SYSLOG_MSG_MAX];
} syslog_entry_t;
void syslog_init(void);
void syslog_write(int priority, const char* ident, const char* message);
size_t syslog_get_count(void);
const syslog_entry_t* syslog_get_entry(size_t index);
#endif // _KERNEL_SYSLOG_H
+39
View File
@@ -0,0 +1,39 @@
#ifndef _NET_HTTP_H
#define _NET_HTTP_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define HTTP_PORT 80
#define HTTP_MAX_PAYLOAD 2048
typedef struct http_request {
char method[8]; // GET, POST, HEAD
char path[128]; // /index.html, /api/status
char version[16]; // HTTP/1.1
char user_agent[64];
uint32_t content_length;
char body[HTTP_MAX_PAYLOAD];
} http_request_t;
typedef struct http_response {
int status_code; // 200, 404, 500
char content_type[32]; // text/html, application/json, text/plain
char body[HTTP_MAX_PAYLOAD];
size_t body_len;
} http_response_t;
void httpd_init(void);
int httpd_start(uint16_t port);
int httpd_stop(void);
bool httpd_is_running(void);
uint32_t httpd_get_requests_served(void);
// Process a raw HTTP request and generate HTTP response
int httpd_handle_request(const char* raw_request, char* raw_response, size_t max_resp_len);
// Client operations
int http_client_get(const char* url, char* response_buf, size_t max_len);
#endif // _NET_HTTP_H
+34
View File
@@ -0,0 +1,34 @@
#ifndef _SECURITY_AUTH_H
#define _SECURITY_AUTH_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define MAX_USERS 16
typedef struct user_account {
uint32_t uid;
uint32_t gid;
char username[32];
char full_name[64];
char home_dir[64];
char shell[32];
char password_hash[65]; // 64-char SHA256 hex string + null
bool in_use;
} user_account_t;
void auth_init(void);
int auth_add_user(const char* username, const char* password, uint32_t uid, uint32_t gid, const char* home, const char* shell);
bool auth_verify_password(const char* username, const char* password);
int auth_change_password(const char* username, const char* new_password);
const user_account_t* auth_get_user_by_name(const char* username);
const user_account_t* auth_get_user_by_uid(uint32_t uid);
const user_account_t* auth_get_current_user(void);
int auth_set_current_user(const char* username);
size_t auth_get_user_count(void);
const user_account_t* auth_get_user_by_index(size_t index);
#endif // _SECURITY_AUTH_H