libepp_nicbr
IpNetworkFunctions.H
Go to the documentation of this file.
1 /* ${copyright}$ */
2 /* $Id: IpNetworkFunctions.H 1273 2014-12-08 15:41:50Z gustavo $ */
6 #ifndef __IPNETWORK_FUNCTIONS_H__
7 #define __IPNETWORK_FUNCTIONS_H__
9 
10 #include "IpNetworkCheck.H"
11 #include "IpNetworkCreate.H"
12 #include "IpNetworkDelete.H"
13 #include "IpNetworkInfo.H"
14 #include "IpNetworkRenew.H"
15 #include "IpNetworkTransfer.H"
16 #include "IpNetworkUpdate.H"
17 
19 
24 int cmd_ipnetwork_help(string error_msg, string specific = "")
25 {
26  if (error_msg != "") {
27  printf("error: %s\n", error_msg.c_str());
28  }
29 
30  printf("ipnetwork command syntax help:\n");
31  printf("\n");
32 
33  if (specific == "" || specific == "check") {
34  printf(" check <<v4|v6>=<startAddr>-<endAddr>> "
35  "[<v4|v6>=<startAddr>-<endAddr> ...]\n");
36  printf("\n");
37  }
38 
39  if (specific == "" || specific == "create") {
40  printf(" create <v4|v6>=<startAddr>-<endAddr> <-o organization> "
41  "[-t allocType]\n"
42  " [-reserve reserveType [-comment reserveComment]]\n"
43  " [-a asn] [-contact type=value ...] \n"
44  " [-rev-ns "
45  "<v4|v6>=<startAddr>-<endAddr>,hostname[,hostname ...] ...]\n"
46  " [-ds <v4|v6>=<startAddr>-<endAddr> "
47  "<keyTag> <alg> <digestType> <digest>] ");
48  printf("\n");
49  }
50 
51  if (specific == "" || specific == "delete") {
52  printf(" delete <-roid repository-id>\n");
53  printf("\n");
54  }
55 
56  if (specific == "" || specific == "info") {
57  printf(" info <<v4|v6>=<startAddr>-<endAddr>> [-roid repository-id]\n");
58  printf("\n");
59  }
60 
61  if (specific == "" || specific == "renew") {
62  printf(" renew <-roid repository-id> <-expdate expDate> "
63  "[-period time:unit]\n");
64  printf("\n");
65  }
66 
67  if (specific == "" || specific == "transfer") {
68  printf(" transfer <-op [query|request]> <-roid repository-id>\n");
69  printf("\n");
70  }
71 
72  if (specific == "" || specific == "update") {
73  printf(" update <roid> [-add-contact type=value ...]\n"
74  " [-rem-contact type=value ...] [-o organization] "
75  "[-t allocationType] [-a asn] \n"
76  " [-creation-date yyyy-mm-ddThh:mm:ss.0Z]\n"
77  " [-add-rev-ns "
78  "<v4|v6>=<startAddr>-<endAddr>,hostname[,hostname ...] ...]\n"
79  " [-add-ds <v4|v6>=<startAddr>-<endAddr> "
80  "<keyTag> <alg> <digestType> <digest>] \n"
81  " [-rem-rev-ns "
82  "<v4|v6>=<startAddr>-<endAddr>,hostname[,hostname ...] ...]\n"
83  " [-rem-ds <v4|v6>=<startAddr>-<endAddr> "
84  "<keyTag> <alg> <digestType> <digest>] \n"
85  " [-aggregate <roid>[,hostname,hostname ...]]\n");
86  printf("\n");
87  }
88 
89  if (error_msg != "") {
90  return -1;
91  }
92 
93  return 0;
94 }
95 
97 
101 int cmd_ipnetwork_check(vector<string> &args)
102 {
103  string cmd_name = "check";
104 
105  IpNetworkCheck act;
106  IpNetworkCheckCmd *cmd = act.get_command();
107 
108  while (!args.empty()) {
109  if (args[0].substr(0, 1) == "v") {
110  //IP range
111  IpRange ipRange;
112 
113  if (SheppObjSet::parse_iprange(args[0], ipRange) != 0) {
114  return cmd_ipnetwork_help("invalid IP range", cmd_name);
115  }
116 
117  args.erase(args.begin());
118  cmd->insert_ipRange(ipRange);
119 
120  } else {
121  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
122  cmd_name);
123  }
124  }
125 
126  // check mandatory fields
127  if (cmd->get_ipRanges().empty()) {
128  return cmd_ipnetwork_help("no IP ranges specified", cmd_name);
129  }
130 
131  if (_debug) {
132  vector<IpRange> ipRanges = cmd->get_ipRanges();
133  printf("ranges to be checked:\n");
134 
135  for (unsigned int i = 0; i < ipRanges.size(); i++) {
136  printf(" (%s) from [%s] to [%s]\n",
137  ipRanges[i].get_version().c_str(),
138  ipRanges[i].get_ipBegin().c_str(),
139  ipRanges[i].get_ipEnd().c_str());
140  }
141  } // _debug
142 
143  if (process_action(act) != 0) {
144  return -1;
145  }
146 
147  return 0;
148 }
149 
151 
155 int cmd_ipnetwork_create(vector<string> &args)
156 {
157  string cmd_name = "create";
158 
159  IpNetworkCreate act;
160  IpNetworkCreateCmd *cmd = act.get_command();
161 
162  // mandatory fields
163  bool hasIpRange = false;
164  bool hasOrganization = false;
165 
166  while (!args.empty()) {
167  if (args[0].substr(0, 1) == "v") {
168  //IP range
169  if (hasIpRange) {
170  return cmd_ipnetwork_help("only one IP range allowed per command",
171  cmd_name);
172 
173  } else {
174  hasIpRange = true;
175  }
176 
177  IpRange ipRange;
178 
179  if (SheppObjSet::parse_iprange(args[0], ipRange) != 0) {
180  return cmd_ipnetwork_help("invalid IP range", cmd_name);
181  }
182 
183  args.erase(args.begin());
184  cmd->set_ipRange(ipRange);
185 
186  } else if (args[0] == "-o") {
187  //set organization
188  if (hasOrganization) {
189  return cmd_ipnetwork_help("only one organization allowed per command",
190  cmd_name);
191 
192  } else {
193  hasOrganization = true;
194  }
195 
196  args.erase(args.begin());
197 
198  if (args.empty()) {
199  return cmd_ipnetwork_help("organization parameter missing", cmd_name);
200  }
201 
202  cmd->set_organization(args[0]);
203  args.erase(args.begin());
204 
205  } else if (args[0] == "-t") {
206  //set allocType
207  args.erase(args.begin());
208 
209  if (args.empty()) {
210  return cmd_ipnetwork_help("allocType parameter missing", cmd_name);
211  }
212 
213  cmd->set_allocType(args[0]);
214  args.erase(args.begin());
215 
216  } else if (args[0] == "-reserve") {
217  args.erase(args.begin());
218 
219  if (args.empty()) {
220  return cmd_ipnetwork_help("reserveType parameter missing", cmd_name);
221  }
222 
223  cmd->set_reserveType(args[0]);
224  args.erase(args.begin());
225 
226  } else if (args[0] == "-comment") {
227  args.erase(args.begin());
228 
229  if (args.empty()) {
230  return cmd_ipnetwork_help("reserveComment parameter missing", cmd_name);
231  }
232 
233  string comment = args[0];
234  args.erase(args.begin());
235 
236  if (SheppStrUtil::quote_gathering(args, comment) != 0) {
237  return cmd_ipnetwork_help("error setting reservation comment", cmd_name);
238  }
239 
240  cmd->set_reserveComment(comment);
241 
242  } else if (args[0] == "-a") {
243  //set asn
244  args.erase(args.begin());
245 
246  if (args.empty()) {
247  return cmd_ipnetwork_help("asn parameter missing", cmd_name);
248  }
249 
250  if (atoi(args[0].c_str()) <= 0) {
251  return cmd_ipnetwork_help("asn parameter must be a positive integer",
252  cmd_name);
253  }
254 
255  cmd->set_asn(atoi(args[0].c_str()));
256  args.erase(args.begin());
257 
258  } else if (args[0] == "-contact") {
259  //contact
260  args.erase(args.begin());
261 
262  if (args.empty()) {
263  return cmd_ipnetwork_help("contact parameter missing", cmd_name);
264  }
265 
266  string type;
267  string value;
268 
269  if (SheppStrUtil::split(args[0], type, value, "=", false) != 0) {
270  return cmd_ipnetwork_help("invalid contact", cmd_name);
271  }
272 
273  cmd->insert_contact(type, value);
274  args.erase(args.begin());
275 
276  } else if (args[0] == "-rev-ns") {
277  //reverse ns
278  args.erase(args.begin());
279 
280  if (args.empty()) {
281  return cmd_ipnetwork_help("reverse DNS parameter missing", cmd_name);
282  }
283 
284  ReverseDns revDns;
285  string range;
286  string nameservers;
287 
288  if (SheppStrUtil::split(args[0], range, nameservers, ",", false) != 0 ||
289  SheppObjSet::parse_iprange(range, revDns.ipRange) != 0) {
290  return cmd_ipnetwork_help("invalid reverse DNS", cmd_name);
291  }
292 
293  string tmp1 = nameservers;
294  string tmp2;
295 
296  while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
297  revDns.nameservers.push_back(tmp1);
298 
299  if (tmp2 == "") {
300  break;
301  }
302 
303  tmp1 = tmp2;
304  }
305 
306  cmd->insert_reverseDns(revDns);
307  args.erase(args.begin());
308 
309  } else if (args[0] == "-ds") {
310  //DNSSEC data (RFC 4310/5910)
311  ReverseDSInfo ds;
312  string error_msg;
313 
314  if (SheppObjSet::dsInfo(ds, args, error_msg) != 0) {
315  return cmd_ipnetwork_help(error_msg, cmd_name);
316  }
317 
318  cmd->add_dsInfo(ds);
319 
320  } else {
321  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
322  cmd_name);
323  }
324  }
325 
326  // check mandatory fields
327  if (!hasIpRange) {
328  return cmd_ipnetwork_help("no IP range specified", cmd_name);
329  }
330 
331  if (!hasOrganization) {
332  return cmd_ipnetwork_help("no organization specified", cmd_name);
333  }
334 
335  if (_debug) {
336  IpRange ipRange = cmd->get_ipRange();
337  printf("range to be created:\n");
338  printf(" (%s) from [%s] to [%s]\n",
339  ipRange.get_version().c_str(),
340  ipRange.get_ipBegin().c_str(),
341  ipRange.get_ipEnd().c_str());
342  printf("organization: [%s]\n", cmd->get_organization().c_str());
343  printf("allocType: [%s]\n", cmd->get_allocType().c_str());
344 
345  if (cmd->get_asn() > 0) {
346  printf("asn: [%d]\n", cmd->get_asn());
347  }
348 
349  map< string, string, less<string> > contacts = cmd->get_contacts();
350  map< string, string, less<string> >::const_iterator cit;
351 
352  for (cit = contacts.begin(); cit != contacts.end(); cit++) {
353  printf("contact %s: %s\n", (*cit).first.c_str(), (*cit).second.c_str());
354  }
355 
356  printf("reverse nameservers:\n");
357  vector<ReverseDns> revNs = cmd->get_reversesDns();
358 
359  for (unsigned int i = 0; i < revNs.size(); i++) {
360  printf(" range (%s) from [%s] to [%s]:\n",
361  revNs[i].ipRange.get_version().c_str(),
362  revNs[i].ipRange.get_ipBegin().c_str(),
363  revNs[i].ipRange.get_ipEnd().c_str());
364 
365  for (unsigned int j = 0; j < revNs[i].nameservers.size(); j++) {
366  printf(" nameserver: [%s]\n", revNs[i].nameservers[j].c_str());
367  }
368  }
369  } // _debug
370 
371  if (process_action(act) != 0) {
372  return -1;
373  }
374 
375  return 0;
376 }
377 
379 
383 int cmd_ipnetwork_delete(vector<string> &args)
384 {
385  string cmd_name = "delete";
386 
387  IpNetworkDelete act;
388  IpNetworkDeleteCmd *cmd = act.get_command();
389 
390  // mandatory field
391  bool hasRoid = false;
392 
393  while (!args.empty()) {
394  if (args[0] == "-roid") {
395  //roid
396  if (hasRoid) {
397  return cmd_ipnetwork_help("only one repository ID allowed per command",
398  cmd_name);
399 
400  } else {
401  hasRoid = true;
402  }
403 
404  args.erase(args.begin());
405 
406  if (args.empty()) {
407  return cmd_ipnetwork_help("repository ID parameter missing", cmd_name);
408  }
409 
410  cmd->set_roid(args[0]);
411  args.erase(args.begin());
412 
413  } else {
414  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
415  cmd_name);
416  }
417  }
418 
419  if (!hasRoid) {
420  return cmd_ipnetwork_help("no repository ID specified", cmd_name);
421  }
422 
423  if (_debug) {
424  printf("roid: [%s]\n", cmd->get_roid().c_str());
425  } // _debug
426 
427  if (process_action(act) != 0) {
428  return -1;
429  }
430 
431  return 0;
432 }
433 
435 
439 int cmd_ipnetwork_info(vector<string> &args)
440 {
441  string cmd_name = "info";
442 
443  IpNetworkInfo act;
444  IpNetworkInfoCmd *cmd = act.get_command();
445 
446  // mandatory field
447  bool hasIpRange = false;
448 
449  while (!args.empty()) {
450  if (args[0].substr(0, 1) == "v") {
451  //IP range
452  if (hasIpRange) {
453  return cmd_ipnetwork_help("only one IP range allowed per command",
454  cmd_name);
455 
456  } else {
457  hasIpRange = true;
458  }
459 
460  IpRange ipRange;
461 
462  if (SheppObjSet::parse_iprange(args[0], ipRange) != 0) {
463  return cmd_ipnetwork_help("invalid IP range", cmd_name);
464  }
465 
466  args.erase(args.begin());
467  cmd->set_ipRange(ipRange);
468 
469  } else if (args[0] == "-roid") {
470  //roid
471  args.erase(args.begin());
472 
473  if (args.empty()) {
474  return cmd_ipnetwork_help("repository ID parameter missing", cmd_name);
475  }
476 
477  cmd->set_roid(args[0]);
478  args.erase(args.begin());
479 
480  } else {
481  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
482  cmd_name);
483  }
484  }
485 
486  // check mandatory field
487  if (!hasIpRange) {
488  return cmd_ipnetwork_help("no IP range specified", cmd_name);
489  }
490 
491  if (_debug) {
492  IpRange ipRange = cmd->get_ipRange();
493  printf("range to get info:\n");
494  printf(" (%s) from [%s] to [%s]\n",
495  ipRange.get_version().c_str(),
496  ipRange.get_ipBegin().c_str(),
497  ipRange.get_ipEnd().c_str());
498 
499  if (cmd->get_roid() != "") {
500  printf("roid: [%s]\n", cmd->get_roid().c_str());
501  }
502  } // _debug
503 
504  if (process_action(act) != 0) {
505  return -1;
506  }
507 
508  return 0;
509 }
510 
512 
516 int cmd_ipnetwork_renew(vector<string> &args)
517 {
518  string cmd_name = "renew";
519 
520  IpNetworkRenew act;
521  IpNetworkRenewCmd *cmd = act.get_command();
522 
523  // mandatory fields
524  bool hasRoid = false;
525  bool hasExpDate = false;
526 
527  while (!args.empty()) {
528  if (args[0] == "-roid") {
529  //roid
530  if (hasRoid) {
531  return cmd_ipnetwork_help("only one repository ID allowed per command",
532  cmd_name);
533 
534  } else {
535  hasRoid = true;
536  }
537 
538  args.erase(args.begin());
539 
540  if (args.empty()) {
541  return cmd_ipnetwork_help("repository ID parameter missing", cmd_name);
542  }
543 
544  cmd->set_roid(args[0]);
545  args.erase(args.begin());
546 
547  } else if (args[0] == "-expdate") {
548  //expdate
549  if (hasExpDate) {
550  return cmd_ipnetwork_help("only one expDate allowed per command",
551  cmd_name);
552 
553  } else {
554  hasExpDate = true;
555  }
556 
557  args.erase(args.begin());
558 
559  if (args.empty()) {
560  return cmd_ipnetwork_help("expDate missing", cmd_name);
561  }
562 
563  cmd->set_expDate(args[0]);
564  args.erase(args.begin());
565 
566  } else if (args[0] == "-period") {
567  //period
568  args.erase(args.begin());
569 
570  if (args.empty()) {
571  return cmd_ipnetwork_help("period parameter missing", cmd_name);
572  }
573 
574  string time;
575  string unit;
576 
577  if (SheppStrUtil::split(args[0], time, unit, ":", false) != 0) {
578  return cmd_ipnetwork_help("invalid period", cmd_name);
579  }
580 
581  cmd->set_period(atoi(time.c_str()), unit);
582  args.erase(args.begin());
583 
584  } else {
585  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
586  cmd_name);
587  }
588  }
589 
590  // check mandatory fields
591  if (!hasRoid) {
592  return cmd_ipnetwork_help("no repository ID specified", cmd_name);
593  }
594 
595  if (!hasExpDate) {
596  return cmd_ipnetwork_help("no expDate specified", cmd_name);
597  }
598 
599  if (_debug) {
600  printf("roid : [%s]\n", cmd->get_roid().c_str());
601  printf("expDate: [%s]\n", cmd->get_expDate().c_str());
602 
603  if (cmd->get_period().time != 0 || cmd->get_period().unit != "") {
604  printf("period : [%d %s]\n", cmd->get_period().time,
605  cmd->get_period().unit.c_str());
606  }
607  } // _debug
608 
609  if (process_action(act) != 0) {
610  return -1;
611  }
612 
613  return 0;
614 }
615 
617 
621 int cmd_ipnetwork_transfer(vector<string> &args)
622 {
623  string cmd_name = "transfer";
624 
625  IpNetworkTransfer act;
626  IpNetworkTransferCmd *cmd = act.get_command();
627 
628  // mandatory fields
629  bool hasRoid = false;
630  bool hasOp = false;
631 
632  while (!args.empty()) {
633  if (args[0] == "-roid") {
634  //roid
635  if (hasRoid) {
636  return cmd_ipnetwork_help("only one repository ID allowed per command",
637  cmd_name);
638 
639  } else {
640  hasRoid = true;
641  }
642 
643  args.erase(args.begin());
644 
645  if (args.empty()) {
646  return cmd_ipnetwork_help("repository ID parameter missing", cmd_name);
647  }
648 
649  cmd->set_roid(args[0]);
650  args.erase(args.begin());
651 
652  } else if (args[0] == "-op") {
653  //op
654  if (hasOp) {
655  return cmd_ipnetwork_help("only one operation allowed per command",
656  cmd_name);
657 
658  } else {
659  hasOp = true;
660  }
661 
662  args.erase(args.begin());
663 
664  if (args.empty()) {
665  return cmd_ipnetwork_help("operation parameter missing", cmd_name);
666  }
667 
668  if (args[0] != "query" && args[0] != "request") {
669  return cmd_ipnetwork_help("invalid operation '" + args[0] + "'",
670  cmd_name);
671  }
672 
673  cmd->set_operation(args[0]);
674  args.erase(args.begin());
675 
676  } else {
677  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
678  cmd_name);
679  }
680  }
681 
682  if (!hasRoid) {
683  return cmd_ipnetwork_help("no repository ID specified", cmd_name);
684  }
685 
686  if (!hasOp) {
687  return cmd_ipnetwork_help("no operation specified", cmd_name);
688  }
689 
690  if (_debug) {
691  printf("roid: [%s]\n", cmd->get_roid().c_str());
692  printf("op : [%s]\n", cmd->get_operation().c_str());
693  } // _debug
694 
695  if (process_action(act) != 0) {
696  return -1;
697  }
698 
699  return 0;
700 }
701 
703 
707 int cmd_ipnetwork_update(vector<string> &args)
708 {
709  string cmd_name = "update";
710 
711  IpNetworkUpdate act;
712  IpNetworkUpdateCmd *cmd = act.get_command();
713 
714  if (args.empty()) {
715  return cmd_ipnetwork_help("no ROID specified", cmd_name);
716  }
717 
718  cmd->set_roid(args[0]);
719  args.erase(args.begin());
720 
721  bool hasOrganization = false;
722  bool hasAllocType = false;
723  bool hasContactsAdd = false;
724  bool hasContactsRem = false;
725  bool hasReverseDnsAdd = false;
726  bool hasReverseDnsRem = false;
727  bool hasReverseDsAdd = false;
728  bool hasReverseDsRem = false;
729  bool hasAggregate = false;
730  bool hasCreationDate = false;
731 
732  while (!args.empty()) {
733  if (args[0] == "-add-contact") {
734  //contact(s) to add
735  hasContactsAdd = true;
736  args.erase(args.begin());
737 
738  if (args.empty()) {
739  return cmd_ipnetwork_help("add-contact parameter missing", cmd_name);
740  }
741 
742  string type;
743  string value;
744 
745  if (SheppStrUtil::split(args[0], type, value, "=", false) != 0) {
746  return cmd_ipnetwork_help("invalid contact", cmd_name);
747  }
748 
749  cmd->insert_contact_add(type, value);
750  args.erase(args.begin());
751 
752  } else if (args[0] == "-rem-contact") {
753  //contact(s) to remove
754  hasContactsRem = true;
755  args.erase(args.begin());
756 
757  if (args.empty()) {
758  return cmd_ipnetwork_help("rem-contact parameter missing", cmd_name);
759  }
760 
761  string type;
762  string value;
763 
764  if (SheppStrUtil::split(args[0], type, value, "=", false) != 0) {
765  return cmd_ipnetwork_help("invalid contact", cmd_name);
766  }
767 
768  cmd->insert_contact_rem(type, value);
769  args.erase(args.begin());
770 
771  } else if (args[0] == "-o") {
772  //set organization
773  if (hasOrganization) {
774  return cmd_ipnetwork_help("only one organization allowed per command",
775  cmd_name);
776 
777  } else {
778  hasOrganization = true;
779  }
780 
781  args.erase(args.begin());
782 
783  if (args.empty()) {
784  return cmd_ipnetwork_help("organization parameter missing", cmd_name);
785  }
786 
787  cmd->set_organization(args[0]);
788  args.erase(args.begin());
789 
790  } else if (args[0] == "-t") {
791  //set allocType
792  if (hasAllocType) {
793  return cmd_ipnetwork_help("only one allocation allowed per command",
794  cmd_name);
795 
796  } else {
797  hasAllocType = true;
798  }
799 
800  args.erase(args.begin());
801 
802  if (args.empty()) {
803  return cmd_ipnetwork_help("allocType parameter missing", cmd_name);
804  }
805 
806  cmd->set_allocType(args[0]);
807  args.erase(args.begin());
808 
809  } else if (args[0] == "-a") {
810  //set asn
811  args.erase(args.begin());
812 
813  if (args.empty()) {
814  return cmd_ipnetwork_help("ASN parameter missing", cmd_name);
815  }
816 
817  unsigned int asn = strtoul(args[0].c_str(), NULL, 10);
818  cmd->set_asn(asn);
819  args.erase(args.begin());
820 
821  } else if (args[0] == "-add-rev-ns") {
822  //reverse ns
823  hasReverseDnsAdd = true;
824  args.erase(args.begin());
825 
826  if (args.empty()) {
827  return cmd_ipnetwork_help("reverse DNS parameter missing", cmd_name);
828  }
829 
830  ReverseDns revDns;
831  string range;
832  string nameservers;
833 
834  if (SheppStrUtil::split(args[0], range, nameservers, ",", false) != 0 ||
835  SheppObjSet::parse_iprange(range, revDns.ipRange) != 0) {
836  return cmd_ipnetwork_help("invalid reverse DNS", cmd_name);
837  }
838 
839  string tmp1 = nameservers;
840  string tmp2;
841 
842  while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
843  revDns.nameservers.push_back(tmp1);
844 
845  if (tmp2 == "") {
846  break;
847  }
848 
849  tmp1 = tmp2;
850  }
851 
852  cmd->insert_reverseDNS_add(revDns);
853  args.erase(args.begin());
854 
855  } else if (args[0] == "-rem-rev-ns") {
856  hasReverseDnsRem = true;
857  //reverse ns
858  args.erase(args.begin());
859 
860  if (args.empty()) {
861  return cmd_ipnetwork_help("reverse DNS parameter missing", cmd_name);
862  }
863 
864  ReverseDns revDns;
865  string range;
866  string nameservers;
867 
868  if (SheppStrUtil::split(args[0], range, nameservers, ",", false) != 0 ||
869  SheppObjSet::parse_iprange(range, revDns.ipRange) != 0) {
870  return cmd_ipnetwork_help("invalid reverse DNS", cmd_name);
871  }
872 
873  string tmp1 = nameservers;
874  string tmp2;
875 
876  while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
877  revDns.nameservers.push_back(tmp1);
878 
879  if (tmp2 == "") {
880  break;
881  }
882 
883  tmp1 = tmp2;
884  }
885 
886  cmd->insert_reverseDNS_rem(revDns);
887  args.erase(args.begin());
888 
889  } else if (args[0] == "-add-ds") {
890  //DS to add
891  ReverseDSInfo ds;
892  string error_msg;
893 
894  if (SheppObjSet::dsInfo(ds, args, error_msg) != 0) {
895  return cmd_ipnetwork_help(error_msg, cmd_name);
896  }
897 
898  cmd->insert_dsInfo_add(ds);
899  hasReverseDsAdd = true;
900 
901  } else if (args[0] == "-rem-ds") {
902  //DS to remove
903  ReverseDSInfo ds;
904  string error_msg;
905 
906  if (SheppObjSet::dsInfo(ds, args, error_msg) != 0) {
907  return cmd_ipnetwork_help(error_msg, cmd_name);
908  }
909 
910  cmd->insert_dsInfo_rem(ds);
911  hasReverseDsRem = true;
912 
913  } else if (args[0] == "-aggregate") {
914  args.erase(args.begin());
915 
916  if (args.empty()) {
917  return cmd_ipnetwork_help("roid parameter missing", cmd_name);
918  }
919 
920  string aggregateRoid;
921  string aggregateHostnames;
922 
923  if (SheppStrUtil::split(args[0], aggregateRoid, aggregateHostnames, ",",
924  true) != 0) {
925  return cmd_ipnetwork_help("Invalid aggregate parameter", cmd_name);
926  }
927 
928  cmd->setAggregateRoid(aggregateRoid);
929  hasAggregate = true;
930 
931  if (aggregateHostnames != "") {
932  string tmp1 = aggregateHostnames;
933  string tmp2;
934 
935  while (SheppStrUtil::split(tmp1, tmp1, tmp2, ",", true) == 0) {
936  cmd->insertAggregateHostname(tmp1);
937 
938  if (tmp2 == "") {
939  break;
940  }
941 
942  tmp1 = tmp2;
943  }
944  }
945 
946  args.erase(args.begin());
947 
948  } else if (args[0] == "-creation-date") {
949 
950  if (hasCreationDate) {
951  return cmd_ipnetwork_help("only one creationdate allowed per command",
952  cmd_name);
953 
954  } else {
955  hasCreationDate = true;
956  }
957 
958  args.erase(args.begin());
959 
960  if (args.empty()) {
961  return cmd_ipnetwork_help("creation-date missing", cmd_name);
962  }
963 
964  cmd->setCreationDate(args[0]);
965  args.erase(args.begin());
966 
967  } else {
968  return cmd_ipnetwork_help("invalid syntax near \"" + args[0] + "\"",
969  cmd_name);
970  }
971  }
972 
973  if (!hasOrganization && !hasContactsAdd && !hasContactsRem &&
974  !hasAllocType && !hasReverseDnsAdd && !hasReverseDnsRem &&
975  hasReverseDsAdd == false && hasReverseDsRem == false &&
976  hasAggregate == false && !hasCreationDate &&
977  cmd->asn_changed() == false) {
978  return cmd_ipnetwork_help("nothing to update", cmd_name);
979  }
980 
981  if (_debug) {
982  printf("IP Network to be updated: [%s]\n", cmd->get_roid().c_str());
983  printf("organization: [%s]\n", cmd->get_organization().c_str());
984  printf("allocation type: [%s]\n", cmd->get_allocType().c_str());
985 
986  map< string, string, less<string> >::const_iterator cit;
987  map< string, string, less<string> > contacts;
988 
989  contacts = cmd->get_contacts_add();
990 
991  for (cit = contacts.begin(); cit != contacts.end(); cit++) {
992  printf("contact to add %s: %s\n",
993  (*cit).first.c_str(), (*cit).second.c_str());
994  }
995 
996  contacts = cmd->get_contacts_rem();
997 
998  for (cit = contacts.begin(); cit != contacts.end(); cit++) {
999  printf("contact to remove %s: %s\n",
1000  (*cit).first.c_str(), (*cit).second.c_str());
1001  }
1002 
1003  vector<ReverseDns> reverseDns;
1004 
1005  reverseDns = cmd->get_reverseDns_add();
1006 
1007  for (unsigned int i = 0; i < reverseDns.size(); i++) {
1008  IpRange ipRange = reverseDns[i].ipRange;
1009  printf("reverse DNS to add: [%s] from [%s] to [%s]\n",
1010  ipRange.get_version().c_str(),
1011  ipRange.get_ipBegin().c_str(),
1012  ipRange.get_ipEnd().c_str());
1013  vector<string> nameservers = reverseDns[i].nameservers;
1014 
1015  for (unsigned int j = 0; j < nameservers.size(); j++) {
1016  printf(" nameserver [%s]\n", nameservers[j].c_str());
1017  }
1018  }
1019 
1020  reverseDns = cmd->get_reverseDns_rem();
1021 
1022  for (unsigned int i = 0; i < reverseDns.size(); i++) {
1023  IpRange ipRange = reverseDns[i].ipRange;
1024  printf("reverse DNS to remove: [%s] from [%s] to [%s]\n",
1025  ipRange.get_version().c_str(),
1026  ipRange.get_ipBegin().c_str(),
1027  ipRange.get_ipEnd().c_str());
1028  vector<string> nameservers = reverseDns[i].nameservers;
1029 
1030  for (unsigned int j = 0; j < nameservers.size(); j++) {
1031  printf(" nameserver [%s]\n", nameservers[j].c_str());
1032  }
1033  }
1034  } // _debug
1035 
1036  if (process_action(act) != 0) {
1037  return -1;
1038  }
1039 
1040  return 0;
1041 }
1042 
1044 
1048 int cmd_ipnetwork(vector<string> &args)
1049 {
1050  // ipnetwork command processing
1051  if (!args.empty() && !(args[0] == "help")) {
1052  if (args[0] == "check") {
1053  args.erase(args.begin());
1054  return cmd_ipnetwork_check(args);
1055 
1056  } else if (args[0] == "create") {
1057  args.erase(args.begin());
1058  return cmd_ipnetwork_create(args);
1059 
1060  } else if (args[0] == "delete") {
1061  args.erase(args.begin());
1062  return cmd_ipnetwork_delete(args);
1063 
1064  } else if (args[0] == "info") {
1065  args.erase(args.begin());
1066  return cmd_ipnetwork_info(args);
1067 
1068  } else if (args[0] == "renew") {
1069  args.erase(args.begin());
1070  return cmd_ipnetwork_renew(args);
1071 
1072  } else if (args[0] == "transfer") {
1073  args.erase(args.begin());
1074  return cmd_ipnetwork_transfer(args);
1075 
1076  } else if (args[0] == "update") {
1077  args.erase(args.begin());
1078  return cmd_ipnetwork_update(args);
1079 
1080  } else {
1081  return cmd_ipnetwork_help("invalid command: ipnetwork " + args[0]);
1082  }
1083  }
1084 
1085  return cmd_ipnetwork_help("");
1086 }
1087 
1088 #endif //__IPNETWORK_FUNCTIONS_H__
string get_operation() const
Returns operation.
Definition: IpNetworkTransferCmd.H:45
EPP IpNetworkUpdate Class.
map< string, string, less< string > > get_contacts_rem() const
Returns map of other contacts to be removed.
Definition: IpNetworkUpdateCmd.H:224
void set_period(const int time, const string &unit)
Sets period.
Definition: IpNetworkRenewCmd.H:74
void set_asn(const unsigned int &asn)
Sets asn.
Definition: IpNetworkUpdateCmd.H:95
string get_roid() const
Returns repository object ID.
Definition: IpNetworkTransferCmd.H:63
string get_roid() const
Returns repository object ID.
Definition: IpNetworkDeleteCmd.H:41
EPP IpNetworkRenewCmd Class.
Definition: IpNetworkRenewCmd.H:22
int cmd_ipnetwork_transfer(vector< string > &args)
ipnetwork transfer command function
Definition: IpNetworkFunctions.H:621
void set_organization(const string &organization)
Sets organization.
Definition: IpNetworkCreateCmd.H:61
EPP IpNetworkTransfer Class.
IpNetworkInfoCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkInfo.H:48
int get_asn() const
Returns asn.
Definition: IpNetworkCreateCmd.H:88
EPP IpNetworkCheckCmd Class.
Definition: IpNetworkCheckCmd.H:21
EPP IpNetworkInfo Class.
Definition: IpNetworkInfoCmd.H:11
static int split(string input, string &first, string &second, string splitter, bool relaxed=false)
Definition: SheppStrUtil.H:120
RegistrationPeriod get_period() const
Returns period.
Definition: IpNetworkRenewCmd.H:84
void add_dsInfo(const ReverseDSInfo &ds_info)
Adds DS information.
Definition: IpNetworkCreateCmd.H:188
void insert_dsInfo_rem(const ReverseDSInfo &ds_info)
Inserts a reverse DS to be removed.
Definition: IpNetworkUpdateCmd.H:177
int cmd_ipnetwork_update(vector< string > &args)
ipnetwork update command function
Definition: IpNetworkFunctions.H:707
string get_organization() const
Returns organization associated with the ip range.
Definition: IpNetworkCreateCmd.H:70
IpNetworkDeleteCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkDelete.H:54
void set_ipRange(const IpRange &ipRange)
Sets ip range.
Definition: IpNetworkInfoCmd.H:26
string get_allocType() const
Returns allocation type.
Definition: IpNetworkUpdateCmd.H:86
void set_operation(const string &op)
Sets operation.
Definition: IpNetworkTransferCmd.H:36
IpNetworkCreateCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkCreate.H:54
EPP IpNetworkRenew Class.
IpNetworkCheckCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkCheck.H:54
void set_expDate(const string &expDate)
Sets expiration date.
Definition: IpNetworkRenewCmd.H:55
void insert_contact_add(const string &type, const string &identification)
Inserts a contact to be added.
Definition: IpNetworkUpdateCmd.H:196
EPP IpNetworkCheck Class.
Definition: IpNetworkCheck.H:21
void insert_reverseDns(const ReverseDns &reverseDns)
Sets reverse dns.
Definition: IpNetworkCreateCmd.H:170
EPP IpNetworkDelete Class.
Definition: IpNetworkDelete.H:21
Describes IpRange structure.
Definition: CommonData.H:192
EPP IpNetworkDelete Class.
void set_organization(const string &organization)
Sets organization.
Definition: IpNetworkUpdateCmd.H:59
void set_roid(const string &roid)
Sets repository object ID.
Definition: IpNetworkTransferCmd.H:54
void set_allocType(const string &allocType)
Sets allocation type.
Definition: IpNetworkUpdateCmd.H:77
EPP IpNetworkDelete Class.
Definition: IpNetworkDeleteCmd.H:17
void set_roid(const string &roid)
Sets repository object ID.
Definition: IpNetworkInfoCmd.H:44
EPP IpNetworkRenew Class.
Definition: IpNetworkRenew.H:21
void set_reserveType(const string &reserveType)
Sets reservation type.
Definition: IpNetworkCreateCmd.H:133
void insert_ipRange(const IpRange &ipRange)
Add an ip range.
Definition: IpNetworkCheckCmd.H:36
IpRange get_ipRange() const
Returns ip range.
Definition: IpNetworkCreateCmd.H:52
static int parse_iprange(const string &input, IpRange &ipRange)
reads an IpRange object from args
Definition: SheppObjSet.H:26
vector< ReverseDns > get_reverseDns_rem() const
Returns all the reverse DNS to be removed.
Definition: IpNetworkUpdateCmd.H:150
int cmd_ipnetwork_create(vector< string > &args)
ipnetwork create command function
Definition: IpNetworkFunctions.H:155
map< string, string, less< string > > get_contacts_add() const
Returns map of other contacts to be added.
Definition: IpNetworkUpdateCmd.H:205
EPP IpNetworkUpdateCmd Class.
Definition: IpNetworkUpdateCmd.H:26
void set_reserveComment(const string &reserveComment)
Sets reservation comments.
Definition: IpNetworkCreateCmd.H:115
int process_action(Action &act)
Send and EPP Action.
Definition: SheppCommandFunctions.H:871
IpNetworkTransferCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkTransfer.H:54
EPP IpNetworkCreate Class.
string get_expDate() const
Returns expiration date.
Definition: IpNetworkRenewCmd.H:64
void set_roid(const string &roid)
Sets repository object ID.
Definition: IpNetworkUpdateCmd.H:41
EPP IpNetworkCheck Class.
vector< ReverseDns > get_reverseDns_add() const
Returns all the reverse DNS to be added.
Definition: IpNetworkUpdateCmd.H:132
map< string, string, less< string > > get_contacts() const
Returns map of other contacts.
Definition: IpNetworkCreateCmd.H:161
void set_ipRange(const IpRange &ipRange)
Sets ip range.
Definition: IpNetworkCreateCmd.H:43
vector< IpRange > get_ipRanges() const
Returns list of ip range.
Definition: IpNetworkCheckCmd.H:45
void set_roid(const string &roid)
Sets repository object ID.
Definition: IpNetworkDeleteCmd.H:32
int cmd_ipnetwork_renew(vector< string > &args)
ipnetwork renew command function
Definition: IpNetworkFunctions.H:516
void set_allocType(const string &allocType)
Sets allocation type.
Definition: IpNetworkCreateCmd.H:97
void set_roid(const string &roid)
Sets repository object ID.
Definition: IpNetworkRenewCmd.H:37
EPP IpNetworkCreateCmd Class.
Definition: IpNetworkCreateCmd.H:28
int cmd_ipnetwork(vector< string > &args)
main ipnetwork command
Definition: IpNetworkFunctions.H:1048
EPP IpNetworkTransfer Class.
Definition: IpNetworkTransfer.H:21
EPP IpNetworkTransferCmd Class.
Definition: IpNetworkTransferCmd.H:21
EPP IpNetworkInfo Class.
Definition: IpNetworkInfo.H:15
int cmd_ipnetwork_delete(vector< string > &args)
ipnetwork check delete function
Definition: IpNetworkFunctions.H:383
void insert_dsInfo_add(const ReverseDSInfo &ds_info)
Inserts a reverse DS to be added.
Definition: IpNetworkUpdateCmd.H:159
vector< ReverseDns > get_reversesDns() const
Returns reverses dns.
Definition: IpNetworkCreateCmd.H:179
EPP command-line shell client command functions include file.
string get_roid() const
Returns repository object ID.
Definition: IpNetworkRenewCmd.H:46
void insert_reverseDNS_add(const ReverseDns &reverseDns)
Inserts a reverse DNS to be added.
Definition: IpNetworkUpdateCmd.H:123
static int quote_gathering(vector< string > &words, string &gather)
Gathers command-line arguments bounded by quotes in a string.
Definition: SheppStrUtil.H:152
string get_allocType() const
Returns allocation type.
Definition: IpNetworkCreateCmd.H:106
string get_roid() const
Returns repository object ID.
Definition: IpNetworkUpdateCmd.H:50
IpNetworkRenewCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkRenew.H:54
int cmd_ipnetwork_help(string error_msg, string specific="")
print ipnetwork command usage info
Definition: IpNetworkFunctions.H:24
int cmd_ipnetwork_check(vector< string > &args)
ipnetwork check command function
Definition: IpNetworkFunctions.H:101
bool asn_changed() const
Returns asn_changed.
Definition: IpNetworkUpdateCmd.H:114
string get_roid() const
Returns repository object ID.
Definition: IpNetworkInfoCmd.H:53
IpRange get_ipRange() const
Returns ip range.
Definition: IpNetworkInfoCmd.H:35
void insert_contact_rem(const string &type, const string &identification)
Inserts a contact to be removed.
Definition: IpNetworkUpdateCmd.H:215
void insert_reverseDNS_rem(const ReverseDns &reverseDns)
Inserts a reverse DNS to be removed.
Definition: IpNetworkUpdateCmd.H:141
EPP IpNetworkUpdate Class.
Definition: IpNetworkUpdate.H:21
int cmd_ipnetwork_info(vector< string > &args)
ipnetwork info command function
Definition: IpNetworkFunctions.H:439
void set_asn(const int asn)
Sets asn.
Definition: IpNetworkCreateCmd.H:79
static int dsInfo(DSInfo &ds, vector< string > &words, string &error_msg)
fills a DSInfo based on input command line
Definition: SheppObjSet.H:182
void insert_contact(const string &type, const string &identification)
Inserts a contact in the map of other contacts.
Definition: IpNetworkCreateCmd.H:152
Reverse DSInfo Class.
Definition: ReverseDSInfo.H:16
IpNetworkUpdateCmd * get_command()
Returns raw pointer to the command.
Definition: IpNetworkUpdate.H:54
string get_organization() const
Returns organization associated with the ip network.
Definition: IpNetworkUpdateCmd.H:68
EPP IpNetworkCreate Class.
Definition: IpNetworkCreate.H:21