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
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
header("Access-Control-Allow-Origin: *");
......@@ -29,7 +29,7 @@ include_once __DIR__ . '/../../misc/utilities.php';
$database = new Database();
$db = $database->getConnection();
$account = new Account($db);
$data = json_decode(file_get_contents("php://input"));
......@@ -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);
} else {
$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;
}
if (!$password->create()) {
......@@ -88,5 +88,3 @@ if ((!empty($data->username) || !empty($data->phone)) && (!empty($data->password
http_response_code(400);
echo json_encode(array("message" => "Unable to create account, data is incomplete."));
}
?>
\ No newline at end of file
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
header("Access-Control-Allow-Origin: *");
......@@ -31,14 +31,14 @@ $logger = Logger::getInstance();
$database = new Database();
$db = $database->getConnection();
$account = new Account($db);
$data = json_decode(file_get_contents("php://input"));
if (!empty($data->id) || !empty($data->username)) {
if (!empty($data->id)) {
$account->id = $data->id;
} else if (!empty($data->username)) {
} elseif (!empty($data->username)) {
$account->username = $data->username;
if (!empty($data->domain)) {
$account->domain = $data->domain;
......@@ -48,7 +48,7 @@ if (!empty($data->id) || !empty($data->username)) {
if ($account->getOne()) {
$password = new Password($db);
$password->account_id = $account->id;
$alias = new Alias($db);
$alias->account_id = $account->id;
......@@ -77,6 +77,3 @@ if (!empty($data->id) || !empty($data->username)) {
http_response_code(400);
echo json_encode(array("message" => "Unable to delete account, data is incomplete."));
}
?>
\ No newline at end of file
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
header("Access-Control-Allow-Origin: *");
......@@ -28,7 +28,7 @@ include_once __DIR__ . '/../../objects/alias.php';
$database = new Database();
$db = $database->getConnection();
$account = new Account($db);
$account->id = isset($_GET['id']) ? $_GET['id'] : null;
$account->username = isset($_GET['username']) ? $_GET['username'] : null;
......@@ -68,5 +68,3 @@ if (!empty($account->id) && !empty($account->username) && !empty($account->domai
http_response_code(404);
echo json_encode(array("message" => "Account doesn't exist"));
}
?>
\ No newline at end of file
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
header("Access-Control-Allow-Origin: *");
......@@ -26,7 +26,7 @@ include_once __DIR__ . '/../../objects/account.php';
$database = new Database();
$db = $database->getConnection();
$account = new Account($db);
$stmt = $account->getAll();
......@@ -52,5 +52,3 @@ if ($num > 0) {
http_response_code(404);
echo json_encode(array("message" => "No account found"));
}
?>
\ No newline at end of file
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
header("Access-Control-Allow-Origin: *");
......@@ -31,14 +31,14 @@ $logger = Logger::getInstance();
$database = new Database();
$db = $database->getConnection();
$account = new Account($db);
$data = json_decode(file_get_contents("php://input"));
if (!empty($data->id) || !empty($data->username)) {
if (!empty($data->id)) {
$account->id = $data->id;
} else if (!empty($data->username)) {
} elseif (!empty($data->username)) {
$account->username = $data->username;
if (!empty($data->domain)) {
$account->domain = $data->domain;
......@@ -53,7 +53,7 @@ if (!empty($data->id) || !empty($data->username)) {
$password = new Password($db);
$password->account_id = $account->id;
$alias = new Alias($db);
$alias->account_id = $account->id;
......@@ -104,5 +104,3 @@ if (!empty($data->id) || !empty($data->username)) {
http_response_code(400);
echo json_encode(array("message" => "Unable to update account, data is incomplete."));
}
?>
\ No newline at end of file
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
include_once __DIR__ . '/../config/config.php';
include_once __DIR__ . '/../misc/logging.php';
class Database {
class Database
{
public $conn;
public function getConnection() {
public function getConnection()
{
$this->conn = null;
try {
$this->conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD);
$this->conn->exec("set names utf8");
} catch(PDOException $exception) {
} catch (PDOException $exception) {
Logger::getInstance()->error("Connection error: " . $exception->getMessage());
}
return $this->conn;
}
}
?>
\ No newline at end of file
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
include_once __DIR__ . '/../config/config.php';
include_once __DIR__ . '/../misc/logging.php';
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) {
Logger::getInstance()->error("[EMAIL] Email delivery declined !");
}
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) {
Logger::getInstance()->error("[EMAIL] Email delivery declined !");
}
}
function send_email_with_activation_link($email, $key, $username, $algo) {
if( !EMAIL_ENABLED ){
Logger::getInstance()->warning("[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);
$link = str_replace("%username%", $username, $link);
$link = str_replace("%algo%", $algo, $link);
Logger::getInstance()->debug("[EMAIL] Activation link is " . $link);
$body = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY);
Logger::getInstance()->debug("[EMAIL] Activation body is " . $body);
$body_html = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY_HTML);
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_activation_link($email, $key, $username, $algo)
{
if (!EMAIL_ENABLED) {
Logger::getInstance()->warning("[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);
$link = str_replace("%username%", $username, $link);
$link = str_replace("%algo%", $algo, $link);
Logger::getInstance()->debug("[EMAIL] Activation link is " . $link);
$body = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY);
Logger::getInstance()->debug("[EMAIL] Activation body is " . $body);
$body_html = str_replace("%link%", $link, EMAIL_ACTIVATION_BODY_HTML);
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) {
if( !EMAIL_ENABLED ){
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_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");
}
function send_email_with_recover_key($email, $key)
{
if (!EMAIL_ENABLED) {
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_html = str_replace("%key%", $key, EMAIL_RECOVERY_BODY_HTML);
Logger::getInstance()->debug("[EMAIL] Recovery html body is " . $body_html);
?>
\ No newline at end of file
send_email($email, EMAIL_RECOVERY_SUBJECT, $body, $body_html);
Logger::getInstance()->message("[EMAIL] Email sent to email " . $email . " to recover the account");
}
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
include_once __DIR__ . '/../config/config.php';
class Geoloc {
static function getGeolocInfosFromIp($ip_address){
if($ip_address == "::1" || $ip_address == "127.0.0.1" || $ip_address == "localhost"){
$service_url = 'https://ipecho.net/plain';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
Logger::getInstance()->error('Error occured during curl exec (getting public ip of server). Additionnal info: ' . var_export($info));
return false;
} else{
Logger::getInstance()->debug("Getting external public ip from ipecho.net= " . $curl_response);
$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);
Logger::getInstance()->debug("Geoloc url = " . $service_url);
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
class Geoloc
{
public static function getGeolocInfosFromIp($ip_address)
{
if ($ip_address == "::1" || $ip_address == "127.0.0.1" || $ip_address == "localhost") {
$service_url = 'https://ipecho.net/plain';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
Logger::getInstance()->error('Error occured during curl exec (getting public ip of server). Additionnal info: ' . var_export($info));
return false;
} else {
Logger::getInstance()->debug("Getting external public ip from ipecho.net= " . $curl_response);
$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);
Logger::getInstance()->debug("Geoloc url = " . $service_url);
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
Logger::getInstance()->error('Error occured during curl exec (geoloc). Additionnal info: ' . var_export($info));
return false;
}
curl_close($curl);
Logger::getInstance()->error('Error occured during curl exec (geoloc). Additionnal info: ' . var_export($info));
return false;
}
curl_close($curl);
Logger::getInstance()->debug('geoloc, curl response : ' . $curl_response);
$decoded = json_decode($curl_response);
Logger::getInstance()->debug('geoloc, curl response : ' . $curl_response);
$decoded = json_decode($curl_response);
return $decoded;
}
return $decoded;
}
}
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2019 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
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/>.
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/>.
*/
include_once __DIR__ . '/../config/config.php';
class Logger {
private static $instance = null;
class Logger
{
private static $instance = null;
private $log_file;
public function __construct() {
public function __construct()
{
if (!LOGS_ENABLED) {
return;
}
if (USE_ONE_LOG_FILE) {
$this->log_file = LOG_FILE;
} else {
if (!file_exists(LOG_DIR)) {
mkdir(LOG_DIR, 0777, true);
}
$this->log_file = LOG_DIR . "/" . date('d-M-Y') . '.logs';
}
}
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new Logger();
}
return self::$instance;
}