From 029c1676e4e147513efa452dca170fcf03ca0c3b Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Sun, 29 Sep 2024 23:07:45 -0400 Subject: [PATCH] oh really? --- Makefile | 23 ++++++++++ credentials.json | 4 ++ errors.json | 16 +++++++ failure | Bin 0 -> 18488 bytes ips.txt | 1 + readme.md | 4 ++ src/main.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 156 insertions(+) create mode 100644 Makefile create mode 100644 credentials.json create mode 100644 errors.json create mode 100755 failure create mode 100644 ips.txt create mode 100644 readme.md create mode 100644 src/main.c 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 0000000000000000000000000000000000000000..dd8dd0c9581e5eddb555bc71c0fb5e88f9084700 GIT binary patch literal 18488 zcmeHP4|G)3nZF4{Qj{dHpomzf2sWsh1O!BdbwWsZVFRQR|AffLj@Qfj zDOBZs3Vzfszi(29d95tZ={R^~|5PZ8XVsx#>!JnKA%9gU7>;kN+O~L6)uILNSj0V_ zhd^=F;75IG#p)JT+|BxkQ~pJ)C{HeyGE8_P+o||bvy=au57*55@weAjl-=09<-?gP zj{e=V-zy^@ z_6-jFjmT%#DEU9{V1KDYxvL!b1_%D%9rAzFf&ajPf6IY?*MYy^f#2c4Z*btt9qLu> zz~AGL&uIt#DF=SQfzLYd2#2}wvnT3%E;|YNdIx^JL%k}&PiB|1A&9`;yy18! zlO%`jsu7VeA&!)AbW z#z``xVP9t#DuCF1n{{9NWNUI zy+y39Wo?tbrn!Fgx^+$Z0=A;5aao-{A0}#V-tg`X!@Kj{3+c!e<8K`P2*+d8EXHUh zB*BY)#bC7Le`GBZ$)81Epz+X!-^L7P^osXLzR#1-E4lAh!PD5x?>~gd z1}wb1h2WY&3xBz^B{*Z@XIS_l3x9=`_XvT?q;oNsJYtW^lvU+KsfAZ+yanXi zW($uFkxRE*__7?!*d_~KZsFT4yt=m_b*F`wx6DMdZ5DnCXT+x4!vB$l-(}(HzCfkj z9v_FYOO~9fW=!ktGmEo>TF=v^CwMKh3;z*xcFvEmEx*cxJ(Al=ml?_; z&3TGsx|C!FxqO)9Vv_r~{5_KC(vf+D%YRKWT{1HJxqN_Rx=dwubNQPj)1@QR&E-EQ znTDrKCzt<}WV(c8HgWmOB-5oM)6C_&NS;Wths#lt=~9uY;qvE6rb|S|#pPC#>C%v? z;PM8N>5`CPTwY6ZImu@~0x@SL$#e3IX^FGi@i%YPj-MZ=6`j;he`HQY2H%$%lx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^Q|P)s7SY?iVLvT4 z!)mG^R&3c;UgaFH7D}wI$}w0dB^F-g7^-1_UL;~9Y(w9+E&s~dEnqrdai;57@21zU zUXImmcuniq@fOtbN>z-k_L}mQW4Ww&kyurhN6-qhJYu*XIyB#~0R?6+a#$!=gbW+R5DEh-tXn!f`jQ3TR}r%R;rr zgIK^E^h>ICS!0#yZDZWL-5YCXZhu!8MF=#bLW3(I4IO!c4qem;dC5WUb%spl=DpEv z8h8Qk=I4Ps8sR6Z+i2GVQE!K#xBKC%B;lcZqfsvcB@eZajJ+K}A4o0U|RT zHsI<{a8N2JMrvo}ujciF;3#C}ujU68s`)^e@I-l7)144#?oIit`8I`1 zq_K)$*(v-Y^fZ^JWHq0suv7Z0HdgUVnx(Kq$3*$7`9y_kK2epg{8jzGF8!Cu4AuOk zLN%XB{`BZ+_kRE!wTa3<_q-;b+tj=*On9>QpM7Ah{x0dKu-n$)>TyuvcWwUr<-DB2 zWz=w%r2G{15O%EPtLI{cYF=8|+v9&s`m6S5E@>(8He39v{iGH9d+d;j@>la53f2Fg zQ1`aczRdnGIUIeg14{%Sscpb8|CvJ=v< ztoYZUpuVHZSMxdQ|Bk5tFQN{k@>9q0UHDS_DSx%jxvv@|Ql)_0R{1NW|F>ZESM&L4 z=|7nB6g$dKVKJPo{_1)BP>rxxajI;TUrvTIaVq{HkI)P__`8HUx1A)*m*zQM`PKq7lTBp*3F6KEmjD0& literal 0 HcmV?d00001 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