commit 029c1676e4e147513efa452dca170fcf03ca0c3b Author: Tristan Smith Date: Sun Sep 29 23:07:45 2024 -0400 oh really? diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..86a7721 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# Define the compiler and flags +CC = gcc +CFLAGS = -Wall -Wextra -std=c99 + +# Define the target executable and the source files +TARGET = caur +SRCS = $(wildcard src/*.c) +OBJS = $(SRCS:.c=.o) + +# The default rule: build the target +all: $(TARGET) + +# Link the object files into the target executable +$(TARGET): $(OBJS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) -lcurl + +# Compile the .c files into .o files +src/%.o: src/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +# Clean up the build artifacts +clean: + rm -f $(TARGET) $(OBJS) diff --git a/credentials.json b/credentials.json new file mode 100644 index 0000000..f0ed663 --- /dev/null +++ b/credentials.json @@ -0,0 +1,4 @@ +{ + "creds": [["root", "root"], ["miner", "miner"]] +} + diff --git a/errors.json b/errors.json new file mode 100644 index 0000000..1b4813b --- /dev/null +++ b/errors.json @@ -0,0 +1,16 @@ +{ + "error_keywords": { + "ERROR_TEMP_TOO_HIGH": "Temperature Error", + "ERROR_NETWORK_DISCONNECTED": "probably doesn't exist", + "ERROR_POWER_LOST: power voltage rise or drop": "voltage drop", + "_pic_write_iic failed!": "PIC Error", + "PLL read exceeded wait time": "PLL Error", + "ERROR_SOC_INIT: soc init failed": "SoC failure", + "fail to read 0:1": "eeprom", + "fail to write 0:1": "eeprom", + "bitmain_get_power_status failed": "PSU", + "power voltage can not meet the target": "PSU", + "reg crc error": "black hole", + "ERROR_POWER_LOST: pic check voltage drop": "voltage drop" + } +} diff --git a/failure b/failure new file mode 100755 index 0000000..dd8dd0c Binary files /dev/null and b/failure differ diff --git a/ips.txt b/ips.txt new file mode 100644 index 0000000..387ecfe --- /dev/null +++ b/ips.txt @@ -0,0 +1 @@ +10.0.20.152 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..65476d9 --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +## Antminer error finder + +Checks for specific strings in log files of Antminer machines. Currently works with stock firmware (and barely at that). Expand to Braiins & LuxOS potentially. + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..2e71a9c --- /dev/null +++ b/src/main.c @@ -0,0 +1,108 @@ +// Antminer log viewer with proposed fixes and possible log highlighting +// Currently only 'working' on stock firmware +// TODO: Find endpoint for custom firmware + +#include +#include +#include +#include + +#define MAX_IPS 100 +#define MAX_IP_LENGTH 16 +#define MAX_LOG_LINE_LENGTH 1024 + +// Structure to hold memory +struct MemoryStruct { + char *memory; + size_t size; +}; + +static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { + size_t realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)userp; + + char *ptr = realloc(mem->memory, mem->size + realsize + 1); + if(ptr == NULL) { + fprintf(stderr, "Not enough memory (realloc returned NULL - get rekt)\n"); + return 0; + } + + mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + return realsize; +} + +void read_ips(const char *filename, char ips[][MAX_IP_LENGTH], int *ip_count) { + FILE *file = fopen(filename, "r"); + if(file == NULL) { + fprintf(stderr, "Failed to open IP file %s\n", filename); + exit(EXIT_FAILURE); + } + + char line[MAX_IP_LENGTH]; + while (fgets(line, sizeof(line), file) != NULL && *ip_count < MAX_IPS) { + line[strcspn(line, "\n")] = '\0'; // Remove newline + strncpy(ips[*ip_count], line, MAX_IP_LENGTH); + (*ip_count)++; + } + fclose(file); +} + +void fetch_logs(const char *ip, const char *username, const char *password) { + CURL *curl; + CURLcode res; + struct MemoryStruct chunk; + chunk.memory = malloc(1); + chunk.size = 0; + + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); + + if(curl) { + char url[256]; + snprintf(url, sizeof(url), "http://%s/cgi-bin/log.cgi", ip); + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_USERNAME, username); + curl_easy_setopt(curl, CURLOPT_PASSWORD, password); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); + res = curl_easy_perform(curl); + + if(res != CURLE_OK) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); + } else { + printf("%lu bytes retrieved\n", (unsigned long)chunk.size); + printf("%s\n", chunk.memory); + // TODO: Parse log lines and highlight(?) errors + } + + curl_easy_cleanup(curl); + free(chunk.memory); // I hear this is important! + } + + curl_global_cleanup(); +} + +int main() { + char ips[MAX_IPS][MAX_IP_LENGTH]; + int ip_count = 0; + + printf("Antminer log viewer\n"); + + read_ips("ips.txt", ips, &ip_count); + + for(int i = 0; i < ip_count; i++) { + printf("Fetching logs for IP: %s\n", ips[i]); + fetch_logs(ips[i], "root", "root"); + printf("Logs fetched for IP: %s\n", ips[i]); + printf("----------------------------------------\n"); + } + + printf("All logs fetched successfully!\n"); + + return 0; +} \ No newline at end of file