Skip to content

endScript() cleanup #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2018
Merged
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
19 changes: 4 additions & 15 deletions deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function errorPage($msg) {
}

// Command to execute at the end of the script
function endScript() {
function endScript($errorMessage = "") {
// Remove lock file
unlink(__DIR__ . '/deploy.lock');
// Flush buffer and prepare output for log and email
Expand All @@ -51,6 +51,7 @@ function endScript() {
if(defined('LOG_FILE') && LOG_FILE !== '') error_log($output, 3, LOG_FILE);
// Send email notification
if(defined('EMAIL_NOTIFICATIONS') && EMAIL_NOTIFICATIONS !== '') error_log($output, 1, EMAIL_NOTIFICATIONS);
die($errorMessage);
}

/* Begin Script Execution */
Expand All @@ -70,7 +71,6 @@ function endScript() {
} else {
errorPage('<h2>File deploy-config.php does not exist</h2>');
endScript();
die();
}

// Check configuration errors
Expand All @@ -88,14 +88,12 @@ function endScript() {
if (count($err)) {
errorPage("<h2>Configuration Error</h2>\n<pre>\n" . implode("\n", $err) . "\n</pre>");
endScript();
die();
}

// Check if lock file exists
if (file_exists(__DIR__ . '/deploy.lock')) {
errorPage('<h2>File deploy.lock detected, another process already running</h2>');
endScript();
die();
}

// Create lock file
Expand Down Expand Up @@ -133,15 +131,13 @@ function endScript() {
if(!$allow) {
errorPage('<h2>Access Denied</h2>');
endScript();
die();
}
}

// If there's authorization error
if (!isset($_GET['t']) || $_GET['t'] !== ACCESS_TOKEN || DISABLED === true) {
errorPage('<h2>Access Denied</h2>');
endScript();
die();
}
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -193,7 +189,6 @@ function getallheaders() {
} else {
echo "\nOnly push and merged pull request events are processed\n\nDone.\n</pre></body></html>";
endScript();
exit;
}
} else if(isset($headers['X-GitHub-Event'])) {
// Github webhook
Expand All @@ -211,7 +206,6 @@ function getallheaders() {
} else {
echo "\nOnly push and merged pull request events are processed\n\nDone.\n</pre></body></html>";
endScript();
exit;
}
}

Expand All @@ -221,7 +215,6 @@ function getallheaders() {
if($branch != unserialize(BRANCH)[0]) {
echo "\nBranch $branch not allowed, stopping execution.\n</pre></body></html>";
endScript();
exit;
}

} else {
Expand All @@ -232,7 +225,6 @@ function getallheaders() {
if(!in_array($branch, unserialize(BRANCH))) {
echo "\nBranch $branch not allowed, stopping execution.\n</pre></body></html>";
endScript();
exit;
}
} else {
$branch = unserialize(BRANCH)[0];
Expand All @@ -249,8 +241,7 @@ function getallheaders() {
$path = trim(shell_exec('which '.$command));
if ($path == '') {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
endScript();
die(sprintf('<div class="error"><b>%s</b> not available. It needs to be installed on the server for this script to work.</div>', $command));
endScript(sprintf('<div class="error"><b>%s</b> not available. It needs to be installed on the server for this script to work.</div>', $command));
} else {
$version = explode("\n", shell_exec($command.' --version'));
printf('<b>%s</b> : %s'."\n"
Expand Down Expand Up @@ -293,7 +284,6 @@ function cmd($command, $print = true, $dir = GIT_DIR) {
'
);
endScript();
exit;
}

return $tmp;
Expand Down Expand Up @@ -484,5 +474,4 @@ function cmd($command, $print = true, $dir = GIT_DIR) {
</body>
</html>
<?php
endScript();
exit;
endScript();