mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-14 00:24:05 +00:00
merge xml_translate() and html_translate() into one function since
they do similar things. Add a small form on top of the html output so request like http://foo:8088/asterisk/manager will suggest you what to do. Note: i suspect there is still a bug somewhere in the session matching code, as sometimes you have to login twice in order for the following commands to be recognised. Apart from this, the cli now is basically usable from a web form! git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45475 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -285,7 +285,7 @@ static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int mod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *xml_translate(char *in, struct ast_variable *vars)
|
static char *__xml_translate(char *in, struct ast_variable *vars, int xml)
|
||||||
{
|
{
|
||||||
struct ast_variable *v;
|
struct ast_variable *v;
|
||||||
char *dest = NULL;
|
char *dest = NULL;
|
||||||
@@ -335,10 +335,11 @@ static char *xml_translate(char *in, struct ast_variable *vars)
|
|||||||
ast_verbose("inobj %d in_data %d line <%s>\n", inobj, in_data, val);
|
ast_verbose("inobj %d in_data %d line <%s>\n", inobj, in_data, val);
|
||||||
if (ast_strlen_zero(val)) {
|
if (ast_strlen_zero(val)) {
|
||||||
if (in_data) { /* close data */
|
if (in_data) { /* close data */
|
||||||
ast_build_string(&tmp, &len, "'");
|
ast_build_string(&tmp, &len, xml ? "'" : "</td></tr>\n");
|
||||||
in_data = 0;
|
in_data = 0;
|
||||||
}
|
}
|
||||||
ast_build_string(&tmp, &len, " /></response>\n");
|
ast_build_string(&tmp, &len, xml ? " /></response>\n" :
|
||||||
|
"<tr><td colspan=\"2\"><hr></td></tr>\r\n");
|
||||||
inobj = 0;
|
inobj = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -356,77 +357,41 @@ static char *xml_translate(char *in, struct ast_variable *vars)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!inobj) {
|
if (!inobj) {
|
||||||
ast_build_string(&tmp, &len, "<response type='object' id='%s'><%s", dest, objtype);
|
if (xml)
|
||||||
|
ast_build_string(&tmp, &len, "<response type='object' id='%s'><%s", dest, objtype);
|
||||||
|
else
|
||||||
|
ast_build_string(&tmp, &len, "<body>\n");
|
||||||
inobj = 1;
|
inobj = 1;
|
||||||
}
|
}
|
||||||
if (!in_data) {
|
if (!in_data) {
|
||||||
ast_build_string(&tmp, &len, " ");
|
ast_build_string(&tmp, &len, xml ? " " : "<tr><td>");
|
||||||
xml_copy_escape(&tmp, &len, var, 1 | 2);
|
xml_copy_escape(&tmp, &len, var, xml ? 1 | 2 : 0);
|
||||||
ast_build_string(&tmp, &len, "='");
|
ast_build_string(&tmp, &len, xml ? "='" : "</td><td>");
|
||||||
xml_copy_escape(&tmp, &len, val, 0);
|
xml_copy_escape(&tmp, &len, val, 0);
|
||||||
if (!strcmp(var, "Opaque-data")) {
|
if (!strcmp(var, "Opaque-data")) {
|
||||||
in_data = 1;
|
in_data = 1;
|
||||||
} else {
|
} else {
|
||||||
ast_build_string(&tmp, &len, "'");
|
ast_build_string(&tmp, &len, xml ? "'" : "</td></tr>\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xml_copy_escape(&tmp, &len, val, 0);
|
xml_copy_escape(&tmp, &len, val, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inobj)
|
if (inobj)
|
||||||
ast_build_string(&tmp, &len, " /></response>\n");
|
ast_build_string(&tmp, &len, xml ? " /></response>\n" : "</body>\n");
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *xml_translate(char *in, struct ast_variable *vars)
|
||||||
|
{
|
||||||
|
return __xml_translate(in, vars, 1);
|
||||||
|
}
|
||||||
|
|
||||||
static char *html_translate(char *in)
|
static char *html_translate(char *in)
|
||||||
{
|
{
|
||||||
int x;
|
return __xml_translate(in, NULL, 0);
|
||||||
int colons = 0;
|
|
||||||
int breaks = 0;
|
|
||||||
size_t len;
|
|
||||||
int count = 1;
|
|
||||||
char *tmp, *var, *val, *out;
|
|
||||||
|
|
||||||
for (x=0; in[x]; x++) {
|
|
||||||
if (in[x] == ':')
|
|
||||||
colons++;
|
|
||||||
if (in[x] == '\n')
|
|
||||||
breaks++;
|
|
||||||
}
|
|
||||||
len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
|
|
||||||
out = ast_malloc(len);
|
|
||||||
if (!out)
|
|
||||||
return 0;
|
|
||||||
tmp = out;
|
|
||||||
while (*in) {
|
|
||||||
var = in;
|
|
||||||
while (*in && (*in >= 32))
|
|
||||||
in++;
|
|
||||||
if (*in) {
|
|
||||||
if ((count % 4) == 0){
|
|
||||||
ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
while (*in && (*in < 32)) {
|
|
||||||
*in = '\0';
|
|
||||||
in++;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
val = strchr(var, ':');
|
|
||||||
if (val) {
|
|
||||||
*val = '\0';
|
|
||||||
val++;
|
|
||||||
if (*val == ' ')
|
|
||||||
val++;
|
|
||||||
ast_build_string(&tmp, &len, "<tr><td>%s</td><td>%s</td></tr>\r\n", var, val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static struct ast_manager_user *ast_get_manager_by_name_locked(const char *name)
|
static struct ast_manager_user *ast_get_manager_by_name_locked(const char *name)
|
||||||
{
|
{
|
||||||
struct ast_manager_user *user = NULL;
|
struct ast_manager_user *user = NULL;
|
||||||
@@ -2394,7 +2359,7 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
|
|||||||
{
|
{
|
||||||
struct mansession *s = NULL;
|
struct mansession *s = NULL;
|
||||||
unsigned long ident = 0;
|
unsigned long ident = 0;
|
||||||
char workspace[512];
|
char workspace[1024];
|
||||||
char cookie[128];
|
char cookie[128];
|
||||||
size_t len = sizeof(workspace);
|
size_t len = sizeof(workspace);
|
||||||
int blastaway = 0;
|
int blastaway = 0;
|
||||||
@@ -2456,8 +2421,14 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
|
|||||||
if (format == FORMAT_XML) {
|
if (format == FORMAT_XML) {
|
||||||
ast_build_string(&c, &len, "<ajax-response>\n");
|
ast_build_string(&c, &len, "<ajax-response>\n");
|
||||||
} else if (format == FORMAT_HTML) {
|
} else if (format == FORMAT_HTML) {
|
||||||
|
#define ROW_FMT "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s</td></tr>\r\n"
|
||||||
|
#define TEST_STRING \
|
||||||
|
"<form action=\"manager\">action: <input name=\"action\"> cmd <input name=\"command\"><br>\
|
||||||
|
user <input name=\"username\"> pass <input type=\"password\" name=\"secret\"><br>
|
||||||
|
<input type=\"submit\"></form>"
|
||||||
ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n");
|
ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n");
|
||||||
ast_build_string(&c, &len, "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\"><h1> Manager Tester</h1></td></tr>\r\n");
|
ast_build_string(&c, &len, ROW_FMT, "<h1> Manager Tester</h1>");
|
||||||
|
ast_build_string(&c, &len, ROW_FMT, TEST_STRING);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
char template[32];
|
char template[32];
|
||||||
|
Reference in New Issue
Block a user