Commit 065f0d3d authored by Timothée Jaussoin's avatar Timothée Jaussoin

Reindent and reformat the code to follow PHP-PSR2

parent 6abd99e3
Pipeline #10613 passed with stage
in 44 seconds
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
...@@ -29,7 +29,7 @@ include_once __DIR__ . '/../../misc/utilities.php'; ...@@ -29,7 +29,7 @@ include_once __DIR__ . '/../../misc/utilities.php';
$database = new Database(); $database = new Database();
$db = $database->getConnection(); $db = $database->getConnection();
$account = new Account($db); $account = new Account($db);
$data = json_decode(file_get_contents("php://input")); $data = json_decode(file_get_contents("php://input"));
...@@ -53,7 +53,7 @@ if ((!empty($data->username) || !empty($data->phone)) && (!empty($data->password ...@@ -53,7 +53,7 @@ if ((!empty($data->username) || !empty($data->phone)) && (!empty($data->password
$password->password = hash_password($account->username, generate_password(), $account->domain, $password->algorithm); $password->password = hash_password($account->username, generate_password(), $account->domain, $password->algorithm);
} else { } else {
$password->password = empty($data->password) $password->password = empty($data->password)
? hash_password($account->username, generate_password(), $account->domain, $password->algorithm) ? hash_password($account->username, generate_password(), $account->domain, $password->algorithm)
: $data->password; : $data->password;
} }
if (!$password->create()) { if (!$password->create()) {
...@@ -88,5 +88,3 @@ if ((!empty($data->username) || !empty($data->phone)) && (!empty($data->password ...@@ -88,5 +88,3 @@ if ((!empty($data->username) || !empty($data->phone)) && (!empty($data->password
http_response_code(400); http_response_code(400);
echo json_encode(array("message" => "Unable to create account, data is incomplete.")); echo json_encode(array("message" => "Unable to create account, data is incomplete."));
} }
?>
\ No newline at end of file
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
...@@ -31,14 +31,14 @@ $logger = Logger::getInstance(); ...@@ -31,14 +31,14 @@ $logger = Logger::getInstance();
$database = new Database(); $database = new Database();
$db = $database->getConnection(); $db = $database->getConnection();
$account = new Account($db); $account = new Account($db);
$data = json_decode(file_get_contents("php://input")); $data = json_decode(file_get_contents("php://input"));
if (!empty($data->id) || !empty($data->username)) { if (!empty($data->id) || !empty($data->username)) {
if (!empty($data->id)) { if (!empty($data->id)) {
$account->id = $data->id; $account->id = $data->id;
} else if (!empty($data->username)) { } elseif (!empty($data->username)) {
$account->username = $data->username; $account->username = $data->username;
if (!empty($data->domain)) { if (!empty($data->domain)) {
$account->domain = $data->domain; $account->domain = $data->domain;
...@@ -48,7 +48,7 @@ if (!empty($data->id) || !empty($data->username)) { ...@@ -48,7 +48,7 @@ if (!empty($data->id) || !empty($data->username)) {
if ($account->getOne()) { if ($account->getOne()) {
$password = new Password($db); $password = new Password($db);
$password->account_id = $account->id; $password->account_id = $account->id;
$alias = new Alias($db); $alias = new Alias($db);
$alias->account_id = $account->id; $alias->account_id = $account->id;
...@@ -77,6 +77,3 @@ if (!empty($data->id) || !empty($data->username)) { ...@@ -77,6 +77,3 @@ if (!empty($data->id) || !empty($data->username)) {
http_response_code(400); http_response_code(400);
echo json_encode(array("message" => "Unable to delete account, data is incomplete.")); echo json_encode(array("message" => "Unable to delete account, data is incomplete."));
} }
?>
\ No newline at end of file
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
...@@ -28,7 +28,7 @@ include_once __DIR__ . '/../../objects/alias.php'; ...@@ -28,7 +28,7 @@ include_once __DIR__ . '/../../objects/alias.php';
$database = new Database(); $database = new Database();
$db = $database->getConnection(); $db = $database->getConnection();
$account = new Account($db); $account = new Account($db);
$account->id = isset($_GET['id']) ? $_GET['id'] : null; $account->id = isset($_GET['id']) ? $_GET['id'] : null;
$account->username = isset($_GET['username']) ? $_GET['username'] : null; $account->username = isset($_GET['username']) ? $_GET['username'] : null;
...@@ -68,5 +68,3 @@ if (!empty($account->id) && !empty($account->username) && !empty($account->domai ...@@ -68,5 +68,3 @@ if (!empty($account->id) && !empty($account->username) && !empty($account->domai
http_response_code(404); http_response_code(404);
echo json_encode(array("message" => "Account doesn't exist")); echo json_encode(array("message" => "Account doesn't exist"));
} }
?>
\ No newline at end of file
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
...@@ -26,7 +26,7 @@ include_once __DIR__ . '/../../objects/account.php'; ...@@ -26,7 +26,7 @@ include_once __DIR__ . '/../../objects/account.php';
$database = new Database(); $database = new Database();
$db = $database->getConnection(); $db = $database->getConnection();
$account = new Account($db); $account = new Account($db);
$stmt = $account->getAll(); $stmt = $account->getAll();
...@@ -52,5 +52,3 @@ if ($num > 0) { ...@@ -52,5 +52,3 @@ if ($num > 0) {
http_response_code(404); http_response_code(404);
echo json_encode(array("message" => "No account found")); echo json_encode(array("message" => "No account found"));
} }
?>
\ No newline at end of file
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
...@@ -31,14 +31,14 @@ $logger = Logger::getInstance(); ...@@ -31,14 +31,14 @@ $logger = Logger::getInstance();
$database = new Database(); $database = new Database();
$db = $database->getConnection(); $db = $database->getConnection();
$account = new Account($db); $account = new Account($db);
$data = json_decode(file_get_contents("php://input")); $data = json_decode(file_get_contents("php://input"));
if (!empty($data->id) || !empty($data->username)) { if (!empty($data->id) || !empty($data->username)) {
if (!empty($data->id)) { if (!empty($data->id)) {
$account->id = $data->id; $account->id = $data->id;
} else if (!empty($data->username)) { } elseif (!empty($data->username)) {
$account->username = $data->username; $account->username = $data->username;
if (!empty($data->domain)) { if (!empty($data->domain)) {
$account->domain = $data->domain; $account->domain = $data->domain;
...@@ -53,7 +53,7 @@ if (!empty($data->id) || !empty($data->username)) { ...@@ -53,7 +53,7 @@ if (!empty($data->id) || !empty($data->username)) {
$password = new Password($db); $password = new Password($db);
$password->account_id = $account->id; $password->account_id = $account->id;
$alias = new Alias($db); $alias = new Alias($db);
$alias->account_id = $account->id; $alias->account_id = $account->id;
...@@ -104,5 +104,3 @@ if (!empty($data->id) || !empty($data->username)) { ...@@ -104,5 +104,3 @@ if (!empty($data->id) || !empty($data->username)) {
http_response_code(400); http_response_code(400);
echo json_encode(array("message" => "Unable to update account, data is incomplete.")); echo json_encode(array("message" => "Unable to update account, data is incomplete."));
} }
?>
\ No newline at end of file
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
include_once __DIR__ . '/../config/config.php'; include_once __DIR__ . '/../config/config.php';
include_once __DIR__ . '/../misc/logging.php'; include_once __DIR__ . '/../misc/logging.php';
class Database { class Database
{
public $conn; public $conn;
public function getConnection() { public function getConnection()
{
$this->conn = null; $this->conn = null;
try { try {
$this->conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD); $this->conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD);
$this->conn->exec("set names utf8"); $this->conn->exec("set names utf8");
} catch(PDOException $exception) { } catch (PDOException $exception) {
Logger::getInstance()->error("Connection error: " . $exception->getMessage()); Logger::getInstance()->error("Connection error: " . $exception->getMessage());
} }
return $this->conn; return $this->conn;
} }
} }
?>
\ No newline at end of file
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
include_once __DIR__ . '/../config/config.php'; include_once __DIR__ . '/../config/config.php';
include_once __DIR__ . '/../misc/logging.php'; include_once __DIR__ . '/../misc/logging.php';
function send_email($email, $subject, $text, $html) { function send_email($email, $subject, $text, $html)
$site = EMAIL_SITE; {
$from = EMAIL_FROM_ADDR; $site = EMAIL_SITE;
$name = EMAIL_FROM_NAME; $from = EMAIL_FROM_ADDR;
$to = $email; $name = EMAIL_FROM_NAME;
$from = $name." <".$from.">"; $to = $email;
$from = $name." <".$from.">";
$limite = "_----------=_parties_".md5(uniqid (rand()));
$limite = "_----------=_parties_".md5(uniqid(rand()));
$headers = "Reply-to: ".$from."\n";
$headers .= "From: ".$from."\n"; $headers = "Reply-to: ".$from."\n";
$headers .= "Return-Path: ".$from."\n"; $headers .= "From: ".$from."\n";
$headers .= "X-Sender: <".$site.">\n"; $headers .= "Return-Path: ".$from."\n";
$headers .= "X-Mailer: PHP\n"; $headers .= "X-Sender: <".$site.">\n";
$headers .= "X-auth-smtp-user: ".$from." \n"; $headers .= "X-Mailer: PHP\n";
$headers .= "X-abuse-contact: ".$from." \n"; $headers .= "X-auth-smtp-user: ".$from." \n";
$headers .= "X-auth-smtp-user: ".$from." \n"; $headers .= "X-abuse-contact: ".$from." \n";
$headers .= "X-abuse-contact: ".$from." \n"; $headers .= "X-auth-smtp-user: ".$from." \n";
$headers .= "Date: ".date("D, j M Y G:i:s O")."\n"; $headers .= "X-abuse-contact: ".$from." \n";
$headers .= "MIME-Version: 1.0\n"; $headers .= "Date: ".date("D, j M Y G:i:s O")."\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"".$limite."\""; $headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";
$message = "";
$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain; charset=\"utf-8\"\n"; $message .= "--".$limite."\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= "Content-Type: text/plain; charset=\"utf-8\"\n";
$message .= $text; $message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $text;
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; charset=\"utf-8\"\n"; $message .= "\n\n--".$limite."\n";
$message .= "Content-Transfer-Encoding: 8bit;\n\n"; $message .= "Content-Type: text/html; charset=\"utf-8\"\n";
$message .= $html; $message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $html;
$message .= "\n--".$limite."--";
$message .= "\n--".$limite."--";
$params = "-f" . EMAIL_FROM_ADDR . " -O DeliveryMode=b";
$result = mail($email, $subject, $message, $headers, $params); $params = "-f" . EMAIL_FROM_ADDR . " -O DeliveryMode=b";
if (!$result) { $result = mail($email, $subject, $message, $headers, $params);
Logger::getInstance()->error("[EMAIL] Email delivery declined !"); if (!$result) {
} Logger::getInstance()->error("[EMAIL] Email delivery declined !");
}
} }
function send_email_with_activation_link($email, $key, $username, $algo) { function send_email_with_activation_link($email, $key, $username, $algo)
if( !EMAIL_ENABLED ){ {
Logger::getInstance()->warning("[EMAIL] Emails are disabled"); if (!EMAIL_ENABLED) {
return "WARNING_EMAILS_DISABLED"; Logger::getInstance()->warning("[EMAIL] Emails are disabled");
} return "WARNING_EMAILS_DISABLED";
}
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL = 'http';
$pageURL .= "://"; if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
$link = $pageURL . EMAIL_ACTIVATION_LINK; }
$link = str_replace("%key%", $key, $link); $pageURL .= "://";
$link = str_replace("%username%", $username, $link);
$link = str_replace("%algo%", $algo, $link); $link = $pageURL . EMAIL_ACTIVATION_LINK;
Logger::getInstance()->debug("[EMAIL] Activation link is " . $link); $link = str_replace("%key%", $key, $link);
$link = str_replace("%username%", $username, $link);
$body = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY); $link = str_replace("%algo%", $algo, $link);
Logger::getInstance()->debug("[EMAIL] Activation body is " . $body); Logger::getInstance()->debug("[EMAIL] Activation link is " . $link);
$body_html = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY_HTML);
Logger::getInstance()->debug("[EMAIL] Activation html body is " . $body_html); $body = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY);
Logger::getInstance()->debug("[EMAIL] Activation body is " . $body);
send_email($email, EMAIL_ACTIVATION_SUBJECT, $body, $body_html); $body_html = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY_HTML);
Logger::getInstance()->message("[EMAIL] Email sent to email " . $email . " to activate the account"); Logger::getInstance()->debug("[EMAIL] Activation html body is " . $body_html);
send_email($email, EMAIL_ACTIVATION_SUBJECT, $body, $body_html);
Logger::getInstance()->message("[EMAIL] Email sent to email " . $email . " to activate the account");
} }
function send_email_with_recover_key($email, $key) { function send_email_with_recover_key($email, $key)
if( !EMAIL_ENABLED ){ {
Logger::getInstance()->warning("[EMAIL] Emails are disabled"); if (!EMAIL_ENABLED) {
return "WARNING_EMAILS_DISABLED"; Logger::getInstance()->warning("[EMAIL] Emails are disabled");
} return "WARNING_EMAILS_DISABLED";
}
$body = str_replace("%key%", $key, EMAIL_RECOVERY_BODY);
Logger::getInstance()->debug("[EMAIL] Recovery body is " . $body); $body = str_replace("%key%", $key, EMAIL_RECOVERY_BODY);
$body_html = str_replace("%key%", $key, EMAIL_RECOVERY_BODY_HTML); Logger::getInstance()->debug("[EMAIL] Recovery body is " . $body);
Logger::getInstance()->debug("[EMAIL] Recovery html body is " . $body_html); $body_html = str_replace("%key%", $key, EMAIL_RECOVERY_BODY_HTML);
Logger::getInstance()->debug("[EMAIL] Recovery html body is " . $body_html);
send_email($email, EMAIL_RECOVERY_SUBJECT, $body, $body_html);
Logger::getInstance()->message("[EMAIL] Email sent to email " . $email . " to recover the account");
}
?> send_email($email, EMAIL_RECOVERY_SUBJECT, $body, $body_html);
\ No newline at end of file Logger::getInstance()->message("[EMAIL] Email sent to email " . $email . " to recover the account");
}
<
<?php <?php
/* /*
Flexisip Account Manager is a set of tools to manage SIP accounts. Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved. Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details. GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
include_once __DIR__ . '/../config/config.php'; include_once __DIR__ . '/../config/config.php';
class Geoloc { class Geoloc
static function getGeolocInfosFromIp($ip_address){ {
if($ip_address == "::1" || $ip_address == "127.0.0.1" || $ip_address == "localhost"){ public static function getGeolocInfosFromIp($ip_address)
$service_url = 'https://ipecho.net/plain'; {
$curl = curl_init($service_url); if ($ip_address == "::1" || $ip_address == "127.0.0.1" || $ip_address == "localhost") {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $service_url = 'https://ipecho.net/plain';
$curl_response = curl_exec($curl); $curl = curl_init($service_url);
if ($curl_response === false) { curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$info = curl_getinfo($curl); $curl_response = curl_exec($curl);
curl_close($curl); if ($curl_response === false) {
Logger::getInstance()->error('Error occured during curl exec (getting public ip of server). Additionnal info: ' . var_export($info)); $info = curl_getinfo($curl);
return false; curl_close($curl);
} else{ Logger::getInstance()->error('Error occured during curl exec (getting public ip of server). Additionnal info: ' . var_export($info));
Logger::getInstance()->debug("Getting external public ip from ipecho.net= " . $curl_response); return false;
$ip_address = $curl_response; } else {
} Logger::getInstance()->debug("Getting external public ip from ipecho.net= " . $curl_response);
curl_close($curl); $ip_address = $curl_response;
}
} curl_close($curl);
$service_url = 'http://api.ipapi.com/' . $ip_address .'?access_key='. GEOLOC_ACCESS_KEY .'&fields=country_code,country_name'; }
Logger::getInstance()->debug("Getting geoloc infos for ip after parse if=" . $ip_address); $service_url = 'http://api.ipapi.com/' . $ip_address .'?access_key='. GEOLOC_ACCESS_KEY .'&fields=country_code,country_name';
Logger::getInstance()->debug("Geoloc url = " . $service_url); Logger::getInstance()->debug("Getting geoloc infos for ip after parse if=" . $ip_address);
$curl = curl_init($service_url); Logger::getInstance()->debug("Geoloc url = " . $service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $curl = curl_init($service_url);
$curl_response = curl_exec($curl); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($curl_response === false) { $curl_response = curl_exec($curl);
$info = curl_getinfo($curl); if ($curl_response === false) {