mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
Added create_push_accounts
This commit is contained in:
parent
e0390ce1d2
commit
3dd5471ea9
4 changed files with 77 additions and 2 deletions
|
|
@ -36,6 +36,20 @@ define("GENERATED_PASSWORD_LENGTH", 8);
|
||||||
*/
|
*/
|
||||||
define("DEFAULT_ALGORITHM", "MD5");
|
define("DEFAULT_ALGORITHM", "MD5");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A string with each character allowed in the username generation.
|
||||||
|
*
|
||||||
|
* Default value: abcdefghijklmnopqrstuvwxyz0123456789.-_
|
||||||
|
*/
|
||||||
|
define("GENERATED_USERNAME_CHARACTERS", "abcdefghijklmnopqrstuvwxyz0123456789.-_");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The length of the username that will be generated.
|
||||||
|
*
|
||||||
|
* Default value: 12
|
||||||
|
*/
|
||||||
|
define("GENERATED_USERNAME_LENGTH", 12);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If set to True, a created account will automatically be activated and it's expiration date set to now + TRIAL_DURATION_DAYS,
|
* If set to True, a created account will automatically be activated and it's expiration date set to now + TRIAL_DURATION_DAYS,
|
||||||
* otherwise expiration date for trial will be set when account is activated via a different xml rpc call.
|
* otherwise expiration date for trial will be set when account is activated via a different xml rpc call.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#%define _datadir %{_datarootdir}
|
#%define _datadir %{_datarootdir}
|
||||||
#%define _docdir %{_datadir}/doc
|
#%define _docdir %{_datadir}/doc
|
||||||
|
|
||||||
%define build_number 19
|
%define build_number 20
|
||||||
%define var_dir /var/opt/belledonne-communications
|
%define var_dir /var/opt/belledonne-communications
|
||||||
%define opt_dir /opt/belledonne-communications/share/flexisip-account-manager
|
%define opt_dir /opt/belledonne-communications/share/flexisip-account-manager
|
||||||
%define env_file "$RPM_BUILD_ROOT/etc/flexisip-account-manager/flexiapi.env"
|
%define env_file "$RPM_BUILD_ROOT/etc/flexisip-account-manager/flexiapi.env"
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,12 @@ function hash_password($user, $password, $domain, $algo)
|
||||||
return $hashed_password;
|
return $hashed_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generate_username()
|
||||||
|
{
|
||||||
|
$generated_username = substr(str_shuffle(GENERATED_USERNAME_CHARACTERS), 0, GENERATED_USERNAME_LENGTH);
|
||||||
|
return $generated_username;
|
||||||
|
}
|
||||||
|
|
||||||
function generate_password()
|
function generate_password()
|
||||||
{
|
{
|
||||||
$generated_password = substr(str_shuffle(GENERATED_PASSWORD_CHARACTERS), 0, GENERATED_PASSWORD_LENGTH);
|
$generated_password = substr(str_shuffle(GENERATED_PASSWORD_CHARACTERS), 0, GENERATED_PASSWORD_LENGTH);
|
||||||
|
|
|
||||||
|
|
@ -173,13 +173,68 @@ function xmlrpc_get_accounts_count($method, $args)
|
||||||
return $account->getCount();
|
return $account->getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// args = [user_agent, [domain], [algo]]
|
||||||
|
function xmlrpc_create_push_account($method, $args)
|
||||||
|
{
|
||||||
|
$user_agent = $args[0];
|
||||||
|
$domain = get_domain($args[1]);
|
||||||
|
$algo = get_algo($args[2]);
|
||||||
|
|
||||||
|
Logger::getInstance()->message("[XMLRPC] xmlrpc_create_push_account(" . $domain . ", " . $algo . ")");
|
||||||
|
|
||||||
|
if ($algo == null) {
|
||||||
|
return ALGO_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
$database = new Database();
|
||||||
|
$db = $database->getConnection();
|
||||||
|
$account = new Account($db);
|
||||||
|
$account->domain = $domain;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$user = generate_username();
|
||||||
|
$account->username = $user;
|
||||||
|
} while ($account->getOne());
|
||||||
|
|
||||||
|
Logger::getInstance()->message("[XMLRPC] Push account generated username is: " . $user);
|
||||||
|
|
||||||
|
$hashed_password = hash_password($user, generate_password(), $domain, $algo);
|
||||||
|
|
||||||
|
$account->user_agent = $user_agent;
|
||||||
|
$account->ip_address = getIp();
|
||||||
|
$account->activated = "1";
|
||||||
|
$account->create();
|
||||||
|
|
||||||
|
$password = new Password($db);
|
||||||
|
$password->account_id = $account->id;
|
||||||
|
$password->password = $hashed_password;
|
||||||
|
$password->algorithm = $algo;
|
||||||
|
$password->create();
|
||||||
|
|
||||||
|
if (CUSTOM_HOOKS) {
|
||||||
|
hook_on_account_created($account);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"username" => $account->username,
|
||||||
|
"domain" => $account->domain,
|
||||||
|
"password" => $password->password,
|
||||||
|
"algorithm" => $password->algorithm
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function xmlrpc_accounts_register_methods($server)
|
function xmlrpc_accounts_register_methods($server)
|
||||||
{
|
{
|
||||||
xmlrpc_server_register_method($server, 'is_account_used', 'xmlrpc_is_account_used');// args = [username, [domain]], return OK or NOK
|
xmlrpc_server_register_method($server, 'is_account_used', 'xmlrpc_is_account_used');// args = [username, [domain]], return OK or NOK
|
||||||
xmlrpc_server_register_method($server, 'is_account_activated', 'xmlrpc_is_account_activated');// args = [username, [domain]], return OK or NOK
|
xmlrpc_server_register_method($server, 'is_account_activated', 'xmlrpc_is_account_activated');// args = [username, [domain]], return OK or NOK
|
||||||
xmlrpc_server_register_method($server, 'recover_account_from_confirmation_key', 'xmlrpc_recover_account_from_confirmation_key');// args = [username, key, [domain], [algo]]
|
xmlrpc_server_register_method($server, 'recover_account_from_confirmation_key', 'xmlrpc_recover_account_from_confirmation_key');// args = [username, key, [domain], [algo]]
|
||||||
|
|
||||||
xmlrpc_server_register_method($server, 'get_accounts_count', 'xmlrpc_get_accounts_count');//args = []
|
xmlrpc_server_register_method($server, 'get_accounts_count', 'xmlrpc_get_accounts_count');// args = []
|
||||||
|
|
||||||
|
xmlrpc_server_register_method($server, 'create_push_account', 'xmlrpc_create_push_account');// args = [user_agent, [domain], [algo]]
|
||||||
|
|
||||||
xmlrpc_accounts_email_register_methods($server);
|
xmlrpc_accounts_email_register_methods($server);
|
||||||
xmlrpc_accounts_phone_register_methods($server);
|
xmlrpc_accounts_phone_register_methods($server);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue