]> git.defcon.no Git - hermes/blobdiff - api/user.php
backlog add
[hermes] / api / user.php
index 260ac35016365afc7f19a8d703beccd74ce019e5..e8099d9dfebcfbe479f840c277d043c5b8fe10b9 100644 (file)
@@ -101,6 +101,40 @@ token_auth();
                        else
                                print json_encode ( array( 'response' => 'invalid') );
                        break;
+
+               case "/location":
+                       if ( array_key_exists('user', $_POST) ||
+                               ( array_key_exists('username', $_POST) && array_key_exists('domain', $_POST )))
+                       {
+                               $username = "";
+                               $domain = "";
+                               if ( array_key_exists('username', $_POST) )
+                               {
+                                       $username = $_POST['username'];
+                                       $domain = $_POST['domain'];
+                               }
+                               else
+                               {
+                                       $user = split_sipaddress($_POST['user']);
+                                       if ( !$user )
+                                       {
+                                               print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
+                                               break;
+                                       }
+                                       list ( $username, $domain ) = $user;
+                               }
+                               $location = get_locations( $username, $domain );
+                               if ( $location == null )
+                               {
+                                       print json_encode( array( 'response' => 'failed', 'cause' => 'offline' ));
+                                       break;
+                               }
+                               print json_encode( array( 'response' => 'ok', 'locations' => $location ));
+                       }
+                       else
+                               print json_encode ( array( 'response' => 'invalid') );
+                       break;
+
                case "/list":
                        /* 
                        Simply list all users in user@domain format