From: Jon Langseth Date: Tue, 24 Apr 2012 09:24:32 +0000 (+0200) Subject: Added auto-location of config file to scripts tool-scripts X-Git-Url: https://git.defcon.no/?p=hermes;a=commitdiff_plain;h=7ba75390b050c627e8466d046dfcdc83bd2d1ab6 Added auto-location of config file to scripts tool-scripts --- diff --git a/guc-clients/add_apikey.pl b/guc-clients/add_apikey.pl index a543c23..ce303bd 100755 --- a/guc-clients/add_apikey.pl +++ b/guc-clients/add_apikey.pl @@ -13,13 +13,21 @@ my $level = ""; my $keyfile =""; my $api_base = ""; my $api_key = ""; -my $configfile; +my $configfile = undef; 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, "host=s" => \$host_ip, diff --git a/guc-clients/addsipuser b/guc-clients/addsipuser index cacbad2..00eae4b 100755 --- a/guc-clients/addsipuser +++ b/guc-clients/addsipuser @@ -18,7 +18,7 @@ my $api_key; my $help; my $username; -my $configfile; +my $configfile = undef; my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $displayname, $phone, $mail, $sipuser, $linetext); @@ -37,6 +37,14 @@ $config->define("default_domain=s"); #TODO: Move this to config file. $config->default_domain("hig.no"); +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, "username=s" => \$username, diff --git a/guc-clients/assignphone b/guc-clients/assignphone index 91b10a9..4b06f66 100755 --- a/guc-clients/assignphone +++ b/guc-clients/assignphone @@ -13,7 +13,7 @@ my $api_key; my $help; my $username; -my $configfile; +my $configfile = undef; my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $sipuser, $mac); @@ -23,6 +23,14 @@ 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, diff --git a/guc-clients/feide2sipuser b/guc-clients/feide2sipuser index 5660c5e..fe20e47 100755 --- a/guc-clients/feide2sipuser +++ b/guc-clients/feide2sipuser @@ -13,7 +13,7 @@ my $api_key; my $help; my $username; -my $configfile; +my $configfile = undef; my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $displayname, $phone, $mail, $sipuser, $linetext); @@ -31,6 +31,14 @@ $config->define("numbers_local_prefix=s"); $config->define("numbers_local_series=s"); $config->define("numbers_countrycode=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, "username=s" => \$username, diff --git a/guc-clients/listsipusers b/guc-clients/listsipusers index 3648cd0..fccedb0 100755 --- a/guc-clients/listsipusers +++ b/guc-clients/listsipusers @@ -13,14 +13,11 @@ use JSON; use AppConfig; use Text::Iconv; -use Data::Dumper; - -my $utf2iso = Text::Iconv->new("utf-8","latin1"); my $api_key; my $help; my $username; -my $configfile; +my $configfile = undef; my $dryrun = 0; my ($g_ua, $session, $api_key, $auth_key, $data, $domain); my ($user, $displayname, $phone, $mail, $sipuser, $linetext); @@ -30,8 +27,13 @@ my $config = AppConfig->new({ CREATE => 1 }); $config->define("api_url=s"); $config->define("api_keyfile=s"); -#TODO: Move this to config file. -$config->default_domain("hig.no"); +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,