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);
"macaddress=s" => \$mac,
"username=s" => \$username,
"configfile=s" => \$configfile,
+ "remove" => \$remove,
"dryrun" => \$dryrun,
);
--configfile=s|--config|-c
--username=s|--user|-u
--macaddress=s|--mac|-m
+ --remove|-r
--dryrun|--dry|-d
Verify the contents of the configuration file.
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($$)