| <?php |
| /******************************************************************************* |
| * Copyright (c) 2013-2015 Eclipse Foundation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Denis Roy (Eclipse Foundation)- initial API and implementation |
| *******************************************************************************/ |
| |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/projects/projectList.class.php"); |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/projects/hipp.class.php"); |
| require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/evt_log.class.php"); |
| |
| $App = new App(); |
| |
| define("SVCTYPE", "HIPPCTL"); |
| |
| # require session for this page |
| $Session = $App->useSession(true); |
| $Friend = $Session->getFriend(); |
| |
| $ProjectList = new ProjectList(); |
| $ProjectList->selectCommitterProjectList($Friend->getUID()); |
| |
| $prj = $App->getHTTPParameter("project"); |
| $action = $App->getHTTPParameter("action"); |
| $token = $App->getHTTPParameter("token"); |
| $token = preg_replace("/[^a-zA-Z0-9]/", "", $token); |
| |
| # Sanitize action |
| $validActions = array("start", "stop", "restart", "check", "upgrade", "readme"); |
| if(!in_array($action, $validActions)) { |
| echo "Invalid request."; exit; |
| } |
| |
| # Check status of token |
| if($action == "check") { |
| if($token != "") { |
| $sql = "SELECT /* USE MASTER */ NOW() AS timenow, ROUND(NOW() - req_when,0) AS seconds_waiting, req_result, req_output, req_action FROM service_requests |
| WHERE token = " . $App->returnQuotedString($App->sqlSanitize($token)); |
| $rs = $App->eclipse_sql($sql); |
| if($myrow = mysql_fetch_assoc($rs)) { |
| if($myrow['req_result'] == "") { |
| if($myrow['seconds_waiting'] > 300) { |
| echo "<b>Your request has not produced a result in 5 minutes. Please refresh this page and try again, and notify webmaster@eclipse.org if the problem persists.</b>"; |
| } |
| else { |
| $dots = 1; |
| if($myrow['seconds_waiting'] > 0) { |
| $dots = $myrow['seconds_waiting'] / 5; |
| } |
| $s = str_repeat(".", $dots); |
| echo "<img class='spinner' src='../images/spinner.gif' />   <b>" . $myrow['timenow'] . ":</b> pending execution of " . $myrow['req_action'] . $s; |
| } |
| } |
| else { |
| if($myrow['req_action'] == "upgrade") { |
| $output = nl2br($myrow['req_output']); |
| echo "Your request to " . $myrow['req_action'] . " Hudson has begun. <b>Output text:</b> " . $output; |
| } |
| else { |
| echo "Your request to " . $myrow['req_action'] . " Hudson has completed. <b>Output text:</b> " . $myrow['req_output']; |
| } |
| } |
| } |
| else { |
| echo "<b><font class='darkred'>Invalid or expired token. Please refresh this page.</font></b>"; |
| } |
| } |
| else { |
| echo "No token!"; |
| } |
| exit; |
| } |
| |
| |
| # Sanitize committer/project |
| $validCommitter = false; |
| if($ProjectList->getCount() > 0) { |
| for($i = 0; $i < $ProjectList->getCount(); $i++) { |
| $Project = $ProjectList->getItemAt($i); |
| if($Project->getProjectID() == $prj) { |
| $validCommitter = true; |
| break; |
| } |
| } |
| } |
| if(!$validCommitter) { |
| echo "You are not a committer on this project."; exit; |
| } |
| # End sanitize |
| |
| # Determine if another request is still pending |
| $sql = "SELECT /* USE MASTER */ COUNT(1) AS RecordCount FROM service_requests |
| WHERE service_type = " . $App->returnQuotedString(SVCTYPE) |
| . " AND project_id = " . $App->returnQuotedString($App->sqlSanitize($prj)) |
| . " AND req_result IS NULL"; |
| $rs = $App->eclipse_sql($sql); |
| $myrow = mysql_fetch_assoc($rs); |
| if($myrow['RecordCount'] > 0) { |
| echo "<b><font color='darkred'>You have already submitted a request. Please wait for the current request to complete. (1356)</font></b>"; |
| exit; |
| } |
| |
| # Completed requests will stay in the table for 15 minutes. |
| # Determine if another request was issued recently, and prevent another from happening |
| $sql = "SELECT /* USE MASTER */ COUNT(1) AS RecordCount FROM service_requests |
| WHERE service_type = " . $App->returnQuotedString(SVCTYPE) |
| . " AND project_id = " . $App->returnQuotedString($App->sqlSanitize($prj)) |
| . " AND req_result IS NOT NULL AND DATE_SUB(NOW(), INTERVAL 1 minute) < req_when"; |
| $rs = $App->eclipse_sql($sql); |
| $myrow = mysql_fetch_assoc($rs); |
| if($myrow['RecordCount'] > 4) { |
| echo "<b><font color='darkred'>A similar request was issued recently. Please wait a few moments before trying again. If the problem persists, please contact webmaster@eclipse.org (1122).</font></b>"; |
| exit; |
| } |
| |
| # Completed requests will stay in the table for 15 minutes. |
| # Determine if an specific IP address is trying to harm us |
| $sql = "SELECT /* USE MASTER */ COUNT(1) AS RecordCount FROM service_requests |
| WHERE service_type = " . $App->returnQuotedString(SVCTYPE) |
| . " AND ip = " . $App->returnQuotedString($_SERVER['REMOTE_ADDR']); |
| $rs = $App->eclipse_sql($sql); |
| $myrow = mysql_fetch_assoc($rs); |
| if($myrow['RecordCount'] > 4) { |
| echo "<b><font color='darkred'>Too many requests. Please wait a few moments before trying again. If the problem persists, please contact webmaster@eclipse.org (3124).</font></b>"; |
| exit; |
| } |
| |
| |
| ##################################### |
| # All is good. |
| if($action == "readme") { |
| $Hipp = new Hipp(); |
| $Hipp->selectHipp($prj); |
| echo $Hipp->getReadmeContents("hipp", $Hipp->getServiceLatestVersion()); |
| } |
| else { |
| $token = $App->getAlphaCode(64); |
| $sql = "INSERT INTO service_requests VALUES (NULL, |
| " . $App->returnQuotedString($Friend->getUID()) . ", |
| " . $App->returnQuotedString($App->sqlSanitize($prj)) . ", |
| 'HIPPCTL', |
| " . $App->returnQuotedString($App->sqlSanitize($action)) . ", |
| NULL, |
| NULL, |
| " . $App->returnQuotedString($_SERVER['REMOTE_ADDR']) . ", |
| NOW(), |
| " . $App->returnQuotedString($token) . ")"; |
| $App->eclipse_sql($sql); |
| |
| $EventLog = new EvtLog(); |
| $EventLog->setLogTable("service_requests"); |
| $EventLog->setPK1("HIPPCTL"); |
| $EventLog->setPK2($App->sqlSanitize($prj)); |
| $EventLog->setLogAction("request_" . $App->sqlSanitize($action)); |
| $EventLog->insertModLog($Friend->getUID()); |
| |
| echo "token:" . $token; |
| } |
| ?> |