Skip to content
Snippets Groups Projects
Commit 367c99c2 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add method isEnabled

parent 24b764cb
No related branches found
No related tags found
No related merge requests found
......@@ -13,57 +13,36 @@
* ----------------------------------------------------------------------
* admin: list all defined redirections
* ----------------------------------------------------------------------
* 2022-02-03 v0.1 <axel.hahn@iml.unibe.ch> initial version
* ----------------------------------------------------------------------
*/
require_once 'classes/redirect.admin.class.php';
$oR=new redirectadmin();
$sHtml='';
// ----------------------------------------------------------------------
// FUNCTIONS
// ----------------------------------------------------------------------
$oR=new redirectadmin();
function getId($sDomain){
return 'id_'.md5($sDomain);
}
$sHtml='';
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
if (!$oR->isEnabled()){
$sHtml.='<div class="error">Admin is disabled.</div>';
} else {
// ---------- GET CONFIG DATA
// echo '<pre>'.print_r($oR->getHosts(), 1).'</pre>';
/*
[aum-biss.iml.unibe.ch] => Array
(
[type] => alias
[target] => aum-biss.unibe.ch
[ip] => 130.92.30.62
)
...
[chirosurf.ch] => Array
(
[type] => config
[file] => /media/sf_htdocs/dev.links.iml.unibe.ch/public_html/classes/../../config/redirects_chirosurf.ch.json
[ip] => 130.92.30.62
[aliases] => Array
(
[0] => www.chirosurf.ch
)
[redirects] => Array
(
[direct] => Array
(
)
[regex] => Array
(
[.*] => Array
(
[code] => 307
[target] => https://chirosurf.elearning.aum.iml.unibe.ch
)
)
)
)
*/
$aHosts=$oR->getHosts();
// ---------- SHOW ERRORS
if(count($aHosts['_errors'])) {
$sHtml.= '<h2>Found errors</h2>'
.'<ol class="error">'
......@@ -73,9 +52,7 @@ if(count($aHosts['_errors'])) {
unset($aHosts['_errors']);
}
function getId($sDomain){
return 'id_'.md5($sDomain);
}
// ---------- LOOP OVER ALL ENTRIES
$sHtml.='<h2>Domains and their redirects</h2>'
.'<table class="mydatatable"><thead>
......@@ -114,6 +91,9 @@ foreach($aHosts as $sHost => $aCfg){
}
$sHtml.='</tbody></table>';
}
// ---------- OUTPUT
?><!doctype html>
<html>
......@@ -125,7 +105,7 @@ $sHtml.='</tbody></table>';
<style>
a{color:royalblue;}
body{background: #f8f8f8; color: #234;}
ol.error{background: #fcc;}
.error{background: #fcc;}
pre{background: rgba(0,0,0,0.05);padding: 0.3em; border: 1px solid rgba(0,0,0,0.1)}
.cfgtype-alias{color:#89a; }
.http-301::after{color:#a55; content: ' (Moved Permanently)'}
......
......@@ -15,6 +15,7 @@ require_once 'redirect.class.php';
* if the definition exists
* ----------------------------------------------------------------------
* 2020-05-11 v1.4 ah rewrite as class
* 2022-02-03 v1.5 ah add method isEnabled
*/
/**
......@@ -24,6 +25,11 @@ require_once 'redirect.class.php';
*/
class redirectadmin extends redirect {
public function isEnabled(){
$sFile2Enable=__DIR__ . '/'.basename(__FILE__).'_enabled.txt';
return file_exists($sFile2Enable);
}
public function getHosts(){
$aReturn = array();
$aErrors = array();
......
# redirect.admin.class.php_enabled.txt
By default this file does not exist.
It means: the redirect admin is disabled.
Rename the *dist file and remove the extension ".dist"
to enable the admin
\ 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