clockwerk-www – Diff between revs 50 and 53
?pathlinks?
Rev 50 | Rev 53 | |||
---|---|---|---|---|
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 | |
- | ||
7 | /////////////////////////////////////////////////////////////////////////// |
- | ||
8 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
- | ||
9 | /////////////////////////////////////////////////////////////////////////// |
- | ||
10 | function wasChown($path, $uid, $gid) { |
- | ||
11 | switch(filetype($path)) { |
- | ||
12 | case 'dir': |
- | ||
13 | if(($dir = opendir($path)) === false) break; |
- | ||
14 | while(false !== ($file = readdir($dir))) { |
- | ||
15 | if($file == '.' || $file == '..') continue; |
- | ||
16 | wasChown($path.'/'.$file, $uid, $gid); |
- | ||
17 | } |
- | ||
18 | case 'file': |
- | ||
19 | chown($path, $uid); |
- | ||
20 | chgrp($path, $gid); |
- | ||
21 | break; |
- | ||
22 | } |
- | ||
23 | } |
- | ||
24 | |
6 | |
|
25 | // Hostname or IP of your OpenSim MySQL server. |
7 | // Hostname or IP of your OpenSim MySQL server. |
|
26 | $MYSQL_HOSTNAME='localhost'; |
8 | $MYSQL_HOSTNAME='localhost'; |
|
27 | // Username of the OpenSim MySQL user. |
9 | // Username of the OpenSim MySQL user. |
|
28 | $MYSQL_USERNAME='opensim'; |
10 | $MYSQL_USERNAME='opensim'; |
|
29 | // Password of the OpenSim MySQL user. |
11 | // Password of the OpenSim MySQL user. |
|
30 | $MYSQL_PASSWORD='***'; |
12 | $MYSQL_PASSWORD='***'; |
|
31 | // Name of the OpenSim database on the MySQL server. |
13 | // Name of the OpenSim database on the MySQL server. |
|
32 | $MYSQL_DATABASE='opensim'; |
14 | $MYSQL_DATABASE='opensim'; |
|
33 | |
15 | |
|
34 | require_once 'lib/recaptchalib.php'; |
16 | require_once 'lib/recaptchalib.php'; |
|
35 | require_once 'lib/wasRemoteAdmin.php'; |
17 | require_once 'lib/wasRemoteAdmin.php'; |
|
36 | |
18 | |
|
37 | define('RECAPTCHA_PRIVATE_KEY', '6Lcz9ukSAAAAAC3u90rcOIdnNnaK_JgMjrOsSzZr'); |
19 | define('RECAPTCHA_PRIVATE_KEY', '6Lcz9ukSAAAAAC3u90rcOIdnNnaK_JgMjrOsSzZr'); |
|
38 | |
20 | |
|
39 | $first = $_POST["first"]; |
21 | $first = $_POST["first"]; |
|
40 | $last = $_POST["last"]; |
22 | $last = $_POST["last"]; |
|
41 | $region = $_POST["region"]; |
23 | $region = $_POST["region"]; |
|
42 | $file = $_FILES["file"]["tmp_name"]; |
24 | $file = $_FILES["file"]["tmp_name"]; |
|
43 | $password = $_POST["password"]; |
25 | $password = $_POST["password"]; |
|
44 | |
26 | |
|
45 | $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY, |
27 | $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY, |
|
46 | $_SERVER["REMOTE_ADDR"], |
28 | $_SERVER["REMOTE_ADDR"], |
|
47 | $_POST["recaptcha_challenge_field"], |
29 | $_POST["recaptcha_challenge_field"], |
|
48 | $_POST["recaptcha_response_field"]); |
30 | $_POST["recaptcha_response_field"]); |
|
49 | |
31 | |
|
50 | if ($resp->is_valid) { |
32 | if ($resp->is_valid) { |
|
51 | $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim'); |
33 | $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim'); |
|
52 | $ret = $req->admin_authenticate_user($first, $last, MD5($password), '1'); |
34 | $ret = $req->admin_authenticate_user($first, $last, MD5($password), '1'); |
|
53 | $rep = new SimpleXMLElement($ret); |
35 | $rep = new SimpleXMLElement($ret); |
|
54 | foreach($rep->params->param->value->struct->member as $member) { |
36 | foreach($rep->params->param->value->struct->member as $member) { |
|
55 | if ($member->name == "success" && $member->value->boolean == "0") { |
37 | if ($member->name == "success" && $member->value->boolean == "0") { |
|
56 | echo 'Sorry, wrong password.'; |
38 | echo 'Sorry, wrong password.'; |
|
57 | exit; |
39 | exit; |
|
58 | } |
40 | } |
|
59 | } |
41 | } |
|
60 | try { |
42 | try { |
|
61 | $mysql = new PDO('mysql:host='.$MYSQL_HOSTNAME.';dbname='.$MYSQL_DATABASE.';', $MYSQL_USERNAME, $MYSQL_PASSWORD); |
43 | $mysql = new PDO('mysql:host='.$MYSQL_HOSTNAME.';dbname='.$MYSQL_DATABASE.';', $MYSQL_USERNAME, $MYSQL_PASSWORD); |
|
62 | $mysql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
44 | $mysql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
63 | $query = $mysql->prepare("SELECT RegionName FROM regions WHERE owner_uuid=(SELECT PrincipalID FROM UserAccounts WHERE FirstName=:first AND LastName=:last)"); |
45 | $query = $mysql->prepare("SELECT RegionName FROM regions WHERE owner_uuid=(SELECT PrincipalID FROM UserAccounts WHERE FirstName=:first AND LastName=:last)"); |
|
64 | $query->bindParam(':first', $first); |
46 | $query->bindParam(':first', $first); |
|
65 | $query->bindParam(':last', $last); |
47 | $query->bindParam(':last', $last); |
|
66 | $query->execute(); |
48 | $query->execute(); |
|
67 | } |
49 | } |
|
68 | catch(PDOException $e) { |
50 | catch(PDOException $e) { |
|
69 | print 'The given agent is not the owner of the region to download.'; |
51 | print 'The given agent is not the owner of the region to download.'; |
|
70 | return 1; |
52 | return 1; |
|
71 | } |
53 | } |
|
72 | while ($result = $query->fetchObject()) { |
54 | while ($result = $query->fetchObject()) { |
|
73 | if ($result->RegionName == $region) { |
55 | if ($result->RegionName == $region) { |
|
74 | if (file_exists($file)) { |
56 | if (file_exists($file)) { |
|
75 | $req->admin_console_command('change region '.$region); |
57 | $req->admin_console_command('change region '.$region); |
|
76 | wasChown($file, 'opensim', 'opensim'); |
58 | chmod($file, 0644); |
|
77 | $req->admin_console_command('load oar '.$file); |
59 | $req->admin_console_command('load oar '.$file); |
|
78 | wasChown($file, 'www-data', 'www-data'); |
60 | chmod($file, 0600); |
|
79 | header('Location: welcome.php'); |
61 | header('Location: welcome.php'); |
|
80 | exit; |
62 | exit; |
|
81 | } |
63 | } |
|
82 | } |
64 | } |
|
83 | } |
65 | } |
|
84 | } |
66 | } |
|
85 | |
67 | |
|
86 | echo '<p>Sorry, incorrect CAPTCHA. Please try again.</p>'; |
68 | echo '<p>Sorry, incorrect CAPTCHA. Please try again.</p>'; |
|
87 | |
69 | |