#include #include #include #include "netadm.h" static bool debug = false; int main (int argc, char *argv[]) { glocal const char *host = NULL; glocal const char *passwd = NULL; glocal const char *secret = NULL; glocal const char *port = "98"; (argc,argv); setproginfo ("netadmtest",0,"test netadm over port 98"); setarg ('d',"debug","Turn on debug",debug,false); setarg ('h',"host","Host to contact",glocal.host,true); setarg ('p',"password","Password needed to connect",glocal.passwd,false); setarg ('P',"port","Port to use instead of 98",glocal.port,false); setarg ('s',"secret","Secret needed to connect",glocal.host,false); int ret = -1; if (glocal.secret == NULL && glocal.passwd == NULL){ fprintf (stderr,"you must provide either a secret or password\n"); }else{ glocal int step = 0; glocal SSTRINGS datas; glocal int argc = argc; glocal char **argv = argv; (glocal.host,glocal.port,10); // Do nothing, wait for version send ("GET /htmlmod:netadm:\r\n\r\n"); SSTRINGS tb; str_splitline (line,' ',tb); int nb = tb.getnb(); if (debug) fprintf (stderr,"receive %d %s\n",nb,line); if (nb < 2){ fprintf (stderr,"Strange line: %s\n",line); }else{ int command = tb.getitem(0)->getval(); const char *endline = str_skip(str_skipdig(line)); if (command == PROTO_C_DATA){ glocal.datas.add (str_skip(str_skipdig(line))); printf ("Data: %s\n",endline); }else if (command == PROTO_C_PROMPT){ glocal.step++; if (glocal.step == 1){ send ("version 1\n"); }else if (glocal.step == 2){ if (glocal.passwd != NULL){ sendf ("password %s\n",glocal.passwd); }else{ sendf ("password %s\n",glocal.secret); } }else if (glocal.step - 3 >= glocal.argc){ send ("quit\n"); end = true; }else{ const char *cmd = glocal.argv[glocal.step-3]; fprintf (stderr,"Sending %s\n",cmd); sendf ("%s\n",cmd); } }else if (command == PROTO_C_COMMENT){ printf ("Comment: %s\n",endline); }else if (command == PROTO_C_ACK){ printf ("Ack: %s\n",endline); }else if (command == PROTO_C_ERROR){ fprintf (stderr,"ERROR: %s\n",endline); }else{ fprintf (stderr,"Unknown: %s\n",line); } } } return ret; return 0; }