File: upsfstats.c

package info (click to toggle)
apcupsd 3.8.5-1.1.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 7,012 kB
  • ctags: 2,783
  • sloc: ansic: 26,374; sh: 3,012; makefile: 1,860; cpp: 1,713; perl: 191; sed: 93
file content (75 lines) | stat: -rw-r--r-- 1,518 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *  Program to print the full status output from apcupsd
 *
 *   Kern Sibbald, 17 November 1999
 *
 *
 */

#include <unistd.h>
#include <stdio.h>
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#include "upsfetch.h"

char   monhost[256];
char   answer[256];

extern int extractcgiargs();
extern int checkhost(char *host);

void parsearg(char var[255], char value[255]) 
{
    if (!strcmp(var, "host")) {
	strncpy (monhost, value, sizeof(monhost));
    }
}

static void bailout()
{
    printf ("</BODY></HTML>\n");
    exit(0);
}


int main() 
{
    strcpy (monhost, "127.0.0.1");  /* default host */

    printf ("Content-type: text/html\n");
    printf ("\n");

    printf ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n");
    printf ("<html version=\"-//W3C//DTD HTML 3.2 Final//EN\">\n");


    printf ("<HTML>\n");
    printf ("<HEAD><TITLE>APCUPSD STATUS Output Page</TITLE></HEAD>\n");
    printf ("<BODY BGCOLOR=\"#FFFFFF\">\n");

    if (!extractcgiargs()) {
        printf("Unable to extract cgi arguments!\n");
	bailout();
    }

    if (!checkhost(monhost)) {
        printf ("Access to %s host is not authorized.\n", monhost);
	bailout();
    }

    /* check if host is available */
    if (getupsvar (monhost, "date", answer, sizeof(answer)) <= 0)  {
        printf ("Host %s is not available.\n", monhost);
	bailout();
    }
    printf ("<blockquote><pre>");

    printf (statbuf);

    printf ("</pre></blockquote></BODY></HTML>\n");

    exit(0);
}