oh really?
This commit is contained in:
commit
029c1676e4
7 changed files with 156 additions and 0 deletions
23
Makefile
Normal file
23
Makefile
Normal file
|
@ -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)
|
4
credentials.json
Normal file
4
credentials.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"creds": [["root", "root"], ["miner", "miner"]]
|
||||||
|
}
|
||||||
|
|
16
errors.json
Normal file
16
errors.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
BIN
failure
Executable file
BIN
failure
Executable file
Binary file not shown.
1
ips.txt
Normal file
1
ips.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
10.0.20.152
|
4
readme.md
Normal file
4
readme.md
Normal file
|
@ -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.
|
||||||
|
|
108
src/main.c
Normal file
108
src/main.c
Normal file
|
@ -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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
Loading…
Reference in a new issue