Overview
  • Namespace
  • Class

Namespaces

  • rpf
    • api
      • module
    • extension
      • module
    • system
      • module

Classes

  • rpf\api\api
  • rpf\api\apiModule
  • rpf\api\bbRpc
  • rpf\api\module\bbCustomer_getFreeOrdNr
  • rpf\api\module\bbCustomer_readAddress
  • rpf\api\module\bbCustomer_readDiscount
  • rpf\api\module\bbCustomer_readEntry
  • rpf\api\module\bbCustomer_readPayment
  • rpf\api\module\bbCustomer_readTitle
  • rpf\api\module\bbCustomer_saveAdress
  • rpf\api\module\bbCustomer_validateAddress
  • rpf\api\module\bbCustomer_validateEntry
  • rpf\api\module\bbCustomer_validatePayinfo
  • rpf\api\module\bbDomain_readEntry
  • rpf\api\module\bbDomain_readFrontpage
  • rpf\api\module\bbDomain_readHandles
  • rpf\api\module\bbDomain_readPhpini
  • rpf\api\module\bbDomain_readSettings
  • rpf\api\module\bbDomain_readSubdomain
  • rpf\api\module\bbDomain_readWebalizerSettings
  • rpf\api\module\bbDomain_searchEntry
  • rpf\api\module\bbEmail_readAccount
  • rpf\api\module\bbMysql_inuseEntry
  • rpf\api\module\bbMysql_makeBackup
  • rpf\api\module\bbMysql_readEntry
  • rpf\api\module\bbOrder_readAccountAddress
  • rpf\api\module\bbOrder_readAccountEntry
  • rpf\api\module\bbOrder_readDisposition
  • rpf\api\module\bbOrder_readEntry
  • rpf\api\module\bbQuota_readEntry
  • rpf\api\module\customer
  • rpf\api\module\email
  • rpf\api\module\order
  • rpf\api\module\placeholder
  • rpf\api\module\user
  • rpf\extension\extension
  • rpf\extension\extensionModule
  • rpf\extension\invoiceTextExport
  • rpf\extension\mailExport
  • rpf\extension\module\domainExport
  • rpf\extension\module\index
  • rpf\extension\module\mgntRatioExport
  • rpf\system\module
  • rpf\system\module\log
  • rpf\system\module\moduleManager
  • rpf\system\rpf

Exceptions

  • rpf\system\module\exception
  1 <?php
  2 namespace rpf\api;
  3 /*
  4  * bbRpc Class (c) 2015 by domainfactory GmbH - www.df.eu
  5  *
  6  *   Klasse zur Kommunikation mit der RP2 - API
  7  *
  8  *   Version 1.05
  9  *   Requirements:
 10  *    - php >= 5.3
 11  *    - mod: curl
 12  *
 13  *
 14  *   Generated : 2013-04-10
 15  *   Updated   : 2015-04-21
 16  *   Author    : Michael Boehm - support@df.eu
 17  *
 18  */
 19 class bbRpc{
 20   protected static $rpc_url = null;
 21   protected static $msgs    = array();
 22   private static $rpc_user = null;
 23   private static $rpc_pass = null;
 24   private static $client   = null;
 25   private static $session  = array();
 26   private static $cookie   = null;
 27   private static $response = null;
 28   private static $guest_token = null;
 29   private static $utf8 = 0;
 30   const result    = 'Return';
 31   const error_msg = 'Error';
 32   /*
 33    * setUrl()
 34    * Setzt die RP-RPC-Server-Basis-URL
 35    *
 36    * params:
 37    *  - (string) sUrl : RP2-INSTANZ Url: z.B. http://12345.premium-admin.eu/
 38    *
 39    * return void
 40    *
 41    */
 42   final public static function setUrl($sUrl=null){
 43     if (isset($sUrl)){
 44       if (substr($sUrl, -1) !== '/') {
 45         $sUrl .= '/';
 46       }
 47       static::$rpc_url = $sUrl;
 48     }
 49   }
 50   /*
 51    * setGUESTToken()
 52    * Setzt die den Fallback AUTH Token falls man nur als GUEST authentifiziert ist
 53    *
 54    * params:
 55    *  - (string) sToken : GUEST-AUTH-Token z.B. michi&milo$
 56    *
 57    * return void
 58    *
 59    */
 60   final public static function setGUESTToken($sToken=null){
 61     if (isset($sToken)){
 62       static::$guest_token = $sToken;
 63     }
 64   }
 65   /*
 66    * setUTF8Native()
 67    * Wenn gesetzt wird Result / Params nicht von latin nach utf8 und zurueck convertiert
 68    *
 69    * params:
 70    *  - (bool) bUTF8 : Params und Result nativ utf8 codieren 
 71    *
 72    * return void
 73    *
 74    */
 75   final public static function setUTF8Native($bUTF8=0){
 76     static::$utf8 = ($bUTF8) ? 1 : 0;
 77   }
 78   /*
 79    * auth()
 80    * Authentifiziert die aktuelle Session bei dem RP2-RPC Service
 81    *
 82    * params;
 83    *  - (string) sUser : Benutzername
 84    *  - (string) sPass : Passwort
 85    *
 86    * return (int) uid
 87    *
 88    */
 89   final public static function auth($sUser=null,$sPass=null){
 90     if (!is_null($sUser)){
 91       static::$rpc_user = $sUser;
 92     }
 93     if (!is_null($sPass)){
 94       static::$rpc_pass = $sPass;
 95     }
 96     return static::post('auth',array(
 97       'user' => static::$rpc_user,
 98       'pass' => static::$rpc_pass,
 99     ),'auth');
100   }
101   /*
102    * getSid()
103    * Stellt die Session-ID zur Verfügung
104    *
105    * return (string) sid
106    *
107    */
108   final public static function getSid(){
109     if (!array_key_exists('sid',static::$session) || !static::$session['sid']){
110       static::auth();
111     }
112     if (!array_key_exists('sid',static::$session) || !static::$session['sid']){
113       return null;
114     }
115     return static::$session['sid'];
116   }
117   /*
118    * setSid()
119    * Setzt die Session-ID
120    *
121    * params;
122    * - (string) sSid : Session-ID
123    *
124    * return (bool)
125    *
126    */
127   final public static function setSid($sSid){
128     if (strlen($sSid)){
129       static::$session['sid'] = $sSid;
130       return 1;
131     }
132     return 0;
133   }
134   /*
135    * call()
136    * Fuehrt einen Remote-Call am RPC-Service aus
137    *
138    * params:
139    *  - (string) sMethod                  : aufzurufende Methode z.B. bbOrder::readEntry
140    *  - (hash)   hArgs         (optional) : zu uebergebende Argumente an die aufgerufene Methode z.B. array('return_array' => 1)
141    *  - (hash)   hPlaceholders (optional) : Uebersetzungshash der Feldnamen in beliebige Bezeichner in den Meldungen uebersetzt z.B. array('phone_1' => 'Telefonnummer')
142    *
143    * return xData
144    *
145    */
146   final public static function call($sMethod,$hArgs=array(),$hPlaceholders=null){
147     if (!array_key_exists('sid',static::$session) || !static::$session['sid']){
148       static::auth();
149     }
150     return static::post($sMethod,$hArgs,'call',$hPlaceholders);
151   }
152   /*
153    * getMessages()
154    * Liefert alle RPC-Meldungen zurueck (Fehler / Erfolg / Informationen / Warnungen)
155    *
156    * params:
157    * - (hash) hParams  (optional) : Zusaetzliche Parameter z.B. array('delete_previous' => 1)
158    *
159    * return (array)
160    *
161    */
162   final public static function getMessages($hParams=array()){
163     $ahMsgs = static::$msgs;
164     if ( array_key_exists('delete_previous', $hParams) && $hParams['delete_previous'] ) {
165         static::$msgs = array();
166     }
167     return $ahMsgs;
168   }
169   /*
170    * logout()
171    * Beendet angemeldete Session
172    *
173    * return void
174    *
175    */
176   final public static function logout(){
177     return static::post('logout',null,'logout');
178   }
179   /*
180    * setOrder()
181    * Wechselt auf einen anderen Endkunden Auftrag / sofern man als Endkunde authentifiziert ist
182    *
183    * params:
184    *  - (integer) iOeid : oeid auf des zu wechselnden Auftrages
185    *
186    * return void
187    *
188    */
189   final public static function setOrder($iOeid){
190     return static::post('setOrder',array(
191       'oeid' => $iOeid,
192     ),'setOrder');
193   }
194   /*
195    *
196    * PRIVATE FUNCTIONS
197    *
198    *
199    */
200   private static function addNotice($sMsg){
201     static::$msgs[] = array(
202       'typ' => 'notice',
203       'msg' => $sMsg,
204     );
205   }
206   private static function addError($sMsg){
207     static::$msgs[] = array(
208       'typ' => 'hard',
209       'msg' => $sMsg,
210     );
211   }
212   final private static function setOpt($sOption,$xValue){
213     if (!curl_setopt(static::$client,$sOption,$xValue)){
214       static::addError('Fehler beim Setzen der Client-Option: '.$sOption.' auf: '.$xValue);
215       return 0;
216     }
217     return 1;
218   }
219   final private static function init(){
220     if (is_null(static::$cookie)){
221       static::$cookie = (defined('BBRPC_COOKIE')) ? BBRPC_COOKIE : getcwd().'/bb.rpc.cookie';
222     }
223     if (is_null(static::$rpc_url)){
224       static::$rpc_url = BBRPC_URL;
225     }
226     if (is_null(static::$client)){
227       static::$client = curl_init();
228       static::setOpt(CURLOPT_SSL_VERIFYPEER,    FALSE);
229       static::setOpt(CURLOPT_RETURNTRANSFER,    TRUE);
230       static::setOpt(CURLOPT_TIMEOUT,           300);
231       static::setOpt(CURLOPT_HEADER,            FALSE);
232       static::setOpt(CURLOPT_FORBID_REUSE,      FALSE);
233       static::setOpt(CURLOPT_VERBOSE,           FALSE);
234       static::setOpt(CURLOPT_COOKIEFILE,        static::$cookie);
235       static::setOpt(CURLOPT_COOKIEJAR,         static::$cookie);
236       static::setOpt(CURLOPT_HTTPHEADER,        array(
237         'Connection: keep-alive',
238         'Keep-Alive: 300',
239         'Expect: ',
240       ));
241       return 1;
242     }
243     return 0;
244   }
245   final private static function isCriticalError(){
246     return (static::getResponse('IsCriticalError')) ? TRUE : FALSE;
247   }
248   final private static function getResponse($sName){
249     return (is_array(static::$response) && array_key_exists($sName,static::$response)) ? static::$response[$sName] : NULL;
250   }
251   final private static function getErrors(){
252     return static::getResponse(static::error_msg);
253   }
254   final private static function replacePlaceholder($sMsg,$hPlaceholders){
255     foreach($hPlaceholders as $sFld => $sDscr){
256       $sMsg = str_replace("\$".$sFld,$sDscr,$sMsg);
257     }
258     return $sMsg;
259   }
260   final private static function displayMessages($hPlaceholders=null){
261     $ahMsgs = static::getErrors();
262     if (is_array($ahMsgs)){
263       foreach($ahMsgs as $hMsg){
264         if (isset($hPlaceholders)){
265           $hMsg['msg'] = static::replacePlaceholder($hMsg['msg'],$hPlaceholders);
266         }
267         static::$msgs[] = $hMsg;
268       }
269     }
270   }
271   final private static function utf8_encode_data($xData){
272     if (is_array($xData)){
273       $aKeys = array_keys($xData);
274       while(($xKey = array_shift($aKeys)) !== null){
275         $xVal = static::utf8_encode_data($xData[$xKey]);
276         unset($xData[$xKey]);
277         $xKey = static::utf8_encode_data($xKey);
278         $xData[$xKey] = $xVal;
279       }
280       return $xData;
281     }elseif (is_string($xData)){
282       return utf8_encode($xData);
283     }else{
284       return $xData;
285     }
286   }
287   final private static function utf8_decode_data($xData){
288     if (is_array($xData)){
289       $aKeys = array_keys($xData);
290       while(($xKey = array_shift($aKeys)) !== null){
291         $xVal = static::utf8_decode_data($xData[$xKey]);
292         unset($xData[$xKey]);
293         $xKey = static::utf8_decode_data($xKey);
294         $xData[$xKey] = $xVal;
295       }
296       return $xData;
297     }elseif (is_string($xData)){
298       return utf8_decode($xData);
299     }elseif (is_float($xData) || is_double($xData)){
300       if (strpos((string)$xData,'.') === false && strpos((string)$xData,',') === false){
301         return (integer) $xData;
302       }else{
303         return (float) $xData;
304       }
305     }else{
306       return $xData;
307     }
308   }
309   final private static function json_encode($xData){
310     return (static::$utf8) ? json_encode($xData) : json_encode(static::utf8_encode_data($xData));
311   }
312   final private static function json_decode($xData){
313     return (static::$utf8) ? json_decode($xData,1) : static::utf8_decode_data(json_decode($xData,1));
314   }
315   final private static function post($sMethod,$xArgs=null,$sTyp='call',$hPlaceholders=null){
316     static::init();
317     $sSessionID = (array_key_exists('sid',static::$session) && static::$session['sid']) ? static::$session['sid'] : '__';
318     if ($sTyp == 'call'){
319       static::setOpt(CURLOPT_URL, static::$rpc_url.$sSessionID.'/rpc/call');
320     }elseif($sTyp == 'auth'){
321       if ((is_null($xArgs['user']) || !strlen($xArgs['user'])) && (is_null($xArgs['pass']) || !strlen($xArgs['pass']))){
322         unset($xArgs['user']);
323         unset($xArgs['pass']);
324       }
325       static::setOpt(CURLOPT_URL, static::$rpc_url.$sSessionID.'/rpc/auth');
326     }elseif($sTyp == 'setOrder'){
327       static::setOpt(CURLOPT_URL, static::$rpc_url.static::$session['sid'].'/rpc/setOrder');
328     }elseif($sTyp == 'logout'){
329       static::setOpt(CURLOPT_URL, static::$rpc_url.$sSessionID.'/rpc/logout');
330     }
331 
332     $hMsg = array('method' => $sMethod);
333     if (isset(static::$guest_token)){
334       $hMsg['guest_token'] = static::$guest_token;
335     }
336     if (isset($xArgs)) {
337       $hMsg['params'] = $xArgs;
338     }
339     $sMsg = static::json_encode($hMsg);
340     static::setOpt(CURLOPT_POSTFIELDS, array(
341       'data' => $sMsg,
342     ));
343     $xResponseOrig = @curl_exec(static::$client);
344     $bTmpErr = 0;
345     if ($xResponseOrig === FALSE){
346       static::addError('Verbindung zum BB-System nicht moeglich.');
347       $bTmpErr = 1;
348     }
349     if ($xResponseOrig !== FALSE && (static::$response = static::json_decode($xResponseOrig)) === FALSE && !$bTmpErr){
350       static::addError('Ungueltiger Rueckgabewert des BB-Systems: '.$xResponseOrig);
351       echo('Error: curl_exec.response['.$sMethod.']=> '.$xResponseOrig."\n");
352       die;
353     }
354     if (static::isCriticalError()){
355       trigger_error(static::getResponse(static::result), E_USER_ERROR);
356       die;
357     }
358     if ($sTyp == 'auth'){
359       static::$session['sid'] = static::getResponse('sid');
360     }
361     static::displayMessages($hPlaceholders);
362     return static::getResponse(static::result);
363   }
364 }
365 
API documentation generated by ApiGen