clockwerk-www – Diff between revs 44 and 46

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 44 Rev 46
1 <?php 1 <?php
2   2  
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // Copyright (C) Wizardry and Steamworks 2014 - License: MIT // 4 // Copyright (C) Wizardry and Steamworks 2014 - License: MIT //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6   6  
7 // Hostname or IP of your OpenSim MySQL server. 7 // Hostname or IP of your OpenSim MySQL server.
8 $MYSQL_HOSTNAME='localhost'; 8 $MYSQL_HOSTNAME='localhost';
9 // Username of the OpenSim MySQL user. 9 // Username of the OpenSim MySQL user.
10 $MYSQL_USERNAME='opensim'; 10 $MYSQL_USERNAME='opensim';
11 // Password of the OpenSim MySQL user. 11 // Password of the OpenSim MySQL user.
12 $MYSQL_PASSWORD='***'; 12 $MYSQL_PASSWORD='***';
13 // Name of the OpenSim database on the MySQL server. 13 // Name of the OpenSim database on the MySQL server.
14 $MYSQL_DATABASE='opensim'; 14 $MYSQL_DATABASE='opensim';
15   15  
16 require_once 'lib/recaptchalib.php'; 16 require_once 'lib/recaptchalib.php';
17 require_once 'lib/wasRemoteAdmin.php'; 17 require_once 'lib/wasRemoteAdmin.php';
18   18  
19 define('RECAPTCHA_PRIVATE_KEY', '6Lcz9ukSAAAAAC3u90rcOIdnNnaK_JgMjrOsSzZr'); 19 define('RECAPTCHA_PRIVATE_KEY', '6Lcz9ukSAAAAAC3u90rcOIdnNnaK_JgMjrOsSzZr');
20   20  
21 $first = $_GET["first"]; 21 $first = $_POST["first"];
22 $last = $_GET["last"]; 22 $last = $_POST["last"];
23 $region = $_GET["region"]; 23 $region = $_POST["region"];
24 $password = $_GET["password"]; 24 $password = $_POST["password"];
25   25  
26 $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY, 26 $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY,
27 $_SERVER["REMOTE_ADDR"], 27 $_SERVER["REMOTE_ADDR"],
28 $_POST["recaptcha_challenge_field"], 28 $_POST["recaptcha_challenge_field"],
29 $_POST["recaptcha_response_field"]); 29 $_POST["recaptcha_response_field"]);
30   30  
31 if ($resp->is_valid) { 31 if ($resp->is_valid) {
32 $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim'); 32 $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim');
33 $ret = $req->admin_authenticate_user($first, $last, MD5($password), '1'); 33 $ret = $req->admin_authenticate_user($first, $last, MD5($password), '1');
34 $rep = new SimpleXMLElement($ret); 34 $rep = new SimpleXMLElement($ret);
35 foreach($rep->params->param->value->struct->member as $member) { 35 foreach($rep->params->param->value->struct->member as $member) {
36 if ($member->name == "success" && $member->value->boolean == "0") { 36 if ($member->name == "success" && $member->value->boolean == "0") {
37 echo 'Sorry, wrong password.'; 37 echo 'Sorry, wrong password.';
38 exit; 38 exit;
39 } 39 }
40 } 40 }
41 try { 41 try {
42 $mysql = new PDO('mysql:host='.$MYSQL_HOSTNAME.';dbname='.$MYSQL_DATABASE.';', $MYSQL_USERNAME, $MYSQL_PASSWORD); 42 $mysql = new PDO('mysql:host='.$MYSQL_HOSTNAME.';dbname='.$MYSQL_DATABASE.';', $MYSQL_USERNAME, $MYSQL_PASSWORD);
43 $mysql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 43 $mysql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
44 $query = $mysql->prepare("SELECT RegionName FROM regions WHERE owner_uuid=(SELECT PrincipalID FROM UserAccounts WHERE FirstName=:first AND LastName=:last)"); 44 $query = $mysql->prepare("SELECT RegionName FROM regions WHERE owner_uuid=(SELECT PrincipalID FROM UserAccounts WHERE FirstName=:first AND LastName=:last)");
45 $query->bindParam(':first', $first); 45 $query->bindParam(':first', $first);
46 $query->bindParam(':last', $last); 46 $query->bindParam(':last', $last);
47 $query->execute(); 47 $query->execute();
48 } 48 }
49 catch(PDOException $e) { 49 catch(PDOException $e) {
50 print 'The given agent is not the owner of the region to download.'; 50 print 'The given agent is not the owner of the region to download.';
51 return 1; 51 return 1;
52 } 52 }
53 while ($result = $query->fetchObject()) { 53 while ($result = $query->fetchObject()) {
54 if ($result->RegionName == $region) { 54 if ($result->RegionName == $region) {
55 $oar_path = '/var/lib/oar/'.$region.'/'.$region.'.oar'; 55 $oar_path = '/var/lib/oar/'.$region.'/'.$region.'.oar';
56 if (file_exists($oar_path)) { 56 if (file_exists($oar_path)) {
57 header('Content-Description: File Transfer'); 57 header('Content-Description: File Transfer');
58 header('Content-Type: application/x-gzip-compressed'); 58 header('Content-Type: application/x-gzip-compressed');
59 header('Content-Disposition: attachment; filename='.basename($oar_path)); 59 header('Content-Disposition: attachment; filename='.basename($oar_path));
60 header('Content-Transfer-Encoding: binary'); 60 header('Content-Transfer-Encoding: binary');
61 header('Expires: 0'); 61 header('Expires: 0');
62 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 62 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
63 header('Pragma: public'); 63 header('Pragma: public');
64 header('Content-Length: '.filesize($oar_path)); 64 header('Content-Length: '.filesize($oar_path));
65 readfile($oar_path); 65 readfile($oar_path);
66 exit; 66 exit;
67 } 67 }
68 } 68 }
69 } 69 }
70 } 70 }
71   71  
72 echo '<p>Sorry, incorrect CAPTCHA. Please try again.</p>'; 72 echo '<p>Sorry, incorrect CAPTCHA. Please try again.</p>';
73   73