DRDE/APIG/client/commander.cpp

203 lines
5.6 KiB
C++
Raw Normal View History

2014-01-11 19:34:15 +00:00
#include "ausreg-cd.h"
int is_numeric(const char *p) { int i = strlen(p),j=0;
if (*p) {
char c;
while ((c=*p++)) { j++;
if (!isdigit(c)) {
if (j == i) return 2;
else return 0;
}
}
return 1;
}
return 0;
}
void mdCommander::driver() {
bool rc;
2014-01-11 19:34:15 +00:00
char instrinsic[16],next,rawString[4096],work[4096];
const char *mdErrCode = "";
int i,commandLength;
greet();
while(acceptingInput) {
putchar('>');
next=0;
i=0;
memset(rawString,0,sizeof(rawString));
while(next != '\012') {
next = getchar();
rawString[i++] = next;
if (i > (sizeof(rawString) - 1)) {
puts("Max length exceeded!");
continue;
}
}
if (!strlen(rawString)) continue;
2014-01-11 19:34:15 +00:00
if (strlen(rawString) == 2) {
switch(rawString[0]) {
case '?': help();
break;
case 'e': eppMainMenu();
break;
case '!': sendCommand();
break;
case 'X': flushCommand();
break;
case 'a': acMainMenu();
break;
case 'c': check();
break;
case 'i': info();
break;
case 't': transferCheck();
break;
case 'C': create();
break;
case 'R': renew();
break;
case 'U': update();
break;
case 'D': trash();
break;
case 'T': transfer();
break;
}
continue;
}
if (strlen(rawString) == 3) {
if (!strcmp(rawString,"??")) {
showCommand();
continue;
}
}
if (is_numeric(rawString) == 2) {
rawString[strlen(rawString)] = 0;
mdStdDevIdx = atoi(rawString);
continue;
}
if (strlen(rawString) >= 4 && strlen(rawString) <= 6 )
{if (!strcmp(rawString,"log\n")) {
2014-01-11 19:34:15 +00:00
system("less /tmp/ausreg-cd.log");
continue;
}
if (!strcmp(rawString,"done\n")) {
return;
}
if (!strcmp(rawString,"mdapi\n")) {
system("mdclient ");
continue;
}
if (!strcmp(rawString,"quit\n")) {
thisConfig->terminateRequest = true;
return;
}
if (!strcmp(rawString,"mdapi\n")) {
continue;
}
if (strlen(rawString) < 3) {
puts("That SCPI command is too short!");
continue;
}
2014-01-11 19:34:15 +00:00
rc = epp(rawString);
if (!rc) puts("Command transmitted: OK.");
else printf("Command result: %s.",mdErrCode);
continue;
}
2014-01-11 19:34:15 +00:00
}
}
2014-01-11 19:34:15 +00:00
void mdCommander::greet() {
2014-01-11 19:34:15 +00:00
puts(" AC Commander ");
puts("Enter ? for help or an AC command");
acceptingInput = true;
2014-01-11 19:34:15 +00:00
EPPmode = true;
currentDevice = std::string("ALX");
}
void mdCommander::help() {
2014-01-11 19:34:15 +00:00
const char *banner = "\n" CD_NAME " " CD_VERSION " compiled on " __DATE__ " @ " __TIME__ " (%d)\n\n";
system("clear");
printf(banner,thisConfig->shellProcess);
2014-01-11 19:34:15 +00:00
printf(" target acEPPDevIdx-> %d this acEPPDevIdx: %d \n\n",0,mdStdDevIdx);
puts(" ? - display this screen");
2014-01-11 19:34:15 +00:00
puts(" ! - send the pending command");
puts(" ?? - display the pending command");
puts(" X - discard the pending command");
puts(" <n> - make <n> (an integer) the target acEPPDevIdx");
puts(" done - terminate this command loop but not ausreg-cd");
puts(" e - standard EPP command menu");
puts(" a - AC system control menu");
puts(" log - display this cliever's log");
puts(" rlog - pull and display the master daemon log");
puts(" quit - terminate this process tree\n\n");
puts("Any command valid outside command data loop(>>).");
}
2014-01-11 19:34:15 +00:00
void mdCommander::eppMainMenu() {
const char *banner = "\n" CD_NAME " " CD_VERSION " compiled on " __DATE__ " @ " __TIME__ " (%d)\n\n";
system("clear");
printf(banner,thisConfig->shellProcess);
printf(" target acEPPDevIdx-> %d this acEPPDevIdx: %d \n\n",0,mdStdDevIdx);
puts(" Queries \n");
puts(" c - check");
puts(" i - info");
puts(" t - transfer\n");
puts(" Commands \n");
puts(" C - create");
puts(" R - renew");
puts(" U - update\n");
puts(" D - delete");
puts(" T - transfer");
}
void mdCommander::acMainMenu() {
const char *banner = "\n" CD_NAME " " CD_VERSION " compiled on " __DATE__ " @ " __TIME__ " (%d)\n\n";
system("clear");
printf(banner,thisConfig->shellProcess);
printf(" target acEPPDevIdx-> %d this acEPPDevIdx: %d \n\n",0,mdStdDevIdx);
puts(" Directives \n\n");
puts(" RST - followed by quit resets entire AC system");
}
bool mdCommander::epp(char *cmd) {
char *command,work[256];
bool isDirect=false,rc=true;
if (!mdStdDevIdx && !strncmp(cmd,"RST",3)) {
mdDG mdg;
mdg.dg.hdr.sourceHandle = thisCliever->myHandle;
mdg.dg.hdr.payloadSize = 0;
mdg.dg.hdr.msgType = MDDG_CDRESET;
if (thisCliever->fg->send(mdg.dg)) rc = false;
}
return rc;
}
2014-01-11 19:34:15 +00:00
void mdCommander::check(){};
void mdCommander::create(){};
void mdCommander::flushCommand(){};
void mdCommander::info(){};
void mdCommander::renew(){};
void mdCommander::sendCommand(){};
void mdCommander::showCommand(){};
void mdCommander::trash(){};
void mdCommander::transfer(){};
void mdCommander::transferCheck(){};
void mdCommander::update(){};