Skip to content
Snippets Groups Projects
Verified Commit 35c4b6b1 authored by Benedikt Wildenhain's avatar Benedikt Wildenhain
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
<?php
//application details
$apps[$x]['name'] = "Fail2Ban";
$apps[$x]['uuid'] = "9cda5dab-a584-4ff5-a4e4-6d95d52d92dc";
$apps[$x]['category'] = "Switch";
$apps[$x]['subcategory'] = "";
$apps[$x]['version'] = "1.0";
$apps[$x]['license'] = "CC-BY-SA 3.0";
$apps[$x]['url'] = "https://salsa.debian.org/benedikt-guest";
$apps[$x]['description']['en-us'] = "(Un)ban hosts";
$apps[$x]['description']['en-gb'] = "(Un)ban hosts";
$apps[$x]['description']['ar-eg'] = "";
$apps[$x]['description']['de-at'] = "temporäre Hostsperren einrichten und aufheben";
$apps[$x]['description']['de-ch'] = "temporäre Hostsperren einrichten und aufheben";
$apps[$x]['description']['de-de'] = "temporäre Hostsperren einrichten und aufheben";
$apps[$x]['description']['es-cl'] = "";
$apps[$x]['description']['es-mx'] = "";
$apps[$x]['description']['fr-ca'] = "";
$apps[$x]['description']['fr-fr'] = "";
$apps[$x]['description']['he-il'] = "";
$apps[$x]['description']['it-it'] = "";
$apps[$x]['description']['nl-nl'] = "";
$apps[$x]['description']['pl-pl'] = "";
$apps[$x]['description']['pt-br'] = "";
$apps[$x]['description']['pt-pt'] = "";
$apps[$x]['description']['ro-ro'] = "";
$apps[$x]['description']['ru-ru'] = "";
$apps[$x]['description']['sv-se'] = "";
$apps[$x]['description']['uk-ua'] = "";
//permission details
$y=0;
$apps[$x]['permissions'][$y]['name'] = "fail2ban_view";
$apps[$x]['permissions'][$y]['menu']['uuid'] = "9cda5dab-a584-4ff5-a4e4-6d95d52d92dc";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "fail2ban_ban";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "fail2ban_unban";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
?>
<?php
?>
<?php
$text['title-fail2ban']['en-us'] = "Fail2ban";
$text['title-fail2ban']['en-gb'] = "Fail2ban";
$text['title-fail2ban']['ar-eg'] = "Fail2ban";
$text['title-fail2ban']['de-at'] = "Fail2ban";
$text['title-fail2ban']['de-ch'] = "Fail2ban";
$text['title-fail2ban']['de-de'] = "Fail2ban";
$text['title-fail2ban']['el-gr'] = "Fail2ban";
$text['title-fail2ban']['es-cl'] = "Fail2ban";
$text['title-fail2ban']['es-mx'] = "Fail2ban";
$text['title-fail2ban']['fr-ca'] = "Fail2ban";
$text['title-fail2ban']['fr-fr'] = "Fail2ban";
$text['title-fail2ban']['he-il'] = "Fail2ban";
$text['title-fail2ban']['it-it'] = "Fail2ban";
$text['title-fail2ban']['nl-nl'] = "Fail2ban";
$text['title-fail2ban']['pl-pl'] = "Fail2ban";
$text['title-fail2ban']['pt-br'] = "Fail2ban";
$text['title-fail2ban']['pt-pt'] = "Fail2ban";
$text['title-fail2ban']['ro-ro'] = "Fail2ban";
$text['title-fail2ban']['ru-ru'] = "Fail2ban";
$text['title-fail2ban']['sv-se'] = "Fail2ban";
$text['title-fail2ban']['uk-ua'] = "Fail2ban";
$text['message-connection']['en-us'] = "Connection to Socket failed.";
$text['message-connection']['en-gb'] = "Connection to Socket failed.";
$text['message-connection']['ar-eg'] = "";
$text['message-connection']['de-at'] = "Verbindung zum Socket fehlgeschlagen."; //copied from de-de
$text['message-connection']['de-ch'] = "Verbindung zum Socket fehlgeschlagen."; //copied from de-de
$text['message-connection']['de-de'] = "Verbindung zum Socket fehlgeschlagen.";
$text['message-connection']['es-cl'] = "Conexión a Socket de o fallida.";
$text['message-connection']['es-mx'] = "Conexión a Socket de o fallida."; //copied from es-cl
$text['message-connection']['fr-ca'] = "Connexion au socket en echec."; //copied from fr-fr
$text['message-connection']['fr-fr'] = "Connexion au socket en echec.";
$text['message-connection']['he-il'] = "";
$text['message-connection']['it-it'] = "Connessione all' Socket fallita.";
$text['message-connection']['nl-nl'] = "Verbinding met Socket mislukt";
$text['message-connection']['pl-pl'] = "Połączenie do „Socket” nie powiodło się";
$text['message-connection']['pt-br'] = "";
$text['message-connection']['pt-pt'] = "Conexão à Socket falhou.";
$text['message-connection']['ro-ro'] = "";
$text['message-connection']['ru-ru'] = "Подключение к Socket неудачно.";
$text['message-connection']['sv-se'] = "Anslutning till Händelse misslyckades";
$text['message-connection']['uk-ua'] = "";
$text['label-message']['en-us'] = "Message";
$text['label-message']['en-gb'] = "Message";
$text['label-message']['ar-eg'] = "";
$text['label-message']['de-at'] = "Nachricht"; //copied from de-de
$text['label-message']['de-ch'] = "Nachricht"; //copied from de-de
$text['label-message']['de-de'] = "Nachricht";
$text['label-message']['es-cl'] = "Mensaje";
$text['label-message']['es-mx'] = "Mensaje"; //copied from es-cl
$text['label-message']['fr-ca'] = "Message"; //copied from fr-fr
$text['label-message']['fr-fr'] = "Message";
$text['label-message']['he-il'] = "";
$text['label-message']['it-it'] = "Messaggio";
$text['label-message']['nl-nl'] = "Boodschap";
$text['label-message']['pl-pl'] = "Wiadomość";
$text['label-message']['pt-br'] = "Mensagem"; //copied from pt-pt
$text['label-message']['pt-pt'] = "Mensagem";
$text['label-message']['ro-ro'] = "";
$text['label-message']['ru-ru'] = "Сообщение";
$text['label-message']['sv-se'] = "Meddelande";
$text['label-message']['uk-ua'] = "Повідомлення";
$text['label-jail']['en-us'] = "Category";
$text['label-jail']['en-gb'] = "Category";
$text['label-jail']['ar-eg'] = "Category";
$text['label-jail']['de-at'] = "Kategorie";
$text['label-jail']['de-ch'] = "Kategorie";
$text['label-jail']['de-de'] = "Kategorie";
$text['label-jail']['el-gr'] = "Category";
$text['label-jail']['es-cl'] = "Category";
$text['label-jail']['es-mx'] = "Category";
$text['label-jail']['fr-ca'] = "Category";
$text['label-jail']['fr-fr'] = "Category";
$text['label-jail']['he-il'] = "Category";
$text['label-jail']['it-it'] = "Category";
$text['label-jail']['nl-nl'] = "Category";
$text['label-jail']['pl-pl'] = "Category";
$text['label-jail']['pt-br'] = "Category";
$text['label-jail']['pt-pt'] = "Category";
$text['label-jail']['ro-ro'] = "Category";
$text['label-jail']['ru-ru'] = "Category";
$text['label-jail']['sv-se'] = "Category";
$text['label-jail']['uk-ua'] = "Category";
$text['label-ip-address']['en-us'] = "IP-Address";
$text['label-ip-address']['en-gb'] = "IP-Address";
$text['label-ip-address']['ar-eg'] = "IP-Address";
$text['label-ip-address']['de-at'] = "IP-Adresse";
$text['label-ip-address']['de-ch'] = "IP-Adresse";
$text['label-ip-address']['de-de'] = "IP-Adresse";
$text['label-ip-address']['el-gr'] = "IP-Address";
$text['label-ip-address']['es-cl'] = "IP-Address";
$text['label-ip-address']['es-mx'] = "IP-Address";
$text['label-ip-address']['fr-ca'] = "IP-Address";
$text['label-ip-address']['fr-fr'] = "IP-Address";
$text['label-ip-address']['he-il'] = "IP-Address";
$text['label-ip-address']['it-it'] = "IP-Address";
$text['label-ip-address']['nl-nl'] = "IP-Address";
$text['label-ip-address']['pl-pl'] = "IP-Address";
$text['label-ip-address']['pt-br'] = "IP-Address";
$text['label-ip-address']['pt-pt'] = "IP-Address";
$text['label-ip-address']['ro-ro'] = "IP-Address";
$text['label-ip-address']['ru-ru'] = "IP-Address";
$text['label-ip-address']['sv-se'] = "IP-Address";
$text['label-ip-address']['uk-ua'] = "IP-Address";
$text['label-action']['en-us'] = "Action";
$text['label-action']['en-gb'] = "Action";
$text['label-action']['ar-eg'] = "";
$text['label-action']['de-at'] = "Aktion"; //copied from de-de
$text['label-action']['de-ch'] = "Aktion"; //copied from de-de
$text['label-action']['de-de'] = "Aktion";
$text['label-action']['el-gr'] = "Ενέργεια";
$text['label-action']['es-cl'] = "Acción";
$text['label-action']['es-mx'] = "Acción"; //copied from es-cl
$text['label-action']['fr-ca'] = "Action"; //copied from fr-fr
$text['label-action']['fr-fr'] = "Action";
$text['label-action']['he-il'] = "פעולה";
$text['label-action']['it-it'] = "Azione";
$text['label-action']['nl-nl'] = "Actie";
$text['label-action']['pl-pl'] = "Operacja";
$text['label-action']['pt-br'] = "Ação";
$text['label-action']['pt-pt'] = "Acção";
$text['label-action']['ro-ro'] = "Acțiune";
$text['label-action']['ru-ru'] = "Действие";
$text['label-action']['sv-se'] = "Åtgärd";
$text['label-action']['uk-ua'] = "Дія";
$text['button-unban']['en-us'] = "Unban";
$text['button-unban']['en-gb'] = "Unban";
$text['button-unban']['ar-eg'] = "Unban";
$text['button-unban']['de-at'] = "Sperre aufheben";
$text['button-unban']['de-ch'] = "Sperre aufheben";
$text['button-unban']['de-de'] = "Sperre aufheben";
$text['button-unban']['el-gr'] = "Unban";
$text['button-unban']['es-cl'] = "Unban";
$text['button-unban']['es-mx'] = "Unban";
$text['button-unban']['fr-ca'] = "Unban";
$text['button-unban']['fr-fr'] = "Unban";
$text['button-unban']['he-il'] = "Unban";
$text['button-unban']['it-it'] = "Unban";
$text['button-unban']['nl-nl'] = "Unban";
$text['button-unban']['pl-pl'] = "Unban";
$text['button-unban']['pt-br'] = "Unban";
$text['button-unban']['pt-pt'] = "Unban";
$text['button-unban']['ro-ro'] = "Unban";
$text['button-unban']['ru-ru'] = "Unban";
$text['button-unban']['sv-se'] = "Unban";
$text['button-unban']['uk-ua'] = "Unban";
$text['button-ban']['en-us'] = "Ban";
$text['button-ban']['en-gb'] = "Ban";
$text['button-ban']['ar-eg'] = "Ban";
$text['button-ban']['de-at'] = "Sperre einrichten";
$text['button-ban']['de-ch'] = "Sperre einrichten";
$text['button-ban']['de-de'] = "Sperre einrichten";
$text['button-ban']['el-gr'] = "Ban";
$text['button-ban']['es-cl'] = "Ban";
$text['button-ban']['es-mx'] = "Ban";
$text['button-ban']['fr-ca'] = "Ban";
$text['button-ban']['fr-fr'] = "Ban";
$text['button-ban']['he-il'] = "Ban";
$text['button-ban']['it-it'] = "Ban";
$text['button-ban']['nl-nl'] = "Ban";
$text['button-ban']['pl-pl'] = "Ban";
$text['button-ban']['pt-br'] = "Ban";
$text['button-ban']['pt-pt'] = "Ban";
$text['button-ban']['ro-ro'] = "Ban";
$text['button-ban']['ru-ru'] = "Ban";
$text['button-ban']['sv-se'] = "Ban";
$text['button-ban']['uk-ua'] = "Ban";
?>
<?php
$y=0;
$apps[$x]['menu'][$y]['title']['en-us'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['en-gb'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['ar-eg'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['de-at'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['de-ch'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['de-de'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['es-cl'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['es-mx'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['fr-ca'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['fr-fr'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['he-il'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['it-it'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['nl-nl'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['pl-pl'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['pt-br'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['pt-pt'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['ro-ro'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['ru-ru'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['sv-se'] = "Fail2ban";
$apps[$x]['menu'][$y]['title']['uk-ua'] = "Fail2ban";
$apps[$x]['menu'][$y]['uuid'] = "9cda5dab-a584-4ff5-a4e4-6d95d52d92dc";
$apps[$x]['menu'][$y]['parent_uuid'] = "594d99c5-6128-9c88-ca35-4b33392cec0f";
$apps[$x]['menu'][$y]['category'] = "internal";
$apps[$x]['menu'][$y]['path'] = "/app/fail2ban/fail2ban.php";
$apps[$x]['menu'][$y]['groups'][] = "admin";
$apps[$x]['menu'][$y]['groups'][] = "superadmin";
?>
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2019
the Initial Developer. All Rights Reserved.
The code has been adapted to control fail2ban by Benedikt Wildenhain.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
James Rose <james.o.rose@gmail.com>
Benedikt Wildenhain <benedikt.wildenhain@hs-bochum.de> (C) 2020
*/
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/engine.inc.php";
//check permissions
if (permission_exists('fail2ban_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//get session data
if ($_SESSION['fail2ban-jails']) {
$jails = $_SESSION['fail2ban-jails'];
if (permission_exists('fail2ban_unban') && $_POST['action'] == 'delete' && $_POST['target'] != '') {
$target = explode(':', $_POST['target']);
if (count($target) == 2) {
$target_jail = $target[0];
$target_entry = $target[1];
if (array_key_exists($target_jail, $jails)) {
unban_ip($target_jail, $jails[$target_jail][$target_entry]);
}
}
} elseif (permission_exists('fail2ban_ban')&& $_POST['action'] == 'add' && $_POST['ip'] != '') {
$target_jail = $_POST['jail'];
$ip = $_POST['ip'];
if (array_key_exists($target_jail, $jails)) {
ban_ip($target_jail, $ip);
sleep (1); # sometimes won't appear in list_banned without this
}
}
}
//includes and title
$document['title'] = $text['title-fail2ban'];
require_once "resources/header.php";
//show the content
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-fail2ban']."</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'collapse'=>'hide-xs','style'=>'margin-left: 15px;','link'=>'fail2ban.php']);
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "Dieses Modul ist aktuell noch in Entwicklung<br />";
$socket_check = check_socket();
if ($socket_check != 'OK') {
$msg = "<div align='center'>".$text['message-connection']."<br />$socket_check</div>";
echo "<div align='center'>\n";
echo "<table width='40%'>\n";
echo "<tr>\n";
echo "<th align='left'>".$text['label-message']."</th>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='row_style1'><strong>$msg</strong></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
} else {
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value='delete'>\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
echo "<th>".$text['label-jail']."</th>\n";
echo "<th>".$text['label-ip-address']."</th>\n";
if (permission_exists('fail2ban_unban'))
echo "<th>".$text['label-action']."</th>\n";
echo "</tr>\n";
$jails=list_jails();
$_SESSION["fail2ban-jails"]=array();
foreach($jails as $j=>$i){ $banned=list_banned($j); $jails[$j]=$banned; }
foreach ($jails as $key => $value) {
$_SESSION["fail2ban-jails"][$key]=array();
$i=0;
foreach ($value as $banned) {
$_SESSION["fail2ban-jails"][$key][$i]=strval(explode(' ', $banned)[0]);
echo "<tr>\n";
echo "<td>$key</td>\n";
echo "<td>$banned</td>\n";
if (permission_exists('fail2ban_unban')) {
echo "<td>";
echo button::create(['type'=>'submit','label'=>$text['button-unban'],'icon'=>$_SESSION['theme']['button_icon_delete'],'collapse'=>'hide-xs','style'=>'margin-right: 15px;', 'name'=>'target', 'value'=>"$key:$i"]);
echo "</td>\n";
}
echo "</tr>\n";
$i++;
}
}
echo "</form>\n";
if (permission_exists('fail2ban_ban')) {
echo "<tr>\n";
echo "<form id='form_ban' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value='add'>\n";
echo "<td>\n";
#echo "<input type='hidden' id='action' name='action' value='ban'>\n";
echo " <select class='formfld' name='jail'>\n";
foreach ($jails as $key => $value) {
echo " <option value='$key'>".$key."</option>\n";
}
echo " </select>\n";
echo "</td>\n";
echo "<td>\n";
echo " <input class='formfld' name='ip'>\n";
echo "</td>\n";
echo "<td>\n";
echo button::create(['type'=>'submit','label'=>$text['button-ban'],'icon'=>$_SESSION['theme']['button_icon_add'],'collapse'=>'hide-xs','style'=>'margin-right: 15px;', 'name'=>'ban']);
echo "</td>\n";
echo "</form>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
//include the footer
require_once "resources/footer.php";
?>
<?php
# Fail2Ban Webinterface (f2bwi)
# Monitoring fail2ban and manually ban / release IP's
# (c) 2017 CC-BY-SA 3.0 Steffen Ille <steffen@php-works.net>
#####################
# FAIL2BAN SETTINGS #
#####################
$f2b['socket']='/var/run/fail2ban/fail2ban.sock'; # path to the Fail2Ban socket file
$f2b['usedns']=true; # show hostnames per banned IP [true|false]
$f2b['noempt']=true; # do not show jails without banned clients [true|false]
$f2b['jainfo']=true; # show jail information in table headers [true|false]
######################
# DO NOT EDIT PLEASE #
######################
$f2b['version']='0.1a (2017-07)';
?>
\ No newline at end of file
<?php
# Fail2Ban Webinterface (f2bwi)
# Monitoring fail2ban and manually ban / release IP's
# (c) 2017 CC-BY-SA 3.0 Steffen Ille <steffen@php-works.net>
# (c) 2020 CC-BY-SA 3.0 or MPL1.1 Benedikt Wildenhain <benedikt.wildenhain@hs-bochum.de>
require_once('config.inc.php');
function check_socket()
{ global $f2b;
if(!file_exists($f2b['socket'])){ return 'Socket file not found.'; }
#elseif(!is_readable($f2b['socket'])){ return 'Socket file not readable.'; }
elseif(!is_writeable($f2b['socket'])){ return 'Socket file not writeable.'; }
return 'OK';
}
function list_jails()
{ global $f2b; $jails=array();
$erg=@exec('fail2ban-client status | grep "Jail list:" | awk -F ":" \'{print $2}\' | awk \'{$1=$1;print}\'');
$erg=explode(",",$erg);
foreach($erg as $i=>$j){ $jails[trim($j)]=false; }
ksort($jails); return $jails;
}
function jail_info($jail)
{ global $f2b; $info=array();
$erg=@exec('fail2ban-client get '.escapeshellarg($jail).' findtime ');
if(is_numeric($erg)){ $info['findtime']='findtime: '.$erg; }
$erg=@exec('fail2ban-client get '.escapeshellarg($jail).' bantime ');
if(is_numeric($erg)){ $info['bantime']='bantime: '.$erg; }
$erg=@exec('fail2ban-client get '.escapeshellarg($jail).' maxretry ');
if(is_numeric($erg)){ $info['maxretry']='maxretry: '.$erg; }
return $info;
}
function list_banned($jail)
{ global $f2b; $banned=array();
$erg=@exec('fail2ban-client status '.$jail.' | grep "IP list:" | cut -d: -f2- | awk \'{$1=$1;print}\'');
if($erg!='')
{ $banned=explode(" ",$erg);
if($f2b['usedns']===true)
{ foreach($banned as $i=>$cli)
{ $dns=gethostbyaddr($cli);
if($dns==$cli){ $dns=' (unknown)'; } else { $dns=' ('.$dns.')'; }
$banned[$i].=$dns;
}
} return $banned;
}
return false;
}
function ban_ip($jail,$ip)
{ if($jail==''){ return 'no jail selected'; }
elseif(!filter_var($ip,FILTER_VALIDATE_IP)) { return 'no valid ip address'; }
$jails = list_jails();
if(!array_key_exists($jail, $jails)) { return 'invalid jail'; }
$erg=@exec('fail2ban-client set '.escapeshellarg($jail).' banip '.escapeshellarg($ip));
if($erg!=$ip){ return 'could not ban this ip'; }
return 'OK';
}
function unban_ip($jail,$ip)
{ if($jail==''){ return 'no jail selected'; }
elseif(!filter_var($ip,FILTER_VALIDATE_IP)) { return 'no valid ip address'; }
$jails = list_jails();
if(!array_key_exists($jail, $jails)) { return 'invalid jail'; }
$erg=@exec('fail2ban-client set '.escapeshellarg($jail).' unbanip '.escapeshellarg($ip));
if($erg!=$ip){ return 'could not unban this ip'; }
return 'OK';
}
?>
root.php 0 → 100644
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
// make sure the PATH_SEPARATOR is defined
umask(2);
if (!defined("PATH_SEPARATOR")) {
if (strpos($_ENV["OS"], "Win") !== false) {
define("PATH_SEPARATOR", ";");
} else {
define("PATH_SEPARATOR", ":");
}
}
if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html';
// make sure the document_root is set
$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]);
if(PHP_SAPI == 'cli'){
chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME));
$script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]);
$dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME));
if (file_exists('/project_root.php')) {
$path = '/';
} else {
$i = 1;
$path = '';
while ($i < count($dirs)) {
$path .= '/' . $dirs[$i];
if (file_exists($path. '/project_root.php')) {
break;
}
$i++;
}
}
$_SERVER["DOCUMENT_ROOT"] = $path;
}else{
$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
}
$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
// try to detect if a project path is being used
if (!defined('PROJECT_PATH')) {
if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) {
define('PROJECT_PATH', '/fusionpbx');
} elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) {
define('PROJECT_PATH', '');
} else {
$dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME)));
$i = 1;
$path = $_SERVER["DOCUMENT_ROOT"];
while ($i < count($dirs)) {
$path .= '/' . $dirs[$i];
if (file_exists($path. '/project_root.php')) {
break;
}
$i++;
}
if(!file_exists($path. '/project_root.php')){
die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance");
}
$project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path);
define('PROJECT_PATH', $project_path);
}
$_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH);
set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]);
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment