From 1fded126d8c419e3c1d07889c2d3d7808c747edc Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Mon, 16 Apr 2012 12:10:51 +0200 Subject: [PATCH] Adding --dryrun|-d option to assignphone and feide2sipuser --- guc-clients/assignphone | 9 +++++++++ guc-clients/feide2sipuser | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/guc-clients/assignphone b/guc-clients/assignphone index 074ab1f..91b10a9 100755 --- a/guc-clients/assignphone +++ b/guc-clients/assignphone @@ -14,6 +14,7 @@ my $api_key; my $help; my $username; my $configfile; +my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $sipuser, $mac); @@ -27,6 +28,7 @@ GetOptions( "macaddress=s" => \$mac, "username=s" => \$username, "configfile=s" => \$configfile, + "dryrun" => \$dryrun, ); if ( @@ -57,6 +59,7 @@ Verify that the following options are set: --configfile=s|--config|-c --username=s|--user|-u --macaddress=s|--mac|-m + --dryrun|--dry|-d Verify the contents of the configuration file. Verify that the key-file exists. @@ -106,6 +109,12 @@ if ( not $data->{'response'} eq 'ok' ) exit; } +if ( $dryrun ) { + print("Dryrun specified. All OK so far, stopping before add.\n"); + logout(); + exit; +} + $data = exec_apinode("phone/add", { 'user' => $sipuser, 'mac' => $mac }); printf("Failed to add phone+user, cause given: '%s'\n", $data->{'cause'}) diff --git a/guc-clients/feide2sipuser b/guc-clients/feide2sipuser index 48e20c8..5660c5e 100755 --- a/guc-clients/feide2sipuser +++ b/guc-clients/feide2sipuser @@ -14,6 +14,7 @@ my $api_key; my $help; my $username; my $configfile; +my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $displayname, $phone, $mail, $sipuser, $linetext); @@ -34,6 +35,7 @@ GetOptions( "help" => \$help, "username=s" => \$username, "configfile=s" => \$configfile, + "dryrun" => \$dryrun, ); if ( @@ -62,6 +64,7 @@ print <cookie_jar({}); # In-memory jar, look at HTTP::Cookies for persistant login_apikey(); + $data = exec_apinode("user/available", { "user" => $sipuser }); if ( not $data->{'response'} eq 'ok' ) { @@ -141,6 +145,12 @@ if ( not $data->{'response'} eq 'ok' ) } undef $data; +if ( $dryrun ) { + print("Dryrun specified. All OK so far, stopping before add.\n"); + logout(); + exit; +} + $data = exec_apinode("user/add_local", { "user" => $sipuser, "displayname" => $displayname, -- 2.39.2