-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-xmlrpc.php
More file actions
130 lines (114 loc) · 5.42 KB
/
wp-xmlrpc.php
File metadata and controls
130 lines (114 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Authentication Plugin: MooLogin - Wordpress and Moodle authentication.
*
* @package moologin
* @author Tõnis Tartes
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once($CFG->libdir.'/moodlelib.php');
require_once($CFG->libdir.'/authlib.php');
class XMLRPClientWordPress {
var $xmlrpcurl = "";
var $username = "";
var $password = "";
var $msharedsecret = "";
// Constructor
public function __construct() {
$this->config = get_config('auth/moologin');
$this->xmlrpcurl = $this->config->wpaddress.'xmlrpc.php';
$this->username = $this->config->wprpcuser;
$this->password = $this->config->wprpcpassword;
$this->msharedsecret = $this->config->sharedsecret;
}
function send_request($requestname, $params) {
$request = xmlrpc_encode_request($requestname, $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $this->xmlrpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
function validateUser($username, $password) {
//Crypted query
$details = http_build_query(array(
"a", rand(1, 1500), // set first to randomise the encryption when this string is encoded
"stamp" => time(), // unix timestamp so we can check that the link isn't expired
"wpusername" => $this->username, // WP username
"wppassword" => $this->password, // WP password
"username" => $username, // username to check
"password" => $password, // password to check
"z" => rand(1, 1500), // extra randomiser for when this string is encrypted (for variance)
));
$params = array($this->encrypt_string($details, $this->msharedsecret));
return $this->send_request('moologinClient.validateUser', $params);
}
function checkUser($username) {
//Crypted query
$details = http_build_query(array(
"a", rand(1, 1500), // set first to randomise the encryption when this string is encoded
"stamp" => time(), // unix timestamp so we can check that the link isn't expired
"wpusername" => $this->username, // WP username
"wppassword" => $this->password, // WP password
"username" => $username, // username to check
"z" => rand(1, 1500), // extra randomiser for when this string is encrypted (for variance)
));
$params = array($this->encrypt_string($details, $this->msharedsecret));
return $this->send_request('moologinClient.checkUser', $params);
}
function getUserInfo($username) {
//Crypted query
$details = http_build_query(array(
"a", rand(1, 1500), // set first to randomise the encryption when this string is encoded
"stamp" => time(), // unix timestamp so we can check that the link isn't expired
"wpusername" => $this->username, // WP username
"wppassword" => $this->password, // WP password
"username" => $username, // username to check
"z" => rand(1, 1500), // extra randomiser for when this string is encrypted (for variance)
));
$params = array($this->encrypt_string($details, $this->msharedsecret));
return $this->send_request('moologinClient.userInfo', $params);
}
function parse_xml_string($string) {
$xml = simplexml_load_string($string);
$value = $xml->params;
return $value;
}
/**
* Given a string and key, return the encrypted version (hard coded to use rijndael because it's tough)
*/
function encrypt_string($value, $key) {
if (!$value) {
return "";
}
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key.$key), $text, MCRYPT_MODE_ECB, $iv);
// encode data so that $_GET won't urldecode it and mess up some characters
$data = base64_encode($crypttext);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return trim($data);
}
}
?>