$dest_username = "";
$dest_domain = "";
$e164_only = false;
- if ( array_key_exists( 'destination', $_GET) )
+ if ( array_key_exists( 'destination', $_POST) )
{
- $tmp = split_sipaddress($_GET['destination']);
+ $tmp = split_sipaddress($_POST['destination']);
if ( !$tmp )
{
print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
}
list ( $dest_username, $dest_domain ) = $tmp;
- if ( array_key_exists( 'e164', $_GET ) )
+ if ( array_key_exists( 'e164', $_POST ) )
{
- if ( strtolower($_GET['e164']) == "true" ) $e164_only = true;
+ if ( strtolower($_POST['e164']) == "true" ) $e164_only = true;
$list = get_e164_alias( $dest_username, $dest_domain );
}
else if ( $dest_username && $dest_domain )
$list = get_aliases( $dest_username, $dest_domain );
}
}
- else if ( array_key_exists( 'alias', $_GET) )
+ else if ( array_key_exists( 'alias', $_POST) )
{
- $tmp = split_sipaddress($_GET['alias']);
+ $tmp = split_sipaddress($_POST['alias']);
if ( !$tmp )
{
print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
print json_encode ( array( 'response' => 'ok', 'aliases' => $list ) );
break;
case "/add":
- if ( array_key_exists( 'destination', $_GET)
- && ( ( array_key_exists( 'alias_username', $_GET) && array_key_exists( 'alias_domain', $_GET ) ) || array_key_exists('alias', $_GET) ) )
+ if ( array_key_exists( 'destination', $_POST)
+ && ( ( array_key_exists( 'alias_username', $_POST) && array_key_exists( 'alias_domain', $_POST ) ) || array_key_exists('alias', $_POST) ) )
{
$alias_username = "";
$alias_domain = "";
- if ( array_key_exists('alias_username', $_GET) )
+ if ( array_key_exists('alias_username', $_POST) )
{
- $alias_username = $_GET['alias_username'];
- $alias_domain = $_GET['alias_domain'];
+ $alias_username = $_POST['alias_username'];
+ $alias_domain = $_POST['alias_domain'];
}
else
{
- $alias = split_sipaddress($_GET['alias']);
+ $alias = split_sipaddress($_POST['alias']);
if ( !$alias )
{
print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
list ( $alias_username, $alias_domain ) = $alias;
}
- if ( !verify_sipadress($_GET['destination']) )
+ if ( !verify_sipadress($_POST['destination']) )
{
// TODO: Provide a better response..
print json_encode ( array( 'response' => 'invalid', 'cause' => 'destination' ) );
break;
}
- list ( $dest_username, $dest_domain ) = split_sipaddress( $_GET['destination']);
+ list ( $dest_username, $dest_domain ) = split_sipaddress( $_POST['destination']);
if ( (!$dest_username)||(!$dest_domain))
{
}
break;
case "/remove":
- if ( ( array_key_exists( 'alias_username', $_GET) && array_key_exists( 'alias_domain', $_GET ) ) || array_key_exists('alias', $_GET) )
+ if ( ( array_key_exists( 'alias_username', $_POST) && array_key_exists( 'alias_domain', $_POST ) ) || array_key_exists('alias', $_POST) )
{
$alias_username = "";
$alias_domain = "";
- if ( array_key_exists('alias_username', $_GET) )
+ if ( array_key_exists('alias_username', $_POST) )
{
- $alias_username = $_GET['alias_username'];
- $alias_domain = $_GET['alias_domain'];
+ $alias_username = $_POST['alias_username'];
+ $alias_domain = $_POST['alias_domain'];
}
else
{
- $alias = split_sipaddress($_GET['alias']);
+ $alias = split_sipaddress($_POST['alias']);
if ( !$alias )
{
print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
$type = false;
$authid = false;
- if ( array_key_exists('username', $_GET)
- && array_key_exists('password', $_GET) )
+ if ( array_key_exists('username', $_POST)
+ && array_key_exists('password', $_POST) )
{
- if ( 1 == authuser_verify( sql_clean($_GET['username']), sql_clean($_GET['password'])))
+ if ( 1 == authuser_verify( sql_clean($_POST['username']), sql_clean($_POST['password'])))
{
$type = "user";
- $authid = $_GET['username'];
+ $authid = $_POST['username'];
}
else
{
exit;
}
}
- else if ( array_key_exists('api_key', $_GET) )
+ else if ( array_key_exists('api_key', $_POST) )
{
- if ( verify_apikey( sql_clean( $_GET['api_key'] ) ) == 1 )
+ if ( verify_apikey( sql_clean( $_POST['api_key'] ) ) == 1 )
{
$type = "key";
- $authid = $_GET['api_key'];
+ $authid = $_POST['api_key'];
}
else
{
// De-authenticate/deauthorize the ongoing session.
// I.e. destroy session data, remove session cookies.
$session_name = "";
- if ( array_key_exists('session', $_GET ) )
- $session_name = $_GET['session'];
+ if ( array_key_exists('session', $_POST ) )
+ $session_name = $_POST['session'];
session_name($session_name);
session_start();
clear_credentials($session_name);
// The ping required a valid session...
// A successful ping returns a 'response' => 'pong'
// along with the new auth_key.
- $session_name = $_GET['session'];
+ $session_name = $_POST['session'];
$authid = $_SESSION['authid'];
$auth_key = update_authkey( $session_name, $authid );
print json_encode( array( 'response' => 'pong', 'auth_key' => $auth_key ));
if ( ! can_write() )
simple_authfail();
- if ( array_key_exists('host_ip', $_GET )
- && array_key_exists('access', $_GET ))
+ if ( array_key_exists('host_ip', $_POST )
+ && array_key_exists('access', $_POST ))
{
- $host = $_GET['host_ip'];
- $access = $_GET['access'];
+ $host = $_POST['host_ip'];
+ $access = $_POST['access'];
if (! preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $host) || ! authlevel_value( $access ) )
{
if ( ! can_write() )
simple_authfail();
- if ( array_key_exists('api_key', $_GET ) )
+ if ( array_key_exists('api_key', $_POST ) )
{
- $key = sql_clean( $_GET['api_key'] );
+ $key = sql_clean( $_POST['api_key'] );
// Perform a key-verification, skipping host/remote-address check.
if ( ! verify_apikey( $key, true ) )
{
if ( ! can_write() )
simple_authfail();
- if ( array_key_exists('username', $_GET )
- && array_key_exists('access', $_GET ))
+ if ( array_key_exists('username', $_POST )
+ && array_key_exists('access', $_POST ))
{
- $user = $_GET['username'];
- $access = $_GET['access'];
+ $user = $_POST['username'];
+ $access = $_POST['access'];
$level = authlevel_value( $access );
if ( ! $level )
if ( ! can_write() )
simple_authfail();
- if ( array_key_exists('username', $_GET ))
+ if ( array_key_exists('username', $_POST ))
{
- $user = $_GET['username'];
+ $user = $_POST['username'];
$t_level = get_authorization( "user", $user );
print json_encode ( array( 'response' => 'ok', 'list' => $domains ) );
break;
case "/get_servers":
- if ( array_key_exists('domain', $_GET))
+ if ( array_key_exists('domain', $_POST))
{
- $domain = $_GET['domain'];
+ $domain = $_POST['domain'];
if ( !$domain || $domain == "" )
print json_encode ( array( 'response' => 'invalid', 'cause' => 'parameters') );
break;
case "/set_servers":
- if ( array_key_exists('domain', $_GET)
- && array_key_exists('registrar', $_GET)
- && array_key_exists('r_port', $_GET)
- && array_key_exists('proxy', $_GET)
- && array_key_exists('p_port', $_GET)
- && array_key_exists('prov_url', $_GET))
+ if ( array_key_exists('domain', $_POST)
+ && array_key_exists('registrar', $_POST)
+ && array_key_exists('r_port', $_POST)
+ && array_key_exists('proxy', $_POST)
+ && array_key_exists('p_port', $_POST)
+ && array_key_exists('prov_url', $_POST))
{
- $domain = $_GET['domain'];
- $registrar = $_GET['registrar'];
- $r_port = $_GET['r_port'];
- $proxy = $_GET['proxy'];
- $p_port = $_GET['p_port'];
- $prov_url = $_GET['prov_url'];
+ $domain = $_POST['domain'];
+ $registrar = $_POST['registrar'];
+ $r_port = $_POST['r_port'];
+ $proxy = $_POST['proxy'];
+ $p_port = $_POST['p_port'];
+ $prov_url = $_POST['prov_url'];
if (!($domain && $registrar && $r_port && $proxy && $p_port && $prov_url ))
{
function token_auth( )
{
- global $_GET;
+ global $_POST;
// TODO: Part of ping/pong requirement.
// Run a function to clear all authkeys older than 5 minutes.
expire_authkeys();
- if ( array_key_exists('session', $_GET )
- && array_key_exists('auth_key', $_GET ) )
+ if ( array_key_exists('session', $_POST )
+ && array_key_exists('auth_key', $_POST ) )
{
- if ( ! check_session($_GET['session'] ) ) simple_authfail();
- if ( ! check_authkey($_GET['auth_key'] ) ) simple_authfail();
+ if ( ! check_session($_POST['session'] ) ) simple_authfail();
+ if ( ! check_authkey($_POST['auth_key'] ) ) simple_authfail();
}
else simple_authfail();
}
while ( strlen( $string ) < $length )
{
$string .= crypt(substr(md5(rand().rand()), 0, $length+1));
- $string = preg_replace( '/\W/', '', $string+1);
+ $string = preg_replace( '/\W/', '', $string);
}
return substr( $string, 1, $length );
global $config;
$query = sprintf("SELECT CONCAT(username, '@', domain), displayname FROM %s ORDER BY username,domain", $config['provision_users_table'] );
- if ( array_key_exists ( 'search', $_GET ) )
+ if ( array_key_exists ( 'search', $_POST ) )
{
- $search = $_GET['search']; // TODO: Add some sanitation and input validation!
+ $search = $_POST['search']; // TODO: Add some sanitation and input validation!
$query = sprintf("SELECT CONCAT(username, '@', domain) FROM %s WHERE CONCAT(username, '@', domain) LIKE '%%%s%%' ORDER BY username,domain", $config['provision_users_table'], sql_clean( $search ) );
}
$limit = 0;
$random = false;
$search = null;
- if ( array_key_exists('limit', $_GET ) && is_numeric( $_GET['limit']))
- $limit = $_GET['limit'];
+ if ( array_key_exists('limit', $_POST ) && is_numeric( $_POST['limit']))
+ $limit = $_POST['limit'];
- if ( array_key_exists('search', $_GET ) )
- $search = $_GET['search'];
- else if ( array_key_exists('random', $_GET ) && (strtolower( $_GET['random'] ) === 'true'))
+ if ( array_key_exists('search', $_POST ) )
+ $search = $_POST['search'];
+ else if ( array_key_exists('random', $_POST ) && (strtolower( $_POST['random'] ) === 'true'))
$random = true;
$numbers = null;
print json_encode( array( 'response' => 'failed', 'cause' => 'empty', 'detail' => 'Empty result.' ));
break;
case "/add_range":
- if ( array_key_exists('start', $_GET) && array_key_exists('end', $_GET) )
+ if ( array_key_exists('start', $_POST) && array_key_exists('end', $_POST) )
{
- $start = $_GET['start'];
- $end = sql_clean( $_GET['end'] );
+ $start = $_POST['start'];
+ $end = sql_clean( $_POST['end'] );
$result = add_range( $start, $end );
if ( $result === 'ok' )
{
case "/add":
// TODO: This should return better responses!
// Currently, it will fail with "invalid"
- if ( array_key_exists('number', $_GET))
+ if ( array_key_exists('number', $_POST))
{
- $number = $_GET['number'];
+ $number = $_POST['number'];
if (! verify_e164( $number ) )
{
print json_encode ( array( 'response' => 'invalid') );
break;
case "/remove":
- if ( array_key_exists('number', $_GET))
+ if ( array_key_exists('number', $_POST))
{
- $number = $_GET['number'];
+ $number = $_POST['number'];
if (! verify_e164( $number ) )
{
print json_encode ( array( 'response' => 'invalid') );
break;
case "/inpool":
- if ( array_key_exists('number', $_GET))
+ if ( array_key_exists('number', $_POST))
{
- $number = $_GET['number'];
+ $number = $_POST['number'];
if ( number_inpool( $number ) )
print json_encode ( array( 'response' => 'ok', 'number' => $number ) );
else
// 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 )
{
}
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') );
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 ));
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') );
}
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.') );
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') );
}
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.') );
ok( !$session, 'logged out, session cleared');
login_apikey();
-$data = exec_apinode("auth/remove_user", { "&username" => $test_username });
+$data = exec_apinode("auth/remove_user", { "username" => $test_username });
is( $data->{'response'}, 'ok', 'auth/remove_user as user ok');
is( $data->{'user'}, $test_username, 'auth/remove_user removed ' . $test_username);
undef $data;
--- /dev/null
+#!/bin/bash -xe
+
+perl auth.t
+perl user.t
+perl domain.t
+perl alias.t
+perl numbers.t
$session = "" if not defined $session;
$auth_key = "" if not defined $auth_key;
- my $url = $api_base . $node .
- "?session=" . $session .
- "&auth_key=" . $auth_key;
+ my $url = $api_base . $node;
- foreach my $key ( keys %$param )
- {
- $url .= "&" . $key . "=" . $param->{$key};
- }
- $response = $g_ua->get( $url );
+ $param->{'session'} = $session;
+ $param->{'auth_key'} = $auth_key;
+
+ $response = $g_ua->post( $url, $param );
if ( $response->is_success )
{
if ( $response->content =~ m/\s*{/ )
sub login_apikey
{
- my $response = $g_ua->get( $api_base . "auth/login" .
- "?api_key=" . $api_key );
+ my $response = $g_ua->post( $api_base . "auth/login",
+ [ "api_key" => $api_key ] );
+
ok ($response->is_success, 'login_apikey request is_success');
my $data = decode_json( $response->content) if $response->is_success;
die("HTTP error") unless $response->is_success;
sub login_user
{
- my $response = $g_ua->get( $api_base . "auth/login" .
- "?username=" . $test_username .
- "&password=" . $test_password );
+ my $response = $g_ua->post( $api_base . "auth/login",
+ [ "username" => $test_username,
+ "password" => $test_password ] );
+
ok ($response->is_success, 'login_user request is_success');
my $data = decode_json( $response->content) if $response->is_success;
sub logout
{
- my $response = $g_ua->get( $api_base . "auth/logout" .
- "?session=" . $session );
+ my $response = $g_ua->post( $api_base . "auth/logout",
+ [ "session" => $session ] );
ok ($response->is_success, 'logout request is_success');
die("HTTP error") unless $response->is_success;
// user: authentication username, SIP-username without domain component
// domain: Domain/realm of the user. username + '@' + domain == SIP address.
- if ( array_key_exists('user', $_GET) ||
- ( array_key_exists('username', $_GET) && array_key_exists('domain', $_GET )))
+ if ( 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') );
* SQL SELECT CONCAT() WHERE CONCAT() must be used *shrug*
*/
$search = null;
- if ( array_key_exists ( 'search', $_GET ) )
- $search = $_GET['search']; // TODO: Add some sanitation and input validation!
+ if ( array_key_exists ( 'search', $_POST ) )
+ $search = $_POST['search']; // TODO: Add some sanitation and input validation!
$list = list_users( $search );
print json_encode( array( 'response' => 'ok', 'list' => $list ));
break;
*/
// Test required parameters:
if (
- ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) || array_key_exists('user', $_GET) )
- && array_key_exists( 'displayname', $_GET )
- && array_key_exists( 'email', $_GET ) )
+ ( ( array_key_exists( 'username', $_POST) && array_key_exists( 'domain', $_POST ) ) || array_key_exists('user', $_POST) )
+ && array_key_exists( 'displayname', $_POST )
+ && array_key_exists( 'email', $_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') );
}
$password = generate_password();
- $displayname = $_GET['displayname'];
- $email = $_GET['email'];
+ $displayname = $_POST['displayname'];
+ $email = $_POST['email'];
if ( !is_kamailio_domain( $domain ) )
{
// Test required parameters:
if (
- ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) ) || array_key_exists('user', $_GET) )
- && array_key_exists( 'displayname', $_GET )
- && array_key_exists( 'password', $_GET )
- && array_key_exists( 'registrar', $_GET ) )
+ ( ( array_key_exists( 'username', $_POST) && array_key_exists( 'domain', $_POST ) ) || array_key_exists('user', $_POST) )
+ && array_key_exists( 'displayname', $_POST )
+ && array_key_exists( 'password', $_POST )
+ && array_key_exists( 'registrar', $_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') );
list ( $username, $domain ) = $user;
}
- $password = $_GET['password'];
- $displayname = $_GET['displayname'];
- $registrar = $_GET['registrar'];
- $r_port = ( array_key_exists('r_port', $_GET) ) ? $_GET['r_port'] : 5060;
+ $password = $_POST['password'];
+ $displayname = $_POST['displayname'];
+ $registrar = $_POST['registrar'];
+ $r_port = ( array_key_exists('r_port', $_POST) ) ? $_POST['r_port'] : 5060;
- $proxy = ( array_key_exists('proxy', $_GET) ) ? $_GET['proxy'] : $registrar;
- $p_port = ( array_key_exists('p_port', $_GET) ) ? $_GET['p_port'] : $r_port;
- $authid = ( array_key_exists('authid', $_GET) ) ? $_GET['authid'] : $username;
- $dialplan = ( array_key_exists('dialplan', $_GET) ) ? $_GET['dialplan'] : $config['standard_dialplan'];
- $linetext = ( array_key_exists('linetext', $_GET) ) ? $_GET['linetext'] : $username . '@' . $domain;
+ $proxy = ( array_key_exists('proxy', $_POST) ) ? $_POST['proxy'] : $registrar;
+ $p_port = ( array_key_exists('p_port', $_POST) ) ? $_POST['p_port'] : $r_port;
+ $authid = ( array_key_exists('authid', $_POST) ) ? $_POST['authid'] : $username;
+ $dialplan = ( array_key_exists('dialplan', $_POST) ) ? $_POST['dialplan'] : $config['standard_dialplan'];
+ $linetext = ( array_key_exists('linetext', $_POST) ) ? $_POST['linetext'] : $username . '@' . $domain;
if ( is_kamailio_domain( $domain ) )
{
* If no such user exists, return 'response' => 'failed' with 'cause' => 'nonexistant'
* On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
*/
- if ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
- || array_key_exists('user', $_GET) )
+ 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') );
* Update user passwords in 'provision' and 'kamailio' as appropriate
* On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
*/
- if ( array_key_exists('password', $_GET) &&
- ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
- || array_key_exists('user', $_GET) ))
+ if ( array_key_exists('password', $_POST) &&
+ ( ( 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') );
}
list ( $username, $domain ) = $user;
}
- $password = $_GET['password'];
+ $password = $_POST['password'];
// Check compatibility of password? TODO...
// Fetch old password for rollback? TODO...
( username & domain ) | user
email
*/
- if ( array_key_exists('email', $_GET) &&
- ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
- || array_key_exists('user', $_GET) ))
+ if ( array_key_exists('email', $_POST) &&
+ ( ( 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') );
}
list ( $username, $domain ) = $user;
}
- $email = $_GET['email'];
+ $email = $_POST['email'];
// Check for user in kamailio
if ( is_kamailio_subscriber( $username, $domain ) )
* Get update parameters, and change as appropriate ;)
* On other failures, return 'response' => 'failed' with 'cause' => 'error' (may set 'detail' => 'message')
*/
- if ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
- || array_key_exists('user', $_GET) )
+ 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') );
$params = array('displayname', 'dialplan', 'linetext', 'registrar', 'r_port', 'proxy', 'p_port');
foreach ( $params as $p )
{
- if ( array_key_exists($p, $_GET ) )
+ if ( array_key_exists($p, $_POST ) )
{
- $data = $_GET[$p];
+ $data = $_POST[$p];
$t = update_provision_data($p, $username, $domain, $data);
if ( $t != true )
{
print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
break;
case "/available":
- if ( ( array_key_exists( 'username', $_GET) && array_key_exists( 'domain', $_GET ) )
- || array_key_exists('user', $_GET) )
+ 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') );
General description on API protocol:
=========================================================================
-All API nodes currently use GET requests for all parameters.
+All API nodes currently use POST requests for all parameters.
All API nodes return JSON data unless explicitly noted ,
and all JSON results will contain a 'response' element.
The 'response' may be set to:
Permissions! (user/permissions?user=...)
-Change all GET to POST
-
-Implement test-tool for POST-based communication ;)
-
Improve robustness of change_pw: fetch old password for rollback/testing.
Check for locations where sql_dbexec_rows is more appropriate/correct than sql_dbexec