]> git.defcon.no Git - hermes/blobdiff - guc-clients/assignphone
Updates: showsipuser tool to show a sip user, listphones to list registered phones...
[hermes] / guc-clients / assignphone
index 4b06f66eb6f56678e798d87c598d1825c0961d65..bd8a623b8676ab11f3cd72dba9565ffe858acd88 100755 (executable)
@@ -14,6 +14,7 @@ my $api_key;
 my $help;
 my $username;
 my $configfile = undef;
+my $remove = 0;
 my $dryrun = 0;
 my ($g_ua, $session, $api_key, $auth_key, $data, $domain);
 my ($user, $sipuser, $mac);
@@ -36,6 +37,7 @@ GetOptions(
        "macaddress=s"  => \$mac,
        "username=s"    => \$username,
        "configfile=s"  => \$configfile,
+       "remove"        => \$remove,
        "dryrun"        => \$dryrun,
 );
 
@@ -67,6 +69,7 @@ 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.
@@ -116,21 +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($$)