| 1 | package App::pepper; | ||
| 2 | use App::pepper::EPPClient; | ||
| 3 | use App::pepper::Highlighter; | ||
| 4 | use File::Temp qw(tmpnam); | ||
| 5 | use Getopt::Long; | ||
| 6 | use Mozilla::CA; | ||
| 7 | use Net::EPP::Simple; | ||
| 8 | use List::Util qw(none); | ||
| 9 | use Pod::Usage; | ||
| 10 | use Term::ANSIColor; | ||
| 11 | use Term::ReadLine; | ||
| 12 | use Text::ParseWords; | ||
| 13 | use XML::LibXML; | ||
| 14 | use strict; | ||
| 15 | use constant { | ||
| 16 | SECURE_AUTHINFO_XMLNS => 'urn:ietf:params:xml:ns:epp:secure-authinfo-transfer-1.0', | ||
| 17 | }; | ||
| 18 | use vars qw($VERSION); | ||
| 19 | |||
| 20 | our $VERSION = '1.0.0'; | ||
| 21 | |||
| 22 | my $opt = { | ||
| 23 | 'port' => 700, | ||
| 24 | 'timeout' => 3, | ||
| 25 | 'lang' => 'en', | ||
| 26 | }; | ||
| 27 | |||
| 28 | my $result = GetOptions($opt, | ||
| 29 | 'host=s', | ||
| 30 | 'user=s', | ||
| 31 | 'pass=s', | ||
| 32 | 'newpw=s', | ||
| 33 | 'exec=s', | ||
| 34 | 'port=i', | ||
| 35 | 'timeout=i', | ||
| 36 | 'help', | ||
| 37 | 'insecure', | ||
| 38 | 'lang=s', | ||
| 39 | 'debug', | ||
| 40 | 'cert=s', | ||
| 41 | 'key=s', | ||
| 42 | 'login-security', | ||
| 43 | 'nossl', | ||
| 44 | ); | ||
| 45 | |||
| 46 | if (!$result || $opt->{'help'}) { | ||
| 47 | pod2usage( | ||
| 48 | '-verbose' => 99, | ||
| 49 | '-sections' => 'USAGE', | ||
| 50 | '-input' => __FILE__, | ||
| 51 | ); | ||
| 52 | exit; | ||
| 53 | } | ||
| 54 | |||
| 55 | my $handlers = { | ||
| 56 | 'timeout' => \&handle_timeout, | ||
| 57 | 'ssl' => \&handle_ssl, | ||
| 58 | 'host' => \&handle_host, | ||
| 59 | 'port' => \&handle_port, | ||
| 60 | 'credentials' => \&handle_credentials, | ||
| 61 | 'id' => \&handle_id, | ||
| 62 | 'pw' => \&handle_pw, | ||
| 63 | 'newpw' => \&handle_newpw, | ||
| 64 | 'connect' => \&handle_connect, | ||
| 65 | 'login' => \&handle_login, | ||
| 66 | 'logout' => \&handle_logout, | ||
| 67 | 'hello' => \&handle_hello, | ||
| 68 | 'check' => \&handle_check, | ||
| 69 | 'info' => \&handle_info, | ||
| 70 | 'poll' => \&handle_poll, | ||
| 71 | 'help' => \&handle_help, | ||
| 72 | 'send' => \&handle_send, | ||
| 73 | 'BEGIN' => \&handle_begin, | ||
| 74 | 'exit' => \&handle_exit, | ||
| 75 | 'transfer' => \&handle_transfer, | ||
| 76 | 'clone' => \&handle_clone, | ||
| 77 | 'delete' => \&handle_delete, | ||
| 78 | 'renew' => \&handle_renew, | ||
| 79 | 'create' => \&handle_create, | ||
| 80 | 'edit' => \&handle_edit, | ||
| 81 | 'cert' => \&handle_cert, | ||
| 82 | 'key' => \&handle_key, | ||
| 83 | 'restore' => \&handle_restore, | ||
| 84 | 'update' => \&handle_update, | ||
| 85 | }; | ||
| 86 | |||
| 87 | our $term; | ||
| 88 | $term = Term::ReadLine->new('pepper') if (-t STDIN && -t STDOUT); | ||
| 89 | |||
| 90 | my $outfh = ($term ? \*STDOUT : \*STDERR); | ||
| 91 | |||
| 92 | my $prompt = 'pepper> '; | ||
| 93 | |||
| 94 | my $histfile = $ENV{'HOME'}.'/.pepper_history'; | ||
| 95 | |||
| 96 | my $xml = XML::LibXML->new; | ||
| 97 | |||
| 98 | if ($term) { | ||
| 99 | $term->ReadHistory($histfile) if ('Term::ReadLine::Gnu' eq $term->ReadLine); | ||
| 100 | |||
| 101 | note('Welcome to pepper!'); | ||
| 102 | |||
| 103 | note(color('yellow').'> For best results, install Term::ReadLine::Gnu <'.color('reset')) if ($term && 'Term::ReadLine::Gnu' ne $term->ReadLine); | ||
| 104 | } | ||
| 105 | |||
| 106 | my $epp = App::pepper::EPPClient->new( | ||
| 107 | 'host' => '', | ||
| 108 | 'connect' => undef, | ||
| 109 | 'debug' => $opt->{'debug'}, | ||
| 110 | 'login' => undef, | ||
| 111 | 'reconnect' => 0, | ||
| 112 | 'verify' => ($opt->{'insecure'} ? undef : 1), | ||
| 113 | 'ca_file' => Mozilla::CA::SSL_ca_file(), | ||
| 114 | 'lang' => ($opt->{'lang'} ? $opt->{'lang'} : 'en'), | ||
| 115 | 'appname' => sprintf('Pepper %s', $VERSION), | ||
| 116 | 'login_security' => $opt->{'login-security'}, | ||
| 117 | ); | ||
| 118 | |||
| 119 | execute_command('ssl off') if ($opt->{'nossl'}); | ||
| 120 | execute_command(sprintf('timeout %d', $opt->{'timeout'})) if ($opt->{'timeout'}); | ||
| 121 | execute_command(sprintf('port %d', $ opt->{'port'})) if ($opt->{'port'}); | ||
| 122 | execute_command(sprintf('host "%s"', quotemeta($opt->{'host'}))) if ($opt->{'host'}); | ||
| 123 | execute_command(sprintf('id "%s"', quotemeta($opt->{'user'}))) if ($opt->{'user'}); | ||
| 124 | execute_command(sprintf('pw "%s"', quotemeta($opt->{'pass'}))) if ($opt->{'pass'}); | ||
| 125 | execute_command(sprintf('newpw "%s"', quotemeta($opt->{'newpw'}))) if ($opt->{'newpw'}); | ||
| 126 | execute_command(sprintf('cert "%s"', quotemeta($opt->{'cert'}))) if ($opt->{'cert'}); | ||
| 127 | execute_command(sprintf('key "%s"', quotemeta($opt->{'key'}))) if ($opt->{'key'}); | ||
| 128 | |||
| 129 | if ($epp->{'user'} ne '' && $epp->{'pass'} ne '') { | ||
| 130 | execute_command('login'); | ||
| 131 | |||
| 132 | } elsif ($epp->{'host'} ne '') { | ||
| 133 | execute_command('connect'); | ||
| 134 | |||
| 135 | } | ||
| 136 | |||
| 137 | if ($opt->{'exec'}) { | ||
| 138 | execute_command($opt->{'exec'}); | ||
| 139 | handle_exit(); | ||
| 140 | |||
| 141 | } elsif ($term) { | ||
| 142 | note("Entering interactive mode, exit with Ctrl-D, Ctrl-C or 'exit'"); | ||
| 143 | |||
| 144 | } else { | ||
| 145 | note("Entering batch mode"); | ||
| 146 | |||
| 147 | } | ||
| 148 | |||
| 149 | # | ||
| 150 | # main loop | ||
| 151 | # | ||
| 152 | my $last; | ||
| 153 | while (1) { | ||
| 154 | $prompt = sprintf('pepper (%s@%s)> ', $epp->{'user'}, $epp->{'host'}) if ($epp->authenticated); | ||
| 155 | |||
| 156 | my $command; | ||
| 157 | if ($term) { | ||
| 158 | $command = $term->readline($prompt); | ||
| 159 | |||
| 160 | } else { | ||
| 161 | $command = <STDIN>; | ||
| 162 | chomp($command); | ||
| 163 | |||
| 164 | # remove any trailing comment | ||
| 165 | $command =~ s/\#.*//g; | ||
| 166 | } | ||
| 167 | |||
| 168 | if (!defined($command)) { | ||
| 169 | last; | ||
| 170 | |||
| 171 | } elsif ($command ne '') { | ||
| 172 | if ($term && $command eq '!!') { | ||
| 173 | execute_command($last) if ($last ne ''); | ||
| 174 | |||
| 175 | } else { | ||
| 176 | $last = $command; | ||
| 177 | |||
| 178 | note("Executing command '%s'", $command) if (!$term); | ||
| 179 | execute_command($command); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | $term->WriteHistory($histfile) if ($term && 'Term::ReadLine::Gnu' eq $term->ReadLine); | ||
| 185 | |||
| 186 | handle_logout() if ($epp->connected && $epp->authenticated); | ||
| 187 | $epp->disconnect if ($epp->connected); | ||
| 188 | |||
| 189 | note('Bye!'); | ||
| 190 | |||
| 191 | exit(0); | ||
| 192 | |||
| 193 | sub execute_command { | ||
| 194 | my $line = shift; | ||
| 195 | |||
| 196 | return if ($line eq ''); | ||
| 197 | |||
| 198 | my @args = shellwords($line); | ||
| 199 | |||
| 200 | my $command = shift(@args); | ||
| 201 | |||
| 202 | my $fail; | ||
| 203 | if (!$term && $command =~/^!/) { | ||
| 204 | $fail = 1; | ||
| 205 | $command = substr($command, 1); | ||
| 206 | } | ||
| 207 | |||
| 208 | if (!defined($handlers->{$command})) { | ||
| 209 | error("Unknown command '$command'"); | ||
| 210 | handle_exit() if (!$term); | ||
| 211 | |||
| 212 | } else { | ||
| 213 | &{$handlers->{$command}}(@args); | ||
| 214 | if (!$term && $fail) { | ||
| 215 | note("%s%04d%s %s", color($Net::EPP::Simple::Code < 2000 ? 'green' : 'red'), $Net::EPP::Simple::Code, color('reset'), $Net::EPP::Simple::Message); | ||
| 216 | fatal($Net::EPP::Simple::Message) if ($Net::EPP::Simple::Code > 1999); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | sub handle_timeout { | ||
| 222 | $epp->{'timeout'} = int($_[0]); | ||
| 223 | note("Timeout set to %ds", $_[0]); | ||
| 224 | return 1; | ||
| 225 | } | ||
| 226 | |||
| 227 | sub handle_ssl { | ||
| 228 | if ($epp->connected) { | ||
| 229 | return error("Already connected"); | ||
| 230 | |||
| 231 | } elsif ($_[0] eq 'on') { | ||
| 232 | $epp->{'ssl'} = 1; | ||
| 233 | note('SSL enabled'); | ||
| 234 | |||
| 235 | } elsif ($_[0] eq 'off') { | ||
| 236 | $epp->{'ssl'} = 0; | ||
| 237 | note('SSL disabled'); | ||
| 238 | |||
| 239 | } else { | ||
| 240 | return error("Invalid SSL mode '%s'", $_[0]); | ||
| 241 | |||
| 242 | } | ||
| 243 | return 1; | ||
| 244 | } | ||
| 245 | |||
| 246 | sub handle_host { | ||
| 247 | if ($epp->connected) { | ||
| 248 | return error("Already connected"); | ||
| 249 | |||
| 250 | } else { | ||
| 251 | $epp->{'host'} = $_[0]; | ||
| 252 | note("Host set to %s", $_[0]); | ||
| 253 | return 1; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | sub handle_port { | ||
| 258 | if ($epp->connected) { | ||
| 259 | return error("Already connected"); | ||
| 260 | |||
| 261 | } else { | ||
| 262 | $epp->{'port'} = int($_[0]); | ||
| 263 | note("Port set to %d", $_[0]); | ||
| 264 | return 1; | ||
| 265 | } | ||
| 266 | } | ||
| 267 | |||
| 268 | sub handle_connect { | ||
| 269 | if ($epp->connected) { | ||
| 270 | return error("Already connected"); | ||
| 271 | |||
| 272 | } elsif ($epp->{'host'} eq '') { | ||
| 273 | return error('No host specified'); | ||
| 274 | |||
| 275 | } else { | ||
| 276 | note('Connecting to %s...', $epp->{'host'}); | ||
| 277 | |||
| 278 | $epp->{'quiet'} = 1; | ||
| 279 | my $result = $epp->_connect(undef); | ||
| 280 | $epp->{'quiet'} = 0; | ||
| 281 | |||
| 282 | if ($result) { | ||
| 283 | note("Connected OK. Type 'hello' to see the greeting frame."); | ||
| 284 | |||
| 285 | } else { | ||
| 286 | error("Unable to connect: %s", $Net::EPP::Simple::Message); | ||
| 287 | |||
| 288 | } | ||
| 289 | return $result; | ||
| 290 | } | ||
| 291 | } | ||
| 292 | |||
| 293 | sub handle_credentials { | ||
| 294 | if ($_[0] eq '') { | ||
| 295 | return error('Missing client ID'); | ||
| 296 | |||
| 297 | } elsif ($_[1] eq '') { | ||
| 298 | return error('Missing password'); | ||
| 299 | |||
| 300 | } else { | ||
| 301 | handle_id($_[0]) && handle_pw($_[1]); | ||
| 302 | return 1; | ||
| 303 | |||
| 304 | } | ||
| 305 | } | ||
| 306 | |||
| 307 | sub handle_id { | ||
| 308 | if ($epp->authenticated) { | ||
| 309 | return error("Already authenticated"); | ||
| 310 | |||
| 311 | } else { | ||
| 312 | $epp->{'user'} = shift; | ||
| 313 | note("User ID set to '%s'", $epp->{'user'}); | ||
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | sub handle_pw { | ||
| 318 | if ($epp->authenticated) { | ||
| 319 | return error("Already authenticated"); | ||
| 320 | |||
| 321 | } else { | ||
| 322 | $epp->{'pass'} = shift; | ||
| 323 | note("Password set to '%s'", ('*' x length($epp->{'pass'}))); | ||
| 324 | |||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 328 | sub handle_newpw { | ||
| 329 | if ($epp->authenticated) { | ||
| 330 | return error("Already authenticated"); | ||
| 331 | |||
| 332 | } else { | ||
| 333 | $epp->{'newPW'} = shift; | ||
| 334 | note("New password set to '%s'", ('*' x length($epp->{'newPW'}))); | ||
| 335 | |||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | sub handle_login { | ||
| 340 | my $verbose = shift; | ||
| 341 | if (!$epp->connected) { | ||
| 342 | return handle_connect() && handle_login(); | ||
| 343 | |||
| 344 | } elsif ($epp->authenticated) { | ||
| 345 | return error('Already logged in'); | ||
| 346 | |||
| 347 | } elsif ($epp->{'host'} eq '') { | ||
| 348 | return error('No host specified'); | ||
| 349 | |||
| 350 | } elsif ($epp->{'user'} eq '' || $epp->{'pass'} eq '') { | ||
| 351 | return error('No credentials specified'); | ||
| 352 | |||
| 353 | } else { | ||
| 354 | note("Attempting to login as '%s'...", $epp->{'user'}); | ||
| 355 | $epp->{'quiet'} = ($verbose ? 0 : 1); | ||
| 356 | my $result = $epp->_login; | ||
| 357 | $epp->{'quiet'} = 0; | ||
| 358 | if ($result) { | ||
| 359 | note('Logged in OK!'); | ||
| 360 | |||
| 361 | } else { | ||
| 362 | error("%s%04d%s %s", color($Net::EPP::Simple::Code < 2000 ? 'green' : 'red'), $Net::EPP::Simple::Code, color('reset'), $Net::EPP::Simple::Message); | ||
| 363 | |||
| 364 | } | ||
| 365 | return $result; | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | sub handle_logout { | ||
| 370 | if (!$epp->authenticated) { | ||
| 371 | return error('Not logged in'); | ||
| 372 | |||
| 373 | } else { | ||
| 374 | note('logging out'); | ||
| 375 | $epp->{'quiet'} = 1; | ||
| 376 | my $result = $epp->logout; | ||
| 377 | $epp->{'quiet'} = 0; | ||
| 378 | note("%s%04d%s %s", color($Net::EPP::Simple::Code < 2000 ? 'green' : 'red'), $Net::EPP::Simple::Code, color('reset'), $Net::EPP::Simple::Message); | ||
| 379 | return $result; | ||
| 380 | } | ||
| 381 | } | ||
| 382 | |||
| 383 | sub handle_hello { | ||
| 384 | if (!$epp->connected) { | ||
| 385 | return error('Not connected'); | ||
| 386 | |||
| 387 | } else { | ||
| 388 | return $epp->ping; | ||
| 389 | |||
| 390 | } | ||
| 391 | } | ||
| 392 | |||
| 393 | sub handle_check { | ||
| 394 | if (!$epp->authenticated) { | ||
| 395 | return error('Not connected'); | ||
| 396 | |||
| 397 | } else { | ||
| 398 | my ($type, $id, @extra) = @_; | ||
| 399 | if ($type eq 'domain') { | ||
| 400 | return $epp->check_domain($id); | ||
| 401 | |||
| 402 | } elsif ($type eq 'claims') { | ||
| 403 | return handle_claims_check($id); | ||
| 404 | |||
| 405 | } elsif ($type eq 'fee') { | ||
| 406 | return handle_fee_check($id, @extra); | ||
| 407 | |||
| 408 | } elsif ($type eq 'host') { | ||
| 409 | return $epp->check_host($id); | ||
| 410 | |||
| 411 | } elsif ($type eq 'contact') { | ||
| 412 | return $epp->check_contact($id); | ||
| 413 | |||
| 414 | } else { | ||
| 415 | return error("Unsupported object type '$type'"); | ||
| 416 | |||
| 417 | } | ||
| 418 | } | ||
| 419 | } | ||
| 420 | |||
| 421 | sub handle_claims_check { | ||
| 422 | my $domain = shift; | ||
| 423 | my $frame = Net::EPP::Frame::Command::Check::Domain->new; | ||
| 424 | $frame->addDomain($domain); | ||
| 425 | |||
| 426 | my $launch_ns = 'urn:ietf:params:xml:ns:launch-1.0'; | ||
| 427 | |||
| 428 | my $phase = $frame->createElementNS($launch_ns, 'phase'); | ||
| 429 | $phase->appendChild($frame->createTextNode('claims')); | ||
| 430 | |||
| 431 | my $launch = $frame->createElementNS($launch_ns, 'check'); | ||
| 432 | $launch->setAttribute('type', 'claims'); | ||
| 433 | $launch->appendChild($phase); | ||
| 434 | |||
| 435 | my $extn = $frame->createElement('extension'); | ||
| 436 | $extn->appendChild($launch); | ||
| 437 | |||
| 438 | $frame->clTRID->parentNode->insertBefore($extn, $frame->clTRID); | ||
| 439 | |||
| 440 | return $epp->request($frame); | ||
| 441 | } | ||
| 442 | |||
| 443 | sub handle_fee_check { | ||
| 444 | my %params; | ||
| 445 | ($params{'name'}, $params{'command'}, $params{'currency'}, $params{'period'}) = @_; | ||
| 446 | |||
| 447 | my $domain = shift; | ||
| 448 | my $frame = Net::EPP::Frame::Command::Check::Domain->new; | ||
| 449 | $frame->addDomain($params{'name'}); | ||
| 450 | |||
| 451 | my $fee_ns = 'urn:ietf:params:xml:ns:fee-0.5'; | ||
| 452 | my $ok = undef; | ||
| 453 | foreach my $el ($epp->greeting->getElementsByTagName('extURI')) { | ||
| 454 | $ok = 1 if ($el->textContent eq $fee_ns); | ||
| 455 | } | ||
| 456 | |||
| 457 | return error("Server does not support the version of the fee extension that I support!") if (!$ok); | ||
| 458 | |||
| 459 | my $domain = $frame->createElementNS($fee_ns, 'domain'); | ||
| 460 | foreach my $name (qw(name currency command period)) { | ||
| 461 | next if ($params{$name} eq ''); | ||
| 462 | my $el = $frame->createElementNS($fee_ns, $name); | ||
| 463 | $el->appendChild($frame->createTextNode($params{$name})); | ||
| 464 | $el->setAttribute('unit', 'y') if ('period' eq $name); | ||
| 465 | $domain->appendChild($el); | ||
| 466 | } | ||
| 467 | |||
| 468 | my $check = $frame->createElementNS($fee_ns, 'check'); | ||
| 469 | $check->appendChild($domain); | ||
| 470 | |||
| 471 | my $extn = $frame->createElement('extension'); | ||
| 472 | $extn->appendChild($check); | ||
| 473 | |||
| 474 | $frame->clTRID->parentNode->insertBefore($extn, $frame->clTRID); | ||
| 475 | |||
| 476 | return $epp->request($frame); | ||
| 477 | } | ||
| 478 | |||
| 479 | sub handle_info { | ||
| 480 | if (!$epp->authenticated) { | ||
| 481 | return error('Not connected'); | ||
| 482 | |||
| 483 | } else { | ||
| 484 | my ($type, $id, $authInfo, $opt) = @_; | ||
| 485 | if ($type eq 'domain') { | ||
| 486 | $opt = $opt || 'all'; | ||
| 487 | return $epp->domain_info($id, $authInfo, undef, $opt); | ||
| 488 | |||
| 489 | } elsif ($type eq 'host') { | ||
| 490 | return $epp->host_info($id); | ||
| 491 | |||
| 492 | } elsif ($type eq 'contact') { | ||
| 493 | return $epp->contact_info($id, $authInfo, $opt); | ||
| 494 | |||
| 495 | } else { | ||
| 496 | return error("Unsupported object type '$type'"); | ||
| 497 | |||
| 498 | } | ||
| 499 | } | ||
| 500 | } | ||
| 501 | |||
| 502 | sub handle_poll { | ||
| 503 | if (!$epp->authenticated) { | ||
| 504 | return error('Not connected'); | ||
| 505 | |||
| 506 | } else { | ||
| 507 | my ($op, $id) = @_; | ||
| 508 | if ($op eq 'req') { | ||
| 509 | my $frame = Net::EPP::Frame::Command::Poll::Req->new; | ||
| 510 | $epp->request($frame); | ||
| 511 | |||
| 512 | } elsif ($op eq 'ack') { | ||
| 513 | my $frame = Net::EPP::Frame::Command::Poll::Ack->new; | ||
| 514 | $frame->setMsgID($id); | ||
| 515 | $epp->request($frame); | ||
| 516 | |||
| 517 | } else { | ||
| 518 | error("Unsupported poll op '$op'"); | ||
| 519 | |||
| 520 | } | ||
| 521 | } | ||
| 522 | } | ||
| 523 | |||
| 524 | sub handle_send { | ||
| 525 | if (!$epp->connected) { | ||
| 526 | return error('Not connected'); | ||
| 527 | |||
| 528 | } else { | ||
| 529 | return send_file($_[0]); | ||
| 530 | |||
| 531 | } | ||
| 532 | } | ||
| 533 | |||
| 534 | sub handle_begin { | ||
| 535 | if (!$epp->connected) { | ||
| 536 | return error('Not connected'); | ||
| 537 | |||
| 538 | } else { | ||
| 539 | my $buffer = ''; | ||
| 540 | while (my $line = <STDIN>) { | ||
| 541 | if ($line =~ /^END/) { | ||
| 542 | last; | ||
| 543 | |||
| 544 | } else { | ||
| 545 | $buffer .= $line; | ||
| 546 | |||
| 547 | } | ||
| 548 | } | ||
| 549 | my $frame; | ||
| 550 | eval { $frame = $xml->parse_string($buffer) }; | ||
| 551 | if ($@ || !$frame) { | ||
| 552 | $@ =~ s/[\r\n]+$//g; | ||
| 553 | error("Unable to parse frame ($@)"); | ||
| 554 | |||
| 555 | } else { | ||
| 556 | return $epp->request($frame); | ||
| 557 | |||
| 558 | } | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 562 | sub handle_edit { | ||
| 563 | if (!$epp->connected) { | ||
| 564 | return error('Not connected'); | ||
| 565 | |||
| 566 | } else { | ||
| 567 | my $file = tmpnam(); | ||
| 568 | |||
| 569 | open(FILE, ">$file"); | ||
| 570 | print FILE Net::EPP::Frame->new('command')->toString(2); | ||
| 571 | close(FILE); | ||
| 572 | |||
| 573 | my $cmd = ($ENV{'EDITOR'} || '/usr/bin/vi'); | ||
| 574 | my ($cmd, @args) = split(/[ \t]+/, $cmd); | ||
| 575 | push(@args, $file); | ||
| 576 | |||
| 577 | if (0 != system($cmd, @args)) { | ||
| 578 | error("Command '$cmd' exited abnormally"); | ||
| 579 | |||
| 580 | } else { | ||
| 581 | return send_file($file); | ||
| 582 | |||
| 583 | } | ||
| 584 | } | ||
| 585 | } | ||
| 586 | |||
| 587 | sub send_file { | ||
| 588 | my $file = shift; | ||
| 589 | my $frame; | ||
| 590 | eval { $frame = $xml->parse_file($file) }; | ||
| 591 | if ($@ || !$frame) { | ||
| 592 | $@ =~ s/[\r\n]+$//g; | ||
| 593 | return error("Unable to parse '$file': $@"); | ||
| 594 | |||
| 595 | } else { | ||
| 596 | return $epp->request($frame); | ||
| 597 | |||
| 598 | } | ||
| 599 | } | ||
| 600 | |||
| 601 | sub handle_help { | ||
| 602 | my $cmd = lc(shift || 'help'); | ||
| 603 | |||
| 604 | my %map = ( | ||
| 605 | 'timeout' => 'SYNTAX/Connection Management', | ||
| 606 | 'ssl' => 'SYNTAX/Connection Management', | ||
| 607 | 'host' => 'SYNTAX/Connection Management', | ||
| 608 | 'port' => 'SYNTAX/Connection Management', | ||
| 609 | 'credentials' => 'SYNTAX/Session Management', | ||
| 610 | 'id' => 'SYNTAX/Session Management', | ||
| 611 | 'pw' => 'SYNTAX/Session Management', | ||
| 612 | 'newpw' => 'SYNTAX/Session Management', | ||
| 613 | 'connect' => 'SYNTAX/Connection Management', | ||
| 614 | 'login' => 'SYNTAX/Session Management', | ||
| 615 | 'logout' => 'SYNTAX/Session Management', | ||
| 616 | 'hello' => 'SYNTAX/Session Management', | ||
| 617 | 'check' => 'SYNTAX/Query Commands/Availability Checks', | ||
| 618 | 'info' => 'SYNTAX/Query Commands/Object Information', | ||
| 619 | 'poll' => 'SYNTAX/Session Management', | ||
| 620 | 'help' => 'SYNTAX/Getting Help', | ||
| 621 | 'send' => 'SYNTAX/Miscellaneous Commands', | ||
| 622 | 'begin' => 'SYNTAX/Miscellaneous Commands', | ||
| 623 | 'exit' => 'SYNTAX/Connection Management', | ||
| 624 | 'transfer' => 'SYNTAX/Object Transfers', | ||
| 625 | 'clone' => 'SYNTAX/Creating Objects', | ||
| 626 | 'delete' => 'SYNTAX/Transform Commands', | ||
| 627 | 'renew' => 'SYNTAX/Transform Commands', | ||
| 628 | 'create' => 'SYNTAX/Creating Objects', | ||
| 629 | 'create-domain' => 'SYNTAX/Creating Objects/Creating Domain Objects', | ||
| 630 | 'create-host' => 'SYNTAX/Creating Objects/Creating Host Objects', | ||
| 631 | 'create-contact' => 'SYNTAX/Creating Objects/Creating Contact Objects', | ||
| 632 | 'edit' => 'SYNTAX/Miscellaneous Commands', | ||
| 633 | 'cert' => 'SYNTAX/Connection Management', | ||
| 634 | 'key' => 'SYNTAX/Connection Management', | ||
| 635 | 'restore' => 'SYNTAX/Transform Commands', | ||
| 636 | 'update' => 'SYNTAX/Object Updates', | ||
| 637 | 'update-domain' => 'SYNTAX/Object Updates/Domain Updates', | ||
| 638 | 'update-host' => 'SYNTAX/Object Updates/Host Updates', | ||
| 639 | 'update-contact' => 'SYNTAX/Object Updates/Contact Updates', | ||
| 640 | ); | ||
| 641 | |||
| 642 | print "\n"; | ||
| 643 | |||
| 644 | pod2usage( | ||
| 645 | '-verbose' => 99, | ||
| 646 | '-sections' => $map{$cmd} || $map{'help'}, | ||
| 647 | '-exitval' => 'NOEXIT', | ||
| 648 | '-input' => __FILE__, | ||
| 649 | ); | ||
| 650 | } | ||
| 651 | |||
| 652 | sub handle_exit { | ||
| 653 | $epp->{'quiet'} = 1; | ||
| 654 | $epp->logout if ($epp->authenticated); | ||
| 655 | $epp->disconnect if ($epp->connected); | ||
| 656 | note('bye!'); | ||
| 657 | exit; | ||
| 658 | } | ||
| 659 | |||
| 660 | sub handle_transfer { | ||
| 661 | if (!$epp->authenticated) { | ||
| 662 | return error('Not connected'); | ||
| 663 | |||
| 664 | } else { | ||
| 665 | my ($type, $object, $cmd, $authinfo, $period) = @_; | ||
| 666 | |||
| 667 | return error("invalid object type '%s'", $type) if ($type ne 'domain' && $type ne 'contact'); | ||
| 668 | return error("invalid command '%s'", $cmd) if ($cmd ne 'query' && $cmd ne 'request' && $cmd ne 'cancel' && $cmd ne 'approve' && $cmd ne 'reject'); | ||
| 669 | |||
| 670 | return $epp->_transfer_request($cmd, $type, $object, $authinfo, $period); | ||
| 671 | } | ||
| 672 | } | ||
| 673 | |||
| 674 | sub handle_clone { | ||
| 675 | if (!$epp->authenticated) { | ||
| 676 | return error('Not connected'); | ||
| 677 | |||
| 678 | } else { | ||
| 679 | my ($type, $old, $new) = @_; | ||
| 680 | |||
| 681 | if (lc($type) eq 'contact') { | ||
| 682 | return handle_contact_clone($old, $new); | ||
| 683 | |||
| 684 | } elsif (lc($type) eq 'domain') { | ||
| 685 | return handle_domain_clone($old, $new); | ||
| 686 | |||
| 687 | } else { | ||
| 688 | error("Unsupported object type '$type'"); | ||
| 689 | |||
| 690 | } | ||
| 691 | } | ||
| 692 | } | ||
| 693 | |||
| 694 | sub handle_contact_clone { | ||
| 695 | my ($old, $new) = @_; | ||
| 696 | |||
| 697 | my $info = $epp->contact_info($old) || return; | ||
| 698 | |||
| 699 | $info->{'id'} = $new; | ||
| 700 | $info->{'authInfo'} = $epp->server_has_extension(SECURE_AUTHINFO_XMLNS) ? '' : generate_authinfo(); | ||
| 701 | |||
| 702 | return $epp->create_contact($info); | ||
| 703 | } | ||
| 704 | |||
| 705 | sub handle_domain_clone { | ||
| 706 | my ($old, $new) = @_; | ||
| 707 | |||
| 708 | my $info = $epp->domain_info($old) || return; | ||
| 709 | |||
| 710 | $info->{'period'} = 1; | ||
| 711 | $info->{'name'} = $new; | ||
| 712 | $info->{'authInfo'} = $epp->server_has_extension(SECURE_AUTHINFO_XMLNS) ? '' : generate_authinfo(); | ||
| 713 | |||
| 714 | return $epp->create_domain($info); | ||
| 715 | } | ||
| 716 | |||
| 717 | sub generate_authinfo { | ||
| 718 | my $length = shift || 16; | ||
| 719 | |||
| 720 | my $safe = shift; | ||
| 721 | |||
| 722 | my @upper_alpha = ('A'..'Z'); | ||
| 723 | my @lower_alpha = ('a'..'z'); | ||
| 724 | my @digits = (0..9); | ||
| 725 | my @symbols = ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '[', ']', '^', '_', '{', '|', '}', '~'); | ||
| 726 | |||
| 727 | my (@chars, @authinfo); | ||
| 728 | if ($safe) { | ||
| 729 | @chars = (@upper_alpha, @digits); | ||
| 730 | |||
| 731 | @authinfo = ( | ||
| 732 | $upper_alpha[int(scalar(@upper_alpha) * rand())-1], | ||
| 733 | $digits[int(scalar(@digits) * rand())-1], | ||
| 734 | ); | ||
| 735 | } else { | ||
| 736 | @chars = (@upper_alpha, @lower_alpha, @digits, @symbols); | ||
| 737 | |||
| 738 | @authinfo = ( | ||
| 739 | $upper_alpha[int(scalar(@upper_alpha) * rand())-1], | ||
| 740 | $lower_alpha[int(scalar(@lower_alpha) * rand())-1], | ||
| 741 | $digits[int(scalar(@digits) * rand())-1], | ||
| 742 | $symbols[int(scalar(@symbols) * rand())-1] | ||
| 743 | ); | ||
| 744 | } | ||
| 745 | |||
| 746 | push(@authinfo, $chars[int(scalar(@chars) * rand())-1]) while (scalar(@authinfo) < $length); | ||
| 747 | |||
| 748 | return join('', @authinfo); | ||
| 749 | } | ||
| 750 | |||
| 751 | sub generate_contact_id { | ||
| 752 | return generate_authinfo(16, 1); | ||
| 753 | } | ||
| 754 | |||
| 755 | sub handle_delete { | ||
| 756 | if (!$epp->authenticated) { | ||
| 757 | return error('Not connected'); | ||
| 758 | |||
| 759 | } else { | ||
| 760 | my ($type, $id) = @_; | ||
| 761 | if ($type eq 'domain') { | ||
| 762 | return $epp->delete_domain($id); | ||
| 763 | |||
| 764 | } elsif ($type eq 'host') { | ||
| 765 | return $epp->delete_host($id); | ||
| 766 | |||
| 767 | } elsif ($type eq 'contact') { | ||
| 768 | return $epp->delete_contact($id); | ||
| 769 | |||
| 770 | } else { | ||
| 771 | return error("Unsupported object type '$type'"); | ||
| 772 | |||
| 773 | } | ||
| 774 | } | ||
| 775 | } | ||
| 776 | |||
| 777 | sub handle_renew { | ||
| 778 | if (!$epp->authenticated) { | ||
| 779 | return error('Not connected'); | ||
| 780 | |||
| 781 | } else { | ||
| 782 | my ($domain, $period, $date) = @_; | ||
| 783 | $period = 1 if (!$period); | ||
| 784 | |||
| 785 | if (!$date) { | ||
| 786 | my $info = $epp->domain_info($domain, undef, undef, 'none'); | ||
| 787 | return undef if (!$info); | ||
| 788 | |||
| 789 | ($date, undef) = split(/T/, $info->{'exDate'}, 2); | ||
| 790 | } | ||
| 791 | |||
| 792 | return $epp->renew_domain({ | ||
| 793 | 'name' => $domain, | ||
| 794 | 'period' => $period, | ||
| 795 | 'cur_exp_date' => $date, | ||
| 796 | }); | ||
| 797 | } | ||
| 798 | } | ||
| 799 | |||
| 800 | sub handle_create { | ||
| 801 | if (!$epp->authenticated) { | ||
| 802 | return error('Not connected'); | ||
| 803 | |||
| 804 | } else { | ||
| 805 | my $type = lc(shift); | ||
| 806 | |||
| 807 | if ($type eq 'host') { | ||
| 808 | return create_host(@_); | ||
| 809 | |||
| 810 | } elsif ($type eq 'domain') { | ||
| 811 | return create_domain(@_); | ||
| 812 | |||
| 813 | } elsif ($type eq 'contact') { | ||
| 814 | return create_contact(@_); | ||
| 815 | |||
| 816 | } else { | ||
| 817 | return error("invalid type '%s'", $type); | ||
| 818 | |||
| 819 | } | ||
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | sub create_host { | ||
| 824 | my $host = { 'name' => shift }; | ||
| 825 | |||
| 826 | if (scalar(@_) > 0) { | ||
| 827 | $host->{'addrs'} = []; | ||
| 828 | foreach my $addr (@_) { | ||
| 829 | my $version = 'v'.($addr =~ /:/ ? 6 : 4); | ||
| 830 | push(@{$host->{'addrs'}}, { 'ip' => $addr, 'version' => $version }); | ||
| 831 | } | ||
| 832 | } | ||
| 833 | return $epp->create_host($host); | ||
| 834 | } | ||
| 835 | |||
| 836 | sub create_domain { | ||
| 837 | my $domain = { | ||
| 838 | 'name' => shift, | ||
| 839 | 'contacts' => {}, | ||
| 840 | 'ns' => [], | ||
| 841 | }; | ||
| 842 | |||
| 843 | for (my $i = 0 ; $i < scalar(@_) ; $i++) { | ||
| 844 | my $name = $_[$i]; | ||
| 845 | my $value = $_[++$i]; | ||
| 846 | |||
| 847 | if ($name eq 'period') { | ||
| 848 | $domain->{'period'} = int($value); | ||
| 849 | |||
| 850 | } elsif ($name eq 'registrant') { | ||
| 851 | $domain->{'registrant'} = $value; | ||
| 852 | |||
| 853 | } elsif ($name eq 'ns') { | ||
| 854 | push(@{$domain->{'ns'}}, $epp->server_has_object(Net::EPP::Frame::ObjectSpec->xmlns('host')) ? $value : { name => $value}); | ||
| 855 | |||
| 856 | } elsif (lc($name) eq 'authinfo') { | ||
| 857 | $domain->{'authInfo'} = $value; | ||
| 858 | |||
| 859 | } elsif ($name =~ /^(admin|tech|billing)$/) { | ||
| 860 | $domain->{'contacts'}->{$name} = $value; | ||
| 861 | |||
| 862 | } else { | ||
| 863 | return error("Invalid property name '$name'"); | ||
| 864 | |||
| 865 | } | ||
| 866 | } | ||
| 867 | |||
| 868 | $domain->{'period'} = 1 if ($domain->{'period'} < 1); | ||
| 869 | $domain->{'authInfo'} = $epp->server_has_extension(SECURE_AUTHINFO_XMLNS) ? '' : generate_authinfo() if (length($domain->{'authInfo'}) < 1); | ||
| 870 | |||
| 871 | return $epp->create_domain($domain); | ||
| 872 | } | ||
| 873 | |||
| 874 | sub create_contact { | ||
| 875 | my $contact = {}; | ||
| 876 | |||
| 877 | my $type = 'int'; | ||
| 878 | |||
| 879 | my $postalInfo = { 'addr' => { 'street' => [] } }; | ||
| 880 | |||
| 881 | for (my $i = 0 ; $i < scalar(@_) ; $i++) { | ||
| 882 | my $name = $_[$i]; | ||
| 883 | my $value = $_[++$i]; | ||
| 884 | |||
| 885 | if ($name eq 'type') { | ||
| 886 | if ($value eq 'int' || $value eq 'loc') { | ||
| 887 | $type = $value; | ||
| 888 | |||
| 889 | } else { | ||
| 890 | return error("Invalid postalInfo type '$value'"); | ||
| 891 | |||
| 892 | } | ||
| 893 | |||
| 894 | } elsif ($name eq 'street') { | ||
| 895 | push(@{$postalInfo->{'addr'}->{'street'}}, $value); | ||
| 896 | |||
| 897 | } elsif ($name =~ /^(name|org)$/) { | ||
| 898 | $postalInfo->{$name} = $value; | ||
| 899 | |||
| 900 | } elsif ($name =~ /^(city|sp|pc|cc)$/) { | ||
| 901 | $postalInfo->{'addr'}->{$name} = $value; | ||
| 902 | |||
| 903 | } elsif (lc($name) eq 'authinfo') { | ||
| 904 | $contact->{'authInfo'} = $value; | ||
| 905 | |||
| 906 | } elsif ($name =~ /^(id|voice|fax|email)$/) { | ||
| 907 | $contact->{$name} = $value; | ||
| 908 | |||
| 909 | } else { | ||
| 910 | return error("Invalid property name '$name'"); | ||
| 911 | |||
| 912 | } | ||
| 913 | } | ||
| 914 | |||
| 915 | $contact->{'postalInfo'}->{$type} = $postalInfo; | ||
| 916 | $contact->{'id'} = generate_contact_id() if (length($contact->{'id'}) < 1); | ||
| 917 | $contact->{'authInfo'} = $epp->server_has_extension(SECURE_AUTHINFO_XMLNS) ? '' : generate_authinfo() if (length($contact->{'authInfo'}) < 1); | ||
| 918 | |||
| 919 | return $epp->create_contact($contact); | ||
| 920 | } | ||
| 921 | |||
| 922 | sub handle_key { | ||
| 923 | if ($epp->connected) { | ||
| 924 | return error('Already connected'); | ||
| 925 | |||
| 926 | } else { | ||
| 927 | my ($key, $pass) = @_; | ||
| 928 | $epp->{'key'} = $key; | ||
| 929 | $epp->{'passphrase'} = $pass; | ||
| 930 | note("Using '$key' as private key"); | ||
| 931 | } | ||
| 932 | } | ||
| 933 | |||
| 934 | sub handle_cert { | ||
| 935 | if ($epp->connected) { | ||
| 936 | return error('Already connected'); | ||
| 937 | |||
| 938 | } else { | ||
| 939 | my $cert = shift; | ||
| 940 | $epp->{'cert'} = $cert; | ||
| 941 | note("Using '$cert' as certificate"); | ||
| 942 | } | ||
| 943 | } | ||
| 944 | |||
| 945 | sub handle_restore { | ||
| 946 | if (!$epp->connected) { | ||
| 947 | return error('Not connected'); | ||
| 948 | |||
| 949 | } else { | ||
| 950 | my $domain = shift; | ||
| 951 | |||
| 952 | my $frame = Net::EPP::Frame::Command::Update::Domain->new; | ||
| 953 | $frame->setDomain($domain); | ||
| 954 | |||
| 955 | my $ext = $frame->getNode('extension'); | ||
| 956 | if (!defined($ext)) { | ||
| 957 | $ext = $frame->createElementNS(undef, 'extension'); | ||
| 958 | $frame->getNode('command')->insertBefore($ext, $frame->clTRID); | ||
| 959 | } | ||
| 960 | |||
| 961 | my $RGP_URN = 'urn:ietf:params:xml:ns:rgp-1.0'; | ||
| 962 | |||
| 963 | my $upd = $ext->addNewChild($RGP_URN, 'rgp:update'); | ||
| 964 | my $restore = $upd->addNewChild($RGP_URN, 'rgp:restore'); | ||
| 965 | $restore->setAttribute('op', 'request'); | ||
| 966 | |||
| 967 | return $epp->request($frame); | ||
| 968 | } | ||
| 969 | } | ||
| 970 | |||
| 971 | sub handle_update { | ||
| 972 | if (!$epp->connected) { | ||
| 973 | return error('Not connected'); | ||
| 974 | |||
| 975 | } else { | ||
| 976 | my $type = shift; | ||
| 977 | if ($type eq 'domain') { | ||
| 978 | return domain_update(@_); | ||
| 979 | |||
| 980 | } elsif ($type eq 'host') { | ||
| 981 | return host_update(@_); | ||
| 982 | |||
| 983 | } elsif ($type eq 'contact') { | ||
| 984 | return contact_update(@_); | ||
| 985 | |||
| 986 | } else { | ||
| 987 | return error("Unsupported object type '$type'"); | ||
| 988 | |||
| 989 | } | ||
| 990 | } | ||
| 991 | } | ||
| 992 | |||
| 993 | sub domain_update { | ||
| 994 | my $frame = Net::EPP::Frame::Command::Update::Domain->new; | ||
| 995 | |||
| 996 | $frame->setDomain(shift(@_)); | ||
| 997 | |||
| 998 | my $changes = { | ||
| 999 | 'ns' => [], | ||
| 1000 | 'contact' => [], | ||
| 1001 | 'status' => [], | ||
| 1002 | }; | ||
| 1003 | |||
| 1004 | for (my $i = 0 ; $i < scalar(@_) ; $i++) { | ||
| 1005 | my $action = lc($_[$i]); | ||
| 1006 | my $type = lc($_[++$i]); | ||
| 1007 | my $value = $_[++$i]; | ||
| 1008 | |||
| 1009 | return error("Invalid parameter '$action'") if ($action !~ /^(add|rem|chg)$/); | ||
| 1010 | return error("Missing parameter") if (!$type || !$value); | ||
| 1011 | return error("Invalid property '$type'") if ($type !~ /^(ns|admin|tech|billing|status|registrant|authinfo)$/); | ||
| 1012 | |||
| 1013 | if ($type eq 'ns') { | ||
| 1014 | push(@{$changes->{'ns'}}, [ $action, $value ]); | ||
| 1015 | |||
| 1016 | } elsif ($type =~ /^(admin|tech|billing)$/) { | ||
| 1017 | push(@{$changes->{'contact'}}, [ $action, $type, $value ]); | ||
| 1018 | |||
| 1019 | } elsif ($type eq 'status') { | ||
| 1020 | push(@{$changes->{'status'}}, [ $action, $value ]); | ||
| 1021 | |||
| 1022 | } elsif ($action eq 'chg') { | ||
| 1023 | if ('registrant' eq $type) { | ||
| 1024 | $frame->chgRegistrant($value); | ||
| 1025 | |||
| 1026 | } elsif ('authinfo' eq $type) { | ||
| 1027 | $frame->chgAuthInfo($value); | ||
| 1028 | |||
| 1029 | } else { | ||
| 1030 | return error("Don't know how to change '$type'"); | ||
| 1031 | |||
| 1032 | } | ||
| 1033 | |||
| 1034 | } else { | ||
| 1035 | return error("Don't know what to do with '$action $type $value'"); | ||
| 1036 | |||
| 1037 | } | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | foreach my $change (@{$changes->{'ns'}}) { | ||
| 1041 | my ($action, $value) = @{$change}; | ||
| 1042 | if ($action eq 'add') { | ||
| 1043 | $frame->addNS($epp->server_has_object(Net::EPP::Frame::ObjectSpec->xmlns('host')) ? $value : { name => $value}); | ||
| 1044 | |||
| 1045 | } else { | ||
| 1046 | $frame->remNS($epp->server_has_object(Net::EPP::Frame::ObjectSpec->xmlns('host')) ? $value : { name => $value}); | ||
| 1047 | |||
| 1048 | } | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | foreach my $change (@{$changes->{'contact'}}) { | ||
| 1052 | my ($action, $type, $value) = @{$change}; | ||
| 1053 | if ($action eq 'add') { | ||
| 1054 | $frame->addContact($type, $value); | ||
| 1055 | |||
| 1056 | } else { | ||
| 1057 | $frame->remContact($type, $value); | ||
| 1058 | |||
| 1059 | } | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | foreach my $change (@{$changes->{'status'}}) { | ||
| 1063 | my ($action, $value) = @{$change}; | ||
| 1064 | if ($action eq 'add') { | ||
| 1065 | $frame->addStatus($value); | ||
| 1066 | |||
| 1067 | } else { | ||
| 1068 | $frame->remStatus($value); | ||
| 1069 | |||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | return $epp->request($frame); | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | sub host_update { | ||
| 1077 | my $frame = Net::EPP::Frame::Command::Update::Host->new; | ||
| 1078 | |||
| 1079 | $frame->setHost(shift(@_)); | ||
| 1080 | |||
| 1081 | my $changes = { | ||
| 1082 | 'addr' => [], | ||
| 1083 | 'status' => [], | ||
| 1084 | }; | ||
| 1085 | |||
| 1086 | for (my $i = 0 ; $i < scalar(@_) ; $i++) { | ||
| 1087 | my $action = lc($_[$i]); | ||
| 1088 | my $type = lc($_[++$i]); | ||
| 1089 | my $value = $_[++$i]; | ||
| 1090 | |||
| 1091 | return error("Invalid parameter '$action'") if ($action !~ /^(add|rem|chg)$/); | ||
| 1092 | return error("Missing parameter") if (!$type || !$value); | ||
| 1093 | return error("Invalid property '$type'") if ($type !~ /^(addr|status|name)$/); | ||
| 1094 | |||
| 1095 | if ($type eq 'addr') { | ||
| 1096 | push(@{$changes->{'addr'}}, [ $action, $value ]); | ||
| 1097 | |||
| 1098 | } elsif ($type eq 'status') { | ||
| 1099 | push(@{$changes->{'status'}}, [ $action, $value ]); | ||
| 1100 | |||
| 1101 | } elsif ($action eq 'chg') { | ||
| 1102 | if ($type ne 'name') { | ||
| 1103 | return error("You can only change the host name"); | ||
| 1104 | |||
| 1105 | } else { | ||
| 1106 | $frame->chgName($value); | ||
| 1107 | |||
| 1108 | } | ||
| 1109 | |||
| 1110 | } else { | ||
| 1111 | return error("Don't know what to do with '$action $type $value'"); | ||
| 1112 | |||
| 1113 | } | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | # we need to add <addr> elements first | ||
| 1117 | foreach my $change (@{$changes->{'addr'}}) { | ||
| 1118 | my ($action, $value) = @{$change}; | ||
| 1119 | if ($action eq 'add') { | ||
| 1120 | $frame->addAddr({'ip' => $value, 'version' => ($value =~ /:/ ? 'v6' : 'v4') }); | ||
| 1121 | |||
| 1122 | } else { | ||
| 1123 | $frame->remAddr({'ip' => $value, 'version' => ($value =~ /:/ ? 'v6' : 'v4') }); | ||
| 1124 | |||
| 1125 | } | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | # we need to add <status> elements second | ||
| 1129 | foreach my $change (@{$changes->{'status'}}) { | ||
| 1130 | my ($action, $value) = @{$change}; | ||
| 1131 | if ($action eq 'add') { | ||
| 1132 | $frame->addStatus($value); | ||
| 1133 | |||
| 1134 | } else { | ||
| 1135 | $frame->remStatus($value); | ||
| 1136 | |||
| 1137 | } | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | return $epp->request($frame); | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | sub contact_update { | ||
| 1144 | my $id = shift; | ||
| 1145 | |||
| 1146 | my $frame = Net::EPP::Frame::Command::Update::Contact->new; | ||
| 1147 | |||
| 1148 | $frame->setContact($id); | ||
| 1149 | |||
| 1150 | $epp->{noout} = 1; | ||
| 1151 | my $info = $epp->contact_info($id); | ||
| 1152 | delete($epp->{noout}); | ||
| 1153 | |||
| 1154 | my $changes = {}; | ||
| 1155 | my $postalInfoType = 'int'; | ||
| 1156 | my $postalInfo = {}; | ||
| 1157 | |||
| 1158 | for (my $i = 0 ; $i < scalar(@_) ; $i++) { | ||
| 1159 | my $action = lc($_[$i]); | ||
| 1160 | my $type = lc($_[++$i]); | ||
| 1161 | my $value = $_[++$i]; | ||
| 1162 | |||
| 1163 | return error("Missing parameter") if (!defined($type) || !defined($value)); | ||
| 1164 | |||
| 1165 | if ($action =~ /^(add|rem)$/) { | ||
| 1166 | if ('status' ne $type) { | ||
| 1167 | return error('only status codes can be added/removed'); | ||
| 1168 | |||
| 1169 | } elsif ('add' eq $action) { | ||
| 1170 | $frame->addStatus($value); | ||
| 1171 | |||
| 1172 | } else { | ||
| 1173 | $frame->remStatus($value); | ||
| 1174 | |||
| 1175 | } | ||
| 1176 | } elsif ($action ne 'chg') { | ||
| 1177 | return error("Invalid parameter '$action'"); | ||
| 1178 | |||
| 1179 | } else { | ||
| 1180 | if ($type =~ /^(voice|fax|email|authInfo)$/) { | ||
| 1181 | $changes->{$type} = $value; | ||
| 1182 | |||
| 1183 | } elsif ('type' eq $type) { | ||
| 1184 | if ($type !~ /^(int|loc)$/) { | ||
| 1185 | return error(sprintf("invalid postal info type '%s'", $type)); | ||
| 1186 | } | ||
| 1187 | |||
| 1188 | $postalInfoType = $value; | ||
| 1189 | |||
| 1190 | } elsif ($type =~ /^street([1-3])$/) { | ||
| 1191 | $postalInfo->{$postalInfoType} = $info->{'postalInfo'}->{$postalInfoType} unless exists($postalInfo->{$postalInfoType}); | ||
| 1192 | |||
| 1193 | $postalInfo->{$postalInfoType}->{'addr'}->{'street'}->[$1 - 1] = $value; | ||
| 1194 | |||
| 1195 | } elsif ($type =~ /^(name|org)$/) { | ||
| 1196 | $postalInfo->{$postalInfoType} = $info->{'postalInfo'}->{$postalInfoType} unless exists($postalInfo->{$postalInfoType}); | ||
| 1197 | |||
| 1198 | $postalInfo->{$postalInfoType}->{$type} = $value; | ||
| 1199 | |||
| 1200 | } elsif ($type =~ /^(city|sp|pc|cc)$/) { | ||
| 1201 | $postalInfo->{$postalInfoType} = $info->{'postalInfo'}->{$postalInfoType} unless exists($postalInfo->{$postalInfoType}); | ||
| 1202 | |||
| 1203 | $postalInfo->{$postalInfoType}->{'addr'}->{$type} = $value; | ||
| 1204 | |||
| 1205 | } else { | ||
| 1206 | return error(sprintf("unsupported object property '%s'", $type)); | ||
| 1207 | |||
| 1208 | } | ||
| 1209 | } | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | foreach my $type (keys(%{$postalInfo})) { | ||
| 1213 | $frame->chgPostalInfo($type, map { $postalInfo->{$type}->{$_} } qw(name org addr)); | ||
| 1214 | } | ||
| 1215 | |||
| 1216 | foreach (qw(voice fax email authInfo)) { | ||
| 1217 | if (exists($changes->{$_})) { | ||
| 1218 | my $method = 'chg'.ucfirst($_); | ||
| 1219 | $frame->$method($changes->{$_}); | ||
| 1220 | } | ||
| 1221 | } | ||
| 1222 | |||
| 1223 | # | ||
| 1224 | # remove empty elements | ||
| 1225 | # | ||
| 1226 | foreach (qw(add rem chg)) { | ||
| 1227 | my $el = $frame->getElementsByLocalName('contact:'.$_)->item(0); | ||
| 1228 | $el->parentNode->removeChild($el) if ($el && $el->childNodes->size < 1); | ||
| 1229 | } | ||
| 1230 | |||
| 1231 | return $epp->request($frame); | ||
| 1232 | } | ||
| 1233 | |||
| 1234 | sub note { | ||
| 1235 | my ($fmt, @args) = @_; | ||
| 1236 | my $msg = '*** '.sprintf($fmt, @args); | ||
| 1237 | $outfh->print($msg."\n"); | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | sub error { | ||
| 1241 | my ($fmt, @args) = @_; | ||
| 1242 | if ($term) { | ||
| 1243 | note(color('red')."Error: ".color('reset').$fmt, @args); | ||
| 1244 | return undef; | ||
| 1245 | |||
| 1246 | } else { | ||
| 1247 | fatal(@_); | ||
| 1248 | |||
| 1249 | } | ||
| 1250 | } | ||
| 1251 | |||
| 1252 | sub fatal { | ||
| 1253 | my ($fmt, @args) = @_; | ||
| 1254 | note(color('red')."Fatal Error: ".color('reset').$fmt, @args); | ||
| 1255 | exit(1); | ||
| 1256 | } | ||
| 1257 | |||
| 1258 | 1; | ||
| 1259 | |||
| 1260 | =pod | ||
| 1261 | |||
| 1262 | =for comment | ||
| 1263 | To generate the README.md, run pod2markdown pepper | pandoc -f markdown -t markdown -s --toc > README.md | ||
| 1264 | |||
| 1265 | =head1 NAME | ||
| 1266 | |||
| 1267 | Pepper - A command-line EPP client. | ||
| 1268 | |||
| 1269 | =head1 DESCRIPTION | ||
| 1270 | |||
| 1271 | Pepper is a command-line client for the EPP protocol. It's written in Perl and uses the L<Net::EPP> module. | ||
| 1272 | |||
| 1273 | =head1 USAGE | ||
| 1274 | |||
| 1275 | pepper [OPTIONS] | ||
| 1276 | |||
| 1277 | Available command-line options: | ||
| 1278 | |||
| 1279 | =over | ||
| 1280 | |||
| 1281 | =item * C<--help> - show help and exit. | ||
| 1282 | |||
| 1283 | =item * C<--host=HOST> - sets the host to connect to. | ||
| 1284 | |||
| 1285 | =item * C<--port=PORT> - sets the port. Defaults to 700. | ||
| 1286 | |||
| 1287 | =item * C<--timeout=TIMEOUT> - sets the timeout. Defaults to 3. | ||
| 1288 | |||
| 1289 | =item * C<--user=USER> - sets the client ID. | ||
| 1290 | |||
| 1291 | =item * C<--pass=PASS> - sets the client password. | ||
| 1292 | |||
| 1293 | =item * C<--newpw=PASS> - specify a new password to replace the current password. | ||
| 1294 | |||
| 1295 | =item * C<--login-security> - force the use of the Login Security extension (RFC 8807). | ||
| 1296 | |||
| 1297 | =item * C<--cert=FILE> - specify the client certificate to use to connect. | ||
| 1298 | |||
| 1299 | =item * C<--key=FILE> - specify the private key for the client certificate. | ||
| 1300 | |||
| 1301 | =item * C<--exec=COMMAND> - specify a command to execute. If not provided, pepper goes into interactive mode. | ||
| 1302 | |||
| 1303 | =item * C<--nossl> - disable TLS and connect over plaintext. | ||
| 1304 | |||
| 1305 | =item * C<--insecure> - disable TLS certificate checks. | ||
| 1306 | |||
| 1307 | =item * C<--lang=LANG> - set the language when logging in. | ||
| 1308 | |||
| 1309 | =item * C<--debug> - debug mode, makes C<Net::EPP::Simple> verbose. | ||
| 1310 | |||
| 1311 | =back | ||
| 1312 | |||
| 1313 | =head1 USAGE MODES | ||
| 1314 | |||
| 1315 | Pepper supports two usage modes: | ||
| 1316 | |||
| 1317 | =over | ||
| 1318 | |||
| 1319 | =item 1. B<Interactive mode:> this is the default mode. Pepper will provide a command prompt (with history and line editing capabilities) allowing you to input commands manually. | ||
| 1320 | |||
| 1321 | =item 2. B<Script mode:> if Pepper's C<STDIN> is fed a stream of text (ie, it's not attached to a terminal) then commands will be read from C<STDIN> and executed sequentially. Pepper will exit once EOF is reached. | ||
| 1322 | |||
| 1323 | =back | ||
| 1324 | |||
| 1325 | =head1 SYNTAX | ||
| 1326 | |||
| 1327 | Once running in interactive mode, Pepper provides a simple command-line interface. The available commands are listed below. | ||
| 1328 | |||
| 1329 | =head2 Getting Help | ||
| 1330 | |||
| 1331 | Use C<help COMMAND> at any time to get information about that command. Where a command supports different object types (ie domain, host, contact), use C<help command-type>, ie C<help create-domain>. | ||
| 1332 | |||
| 1333 | =head2 Connection Management | ||
| 1334 | |||
| 1335 | =over | ||
| 1336 | |||
| 1337 | =item * C<host HOST> - sets the host to connect to. | ||
| 1338 | |||
| 1339 | =item * C<port PORT> - sets the port. Defaults to 700. | ||
| 1340 | |||
| 1341 | =item * C<ssl on|off> - enable/disable SSL (default is on) | ||
| 1342 | |||
| 1343 | =item * C<key FILE> - sets the private key | ||
| 1344 | |||
| 1345 | =item * C<cert FILE> - sets the client certificate. | ||
| 1346 | |||
| 1347 | =item * C<timeout TIMEOUT> - sets the timeout | ||
| 1348 | |||
| 1349 | =item * C<connect> - connect to the server. | ||
| 1350 | |||
| 1351 | =item * C<hello> - gets the greeting from server. | ||
| 1352 | |||
| 1353 | =item * C<exit> - quit the program (logging out if necessary) | ||
| 1354 | |||
| 1355 | =back | ||
| 1356 | |||
| 1357 | =head2 Session Management | ||
| 1358 | |||
| 1359 | =over | ||
| 1360 | |||
| 1361 | =item * C<id USER> - sets the client ID. | ||
| 1362 | |||
| 1363 | =item * C<pw PASS> - sets the client password. | ||
| 1364 | |||
| 1365 | =item * C<login> - log in. | ||
| 1366 | |||
| 1367 | =item * C<logout> - log out. | ||
| 1368 | |||
| 1369 | =item * C<poll req> - requests the most recent poll message. | ||
| 1370 | |||
| 1371 | =item * C<poll ack ID> - acknowledge the poll message with ID C<ID>. | ||
| 1372 | |||
| 1373 | =back | ||
| 1374 | |||
| 1375 | =head2 Query Commands | ||
| 1376 | |||
| 1377 | =head3 Availability Checks | ||
| 1378 | |||
| 1379 | check TYPE OBJECT | ||
| 1380 | |||
| 1381 | This checks the availability of an object. C<TYPE> is one of C<domain>, C<host>, C<contact>, C<claims> or C<fee>. See L<Claims and fee Checks> for more information about the latter two. | ||
| 1382 | |||
| 1383 | =head3 Object Information | ||
| 1384 | |||
| 1385 | info TYPE OBJECT [PARAMS] | ||
| 1386 | |||
| 1387 | Get object information. C<TYPE> is one of C<domain>, C<host>, C<contact>. For domain objects, C<PARAMS> can be C<AUTHINFO [HOSTS]>, where C<AUTHINFO> is the domain's authInfo code, and the optional C<HOSTS> is the value of the "hosts" attribute (ie C<all>, which is the default, or C<del>, C<sub>, or C<none>). If you want to set C<HOSTS> but don't know the authInfo, use an empty quoted string (ie C<"">) as C<AUTHINFO>. | ||
| 1388 | |||
| 1389 | For contact objects, C<PARAMS> can be the contact's authInfo. | ||
| 1390 | |||
| 1391 | =head2 Transform Commands | ||
| 1392 | |||
| 1393 | =over | ||
| 1394 | |||
| 1395 | =item * C<create domain PARAMS> - create a domain object. See L<Creating Domain Objects> for more information. | ||
| 1396 | |||
| 1397 | =item * C<create host PARAMS> - create a host object. See L<Creating Host Objects> for more information. | ||
| 1398 | |||
| 1399 | =item * C<clone TYPE OLD NEW> - clone a domain or contact object C<OLD> into a new object identified by C<NEW>. C<TYPE> is one of C<domain> or C<contact>. | ||
| 1400 | |||
| 1401 | =item * C<update TYPE OBJECT CHANGES> - update an object. C<TYPE> is one of C<domain>, C<host>, or C<contact>. See L<Object Updates> for further information. | ||
| 1402 | |||
| 1403 | =item * C<renew DOMAIN PERIOD [EXDATE]> - renew a domain (1 year by default). If you do not provide the C<EXDATE> argument, pepper will perform an C<E<lt>infoE<gt>> command to get it from the server. | ||
| 1404 | |||
| 1405 | =item * C<transfer PARAMS> - object transfer management See L<Object Transfers> for more information. | ||
| 1406 | |||
| 1407 | =item * C<delete TYPE OBJECT> - delete an object. C<TYPE> is one of C<domain>, C<host>, or C<contact>. | ||
| 1408 | |||
| 1409 | =item * C<restore DOMAIN> - submit an RGP restore request for a domain. | ||
| 1410 | |||
| 1411 | =back | ||
| 1412 | |||
| 1413 | =head2 Miscellaneous Commands | ||
| 1414 | |||
| 1415 | =over | ||
| 1416 | |||
| 1417 | =item * C<send FILE> - send the contents of C<FILE> as an EPP command. | ||
| 1418 | |||
| 1419 | =item * C<BEGIN> - begin inputting a frame to send to the server, end with "C<END>". | ||
| 1420 | |||
| 1421 | =item * C<edit> - Invoke C<$EDITOR> and send the resulting file. | ||
| 1422 | |||
| 1423 | =back | ||
| 1424 | |||
| 1425 | =head2 Claims and fee Checks | ||
| 1426 | |||
| 1427 | Pepper provides limited support for the the Launch and Fee extensions: | ||
| 1428 | |||
| 1429 | =head3 Claims Check | ||
| 1430 | |||
| 1431 | The following command will extend the standard E<lt>checkE<gt> command to perform | ||
| 1432 | a claims check as per Section 3.1.1. of L<draft-ietf-eppext-launchphase>. | ||
| 1433 | |||
| 1434 | pepper> check claims example.xyz | ||
| 1435 | |||
| 1436 | =head3 Fee Check | ||
| 1437 | |||
| 1438 | The following command will extend the standard E<lt>checkE<gt> command to perform | ||
| 1439 | a fee check as per Section 3.1.1. of L<draft-brown-epp-fees-02>. | ||
| 1440 | |||
| 1441 | pepper> check fee example.xyz COMMAND [CURRENCY [PERIOD]] | ||
| 1442 | |||
| 1443 | C<COMMAND> must be one of: C<create>, C<renew>, C<transfer>, or C<restore>. | ||
| 1444 | C<CURRENCY> is OPTIONAL but if provided, must be a three-character currency code. | ||
| 1445 | C<PERIOD> is also OPTIONAL but if provided, must be an integer between 1 and 99. | ||
| 1446 | |||
| 1447 | =head2 Creating Objects | ||
| 1448 | |||
| 1449 | =head3 Creating Domain Objects | ||
| 1450 | |||
| 1451 | There are two ways of creating a domain: | ||
| 1452 | |||
| 1453 | clone domain OLD NEW | ||
| 1454 | |||
| 1455 | This command creates the domain C<NEW> using the same contacts and nameservers as C<OLD>. | ||
| 1456 | |||
| 1457 | create domain DOMAIN PARAMS | ||
| 1458 | |||
| 1459 | This command creates a domain according to the parameters specified after the domain. C<PARAMS> consists of pairs of name and (optionally quoted) value pairs as follows: | ||
| 1460 | |||
| 1461 | =over | ||
| 1462 | |||
| 1463 | =item * C<period> - the registration period. Defaults to 1 year. | ||
| 1464 | |||
| 1465 | =item * C<registrant> - the registrant. | ||
| 1466 | |||
| 1467 | =item * C<admin> - the admin contact. | ||
| 1468 | |||
| 1469 | =item * C<tech> - the tech contact. | ||
| 1470 | |||
| 1471 | =item * C<billing> - the billing contact. | ||
| 1472 | |||
| 1473 | =item * C<ns> - add a nameserver. | ||
| 1474 | |||
| 1475 | =item * C<authinfo> - authInfo code. A random string will be used if not provided. | ||
| 1476 | |||
| 1477 | =back | ||
| 1478 | |||
| 1479 | Example: | ||
| 1480 | |||
| 1481 | pepper (id@host)> create domain example.xyz period 1 registrant sh8013 admin sh8013 tech sh8013 billing sh8013 ns ns0.example.com ns ns1.example.net | ||
| 1482 | |||
| 1483 | =head3 Creating Host Objects | ||
| 1484 | |||
| 1485 | Syntax: | ||
| 1486 | |||
| 1487 | create host HOSTNAME [IP [IP [IP [...]]]] | ||
| 1488 | |||
| 1489 | Create a host object with the specified C<HOSTNAME>. IP address may also be | ||
| 1490 | specified: IPv4 and IPv6 addresses are automatically detected. | ||
| 1491 | |||
| 1492 | =head3 Creating Contact Objects | ||
| 1493 | |||
| 1494 | There are two ways of creating a contact: | ||
| 1495 | |||
| 1496 | clone contact OLD NEW | ||
| 1497 | |||
| 1498 | This command creates the contact C<NEW> using the same data as C<OLD>. | ||
| 1499 | |||
| 1500 | create contact PARAMS | ||
| 1501 | |||
| 1502 | This command creates a contact object according to the parameters specified. C<PARAMS> consists of pairs of name and (optionally quoted) value pairs as follows: | ||
| 1503 | |||
| 1504 | =over | ||
| 1505 | |||
| 1506 | =item * C<id> - contact ID. If not provided, a random 16-charater ID will be generated | ||
| 1507 | |||
| 1508 | =item * C<type> - specify the "type" attribute for the postal address information. Only one type is supported. Possible values are "int" (default) and "loc". | ||
| 1509 | |||
| 1510 | =item * C<name> - contact name | ||
| 1511 | |||
| 1512 | =item * C<org> - contact organisation | ||
| 1513 | |||
| 1514 | =item * C<street> - street address, may be provided multiple times | ||
| 1515 | |||
| 1516 | =item * C<city> - city | ||
| 1517 | |||
| 1518 | =item * C<sp> - state/province | ||
| 1519 | |||
| 1520 | =item * C<pc> - postcode | ||
| 1521 | |||
| 1522 | =item * C<cc> - ISO-3166-alpha2 country code | ||
| 1523 | |||
| 1524 | =item * C<voice> - E164 voice number | ||
| 1525 | |||
| 1526 | =item * C<fax> - E164 fax number | ||
| 1527 | |||
| 1528 | =item * C<email> - email address | ||
| 1529 | |||
| 1530 | =item * C<authinfo> - authInfo code. A random string will be used if not provided. | ||
| 1531 | |||
| 1532 | =back | ||
| 1533 | |||
| 1534 | Example: | ||
| 1535 | |||
| 1536 | pepper (id@host)> create contact id "sh8013" name "John Doe" org "Example Inc." type int street "123 Example Dr." city Dulles sp VA pc 20166-6503 cc US voice +1.7035555555 email jdoe@example.com | ||
| 1537 | |||
| 1538 | =head2 Object Updates | ||
| 1539 | |||
| 1540 | Objects may be updated using the C<update> command. | ||
| 1541 | |||
| 1542 | =head3 Domain Updates | ||
| 1543 | |||
| 1544 | update domain DOMAIN CHANGES | ||
| 1545 | |||
| 1546 | The C<CHANGES> argument consists of groups of three values: an action (ie C<add>, C<rem> or C<chg>), followed by a property name (e.g. C<ns>, a contact type (such as C<admin>, C<tech> or C<billing>) or C<status>), followed by a value. | ||
| 1547 | |||
| 1548 | Example: | ||
| 1549 | |||
| 1550 | update domain example.com add ns ns0.example.com | ||
| 1551 | |||
| 1552 | update domain example.com rem ns ns0.example.com | ||
| 1553 | |||
| 1554 | update domain example.com add status clientUpdateProhibited | ||
| 1555 | |||
| 1556 | update domain example.com rem status clientHold | ||
| 1557 | |||
| 1558 | update domain example.com add admin H12345 | ||
| 1559 | |||
| 1560 | update domain example.com rem tech H54321 | ||
| 1561 | |||
| 1562 | update domain example.com chg registrant H54321 | ||
| 1563 | |||
| 1564 | update domain example.cm chg authinfo foo2bar | ||
| 1565 | |||
| 1566 | Multiple changes can be combined in a single command: | ||
| 1567 | |||
| 1568 | update domain example.com add status clientUpdateProhibited rem ns ns0.example.com chg registrant H54321 | ||
| 1569 | |||
| 1570 | =head3 Host Updates | ||
| 1571 | |||
| 1572 | Syntax: | ||
| 1573 | |||
| 1574 | update host HOSTNAME CHANGES | ||
| 1575 | |||
| 1576 | The C<CHANGES> argument consists of groups of three values: an action (ie C<add>, C<rem> or C<chg>), followed by a property name (ie C<addr>, C<status> or C<name>), followed by a value (which may be quoted). | ||
| 1577 | |||
| 1578 | Examples: | ||
| 1579 | |||
| 1580 | update host ns0.example.com add status clientUpdateProhibited | ||
| 1581 | |||
| 1582 | update host ns0.example.com rem addr 10.0.0.1 | ||
| 1583 | |||
| 1584 | update host ns0.example.com chg name ns0.example.net | ||
| 1585 | |||
| 1586 | Multiple changes can be combined in a single command: | ||
| 1587 | |||
| 1588 | update host ns0.example.com add status clientUpdateProhibited rem addr 10.0.0.1 add addr 1::1 chg name ns0.example.net | ||
| 1589 | |||
| 1590 | =head3 Contact Updates | ||
| 1591 | |||
| 1592 | update contact ID CHANGES | ||
| 1593 | |||
| 1594 | The C<CHANGES> argument consists of groups of three values: an action (ie C<add>, C<rem> or C<chg>), followed by a property name, followed by a value (which may be quoted, and may be empty). The property name may be one of: | ||
| 1595 | |||
| 1596 | =over | ||
| 1597 | |||
| 1598 | =item * C<status> | ||
| 1599 | |||
| 1600 | =item * C<name> | ||
| 1601 | |||
| 1602 | =item * C<type> (either "C<int>" or "C<loc>", which applies to all subsequent values, and which may appear multiple times) | ||
| 1603 | |||
| 1604 | =item * C<org> | ||
| 1605 | |||
| 1606 | =item * C<street1>, C<street2>, C<street3> | ||
| 1607 | |||
| 1608 | =item * C<city> | ||
| 1609 | |||
| 1610 | =item * C<sp> | ||
| 1611 | |||
| 1612 | =item * C<pc> | ||
| 1613 | |||
| 1614 | =item * C<cc> | ||
| 1615 | |||
| 1616 | =item * C<voice> | ||
| 1617 | |||
| 1618 | =item * C<fax> | ||
| 1619 | |||
| 1620 | =item * C<email> | ||
| 1621 | |||
| 1622 | =item * C<authInfo> | ||
| 1623 | |||
| 1624 | =back | ||
| 1625 | |||
| 1626 | If postal address information is being changed, then any values not specified in the command line will be populated from the existing object information. This is because contact information is updated atomically. | ||
| 1627 | |||
| 1628 | Examples: | ||
| 1629 | |||
| 1630 | pepper (id@host)> create contact id "sh8013" name "John Doe" org "Example Inc." type int street "123 Example Dr." city Dulles sp VA pc 20166-6503 cc US voice email jdoe@example.com | ||
| 1631 | |||
| 1632 | update contact sh8013 chg email example@example.com | ||
| 1633 | |||
| 1634 | update contact sh8013 chg voice +1.7035555555 | ||
| 1635 | |||
| 1636 | update contact sh8013 street1 "123 Example Dr." street2 "" street3 "" | ||
| 1637 | |||
| 1638 | update contact city Dulles sp VA pc 20166-6503 cc US | ||
| 1639 | |||
| 1640 | update contact authInfo foo2bar | ||
| 1641 | |||
| 1642 | =head2 Object Transfers | ||
| 1643 | |||
| 1644 | Object transfers may be managed with the C<transfer> command. Usage: | ||
| 1645 | |||
| 1646 | transfer TYPE OBJECT CMD [AUTHINFO [PERIOD]] | ||
| 1647 | |||
| 1648 | where: | ||
| 1649 | |||
| 1650 | =over | ||
| 1651 | |||
| 1652 | =item * C<TYPE> - C<domain> or C<contact> | ||
| 1653 | |||
| 1654 | =item * C<OBJECT> - domain name or contact ID | ||
| 1655 | |||
| 1656 | =item * C<CMD> - one of (C<request>, C<query>, C<approve>, C<reject>, or C<cancel>) | ||
| 1657 | |||
| 1658 | =item * C<AUTHINFO> - authInfo code (used with C<request> only) | ||
| 1659 | |||
| 1660 | =item * C<PERIOD> - additional validity period (used with domain C<request> only) | ||
| 1661 | |||
| 1662 | =back | ||
| 1663 | |||
| 1664 | =head2 Errors | ||
| 1665 | |||
| 1666 | If you prefix a command with a C<!> character, then Pepper will end the session if an EPP command fails (that is, if the result code of the response is 2000 or higher). | ||
| 1667 | |||
| 1668 | This is mostly useful in scripting mode where you may want the script to terminate if an error occurs. | ||
| 1669 | |||
| 1670 | Example usage: | ||
| 1671 | |||
| 1672 | !create domain example.com authinfo foo2bar | ||
| 1673 | update domain example.com add ns ns0.example.com | ||
| 1674 | |||
| 1675 | In the above example, Pepper will end the session if the first command fails, since there is no point in running the second command if the first has failed. | ||
| 1676 | |||
| 1677 | =head1 INSTALLATION | ||
| 1678 | |||
| 1679 | To install, run: | ||
| 1680 | |||
| 1681 | cpanm --sudo App::pepper | ||
| 1682 | |||
| 1683 | If L<Term::ReadLine::Gnu> is available, then Pepper can provide a richer interactive command line, with support for history and rich command editing. | ||
| 1684 | |||
| 1685 | =head1 RUNNING VIA DOCKER | ||
| 1686 | |||
| 1687 | The L<git repository|https://github.com/gbxyz/pepper> contains a C<Dockerfile> | ||
| 1688 | that can be used to build an image on your local system. | ||
| 1689 | |||
| 1690 | Alternatively, you can pull the L<image from Docker Hub|https://hub.docker.com/r/gbxyz/pepper>: | ||
| 1691 | |||
| 1692 | $ docker pull gbxyz/pepper | ||
| 1693 | |||
| 1694 | $ docker run -it gbxyz/pepper --help | ||
| 1695 | |||
| 1696 | =head1 LICENSE | ||
| 1697 | |||
| 1698 | Copyright 2014 - 2023 CentralNic Group plc. | ||
| 1699 | Copyright 2023 - 2025 Gavin Brown. | ||
| 1700 | |||
| 1701 | This program is Free Software; you can use it and/or modify it under the same terms as Perl itself. | ||
| 1702 | |||
| 1703 | =cut |