function callRemote($method) { // Curl is required so generate a fault if curl functions cannot be found. if (!$this->curl) { return array('faultCode' => -1, 'faultString' => 'Curl functions are unavailable.'); } // The first argument will always be the method name while all remaining arguments need // to be passed along with the call. $args = func_get_args(); array_shift($args); if ($this->xmlrpc) { // If php has xmlrpc support use the built in functions. $request = xmlrpc_encode_request($method, $args); $result = $this->__xmlrpc_call($request); $decodedResult = xmlrpc_decode($result); } else { // If no xmlrpc support is found, use the phpxmlrpc library. This involves containing // all variables inside the xmlrpcval class. $encapArgs = array(); foreach ($args as $arg) { $encapArgs[] = $this->__phpxmlrpc_encapsulate($arg); } $msg = new xmlrpcmsg($method, $encapArgs); $client = new xmlrpc_client($this->url); $client->verifypeer = false; $result = $client->send($msg); if ($result->errno) { $decodedResult = array('faultCode' => $result->errno, 'faultString' => $result->errstr); } else { $decodedResult = php_xmlrpc_decode($result->value()); } } return $decodedResult; }
function unsubscribe_topic_func($xmlrpc_params) { global $db, $user; $user->setup('viewtopic'); $params = php_xmlrpc_decode($xmlrpc_params); // get topic id from parameters $topic_id = intval($params[0]); if (!$topic_id) { trigger_error('NO_TOPIC'); } $user_id = $user->data['user_id']; $uns_result = false; // Is user login? if ($user_id != ANONYMOUS) { $sql = 'SELECT notify_status FROM ' . TOPICS_WATCH_TABLE . "\n WHERE topic_id = {$topic_id}\n AND user_id = {$user_id}"; $result = $db->sql_query($sql); $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL; $db->sql_freeresult($result); if (!is_null($notify_status) && $notify_status !== '') { $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . "\n WHERE topic_id = {$topic_id}\n AND user_id = {$user_id}"; $db->sql_query($sql); $uns_result = true; } } $response = new xmlrpcval(array('result' => new xmlrpcval($uns_result, 'boolean'), 'result_text' => new xmlrpcval($uns_result ? '' : 'Unsubscribe failed', 'base64')), 'struct'); return new xmlrpcresp($response); }
function delete_message_func($xmlrpc_params) { global $db, $user, $config, $phpbb_root_path, $phpEx; $user->setup('ucp'); $params = php_xmlrpc_decode($xmlrpc_params); // get folder id from parameters $msg_id = intval($params[0]); $user_id = $user->data['user_id']; if (!$msg_id) { trigger_error('NO_MESSAGE'); } if (!$user->data['is_registered']) { trigger_error('LOGIN_EXPLAIN_UCP'); } // Is PM disabled? if (!$config['allow_privmsg']) { trigger_error('Module not accessible'); } $sql = 'SELECT folder_id FROM ' . PRIVMSGS_TO_TABLE . "\r\r\n WHERE user_id = {$user_id}\r\r\n AND msg_id = {$msg_id}"; $result = $db->sql_query_limit($sql, 1); $folder_id = (int) $db->sql_fetchfield('folder_id'); $db->sql_freeresult($result); include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; $result = delete_pm($user_id, $msg_id, $folder_id); $response = new xmlrpcval(array('result' => new xmlrpcval($result, 'boolean'), 'result_text' => new xmlrpcval($result ? '' : 'Delete message failed', 'base64')), 'struct'); return new xmlrpcresp($response); }
/** * Get request protocol based on Content-Type * * @return string default as xmlrpc */ protected function init() { $ver = phpversion(); if ($ver[0] >= 5) { $data = file_get_contents('php://input'); } else { $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; } if (count($_SERVER) == 0) { self::alert('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated'); } if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) { $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']); } else { $content_encoding = ''; } if ($content_encoding != '' && strlen($data)) { if ($content_encoding == 'deflate' || $content_encoding == 'gzip') { // if decoding works, use it. else assume data wasn't gzencoded if (function_exists('gzinflate')) { if ($content_encoding == 'deflate' && ($degzdata = @gzuncompress($data))) { $data = $degzdata; } elseif ($degzdata = @gzinflate(substr($data, 10))) { $data = $degzdata; } } else { self::alert('XML-RPC: ' . __METHOD__ . ': Received from client compressed HTTP request and cannot decompress'); } } } $parsers = php_xmlrpc_decode_xml($data); $this->cmd = $parsers->methodname; $this->input = php_xmlrpc_decode(new xmlrpcval($parsers->params, 'array')); }
/** * Returns current version number, support link, and reviews for the passed in extension name. Input 1=cms name, input 2=extension name. * @return string (or an xmlrpcresp obj instance if call fails) */ function _getExtensionData($cmsName, $extensionName) { #$client =& new xmlrpc_client('/cmsmarket/xmlrpc/index.php', 'localhost', 80); $client =& new xmlrpc_client('/xmlrpc/index.php', 'www.cmsmarket.com', 80); $client->return_type = 'xmlrpcvals'; $msg =& new xmlrpcmsg('CMSMarketItems.getExtensionDataBasic'); $p1 =& new xmlrpcval($cmsName, 'string'); $msg->addparam($p1); $p2 =& new xmlrpcval($extensionName, 'string'); $msg->addparam($p2); $res =& $client->send($msg, 0, ''); if ($res->faultcode()) { return $res; } else { $data = php_xmlrpc_decode($res->value()); if (isset($data['url'])) { $this->dataReturned = true; $this->name = $data['name']; $this->url = $data['url']; $this->supportPage = $data['support_page']; $this->currentVersion = $data['current_version']; $this->rating = html_entity_decode($data['rating']); } else { $this->dataReturned = false; } } }
function get_forum_func($xmlrpc_params) { $params = php_xmlrpc_decode($xmlrpc_params); $desc = isset($params[0]) ? true : false; $parent_id = isset($params[1]) ? intval($params[1]) : 0; global $db; $cats = $db->sql_ufetchrowset('SELECT cat_id, cat_title FROM ' . CATEGORIES_TABLE . ' ORDER BY cat_order', SQL_ASSOC); $forums = mobi_forums($parent_id); for ($i = 0, $c = count($cats); $i < $c; ++$i) { $cats[$i]['forum_id'] = $cats[$i]['cat_id'] + 99999; $cats[$i]['forum_name'] = $cats[$i]['cat_title']; $cats[$i]['parent_id'] = '-1'; $cats[$i]['sub_only'] = true; $cats[$i]['child'] = array(); foreach ($forums as &$forum) { if ($cats[$i]['cat_id'] != $forum['cat_id']) { continue; } if (!$forum['parent_id']) { $forum['parent_id'] = $forum['cat_id'] + 99999; } $cats[$i]['child'][] = assocToStruct($forum); unset($forum); } if (empty($cats[$i]['child'])) { unset($cats[$i]); continue; } $cats[$i] = assocToStruct($cats[$i], $desc); } return new xmlrpcresp(new xmlrpcval($cats, 'array')); }
function mark_pm_unread_func($xmlrpc_params) { global $db, $auth, $user, $config; $params = php_xmlrpc_decode($xmlrpc_params); $msg_id = intval($params[0]); $user->setup('ucp'); $message_row = array(); // Get Message user want to see $sql = 'SELECT t.*, p.*, u.* FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE t.user_id = ' . $user->data['user_id'] . "\r\r\n AND p.author_id = u.user_id\r\r\n AND t.msg_id = p.msg_id\r\r\n AND p.msg_id = {$msg_id}"; $result = $db->sql_query($sql); $message_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $folder_id = $message_row['folder_id']; $user_id = $user->data['user_id']; if (!$message_row) { trigger_error('NO_MESSAGE'); } $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "\r\r\n\t\tSET pm_unread = 1\r\r\n\t\tWHERE msg_id = {$msg_id}\r\r\n\t\t\tAND user_id = {$user_id}\r\r\n\t\t\tAND folder_id = {$folder_id}"; $db->sql_query($sql); $sql = 'UPDATE ' . USERS_TABLE . "\r\r\n\t\tSET user_unread_privmsg = user_unread_privmsg + 1\r\r\n\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); if ($user->data['user_id'] == $user_id) { $user->data['user_unread_privmsg']++; // Try to cope with previous wrong conversions... if ($user->data['user_unread_privmsg'] < 0) { $sql = 'UPDATE ' . USERS_TABLE . "\r\r\n\t\t\t\tSET user_unread_privmsg = 0\r\r\n\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); $user->data['user_unread_privmsg'] = 0; } } return xmlresptrue(); }
function addcomment($m) { global $xmlrpcerruser; $err = ""; // get the first param $msgID = php_xmlrpc_decode($m->getParam(0)); $name = php_xmlrpc_decode($m->getParam(1)); $comment = php_xmlrpc_decode($m->getParam(2)); $dbh = dba_open("/tmp/comments.db", "c", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); } else { $count = 0; } // add the new comment in dba_insert($msgID . "_comment_{$count}", $comment, $dbh); dba_insert($msgID . "_name_{$count}", $name, $dbh); $count++; dba_replace($countID, $count, $dbh); dba_close($dbh); } else { $err = "Unable to open comments database."; } // if we generated an error, create an error return response if ($err) { return new xmlrpcresp(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response // with the state name return new xmlrpcresp(new xmlrpcval($count, "int")); } }
function getcomments($m) { global $xmlrpcerruser; $err = ""; $ra = array(); // get the first param if (XMLRPC_EPI_ENABLED == '1') { $msgID = xmlrpc_decode($m->getParam(0)); } else { $msgID = php_xmlrpc_decode($m->getParam(0)); } $dbh = dba_open("/tmp/comments.db", "r", "db2"); if ($dbh) { $countID = "{$msgID}_count"; if (dba_exists($countID, $dbh)) { $count = dba_fetch($countID, $dbh); for ($i = 0; $i < $count; $i++) { $name = dba_fetch("{$msgID}_name_{$i}", $dbh); $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh); // push a new struct onto the return array $ra[] = array("name" => $name, "comment" => $comment); } } } // if we generated an error, create an error return response if ($err) { return new xmlrpcresp(0, $xmlrpcerruser, $err); } else { // otherwise, we create the right response // with the state name return new xmlrpcresp(php_xmlrpc_encode($ra)); } }
public function get_sysinfo() { $msgs = array(); $msgs[] = new xmlrpcmsg('system.client_version', array()); $msgs[] = new xmlrpcmsg('system.library_version', array()); $msgs[] = new xmlrpcmsg('get_down_rate', array()); $msgs[] = new xmlrpcmsg('get_up_rate', array()); $msgs[] = new xmlrpcmsg('get_directory', array()); $resps = $this->_rpc->multicall($msgs); $values = array(); foreach ($resps as $r) { $values[] = php_xmlrpc_decode($r->value()); } $values = array_combine(array('version', 'lib_version', 'downrate', 'uprate', 'directory'), $values); $values['downrate'] = round($values['downrate'] / 1024, 2) . 'K'; $values['uprate'] = round($values['uprate'] / 1024, 2) . 'K'; if (is_dir($values['directory'])) { $values['have_disk_space'] = true; $disk_total = disk_total_space($values['directory']); $disk_free = disk_free_space($values['directory']); $disk_used = round($disk_total - $disk_free); $values['disk_total'] = $disk_total; $values['disk_free'] = $disk_free; $values['disk_used'] = $disk_used; $values['disk_percent_used'] = round($disk_used / $disk_total * 100); $values['disk_percent_free'] = round($disk_free / $disk_total * 100); } else { $values['have_disk_space'] = false; } return $values; }
function get_quote_pm_func($xmlrpc_params) { global $db, $auth, $user; $user->setup('ucp'); $params = php_xmlrpc_decode($xmlrpc_params); // get msg id from parameters $msg_id = intval($params[0]); if (!$msg_id) { trigger_error('NO_MESSAGE'); } if (!$auth->acl_get('u_sendpm')) { trigger_error('NO_AUTH_SEND_MESSAGE'); } $sql = 'SELECT p.*, u.username as quote_username FROM ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE p.author_id = u.user_id AND p.msg_id = ' . $msg_id; $result = $db->sql_query($sql); $post = $db->sql_fetchrow($result); $db->sql_freeresult($result); $msg_id = (int) $post['msg_id']; if (!$post) { trigger_error('NO_MESSAGE'); } if ((!$post['author_id'] || $post['author_id'] == ANONYMOUS && $action != 'delete') && $msg_id) { trigger_error('NO_AUTHOR'); } $message_subject = (!preg_match('/^Re:/', $post['message_subject']) ? 'Re: ' : '') . censor_text($post['message_subject']); decode_message($post['message_text'], $post['bbcode_uid']); $message = '[quote="' . $post['quote_username'] . '"]' . censor_text(trim($post['message_text'])) . "[/quote]\n"; return new xmlrpcresp(new xmlrpcval(array('msg_id' => new xmlrpcval($msg_id), 'msg_subject' => new xmlrpcval(html_entity_decode(strip_tags($message_subject)), 'base64'), 'text_body' => new xmlrpcval(html_entity_decode($message), 'base64')), 'struct')); }
function login_func($xmlrpc_params) { global $auth, $user, $config, $db, $phpbb_root_path, $phpEx; $params = php_xmlrpc_decode($xmlrpc_params); $user->setup('ucp'); $username = $params[0]; $password = $params[1]; $viewonline = isset($params[2]) ? !$params[2] : 1; set_var($username, $username, 'string', true); set_var($password, $password, 'string', true); header('Set-Cookie: mobiquo_a=0'); header('Set-Cookie: mobiquo_b=0'); header('Set-Cookie: mobiquo_c=0'); $login_result = $auth->login($username, $password, true, $viewonline); $usergroup_id = array(); if ($login_result['status'] == LOGIN_SUCCESS) { $auth->acl($user->data); //add tapatalk_users here,for push service if ($params[3] == '1' && push_table_exists()) { global $table_prefix; $sql = "SELECT * FROM " . $table_prefix . "tapatalk_users where userid = '" . $user->data['user_id'] . "'"; $result = $db->sql_query($sql); $userInfo = $db->sql_fetchrow($result); $db->sql_freeresult($result); $time = time(); if (empty($userInfo)) { $sql_data[$table_prefix . "tapatalk_users"]['sql'] = array('userid' => $user->data['user_id'], 'announcement' => 1, 'pm' => 1, 'subscribe' => 1, 'quote' => 1, 'tag' => 1, 'newtopic' => 1, 'updated' => time()); $sql = 'INSERT INTO ' . $table_prefix . "tapatalk_users" . ' ' . $db->sql_build_array('INSERT', $sql_data[$table_prefix . "tapatalk_users"]['sql']); $db->sql_query($sql); } else { $sql = "UPDATE " . $table_prefix . "tapatalk_users \n\t \tSET updated= '" . time() . "' WHERE userid='" . $user->data['user_id'] . "'"; $db->sql_query($sql); } } // Compatibility with mod NV who was here if (file_exists($phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx)) { include_once $phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx; if (class_exists('phpbb_mods_who_was_here') && method_exists('phpbb_mods_who_was_here', 'update_session')) { @phpbb_mods_who_was_here::update_session(); } } } else { $error_msg = str_replace('%s', '', strip_tags($user->lang[$login_result['error_msg']])); return new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'result_text' => new xmlrpcval($error_msg, 'base64')), 'struct')); } if ($config['max_attachments'] == 0) { $config['max_attachments'] = 100; } $usergroup_id[] = new xmlrpcval($user->data['group_id']); $can_readpm = $config['allow_privmsg'] && $auth->acl_get('u_readpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')); $can_sendpm = $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')); $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && (function_exists('phpbb_is_writable') ? phpbb_is_writable($phpbb_root_path . $config['avatar_path']) : 1) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false; $can_search = $auth->acl_get('u_search') && $auth->acl_getf_global('f_search') && $config['load_search']; $can_whosonline = $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'); $max_filesize = $config['max_filesize'] === '0' || $config['max_filesize'] > 10485760 ? 10485760 : $config['max_filesize']; $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'user_id' => new xmlrpcval($user->data['user_id'], 'string'), 'username' => new xmlrpcval($user->data['username'], 'base64'), 'usergroup_id' => new xmlrpcval($usergroup_id, 'array'), 'icon_url' => new xmlrpcval(get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']), 'string'), 'post_count' => new xmlrpcval($user->data['user_posts'], 'int'), 'can_pm' => new xmlrpcval($can_readpm, 'boolean'), 'can_send_pm' => new xmlrpcval($can_sendpm, 'boolean'), 'can_moderate' => new xmlrpcval($auth->acl_get('m_') || $auth->acl_getf_global('m_'), 'boolean'), 'max_attachment' => new xmlrpcval($config['max_attachments'], 'int'), 'max_png_size' => new xmlrpcval($max_filesize, 'int'), 'max_jpg_size' => new xmlrpcval($max_filesize, 'int'), 'can_search' => new xmlrpcval($can_search, 'boolean'), 'can_whosonline' => new xmlrpcval($can_whosonline, 'boolean'), 'can_upload_avatar' => new xmlrpcval($can_upload, 'boolean')), 'struct'); return new xmlrpcresp($response); }
function get_id_by_url_func($xmlrpc_params) { global $phpbb_home; $params = php_xmlrpc_decode($xmlrpc_params); $url = trim($params[0]); if (strpos($url, $phpbb_home) === 0) { $path = '/' . substr($url, strlen($phpbb_home)); $fid = $tid = $pid = ""; // get forum id if (preg_match('/(\\?|&|;)(f|fid|board)=(\\d+)(\\W|$)/', $path, $match)) { $fid = $match['3']; } elseif (preg_match('/\\W(f|forum)-?(\\d+)(\\W|$)/', $path, $match)) { $fid = $match['2']; } elseif (preg_match('/\\/forum\\/(\\d+)-(\\w|-)+(\\W|$)/', $path, $match)) { $fid = $match['1']; $path = str_replace($match[0], $match[3], $path); } elseif (preg_match('/forumdisplay\\.php(\\?|\\/)(\\d+)(\\W|$)/', $path, $match)) { $fid = $match['2']; $path = str_replace($match[0], $match[3], $path); } elseif (preg_match('/(index\\.php\\?|\\/)forums\\/.+\\.(\\d+)/', $path, $match)) { $fid = $match['2']; } // get topic id if (preg_match('/(\\?|&|;)(t|tid|topic)=(\\d+)(\\W|$)/', $path, $match)) { $tid = $match['3']; } elseif (preg_match('/\\W(t|(\\w|-)+-t_|topic|article)-?(\\d+)(\\W|$)/', $path, $match)) { $tid = $match['3']; } elseif (preg_match('/showthread\\.php(\\?|\\/)(\\d+)(\\W|$)/', $path, $match)) { $tid = $match['2']; } elseif (preg_match('/(\\?|\\/)(\\d+)-(\\w|-)+(\\.|\\/|$)/', $path, $match)) { $tid = $match['2']; } elseif (preg_match('/(\\?|\\/)(\\w|-)+-(\\d+)(\\.|\\/|$)/', $path, $match)) { $tid = $match['3']; } elseif (preg_match('/(index\\.php\\?|\\/)threads\\/.+\\.(\\d+)/', $path, $match)) { $tid = $match['2']; } // get post id if (preg_match('/(\\?|&|;)(p|pid)=(\\d+)(\\W|$)/', $path, $match)) { $pid = $match['3']; } elseif (preg_match('/\\W(p|(\\w|-)+-p|post|msg)(-|_)?(\\d+)(\\W|$)/', $path, $match)) { $pid = $match['4']; } elseif (preg_match('/__p__(\\d+)(\\W|$)/', $path, $match)) { $pid = $match['1']; } } $result = array(); if ($fid) { $result['forum_id'] = new xmlrpcval($fid, 'string'); } if ($tid) { $result['topic_id'] = new xmlrpcval($tid, 'string'); } if ($pid) { $result['post_id'] = new xmlrpcval($pid, 'string'); } $response = new xmlrpcval($result, 'struct'); return new xmlrpcresp($response); }
public static function filterXmlInput(array $filters, $xmlrpc_params) { global $db, $mybb; require_once MYBB_ROOT . $mybb->settings['tapatalk_directory'] . '/emoji/emoji.class.php'; $params = php_xmlrpc_decode($xmlrpc_params); // handle upload requests etc. if (empty($params) && !empty($_POST['method_name'])) { $params = array(); foreach ($filters as $name => $type) { if (isset($_POST[$name])) { $params[] = $_POST[$name]; } } } $data = array(); $i = 0; foreach ($filters as $name => $type) { switch ($type) { case self::INT: if (isset($params[$i])) { $data[$name] = intval($params[$i]); } else { $data[$name] = 0; } break; case self::ALPHASTRING: if (isset($params[$i])) { $data[$name] = preg_replace("#[^a-z\\.\\-_]#i", "", $params[$i]); } else { $data[$name] = ''; } $data[$name . '_esc'] = $db->escape_string($data[$name]); break; case self::STRING: if (isset($params[$i])) { if ($name == 'subject' || $name == 'post_title' || $name == 'title') { $data[$name] = tapatalkEmoji::covertUnifiedToEmpty($params[$i]); } else { $data[$name] = tapatalkEmoji::covertEmojiToName($params[$i]); } } else { $data[$name] = ''; } $data[$name . '_esc'] = $db->escape_string($data[$name]); break; case self::RAW: $data[$name] = $params[$i]; break; } $i++; } return $data; }
function mark_all_as_read_func($xmlrpc_params) { $params = php_xmlrpc_decode($xmlrpc_params); if (!isset($params[0]) || $params[0] === 0) { markread('all'); } else { $forum_id = intval($params[0]); markread('topics', $forum_id); } $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'result_text' => new xmlrpcval('', 'base64')), 'struct'); return new xmlrpcresp($response); }
/** * XML-RPC routine to add a response to the survey table * Returns the id of the inserted survey response * * @param array $request Array containing the following elements (in that order): * - Session key (string) * - Survey ID (integer) * - ResponseData (array) * */ function addResponse($request) { global $connect, $dbprefix; if (!is_object($request)) { die; } if ($request->getNumParams() != 3) { return new xmlrpcresp(0, 3, 'Missing parameters'); } $sSessionKey = $request->getParam(0)->scalarVal(); $iSurveyID = (int) $request->getParam(1)->scalarVal(); $aResponseData = php_xmlrpc_decode($request->getParam(2)); if (!is_array($aResponseData)) { return new xmlrpcresp(0, '14', 'Survey data is not in array form'); } $uid = _doLogin(); if ($uid) { if (bHasSurveyPermission($iSurveyID, 'responses', 'create', $uid)) { $surveytable = db_table_name("survey_" . $iSurveyID); if (!db_tables_exist($dbprefix . "survey_" . $iSurveyID)) { return new xmlrpcresp(0, '12', 'No survey table'); } //set required values if not set if (!isset($aResponseData['submitdate'])) { $aResponseData['submitdate'] = date("Y-m-d H:i:s"); } if (!isset($aResponseData['datestamp'])) { $aResponseData['datestamp'] = date("Y-m-d H:i:s"); } if (!isset($aResponseData['startdate'])) { $aResponseData['startdate'] = date("Y-m-d H:i:s"); } if (!isset($aResponseData['startlanguage'])) { $aResponseData['startlanguage'] = GetBaseLanguageFromSurveyID($iSurveyID); } $SQL = "INSERT INTO {$surveytable}\n (" . implode(',', array_keys($aResponseData)) . ")\n VALUES\n (" . implode(',', array_map('db_quoteall', $aResponseData)) . ")"; $iinsert = $connect->Execute($SQL); if ($iinsert) { $thisid = $connect->Insert_ID(); return new xmlrpcresp(new xmlrpcval($thisid, 'int')); } else { //Failed to insert return error return new xmlrpcresp(0, '13', 'Unable to add response'); } } else { return new xmlrpcresp(0, '2', 'No permission'); } } die; }
function dispatch($client, $method, $args) { $msg = new xmlrpcmsg($method, $args); $resp = $client->send($msg); if (!$resp) { print "<p>IO error: " . $client->errstr . "</p>"; bomb(); } if ($resp->faultCode()) { print "<p>There was an error: " . $resp->faultCode() . " " . $resp->faultString() . "</p>"; bomb(); } return php_xmlrpc_decode($resp->value()); }
function report_pm_func($xmlrpc_params) { global $db, $user, $config; $user->setup('mcp'); $params = php_xmlrpc_decode($xmlrpc_params); $post_id = 0; $pm_id = intval($params[0]); $report_text = utf8_normalize_nfc($params[1]); $reason_id = intval($params[2]) ? intval($params[2]) : 2; $forum_id = intval($params[3]) ? intval($params[3]) : ''; $user_notify = true; if (!$pm_id || !$config['allow_pm_report']) { trigger_error('NO_POST_SELECTED'); } // Grab all relevant data $sql = 'SELECT p.*, pt.* FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt\r\r\n WHERE p.msg_id = {$pm_id}\r\r\n AND p.msg_id = pt.msg_id\r\r\n AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")"; $result = $db->sql_query($sql); $report_data = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$report_data) { $user->add_lang('ucp'); trigger_error('NO_MESSAGE'); } if ($report_data['message_reported']) { trigger_error('ALREADY_REPORTED_PM'); } $sql = 'SELECT * FROM ' . REPORTS_REASONS_TABLE . "\r\r\n WHERE reason_id = {$reason_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row || !$report_text && strtolower($row['reason_title']) == 'other') { trigger_error('EMPTY_REPORT'); } $sql_ary = array('reason_id' => (int) $reason_id, 'post_id' => $post_id, 'pm_id' => $pm_id, 'user_id' => (int) $user->data['user_id'], 'user_notify' => (int) $user_notify, 'report_closed' => 0, 'report_time' => (int) time(), 'report_text' => (string) $report_text); $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $report_id = $db->sql_nextid(); $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET message_reported = 1 WHERE msg_id = ' . $pm_id; $db->sql_query($sql); $sql_ary = array('msg_id' => $pm_id, 'user_id' => ANONYMOUS, 'author_id' => (int) $report_data['author_id'], 'pm_deleted' => 0, 'pm_new' => 0, 'pm_unread' => 0, 'pm_replied' => 0, 'pm_marked' => 0, 'pm_forwarded' => 0, 'folder_id' => PRIVMSGS_INBOX); $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $result = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean')), 'struct'); return new xmlrpcresp($result); }
/** * Connects to the Mail API and calls the desired * function with the specified parameters * * @param method to invoke and parameters for the method * @return mixed */ public function executeMethod($method, $params) { $host = getenv("MAILAPI_URL") ? getenv("MAILAPI_URL") : MAILAPI_ENDPOINT; $params['apikey'] = new xmlrpcval($this->apikey); $xmlrpcmsg = new xmlrpcmsg($method, array(new xmlrpcval($params, 'struct'))); $xmlrpc_client = new xmlrpc_client($host); $xmlrpc_client->request_charset_encoding = "UTF-8"; $xmlrpc_client->SetUserAgent(MAILAPI_PARTNER . "/PHP/v" . MAILAPI_VERSION); $response = $xmlrpc_client->send($xmlrpcmsg); if (!$response->faultCode()) { return php_xmlrpc_decode($response->value()); } else { return new MAILAPI_Error($response->faultCode(), $response->faultString()); } }
/** * <MethodDescription> * * @param string <description> * * @return mixed <description> */ function dispatch($msg = NULL) { # ensure correct invocation if (is_null($msg) || !is_a($msg, 'xmlrpcmsg')) { return $this->throw_exception('functions_parameters_type must not be ' . 'phpvals.'); } # get decoded parameters $len = $msg->getNumParams(); $argument_array = array(); for ($i = 0; $i < $len; ++$i) { $argument_array[] = php_xmlrpc_decode($msg->getParam($i)); } # return result return new xmlrpcresp(php_xmlrpc_encode($this->invoke($msg->method(), $argument_array))); }
function do_call($call) { global $client; // Do call and handle feedback if (!($res = $client->send($call))) { print "Could not connect to HTTPS server."; return FALSE; } if ($res->faultCode() == 0) { $value = $res->value(); return php_xmlrpc_decode($value); } else { print "XML-RPC Fault #" . $res->faultCode() . ": " . $res->faultString(); return FALSE; } }
function sendXmlRpc($sMessage, $aParam) { $r_client = new xmlrpc_client(ADDR_XMLRPC_ENTERPOINT, ADDR_XMLRPC_SERVER, 80); foreach ($aParam as $k => $v) { $aParam[$k] = php_xmlrpc_encode($v); } $r_message = new xmlrpcmsg($sMessage, $aParam); //$c->setDebug(1); $response =& $r_client->send($r_message); if ($response->faultCode()) { return $response; return 'xmlrpc-error: ' . $file . ' [' . $r->faultCode() . '] ' . $r->faultString(); } $value = $response->value(); return php_xmlrpc_decode($value); }
/** * Forward an xmlrpc request to another server, and return to client the response received. * @param xmlrpcmsg $m (see method docs below for a description of the expected parameters) * @return xmlrpcresp */ function forward_request($m) { // create client $timeout = 0; $url = php_xmlrpc_decode($m->getParam(0)); $c = new xmlrpc_client($url); if ($m->getNumParams() > 3) { // we have to set some options onto the client. // Note that if we do not untaint the received values, warnings might be generated... $options = php_xmlrpc_decode($m->getParam(3)); foreach ($options as $key => $val) { switch ($key) { case 'Cookie': break; case 'Credentials': break; case 'RequestCompression': $c->setRequestCompression($val); break; case 'SSLVerifyHost': $c->setSSLVerifyHost($val); break; case 'SSLVerifyPeer': $c->setSSLVerifyPeer($val); break; case 'Timeout': $timeout = (int) $val; break; } // switch } } // build call for remote server /// @todo find a weay to forward client info (such as IP) to server, either /// - as xml comments in the payload, or /// - using std http header conventions, such as X-forwarded-for... $method = php_xmlrpc_decode($m->getParam(1)); $pars = $m->getParam(2); $m = new xmlrpcmsg($method); for ($i = 0; $i < $pars->arraySize(); $i++) { $m->addParam($pars->arraymem($i)); } // add debug info into response we give back to caller xmlrpc_debugmsg("Sending to server {$url} the payload: " . $m->serialize()); return $c->send($m, $timeout); }
function authorize_user_func($xmlrpc_params = '') { global $db, $prefix; $params = php_xmlrpc_decode($xmlrpc_params); header('Set-Cookie: mobiquo_a=0'); header('Set-Cookie: mobiquo_b=0'); header('Set-Cookie: mobiquo_c=0'); $username = $params[0]; $password = MD5($params[1]); $sql = "SELECT user_id from " . $prefix . "_users WHERE username='******' AND user_password='******' AND user_level='1' AND user_active='1' "; $result = $db->sql_query($sql); $login_status = false; if ($db->sql_numrows($result) != NULL) { $login_status = true; } $response = new xmlrpcval(array('authorize_result' => new xmlrpcval($login_status, 'boolean')), 'struct'); return new xmlrpcresp($response); }
function update_push_status_func($xmlrpc_params) { global $db, $auth, $user, $config, $table_prefix; $params = php_xmlrpc_decode($xmlrpc_params); if (!empty($params[1]) && !empty($params[2]) && empty($user->data['is_registered'])) { $user->setup('ucp'); $username = $params[1]; $password = $params[2]; $viewonline = 1; set_var($username, $username, 'string', true); set_var($password, $password, 'string', true); header('Set-Cookie: mobiquo_a=0'); header('Set-Cookie: mobiquo_b=0'); header('Set-Cookie: mobiquo_c=0'); $auth->login($username, $password, true, $viewonline); } if ($user->data['is_registered'] == 1) { $update_params = array(); if (isset($params[0]['all'])) { $update_params['announcement'] = $params[0]['all'] ? 1 : 0; $update_params['pm'] = $params[0]['all'] ? 1 : 0; $update_params['subscribe'] = $params[0]['all'] ? 1 : 0; $update_params['quote'] = $params[0]['all'] ? 1 : 0; $update_params['tag'] = $params[0]['all'] ? 1 : 0; $update_params['newtopic'] = $params[0]['all'] ? 1 : 0; } else { $update_params['announcement'] = isset($params[0]['ann']) ? $params[0]['ann'] : 1; $update_params['pm'] = isset($params[0]['pm']) ? $params[0]['pm'] : 1; $update_params['subscribe'] = isset($params[0]['sub']) ? $params[0]['sub'] : 1; $update_params['quote'] = isset($params[0]['quote']) ? $params[0]['quote'] : 1; $update_params['tag'] = isset($params[0]['tag']) ? $params[0]['tag'] : 1; $update_params['newtopic'] = isset($params[0]['newtopic']) ? $params[0]['newtopic'] : 1; } $sql = 'UPDATE ' . $table_prefix . "tapatalk_users SET announcement = '" . $update_params['announcement'] . "',pm='" . $update_params['pm'] . "',\n\t\tsubscribe = '" . $update_params['subscribe'] . "',quote = '" . $update_params['quote'] . "',tag = '" . $update_params['tag'] . "',newtopic='" . $update_params['newtopic'] . "'\n\t\tWHERE userid = '" . $user->data['user_id'] . "'"; $result = $db->sql_query($sql); if ($result) { return new xmlrpcresp(new xmlrpcval(true, 'boolean')); } else { return new xmlrpcresp(new xmlrpcval(false, 'boolean')); } } }
public function update() { global $config; $host = $config['host']; $port = $config['port']; $user = $config['user']; $passwd = $config['passwd']; $f = new xmlrpcmsg("status", ""); //echo "<PRE>Sending the following request:<BR>" . htmlentities($f->serialize()) . "</PRE>\n"; $c = new xmlrpc_client("", $host, $port); $c->setCredentials($user, $passwd); $c->setDebug(0); $r = $c->send($f); if (!$r->faultCode()) { //Got a valid result, decode into php variables return php_xmlrpc_decode($r->value()); } else { return array('code' => $r->faultCode(), 'reason' => $r->faultString()); } }
public function sendWithoutAddingKey($method, $args, $retry = false) { $encoded_arguments = array(); foreach ($args as $argument) { $encoded_arguments[] = php_xmlrpc_encode($argument, array('auto_dates')); } $call = new xmlrpcmsg($method, $encoded_arguments); $attempts = 0; $start = time(); $req = null; do { if ($attempts > 0) { if (class_exists('CakeLog') && $attempts > 1) { $lastAttemptFaultCode = $req->faultCode(); $lastAttemptFaultString = $req->faultString(); } sleep(5); } $attempts++; $req = $this->client->send($call, $this->timeout, 'https'); } while ($retry && ($req->faultCode() == $GLOBALS['xmlrpcerr']['invalid_return'] || $req->faultCode() == $GLOBALS['xmlrpcerr']['curl_fail'] || strpos($req->faultString(), 'com.infusionsoft.throttle.ThrottlingException: Maximum number of threads throttled') !== false) && $attempts < 3); $this->totalHttpCalls += $attempts; if (!$req->faultCode()) { $result = php_xmlrpc_decode($req->value()); } else { $result = array(); } if (is_object($this->Logger)) { $this->Logger->log(array('time' => date('Y-m-d H:i:s'), 'duration' => time() - $start, 'method' => $method, 'args' => $args, 'attempts' => $attempts, 'result' => $req->faultCode() ? 'Failed' : count($result) . ' Records Returned', 'error_message' => $req->faultCode() ? $req->faultString() : null)); } if ($req->faultCode()) { $exception = new Infusionsoft_Exception($req->faultString() . "\nAttempted: {$attempts} time(s).", $method, $args); $this->addException($exception); throw $exception; return FALSE; } if ($attempts > 2) { CakeLog::write('notice', "Infusionsoft call required {$attempts} calls to receive a successful response. Method: {$method} FaultCode: {$lastAttemptFaultCode} FaultString: {$lastAttemptFaultString}"); } return $result; }
function mobi_parse_requrest() { global $request_method, $request_params, $params_num; $ver = phpversion(); if ($ver[0] >= 5) { $data = file_get_contents('php://input'); } else { $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; } if (count($_SERVER) == 0) { $r = new xmlrpcresp('', 15, 'XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated'); echo $r->serialize('UTF-8'); exit; } if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) { $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']); } else { $content_encoding = ''; } if ($content_encoding != '' && strlen($data)) { if ($content_encoding == 'deflate' || $content_encoding == 'gzip') { // if decoding works, use it. else assume data wasn't gzencoded if (function_exists('gzinflate')) { if ($content_encoding == 'deflate' && ($degzdata = @gzuncompress($data))) { $data = $degzdata; } elseif ($degzdata = @gzinflate(substr($data, 10))) { $data = $degzdata; } } else { $r = new xmlrpcresp('', 106, 'Received from client compressed HTTP request and cannot decompress'); echo $r->serialize('UTF-8'); exit; } } } $parsers = php_xmlrpc_decode_xml($data); $request_method = $parsers->methodname; $request_params = php_xmlrpc_decode(new xmlrpcval($parsers->params, 'array')); $params_num = count($request_params); }
/** * Calls specified API method with optional arguments * * @param string $method API method name * @param array $arguments Method arguments. Each item is an array in format:<pre> * [0] => Argument value * [1] => Argument type ('array', 'int', 'string') * [2] => If not empty - marks argument as optional. In this case, if value is null, argument won't be passed * </pre> * * @return mixed null on error */ private function _request($method, $arguments = array()) { $client = $this->_getClient(); if (!$client) { return null; } $params = array(); foreach ($arguments as $argument) { if (!$argument || !empty($argument[2]) && $argument[0] === null) { break; } $params[] = new \xmlrpcval($argument[0], $argument[1]); } $msg = new \xmlrpcmsg($method, $params); $res = $client->send($msg); if ($res->faultCode()) { $this->_lastError = $res->faultString(); return null; } $this->_lastError = null; return php_xmlrpc_decode($res->value()); }
function login_func($xmlrpc_params) { global $prefix, $user_prefix, $db, $userinfo, $MAIN_CFG; $params = php_xmlrpc_decode($xmlrpc_params); // $user->setup('ucp'); $username = $params[0]; $password = MD5($params[1]); $userinfo['username'] = $username; print_r($userinfo); // set_var($username, $username, 'string', true); // set_var($password, $password, 'string', true); // header('Set-Cookie: mobiquo_a=0'); // header('Set-Cookie: mobiquo_b=0'); // header('Set-Cookie: mobiquo_c=0'); $usergroup_id = array(); $sql = "SELECT user_id from " . $prefix . "_users WHERE username='******' AND user_password='******' AND user_level!='0' AND user_active='1' "; $result = $db->sql_query($sql); $login_status = false; if ($db->sql_numrows($result) != NULL) { $login_status = true; $error_msg = ''; while ($row = $db->sql_fetchrow($result)) { $user_id = $row['user_id']; $userinfo['user_id'] = $user_id; } $sql = "SELECT *\n FROM " . $prefix . "_users\n WHERE user_id = {$user_id}"; $result = $db->sql_query($sql); $user_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); $usergroup_id[] = new xmlrpcval($user_info['user_group_list_cp']); } else { $login_status = false; $error_msg = $sql; $user_id = ''; } $response = new xmlrpcval(array('result' => new xmlrpcval($login_status, 'boolean'), 'result_text' => new xmlrpcval($error_msg, 'base64'), 'user_id' => new xmlrpcval($user_id, 'string'), 'can_pm' => new xmlrpcval($config['allow_privmsg'] ? true : false, 'boolean'), 'can_send_pm' => new xmlrpcval($config['allow_privmsg'] ? true : false, 'boolean'), 'usergroup_id' => new xmlrpcval($usergroup_id, 'array')), 'struct'); return new xmlrpcresp($response); }