version 1.1, 2012/02/21 23:32:47
|
version 1.1.1.2, 2016/11/01 09:56:12
|
Line 42
|
Line 42
|
|
|
static void WebRunBinCmd(FILE *f, const char *query, int priv); |
static void WebRunBinCmd(FILE *f, const char *query, int priv); |
static void WebRunCmd(FILE *f, const char *query, int priv); |
static void WebRunCmd(FILE *f, const char *query, int priv); |
static void WebShowSummary(FILE *f, int priv); | static void WebShowHTMLSummary(FILE *f, int priv); |
| static void WebShowJSONSummary(FILE *f, int priv); |
|
|
/* |
/* |
* GLOBAL VARIABLES |
* GLOBAL VARIABLES |
Line 217 static void
|
Line 218 static void
|
WebShowCSS(FILE *f) |
WebShowCSS(FILE *f) |
{ |
{ |
fprintf(f, "body {font-family: Arial, Helvetica, Sans-Serif; background-color: #EEEEEE; }\n"); |
fprintf(f, "body {font-family: Arial, Helvetica, Sans-Serif; background-color: #EEEEEE; }\n"); |
fprintf(f, "table {background-color: #FFFFFF; }\n"); | fprintf(f, "table, pre {background-color: #FFFFFF; }\n"); |
fprintf(f, "th, td {padding: 0 2pt 0 2pt; }\n"); |
fprintf(f, "th, td {padding: 0 2pt 0 2pt; }\n"); |
fprintf(f, "th {background-color: #00B000; }\n"); |
fprintf(f, "th {background-color: #00B000; }\n"); |
fprintf(f, "td {background-color: #EEEEEE; }\n"); |
fprintf(f, "td {background-color: #EEEEEE; }\n"); |
Line 225 WebShowCSS(FILE *f)
|
Line 226 WebShowCSS(FILE *f)
|
fprintf(f, "td.y {background-color: #EEEEBB; }\n"); |
fprintf(f, "td.y {background-color: #EEEEBB; }\n"); |
fprintf(f, "td.g {background-color: #BBEEBB; }\n"); |
fprintf(f, "td.g {background-color: #BBEEBB; }\n"); |
fprintf(f, "td.d {background-color: #CCCCCC; }\n"); |
fprintf(f, "td.d {background-color: #CCCCCC; }\n"); |
fprintf(f, "pre {background-color: #FFFFFF; }\n"); |
|
fprintf(f, "a, a:visited, a:link { color: blue; }\n"); |
fprintf(f, "a, a:visited, a:link { color: blue; }\n"); |
} |
} |
|
|
static void |
static void |
WebShowSummary(FILE *f, int priv) | WebShowHTMLSummary(FILE *f, int priv) |
{ |
{ |
int b,l; |
int b,l; |
Bund B; |
Bund B; |
Line 238 WebShowSummary(FILE *f, int priv)
|
Line 238 WebShowSummary(FILE *f, int priv)
|
Rep R; |
Rep R; |
char buf[64],buf2[64]; |
char buf[64],buf2[64]; |
|
|
fprintf(f, "<H2>Current status summary</H2>\n"); | fprintf(f, "<h2>Current status summary</h2>\n"); |
fprintf(f, "<table>\n"); |
fprintf(f, "<table>\n"); |
fprintf(f, "<TR><TH>Bund</TH><TH colspan=2>Iface</TH><TH>IPCP</TH><TH>IPV6CP</TH><TH>CCP</TH><TH>ECP</TH>" | fprintf(f, "<thead>\n<tr>\n<th>Bund</th>\n<th colspan=\"2\">Iface</th>\n<th>IPCP</th>\n<th>IPV6CP</th>\n<th>CCP</th>\n<th>ECP</th>\n" |
"<TH>Link</TH><TH>LCP</TH><TH>User</TH><TH colspan=2>Device</TH><TH>Peer</TH><TH>IP</TH><TH colspan=3></TH>%s</TR>", | "<th>Link</th>\n<th>LCP</th>\n<th>User</th>\n<th colspan=\"2\">Device</th>\n<th>Peer</th>\n<th>IP</th>\n<th> </th>\n<th> </th>\n<th> </th>\n%s</tr>\n</thead>\n<tbody>\n", |
priv?"<TH>State</TH>":""); | priv?"<th>State</th>\n":""); |
#define FSM_COLOR(s) (((s)==ST_OPENED)?"g":(((s)==ST_INITIAL)?"r":"y")) |
#define FSM_COLOR(s) (((s)==ST_OPENED)?"g":(((s)==ST_INITIAL)?"r":"y")) |
#define PHYS_COLOR(s) (((s)==PHYS_STATE_UP)?"g":(((s)==PHYS_STATE_DOWN)?"r":"y")) |
#define PHYS_COLOR(s) (((s)==PHYS_STATE_UP)?"g":(((s)==PHYS_STATE_DOWN)?"r":"y")) |
for (b = 0; b<gNumLinks; b++) { |
for (b = 0; b<gNumLinks; b++) { |
if ((L=gLinks[b]) != NULL && L->bund == NULL && L->rep == NULL) { |
if ((L=gLinks[b]) != NULL && L->bund == NULL && L->rep == NULL) { |
fprintf(f, "<TR>\n"); | fprintf(f, "<tr>\n"); |
fprintf(f, "<TD colspan=\"7\"> </a></TD>\n"); | fprintf(f, "<td colspan=\"7\"> </td>\n"); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20link\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20link\">%s</a></td>\n", |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->name); |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->name); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20lcp\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20lcp\">%s</a></td>\n", |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, FsmStateName(L->lcp.fsm.state)); |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, FsmStateName(L->lcp.fsm.state)); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20auth\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20auth\">%s</a></td>\n", |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->lcp.auth.params.authname); |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->lcp.auth.params.authname); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, L->type?L->type->name:""); |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, L->type?L->type->name:""); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, gPhysStateNames[L->state]); |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, gPhysStateNames[L->state]); |
if (L->state != PHYS_STATE_DOWN) { |
if (L->state != PHYS_STATE_DOWN) { |
PhysGetPeerAddr(L, buf, sizeof(buf)); |
PhysGetPeerAddr(L, buf, sizeof(buf)); |
fprintf(f, "<TD>%s</TD>\n", buf); | fprintf(f, "<td>%s</td>\n", buf); |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
PhysGetCallingNum(L, buf, sizeof(buf)); |
PhysGetCallingNum(L, buf, sizeof(buf)); |
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
fprintf(f, "<TD>%s</TD><TD><=</TD><TD>%s</TD>\n", | fprintf(f, "<td>%s</td>\n<td><=</td>\n<td>%s</td>\n", |
buf2, buf); |
buf2, buf); |
} else { |
} else { |
fprintf(f, "<TD>%s</TD><TD>=></TD><TD>%s</TD>\n", | fprintf(f, "<td>%s</td>\n<td>=></td>\n<td>%s</td>\n", |
buf, buf2); |
buf, buf2); |
} |
} |
} else { |
} else { |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "<TD colspan=3></TD>\n"); | fprintf(f, "<td colspan=\"3\"> </td>\n"); |
} |
} |
if (priv) { |
if (priv) { |
if (!L->tmpl) { |
if (!L->tmpl) { |
switch (L->state) { |
switch (L->state) { |
case PHYS_STATE_DOWN: |
case PHYS_STATE_DOWN: |
fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</A></TD>\n", | fprintf(f, "<td><a href=\"/cmd?link%%20%s&open\">[Open]</a></td>\n", |
L->name); |
L->name); |
break; |
break; |
case PHYS_STATE_UP: |
case PHYS_STATE_UP: |
fprintf(f, "<TD><A href=\"/cmd?link%%20%s&close\">[Close]</A></TD>\n", | fprintf(f, "<td><a href=\"/cmd?link%%20%s&close\">[Close]</a></td>\n", |
L->name); |
L->name); |
break; |
break; |
default: |
default: |
fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</a> <A href=\"/cmd?link%%20%s&close\">[Close]</a></TD>\n", | fprintf(f, "<td><a href=\"/cmd?link%%20%s&open\">[Open]</a> <a href=\"/cmd?link%%20%s&close\">[Close]</a></td>\n", |
L->name, L->name); |
L->name, L->name); |
} |
} |
} else { |
} else { |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
} |
} |
} |
} |
fprintf(f, "</TR>\n"); | fprintf(f, "</tr>\n"); |
} |
} |
} |
} |
for (b = 0; b<gNumBundles; b++) { |
for (b = 0; b<gNumBundles; b++) { |
if ((B=gBundles[b]) != NULL) { |
if ((B=gBundles[b]) != NULL) { |
int rows = B->n_links?B->n_links:1; |
int rows = B->n_links?B->n_links:1; |
int first = 1; |
int first = 1; |
fprintf(f, "<TR>\n"); | fprintf(f, "<tr>\n"); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20bund\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20bund\">%s</a></td>\n", |
rows, B->tmpl?"d":(B->iface.up?"g":"r"), B->name, B->name); |
rows, B->tmpl?"d":(B->iface.up?"g":"r"), B->name, B->name); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20iface\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20iface\">%s</a></td>\n", |
rows, B->tmpl?"d":(B->iface.up?"g":"r"), B->name, B->iface.ifname); |
rows, B->tmpl?"d":(B->iface.up?"g":"r"), B->name, B->iface.ifname); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20iface\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20iface\">%s</a></td>\n", |
rows, B->tmpl?"d":(B->iface.up?"g":"r"), B->name, (B->iface.up?"Up":"Down")); |
rows, B->tmpl?"d":(B->iface.up?"g":"r"), B->name, (B->iface.up?"Up":"Down")); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20ipcp\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20ipcp\">%s</a></td>\n", |
rows, B->tmpl?"d":FSM_COLOR(B->ipcp.fsm.state), B->name,FsmStateName(B->ipcp.fsm.state)); |
rows, B->tmpl?"d":FSM_COLOR(B->ipcp.fsm.state), B->name,FsmStateName(B->ipcp.fsm.state)); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20ipv6cp\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20ipv6cp\">%s</a></td>\n", |
rows, B->tmpl?"d":FSM_COLOR(B->ipv6cp.fsm.state), B->name,FsmStateName(B->ipv6cp.fsm.state)); |
rows, B->tmpl?"d":FSM_COLOR(B->ipv6cp.fsm.state), B->name,FsmStateName(B->ipv6cp.fsm.state)); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20ccp\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20ccp\">%s</a></td>\n", |
rows, B->tmpl?"d":FSM_COLOR(B->ccp.fsm.state), B->name,FsmStateName(B->ccp.fsm.state)); |
rows, B->tmpl?"d":FSM_COLOR(B->ccp.fsm.state), B->name,FsmStateName(B->ccp.fsm.state)); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20ecp\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?bund%%20%s&show%%20ecp\">%s</a></td>\n", |
rows, B->tmpl?"d":FSM_COLOR(B->ecp.fsm.state), B->name,FsmStateName(B->ecp.fsm.state)); |
rows, B->tmpl?"d":FSM_COLOR(B->ecp.fsm.state), B->name,FsmStateName(B->ecp.fsm.state)); |
if (B->n_links == 0) { |
if (B->n_links == 0) { |
fprintf(f, "<TD colspan=\"11\"> </a></TD>\n</TR>\n"); | fprintf(f, "<td colspan=\"11\"> </td>\n</tr>\n"); |
} |
} |
for (l = 0; l < NG_PPP_MAX_LINKS; l++) { |
for (l = 0; l < NG_PPP_MAX_LINKS; l++) { |
if ((L=B->links[l]) != NULL) { |
if ((L=B->links[l]) != NULL) { |
if (first) |
if (first) |
first = 0; |
first = 0; |
else |
else |
fprintf(f, "<TR>\n"); | fprintf(f, "<tr>\n"); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20link\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20link\">%s</a></td>\n", |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->name); |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->name); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20lcp\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20lcp\">%s</a></td>\n", |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, FsmStateName(L->lcp.fsm.state)); |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, FsmStateName(L->lcp.fsm.state)); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20auth\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20auth\">%s</a></td>\n", |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->lcp.auth.params.authname); |
L->tmpl?"d":FSM_COLOR(L->lcp.fsm.state), L->name, L->lcp.auth.params.authname); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, L->type?L->type->name:""); |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, L->type?L->type->name:""); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, gPhysStateNames[L->state]); |
L->tmpl?"d":PHYS_COLOR(L->state), L->name, gPhysStateNames[L->state]); |
if (L->state != PHYS_STATE_DOWN) { |
if (L->state != PHYS_STATE_DOWN) { |
PhysGetPeerAddr(L, buf, sizeof(buf)); |
PhysGetPeerAddr(L, buf, sizeof(buf)); |
fprintf(f, "<TD>%s</TD>\n", buf); | fprintf(f, "<td>%s</td>\n", buf); |
if (L->bund != NULL) |
if (L->bund != NULL) |
fprintf(f, "<TD>%s</TD>\n", inet_ntoa(L->bund->ipcp.peer_addr)); | fprintf(f, "<td>%s</td>\n", inet_ntoa(L->bund->ipcp.peer_addr)); |
else |
else |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
PhysGetCallingNum(L, buf, sizeof(buf)); |
PhysGetCallingNum(L, buf, sizeof(buf)); |
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
fprintf(f, "<TD>%s</TD><TD><=</TD><TD>%s</TD>\n", | fprintf(f, "<td>%s</td>\n<td><=</td>\n<td>%s</td>\n", |
buf2, buf); |
buf2, buf); |
} else { |
} else { |
fprintf(f, "<TD>%s</TD><TD>=></TD><TD>%s</TD>\n", | fprintf(f, "<td>%s</td>\n<td>=></td>\n<td>%s</td>\n", |
buf, buf2); |
buf, buf2); |
} |
} |
} else { |
} else { |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "<TD colspan=3></TD>\n"); | fprintf(f, "<td colspan=\"3\"> </td>\n"); |
} |
} |
if (priv) { |
if (priv) { |
switch (L->state) { |
switch (L->state) { |
case PHYS_STATE_DOWN: |
case PHYS_STATE_DOWN: |
fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</A></TD>\n", | fprintf(f, "<td><a href=\"/cmd?link%%20%s&open\">[Open]</a></td>\n", |
L->name); |
L->name); |
break; |
break; |
case PHYS_STATE_UP: |
case PHYS_STATE_UP: |
fprintf(f, "<TD><A href=\"/cmd?link%%20%s&close\">[Close]</A></TD>\n", | fprintf(f, "<td><a href=\"/cmd?link%%20%s&close\">[Close]</a></td>\n", |
L->name); |
L->name); |
break; |
break; |
default: |
default: |
fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</a> <A href=\"/cmd?link%%20%s&close\">[Close]</a></TD>\n", | fprintf(f, "<td><a href=\"/cmd?link%%20%s&open\">[Open]</a> <a href=\"/cmd?link%%20%s&close\">[Close]</a></td>\n", |
L->name, L->name); |
L->name, L->name); |
} |
} |
} |
} |
fprintf(f, "</TR>\n"); | fprintf(f, "</tr>\n"); |
} |
} |
} |
} |
} |
} |
Line 386 WebShowSummary(FILE *f, int priv)
|
Line 386 WebShowSummary(FILE *f, int priv)
|
int rows = (R->links[0]?1:0) + (R->links[1]?1:0); |
int rows = (R->links[0]?1:0) + (R->links[1]?1:0); |
if (rows == 0) |
if (rows == 0) |
rows = 1; |
rows = 1; |
fprintf(f, "<TR>\n"); | fprintf(f, "<tr>\n"); |
fprintf(f, "<TD rowspan=\"%d\" colspan=6>Repeater</TD>\n", rows); | fprintf(f, "<td rowspan=\"%d\" colspan=\"6\">Repeater</td>\n", rows); |
fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?rep%%20%s&show%%20repeater\">%s</a></TD>\n", | fprintf(f, "<td rowspan=\"%d\" class=\"%s\"><a href=\"/cmd?rep%%20%s&show%%20repeater\">%s</a></td>\n", |
rows, R->p_up?"g":"r", R->name, R->name); |
rows, R->p_up?"g":"r", R->name, R->name); |
for (l = 0; l < 2; l++) { |
for (l = 0; l < 2; l++) { |
if ((L=R->links[l]) != NULL) { |
if ((L=R->links[l]) != NULL) { |
if (shown) |
if (shown) |
fprintf(f, "<TR>\n"); | fprintf(f, "<tr>\n"); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
PHYS_COLOR(L->state), L->name, L->name); |
PHYS_COLOR(L->state), L->name, L->name); |
fprintf(f, "<TD colspan=2></TD>\n"); | fprintf(f, "<td colspan=\"2\"> </td>\n"); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
PHYS_COLOR(L->state), L->name, L->type?L->type->name:""); |
PHYS_COLOR(L->state), L->name, L->type?L->type->name:""); |
fprintf(f, "<TD class=\"%s\"><A href=\"/cmd?link%%20%s&show%%20device\">%s</a></TD>\n", | fprintf(f, "<td class=\"%s\"><a href=\"/cmd?link%%20%s&show%%20device\">%s</a></td>\n", |
PHYS_COLOR(L->state), L->name, gPhysStateNames[L->state]); |
PHYS_COLOR(L->state), L->name, gPhysStateNames[L->state]); |
if (L->state != PHYS_STATE_DOWN) { |
if (L->state != PHYS_STATE_DOWN) { |
PhysGetPeerAddr(L, buf, sizeof(buf)); |
PhysGetPeerAddr(L, buf, sizeof(buf)); |
fprintf(f, "<TD>%s</TD>\n", buf); | fprintf(f, "<td>%s</td>\n", buf); |
if (L->bund != NULL) |
if (L->bund != NULL) |
fprintf(f, "<TD>%s</TD>\n", inet_ntoa(L->bund->ipcp.peer_addr)); | fprintf(f, "<td>%s</td>\n", inet_ntoa(L->bund->ipcp.peer_addr)); |
else |
else |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
PhysGetCallingNum(L, buf, sizeof(buf)); |
PhysGetCallingNum(L, buf, sizeof(buf)); |
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
fprintf(f, "<TD>%s</TD><TD><=</TD><TD>%s</TD>\n", | fprintf(f, "<td>%s</td>\n<td><=</td>\n<td>%s</td>\n", |
buf2, buf); |
buf2, buf); |
} else { |
} else { |
fprintf(f, "<TD>%s</TD><TD>=></TD><TD>%s</TD>\n", | fprintf(f, "<td>%s</td>\n<td>=></td>\n<td>%s</td>\n", |
buf, buf2); |
buf, buf2); |
} |
} |
} else { |
} else { |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "<TD colspan=3></TD>\n"); | fprintf(f, "<td colspan=\"3\"> </td>\n"); |
} |
} |
fprintf(f, "<TD></TD>\n"); | fprintf(f, "<td> </td>\n"); |
fprintf(f, "</TR>\n"); | fprintf(f, "</tr>\n"); |
|
|
shown = 1; |
shown = 1; |
} |
} |
} |
} |
if (!shown) { |
if (!shown) { |
fprintf(f, "<TD colspan = \"11\"></TD>\n"); | fprintf(f, "<td colspan=\"11\"> </td>\n"); |
fprintf(f, "</TR>\n"); | fprintf(f, "</tr>\n"); |
} |
} |
} |
} |
} |
} |
fprintf(f, "</TABLE>\n"); | fprintf(f, "</tbody>\n</table>\n"); |
} |
} |
|
|
|
static void |
|
WebShowJSONSummary(FILE *f, int priv) |
|
{ |
|
int b,l; |
|
Bund B; |
|
Link L; |
|
Rep R; |
|
char buf[64],buf2[64]; |
|
|
|
int first_l = 1; |
|
fprintf(f, "{\"links\":[\n"); |
|
for (b = 0; b<gNumLinks; b++) { |
|
if ((L=gLinks[b]) != NULL && L->bund == NULL && L->rep == NULL) { |
|
if (first_l) { |
|
fprintf(f, "{\n"); |
|
first_l = 0; |
|
} else |
|
fprintf(f, ",\n{\n"); |
|
|
|
fprintf(f, "\"link\": \"%s\",\n", L->name); |
|
fprintf(f, "\"lcp\": \"%s\",\n", FsmStateName(L->lcp.fsm.state)); |
|
fprintf(f, "\"auth\": \"%s\",\n", L->lcp.auth.params.authname); |
|
fprintf(f, "\"type\": \"%s\",\n", L->type?L->type->name:""); |
|
fprintf(f, "\"state\": \"%s\",\n", gPhysStateNames[L->state]); |
|
|
|
if (L->state != PHYS_STATE_DOWN) { |
|
PhysGetPeerAddr(L, buf, sizeof(buf)); |
|
fprintf(f, "\"peer_ip\": \"%s\",\n", buf); |
|
|
|
PhysGetCallingNum(L, buf, sizeof(buf)); |
|
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
|
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", buf); |
|
fprintf(f, "\"called_num\": \"%s\"\n", buf2); |
|
} else { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", buf2); |
|
fprintf(f, "\"called_num\": \"%s\"\n", buf); |
|
} |
|
} else { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", ""); |
|
fprintf(f, "\"called_num\": \"%s\"\n", ""); |
|
} |
|
fprintf(f, "}\n"); |
|
} |
|
} |
|
fprintf(f, "],\n"); |
|
|
|
int first_b = 1; |
|
fprintf(f, "\"bundles\":[\n"); |
|
for (b = 0; b<gNumBundles; b++) { |
|
if ((B=gBundles[b]) != NULL) { |
|
if (first_b) { |
|
fprintf(f, "{\n"); |
|
first_b = 0; |
|
} else |
|
fprintf(f, ",\n{\n"); |
|
|
|
fprintf(f, "\"bundle\": \"%s\",\n", B->name); |
|
fprintf(f, "\"iface\": \"%s\",\n", B->iface.ifname); |
|
fprintf(f, "\"state\": \"%s\",\n", (B->iface.up?"Up":"Down")); |
|
fprintf(f, "\"ipcp\": \"%s\",\n", FsmStateName(B->ipcp.fsm.state)); |
|
fprintf(f, "\"ipv6cp\": \"%s\",\n", FsmStateName(B->ipv6cp.fsm.state)); |
|
fprintf(f, "\"ccp\": \"%s\",\n", FsmStateName(B->ccp.fsm.state)); |
|
fprintf(f, "\"ecp\": \"%s\",\n", FsmStateName(B->ecp.fsm.state)); |
|
|
|
int first_l = 1; |
|
fprintf(f, "\"links\":[\n"); |
|
for (l = 0; l < NG_PPP_MAX_LINKS; l++) { |
|
if ((L=B->links[l]) != NULL) { |
|
if (first_l) { |
|
fprintf(f, "{\n"); |
|
first_l = 0; |
|
} else |
|
fprintf(f, ",\n{\n"); |
|
|
|
fprintf(f, "\"link\": \"%s\",\n", L->name); |
|
fprintf(f, "\"lcp\": \"%s\",\n", FsmStateName(L->lcp.fsm.state)); |
|
fprintf(f, "\"auth\": \"%s\",\n", L->lcp.auth.params.authname); |
|
fprintf(f, "\"type\": \"%s\",\n", L->type?L->type->name:""); |
|
fprintf(f, "\"state\": \"%s\",\n", gPhysStateNames[L->state]); |
|
|
|
if (L->state != PHYS_STATE_DOWN) { |
|
PhysGetPeerAddr(L, buf, sizeof(buf)); |
|
fprintf(f, "\"peer_ip\": \"%s\",\n", buf); |
|
|
|
if (L->bund != NULL) |
|
fprintf(f, "\"ipcp_ip\": \"%s\",\n", inet_ntoa(L->bund->ipcp.peer_addr)); |
|
else |
|
fprintf(f, "\"ipcp_ip\": \"%s\",\n", ""); |
|
|
|
PhysGetCallingNum(L, buf, sizeof(buf)); |
|
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
|
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", buf); |
|
fprintf(f, "\"called_num\": \"%s\"\n", buf2); |
|
} else { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", buf2); |
|
fprintf(f, "\"called_num\": \"%s\"\n", buf); |
|
} |
|
} else { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", ""); |
|
fprintf(f, "\"called_num\": \"%s\"\n", ""); |
|
} |
|
fprintf(f, "}\n"); |
|
} |
|
} |
|
fprintf(f, "]\n}\n"); |
|
} |
|
} |
|
fprintf(f, "],\n"); |
|
|
|
int first_r = 1; |
|
fprintf(f, "\"repeaters\":[\n"); |
|
for (b = 0; b<gNumReps; b++) { |
|
if ((R=gReps[b]) != NULL) { |
|
if (first_r) { |
|
fprintf(f, "{\n"); |
|
first_r = 0; |
|
} else |
|
fprintf(f, ",\n{\n"); |
|
|
|
fprintf(f, "\"repeater\": \"%s\",\n", R->name); |
|
|
|
int first_l = 1; |
|
fprintf(f, "\"links\":[\n"); |
|
for (l = 0; l < 2; l++) { |
|
if ((L=R->links[l]) != NULL) { |
|
if (first_l) { |
|
fprintf(f, "{\n"); |
|
first_l = 0; |
|
} else |
|
fprintf(f, ",\n{\n"); |
|
|
|
fprintf(f, "\"link\": \"%s\",\n", L->name); |
|
fprintf(f, "\"type\": \"%s\",\n", L->type?L->type->name:""); |
|
fprintf(f, "\"state\": \"%s\",\n", gPhysStateNames[L->state]); |
|
|
|
if (L->state != PHYS_STATE_DOWN) { |
|
PhysGetPeerAddr(L, buf, sizeof(buf)); |
|
fprintf(f, "\"peer_ip\": \"%s\",\n", buf); |
|
|
|
if (L->bund != NULL) |
|
fprintf(f, "\"ipcp_ip\": \"%s\",\n", inet_ntoa(L->bund->ipcp.peer_addr)); |
|
else |
|
fprintf(f, "\"ipcp_ip\": \"%s\",\n", ""); |
|
|
|
PhysGetCallingNum(L, buf, sizeof(buf)); |
|
PhysGetCalledNum(L, buf2, sizeof(buf2)); |
|
if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", buf); |
|
fprintf(f, "\"called_num\": \"%s\"\n", buf2); |
|
} else { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", buf2); |
|
fprintf(f, "\"called_num\": \"%s\"\n", buf); |
|
} |
|
} else { |
|
fprintf(f, "\"calling_num\": \"%s\",\n", ""); |
|
fprintf(f, "\"called_num\": \"%s\"\n", ""); |
|
} |
|
fprintf(f, "}\n"); |
|
} |
|
} |
|
fprintf(f, "]\n"); |
|
|
|
if (b == (gNumReps - 1)) { |
|
fprintf(f, "}\n"); |
|
} else { |
|
fprintf(f, "},\n"); |
|
} |
|
} |
|
} |
|
fprintf(f, "]}\n"); |
|
} |
|
|
static void |
static void |
WebRunBinCmd(FILE *f, const char *query, int priv) |
WebRunBinCmd(FILE *f, const char *query, int priv) |
{ |
{ |
Line 516 WebRunCmd(FILE *f, const char *query, int priv)
|
Line 690 WebRunCmd(FILE *f, const char *query, int priv)
|
if (++argc >= MAX_CONSOLE_ARGS) |
if (++argc >= MAX_CONSOLE_ARGS) |
break; |
break; |
|
|
fprintf(f, "<P><A href=\"/\"><< Back</A></P>\n"); | fprintf(f, "<p>\n<a href=\"/\">Back</a>\n</p>\n"); |
|
|
if (argc == 0) { |
if (argc == 0) { |
fprintf(f, "<P>No command cpecified!</P>\n"); | fprintf(f, "<p>No command cpecified!</p>\n"); |
goto done; |
goto done; |
} |
} |
|
|
fprintf(f, "<PRE>\n"); | fprintf(f, "<pre>\n"); |
for (k = 0; k < argc; k++) { |
for (k = 0; k < argc; k++) { |
int ac; |
int ac; |
char *av[MAX_CONSOLE_ARGS]; |
char *av[MAX_CONSOLE_ARGS]; |
Line 543 WebRunCmd(FILE *f, const char *query, int priv)
|
Line 717 WebRunCmd(FILE *f, const char *query, int priv)
|
DoCommand(&cs->context, ac, av, NULL, 0); |
DoCommand(&cs->context, ac, av, NULL, 0); |
Freee(buf1); |
Freee(buf1); |
} |
} |
fprintf(f, "</PRE>\n"); | fprintf(f, "</pre>\n"); |
done: |
done: |
Freee(buf); |
Freee(buf); |
fprintf(f, "<P><A href=\"/\"><< Back</A></P>\n"); | fprintf(f, "<p>\n<a href=\"/\">Back</a>\n</p>\n"); |
RESETREF(cs->context.lnk, NULL); |
RESETREF(cs->context.lnk, NULL); |
RESETREF(cs->context.bund, NULL); |
RESETREF(cs->context.bund, NULL); |
RESETREF(cs->context.rep, NULL); |
RESETREF(cs->context.rep, NULL); |
Line 601 WebServletRun(struct http_servlet *servlet,
|
Line 775 WebServletRun(struct http_servlet *servlet,
|
if (!strcmp(path,"/mpd.css")) { |
if (!strcmp(path,"/mpd.css")) { |
http_response_set_header(resp, 0, "Content-Type", "text/css"); |
http_response_set_header(resp, 0, "Content-Type", "text/css"); |
WebShowCSS(f); |
WebShowCSS(f); |
} else if (!strcmp(path,"/bincmd")) { | } else if (!strcmp(path,"/bincmd") || !strcmp(path,"/json")) { |
http_response_set_header(resp, 0, "Content-Type", "text/plain"); |
http_response_set_header(resp, 0, "Content-Type", "text/plain"); |
http_response_set_header(resp, 1, "Pragma", "no-cache"); |
http_response_set_header(resp, 1, "Pragma", "no-cache"); |
http_response_set_header(resp, 1, "Cache-Control", "no-cache, must-revalidate"); |
http_response_set_header(resp, 1, "Cache-Control", "no-cache, must-revalidate"); |
|
|
pthread_cleanup_push(WebServletRunCleanup, NULL); |
pthread_cleanup_push(WebServletRunCleanup, NULL); |
GIANT_MUTEX_LOCK(); |
GIANT_MUTEX_LOCK(); |
WebRunBinCmd(f, query, priv); | |
| if (!strcmp(path,"/bincmd")) |
| WebRunBinCmd(f, query, priv); |
| else if (!strcmp(path,"/json")) |
| WebShowJSONSummary(f, priv); |
| |
GIANT_MUTEX_UNLOCK(); |
GIANT_MUTEX_UNLOCK(); |
pthread_cleanup_pop(0); |
pthread_cleanup_pop(0); |
|
|
} else if (!strcmp(path,"/") || !strcmp(path,"/cmd")) { |
} else if (!strcmp(path,"/") || !strcmp(path,"/cmd")) { |
http_response_set_header(resp, 0, "Content-Type", "text/html"); |
http_response_set_header(resp, 0, "Content-Type", "text/html"); |
http_response_set_header(resp, 1, "Pragma", "no-cache"); |
http_response_set_header(resp, 1, "Pragma", "no-cache"); |
Line 618 WebServletRun(struct http_servlet *servlet,
|
Line 798 WebServletRun(struct http_servlet *servlet,
|
|
|
pthread_cleanup_push(WebServletRunCleanup, NULL); |
pthread_cleanup_push(WebServletRunCleanup, NULL); |
GIANT_MUTEX_LOCK(); |
GIANT_MUTEX_LOCK(); |
fprintf(f, "<!DOCTYPE HTML " | |
"PUBLIC \"-//W3C//DTD HTML 4.01//EN\" " | fprintf(f, "<!DOCTYPE html>\n"); |
"\"http://www.w3.org/TR/html4/strict.dtd\">\n"); | fprintf(f, "<html>\n"); |
fprintf(f, "<HTML>\n"); | fprintf(f, "<head>\n<title>Multi-link PPP Daemon for FreeBSD (mpd)</title>\n"); |
fprintf(f, "<HEAD><TITLE>Multi-link PPP Daemon for FreeBSD (mpd)</TITLE>\n"); | fprintf(f, "<link rel=\"stylesheet\" href=\"/mpd.css\" type=\"text/css\"/>\n"); |
fprintf(f, "<LINK rel='stylesheet' href='/mpd.css' type='text/css'>\n"); | fprintf(f, "</head>\n<body>\n"); |
fprintf(f, "</HEAD>\n<BODY>\n"); | fprintf(f, "<h1>Multi-link PPP Daemon for FreeBSD</h1>\n"); |
fprintf(f, "<H1>Multi-link PPP Daemon for FreeBSD</H1>\n"); | |
|
|
if (!strcmp(path,"/")) |
if (!strcmp(path,"/")) |
WebShowSummary(f, priv); | WebShowHTMLSummary(f, priv); |
else if (!strcmp(path,"/cmd")) |
else if (!strcmp(path,"/cmd")) |
WebRunCmd(f, query, priv); |
WebRunCmd(f, query, priv); |
|
|
GIANT_MUTEX_UNLOCK(); |
GIANT_MUTEX_UNLOCK(); |
pthread_cleanup_pop(0); |
pthread_cleanup_pop(0); |
|
|
fprintf(f, "</BODY>\n</HTML>\n"); | fprintf(f, "</body>\n</html>\n"); |
} else { |
} else { |
http_response_send_error(resp, 404, NULL); |
http_response_send_error(resp, 404, NULL); |
} |
} |