@@ -29,7 +29,7 @@ function errorPage($msg) {
29
29
}
30
30
31
31
// Command to execute at the end of the script
32
- function endScript () {
32
+ function endScript ($ errorMessage = "" ) {
33
33
// Remove lock file
34
34
unlink (__DIR__ . '/deploy.lock ' );
35
35
// Flush buffer and prepare output for log and email
@@ -51,6 +51,7 @@ function endScript() {
51
51
if (defined ('LOG_FILE ' ) && LOG_FILE !== '' ) error_log ($ output , 3 , LOG_FILE );
52
52
// Send email notification
53
53
if (defined ('EMAIL_NOTIFICATIONS ' ) && EMAIL_NOTIFICATIONS !== '' ) error_log ($ output , 1 , EMAIL_NOTIFICATIONS );
54
+ die ($ errorMessage );
54
55
}
55
56
56
57
/* Begin Script Execution */
@@ -70,7 +71,6 @@ function endScript() {
70
71
} else {
71
72
errorPage ('<h2>File deploy-config.php does not exist</h2> ' );
72
73
endScript ();
73
- die ();
74
74
}
75
75
76
76
// Check configuration errors
@@ -88,14 +88,12 @@ function endScript() {
88
88
if (count ($ err )) {
89
89
errorPage ("<h2>Configuration Error</h2> \n<pre> \n" . implode ("\n" , $ err ) . "\n</pre> " );
90
90
endScript ();
91
- die ();
92
91
}
93
92
94
93
// Check if lock file exists
95
94
if (file_exists (__DIR__ . '/deploy.lock ' )) {
96
95
errorPage ('<h2>File deploy.lock detected, another process already running</h2> ' );
97
96
endScript ();
98
- die ();
99
97
}
100
98
101
99
// Create lock file
@@ -133,15 +131,13 @@ function endScript() {
133
131
if (!$ allow ) {
134
132
errorPage ('<h2>Access Denied</h2> ' );
135
133
endScript ();
136
- die ();
137
134
}
138
135
}
139
136
140
137
// If there's authorization error
141
138
if (!isset ($ _GET ['t ' ]) || $ _GET ['t ' ] !== ACCESS_TOKEN || DISABLED === true ) {
142
139
errorPage ('<h2>Access Denied</h2> ' );
143
140
endScript ();
144
- die ();
145
141
}
146
142
?>
147
143
<!DOCTYPE html>
@@ -193,7 +189,6 @@ function getallheaders() {
193
189
} else {
194
190
echo "\nOnly push and merged pull request events are processed \n\nDone. \n</pre></body></html> " ;
195
191
endScript ();
196
- exit ;
197
192
}
198
193
} else if (isset ($ headers ['X-GitHub-Event ' ])) {
199
194
// Github webhook
@@ -211,7 +206,6 @@ function getallheaders() {
211
206
} else {
212
207
echo "\nOnly push and merged pull request events are processed \n\nDone. \n</pre></body></html> " ;
213
208
endScript ();
214
- exit ;
215
209
}
216
210
}
217
211
@@ -221,7 +215,6 @@ function getallheaders() {
221
215
if ($ branch != unserialize (BRANCH )[0 ]) {
222
216
echo "\nBranch $ branch not allowed, stopping execution. \n</pre></body></html> " ;
223
217
endScript ();
224
- exit ;
225
218
}
226
219
227
220
} else {
@@ -232,7 +225,6 @@ function getallheaders() {
232
225
if (!in_array ($ branch , unserialize (BRANCH ))) {
233
226
echo "\nBranch $ branch not allowed, stopping execution. \n</pre></body></html> " ;
234
227
endScript ();
235
- exit ;
236
228
}
237
229
} else {
238
230
$ branch = unserialize (BRANCH )[0 ];
@@ -249,8 +241,7 @@ function getallheaders() {
249
241
$ path = trim (shell_exec ('which ' .$ command ));
250
242
if ($ path == '' ) {
251
243
header ($ _SERVER ['SERVER_PROTOCOL ' ] . ' 500 Internal Server Error ' , true , 500 );
252
- endScript ();
253
- 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 ));
244
+ 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 ));
254
245
} else {
255
246
$ version = explode ("\n" , shell_exec ($ command .' --version ' ));
256
247
printf ('<b>%s</b> : %s ' ."\n"
@@ -293,7 +284,6 @@ function cmd($command, $print = true, $dir = GIT_DIR) {
293
284
'
294
285
);
295
286
endScript ();
296
- exit ;
297
287
}
298
288
299
289
return $ tmp ;
@@ -484,5 +474,4 @@ function cmd($command, $print = true, $dir = GIT_DIR) {
484
474
</body>
485
475
</html>
486
476
<?php
487
- endScript ();
488
- exit ;
477
+ endScript ();
0 commit comments