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);
$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 (
--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.
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($$)