Commit 5da3a0c3693fd3bb55816a59eeed3d192d3065c1
1 parent
9626ebc3
StoryId 778896:Updated Utility Class
Committed by: Jarrett Jordaan Reviewed by: Megan Watson
Showing
4 changed files
with
161 additions
and
10 deletions
control.php
| @@ -36,9 +36,18 @@ | @@ -36,9 +36,18 @@ | ||
| 36 | * | 36 | * |
| 37 | */ | 37 | */ |
| 38 | 38 | ||
| 39 | +// | ||
| 40 | +require_once("setup/wizard/install_util.php"); | ||
| 41 | +// Check if system has been installed | ||
| 42 | +$iu = new InstallUtil(); | ||
| 43 | +if(!$iu->isSystemInstalled()) { | ||
| 44 | + $iu->redirect("setup/wizard"); | ||
| 45 | + exit(0); | ||
| 46 | +} | ||
| 47 | + | ||
| 39 | // main library routines and defaults | 48 | // main library routines and defaults |
| 40 | require_once('config/dmsDefaults.php'); | 49 | require_once('config/dmsDefaults.php'); |
| 41 | -require_once("setup/wizard/install_util.php"); | 50 | + |
| 42 | /** | 51 | /** |
| 43 | * Controller page -- controls the web application by responding to a set of | 52 | * Controller page -- controls the web application by responding to a set of |
| 44 | * defined actions. The controller performs session handling, page-level | 53 | * defined actions. The controller performs session handling, page-level |
| @@ -49,12 +58,6 @@ require_once("setup/wizard/install_util.php"); | @@ -49,12 +58,6 @@ require_once("setup/wizard/install_util.php"); | ||
| 49 | // ------------------------------- | 58 | // ------------------------------- |
| 50 | // page start | 59 | // page start |
| 51 | // ------------------------------- | 60 | // ------------------------------- |
| 52 | -// Check if system has been installed | ||
| 53 | -$iu = new InstallUtil(); | ||
| 54 | -if(!$iu->isSystemInstalled()) { | ||
| 55 | - redirect("setup/wizard"); | ||
| 56 | - exit(0); | ||
| 57 | -} | ||
| 58 | 61 | ||
| 59 | $action = $_REQUEST['action']; | 62 | $action = $_REQUEST['action']; |
| 60 | 63 |
setup/wizard/index.php
| @@ -41,7 +41,19 @@ | @@ -41,7 +41,19 @@ | ||
| 41 | */ | 41 | */ |
| 42 | require_once("install_util.php"); | 42 | require_once("install_util.php"); |
| 43 | $ui = new InstallUtil(); | 43 | $ui = new InstallUtil(); |
| 44 | - if(!$ui->isSystemInstalled()) { | 44 | + $bypass = false; |
| 45 | + // Bypass | ||
| 46 | +// if(isset($_GET['bypass'])) { | ||
| 47 | +// $bypass = $_GET['bypass']; | ||
| 48 | +// $_SESSION['bypass'] = $bypass; | ||
| 49 | +// } | ||
| 50 | + | ||
| 51 | +// if(isset($_SESSION['bypass'])) { | ||
| 52 | +// | ||
| 53 | +// $bypass = $_SESSION['bypass']; | ||
| 54 | +// } | ||
| 55 | + | ||
| 56 | + if(!$ui->isSystemInstalled() || $bypass) { | ||
| 45 | require("installer.php"); | 57 | require("installer.php"); |
| 46 | } else { | 58 | } else { |
| 47 | echo "System has been installed <a href='../../'>Goto Login</a>"; | 59 | echo "System has been installed <a href='../../'>Goto Login</a>"; |
setup/wizard/install_util.php
| @@ -13,5 +13,133 @@ class InstallUtil { | @@ -13,5 +13,133 @@ class InstallUtil { | ||
| 13 | 13 | ||
| 14 | return true; | 14 | return true; |
| 15 | } | 15 | } |
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * Redirect | ||
| 19 | + * | ||
| 20 | + * This function redirects the client. This is done by issuing | ||
| 21 | + * a "Location" header and exiting if wanted. If you set $rfc2616 to true | ||
| 22 | + * HTTP will output a hypertext note with the location of the redirect. | ||
| 23 | + * | ||
| 24 | + * @static | ||
| 25 | + * @access public | ||
| 26 | + * @return mixed Returns true on succes (or exits) or false if headers | ||
| 27 | + * have already been sent. | ||
| 28 | + * @param string $url URL where the redirect should go to. | ||
| 29 | + * @param bool $exit Whether to exit immediately after redirection. | ||
| 30 | + * @param bool $rfc2616 Wheter to output a hypertext note where we're | ||
| 31 | + * redirecting to (Redirecting to <a href="...">...</a>.) | ||
| 32 | + */ | ||
| 33 | + function redirect($url, $exit = true, $rfc2616 = false) | ||
| 34 | + { | ||
| 35 | + if (headers_sent()) { | ||
| 36 | + return false; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + $url = $this->absoluteURI($url); | ||
| 40 | + header('Location: '. $url); | ||
| 41 | + | ||
| 42 | + if ( $rfc2616 && isset($_SERVER['REQUEST_METHOD']) && | ||
| 43 | + $_SERVER['REQUEST_METHOD'] != 'HEAD') { | ||
| 44 | + printf('Redirecting to: <a href="%s">%s</a>.', $url, $url); | ||
| 45 | + } | ||
| 46 | + if ($exit) { | ||
| 47 | + exit; | ||
| 48 | + } | ||
| 49 | + return true; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Absolute URI | ||
| 54 | + * | ||
| 55 | + * This function returns the absolute URI for the partial URL passed. | ||
| 56 | + * The current scheme (HTTP/HTTPS), host server, port, current script | ||
| 57 | + * location are used if necessary to resolve any relative URLs. | ||
| 58 | + * | ||
| 59 | + * Offsets potentially created by PATH_INFO are taken care of to resolve | ||
| 60 | + * relative URLs to the current script. | ||
| 61 | + * | ||
| 62 | + * You can choose a new protocol while resolving the URI. This is | ||
| 63 | + * particularly useful when redirecting a web browser using relative URIs | ||
| 64 | + * and to switch from HTTP to HTTPS, or vice-versa, at the same time. | ||
| 65 | + * | ||
| 66 | + * @author Philippe Jausions <Philippe.Jausions@11abacus.com> | ||
| 67 | + * @static | ||
| 68 | + * @access public | ||
| 69 | + * @return string The absolute URI. | ||
| 70 | + * @param string $url Absolute or relative URI the redirect should go to. | ||
| 71 | + * @param string $protocol Protocol to use when redirecting URIs. | ||
| 72 | + * @param integer $port A new port number. | ||
| 73 | + */ | ||
| 74 | + function absoluteURI($url = null, $protocol = null, $port = null) | ||
| 75 | + { | ||
| 76 | + // filter CR/LF | ||
| 77 | + $url = str_replace(array("\r", "\n"), ' ', $url); | ||
| 78 | + | ||
| 79 | + // Mess around with already absolute URIs | ||
| 80 | + if (preg_match('!^([a-z0-9]+)://!i', $url)) { | ||
| 81 | + if (empty($protocol) && empty($port)) { | ||
| 82 | + return $url; | ||
| 83 | + } | ||
| 84 | + if (!empty($protocol)) { | ||
| 85 | + $url = $protocol .':'. end($array = explode(':', $url, 2)); | ||
| 86 | + } | ||
| 87 | + if (!empty($port)) { | ||
| 88 | + $url = preg_replace('!^(([a-z0-9]+)://[^/:]+)(:[\d]+)?!i', | ||
| 89 | + '\1:'. $port, $url); | ||
| 90 | + } | ||
| 91 | + return $url; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + $host = 'localhost'; | ||
| 95 | + if (!empty($_SERVER['HTTP_HOST'])) { | ||
| 96 | + list($host) = explode(':', $_SERVER['HTTP_HOST']); | ||
| 97 | + } elseif (!empty($_SERVER['SERVER_NAME'])) { | ||
| 98 | + list($host) = explode(':', $_SERVER['SERVER_NAME']); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + if (empty($protocol)) { | ||
| 102 | + if (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'], 'on')) { | ||
| 103 | + $protocol = 'https'; | ||
| 104 | + } else { | ||
| 105 | + $protocol = 'http'; | ||
| 106 | + } | ||
| 107 | + if (!isset($port) || $port != intval($port)) { | ||
| 108 | + $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80; | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + if ($protocol == 'http' && $port == 80) { | ||
| 113 | + unset($port); | ||
| 114 | + } | ||
| 115 | + if ($protocol == 'https' && $port == 443) { | ||
| 116 | + unset($port); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + $server = $protocol .'://'. $host . (isset($port) ? ':'. $port : ''); | ||
| 120 | + | ||
| 121 | + if (!strlen($url)) { | ||
| 122 | + $url = isset($_SERVER['REQUEST_URI']) ? | ||
| 123 | + $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + if ($url{0} == '/') { | ||
| 127 | + return $server . $url; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + // Check for PATH_INFO | ||
| 131 | + if (isset($_SERVER['PATH_INFO']) && strlen($_SERVER['PATH_INFO']) && | ||
| 132 | + $_SERVER['PHP_SELF'] != $_SERVER['PATH_INFO']) { | ||
| 133 | + $path = dirname(substr($_SERVER['PHP_SELF'], 0, -strlen($_SERVER['PATH_INFO']))); | ||
| 134 | + } else { | ||
| 135 | + $path = dirname($_SERVER['PHP_SELF']); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + if (substr($path = strtr($path, '\\', '/'), -1) != '/') { | ||
| 139 | + $path .= '/'; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + return $server . $path . $url; | ||
| 143 | + } | ||
| 16 | } | 144 | } |
| 17 | ?> | 145 | ?> |
| 18 | \ No newline at end of file | 146 | \ No newline at end of file |
setup/wizard/installer.php
| @@ -129,6 +129,13 @@ class Installer { | @@ -129,6 +129,13 @@ class Installer { | ||
| 129 | $this->session = $session; | 129 | $this->session = $session; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | + public function setSessionVars() { | ||
| 133 | + if(isset($_GET['bypass'])) { | ||
| 134 | + $bypass = $_GET['bypass']; | ||
| 135 | + $this->session->set('bypass', $bypass); | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + | ||
| 132 | /** | 139 | /** |
| 133 | * Main control to handle the flow of install | 140 | * Main control to handle the flow of install |
| 134 | * | 141 | * |
| @@ -140,7 +147,8 @@ class Installer { | @@ -140,7 +147,8 @@ class Installer { | ||
| 140 | public function step() { | 147 | public function step() { |
| 141 | $this->readXml(); // Xml steps | 148 | $this->readXml(); // Xml steps |
| 142 | $this->xmlStepsToArray(); // String steps | 149 | $this->xmlStepsToArray(); // String steps |
| 143 | - $this->resetSessions(); // Make sure | 150 | + $this->resetSessions(); // Make sure |
| 151 | + $this->setSessionVars(); | ||
| 144 | $response = $this->landing(); | 152 | $response = $this->landing(); |
| 145 | switch($response) { | 153 | switch($response) { |
| 146 | case 'next': | 154 | case 'next': |
| @@ -494,5 +502,5 @@ class Installer { | @@ -494,5 +502,5 @@ class Installer { | ||
| 494 | } | 502 | } |
| 495 | $ins = new installer(new Session()); // Instantiate the installer | 503 | $ins = new installer(new Session()); // Instantiate the installer |
| 496 | $ins->step(); // Run step | 504 | $ins->step(); // Run step |
| 497 | -//$ins->showSession(); | 505 | +$ins->showSession(); |
| 498 | ?> | 506 | ?> |
| 499 | \ No newline at end of file | 507 | \ No newline at end of file |