-
Notifications
You must be signed in to change notification settings - Fork 0
/
commxmlrpc.php
219 lines (197 loc) · 6.65 KB
/
commxmlrpc.php
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
include_once("tiki-setup.php");
include_once ('lib/commcenter/commlib.php');
if ($tikilib->get_preference("feature_comm", 'n') != 'y') {
die;
}
$map = array(
"sendPage" => array("function" => "sendPage"),
"sendStructurePage" => array("function" => "sendStructurePage"),
"sendArticle" => array("function" => "sendArticle")
);
$s = new XML_RPC_Server($map);
/**
* @param $params
* @return XML_RPC_Response
*/
function sendStructurePage($params)
{
global $commlib, $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$structlib = TikiLib::lib('struct');
$site = $params->getParam(0); $site = $site->scalarval();
$user = $params->getParam(1); $user = $user->scalarval();
$pass = $params->getParam(2); $pass = $pass->scalarval();
$sName = $params->getParam(3); $sName = $sName->scalarval();
$pName = $params->getParam(4); $pName = $pName->scalarval();
$name = $params->getParam(5); $name = $name->scalarval();
$data = $params->getParam(6); $data = $data->scalarval();
$comm = $params->getParam(7); $comm = $comm->scalarval();
$desc = $params->getParam(8); $desc = $desc->scalarval();
$pos = $params->getParam(9); $pos = $pos->scalarval();
$alias = $params->getParam(10); $alias = $alias->scalarval();
if ($user != 'admin' && $prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster'])) {
$ok = $userlib->intervalidate($prefs['interlist'][$prefs['feature_intertiki_mymaster']], $user, $pass, false);
} else {
list($ok, $user, $error) = $userlib->validate_user($user, $pass, '', '');
}
if (!$ok) {
return new XML_RPC_Response(0, 101, "Invalid username or password");
}
// Verify if the user has tiki_p_sendme_pages
if (!$userlib->user_has_permission($user, 'tiki_p_sendme_pages')) {
return new XML_RPC_Response(0, 101, "Permissions denied user $user cannot send pages to this site");
}
// Store the page in the tiki_received_pages_table
$data = base64_decode($data);
$commlib->receive_structure_page($name, $data, $comm, $site, $user, $desc, $sName, $pName, $pos, $alias);
return new XML_RPC_Response(new XML_RPC_Value(1, "boolean"));
}
/* Validates the user and returns user information */
/**
* @param $params
* @return XML_RPC_Response
*/
function sendPage($params)
{
// Get the page and store it in received_pages
global $commlib, $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$pp = $params->getParam(0);
$site = $pp->scalarval();
$pp = $params->getParam(1);
$username = $pp->scalarval();
$pp = $params->getParam(2);
$password = $pp->scalarval();
$pp = $params->getParam(3);
$pageName = $pp->scalarval();
$pp = $params->getParam(4);
$data = $pp->scalarval();
$pp = $params->getParam(5);
$comment = $pp->scalarval();
$pp = $params->getParam(6);
$description = $pp->scalarval();
if ($username != 'admin' && $prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster'])) {
$ok = $userlib->intervalidate($prefs['interlist'][$prefs['feature_intertiki_mymaster']], $username, $password, false);
} else {
list($ok, $username, $error) = $userlib->validate_user($username, $password, '', '');
}
if (!$ok) {
return new XML_RPC_Response(0, 101, "Invalid username or password");
}
// Verify if the user has tiki_p_sendme_pages
if (!$userlib->user_has_permission($username, 'tiki_p_sendme_pages')) {
return new XML_RPC_Response(0, 101, "Permissions denied user $username cannot send pages to this site");
}
// Store the page in the tiki_received_pages_table
$data = base64_decode($data);
$commlib->receive_page($pageName, $data, $comment, $site, $username, $description);
return new XML_RPC_Response(new XML_RPC_Value(1, "boolean"));
}
/**
* @param $params
* @return XML_RPC_Response
*/
function sendArticle($params)
{
// Get the page and store it in received_pages
global $commlib, $prefs;
$userlib = TikiLib::lib('user');
$tikilib = TikiLib::lib('tiki');
$pp = $params->getParam(0);
$site = $pp->scalarval();
$pp = $params->getParam(1);
$username = $pp->scalarval();
$pp = $params->getParam(2);
$password = $pp->scalarval();
$pp = $params->getParam(3);
$title = $pp->scalarval();
$pp = $params->getParam(4);
$authorName = $pp->scalarval();
$pp = $params->getParam(5);
$size = $pp->scalarval();
$pp = $params->getParam(6);
$use_image = $pp->scalarval();
$pp = $params->getParam(7);
$image_name = $pp->scalarval();
$pp = $params->getParam(8);
$image_type = $pp->scalarval();
$pp = $params->getParam(9);
$image_size = $pp->scalarval();
$pp = $params->getParam(10);
$image_x = $pp->scalarval();
$pp = $params->getParam(11);
$image_y = $pp->scalarval();
$pp = $params->getParam(12);
$image_data = $pp->scalarval();
$pp = $params->getParam(13);
$publishDate = $pp->scalarval();
$pp = $params->getParam(14);
$expireDate = $pp->scalarval();
$pp = $params->getParam(15);
$created = $pp->scalarval();
$pp = $params->getParam(16);
$heading = $pp->scalarval();
$pp = $params->getParam(17);
$body = $pp->scalarval();
$pp = $params->getParam(18);
$hash = $pp->scalarval();
$pp = $params->getParam(19);
$author = $pp->scalarval();
$pp = $params->getParam(20);
$type = $pp->scalarval();
$pp = $params->getParam(21);
$rating = $pp->scalarval();
if ($username != 'admin' && $prefs['feature_intertiki'] == 'y' && !empty($prefs['feature_intertiki_mymaster'])) {
$ok = $userlib->intervalidate($prefs['interlist'][$prefs['feature_intertiki_mymaster']], $username, $password, false);
} else {
list($ok, $username, $error) = $userlib->validate_user($username, $password, '', '');
}
if (!$ok) {
return new XML_RPC_Response(0, 101, "Invalid username or password");
}
// Verify if the user has tiki_p_sendme_pages
if (!$userlib->user_has_permission($username, 'tiki_p_sendme_articles')) {
return new XML_RPC_Response(0, 101, "Permissions denied user $username cannot send articles to this site");
}
// Store the page in the tiki_received_pages_table
$title = base64_decode($title);
$authorName = base64_decode($authorName);
$image_data = base64_decode($image_data);
$heading = base64_decode($heading);
$body = base64_decode($body);
$commlib->receive_article(
$site,
$username,
$title,
$authorName,
$size,
$use_image,
$image_name,
$image_type,
$image_size,
$image_x,
$image_y,
$image_data,
$publishDate,
$expireDate,
$created,
$heading,
$body,
$hash,
$author,
$type,
$rating
);
return new XML_RPC_Response(new XML_RPC_Value(1, "boolean"));
}