Skip to content

Commit

Permalink
Rajout des utilitaires mp3tohttp et ufw_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudeStabile committed Feb 1, 2023
1 parent 7914867 commit b8a0e63
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Binary file added mp3tohttp
Binary file not shown.
54 changes: 54 additions & 0 deletions mp3tohttp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <microhttpd.h>

int handle_request(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr) {
struct MHD_Response *response;
int ret;

char *input_file = (char*)cls;
FILE *fp = fopen(input_file, "rb");
if (!fp) {
return MHD_NO;
}

fseek(fp, 0, SEEK_END);
long fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);

char *mp3_data = malloc(fsize + 1);
fread(mp3_data, fsize, 1, fp);
fclose(fp);

response = MHD_create_response_from_buffer(fsize, (void*)mp3_data, MHD_RESPMEM_MUST_FREE);
MHD_add_response_header(response, "Content-Type", "audio/mpeg");

ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
MHD_destroy_response(response);

return ret;
}

int main(int argc, char *argv[]) {
struct MHD_Daemon *daemon;
int port;

if (argc != 3) {
printf("Usage: %s <input_file.mp3> <port>\n", argv[0]);
return 1;
}

char *input_file = argv[1];
port = atoi(argv[2]);

daemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, port, NULL, NULL, &handle_request, input_file, MHD_OPTION_END);
if (!daemon) {
return 1;
}

getchar();

MHD_stop_daemon(daemon);
return 0;
}

Binary file added ufw_ip
Binary file not shown.
26 changes: 26 additions & 0 deletions ufw_ip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]) {
if (argc != 2) {
printf("Usage: %s port\n", argv[0]);
return 1;
}

char* port = argv[1];
char line[256];
FILE* logfile = fopen("ufw.log", "r");

while (fgets(line, sizeof(line), logfile)) {
if (strstr(line, port) != NULL) {
char* ip = strstr(line, "SRC=") + 4;
char* end = strstr(ip, " ");
*end = '\0';
printf("%s\n", ip);
}
}

fclose(logfile);
return 0;
}

0 comments on commit b8a0e63

Please sign in to comment.