]> git.defcon.no Git - hermes/blobdiff - api/phone.php
Adding --dryrun|-d option to assignphone and feide2sipuser
[hermes] / api / phone.php
index a47c4946ff9883924a16cf39bfd621adbf934c05..999824b237bb8795937bd98ca0f1cdad36b40045 100644 (file)
@@ -1,4 +1,30 @@
 <?php
+/*
+#  Copyright (c) 2012, Gjøvik University College
+#  All rights reserved.
+
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions are met:
+#      * Redistributions of source code must retain the above copyright
+#        notice, this list of conditions and the following disclaimer.
+#      * Redistributions in binary form must reproduce the above copyright
+#        notice, this list of conditions and the following disclaimer in the
+#        documentation and/or other materials provided with the distribution.
+#      * Neither the name of the Gjøvik University College nor the
+#        names of its contributors may be used to endorse or promote products
+#        derived from this software without specific prior written permission.
+#       
+#  THIS SOFTWARE IS PROVIDED BY Gjøvik University College ''AS IS'' AND ANY
+#  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+#  DISCLAIMED. IN NO EVENT SHALL Gjøvik University College BE LIABLE FOR ANY
+#  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+#  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
 require_once('config.php');
 require_once('lib/auth_base.php');
 require_once('lib/user_functions.php');
@@ -27,9 +53,9 @@ token_auth();
                        // Required GET parameters:
                        // user: authentication username, SIP-username without domain component
                        // domain: Domain/realm of the user. username + '@' + domain == SIP address.
-                       if ( array_key_exists( 'mac', $_GET) )
+                       if ( array_key_exists( 'mac', $_POST) )
                        {
-                               $mac = $_GET['mac'];
+                               $mac = $_POST['mac'];
                                $relations = get_phone_users ( $mac );
                                if ( $relations )
                                {
@@ -37,18 +63,18 @@ token_auth();
                                }
                                else print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => 'No results.'));
                        }
-                       else if ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) || array_key_exists('user', $_GET) )
+                       else if ( ( array_key_exists( 'username', $_POST) && array_key_exists( 'domain', $_POST ) ) || array_key_exists('user', $_POST) )
                        {
                                $username = "";
                                $domain = "";
-                               if ( array_key_exists('username', $_GET) )
+                               if ( array_key_exists('username', $_POST) )
                                {
-                                       $username = $_GET['username'];
-                                       $domain = $_GET['domain'];
+                                       $username = $_POST['username'];
+                                       $domain = $_POST['domain'];
                                }
                                else
                                {
-                                       $user = split_sipaddress($_GET['user']);
+                                       $user = split_sipaddress($_POST['user']);
                                        if ( !$user )
                                        {
                                                print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
@@ -71,8 +97,8 @@ token_auth();
                case "/list":
                        // List all (distinct) phone MAC-adresses registered...
                        $search = null;
-                       if ( array_key_exists('search', $_GET ) )
-                               $search = $_GET['search'];
+                       if ( array_key_exists('search', $_POST ) )
+                               $search = $_POST['search'];
 
                        $phones = list_phones( $search );
                        print json_encode( array( 'response' => 'ok', 'list' => $phones ));
@@ -89,20 +115,20 @@ token_auth();
                                domain    A valid domain .. to form a registered user@domain combo :)
 
                        */
-                       if ( array_key_exists('mac', $_GET ) &&
-                               ( array_key_exists('user', $_GET) ||
-                                       ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET ))))
+                       if ( array_key_exists('mac', $_POST ) &&
+                               ( array_key_exists('user', $_POST) ||
+                                       ( array_key_exists('username', $_POST) && array_key_exists('domain', $_POST ))))
                        {
                                $username = "";
                                $domain = "";
-                               if ( array_key_exists('username', $_GET) )
+                               if ( array_key_exists('username', $_POST) )
                                {
-                                       $username = $_GET['username'];
-                                       $domain = $_GET['domain'];
+                                       $username = $_POST['username'];
+                                       $domain = $_POST['domain'];
                                }
                                else
                                {
-                                       $user = split_sipaddress($_GET['user']);
+                                       $user = split_sipaddress($_POST['user']);
                                        if ( !$user )
                                        {
                                                print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
@@ -110,7 +136,7 @@ token_auth();
                                        }
                                        list ( $username, $domain ) = $user;
                                }
-                               $mac = clean_mac($_GET['mac']);
+                               $mac = clean_mac($_POST['mac']);
                                if ( !$mac )
                                {
                                        print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'No valid MAC address given.') );
@@ -136,8 +162,7 @@ token_auth();
                                }
                                else
                                {
-                                       print json_encode( array ( 'response' => 'ok', 'data' => array (
-                                               'mac' => $mac, 'username' => $username, 'domain' => $domain) ));
+                                       print json_encode( array ( 'response' => 'ok', 'mac' => $mac, 'username' => $username, 'domain' => $domain) );
                                        break;
                                }
                                break;
@@ -159,20 +184,20 @@ token_auth();
                                domain    A valid domain .. to form a registered user@domain combo :)
 
                        */
-                       if ( array_key_exists('mac', $_GET ) &&
-                               ( array_key_exists('user', $_GET) ||
-                                       ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET ))))
+                       if ( array_key_exists('mac', $_POST ) &&
+                               ( array_key_exists('user', $_POST) ||
+                                       ( array_key_exists('username', $_POST) && array_key_exists('domain', $_POST ))))
                        {
                                $username = "";
                                $domain = "";
-                               if ( array_key_exists('username', $_GET) )
+                               if ( array_key_exists('username', $_POST) )
                                {
-                                       $username = $_GET['username'];
-                                       $domain = $_GET['domain'];
+                                       $username = $_POST['username'];
+                                       $domain = $_POST['domain'];
                                }
                                else
                                {
-                                       $user = split_sipaddress($_GET['user']);
+                                       $user = split_sipaddress($_POST['user']);
                                        if ( !$user )
                                        {
                                                print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
@@ -180,7 +205,7 @@ token_auth();
                                        }
                                        list ( $username, $domain ) = $user;
                                }
-                               $mac = clean_mac($_GET['mac']);
+                               $mac = clean_mac($_POST['mac']);
                                if ( !$mac )
                                {
                                        print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'No valid MAC address given.') );
@@ -201,7 +226,7 @@ token_auth();
                                }
                                else
                                {
-                                       print json_encode( array ( 'response' => 'ok' ));
+                                       print json_encode( array ( 'response' => 'ok', 'mac' => $mac, 'username' => $username, 'domain' => $domain ));
                                        break;
                                }
                                break;