Changeset 2391


Ignore:
Timestamp:
11/26/2011 5:01:07 AM (3 years ago)
Author:
lowjoel
Message:

Added database support for build slave information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/BuildServer.php

    r2388 r2391  
    88    header(sprintf('WWW-Authenticate: Digest realm="%s",qop="auth",nonce="%s",opaque="%s"', 
    99        HTTP_DIGEST_REALM, uniqid(), md5(HTTP_DIGEST_REALM))); 
    10     exit; 
     10    die('Authorisation required.'); 
    1111} 
    1212 
     
    3535} 
    3636 
    37 //user => password 
    38 $users = array('admin' => 'mypass', 'guest' => 'guest'); 
    39  
    4037//Challenge the client if we did not receive the digest 
    4138if (empty($_SERVER['PHP_AUTH_DIGEST'])) 
     
    4441//Analyze the PHP_AUTH_DIGEST variable 
    4542$credentials = http_digest_parse($_SERVER['PHP_AUTH_DIGEST']); 
    46 if (!$credentials || !isset($users[$credentials['username']])) 
     43if (!$credentials) 
    4744    http_digest_challenge(); 
    4845 
    49 //Check the response 
    50 $A1 = md5($credentials['username'] . ':' . HTTP_DIGEST_REALM . ':' . $users[$credentials['username']]); 
     46//Does the user exist? 
     47require_once('Credentials.php'); 
     48require_once('Database.php'); 
     49$database = new Database(); 
     50$count = $database->query(sprintf('SELECT COUNT(*) FROM build_slaves WHERE Username=%s', 
     51    $database->quote($credentials['username'])))->fetch(); 
     52$count = $count[0]; 
     53if (!$count) 
     54    http_digest_challenge(); 
     55 
     56//Check the response for the password. 
     57$password = $database->query(sprintf('SELECT Password FROM build_slaves WHERE Username=%s', 
     58    $database->quote($credentials['username'])))->fetch(); 
     59$password = $password['Password']; 
     60$A1 = md5($credentials['username'] . ':' . HTTP_DIGEST_REALM . ':' . $password); 
    5161$A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $credentials['uri']); 
    5262$valid_response = md5($A1 . ':' . $credentials['nonce'] . ':' . $credentials['nc'] . ':' . 
     
    5868require_once('BuildUtil.php'); 
    5969require_once('BuildBranch.php'); 
    60 require_once('Credentials.php'); 
    61 require_once('Database.php'); 
    6270 
    6371try 
     
    6573    //Check that we have all the necessary information 
    6674    $branches = BuildBranch::Get(); 
     75    if (!is_numeric($_GET['revision']) || !is_numeric($_GET['filesize']) || empty($_GET['url']) || empty($_GET['branch'])) 
     76        throw new Exception('Invalid build information provided.'); 
    6777    if (!array_key_exists($_GET['branch'], $branches)) 
    6878        throw new Exception('The branch ' . $_GET['branch'] . ' does not exist.'); 
    69     if (!is_numeric($_GET['revision']) || !is_numeric($_GET['filesize']) || empty($_GET['url'])) 
    70         throw new Exception('Invalid build information provided.'); 
    7179 
    7280    //Get the branch the notification is for 
Note: See TracChangeset for help on using the changeset viewer.