new upstream 2.8.0
This commit is contained in:
parent
fc7f4b43c1
commit
b2b0c9995a
836 changed files with 137090 additions and 30018 deletions
118
clients/upsset.c
118
clients/upsset.c
|
@ -24,6 +24,7 @@
|
|||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "nut_stdint.h"
|
||||
#include "upsclient.h"
|
||||
#include "cgilib.h"
|
||||
#include "parseconf.h"
|
||||
|
@ -39,12 +40,12 @@ struct list_t {
|
|||
#define HARD_UPSVAR_LIMIT_NUM 64
|
||||
#define HARD_UPSVAR_LIMIT_LEN 256
|
||||
|
||||
char *monups, *username, *password, *function, *upscommand;
|
||||
static char *monups, *username, *password, *function, *upscommand;
|
||||
|
||||
/* set once the MAGIC_ENABLE_STRING is found in the upsset.conf */
|
||||
int magic_string_set = 0;
|
||||
/* set once the MAGIC_ENABLE_STRING is found in the upsset.conf */
|
||||
static int magic_string_set = 0;
|
||||
|
||||
static int port;
|
||||
static uint16_t port;
|
||||
static char *upsname, *hostname;
|
||||
static UPSCONN_t ups;
|
||||
|
||||
|
@ -54,7 +55,7 @@ typedef struct {
|
|||
void *next;
|
||||
} uvtype_t;
|
||||
|
||||
uvtype_t *firstuv = NULL;
|
||||
static uvtype_t *firstuv = NULL;
|
||||
|
||||
void parsearg(char *var, char *value)
|
||||
{
|
||||
|
@ -134,7 +135,7 @@ static void do_header(const char *title)
|
|||
printf("<HTML>\n");
|
||||
printf("<HEAD><TITLE>upsset: %s</TITLE></HEAD>\n", title);
|
||||
|
||||
printf("<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000EE\" VLINK=\"#551A8B\">\n");
|
||||
printf("<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#0000EE\" VLINK=\"#551A8B\">\n");
|
||||
|
||||
printf("<TABLE BGCOLOR=\"#50A0A0\" ALIGN=\"CENTER\">\n");
|
||||
printf("<TR><TD>\n");
|
||||
|
@ -144,7 +145,7 @@ static void start_table(void)
|
|||
{
|
||||
printf("<TABLE CELLPADDING=\"5\" CELLSPACING=\"0\" ALIGN=\"CENTER\" WIDTH=\"100%%\">\n");
|
||||
printf("<TR><TH COLSPAN=2 BGCOLOR=\"#60B0B0\">\n");
|
||||
printf("<FONT SIZE=\"+2\">Network UPS Tools upsset %s</FONT>\n",
|
||||
printf("<FONT SIZE=\"+2\">Network UPS Tools upsset %s</FONT>\n",
|
||||
UPS_VERSION);
|
||||
printf("</TH></TR>\n");
|
||||
}
|
||||
|
@ -158,12 +159,12 @@ static void do_hidden(const char *next)
|
|||
password);
|
||||
|
||||
if (next)
|
||||
printf("<INPUT TYPE=\"HIDDEN\" NAME=\"function\" VALUE=\"%s\">\n",
|
||||
printf("<INPUT TYPE=\"HIDDEN\" NAME=\"function\" VALUE=\"%s\">\n",
|
||||
next);
|
||||
}
|
||||
|
||||
/* generate SELECT chooser from hosts.conf entries */
|
||||
static void upslist_arg(int numargs, char **arg)
|
||||
static void upslist_arg(size_t numargs, char **arg)
|
||||
{
|
||||
if (numargs < 3)
|
||||
return;
|
||||
|
@ -222,7 +223,7 @@ static void do_pickups(const char *currfunc)
|
|||
continue;
|
||||
}
|
||||
|
||||
upslist_arg(ctx.numargs, ctx.arglist);
|
||||
upslist_arg(ctx.numargs, ctx.arglist);
|
||||
}
|
||||
|
||||
pconf_finish(&ctx);
|
||||
|
@ -253,6 +254,10 @@ static void do_pickups(const char *currfunc)
|
|||
printf("</FORM>\n");
|
||||
}
|
||||
|
||||
static void error_page(const char *next, const char *title,
|
||||
const char *fmt, ...)
|
||||
__attribute__((noreturn));
|
||||
|
||||
static void error_page(const char *next, const char *title,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
|
@ -260,7 +265,19 @@ static void error_page(const char *next, const char *title,
|
|||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL
|
||||
#pragma GCC diagnostic push
|
||||
#endif
|
||||
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY
|
||||
#pragma GCC diagnostic ignored "-Wformat-security"
|
||||
#endif
|
||||
vsnprintf(msg, sizeof(msg), fmt, ap);
|
||||
#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
va_end(ap);
|
||||
|
||||
do_header(title);
|
||||
|
@ -282,6 +299,9 @@ static void error_page(const char *next, const char *title,
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void loginscreen(void)
|
||||
__attribute__((noreturn));
|
||||
|
||||
static void loginscreen(void)
|
||||
{
|
||||
do_header("Login");
|
||||
|
@ -331,7 +351,7 @@ static void upsd_connect(void)
|
|||
static void print_cmd(const char *cmd)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
size_t numq, numa;
|
||||
char **answer;
|
||||
const char *query[4];
|
||||
|
||||
|
@ -354,7 +374,7 @@ static void print_cmd(const char *cmd)
|
|||
static void showcmds(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
size_t numq, numa;
|
||||
const char *query[2];
|
||||
char **answer;
|
||||
struct list_t *lhead, *llast, *ltmp, *lnext;
|
||||
|
@ -391,7 +411,7 @@ static void showcmds(void)
|
|||
/* CMD upsname cmdname */
|
||||
if (numa < 3) {
|
||||
fprintf(stderr, "Error: insufficient data "
|
||||
"(got %d args, need at least 3)\n", numa);
|
||||
"(got %zu args, need at least 3)\n", numa);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -466,7 +486,7 @@ static void showcmds(void)
|
|||
|
||||
upscli_disconnect(&ups);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/* handle setting authentication data in the server */
|
||||
static void send_auth(const char *next)
|
||||
|
@ -491,7 +511,7 @@ static void send_auth(const char *next)
|
|||
"upsd version too old - USERNAME not supported");
|
||||
}
|
||||
|
||||
error_page(next, "Can't set user name",
|
||||
error_page(next, "Can't set user name",
|
||||
"Set user name failed: %s", upscli_strerror(&ups));
|
||||
}
|
||||
|
||||
|
@ -504,7 +524,10 @@ static void send_auth(const char *next)
|
|||
if (upscli_readline(&ups, buf, sizeof(buf)) < 0)
|
||||
error_page(next, "Can't set password",
|
||||
"Password set failed: %s", upscli_strerror(&ups));
|
||||
}
|
||||
}
|
||||
|
||||
static void docmd(void)
|
||||
__attribute__((noreturn));
|
||||
|
||||
static void docmd(void)
|
||||
{
|
||||
|
@ -515,13 +538,13 @@ static void docmd(void)
|
|||
"Access to that host is not authorized");
|
||||
|
||||
/* the user is messing with us */
|
||||
if (!upscommand)
|
||||
error_page("showcmds", "Form error",
|
||||
if (!upscommand)
|
||||
error_page("showcmds", "Form error",
|
||||
"No instant command selected");
|
||||
|
||||
/* (l)user took the default blank option */
|
||||
if (strlen(upscommand) == 0)
|
||||
error_page("showcmds", "Form error",
|
||||
error_page("showcmds", "Form error",
|
||||
"No instant command selected");
|
||||
|
||||
upsd_connect();
|
||||
|
@ -595,7 +618,7 @@ static void docmd(void)
|
|||
static const char *get_data(const char *type, const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
size_t numq, numa;
|
||||
char **answer;
|
||||
const char *query[4];
|
||||
|
||||
|
@ -633,7 +656,7 @@ static void do_string(const char *varname, int maxlen)
|
|||
static void do_enum(const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
size_t numq, numa;
|
||||
char **answer, *val;
|
||||
const char *query[4], *tmp;
|
||||
|
||||
|
@ -659,8 +682,9 @@ static void do_enum(const char *varname)
|
|||
|
||||
if (ret < 0) {
|
||||
printf("Unavailable\n");
|
||||
fprintf(stderr, "Error doing ENUM %s %s: %s\n",
|
||||
fprintf(stderr, "Error doing ENUM %s %s: %s\n",
|
||||
upsname, varname, upscli_strerror(&ups));
|
||||
free(val);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -674,7 +698,7 @@ static void do_enum(const char *varname)
|
|||
|
||||
if (numa < 4) {
|
||||
fprintf(stderr, "Error: insufficient data "
|
||||
"(got %d args, need at least 4)\n", numa);
|
||||
"(got %zu args, need at least 4)\n", numa);
|
||||
|
||||
free(val);
|
||||
return;
|
||||
|
@ -697,7 +721,7 @@ static void do_enum(const char *varname)
|
|||
static void do_type(const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int i, numq, numa;
|
||||
size_t i, numq, numa;
|
||||
char **answer;
|
||||
const char *query[4];
|
||||
|
||||
|
@ -709,7 +733,7 @@ static void do_type(const char *varname)
|
|||
ret = upscli_get(&ups, numq, query, &numa, &answer);
|
||||
|
||||
if ((ret < 0) || (numa < numq)) {
|
||||
printf("Unknown type\n");
|
||||
printf("Unknown type\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -727,7 +751,9 @@ static void do_type(const char *varname)
|
|||
/* split out the :<len> data */
|
||||
ptr = strchr(answer[i], ':');
|
||||
*ptr++ = '\0';
|
||||
len = strtol(ptr, (char **) NULL, 10);
|
||||
long l = strtol(ptr, (char **) NULL, 10);
|
||||
assert(l <= 127); /* FIXME: Loophole about longer numbers? Why are we limited to char at all here? */
|
||||
len = (char)l;
|
||||
|
||||
do_string(varname, len);
|
||||
return;
|
||||
|
@ -741,10 +767,12 @@ static void do_type(const char *varname)
|
|||
}
|
||||
}
|
||||
|
||||
static void print_rw(const char *upsname, const char *varname)
|
||||
static void print_rw(const char *arg_upsname, const char *varname)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
printf("<!-- <TR><TD>Device</TD><TD>%s</TD></TR> -->\n", arg_upsname);
|
||||
|
||||
printf("<TR BGCOLOR=\"#60B0B0\" ALIGN=\"CENTER\">\n");
|
||||
|
||||
printf("<TD>");
|
||||
|
@ -765,10 +793,13 @@ static void print_rw(const char *upsname, const char *varname)
|
|||
printf("</TR>\n");
|
||||
}
|
||||
|
||||
static void showsettings(void)
|
||||
__attribute__((noreturn));
|
||||
|
||||
static void showsettings(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
size_t numq, numa;
|
||||
const char *query[2];
|
||||
char **answer, *desc = NULL;
|
||||
struct list_t *lhead, *llast, *ltmp, *lnext;
|
||||
|
@ -907,13 +938,16 @@ static int setvar(const char *var, const char *val)
|
|||
}
|
||||
|
||||
/* turn a form submission of settings into SET commands for upsd */
|
||||
static void savesettings(void)
|
||||
__attribute__((noreturn));
|
||||
|
||||
static void savesettings(void)
|
||||
{
|
||||
int changed = 0;
|
||||
char *desc;
|
||||
uvtype_t *upsvar;
|
||||
|
||||
if (!checkhost(monups, &desc))
|
||||
if (!checkhost(monups, &desc))
|
||||
error_page("showsettings", "Access denied",
|
||||
"Access to that host is not authorized");
|
||||
|
||||
|
@ -953,6 +987,9 @@ static void savesettings(void)
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void initial_pickups(void)
|
||||
__attribute__((noreturn));
|
||||
|
||||
static void initial_pickups(void)
|
||||
{
|
||||
do_header("Select a UPS");
|
||||
|
@ -1027,10 +1064,12 @@ static void check_conf(void)
|
|||
fprintf(stderr, "upsset.conf does not permit execution\n");
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NUT_UNUSED_VARIABLE(argc);
|
||||
NUT_UNUSED_VARIABLE(argv);
|
||||
username = password = function = monups = NULL;
|
||||
|
||||
printf("Content-type: text/html\n\n");
|
||||
|
@ -1040,15 +1079,16 @@ int main(int argc, char **argv)
|
|||
|
||||
/* see if there's anything waiting .. the server my not close STDIN properly */
|
||||
if (1) {
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 250000; /* wait for up to 250ms for a POST response */
|
||||
if ((select(STDIN_FILENO+1, &fds, 0, 0, &tv)) > 0)
|
||||
extractpostargs();
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(STDIN_FILENO, &fds);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 250000; /* wait for up to 250ms for a POST response */
|
||||
|
||||
if ((select(STDIN_FILENO+1, &fds, 0, 0, &tv)) > 0)
|
||||
extractpostargs();
|
||||
}
|
||||
if ((!username) || (!password) || (!function))
|
||||
loginscreen();
|
||||
|
@ -1074,6 +1114,6 @@ int main(int argc, char **argv)
|
|||
docmd();
|
||||
|
||||
printf("Error: Unhandled function name [%s]\n", function);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue