clockwerk-www – Rev 50

Subversion Repositories:
Rev:
<?php

///////////////////////////////////////////////////////////////////////////
//       Copyright (C) Wizardry and Steamworks 2014 - License: MIT       //
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      //
///////////////////////////////////////////////////////////////////////////
function wasChown($path, $uid, $gid) {                                     
  switch(filetype($path)) {                                                
    case 'dir':                                                            
      if(($dir = opendir($path)) === false) break;                         
      while(false !== ($file = readdir($dir))) {
        if($file == '.' || $file == '..') continue;
        wasChown($path.'/'.$file, $uid, $gid);
      }
    case 'file':
      chown($path, $uid);  
      chgrp($path, $gid);  
      break;
  }
}

require_once 'lib/recaptchalib.php';
require_once 'lib/wasRemoteAdmin.php';

define('RECAPTCHA_PRIVATE_KEY', '6Lcz9ukSAAAAAC3u90rcOIdnNnaK_JgMjrOsSzZr');

$first = $_POST["first"];
$last = $_POST["last"];
$file = $_FILES["file"]["tmp_name"];
$password = $_POST["password"];

$resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if ($resp->is_valid) {
  $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim');
  $ret = $req->admin_authenticate_user($first, $last, MD5($password), '1');
  $rep = new SimpleXMLElement($ret);
  foreach($rep->params->param->value->struct->member as $member) {
    if ($member->name == "success" && $member->value->boolean == "0") {
      echo 'Sorry, wrong password.';
      exit;
    }
  }
  if (file_exists($file)) {
    wasChown($file, 'opensim', 'opensim');
    $req->admin_console_command('load iar '.$file. ' '.$last.' / '.$file);
    wasChown($file, 'www-data', 'www-data');
    header('Location: welcome.php');
    exit;  
  } 
}

echo '<p>Sorry, incorrect CAPTCHA. Please try again.</p>';