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

Merge branch 'add-docker' into 'master'

fix loop over config with missing regex section.

See merge request !2
parents 5ce8099f 68d15ec1
Branches
No related tags found
1 merge request!2fix loop over config with missing regex section.
......@@ -3,6 +3,7 @@ body{background: #f8f8f8; color: #234; font-family: arial; margin: 0;}
h1{background:rgba(0,0,0,0.05); margin: 0 0 1em;; padding: 0.5em;}
h1 a{color:#234; text-decoration: none;}
h2{background: #d0e0e8; color:#458; margin: 1em 0 0.5em; border-top: 2px solid #fff; border-left: 5px solid #fff; border-top-left-radius: 0.5em; padding: 0.5em; margin: 0 0 1em;}
h3{color:#ccc; font-size: 250%}
pre{background: rgba(0,0,0,0.02);padding: 0.3em 1em; border: 1px solid rgba(0,0,0,0.1); margin: 2em 0 3em;; border-bottom: 2px solid rgba(0,0,0,0.2);}
......@@ -11,8 +12,8 @@ footer{background:rgba(0,0,0,0.03); margin-top: 4em; text-align: right;padding:
.content{margin: 0 1em;}
.legend{background: #fff; padding: 1em;}
.error{background: #fcc;}
.warning{color:#651; background:#fec;}
.error{background: #fcc; padding: 0.2em 1em;}
.warning{color:#651; background:#fec; padding: 0.2em 1em;}
.cfgtype-alias{color:#89a;}
.http-301::after{color:#a55; content: ' (Moved Permanently)'}
......
......@@ -17,6 +17,7 @@ require_once 'redirect.class.php';
* 2022-02-03 v1.5 ah add method isEnabled
* 2022-05-23 v1.6 ah add http head check+render output;
* 2022-05-31 v1.7 ah optical changes
* 2023-08-28 v1.8 ah remove php warning if there is no config yet
*/
/**
......@@ -149,21 +150,23 @@ class redirectadmin extends redirect {
}
}
$aAliases=$this->_getAliases();
foreach($aAliases as $sAlias=>$sConfig){
if(isset($aReturn[$sAlias])){
$aErrors[]="alias.json: A configuration for alias [$sAlias] is useless. There exists a file redirects_{$sAlias}.json (which has priority).";
} else {
if(!isset($aReturn[$sConfig])){
$aErrors[]="alias.json: [$sAlias] points to a non existing host [$sConfig] - a file redirects_$sConfig.yml does not exist.";
if(is_array($aAliases) && count($aAliases)){
foreach($aAliases as $sAlias=>$sConfig){
if(isset($aReturn[$sAlias])){
$aErrors[]="alias.json: A configuration for alias [$sAlias] is useless. There exists a file redirects_{$sAlias}.json (which has priority).";
} else {
$aReturn[$sConfig]['aliases'][]=$sAlias;
$aReturn[$sAlias]=array(
'type'=>'alias',
'target'=>$sConfig,
'ip'=> $this->_getIp($sAlias),
);
if (!$aReturn[$sAlias]['ip']){
$aErrors[]='alias.json: The hostname was not found in DNS: '.$sAlias;
if(!isset($aReturn[$sConfig])){
$aErrors[]="alias.json: [$sAlias] points to a non existing host [$sConfig] - a file redirects_$sConfig.yml does not exist.";
} else {
$aReturn[$sConfig]['aliases'][]=$sAlias;
$aReturn[$sAlias]=array(
'type'=>'alias',
'target'=>$sConfig,
'ip'=> $this->_getIp($sAlias),
);
if (!$aReturn[$sAlias]['ip']){
$aErrors[]='alias.json: The hostname was not found in DNS: '.$sAlias;
}
}
}
}
......
......@@ -23,6 +23,7 @@
* 2019-04-25 v1.2 ah use REQUEST_URI (works on Win and Linux)
* 2020-05-06 v1.3 ah added aliases for multiple domains with the same config
* 2020-05-06 v1.4 ah rewrite as class
* 2023-08-28 v1.5 ah fix loop over config with missing regex section.
*/
/**
......@@ -229,13 +230,14 @@ class redirect {
$aRedirect = $this->aConfig['direct'][$this->sRequest];
} else {
$this->_wd("no direct match ... scanning regex");
foreach (array_keys($this->aConfig['regex']) as $sRegex) {
$this->_wd("check if regex [$sRegex] matches $this->sRequest");
if (preg_match('#' . $sRegex . '#', $this->sRequest)) {
$this->_wd("REGEX MATCH! aborting tests");
$aRedirect = $this->aConfig['regex'][$sRegex];
break;
if(isset($this->aConfig['regex']) && is_array($this->aConfig['regex'])){
foreach (array_keys($this->aConfig['regex']) as $sRegex) {
$this->_wd("check if regex [$sRegex] matches $this->sRequest");
if (preg_match('#' . $sRegex . '#', $this->sRequest)) {
$this->_wd("REGEX MATCH! aborting tests");
$aRedirect = $this->aConfig['regex'][$sRegex];
break;
}
}
}
}
......
......@@ -8,3 +8,7 @@ Author: Axel Hahn; Institute for Medical Education; University of Bern
📄 Source: <https://git-repo.iml.unibe.ch/iml-open-source/redirect-handler> \
📜 License: GNU GPL 3.0 \
📖 Docs: <https://os-docs.iml.unibe.ch/redirect-handler/> or see the [docs](./docs)
- - -
![Admin ui](docs/images/admin_ui.png)
\ 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