X-Git-Url: https://git.defcon.no/?a=blobdiff_plain;f=guc-clients%2Fassignphone;h=bd8a623b8676ab11f3cd72dba9565ffe858acd88;hb=2f8ceba349fb5fe9df6598bc08961deaffa2a105;hp=074ab1fd8b32853453e6e17a898d7d0d4d68235e;hpb=32b42c418a3bc21529c8992916c6ead97c15ff1e;p=hermes diff --git a/guc-clients/assignphone b/guc-clients/assignphone index 074ab1f..bd8a623 100755 --- a/guc-clients/assignphone +++ b/guc-clients/assignphone @@ -13,7 +13,9 @@ my $api_key; my $help; my $username; -my $configfile; +my $configfile = undef; +my $remove = 0; +my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $sipuser, $mac); @@ -22,11 +24,21 @@ my $config = AppConfig->new({ CREATE => 1 }); $config->define("api_url=s"); $config->define("api_keyfile=s"); +foreach ( + "/usr/local/etc/hermes/hermes_config", + "/usr/local/etc/hermes/config", + "/etc/hermes/config", + $ENV{"HOME"} . "/.hermes/config", + $ENV{"HOME"} . "/.hermes_config", +) { $configfile = $_ if ( -f $_ ); } + GetOptions( "help" => \$help, "macaddress=s" => \$mac, "username=s" => \$username, "configfile=s" => \$configfile, + "remove" => \$remove, + "dryrun" => \$dryrun, ); if ( @@ -57,6 +69,8 @@ Verify that the following options are set: --configfile=s|--config|-c --username=s|--user|-u --macaddress=s|--mac|-m + --remove|-r + --dryrun|--dry|-d Verify the contents of the configuration file. Verify that the key-file exists. @@ -105,15 +119,41 @@ if ( not $data->{'response'} eq 'ok' ) logout(); exit; } +if ( $remove ) +{ + $data = exec_apinode("phone/get", { 'user' => $sipuser, 'mac' => $mac }); + if ( not $data->{'response'} eq 'ok' ) + { + printf("Unable to remove phone+user, lookup gave: '%s'\n", $data->{'cause'}); + logout(); + exit; + } +} +if ( $dryrun ) { + print("Dryrun specified. All OK so far, stopping before add.\n"); + logout(); + exit; +} +if ( $remove ) +{ + $data = exec_apinode("phone/remove", { 'user' => $sipuser, 'mac' => $mac }); -$data = exec_apinode("phone/add", { 'user' => $sipuser, 'mac' => $mac }); + printf("Failed to remove phone+user, cause given: '%s'\n", $data->{'cause'}) + if ( not $data->{'response'} eq 'ok' ); -printf("Failed to add phone+user, cause given: '%s'\n", $data->{'cause'}) - if ( not $data->{'response'} eq 'ok' ); + printf("Removed assigned phone with mac '%s' from user '%s'\n", $mac, $sipuser) + if ( $data->{'response'} eq 'ok' ); +} +else +{ + $data = exec_apinode("phone/add", { 'user' => $sipuser, 'mac' => $mac }); -printf("Assigned phone with mac '%s' to user '%s'\n", $mac, $sipuser) - if ( $data->{'response'} eq 'ok' ); + printf("Failed to add phone+user, cause given: '%s'\n", $data->{'cause'}) + if ( not $data->{'response'} eq 'ok' ); + printf("Assigned phone with mac '%s' to user '%s'\n", $mac, $sipuser) + if ( $data->{'response'} eq 'ok' ); +} logout(); ################################################################################################ sub exec_apinode($$)