Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
(isset($rssPage) && $rssPage) ||
(isset($xmlPage) && $xmlPage);
$isMigrationGateExcluded =
(isset($_GET['m']) && $_GET['m'] === 'install' &&
isset($_GET['a']) && $_GET['a'] === 'maint') ||
(isset($_GET['m']) && ($_GET['m'] === 'login' || $_GET['m'] === 'logout'));

if ($_SESSION['CATS']->isLoggedIn() &&
Expand Down
31 changes: 25 additions & 6 deletions js/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
var response;
var maxSteps;
var installMaintNextAction = "a=reindexResumes";
var maintenanceOnly = false;


function setActiveStep(step)
Expand Down Expand Up @@ -120,13 +121,31 @@

response = http.responseText;

if (maintenanceOnly &&
(http.status < 200 ||
http.status >= 300 ||
AJAX_isPHPError(response) ||

Check notice on line 127 in js/install.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

js/install.js#L127

A function with a name starting with an uppercase letter should only be used as a constructor.
response.indexOf("<errorcode>-1</errorcode>") != -1 ||
response.indexOf("Query Error") != -1 ||
response.indexOf("Access denied.") != -1))
{
document.getElementById("maintenanceProgress").style.display = "none";
document.getElementById("maintenanceError").style.display = "";
document.getElementById("startMaintenance").disabled = false;
return;
}

if (response.indexOf("setProgressUpdating") == -1)
{
if (http.status == 200)
{
Installpage_populate(installMaintNextAction);
installMaintNextAction = "a=reindexResumes";
}
{
if (maintenanceOnly)
{
window.location = "index.php";
}
else if (http.status == 200)
{
Installpage_populate(installMaintNextAction);
installMaintNextAction = "a=reindexResumes";
}
}
else
{
Expand Down
14 changes: 13 additions & 1 deletion lib/ModuleUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* @package CATS
* @subpackage Library
*/
include_once(LEGACY_ROOT . '/lib/SchemaMigrationStatus.php');

class ModuleUtility
{
/* Prevent this class from being instantiated. */
Expand Down Expand Up @@ -508,7 +510,11 @@

if ($moduleName === 'install' && ($currentVersion === NULL || $currentVersion === ''))
{
/* A NULL install module version means the database came from cats_schema.sql and should not replay historical install migrations. */
/* This explicit installer/maintenance finalization is only for
* snapshot databases whose schema already matches the bundled
* baseline. It must not run during normal requests and is not
* proof that an unknown historical database state is current.
*/
$sql = sprintf(
"UPDATE
module_schema
Expand All @@ -521,6 +527,7 @@
);
$db->query($sql);

SchemaMigrationStatus::clearCache();

Check warning on line 530 in lib/ModuleUtility.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/ModuleUtility.php#L530

Avoid using static access to class 'SchemaMigrationStatus' in method 'processModuleSchema'.
return;
}

Expand Down Expand Up @@ -592,6 +599,11 @@
$rs = $db->query($sql);

$currentVersion = $version;

if ($moduleName === 'install')
{
SchemaMigrationStatus::clearCache();
}
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions modules/install/CATSUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@

public function handleRequest()
{
if ($this->getAction() !== 'maint')
{
return;
}

if (!isset($_SESSION['CATS']) || !$_SESSION['CATS']->isLoggedIn())
{
CATSUtility::transferRelativeURI('m=login');

Check warning on line 51 in modules/install/CATSUI.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/install/CATSUI.php#L51

Avoid using static access to class 'CATSUtility' in method 'handleRequest'.
die();

Check warning on line 52 in modules/install/CATSUI.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/install/CATSUI.php#L52

The method handleRequest() contains an exit expression.
}

if ($_SESSION['CATS']->getAccessLevel(ACL::SECOBJ_ROOT) < ACCESS_LEVEL_SA)
{
header('HTTP/1.1 403 Forbidden');
CommonErrors::fatal(COMMONERROR_PERMISSION, $this);

Check warning on line 58 in modules/install/CATSUI.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/install/CATSUI.php#L58

Avoid using static access to class 'CommonErrors' in method 'handleRequest'.
}

if (!SchemaMigrationStatus::hasPendingInstallMigrations())

Check warning on line 61 in modules/install/CATSUI.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/install/CATSUI.php#L61

Avoid using static access to class 'SchemaMigrationStatus' in method 'handleRequest'.
{
CATSUtility::transferRelativeURI('');

Check warning on line 63 in modules/install/CATSUI.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/install/CATSUI.php#L63

Avoid using static access to class 'CATSUtility' in method 'handleRequest'.
die();
}

$this->_template->assign(
'csrfToken',
$_SESSION['CATS']->getCSRFToken()
);
$this->_template->display('./modules/install/Maintenance.tpl');
}
}

Expand Down
45 changes: 45 additions & 0 deletions modules/install/Maintenance.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php /* Installed-system database maintenance. */ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>OpenCATS - Database Maintenance</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo(HTML_ENCODING); ?>" />
<script type="text/javascript">CATSCsrfToken = <?php echo Template::escapeJs($this->csrfToken); ?>;</script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/lib.js'); ?>"></script>
<script type="text/javascript" src="<?php echo TemplateUtility::getVersionedAssetURL('js/install.js'); ?>"></script>
<style type="text/css" media="all">@import "<?php echo TemplateUtility::getVersionedAssetURL('modules/install/install.css'); ?>";</style>
</head>

<body>
<div id="headerBlock">
<span id="mainLogo">OpenCATS</span><br />
<span id="subMainLogo">Applicant Tracking System</span>
</div>

<div id="contents">
<div id="login" style="width: 500px;">
<div style="text-align: left;">
<span style="font-weight: bold;">Database Maintenance</span>
<p>Database migrations are pending. OpenCATS should be updated before normal use continues.</p>
<p><input type="button" class="button" id="startMaintenance" value="Start Maintenance" onclick="this.disabled = true; document.getElementById('maintenanceError').style.display = 'none'; document.getElementById('maintenanceProgress').style.display = ''; maintenanceOnly = true; Installpage_maint();" /></p>
<p id="maintenanceError" style="display: none; color: #b00000;">Maintenance could not be completed. Please reload the page and try again.</p>

<div id="maintenanceProgress" style="display: none;">
<span id="upToDateModuleName"></span><br /><br />
<div id="d3" style="background-color:#eeeeee;border:1px solid black;height:20px;width:300px;padding:0px;" align="left">
<div id="d2" style="position:relative;top:0px;left:0px;background-color:#2244ff;height:20px;width:0px;padding-top:5px;padding:0px;">
<div id="d1" style="position:relative;top:0px;left:0px;color:#ffffff;height:20px;text-align:center;font:bold;padding:0px;padding-top:1px;"></div>
</div>
</div>
<br />
<span id="upToDateSqlQueryLabel" style="display:none;">SQL Query Being Executed:</span><br />
<div id="upToDateSqlQuery" style="overflow:hidden; width: 350px; height:100px; padding: 5px; border: 1px solid #000; background-color: #fff;"></div>
</div>

<span id="subFormBlock"></span>
</div>
</div>
</div>
</body>
</html>
46 changes: 33 additions & 13 deletions modules/install/ajax/maint.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,47 @@

if ($_SERVER['REQUEST_METHOD'] !== 'POST')
{
header('Content-Type: text/html; charset=UTF-8');

$actionURL = htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8');

echo '<!DOCTYPE html>',
'<html><head><title>OpenCATS Maintenance</title></head><body>',
'<p>This maintenance action must be triggered via POST.</p>',
'<p>This page starts maintenance mode and related installer tasks.</p>',
'<form method="post" action="', $actionURL, '">',
'<input type="hidden" name="postback" value="postback" />',
'<button type="submit">Run maintenance now</button>',
'</form>',
'</body></html>';
header('HTTP/1.1 405 Method Not Allowed');
header('Allow: POST');
die();
}

$installerActive = !file_exists('INSTALL_BLOCK');

if (!$installerActive)
{
/* Fresh installation uses the installer's existing access model. An
* installed system requires an authenticated site admin and CSRF token.
*/
include_once('./config.php');
include_once(LEGACY_ROOT . '/constants.php');
include_once(LEGACY_ROOT . '/lib/DatabaseConnection.php');
include_once(LEGACY_ROOT . '/lib/Session.php');

@session_name(CATS_SESSION_NAME);
@session_start();

if (!isset($_SESSION['CATS']) ||
!$_SESSION['CATS']->isLoggedIn() ||
$_SESSION['CATS']->getAccessLevel(ACL::SECOBJ_ROOT) < ACCESS_LEVEL_SA ||
!isset($_POST['csrfToken']) ||
!$_SESSION['CATS']->isCSRFTokenValid($_POST['csrfToken']))
{
header('HTTP/1.1 403 Forbidden');
die('Access denied.');
}
}

if (file_exists('./modules.cache'))
{
@unlink('./modules.cache');
}

if (isset($_SESSION['modules']))
{
unset($_SESSION['modules']);
}

$maintPage = true;

include_once('index.php');
2 changes: 1 addition & 1 deletion modules/login/PendingMigrations.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<?php if ($this->isAdministrator): ?>
<p>Database migrations are pending. OpenCATS should be updated before normal use continues.</p>
<p>Open the <a href="installwizard.php">Installation Wizard</a> to complete the upgrade.</p>
<p><a href="index.php?m=install&amp;a=maint">Start Maintenance</a></p>
<?php else: ?>
<p>Database maintenance is required before OpenCATS can be used normally. Please contact your administrator.</p>
<?php endif; ?>
Expand Down
Loading