Commit a3752621 authored by johan's avatar johan

Initial commit

parents
$(eval GIT_DESCRIBE = $(shell sh -c "git describe"))
OUTPUT_DIR = ${CURDIR}
rpm:
rm -rf $(OUTPUT_DIR)/flexisip-account-manager
mkdir $(OUTPUT_DIR)/flexisip-account-manager
mkdir -p $(OUTPUT_DIR)/rpmbuild/SPECS
mkdir -p $(OUTPUT_DIR)/rpmbuild/SOURCES
cp src/*.php $(OUTPUT_DIR)/flexisip-account-manager/
cp README.md $(OUTPUT_DIR)/flexisip-account-manager/
cp src/*.conf $(OUTPUT_DIR)/flexisip-account-manager/
mkdir -p $(OUTPUT_DIR)/flexisip-account-manager/httpd
cp httpd/flexisip-account-manager.conf $(OUTPUT_DIR)/flexisip-account-manager/httpd
cp flexisip-account-manager.spec $(OUTPUT_DIR)/rpmbuild/SPECS/
tar cvf flexisip-account-manager.tar.gz -C $(OUTPUT_DIR) flexisip-account-manager
mv flexisip-account-manager.tar.gz $(OUTPUT_DIR)/rpmbuild/SOURCES/flexisip-account-manager.tar.gz
rpmbuild -v -bb --define '_topdir $(OUTPUT_DIR)/rpmbuild' --define "_rpmdir $(OUTPUT_DIR)/rpmbuild" $(OUTPUT_DIR)/rpmbuild/SPECS/flexisip-account-manager.spec
rm -rf $(OUTPUT_DIR)/flexisip-account-manager
.PHONY: rpm
PHP Authenticated Lime server
==============================
Packaging
---------
To build a rpm package on centos7:
`make rpm`
To build a rpm package with docker:
`docker run -v $PWD:/home/bc -it gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-centos:7 make`
The lime-server rpm package can be found in rpmbuild/RPMS/x86_64/bc-lime-server*.rpm
Installation requires package centos-release-scl-rh to be installed for php7.1
# -*- rpm-spec -*-
#%define _prefix @CMAKE_INSTALL_PREFIX@
#%define pkg_prefix @BC_PACKAGE_NAME_PREFIX@
# re-define some directories for older RPMBuild versions which don't. This messes up the doc/ dir
# taken from https://fedoraproject.org/wiki/Packaging:RPMMacros?rd=Packaging/RPMMacros
#%define _datarootdir %{_prefix}/share
#%define _datadir %{_datarootdir}
#%define _docdir %{_datadir}/doc
%define build_number 1
#%if %{build_number}
#%define build_number_ext -%{build_number}
#%endif
Name: bc-flexisip-account-manager
Version: 1.0.2
Release: %{build_number}%{?dist}
Summary: SIP account management xml-rpc server, for use with flexisip server suite.
Group: Applications/Communications
License: GPL
URL: http://www.linphone.org
#Source0: %{name}-%{version}%{?build_number_ext}.tar.gz
Source0: flexisip-account-manager.tar.gz
#BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
# dependencies
Requires: rh-php71-php rh-php71-php-xmlrpc rh-php71-php-mysqlnd rh-php71-php-mbstring
%description
PHP server for Linphone and Flexisip providing module for account creation.
%prep
%setup -n flexisip-account-manager
%install
rm -rf "$RPM_BUILD_ROOT"
mkdir -p "$RPM_BUILD_ROOT/opt/belledonne-communications/share/flexisip-account-manager"
cp -R *.php "$RPM_BUILD_ROOT/opt/belledonne-communications/share/flexisip-account-manager"
cp -R README* "$RPM_BUILD_ROOT/opt/belledonne-communications/share/flexisip-account-manager"
mkdir -p "$RPM_BUILD_ROOT/etc/flexisip-account-manager"
cp -R *.conf "$RPM_BUILD_ROOT/etc/flexisip-account-manager"
mkdir -p $RPM_BUILD_ROOT/opt/rh/httpd24/root/etc/httpd/conf.d
cp httpd/flexisip-account-manager.conf "$RPM_BUILD_ROOT/opt/rh/httpd24/root/etc/httpd/conf.d"
%post
if [ $1 -eq 1 ] ; then
mkdir -p /var/opt/belledonne-communications/log
touch /var/opt/belledonne-communications/log/account-manager.log
chown apache:apache /var/opt/belledonne-communications/log/account-manager.log
chcon -t httpd_sys_rw_content_t /var/opt/belledonne-communications/log/account-manager.log
setsebool httpd_can_network_connect_db on
fi
%files
/opt/belledonne-communications/share/flexisip-account-manager/*.php
/opt/belledonne-communications/share/flexisip-account-manager/README*
%config(noreplace) /etc/flexisip-account-manager/*.conf
%config(noreplace) /opt/rh/httpd24/root/etc/httpd/conf.d/flexisip-account-manager.conf
%clean
rm -rf $RPM_BUILD_ROOT
%changelog
* Fri Jun 28 2019 Johan Pascal <johan.pascal@belledonne-communications.com>
-
* Fri May 18 2018 Matthieu TANON <matthieu.tanon@belledonne-communications.com>
- Initial RPM release.
Alias /flexisip-account-manager /opt/belledonne-communications/share/flexisip-account-manager
<Directory /opt/belledonne-communications/share/flexisip-account-manager/>
Options FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
#! /bin/php
<?php
define("PATH_TO_CONFIG", "/etc/flexisip-account-manager/");
include PATH_TO_CONFIG . "xmlrpc.conf";
if (USE_MYSQLI) {
include "mysqli-db.php";
} else {
include "mysql-db.php";
}
include "logging.php";
include "utilities.php";
include "xmlrpc-accounts.php";
include "xmlrpc-aliases.php";
include "xmlrpc-sms.php";
date_default_timezone_set(DEFAULT_TIMEZONE);
mylog("[DEBUG] Timezone set to " . DEFAULT_TIMEZONE);
if ($argc >= 2) {
$action = $argv[1];
if ($action == "list_accounts") {
$accounts = db_get_accounts();
foreach ($accounts as $account) {
echo $account['username'] . '@' . $account['domain'] . ' activation status is ' . $account['activated'] . " (activation code is " . $account['activation_code'] . "): IP " . $account['ip_address'] . ", user-agent " . $account['user_agent'] . "\r\n";
}
} else if ($action == "delete_account") {
if ($argc >= 3) {
$login = $argv[2];
$domain = SIP_DOMAIN;
if ($argc >= 4) {
$domain = $argv[3];
}
if (!db_account_is_existing($login, $domain)) {
echo "Error: account " . $login . " on domain " . $domain . " doesn't exist." . "\r\n";
exit;
}
db_alias_delete($login, $domain);
db_account_delete($login, $domain);
if (startswith($login, "+")) {
db_delete_sms($login);
}
echo "Account " . $login . " successfuly deleted." . "\r\n";
} else {
echo "Proper way to use is php admin.php delete_account <login> [domain]" . "\r\n";
}
} else if ($action == "activate_account") {
if ($argc >= 3) {
$login = $argv[2];
$domain = SIP_DOMAIN;
if ($argc >= 4) {
$domain = $argv[3];
}
if (!db_account_is_existing($login, $domain)) {
echo "Error: account " . $login . " on domain " . $domain . " doesn't exist." . "\r\n";
exit;
}
db_account_super_activate($login, $domain);
echo "Account " . $login . " succesfuly super activated." . "\r\n";
} else {
echo "Proper way to use is php admin.php activate_account <login> [domain]" . "\r\n";
}
} else if ($action == "help") {
echo "Possible commands are:" . "\r\n";
echo "help" . "\r\n";
echo "list_accounts" . "\r\n";
echo "activate_account" . "\r\n";
echo "delete_account <login> [domain]" . "\r\n";
}
} else {
echo "Proper way to use is php admin.php action [params]" . "\r\n";
echo "Try php admin.php help to see all possible actions." . "\r\n";
exit;
}
?>
\ No newline at end of file
<?php
function request_authentication($realm = "sip.example.org") {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Digest realm="' . $realm.
'",qop="auth",nonce="' . uniqid() . '",opaque="' . md5($realm) . '"');
exit();
}
function authenticate($auth_digest, $realm = "sip.example.org") {
// Parse the client authentication data
$default = array('nounce', 'nc', 'cnounce', 'qop', 'username', 'uri', 'response');
preg_match_all('~(\w+)="?([^",]+)"?~', $auth_digest, $matches); # $_SERVER['PHP_AUTH_DIGEST']
$data = array_combine($matches[1] + $default, $matches[2]);
// Get the password/hash from database
$conn = linphonedb_connect();
$query = "SELECT password FROM " . ACCOUNTS_ALGO_DB_TABLE . " WHERE account_id=(SELECT id FROM " . ACCOUNTS_DB_TABLE . " WHERE login='" . linphonedb_escape($conn, $data['username']) . "');";
$result = linphonedb_query($query, $conn);
$row = linphonedb_fetch($result);
$password = $row[0];
// Get the corresponding algorithm if specified
$query = "SELECT algorithm FROM " . ACCOUNTS_ALGO_DB_TABLE . " WHERE account_id=(SELECT id FROM " . ACCOUNTS_DB_TABLE . " WHERE login='" . linphonedb_escape($conn, $data['username']) . "');";
$result = linphonedb_query($query, $conn);
$row = linphonedb_fetch($result);
$algorithm = $row[0];
if (is_null($algorithm)) {
$algorithm = 'MD5';
}
// Close db connection
linphonedb_clean($result);
linphonedb_close($conn);
// Generate the valid response
switch ($algorithm) {
case 'CLRTXT':
$A1 = md5($data['username'].':'.$data['realm'].':'.$password);
$A2 = md5(getenv('REQUEST_METHOD').':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
break;
case 'MD5':
$A1 = $password; // username:realm:password
$A2 = md5(getenv('REQUEST_METHOD').':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
break;
case 'SHA256':
$A1 = $password; // username:realm:password
$A2 = hash('sha256', getenv('REQUEST_METHOD').':'.$data['uri']);
$valid_response = hash('sha256', $A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
break;
}
// Compare with the client response
if($data['response'] === $valid_response) {
return TRUE;
} else {
return FALSE;
}
}
?>
<?php
define("CUSTOM_HOOKS", True);
function hook_on_account_created($user, $domain, $hashed_password, $email) {
mylog("[HOOK] Account created");
}
function hook_on_account_activated($user, $domain, $expiration_date) {
mylog("[HOOK] Account activated");
}
function hook_on_expiration_date_updated($user, $domain, $expiration_date, $payloadJson, $os) {
mylog("[HOOK] Expiration updated");
}
?>
\ No newline at end of file
<?php
// For SMS, remember to stay under 160 characters.
$SMS_OVH_TEMPLATE = array (
'US' => 'Your Linphone validation code is #CODE#', // This one isn't required but if present it MUST be equal to SMS_OVH_US_TEMPLATE
'FR' => 'Votre code de validation Linphone est #CODE#',
);
?>
\ No newline at end of file
<?php
function mylog($message) {
if (!LOGS_ENABLED) {
return;
}
$now = getdate();
$month = sprintf("%02d", $now["mon"]);
$day = sprintf("%02d", $now["mday"]);
$hours = sprintf("%02d", $now["hours"]);
$minutes = sprintf("%02d", $now["minutes"]);
$seconds = sprintf("%02d", $now["seconds"]);
error_log("[" . $day . "/" . $month . "/" . $now["year"] . " " . $hours . ":" . $minutes . ":" . $seconds . "] " . $message . "\r\n", 3, LOG_FILE);
}
?>
\ No newline at end of file
<?php
function linphonedb_connect() {
if (USE_PERSISTENT_CONNECTIONS) {
$conn = mysqli_connect('p:' . DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
} else {
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
}
if ($conn->connect_errno) {
mylog("[ERROR][DB] Connection failed: " . $conn->connect_errno . " - " . $conn->connect_error);
}
return $conn;
}
function linphonedb_escape($conn, $param) {
return mysqli_real_escape_string($conn, $param);
}
function linphonedb_query($queryStr, $conn) {
$result = mysqli_query($conn, $queryStr);
if (! $result) {
mylog("[ERROR][DB] Invalid query: " . $conn->connect_errno . " - " . $conn->connect_error);
return "";
}
// cannot log result because fetch needed
// mylog("[DB] Query: " . $queryStr);
return $result;
}
function linphonedb_fetch($result) {
if ($result->num_rows === 0) {
mylog("[ERROR][DB] Result is empty...");
}
$row = mysqli_fetch_array($result, MYSQLI_NUM);
return $row;
}
function linphonedb_clean($result) {
mysqli_free_result($result);
}
function linphonedb_close($conn) {
mysqli_close($conn);
}
?>
<?php
define("PATH_TO_CONFIG", "/etc/flexisip-account-manager/");
include PATH_TO_CONFIG . "xmlrpc.conf";
$rc_array = parse_ini_file("default.rc", true);
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml = $xml . '<config xmlns="http://www.linphone.org/xsds/lpconfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd">';
foreach ($rc_array as $section => $values) {
$xml = $xml . '<section name="' . $section . '">';
foreach ($values as $key => $value) {
if (REMOTE_PROVISIONING_OVERWRITE_ALL) {
$xml = $xml . '<entry name="' . $key . '" overwrite="true">' . $value . '</entry>';
} else {
$xml = $xml . '<entry name="' . $key . '">' . $value . '</entry>';
}
}
$xml = $xml . '</section>';
}
$xml = $xml . '</config>';
header('Content-type: text/xml');
echo $xml;
?>
<?php
define("PATH_TO_CONFIG", "/etc/flexisip-account-manager/");
include PATH_TO_CONFIG . "xmlrpc.conf";
if (USE_MYSQLI) {
include "mysqli-db.php";
} else {
include "mysql-db.php";
}
include "xmlrpc-sms.php";
include "xmlrpc-accounts.php";
include "xmlrpc-aliases.php";
include "xmlrpc-inapp.php";
include "xmlrpc-devices.php";
include "xmlrpc-compatibility.php";
include "utilities.php";
include "logging.php";
include "hooks.php";
if ($argc == 3) {
$phone = $argv[1];
$msg = $argv[2];
send_sms_ovh($phone, $msg, NULL);
} else {
echo "php ./sms_sender.php <phone number> <message>\r\n";
}
?>
<?php
function startswith($hay, $needle) {
return substr($hay, 0, strlen($needle)) === $needle;
}
function endswith($hay, $needle) {
return $needle === "" || (($temp = strlen($hay) - strlen($needle)) >= 0 and strpos($hay, $needle, $temp) !== FALSE);
}
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $ip;
}
// Internationalization
function get_lang($param) {
if ($param == NULL || $param == "") {
mylog("[WARN] lang parameter wasn't found, use US");
return 'US';
} else if (strlen($param) > 2) {
$param = substr($param, 0, 2);
}
return strtoupper($param);
}
function get_sms_string_for_lang($lang) {
global $SMS_OVH_TEMPLATE;
if (isset($SMS_OVH_TEMPLATE[$lang])) {
return $SMS_OVH_TEMPLATE[$lang];
}
mylog("[WARN] SMS template not found for lang " . $lang . ", using US template");
return SMS_OVH_US_TEMPLATE;
}
// Password
function hash_password($user, $password, $domain, $algo) {
if(strcmp($algo,"")==0 || strcmp($algo,"MD5")==0) $hashed_password = hash("md5", $user . ":" . $domain . ":" . $password);
if(strcmp($algo,"SHA-256")==0) $hashed_password = hash("sha256", $user . ":" . $domain . ":" . $password);
return $hashed_password;
}
function generate_password() {
$generated_password = substr(str_shuffle(GENERATED_PASSWORD_CHARACTERS), 0, GENERATED_PASSWORD_LENGTH);
return $generated_password;
}
function generate_4_digits_code() {
$generated_password = substr(str_shuffle("0123456789"), 0, 4);
return $generated_password;
}
function get_trial_expiration_date() {
$expiration_date = new DateTime('now +' . TRIAL_DURATION_DAYS . ' days');
$expiration = $expiration_date->getTimestamp() * 1000;
return $expiration;
}
function check_parameter($param, $param_name = "username") {
if ($param == NULL || $param == "") {
mylog("[WARN] " . $param_name . " is missing");
return false;
}
return true;
}
function check_algo($algo) {
if (strcmp($algo,"")==0 || strcmp($algo,"MD5")==0 || strcmp($algo,"SHA-256")==0 || strcmp($algo,"clrtxt")==0){
return true;
}
mylog("[ERROR] Algo " . $algo . " is not supported");
return false;
}
function get_domain($param) {
if ($param == NULL || $param == "") {
mylog("[WARN] domain parameter wasn't found, use " . SIP_DOMAIN);
$param = SIP_DOMAIN;
}
return $param;
}
// Email
function send_email($email, $subject, $text, $html) {
$site = EMAIL_SITE;
$from = EMAIL_FROM_ADDR;
$name = EMAIL_FROM_NAME;
$to = $email;
$from = $name." <".$from.">";
$limite = "_----------=_parties_".md5(uniqid (rand()));
$headers = "Reply-to: ".$from."\n";
$headers .= "From: ".$from."\n";
$headers .= "Return-Path: ".$from."\n";
$headers .= "X-Sender: <".$site.">\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "X-auth-smtp-user: ".$from." \n";
$headers .= "X-abuse-contact: ".$from." \n";
$headers .= "X-auth-smtp-user: ".$from." \n";
$headers .= "X-abuse-contact: ".$from." \n";
$headers .= "Date: ".date("D, j M Y G:i:s O")."\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";
$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain; charset=\"utf-8\"\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $text;
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; charset=\"utf-8\"\n";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $html;
$message .= "\n--".$limite."--";
$params = "-f" . EMAIL_FROM_ADDR . " -O DeliveryMode=b";
$result = mail($email, $subject, $message, $headers, $params);
if (!$result) {
mylog("[ERROR][EMAIL] Email delivery declined !");
}
}
function send_email_with_activation_link($email, $key) {
if( !EMAIL_ENABLED ){
mylog("[WARN] [EMAIL] Emails are disabled");
return "WARNING_EMAILS_DISABLED";
}
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
$link = $pageURL . EMAIL_ACTIVATION_LINK;
$link = str_replace("%key%", $key, $link);
mylog("[EMAIL] Activation link is " . $link);
$body = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY);
mylog("[EMAIL] Activation body is " . $body);
$body_html = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY_HTML);
mylog("[EMAIL] Activation html body is " . $body_html);
send_email($email, EMAIL_ACTIVATION_SUBJECT, $body, $body_html);
mylog("[EMAIL] Email sent to email " . $email . " to activate the account");
}
?>
This diff is collapsed.
<?php
function db_drop_alias_table() {
$conn = linphonedb_connect();
$create_req = "DROP TABLE IF EXISTS " . ALIAS_DB_TABLE;
$result = linphonedb_query($create_req, $conn);
linphonedb_clean($result);
linphonedb_close($conn);
}
function db_create_alias_table() {
$conn = linphonedb_connect();
$create_req = "CREATE TABLE IF NOT EXISTS " . ALIAS_DB_TABLE . " (
id INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT,
account_id INTEGER(11) UNSIGNED NOT NULL,
alias VARCHAR(64),
domain VARCHAR(64) NOT NULL,
PRIMARY KEY (id), UNIQUE KEY login (alias, domain))";
$result = linphonedb_query($create_req, $conn);
linphonedb_clean($result);
linphonedb_close($conn);
}
function db_alias_delete($user, $domain) {
$conn = linphonedb_connect();
$result = linphonedb_query("DELETE FROM " . ALIAS_DB_TABLE . " WHERE account_id=(SELECT id FROM " . ACCOUNTS_DB_TABLE . " WHERE login='" . linphonedb_escape($conn, $user) . "' AND domain='" . linphonedb_escape($conn, $domain) . "')", $conn);
linphonedb_clean($result);
linphonedb_close($conn);
}
function db_alias_add($alias, $user, $domain) {
$conn = linphonedb_connect();
$result = linphonedb_query("INSERT INTO " . ALIAS_DB_TABLE . "(account_id, alias, domain) VALUES((SELECT id FROM " . ACCOUNTS_DB_TABLE . " WHERE login='" . linphonedb_escape($conn, $user) . "' AND domain='" . linphonedb_escape($conn, $domain) . "'),'" . linphonedb_escape($conn, $alias) . "','" . linphonedb_escape($conn, $domain) . "')", $conn);
linphonedb_clean($result);
linphonedb_close($conn);
}
function db_alias_update($alias, $user, $domain) {
$conn = linphonedb_connect();
$result = linphonedb_query("UPDATE " . ALIAS_DB_TABLE . " SET account_id=(SELECT id FROM " . ACCOUNTS_DB_TABLE . " WHERE login='" . linphonedb_escape($conn, $user) . "' AND domain='" . linphonedb_escape($conn, $domain) . "') WHERE alias='" . linphonedb_escape($conn, $alias) . "' AND domain='" . linphonedb_escape($conn, $domain) . "'", $conn);
linphonedb_clean($result);
linphonedb_close($conn);
}
function db_alias_is_in_use($alias, $domain) {
$conn = linphonedb_connect();
$result = linphonedb_query("SELECT count(*) FROM " . ALIAS_DB_TABLE . " WHERE alias='" . linphonedb_escape($conn, $alias) . "' AND domain='" . linphonedb_escape($conn, $domain) . "'", $conn);
$row = linphonedb_fetch($result);
$is_in_use = $row[0] == 1;
linphonedb_clean($result);
linphonedb_close($conn);
return $is_in_use;
}
function db_alias_get($alias, $domain) {
$conn = linphonedb_connect();
$result = linphonedb_query("SELECT login FROM " . ACCOUNTS_DB_TABLE . " WHERE id=(SELECT account_id FROM " . ALIAS_DB_TABLE . " WHERE alias='" . linphonedb_escape($conn, $alias) . "' AND domain='" . linphonedb_escape($conn, $domain) . "')", $conn);
$row = linphonedb_fetch($result);
$login = $row[0];
linphonedb_clean($result);
linphonedb_close($conn);
return $login;
}
function db_alias_get_reverse($user, $domain) {
$conn = linphonedb_connect();
$result = linphonedb_query("SELECT alias FROM " . ALIAS_DB_TABLE . " WHERE account_id=(SELECT id FROM " . ACCOUNTS_DB_TABLE . " WHERE login='" . linphonedb_escape($conn, $user) . "' AND domain='" . linphonedb_escape($conn, $domain) . "')", $conn);
$row = linphonedb_fetch($result);
$reverse = $row[0];
linphonedb_clean($result);
linphonedb_close($conn);
return $reverse;
}
// XMLRPC methods
// args = [phone, [domain]]
function xmlrpc_is_alias_used($method, $args) {
$phone = $args[0];
$domain = get_domain($args[1]);
mylog("[XMLRPC] xmlrpc_is_alias_used(" . $user . ")");
if (!check_parameter($phone, "phone")) {
return "ERROR_PHONE_PARAMETER_NOT_FOUND";
} else if (!startswith($phone, "+")) {
mylog("[ERROR] Phone doesn't start by +");
return "ERROR_PHONE_ISNT_E164";
} else if (!db_alias_is_in_use($phone, $domain)) {
return "ERROR_ALIAS_DOESNT_EXIST";
}
return "OK";
}
// args = [phone, account, [domain], [lang]]
function xmlrpc_link_phone_number_with_account($method, $args) {
$phone = $args[0];
$user = $args[1];
$domain = get_domain($args[2]);
$lang = get_lang($args[3]);
mylog("[XMLRPC] xmlrpc_link_phone_number_with_account(" . $user . ", " . $domain . ", " . $phone . ")");
if (!check_parameter($phone)) {
return "ERROR_PHONE_PARAMETER_NOT_FOUND";
} else if (!check_parameter($user)) {
return "ERROR_USERNAME_PARAMETER_NOT_FOUND";
} else if (!startswith($phone, "+")) {
mylog("[ERROR] Phone doesn't start by +");
return "ERROR_PHONE_ISNT_E164";
/*} else if (db_alias_is_in_use($phone, $domain)) {
return "ERROR_ALIAS_ALREADY_IN_USE";*/
} else if (!db_account_is_existing($user, $domain)) {
return "ERROR_ACCOUNT_DOESNT_EXIST";
}
if (SEND_ACTIVATION_SMS) {
if (!SMS_API_ENABLED) {
// This is a hack to allow testing without sending SMS
return "OK";
}
$key = generate_4_digits_code();
db_account_update_confirmation_key($user, $domain, $key);
$ok = send_sms($phone, $key, $lang);
return $ok;
}
return "ERROR_SMS_API_DISABLED";
}
// args = [phone, user, key, ha1, [domain], [algo]]
function xmlrpc_activate_phone_number_link($method, $args) {
$phone = $args[0];
$user = $args[1];
$key = $args[2];
$ha1 = $args[3];
$domain = get_domain($args[4]);
mylog("[XMLRPC] xmlrpc_activate_phone_number_link(" . $user . ", " . $domain . ", " . $phone . ", " . $key . ")");
if (!check_parameter($phone, "phone")) {
return "ERROR_PHONE_PARAMETER_NOT_FOUND";
} else if (!check_parameter($user)) {
return "ERROR_USERNAME_PARAMETER_NOT_FOUND";
} else if (!startswith($phone, "+")) {
mylog("[ERROR] Phone doesn't start by +");
return "ERROR_PHONE_ISNT_E164";
}