6 #ifndef __SHEPP_COMMAND_FUNCTIONS_H__
7 #define __SHEPP_COMMAND_FUNCTIONS_H__
24 #include "IoException.H"
49 #endif //USE_IP_MANAGEMENT
106 "Turn peer's certificate check on/off\n");
110 cmd.
reset(
"source",
cmd_source,
"Read and execute file with shepp commands");
117 "Sets client.pem certificate file location");
120 "Sets root.pem certificate file location");
122 cmd.
reset(
"pass",
cmd_pass,
"Sets SSL certificate passphrase");
152 "EPP Contact related actions"
154 "EPP Contact related actions\n"
158 #if USE_IP_MANAGEMENT
159 cmd.
reset(
"asn",
cmd_asn,
"Autonomous System related actions");
165 #endif //USE_IP_MANAGEMENT
189 list<SheppCommand>::const_iterator it;
191 if ((*it).name == name) {
208 inputFile.open(file.c_str());
209 if (inputFile.eof() ==
true ||
210 inputFile.fail() ==
true ||
211 inputFile.bad() ==
true) {
212 printf(
"error reading input file.\n");
218 while (inputFile.good() ==
true) {
220 getline(inputFile, cmdLine);
223 if (cmdLine.size() == 0) {
228 if (cmdLine[0] ==
'#' || cmdLine[0] ==
';') {
233 vector<string> command_args =
237 if (command_args.empty()) {
244 fprintf(stderr,
"Unknown command: %s\n", command_args[0].c_str());
249 if (command_args[0] ==
"runxml") {
250 string rawcmd(cmdLine);
251 rawcmd = rawcmd.substr(command_args[0].length());
252 while (whitespace(rawcmd[0])) {
253 rawcmd = rawcmd.substr(1);
258 printf(
"Enter XML code. Escape character is '^]'.\n");
261 getline(cin, unit, (
char)29);
265 command_args.clear();
266 command_args.push_back(rawcmd);
268 command_args.erase(command_args.begin());
287 if (args.size() != 0) {
301 if (args.size() != 0) {
308 if (new_port !=
"" && _port != atoi(new_port.c_str())) {
309 _port = atoi(new_port.c_str());
314 printf(
"server %s:%d\n",
_server.c_str(), _port);
316 printf(
"no server address given.\n");
329 if (args.size() == 1) {
330 if (_port != atoi(args[0].c_str())) {
331 _port = atoi(args[0].c_str());
335 printf(
"port %d\n", _port);
347 if (args.size() == 1) {
348 if (_client_pem != args[0]) {
349 _client_pem = args[0];
350 printf(
"Warning: changing cetificates requires you to reconnect.\n");
352 }
else if (args.size() > 1) {
353 printf(
"usage: client-pem <file>\n");
357 printf(
"Current client.pem is %s\n", _client_pem.c_str());
368 if (args.size() == 1) {
369 if (_root_pem != args[0]) {
371 printf(
"Warning: changing cetificates requires you to reconnect.\n");
373 }
else if (args.size() > 1) {
374 printf(
"usage: root-pem <file>\n");
378 printf(
"Current root.pem is %s\n", _root_pem.c_str());
390 _passphrase = args[0];
405 if (args.size() == 0) {
407 printf(
"username: %s\n", _user.c_str());
410 printf(
"no username given.\n");
444 _login_new_pw = args[0];
446 _login_new_pw =
getpasswd(
"New Password");
461 printf(
"usage: lang [en|pt]\n");
481 bool exception =
false;
486 if (_peer_crt_check) {
487 _session->enable_cert_common_name_check();
489 _session->disable_cert_common_name_check();
492 _session->connect(_client_pem, _root_pem, _passphrase);
493 printf(
"Connected to %s\n",
_server.c_str());
498 set<string> extensions = greeting->get_extURI();
499 set<string>::iterator it;
500 for (it = extensions.begin(); it != extensions.end(); it++) {
501 if (*it ==
"urn:ietf:params:xml:ns:secDNS-1.0") {
502 _serverSecDnsVersion =
"1.0";
503 }
else if (*it ==
"urn:ietf:params:xml:ns:secDNS-1.1") {
504 _serverSecDnsVersion =
"1.1";
510 printf(
"Greeting received\n");
514 _xmlrsp =
_session->get_last_response();
515 _xmlcmd =
_session->get_last_command();
520 printf(
"ERROR! IO Exception [%d]:\n[%s]\n",
524 printf(
"ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
528 printf(
"ERROR! General Exception [%d]:\n[%s]\n",
538 vector<string> dummy;
552 bool exception =
false;
557 printf(
"disconnected from %s\n",
_server.c_str());
560 printf(
"ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
564 printf(
"ERROR! General Exception [%d]:\n[%s]\n",
573 printf(
"not connected\n");
586 if (args.size() == 0) {
587 if (!_clTrID.empty()) {
588 printf(
"clTrID: %s\n", _clTrID.c_str());
591 printf(
"clTrID: <random>\n");
613 printf(
"XML beautifier is ON\n");
615 printf(
"XML beautifier is OFF\n");
618 }
else if (args.size() > 1) {
619 printf(
"usage: beauty [on|off]\n");
623 if (args[0] ==
"on") {
625 printf(
"XML beautifier now ON\n");
626 }
else if (args[0] ==
"off") {
628 printf(
"XML beautifier now OFF\n");
630 printf(
"usage: beauty [on|off]\n");
646 printf(
"Debug is ON\n");
648 printf(
"Debug is OFF\n");
651 }
else if (args.size() > 1) {
652 printf(
"usage: debug [on|off]\n");
656 if (args[0] ==
"on") {
658 printf(
"Debug now ON\n");
659 }
else if (args[0] ==
"off") {
661 printf(
"Debug now OFF\n");
663 printf(
"usage: beauty [on|off]\n");
679 printf(
"autorsp is ON\n");
681 printf(
"autorsp is OFF\n");
684 }
else if (args.size() > 1) {
685 printf(
"usage: autorsp [on|off]\n");
689 if (args[0] ==
"on") {
691 printf(
"autorsp now ON\n");
692 }
else if (args[0] ==
"off") {
694 printf(
"autorsp now OFF\n");
696 printf(
"usage: autorsp [on|off]\n");
712 printf(
"Keep-alive is ON\n");
714 printf(
"Keep-alive is OFF\n");
717 }
else if (args.size() > 1) {
718 printf(
"usage: keepalive [on|off]\n");
722 if (args[0] ==
"on") {
724 printf(
"Keep-alive now ON\n");
725 }
else if (args[0] ==
"off") {
727 printf(
"Keep-alive now OFF\n");
729 printf(
"usage: keepalive [on|off]\n");
734 alarm(_keepalive_timer);
750 if (_peer_crt_check) {
751 printf(
"Peer's certificate check is ON\n");
753 printf(
"Peer's certificate check is OFF\n");
756 }
else if (args.size() > 1) {
757 printf(
"usage: peer-crt-check [on|off]\n");
761 if (args[0] ==
"on") {
762 _peer_crt_check =
true;
763 printf(
"Peer's certificate check now ON\n");
764 }
else if (args[0] ==
"off") {
765 _peer_crt_check =
false;
766 printf(
"Peer's certificate check now OFF\n");
768 printf(
"usage: peer-crt-check [on|off]\n");
776 static void sig_alrm(
int signo)
778 if (_connected && !_cmd_running) {
781 args.push_back((
string)
"keepalive");
785 alarm(_keepalive_timer);
796 printf(
"not connected\n");
802 string last_command(
"");
805 if (
_session->get_last_command() ==
"") {
813 printf(
"ERROR! XML Exception [%d]:\n[%s]\n", e.
get_code(),
817 printf(
"%s\n",
_session->get_last_command().c_str());
830 printf(
"not connected\n");
844 printf(
"ERROR! XML Exception [%d]:\n[%s]\n", e.
get_code(),
848 printf(
"%s\n", _xmlrsp.c_str());
859 printf(
"Ok! Use 'xmlcmd' and 'xmlrsp' to view command/response "
862 vector<string> dummy;
874 printf(
"not connected\n");
878 bool exception =
false;
884 printf(
"ERROR! Keep-alive is running. Please try again.\n");
890 _xmlrsp =
_session->get_last_response();
891 _xmlcmd =
_session->get_last_command();
893 printf(
"ERROR! EPP Exception [%d]:\n[%s]\n", e.
get_code(),
897 printf(
"ERROR! IO Exception [%d]:\n[%s]\n",
902 printf(
"ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
907 printf(
"ERROR! General Exception [%d]:\n[%s]\n",
913 _cmd_running =
false;
921 alarm(_keepalive_timer);
924 _cmd_running =
false;
935 printf(
"not connected\n");
939 bool exception =
false;
945 printf(
"ERROR! Keep-alive is running. Please try again.\n");
951 _xmlrsp =
_session->get_last_response();
952 _xmlcmd =
_session->get_last_command();
954 printf(
"ERROR! EPP Exception [%d]:\n[%s]\n", e.
get_code(),
958 printf(
"ERROR! IO Exception [%d]:\n[%s]\n",
963 printf(
"ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
968 printf(
"ERROR! General Exception [%d]:\n[%s]\n",
974 _cmd_running =
false;
982 alarm(_keepalive_timer);
985 _cmd_running =
false;
997 printf(
"not connected\n");
1002 printf(
"no username given.\n");
1011 cmd->
add_extURI(
"urn:ietf:params:xml:ns:brorg-1.0");
1014 cmd->
add_extURI(
"urn:ietf:params:xml:ns:brdomain-1.0");
1016 #if USE_IP_MANAGEMENT
1017 cmd->
add_extURI(
"urn:ietf:params:xml:ns:ipnetwork-1.0");
1018 cmd->
add_extURI(
"urn:ietf:params:xml:ns:asn-1.0");
1021 cmd->
add_extURI(
"urn:ietf:params:xml:ns:secDNS-1.0");
1023 cmd->
add_extURI(
"urn:ietf:params:xml:ns:secDNS-1.1");
1033 if (_lang !=
"" && _lang !=
"en") {
1052 printf(
"not connected\n");
1073 printf(
"not connected\n");
1078 !(args.size() == 1 && args[0] ==
"keepalive")) {
1079 printf(
"ERROR! Keep-alive is running. Please try again.\n");
1083 bool exception =
false;
1087 _cmd_running =
true;
1092 printf(
"Sending EPP Hello\n");
1097 _xmlrsp =
_session->get_last_response();
1098 _xmlcmd =
_session->get_last_command();
1101 printf(
"ERROR! EPP Exception [%d]:\n[%s]\n", e.
get_code(),
1105 printf(
"ERROR! IO Exception [%d]:\n[%s]\n",
1110 printf(
"ERROR! Transport Exception [%d]:\n[%s]\n[%s]\n",
1115 printf(
"ERROR! General Exception [%d]:\n[%s]\n",
1122 _cmd_running =
false;
1134 alarm(_keepalive_timer);
1136 _cmd_running =
false;
1164 list<SheppCommand>::const_iterator it;
1166 printf(
"%-16s %s\n", (*it).name.c_str(), (*it).brief.c_str());
1189 printf(
"%s:", prompt.c_str());
1192 struct termios old_opts;
1193 struct termios new_opts;
1198 res = tcgetattr(STDIN_FILENO, &old_opts);
1202 memcpy(&new_opts, &old_opts,
sizeof(new_opts));
1203 new_opts.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
1204 new_opts.c_lflag |= ICANON;
1205 tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
1208 getline(cin, passwd);
1212 res = tcsetattr(STDIN_FILENO, TCSANOW, &old_opts);
1218 #endif //__SHEPP_COMMAND_FUNCTIONS_H__
LoginCmd * get_command()
Returns raw pointer to the command.
Definition: Login.H:57
Transport Exception Class.
Definition: TransportException.H:17
int cmd_xmlrsp(vector< string > &)
Shows last XML response.
Definition: SheppCommandFunctions.H:827
int cmd_autorsp(vector< string > &)
Turns auto-show response ON and OFF.
Definition: SheppCommandFunctions.H:675
StrUtil Class: String Manipulation Utilities.
Definition: StrUtil.H:26
const SheppCommand * find_command(string name)
Given a word check if it's a valid SheppCommand.
Definition: SheppCommandFunctions.H:187
void set_new_pw(const string &new_pw)
Sets new password.
Definition: LoginCmd.H:44
static int split(string input, string &first, string &second, string splitter, bool relaxed=false)
Definition: SheppStrUtil.H:120
shepp compiler definitions and global variables
int cmd_poll(vector< string > &)
main poll command
Definition: PollFunctions.H:44
int cmd_keepalive(vector< string > &)
Turns keep-alive ON and OFF.
Definition: SheppCommandFunctions.H:708
int cmd_brorg(vector< string > &args)
main brorg command
Definition: BrOrgFunctions.H:1002
int cmd_contact(vector< string > &)
main contact command
Definition: ContactFunctions.H:820
shepp specific objects information setting class
int cmd_connect(vector< string > &)
Connects to previously specified server and port.
Definition: SheppCommandFunctions.H:475
string getpasswd(string prompt)
Function to read from stdin without echoing.
Definition: SheppCommandFunctions.H:1188
int cmd_asn_reserve(vector< string > &args)
main asn reserve command
Definition: AsnReserveFunctions.H:212
int cmd_domain(vector< string > &)
main domain command
Definition: DomainFunctions.H:1296
EPP LoginCmd Class.
Definition: LoginCmd.H:17
int cmd_xmlcmd(vector< string > &)
Shows last XML command.
Definition: SheppCommandFunctions.H:793
static int iso88591_to_utf8(const string &iso88591, string &utf8)
int cmd_lang(vector< string > &)
Sets text language based on input command-line.
Definition: SheppCommandFunctions.H:458
static vector< string > parse_line(char *line)
Given a line, split its words by white space into a string vector (shepp)
Definition: SheppStrUtil.H:63
int cmd_client_pem(vector< string > &)
Sets client.pem certificate file location.
Definition: SheppCommandFunctions.H:345
shepp object information screen printing class
Transport Exception Class.
int cmd_login_new_pw(vector< string > &)
Sets new EPP login password based on input command-line.
Definition: SheppCommandFunctions.H:441
isfunc_t * function
Function to be called.
Definition: SheppCommand.H:49
EPP Action Class.
Definition: Action.H:24
void print_cmd_sent_ok()
Prints "command sent ok" message.
Definition: SheppCommandFunctions.H:856
XML Exception Class.
Definition: XmlException.H:17
int cmd_runxml(vector< string > &)
Run XML input command.
Definition: SheppCommandFunctions.H:932
int cmd_beauty(vector< string > &)
Turns XML beautifier ON and OFF.
Definition: SheppCommandFunctions.H:609
void set_pw(const string &pw)
Sets password.
Definition: LoginCmd.H:38
int cmd_logout(vector< string > &)
Send an EPP Logout.
Definition: SheppCommandFunctions.H:1049
int cmd_pass(vector< string > &)
Sets SSL certificate passphrase based on input command-line.
Definition: SheppCommandFunctions.H:387
int cmd_source(vector< string > &)
Definition: SheppCommandFunctions.H:285
void add_extURI(const string &extURI)
Adds an object extension supported by the client.
Definition: LoginCmd.H:92
int cmd_login(vector< string > &)
Send an EPP Login.
Definition: SheppCommandFunctions.H:994
General Exception Class.
Definition: GeneralException.H:19
int cmd_peer_crt_check(vector< string > &)
Turn peer's certificate check ON and OFF.
Definition: SheppCommandFunctions.H:747
int cmd_port(vector< string > &)
Sets server port based on input command-line.
Definition: SheppCommandFunctions.H:327
string _server
Global connection setup variables.
Definition: SheppGlobal.H:40
auto_ptr< Session > _session
Reference to session.
Definition: SheppGlobal.H:71
int cmd_about(vector< string > &)
Prints version information.
Definition: SheppCommandFunctions.H:1177
string get_msg() const
Returns the Exception Message.
Definition: GeneralException.H:43
int process_action(Action &act)
Send and EPP Action.
Definition: SheppCommandFunctions.H:871
int cmd_server(vector< string > &)
Sets server address [and port] based on input command-line.
Definition: SheppCommandFunctions.H:299
static char * trim(char *line)
Removes leading and ending white spaces from line (shepp)
Definition: SheppStrUtil.H:30
int cmd_root_pem(vector< string > &)
Sets root.pem certificate file location.
Definition: SheppCommandFunctions.H:366
int cmd_quit(vector< string > &)
Leaves shepp.
Definition: SheppCommandFunctions.H:1148
void reset(string name, isfunc_t *function, string brief)
Reinitializes all object attributes.
Definition: SheppCommand.H:38
EPP Login Class.
Definition: Login.H:23
string xml_beautifier(const string &input_txt)
XML Beautifier.
void init_commands()
Populates set of available commands.
Definition: SheppCommandFunctions.H:82
int cmd_ipnetwork(vector< string > &args)
main ipnetwork command
Definition: IpNetworkFunctions.H:1048
int cmd_hello(vector< string > &)
Send an EPP HELLO.
Definition: SheppCommandFunctions.H:1070
SheppCommand class: command name, function and a brief description.
Definition: SheppCommand.H:16
string get_low_level_msg() const
Return Low Level Error Message.
Definition: GeneralException.H:49
int cmd_login_pw(vector< string > &)
Sets EPP login password based on input command-line.
Definition: SheppCommandFunctions.H:425
int executeInputFile(const string &file)
Definition: SheppCommandFunctions.H:205
int cmd_help(vector< string > &)
Prints help.
Definition: SheppCommandFunctions.H:1162
int get_code() const
Returns the Exception Code.
Definition: GeneralException.H:37
EPP Session Class.
Definition: Session.H:30
void set_lang(const string &lang)
Sets text language.
Definition: LoginCmd.H:56
EPP Greeting Class.
Definition: Greeting.H:21
int cmd_def_reg(vector< string > &)
main defensive registration command
Definition: DefRegFunctions.H:657
int cmd_disconnect(vector< string > &)
Closes connection.
Definition: SheppCommandFunctions.H:549
IO Exception Class.
Definition: IoException.H:17
void about()
shepp build info
Definition: SheppGlobal.H:74
int cmd_asn(vector< string > &args)
main asn command
Definition: AsnFunctions.H:674
void set_clID(const string &clID)
Sets Client ID.
Definition: LoginCmd.H:32
int cmd_debug(vector< string > &)
Turns debug messages ON and OFF.
Definition: SheppCommandFunctions.H:642
EPP command-line shell client string manipulation routines class.
LIBEPP_NICBR_NS_USE list< SheppCommand > _commands
Global container of available commands.
Definition: SheppGlobal.H:37
EPP Logout Class.
Definition: Logout.H:23
int cmd_cltrid(vector< string > &)
Sets the client transaction id for the next commands.
Definition: SheppCommandFunctions.H:584
int cmd_user(vector< string > &)
Sets login user based on input command-line.
Definition: SheppCommandFunctions.H:403
EPP Exception Class.
Definition: EppException.H:17