Commit 291533dd authored by frtabu's avatar frtabu

more commands implementation in backend

parent e18753db
......@@ -512,6 +512,8 @@ int process_command(char *buf) {
}
for(j=0; telnetparams.CmdParsers[i].cmd[j].cmdfunc != NULL ; j++) {
if ( telnetparams.CmdParsers[i].cmd[j].cmdflags & TELNETSRV_CMDFLAG_WEBSRVONLY )
continue;
client_printf(" %s %s %s\n",
telnetparams.CmdParsers[i].module,telnetparams.CmdParsers[i].cmd[j].cmdname,
telnetparams.CmdParsers[i].cmd[j].helpstr);
......@@ -542,6 +544,8 @@ int process_command(char *buf) {
} else {
for (k=0 ; telnetparams.CmdParsers[i].cmd[k].cmdfunc != NULL ; k++) {
if (strncasecmp(cmd, telnetparams.CmdParsers[i].cmd[k].cmdname,sizeof(telnetparams.CmdParsers[i].cmd[k].cmdname)) == 0) {
if (telnetparams.CmdParsers[i].cmd[k].cmdflags & TELNETSRV_CMDFLAG_WEBSRVONLY)
continue;
if (telnetparams.CmdParsers[i].cmd[k].qptr != NULL) {
notifiedFIFO_elt_t *msg =newNotifiedFIFO_elt(sizeof(telnetsrv_qmsg_t),0,NULL,NULL);
telnetsrv_qmsg_t *cmddata=NotifiedFifoData(msg);
......
......@@ -83,6 +83,7 @@ typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg);
#define TELNETSRV_CMDFLAG_GETWEBDATA (1<<1) // When called from web server, use the getdata variant of the function
#define TELNETSRV_CMDFLAG_TELNETONLY (1<<2) // Only for telnet client connections
#define TELNETSRV_CMDFLAG_WEBSRVONLY (1<<3) // Only for web server connections
#define TELNETSRV_CMDFLAG_CONFEXEC (1<<4) // Ask for confirm before exec
typedef struct cmddef {
char cmdname[TELNET_CMD_MAXSIZE];
char helpstr[TELNET_HELPSTR_SIZE];
......
......@@ -213,12 +213,46 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
logsdata->lines[i].val[0]= (char *)(g_log->log_component[i].name);
logsdata->lines[i].val[1]=map_int_to_str(log_level_names,(g_log->log_component[i].level>=0)?g_log->log_component[i].level:g_log->log_component[i].savedlevel);
logsdata->lines[i].val[2]=(g_log->log_component[i].level>=0)?0xFFFFFFFF:NULL;
logsdata->lines[i].val[2]=(g_log->log_component[i].level>=0)?(char *)0xFFFFFFFF:NULL;
logsdata->lines[i].val[3]=(g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout";
}
}
}
return 0;
}
}
}
if (strcasestr(cmdbuff,"dbgopt") != NULL) {
webdatadef_t *logsdata = ( webdatadef_t *) data;
logsdata->numcols=3;
logsdata->numlines=0;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"module");
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING;
snprintf(logsdata->columns[1].coltitle,TELNET_CMD_MAXSIZE,"debug");
logsdata->columns[1].coltype = TELNET_CHECKVAL_BOOL;
snprintf(logsdata->columns[2].coltitle,TELNET_CMD_MAXSIZE,"dump");
logsdata->columns[2].coltype = TELNET_CHECKVAL_BOOL;
for (int i=0; log_maskmap[i].name != NULL ; i++) {
logsdata->numlines++;
logsdata->lines[i].val[0]= log_maskmap[i].name;
logsdata->lines[i].val[1]= (g_log->debug_mask & log_maskmap[i].value)?(char *)0xFFFFFFFF:NULL;
logsdata->lines[i].val[2]=(g_log->dump_mask & log_maskmap[i].value)?(char *)0xFFFFFFFF:NULL;
}
}
if (strcasestr(cmdbuff,"logopt") != NULL) {
webdatadef_t *logsdata = ( webdatadef_t *) data;
logsdata->numcols=2;
logsdata->numlines=0;
snprintf(logsdata->columns[0].coltitle,TELNET_CMD_MAXSIZE,"option");
logsdata->columns[0].coltype = TELNET_VARTYPE_STRING;
snprintf(logsdata->columns[1].coltitle,TELNET_CMD_MAXSIZE,"enabled");
logsdata->columns[1].coltype = TELNET_CHECKVAL_BOOL;
for (int i=0; log_options[i].name != NULL; i++) {
logsdata->numlines++;
logsdata->lines[i].val[0]=log_options[i].name;
logsdata->lines[i].val[1]=(g_log->flag & log_options[i].value)?(char *)0xFFFFFFFF:NULL;
}
}
return 0;
}
int proccmd_show(char *buf, int debug, telnet_printfunc_t prnt)
......
......@@ -74,10 +74,13 @@ telnetshell_vardef_t proc_vardef[] = {
telnetshell_cmddef_t proc_cmdarray[] = {
{"show","loglvl|thread|config", proccmd_show,{(webfunc_t)proccmd_websrv_getdata},TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"show","loglvl|thread|config", proccmd_show,{(webfunc_t)proccmd_websrv_getdata},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"log","(enter help for details)", proccmd_log, {NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"show loglvl","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"show logopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"show dbgopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL},
{"thread","(enter help for details)", proccmd_thread,{(webfunc_t)proccmd_websrv_getdata},0,NULL},
{"exit","", proccmd_exit},
{"exit","", proccmd_exit,{NULL},TELNETSRV_CMDFLAG_CONFEXEC,NULL},
{"","",NULL},
};
#else
......
......@@ -160,7 +160,7 @@ void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata)
// else if (wdata->columns[j].coltype == TELNET_VARTYPE_DOUBLE)
// jval=json_real((double)(wdata->lines[i].val[j]));
else
jval=json_integer((int)(wdata->lines[i].val[j]));
jval=json_integer((long)(wdata->lines[i].val[j]));
json_object_set_new(kv, wdata->columns[j].coltitle, jval);
}
json_array_append_new(jdata,kv);
......@@ -168,6 +168,43 @@ void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata)
json_t *jbody=json_pack("{s:o,s:o}","display",json_string(""),"logs",jdata);
websrv_jbody(response,jbody);
}
/*--------------------------------------------------------------------------------------------------*/
/* format a json response from a result table returned from a call to a telnet server command */
void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wdata) {
/* json_t *jcols = json_array();
json_t *jdata = json_array();
char *coltype;
for (int i=0; i<wdata->numcols; i++) {
json_t *jval;
if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL)
coltype="boolean";
else if (wdata->columns[j].coltype == TELNET_VARTYPE_STRING)
coltype="string";
else
coltype="number";
json_t acol=json_pack("{name:s,type:s,modifiable:b}",wdata->columns[j].coltitle,coltype,);
json_array_append_new(jcols,acol);
}
for (int i=0; i<wdata->numlines ; i++) {
json_t *kv=json_object();
for (int j=0; j<wdata->numcols; j++) {
json_t *jval;
if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL)
jval=json_boolean(wdata->lines[i].val[j]);
else if (wdata->columns[j].coltype == TELNET_VARTYPE_STRING)
jval=json_string(wdata->lines[i].val[j]);
// else if (wdata->columns[j].coltype == TELNET_VARTYPE_DOUBLE)
// jval=json_real((double)(wdata->lines[i].val[j]));
else
jval=json_integer((long)(wdata->lines[i].val[j]));
json_object_set_new(kv, wdata->columns[j].coltitle, jval);
}
json_array_append_new(jdata,kv);
}
json_t *jbody=json_pack("{s:o,s:o}","columns",,"rows",);
websrv_jbody(response,jbody);*/
}
/*----------------------------------------------------------------------------------------------------------*/
/* callbacks and utility functions to stream a file */
char * websrv_read_file(const char * filename) {
......@@ -403,7 +440,7 @@ int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestr
if ( cmd->cmdflags & TELNETSRV_CMDFLAG_GETWEBDATA ) {
webdatadef_t wdata;
memset(&wdata,0,sizeof(wdata));
cmd->webfunc_getdata(cmd->helpstr,websrvparams.dbglvl,(webdatadef_t *)&wdata);
cmd->webfunc_getdata(cmd->cmdname,websrvparams.dbglvl,(webdatadef_t *)&wdata);
websrv_getdata_response(response,&wdata);
} else {
websrv_printf_start(response,16384);
......@@ -528,10 +565,18 @@ int websrv_callback_get_softmodemcmd(const struct _u_request * request, struct _
LOG_I(UTIL,"[websrv] received %s commands request\n", modulestruct->module);
json_t *modulesubcom = json_array();
for(int j=0; modulestruct->cmd[j].cmdfunc != NULL ; j++) {
if(strcasecmp("help",modulestruct->cmd[j].cmdname) != 0) {
json_t *acmd =json_pack( "{s:s}", "name",modulestruct->cmd[j].cmdname);
json_array_append(modulesubcom , acmd);
if(strcasecmp("help",modulestruct->cmd[j].cmdname) == 0 || ( modulestruct->cmd[j].cmdflags & TELNETSRV_CMDFLAG_TELNETONLY ) ) {
continue;
}
json_t *acmd;
if (modulestruct->cmd[j].cmdflags & TELNETSRV_CMDFLAG_CONFEXEC) {
char confstr[256];
snprintf(confstr,sizeof(confstr),"Execute %s ?",modulestruct->cmd[j].cmdname);
acmd =json_pack( "{s:s,s:s}", "name",modulestruct->cmd[j].cmdname,"confirm", confstr);
} else {
acmd =json_pack( "{s:s}", "name",modulestruct->cmd[j].cmdname);
}
json_array_append(modulesubcom , acmd);
}
if (modulesubcom==NULL) {
LOG_E(UTIL,"[websrv] cannot encode modulesubcom response for %s\n",modulestruct->module);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment