Go to the source code of this file.
Data Structures | |
| class | Trans |
| (c) 2004-2007 Linbox / Free&ALter Soft, http://linbox.com (c) 2007-2008 Mandriva, http://www.mandriva.com More... | |
Functions | |
| decode_entities ($text) | |
| FIXME: to remove function wich decode UTF-8 Entity with ref  for example need because XMLRPC server doest not like this sort of encoding. | |
| findErrorHandling ($errorFaultCode) | |
| try to find an ErrorHandlingItem for $errorFaultCode | |
| isXMLRPCError () | |
| openSocket ($proto, $conf) | |
| Return a socket object. | |
| prepare_string ($pass) | |
| Return a Trans object so that a potentially non XML-safe string can be sent into the XML-RPC stream. | |
| xmlCall ($method, $params=null) | |
| Make a XML-RPC call If the global variable $errorStatus is not zero, the XML-RPC call is not done, and this function returns nothing. | |
| decode_entities | ( | $ | text | ) |
FIXME: to remove function wich decode UTF-8 Entity with ref  for example need because XMLRPC server doest not like this sort of encoding.
Definition at line 54 of file xmlrpc.inc.php.
00054 { 00055 $text = html_entity_decode($text,ENT_QUOTES,"ISO-8859-1"); /* NOTE: UTF-8 does not work! */ 00056 $text= preg_replace('/&#(\d+);/me',"chr(\\1)",$text); /* decimal notation */ 00057 $text= preg_replace('/&#x([a-f0-9]+);/mei',"chr(0x\\1)",$text); /* hex notation */ 00058 return $text; 00059 }
| findErrorHandling | ( | $ | errorFaultCode | ) |
try to find an ErrorHandlingItem for $errorFaultCode
Definition at line 339 of file xmlrpc.inc.php.
References $errObj.
Referenced by xmlCall().
00339 { 00340 require("includes/commonErrorHandling.php"); 00341 00342 if (!empty($_GET["module"])) { 00343 $errorfile = "modules/".$_GET["module"]."/includes/errorHandling.php"; 00344 if (file_exists($errorfile)) { 00345 require($errorfile); 00346 } 00347 } 00348 00349 if (isset($errObj)) { //if error obj is set 00350 return ($errObj->handle($errorFaultCode)); 00351 } else { 00352 return -1; 00353 } 00354 }
| isXMLRPCError | ( | ) |
Definition at line 98 of file xmlrpc.inc.php.
Referenced by auth_user(), callPluginFunction(), create_group(), and xmlCall().
| openSocket | ( | $ | proto, | |
| $ | conf | |||
| ) |
Return a socket object.
Definition at line 64 of file xmlrpc.inc.php.
References $_SESSION, and $conf.
Referenced by xmlCall().
00064 { 00065 $errLevel = error_reporting(); 00066 error_reporting(0); 00067 if (($proto != "ssl://") 00068 || ($conf[$_SESSION["agent"]]["verifypeer"] != 1) 00069 || !function_exists("stream_socket_client")) { 00070 /* 00071 Not a SSL connection, 00072 or simple SSL connection without client certificate and server 00073 certificate check 00074 or stream_socket_client function not available (PHP 5 only), 00075 */ 00076 $sock = fsockopen($proto.$_SESSION["XMLRPC_agent"]["host"], $_SESSION["XMLRPC_agent"]["port"], $errNo, $errString); 00077 $ret = array($sock, $errNo, $errString); 00078 } else { 00079 $context = stream_context_create(); 00080 stream_context_set_option($context, "ssl", "allow_self_signed", False); 00081 stream_context_set_option($context, "ssl", "verify_peer", True); 00082 stream_context_set_option($context, "ssl", "cafile", $conf[$_SESSION["agent"]]["cacert"]); 00083 stream_context_set_option($context, "ssl", "local_cert", $conf[$_SESSION["agent"]]["localcert"]); 00084 $sock = stream_socket_client('tls://'.$_SESSION["XMLRPC_agent"]["host"].":".$_SESSION["XMLRPC_agent"]["port"], $errNo, $errString, ini_get("default_socket_timeout"), STREAM_CLIENT_CONNECT, $context); 00085 $ret = array($sock, $errNo, $errString); 00086 } 00087 error_reporting($errLevel); 00088 if ($sock !== False) { 00089 /* Setting timeout on a SSL socket only works with PHP >= 5.2.1 */ 00090 stream_set_timeout($sock, $conf[$_SESSION["agent"]]["timeout"]); 00091 } 00092 return $ret; 00093 }
| prepare_string | ( | $ | pass | ) |
Return a Trans object so that a potentially non XML-safe string can be sent into the XML-RPC stream.
e.g. a password can contains the & character, so the password string must be encoded.
Definition at line 40 of file xmlrpc.inc.php.
Referenced by add_user(), addSmbAttr(), auth_user(), and check_auth().
00040 { 00041 $obj = new Trans(); 00042 $obj->scalar = "$pass"; 00043 $obj->xmlrpc_type = "base64"; 00044 return $obj; 00045 }
| xmlCall | ( | $ | method, | |
| $ | params = null | |||
| ) |
Make a XML-RPC call If the global variable $errorStatus is not zero, the XML-RPC call is not done, and this function returns nothing.
| $method | name of the method | |
| $params | array with param |
Definition at line 112 of file xmlrpc.inc.php.
References $_SESSION, $conf, $errObj, $params, $result, $root, $url, exit, findErrorHandling(), isXMLRPCError(), and openSocket().
Referenced by _base_changeUserPasswd(), _base_changeUserPrimaryGroup(), _base_delGroup(), _base_disableUser(), _base_enableUser(), _samba_changeUserPasswd(), _samba_changeUserPrimaryGroup(), _samba_disableUser(), _samba_enableUser(), add_machine(), add_member(), add_share(), add_user(), addComputer(), addElementInBlackList(), addHostToSubnet(), addMailGroup(), addMailObjectClass(), addPool(), addPPolicyObjectClass(), addRecordA(), addRecordCNAME(), addSmbAttr(), addSubnet(), addVDomain(), addZone(), addZoneWithSubnet(), auth_user(), canAddComputer(), canAssociateComputer2Location(), canDelComputer(), change_group_desc(), change_user_main_attr(), changeMailalias(), changeMailbox(), changeMaildrop(), changeMailEnable(), changeMailhost(), changeQuota(), changeSmbAttr(), changeUserAttributes(), changeUserTelephoneNumbers(), check_auth(), checkPPolicy(), computeMailGroupAlias(), create_group(), default_shares_path(), del_group(), del_machine(), del_member(), del_share(), del_user(), delCNAMEs(), delComputer(), delElementInBlackList(), deleteMailGroupAliases(), delHost(), delPool(), delRecord(), delSubnet(), delVDomain(), delZone(), dhcpService(), disableUser(), dnsService(), enableUser(), exist_user(), existGroup(), get_action_type(), get_blacklist(), get_default_group(), get_detailed_group(), get_groups(), get_last_log_user(), get_log_by_id(), get_log_filter(), get_log_user_filter(), get_machines(), get_members(), get_process(), get_shares(), get_shares_detailed(), get_smbconf(), get_user_groups(), get_users(), get_users_detailed(), getAcl(), getACLOnShare(), getAdminUsersOnShare(), getAllGroupsFromUser(), getAllPPolicyAttributes(), getAllZonesNetworkAddresses(), getCNAMEs(), getComputer(), getComputerCount(), getComputersList(), getComputersListHeaders(), getComputersName(), getConnected(), getDefaultPPolicyAttributes(), getDetailedUser(), getDhcpLeases(), getDomainAdminsGroup(), getHost(), getHostHWAddress(), getMXRecords(), getNSRecords(), getPool(), getPPolicyAttribute(), getResourceRecord(), getRestrictedComputersList(), getRestrictedComputersListLen(), getRestrictedComputersName(), getSmbStatus(), getSOARecord(), getStatutProxy(), getSubnet(), getSubnetAndZoneFreeIp(), getSubnetFreeIp(), getSubnetHosts(), getSubnetHostsCount(), getSubnets(), getUserDefaultPrimaryGroup(), getUserPPolicyAttribut(), getUserPrimaryGroup(), getUserSecondaryGroups(), getVDomain(), getVDomains(), getVDomainUsers(), getVDomainUsersCount(), getZoneFreeIp(), getZoneNetworkAddress(), getZoneObjects(), getZoneObjectsCount(), getZones(), has_audit_working(), hasClamAv(), hasComputerManagerWorking(), hasGroupMailObjectClass(), hasMailObjectClass(), hasPPolicyObjectClass(), hasSmbAttr(), hasVDomainSupport(), hostExists(), hostExistsInSubnet(), installPPolicy(), ipExists(), ipExistsInSubnet(), isAccountInGraceLogin(), isAccountLocked(), isAuthorizedSharePath(), isEnabled(), isEnabledUser(), isLockedUser(), isPasswordExpired(), maxGID(), maxUID(), modifyRecord(), move_home(), neededParamsAddComputer(), passwordHasBeenReset(), passwordMustBeChanged(), print_disk_info(), print_health(), print_ldap_conf(), removeMail(), removeMailGroup(), removePPolicyObjectClass(), resetUsersVDomainQuota(), resolve(), rmSmbAttr(), save_smbconf(), sched_backup(), search_groups(), search_machines(), setAcl(), setHostAliases(), setHostHWAddress(), setHostOption(), setHostStatement(), setMXRecords(), setNSRecords(), setPoolRange(), setPPolicyAttribute(), setPPolicyDefaultConfigAttributes(), setSOANSRecord(), setSubnetAuthoritative(), setSubnetDescription(), setSubnetNetmask(), setSubnetOption(), setSubnetStatement(), setUserPPolicyAttribut(), setVDomainDescription(), setVDomainQuota(), setZoneDescription(), share_infos(), share_path(), smbDisableUser(), smbEnableUser(), smbLockUser(), smbUnlockUser(), syncMailGroupAliases(), unlockAccount(), userMustChangePassword(), userPasswdHasExpired(), and zoneExists().
00112 { 00113 global $errorStatus; 00114 global $errorDesc; 00115 global $conf; 00116 00117 if (isXMLRPCError()) { // Don't do a XML-RPC call if a previous one failed 00118 return; 00119 } 00120 00121 /* 00122 Set defaut login/pass if not set. 00123 The credentials are used to authenticate the web interface to the XML-RPC 00124 server. 00125 */ 00126 if (!isset($conf["global"]["login"])) { 00127 $conf["global"]["login"] = "mmc"; 00128 $conf["global"]["password"] = "s3cr3t"; 00129 } 00130 00131 $output_options = array( "output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup"), "version" => "xmlrpc", "encoding" => "UTF-8" ); 00132 00133 $request = xmlrpc_encode_request($method, $params, $output_options); 00134 00135 /* We build the HTTP POST that will be sent */ 00136 $host= $_SESSION["XMLRPC_agent"]["host"].":".$_SESSION["XMLRPC_agent"]["port"]; 00137 $url = "/"; 00138 $httpQuery = "POST ". $url ." HTTP/1.0\r\n"; 00139 $httpQuery .= "User-Agent: MMC web interface\r\n"; 00140 $httpQuery .= "Host: ". $host ."\r\n"; 00141 $httpQuery .= "Content-Type: text/xml\r\n"; 00142 $httpQuery .= "Content-Length: ". strlen($request) . "\r\n"; 00143 /* Don't set the RPC session cookie if the user is on the login page */ 00144 if ($method == "base.ldapAuth") { 00145 unset($_SESSION["RPCSESSION"]); 00146 $httpQuery .= "X-Browser-IP: " . $_SERVER["REMOTE_ADDR"] . "\r\n"; 00147 $httpQuery .= "X-Browser-HOSTNAME: " . gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\r\n"; 00148 } else { 00149 $httpQuery .= "Cookie: " . $_SESSION["RPCSESSION"] . "\r\n"; 00150 } 00151 $httpQuery .= "Authorization: Basic ".base64_encode($conf["global"]["login"].":".$conf["global"]["password"]) . "\r\n\r\n"; 00152 $httpQuery .= $request; 00153 $sock = null; 00154 00155 /* Connect to the XML-RPC server */ 00156 if ($_SESSION["XMLRPC_agent"]["scheme"] == "https") { 00157 $prot = "ssl://"; 00158 } else { 00159 $prot = ""; 00160 } 00161 00162 list($sock, $errNo, $errString) = openSocket($prot, $conf); 00163 if (!$sock) { 00164 /* Connection failure */ 00165 $errObj = new ErrorHandlingItem(''); 00166 $errObj->setMsg(_("Can't connect to MMC agent")); 00167 $errObj->setAdvice(_("MMC agent seems to be down or not correctly configured.") . '<br/> Error: '. $errNo . ' - '. $errString); 00168 $errObj->setTraceBackDisplay(false); 00169 $errObj->setSize(400); 00170 $errObj->process(''); 00171 $errorStatus = 1; 00172 return FALSE; 00173 } 00174 00175 /* Send the HTTP POST */ 00176 if ( !fwrite($sock, $httpQuery, strlen($httpQuery)) ) { 00177 /* Failure */ 00178 $errObj = new ErrorHandlingItem(''); 00179 $errObj->setMsg(_("Can't send XML-RPC request to MMC agent")); 00180 $errObj->setAdvice(_("MMC agent seems to be not correctly configured.")); 00181 $errObj->setTraceBackDisplay(false); 00182 $errObj->setSize(400); 00183 $errObj->process(''); 00184 $errorStatus = 1; 00185 return FALSE; 00186 } 00187 fflush($sock); 00188 00189 /* Get the response from the server */ 00190 $xmlResponse = ''; 00191 while (!feof($sock)) { 00192 $ret = fread($sock, 8192); 00193 $info = stream_get_meta_data($sock); 00194 if ($info['timed_out']) { 00195 $errObj = new ErrorHandlingItem(''); 00196 $errObj->setMsg(_('MMC agent communication problem')); 00197 $errObj->setAdvice(_('Timeout when reading data from the MMC agent. Please check network connectivity and server load.')); 00198 $errObj->setTraceBackDisplay(false); 00199 $errObj->setSize(400); 00200 $errObj->process(''); 00201 $errorStatus = 1; 00202 return FALSE; 00203 } 00204 if ($ret === False) { 00205 $errObj = new ErrorHandlingItem(''); 00206 $errObj->setMsg(_("Error while reading MMC agent XML-RPC response.")); 00207 $errObj->setAdvice(_("Please check network connectivity.")); 00208 $errObj->setTraceBackDisplay(false); 00209 $errObj->setSize(400); 00210 $errObj->process(''); 00211 $errorStatus = 1; 00212 return FALSE; 00213 } 00214 $xmlResponse .= $ret; 00215 } 00216 fclose($sock); 00217 00218 /* Process the response */ 00219 if (!strlen($xmlResponse)) { 00220 $errObj = new ErrorHandlingItem(''); 00221 $errObj->setMsg(_("MMC agent communication problem")); 00222 $errObj->setAdvice(_("Can't communicate with MMC agent. Please check you're using the right TCP port and the right protocol.")); 00223 $errObj->setTraceBackDisplay(false); 00224 $errObj->setSize(400); 00225 $errObj->process(''); 00226 $errorStatus = 1; 00227 return FALSE; 00228 } 00229 00230 /* Process the received HTTP header */ 00231 $pos = strpos($xmlResponse, "\r\n\r\n"); 00232 $httpHeader = substr($xmlResponse, 0, $pos); 00233 if ($method == "base.ldapAuth") { 00234 /* The RPC server must send us a session cookie */ 00235 if (preg_match("/(TWISTED_SESSION=[0-9a-f]+);/", $httpHeader, $match) > 0) { 00236 $_SESSION["RPCSESSION"] = $match[1]; 00237 } else { 00238 /* Can't get a session from the Twisted XML-RPC server */ 00239 $errObj = new ErrorHandlingItem(''); 00240 $errObj->setMsg(_("MMC agent communication problem")); 00241 $errObj->setAdvice(_("The MMC agent didn't give us a session number. Please check the MMC agent version.")); 00242 $errObj->setTraceBackDisplay(false); 00243 $errObj->setSize(400); 00244 $errObj->process(''); 00245 $errorStatus = 1; 00246 return False; 00247 } 00248 } 00249 00250 /* Process the XML response */ 00251 $xmlResponse = substr($xmlResponse, $pos + 4); 00252 /* 00253 Test if the XMLRPC result is a boolean value set to False. 00254 If it is the case, xmlrpc_decode will return an empty string. 00255 So we need to test this special case. 00256 00257 Looks like this bug is fixed in latest PHP version. At least it works 00258 with PHP 5.2.0. 00259 */ 00260 $booleanFalse = "<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"; 00261 if ($xmlResponse == $booleanFalse) $xmlResponse = False; 00262 else { 00263 $xmlResponseTmp = xmlrpc_decode($xmlResponse, "UTF-8"); 00264 /* if we cannot decode in UTF-8 */ 00265 if (!$xmlResponseTmp) { 00266 /* Maybe we received data encoded in ISO latin 1, so convert them 00267 to UTF8 first*/ 00268 $xmlResponse = iconv("ISO-8859-1", "UTF-8", $xmlResponse); 00269 $xmlResponse = xmlrpc_decode($xmlResponse, "UTF-8"); 00270 } else { 00271 $xmlResponse = $xmlResponseTmp; 00272 } 00273 } 00274 00275 /* If debug is on, print the XML-RPC call and result */ 00276 if ($conf["debug"]["level"]!=0) { 00277 $str = '<div id="debugCode">'; 00278 $str .= " debuginfo"; 00279 $str.= '<div id="debugCodeHeader">'; 00280 $str .= "XML RPC CALL FUNCTION: $method("; 00281 if (!$params) { 00282 $params = "null"; 00283 } else if (is_array($params)) { 00284 $str .= var_export($params, True); 00285 } else { 00286 $str .= $params; 00287 } 00288 $str .=')'; 00289 $str .= "</div>"; 00290 if (is_array($xmlResponse)) { 00291 $str .= "<pre>"; 00292 $str .= "result : "; 00293 $str .= var_export($xmlResponse, True); 00294 $str .= "</pre>"; 00295 } else { 00296 $str .= "result : ".$xmlResponse; 00297 } 00298 $str .= '</div>'; 00299 echo $str; 00300 } 00301 00302 /* If the XML-RPC server sent a fault, display an error */ 00303 if ((is_array($xmlResponse) && (isset($xmlResponse["faultCode"])))) { 00304 if ($xmlResponse["faultCode"] == "8003") { 00305 /* 00306 Fault 8003 means the session with the XML-RPC server has expired. 00307 So we make the current PHP session expire, so that the user is 00308 redirected to the login page. 00309 */ 00310 unset($_SESSION["expire"]); 00311 $_SESSION["agentsessionexpired"] = 1; 00312 $root = $conf["global"]["root"]; 00313 header("Location: $root" . "main.php"); 00314 exit; 00315 } 00316 /* Try to find an error handler */ 00317 $result = findErrorHandling($xmlResponse["faultCode"]); 00318 if (!is_object($result) and $result == -1) { 00319 /* We didn't find one */ 00320 $result = new ErrorHandlingItem(''); 00321 $result->setMsg(_("unknown error")); 00322 $result->setAdvice(_("This exception is unknown. Please contact us to add an error handling on this error.")); 00323 } 00324 $result->process($xmlResponse); 00325 $errorStatus = 1; 00326 $errorDesc = $xmlResponse["faultCode"]; 00327 return False; 00328 } 00329 00330 /* Return the result of the remote procedure call */ 00331 return $xmlResponse; 00332 }

1.5.8