1 <?php
2
3 namespace rpf\api\module;
4 use rpf\api\apiModule;
5 use rpf\api\bbRpc;
6 use rpf\system\module\exception;
7 use rpf\system\module\log;
8
9 class user extends apiModule {
10
11 12 13 14 15 16 17 18
19 public function auth($rp2InstanceUrl, $rp2ApiUser, $rp2ApiPwd)
20 {
21 $duration = microtime(1);
22 log::debug('Setting RPC-URL', "bbRpc::setUrl($rp2InstanceUrl)");
23 bbRpc::setUrl($rp2InstanceUrl);
24 $userId = bbRpc::auth($rp2ApiUser, $rp2ApiPwd);
25 $duration = round(microtime(1)-$duration, 3);
26
27 if (!$userId)
28 {
29 log::warning("Login failed from ".$_SERVER['REMOTE_ADDR']." within $duration sec.", "bbRpc::auth($rp2ApiUser, *****)", $_SERVER);
30 $this->fetchRpcLog();
31 return false;
32 }
33 else
34 {
35
36 log::info("Login successful from ".$_SERVER['REMOTE_ADDR']." within $duration sec.", "bbRpc::auth($rp2ApiUser, *****)");
37 $this->fetchRpcLog();
38
39 log::debug('Set UTF-8', 'bbRpc::setUTF8Native(true)');
40 bbRpc::setUTF8Native(true);
41 $this->fetchRpcLog();
42 return true;
43 }
44 }
45
46 47 48 49 50 51 52 53 54
55 public function httpAuth()
56 {
57
58 $path = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : $_SERVER['PWD'];
59 preg_match("/\\/.*\\/(\\d*)_\\d*\\/.*/", $path, $matches);
60 $dfOrderNr = $matches[1];
61 $rp2InstanceUrl = "http://$dfOrderNr.premium-admin.eu/";
62
63 if ( !(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) &&
64 $this->auth($rp2InstanceUrl, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) )
65 {
66 static::sendHttpAuth($dfOrderNr);
67 }
68
69 return $this;
70 }
71
72 protected static function sendHttpAuth($dfOrderNr)
73 {
74 header("WWW-Authenticate: Basic realm=\"Please enter your RP2-User and Password for A$dfOrderNr\"");
75 header('HTTP/1.0 401 Unauthorized');
76 \rpf\showError('Login', "Please authenticate with your RP²-Username and Password for A$dfOrderNr");
77 exit;
78 }
79 }