mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 01:24:38 +00:00
wizard: use fixup spare parts to construct required functionality
This commit is contained in:
parent
540f537a2e
commit
4f3239c7b3
@ -210,6 +210,55 @@ function update_config_field($field, $updatetext, $unset, $arraynum, $field_type
|
||||
eval($text);
|
||||
}
|
||||
|
||||
function redirect_url()
|
||||
{
|
||||
global $config, $title;
|
||||
|
||||
switch($config['system']['webgui']['protocol']) {
|
||||
case "http":
|
||||
$proto = "http";
|
||||
break;
|
||||
case "https":
|
||||
$proto = "https";
|
||||
break;
|
||||
default:
|
||||
$proto = "http";
|
||||
break;
|
||||
}
|
||||
$port = $config['system']['webgui']['port'];
|
||||
if($port != "") {
|
||||
if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
|
||||
$urlport = ":" . $port;
|
||||
} elseif ($port != "80" and $port != "443") {
|
||||
$urlport = ":" . $port;
|
||||
} else {
|
||||
$urlport = "";
|
||||
}
|
||||
}
|
||||
$http_host = $_SERVER['SERVER_NAME'];
|
||||
$urlhost = $http_host;
|
||||
// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
|
||||
if($title == "Reload in progress") {
|
||||
if (is_ipaddr($urlhost)) {
|
||||
$host_if = find_ip_interface($urlhost);
|
||||
if ($host_if) {
|
||||
$host_if = convert_real_interface_to_friendly_interface_name($host_if);
|
||||
if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr']))
|
||||
$urlhost = $config['interfaces'][$host_if]['ipaddr'];
|
||||
}
|
||||
} else if ($urlhost == $config['system']['hostname']) {
|
||||
$urlhost = $config['wizardtemp']['system']['hostname'];
|
||||
} else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain']) {
|
||||
$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
|
||||
}
|
||||
}
|
||||
if ($urlhost != $http_host) {
|
||||
file_put_contents('/tmp/setupwizard_lastreferrer', $proto . '://' . $http_host . $urlport . $_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
return $proto . '://' . $urlhost . $urlport;
|
||||
}
|
||||
|
||||
// handle before form display event.
|
||||
do {
|
||||
$oldstepid = $stepid;
|
||||
@ -411,7 +460,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>\n";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -441,7 +490,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>\n";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -465,7 +514,7 @@ function showchange() {
|
||||
$multiple = "";
|
||||
$name = strtolower($name);
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n";
|
||||
echo ($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n";
|
||||
echo "</td>";
|
||||
echo "<td class=\"vtable\">\n";
|
||||
if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
|
||||
@ -516,7 +565,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>\n";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -536,7 +585,7 @@ function showchange() {
|
||||
$multiple = "";
|
||||
$name = strtolower($name);
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n";
|
||||
echo ($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n";
|
||||
echo "</td>";
|
||||
echo "<td class=\"vtable\">\n";
|
||||
if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
|
||||
@ -574,7 +623,7 @@ function showchange() {
|
||||
$multiple = "";
|
||||
$name = strtolower($name);
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n";
|
||||
echo ($field['displayname'] ? gettext($field['displayname']) : gettext($field['name'])) . ":\n";
|
||||
echo "</td>";
|
||||
echo "<td class=\"vtable\">\n";
|
||||
if($field['size'] <> "") $size = "size=\"{$field['size']}\"";
|
||||
@ -616,7 +665,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>\n";
|
||||
}
|
||||
if($field['size']) $size = " size='" . $field['size'] . "' ";
|
||||
@ -656,7 +705,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -694,7 +743,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -730,7 +779,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -759,7 +808,7 @@ function showchange() {
|
||||
echo ":</td>\n";
|
||||
} else if(!$field['dontdisplayname']) {
|
||||
echo "<td width=\"22%\" align=\"right\" class=\"vncellreq\">\n";
|
||||
echo fixup_string(gettext($field['name']));
|
||||
echo gettext($field['name']);
|
||||
echo ":</td>";
|
||||
}
|
||||
if(!$field['dontcombinecells'])
|
||||
@ -833,7 +882,7 @@ function showchange() {
|
||||
switch ($field['type']) {
|
||||
case "refresh":
|
||||
if($field['page'] <> "" && $field['time'] <> "") {
|
||||
echo '<meta http-equiv="refresh" content="' . $field['time'] . ';url=' . fixup_string('$myurl') . $field['page'] . '">';
|
||||
echo '<meta http-equiv="refresh" content="' . $field['time'] . ';url=' . redirect_url() . '/' . $field['page'] . '">';
|
||||
}
|
||||
break 2;
|
||||
}
|
||||
@ -975,71 +1024,4 @@ if($pkg['step'][$stepid]['javascriptafterformdisplay'] <> "") {
|
||||
echo "</script>\n\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* HELPER FUNCTIONS
|
||||
*/
|
||||
|
||||
function fixup_string($string)
|
||||
{
|
||||
global $config, $myurl, $title;
|
||||
$newstring = $string;
|
||||
// fixup #1: $myurl -> http[s]://ip_address:port/
|
||||
switch($config['system']['webgui']['protocol']) {
|
||||
case "http":
|
||||
$proto = "http";
|
||||
break;
|
||||
case "https":
|
||||
$proto = "https";
|
||||
break;
|
||||
default:
|
||||
$proto = "http";
|
||||
break;
|
||||
}
|
||||
$port = $config['system']['webgui']['port'];
|
||||
if($port != "") {
|
||||
if(($port == "443" and $proto != "https") or ($port == "80" and $proto != "http")) {
|
||||
$urlport = ":" . $port;
|
||||
} elseif ($port != "80" and $port != "443") {
|
||||
$urlport = ":" . $port;
|
||||
} else {
|
||||
$urlport = "";
|
||||
}
|
||||
}
|
||||
$http_host = $_SERVER['SERVER_NAME'];
|
||||
$urlhost = $http_host;
|
||||
// If finishing the setup wizard, check if accessing on a LAN or WAN address that changed
|
||||
if($title == "Reload in progress") {
|
||||
if (is_ipaddr($urlhost)) {
|
||||
$host_if = find_ip_interface($urlhost);
|
||||
if ($host_if) {
|
||||
$host_if = convert_real_interface_to_friendly_interface_name($host_if);
|
||||
if ($host_if && is_ipaddr($config['interfaces'][$host_if]['ipaddr']))
|
||||
$urlhost = $config['interfaces'][$host_if]['ipaddr'];
|
||||
}
|
||||
} else if ($urlhost == $config['system']['hostname'])
|
||||
$urlhost = $config['wizardtemp']['system']['hostname'];
|
||||
else if ($urlhost == $config['system']['hostname'] . '.' . $config['system']['domain'])
|
||||
$urlhost = $config['wizardtemp']['system']['hostname'] . '.' . $config['wizardtemp']['system']['domain'];
|
||||
}
|
||||
if ($urlhost != $http_host) {
|
||||
file_put_contents('/tmp/setupwizard_lastreferrer', $proto . '://' . $http_host . $urlport . $_SERVER['REQUEST_URI']);
|
||||
}
|
||||
$myurl = $proto . "://" . $urlhost . $urlport . "/";
|
||||
|
||||
if (strstr($newstring, "\$myurl"))
|
||||
$newstring = str_replace("\$myurl", $myurl, $newstring);
|
||||
// fixup #2: $wanip
|
||||
if (strstr($newstring, "\$wanip")) {
|
||||
$curwanip = get_interface_ip();
|
||||
$newstring = str_replace("\$wanip", $curwanip, $newstring);
|
||||
}
|
||||
// fixup #3: $lanip
|
||||
if (strstr($newstring, "\$lanip")) {
|
||||
$lanip = get_interface_ip("lan");
|
||||
$newstring = str_replace("\$lanip", $lanip, $newstring);
|
||||
}
|
||||
// fixup #4: fix'r'up here.
|
||||
return $newstring;
|
||||
}
|
||||
|
||||
include('foot.inc');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user