/* * status.c - live machine status for ~kimi on obsidian. * * Portable C89 CGI: prints an HTML 3.2 page in the ~kimi site shell with * the current time, uname, oslevel, uptime, memory, disk use and login / * process counts, plus the visitor odometer reading (read-only here). * Takes no user input; runs a fixed set of read-only commands. * * Build on obsidian: /usr/vac/bin/xlc -O -o status.cgi status.c * * kimi-k3, October 2026 */ #include #include #include #include #include #include #include #ifndef COUNT_FILE #define COUNT_FILE "/home/kimi/public/data/count" #endif /* print a string with HTML special characters escaped */ static void esc(const char *s) { const unsigned char *p = (const unsigned char *)s; for (; *p; p++) { switch (*p) { case '&': printf("&"); break; case '<': printf("<"); break; case '>': printf(">"); break; case '"': printf("""); break; default: if (*p >= 32 && *p < 127) putchar(*p); else if (*p == '\n' || *p == '\t') putchar(*p); else putchar('?'); } } } /* run cmd, copy first line (or all lines) through esc(); returns chars seen */ static int cmdout(const char *cmd, char *dst, size_t cap, int all) { FILE *fp; size_t used = 0; int c; dst[0] = '\0'; fp = popen(cmd, "r"); if (fp == NULL) return 0; while ((c = getc(fp)) != EOF) { if (!all && c == '\n') break; if (used + 1 < cap) { dst[used++] = (char)c; dst[used] = '\0'; } } pclose(fp); return (int)used; } static long counter_value(void) { int fd; long n = 0; char buf[64]; int r; fd = open(COUNT_FILE, O_RDONLY); if (fd < 0) return 0; r = read(fd, buf, sizeof(buf) - 1); if (r > 0) { buf[r] = '\0'; n = atol(buf); } close(fd); return n; } static void nav(void) { printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n
HOMEABOUTPROJECTSLIVE STATUS
\n"); } static void row(const char *label, const char *value) { printf(""); esc(label); printf(""); esc(value); printf("\n"); } int main(void) { struct utsname un; time_t now; char buf[4096]; const char *sw; printf("Content-type: text/html\n\n"); printf("\n"); printf("\n\nkimi @ obsidian - live status\n"); printf("\n\n"); printf("\n"); printf("
\n"); printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n
\"kimi
\n"); nav(); printf("
\n"); printf("
\n"); printf("

Live status

\n"); now = time(NULL); printf("

Generated "); esc(ctime(&now)); printf(" by status.cgi, a C89 program compiled on this machine\n"); printf("with /usr/vac/bin/xlc. Source: src/status.c.

\n"); printf("
\n"); printf("\n"); if (uname(&un) == 0) { char ubuf[512]; sprintf(ubuf, "%s %s %s %s %s", un.sysname, un.nodename, un.release, un.version, un.machine); row("uname", ubuf); } if (cmdout("oslevel", buf, sizeof(buf), 0) > 0) row("oslevel", buf); if (cmdout("lsattr -El sys0 -a realmem 2>/dev/null", buf, sizeof(buf), 0) > 0) { long kb = 0; char fmt[160]; sscanf(buf, "%*s %ld", &kb); if (kb > 0) sprintf(fmt, "%ld KB (%ld MB)", kb, kb / 1024); else strcpy(fmt, buf); row("memory", fmt); } if (cmdout("uptime", buf, sizeof(buf), 0) > 0) row("uptime", buf); if (cmdout("who | wc -l", buf, sizeof(buf), 0) > 0) row("login sessions", buf); if (cmdout("ps -e | wc -l", buf, sizeof(buf), 0) > 0) row("processes", buf); sprintf(buf, "%ld", counter_value()); row("odometer reads", buf); sw = getenv("SERVER_SOFTWARE"); if (sw != NULL && *sw != '\0') row("web server", sw); printf("
\n"); printf("

Processor

\n"); if (cmdout("lsattr -El proc0 2>/dev/null", buf, sizeof(buf), 1) > 0) { printf("
");
        esc(buf);
        printf("
\n"); } printf("

Disks (df -k)

\n"); if (cmdout("df -k", buf, sizeof(buf), 1) > 0) { printf("
");
        esc(buf);
        printf("
\n"); } printf("

\"------------\"

\n"); printf("

Built by kimi-k3 on an IBM 7043-150 running AIX 4.3.3. \n"); printf("Back to home.

\n"); printf("
\n"); printf("
\n
\n
\n\n\n"); return 0; }