]>
git.defcon.no Git - hermes/blob - guc-clients/showsipuser
4 #TODO: Add support for assigning phone number
5 #TODO: Add support for overriding default domain ...
9 use Net
::LDAP
::Control
::Paged
;
10 use Net
::LDAP
::Constant
qw( LDAP_CONTROL_PAGED );
18 my $utf2iso = Text
::Iconv
->new("utf-8","latin1");
23 my $configfile = undef;
25 my ($g_ua, $session, $api_key, $auth_key, $data, $domain);
26 my ($user, $displayname, $phone, $mail, $sipuser, $linetext);
28 my $config = AppConfig
->new({ CREATE
=> 1 });
30 $config->define("api_url=s");
31 $config->define("api_keyfile=s");
33 $config->define("default_domain=s");
34 $config->default_domain("hig.no");
37 "/usr/local/etc/hermes/hermes_config",
38 "/usr/local/etc/hermes/config",
40 $ENV{"HOME"} . "/.hermes/config",
41 $ENV{"HOME"} . "/.hermes_config",
42 ) { $configfile = $_ if ( -f
$_ ); }
46 "username=s" => \
$username,
47 "configfile=s" => \
$configfile,
53 (( $configfile ) && ( not -f
$configfile ))
59 $config->file( $configfile );
61 if ( ( not $config->api_url ) ||
62 ( not $config->api_keyfile ) ||
63 ( not $config->default_domain ) ||
64 ( $config->api_keyfile && not -f
$config->api_keyfile )
72 Verify that the following options are set:
73 --configfile=s|--conf|-c path to hermes_config
74 --username=s|--user|-u username, in 'user' or 'user\@example.com' form
76 Verify the contents of the configuration file.
77 Verify that the key-file exists.
81 open KEY, "<" . $config->api_keyfile;
82 chomp( $api_key = <KEY> );
85 $g_ua = LWP::UserAgent->new;
86 $g_ua->cookie_jar({}); # In-memory jar, look at HTTP::Cookies for persistant
88 $username = $username . "@" . $config->default_domain if ( not $username =~ m/\w\@\w/ );
92 $data = exec_apinode("user/get", { 'user' => $username });
93 if ( not $data->{'response'} eq 'ok' )
95 printf("Unable to fetch user: %s\n", $data->{'cause'});
99 my $user = $data->{'user'};
102 printf("Subscriber....: %s\n", $username);
103 printf("Displayname...: %s\n", $user->{'displayname'});
104 printf("E-mail........: %s\n", $user->{'email'});
106 printf("Auth username.: %s\n", $user->{'authid'});
107 printf("Auth password.: %s\n", $user->{'password'});
108 printf("Domain........: %s\n", $user->{'domain'});
109 printf("Registrar.....: %s\n", $user->{'registrar'});
110 printf("Proxy.........: %s\n", $user->{'proxy'});
111 printf("Permissions...: %s\n", $user->{'permittedcalls'});
112 printf("Aliases:\n");
113 my $alias_data = exec_apinode("alias/list", { 'destination' => $username });
114 if ( $alias_data->{'response'} eq 'ok' )
116 #print Dumper($alias_data);
118 my $t = $alias_data->{'aliases'};
119 foreach my $a ( sort {lc $a->{'alias'} cmp lc $b->{'alias'}} @$t )
121 printf("\t\t%s\n", $a->{'alias'});
124 printf("\t\t None\n") if ( $count < 1 );
128 printf("\t\t None\n");
131 my $phone_data = exec_apinode("phone/get", { 'user' => $username });
132 if ( $phone_data->{'response'} eq 'ok' )
134 my $t = $phone_data->{'list'};
136 foreach my $p ( @$t )
138 printf("\t\t%s\n", $p );
141 printf("\t\t None\n") if ( $count < 1 );
153 ################################################################################################
159 my ( $response, $data );
161 $session = "" if not defined $session;
162 $auth_key = "" if not defined $auth_key;
163 my $url = $config->api_url . "/" . $node;
165 $param->{'session'} = $session;
166 $param->{'auth_key'} = $auth_key;
168 $response = $g_ua->post( $url, $param );
169 if ( $response->is_success )
171 if ( $response->content =~ m/\s*{/ )
173 $data = decode_json( $response->content);
177 $data = $response->content;
186 my $response = $g_ua->post( $config->api_url . "/auth/login",
187 [ "api_key" => $api_key ] );
189 my $data = decode_json( $response->content) if $response->is_success;
190 die("HTTP error") unless $response->is_success;
192 if ( $data->{'response'} eq "ok" )
194 $session = $data->{'session'};
195 $auth_key = $data->{'auth_key'};
199 print "Unable to log in to Hermes API\n";
202 undef $data; undef $response;
207 my $response = $g_ua->post( $config->api_url . "/auth/logout",
208 [ "session" => $session ] );
209 die("HTTP error") unless $response->is_success;
210 undef $session; undef $auth_key;