Flexisipアカウントマネージャ、プロビジョニング

前回のブログで紹介したFlexisipによるSIPサーバシステムにFlexisip Account Managerを配置します。Flexisip Account Managerは次の2つの役割を有しています。
プロビジョニング:プロビジョニングとは、Linphoneアプリに必要な設定ファイルを読み込み(書換え)することであり、XML-RPCサーバからこの設定ファイルが提供されます。conf, srcディレクトリの中身がこの機能に該当します。
ウェブフロントエンド:Laravel PHPフレームワークによるユーザ登録・管理用のウェブインターフェイスです。flexiapiディレクトリがこれに該当します。
以下GitLabで配布されているソースコードをダウンロードしconf, src, flexiapi各フォルダをdocker-composeファイルで指定したホストマシンのディレクトリにコピーして下さい。
GitLab: flexisip-account-managerソースコード
BC / public / flexisip-account-manager
$ cp -r flexisip-account-manager/conf project/ubuntu20-04/etc
$ cp -r flexisip-account-manager/src/* project/ubuntu20-04/html/flexisip-account-manager
$ cp -r flexisip-account-manager/flexiapi project/ubuntu20-04/html
アクセス権の設定
php-fpm-laravelコンテナ内でアクセス権を修復します。
$ docker exec -ti php-fpm-laravel bash
# cd /var/www/html
# chown -R www-data:www-data ./
# chmod -R 755 ./
1. 設定ファイル
データベース設定ファイル:db.conf
docker-composeファイルで指定したMariaDBコンテナをデータベースのホストとします。その他アクセスするデータベース名、ユーザ、パスワードを設定します。
db.conf
/*
* The host on which the database is located.
*
* Default value: localhost
*/
define("DB_HOST", "flexisip-mariadb");
/*
* Enable data transfert over ssl.
*
* Default value: False
*/
define("DB_ENABLE_SSL", "False");
/*
* rootca path. MANDATORY for DB SSL to work
*
* Default value: ""
* Possible value : /opt/belledonne-communications/share/linphone/rootca.pem
*/
define("ROOT_CA_PATH", "");
/*
* The database username.
*
* Default value: flexisip_rw
*/
define("DB_USER", "flexisip");
/*
* The database user's password.
*
* Default value:
*/
define("DB_PASSWORD", "flexisip1234");
/*
* The name of the database.
*
* Default value: flexisip
*/
define("DB_NAME", "flexisip");
プロビジョニング設定ファイル:provisioning.conf
リモートからの設定ファイルの上書きを有効にします。define("REMOTE_PROVISIONING_OVERWRITE_ALL", True);
デフォルトの設定ファイルdefault.rcは同じディレクトリ内で作成します。
provisioning.conf
<?php
/*
* If set to True, each section will be flagged as overwrite, otherwise none of them will be flagged.
*
* Default value: False
*/
define("REMOTE_PROVISIONING_OVERWRITE_ALL", True);
/*
* The path to a default linphone rc file to add to the generated remote provisioning
* If using the default value, the default.rc file should be created in /opt/belledonne-communications/share/flexisip-account-manager/xmlrpc/ directory
* If the file does not exists it is ignored
*
* The file should follow the lpconfig format, for example:
* [sip]
* rls_uri=sips:rls@sip.linphone.org
* # This is a commentary, it won't appear in the generated xml provisioning
*
* Default value: "default.rc"
*/
define("REMOTE_PROVISIONING_DEFAULT_CONFIG", "default.rc");
/*
* The default transport to set in the proxy config if not specified
* Can be "tls", "tcp" or "udp"
*
* Default value: "tls"
*/
define("REMOTE_PROVISIONING_DEFAULT_TRANSPORT", "tls");
/*
* If set to True, provisioning.php will generate a new password if the account was not activated yet and activate it.
*
* Default value: False
*/
define("REMOTE_PROVISIONING_ONE_TIME_PASSWORD", False);
/*
* If set to True, digest authentication will be asked for remote provisioning process (see auth.conf).
*
* Default value: False
*/
define("REMOTE_PROVISIONING_USE_DIGEST_AUTH", False);
?>
アカウント設定ファイル:accounts.conf
パスワードハッシュ条件、メール認証、SMS認証の有無などを設定します。
accounts.conf
<?php
/*
* The SIP domain to use to hash passwords.
*
* Default value: sip.example.org
*/
define("SIP_DOMAIN", "sip.example.org");
/*
* If true, when account is created, the password will be generated automatically (see below).
* Otherwise it has to be given as the last parameter of the create_account method call.
*
* Default value: False
*/
define("GENERATE_PASSWORD_ENABLED", False);
/*
* A string with each character allowed in the password generation.
*
* Default value: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789``-=~!@#$%^&*()_+,./<>?;:[]{}\|
*/
define("GENERATED_PASSWORD_CHARACTERS", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789``-=~!@#$%^&*()_+,./<>?;:[]{}\|");
/*
* The length of the passwords that will be generated.
*
* Default value: 8
*/
define("GENERATED_PASSWORD_LENGTH", 8);
/*
* The default algorithm to use if not specified in the request
*
* Default value: 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,
* otherwise expiration date for trial will be set when account is activated via a different xml rpc call.
*/
define('AUTO_ACTIVATE_ACCOUNT', False);
/*
* Send an email to activate the account when it is created.
*/
define('SEND_ACTIVATION_EMAIL', True);
/*
* Send a sms to activate the phone account when it is created.
*/
define('SEND_ACTIVATION_SMS', True);
/*
* If false, creating an account with an email that is already used for another account will trigger an error
*/
define('ALLOW_SAME_EMAILS_ON_MULTILPLE_ACCOUNTS', True);
/*
* If true, when an account creation request is received for an existing number, assumes recover procedure
*/
define('RECOVER_ACCOUNT_IF_EXISTS', False);
/*
* Enabling geoloc of accounts in user_info table.
* When this option is set, the fields coutry_name and country_code will be filled
* with a call to api.ipapi.com
*
* Default value: False
*/
define("ENABLE_NEW_ACCOUNTS_GEOLOC", False);
/* API key for geoloc. If you need geoloc and don't have a key,
* ask it on ipapi.com
*/
define("GEOLOC_ACCESS_KEY", "");
?>
その他設定ファイルについては、各自必要に応じて編集して下さい。
2. プロビジョニング
Linphoneアプリのデフォルト設定を変更する場合などに利用します。
Linphoneアプリのアシスタントメニューから"FETCH REMOTE CONFIGURATION"をクリックします。
事前に以下のようなprovisioning.confで指定したデフォルトの設定ファイルdefault.rcを作成し、下図URLの入力欄に https://sip.example.cpm/flexisip-account-manager/provisioning.php
と入力すると、default.rcがXMLフォーマットの設定ファイルに変換され、その内容がLinphoneアプリに読み込まれ、設定が上書きされます。
default.rcはxmlrpcディレクトリ内に作成します。
/flexisip-account-manager/xmlrpc/default.rc
#
#This file shall not contain path referencing package name, in order to be portable when app is renamed.
#Paths to resources must be set from LinphoneManager, after creating LinphoneCore.
[assistant]
domain=sip.example.com
xmlrpc_url=https://sip.example.com/flexisip-account-manager/xmlrpc.php
Linphoneアプリの標準設定ファイルは以下から入手可能。これをカスタマイズして読み込ませることでデフォルト設定が上書きされるかどうか検証中。
直接XMLフォーマットによるファイルを指定することでユーザの読み込みなども行えます。
以下LinphoneデフォルトのXML-RPCサーバにより、登録済ユーザがLinphoneアプリに読み込まれます。
Provisioning
https://wiki.linphone.org/xwiki/wiki/public/view/Lib/Features/Remote%20Provisioning/
読み込まれるユーザアカウントの例
LinphoneのアシスタントメニューからQRコードまたは下記アドレスを指定して読み込み。
https://www.linphone.org/remote_provisioning.xml
参考)XML-RPC
https://en.wikipedia.org/wiki/XML-RPC
3. ウェブフロントエンド
PHPフレームワークLaravelのartisanコンソールによりFlexisip-Account-Managerの環境構築を行います。
docker-composeファイルで定義したphp-fpm-laravelコンテナに入り、flexiapiディレクトリ内で以下コマンドを実行します。
$ docker exec -ti php-fpm-laravel bash
# cd flexiapi
# composer install --no-dev
# cp .env.example .env
# php artisan key:generate
APP_KEYが追加された .envファイル でデータベースの設定などを行います。
APP_NAME=FlexiAPI
APP_ENV=local
APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
APP_DEBUG=false
APP_URL=https://www.example.com
APP_SIP_DOMAIN=www.example.com
APP_FLEXISIP_PROXY_PID=/var/run/flexisip-proxy.pid
APP_FLEXISIP_PUSHER_PATH=
APP_EVERYONE_IS_ADMIN=false
# SIP server parameters
ACCOUNT_PROXY_REGISTRAR_ADDRESS=ficus-home.duckdns.org # Proxy registrar address, can be different than the SIP domain
ACCOUNT_TRANSPORT_PROTOCOL_TEXT="TLS (recommended), TCP or UDP" # Simple text, to explain how the SIP server can be reached
ACCOUNT_REALM=null # Default realm for the accounts, fallback to the domain if not set, enforce null by default
# Account provisioning
ACCOUNT_PROVISIONING_RC_FILE=
ACCOUNT_PROVISIONING_OVERWRITE_ALL=
# Instance specific parameters
INSTANCE_COPYRIGHT= # Simple text displayed in the page footer
INSTANCE_INTRO_REGISTRATION= # Markdown text displayed in the home page
INSTANCE_CUSTOM_THEME=false
INSTANCE_CONFIRMED_REGISTRATION_TEXT= # Markdown text displayed when an account is confirmed
NEWSLETTER_REGISTRATION_ADDRESS= # Address to contact when a user wants to register to the newsletter
PUBLIC_REGISTRATION=true # Toggle to enable/disable the public registration forms
PHONE_AUTHENTICATION=true # Toggle to enable/disable the SMS support, requires public registration
DEVICES_MANAGEMENT=false # Toggle to enable/disable the devices management support
TERMS_OF_USE_URL= # A URL pointing to the Terms of Use
PRIVACY_POLICY_URL= # A URL pointing to the Privacy Policy
LOG_CHANNEL=stack
# External FlexiSIP database
# Ensure that you have the proper SELinux configuration to allow database connections, see the README
DB_DRIVER=mysql
DB_HOST=database_host
DB_PORT=3306
DB_DATABASE=flexisip
DB_USERNAME=flexisip
DB_PASSWORD=password
# Logs
# Ensure that you have the proper SELinux configuration to write in the storage directory, see the README
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=cookie
SESSION_LIFETIME=120
# SMTP and emails
# Ensure that you have the proper SELinux configuration to allow emails sending, see the README
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=xxxxxxxxxxxxxxxxxx
MAIL_PASSWORD=xxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=xxxxxxxx@gmail.com
MAIL_FROM_NAME=xxxxxxxxxxxx
MAIL_ALLOW_SELF_SIGNED=false
MAIL_VERIFY_PEER=true
MAIL_VERIFY_PEER_NAME=true
MAIL_SIGNATURE="The xxxxx Team"
MAIL_ENCRYPTION=tls
# OVH SMS API variables
OVH_APP_KEY=
OVH_APP_SECRET=
OVH_APP_ENDPOINT=ovh-eu
OVH_APP_CONSUMER_KEY=
OVH_APP_SENDER=
# Google reCaptcha v2 parameters
NOCAPTCHA_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
NOCAPTCHA_SITEKEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Flexisipに必要なテーブルを作成します。事前にphpからmysqlへ接続するドライバ拡張モジュール pdo_mysql
をインストールします(これはphp-fpmイメージ作成時にインストールするようDockerfileに事前に記述しておきましょう)。
https://www.php.net/manual/en/ref.pdo-mysql.php
# docker-php-ext-install pdo_mysql
LaravelのArtisanコンソールによりテーブルを作成します。
https://laravel.com/docs/8.x/artisan
# php artisan migrate
以下のテーブルが作成されます。
.envファイルで設定したURLにアクセスすると管理画面のページが表示されます。
なお、ユーザ登録を有効にするには、.envファイルの SMTP and emails(email認証する場合)、 OVH SMS API variables(SMS認証する場合) セクションの設定とreCAPTCHAの設定が必要です。
アカウント作成・管理ホーム画面
Email認証によるユーザ登録画面
注)500サーバエラーが表示された場合、flexiapiのアクセス権を見直すか、コンテナを再起動して下さい。
4. 管理者ユーザの設定
登録した任意のユーザを管理者ユーザに設定します。
php-fpm-laravelコンテナ内で以下のLaravelの php artisanコンソール
により既存ユーザを管理者として登録します。登録ユーザのIDを指定します。
$ dcoker exec -ti php-fpm-laravel bash
# php artisan accounts:set-admin USER_ID_NUMBER
php artisan ヘルプ
https://laravel.com/docs/8.x/artisan
# php artisan --help
php artisan “accounts:set-admin” ヘルプ
# php artisan accounts:set-admin --help
Description:
Give the admin role to an account
Usage:
accounts:set-admin <id>
Arguments:
id
管理者ユーザになることにより、他ユーザアカウントの管理・追加・編集権限が付与されます。
管理メニュー
ユーザアカウントリスト
ユーザアカウント
5. テーマのカスタマイズ
テーマのカスタマイズは.envファイル内で設定します。
.env
.....
APP_ENV=local
.....
INSTANCE_CUSTOM_THEME=true
.....
# memo
# If you set INSTANCE_CUSTOM_THEME to true(.env), FlexiAPI will try to load a CSS # file located in public/css/$APP_ENV.style.css. If the file doesn’t exists it will fallback to public/css/style.css.
# We advise you to copy the style.css file and rename it to make your custom CSS # configurations for your instance.
GitHub : Flexisip + Account Manager on Ubuntu 20.04
以下GitHubに関連ファイルをアップロード。一部設定ファイルなどはセキュリティ上割愛。docker-composeファイルのコメント欄を一読願います。
docker-flexisip/ubuntu20-04 at master · capitalfuse/docker-flexisip