user/update?username=foo&domain=bar
user/update?user=foo@bar.bz
- optionals: &displayname=baz&dialplan=(.*)&linetext=lalala
+ optionals: &displayname=baz&dialplan=(.*)&linetext=lalala&email=foo@bar.baz
Not implemented! Will only be implemented for Local users.
Remote users will have to be removed, and re-added.
+user/change_email?username=foo&domain=bar&email=user@example.com
+user/change_email?user=foo@bar.bz&email=user@example.com
+ Changes the email address for the given user, returns 'ok' with
+ 'user' set to the requested username and 'email' set to the
+ email address. This only applies to kamailio local users.
+
+ Returns 'failed' with 'cause' = 'nonexistant' if user does not exist.
+
+ Returns 'failed' with 'cause' = 'dbfail' if the database request
+ failed. Note that this may be because the given password was identical
+ to the old.
+
user/remove?username=foo&domain=bar
user/remove?user=foo@bar.bz
return true;
}
+function update_kamailio_email ( $username, $domain, $email )
+{
+ global $config;
+
+ if ( ! ($username && $domain && $email))
+ return false;
+
+ $query = sprintf("UPDATE %s SET email_address = '%s' WHERE username = '%s' AND domain = '%s'",
+ $config['kamailio_subscriber_table'],
+ sql_clean($email),
+ sql_clean($username),
+ sql_clean($domain)
+
+ );
+ if ( sql_dbexec_rows( $config['kamailio_db'], $query) != 1 ) return false;
+ return true;
+}
+
+
function add_provision_user( $username, $password, $domain, $authid, $registrar, $r_port, $proxy, $p_port, $displayname, $dialplan, $linetext )
{ global $config;
return true;
}
+function update_provision_data ( $param, $username, $domain, $data )
+{
+ global $config;
+
+ if (! (
+ $param == "displayname" ||
+ $param == "dialplan" ||
+ $param == "linetext" ||
+ $param == "registrar" ||
+ $param == "r_port" ||
+ $param == "proxy" ||
+ $param == "p_port"
+ ) ) return -1;
+
+
+ if ( ! ($username && $domain))
+ return -1;
+
+ if ( ! is_provision_user( $username, $domain ) )
+ return -2;
+
+ $query = sprintf("UPDATE %s SET %s = '%s' WHERE username = '%s' AND domain = '%s'",
+ $config['provision_users_table'],
+ sql_clean($param),
+ sql_clean($data),
+ sql_clean($username),
+ sql_clean($domain)
+
+ );
+ $res = sql_dbexec_rows( $config['provision_db'], $query);
+
+ if ( $res < 0 ) return -2;
+ if ( $res > 1 ) return -2;
+ return $res;
+}
+
function update_provision_pw ( $username, $domain, $password )
{
global $config;
$user['linetext'] = $provision_data['linetext'];
if ( $type == 'local' )
{
- $user['email'] = $kamailio_data['email'];
+ $user['email'] = $kamailio_data['email_address'];
$user['ha1'] = $kamailio_data['ha1'];
$user['ha1b'] = $kamailio_data['ha1b'];
$user['rpid'] = $kamailio_data['rpid'];
if ( is_provision_user( $username, $domain ) )
{
// Update provisioning password
- if (! update_provision_pw( $username, $domain, $password ) )
+ if ( update_provision_pw( $username, $domain, $password ) < 0 )
{
print json_encode( array( 'response' => 'failed', 'cause' => 'dbfail', 'detail' => 'Failed to update provisioning password' ) );
break;
if ( is_kamailio_subscriber( $username, $domain ) )
{
// Update kamailio password
- if (! update_kamailio_pw( $username, $domain, $password ) )
+ if ( update_kamailio_pw( $username, $domain, $password ) < 0 )
{
print json_encode( array( 'response' => 'failed', 'cause' => 'dbfail', 'detail' => 'Failed to update kamailio password' ) );
break;
print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
break;
+
+ case "/change_email":
+ /*
+ Required parameters should be...
+ ( 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) ))
+
+ {
+ $username = "";
+ $domain = "";
+ if ( array_key_exists('username', $_GET) )
+ {
+ $username = $_GET['username'];
+ $domain = $_GET['domain'];
+ }
+ else
+ {
+ $user = split_sipaddress($_GET['user']);
+ if ( !$user )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
+ break;
+ }
+ list ( $username, $domain ) = $user;
+ }
+ $email = $_GET['email'];
+
+ // Check for user in kamailio
+ if ( is_kamailio_subscriber( $username, $domain ) )
+ {
+ // Update kamailio email
+ if ( update_kamailio_email( $username, $domain, $email ) < 0 )
+ {
+ print json_encode( array( 'response' => 'failed', 'cause' => 'dbfail', 'detail' => 'Failed to update kamailio email' ) );
+ break;
+ }
+ }
+ print json_encode( array ( 'response' => 'ok', 'user' => $username.'@'.$domain, 'email' => $email));
+ break;
+ }
+ else
+ print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
+ break;
+
+
+
+
+
+
+
case "/update":
/*
Required parameters should be...
}
list ( $username, $domain ) = $user;
}
- print json_encode ( array( 'response' => 'failed', 'cause' => 'notimplemented', 'detail' => 'Requested feature valid, but not implemented' ) );
+ if ( ! is_provision_user ( $username, $domain ) )
+ {
+ print json_encode( array ( 'response' => 'failed', 'cause' => 'nonexistant', 'detail' => '' . $username . '@' . $domain . ' does not exist.'));
+ break;
+ }
+ $updated = array();
+ $failed = array();
+ $error = 1;
+ $result_text = "";
+ $params = array('displayname', 'dialplan', 'linetext', 'registrar', 'r_port', 'proxy', 'p_port');
+ foreach ( $params as $p )
+ {
+ if ( array_key_exists($p, $_GET ) )
+ {
+ $data = $_GET[$p];
+ $t = update_provision_data($p, $username, $domain, $data);
+ if ( $t != true )
+ {
+ $error = $t;
+ array_push($failed, $p);
+ }
+ else
+ {
+ array_push( $updated, $p);
+ }
+ }
+ }
+ $res = array();
+ if ( ( $error == 1 ) || ( $error == 0 ) )
+ {
+ $res['response'] = 'ok';
+ $res['skipped'] = $failed;
+ }
+ else if ( $error == -1 )
+ {
+ $res['response'] = 'failed';
+ $res['cause'] = 'param';
+ $res['detail'] = 'Invalid parameters';
+ $res['failed'] = $failed;
+ }
+ else if ( $error == -2 )
+ {
+ $res['response'] = 'failed';
+ $res['cause'] = 'dbfail';
+ $res['detail'] = 'Database failure';
+ $res['failed'] = $failed;
+ }
+ else
+ $res['response'] = 'error'; // Wait, what?
+
+ $res['updated'] = $updated;
+
+ print json_encode ( $res );
}
else
print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );