Skip to content

Commit 23af79b

Browse files
authored
Merge pull request #296 from ostepu/develop
Version 0.6.2
2 parents 7a41c69 + 6dc488d commit 23af79b

File tree

136 files changed

+2633
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+2633
-200
lines changed

Assistants/CConfig.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,20 @@ public function commands( $pre = '', $nativeOnly=false, $returnData=false )
330330
}
331331
}
332332
}
333+
334+
// liefert die API-Regeln für das develop-Profil
335+
public function apiRulesDevelop($myComponentName){
336+
$rules = array();
337+
338+
$rules[] = GateRule::createGateRule(null,'httpCall',$myComponentName,'GET ((/profile)/:pre)/info/commands(/)',null);
339+
$rules[] = GateRule::createGateRule(null,'httpCall',$myComponentName,'GET ((/profile)/:pre)/info/links(/)',null);
340+
if (!$this->_noInfo) $rules[] = GateRule::createGateRule(null,'httpCall',$myComponentName,'GET ((/profile)/:pre)/info/:language(/)',null);
341+
////$rules[] = GateRule::createGateRule(null,'httpCall',$myComponentName,'POST ((/profile)/:pre)/control',null);
342+
$rules[] = GateRule::createGateRule(null,'httpCall',$myComponentName,'GET ((/profile)/:pre)/control',null);
343+
if (!$this->_noHelp) $rules[] = GateRule::createGateRule(null,'httpCall',$myComponentName,'GET ((/profile)/:pre)/help/:language/path+',null);
344+
345+
return $rules;
346+
}
333347

334348
public function component( $pre = '', $nativeOnly=false, $returnData=false )
335349
{

Assistants/Model.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require_once ( dirname(__FILE__) . '/vendor/Slim/Slim/Route.php' );
1515
require_once ( dirname(__FILE__) . '/vendor/Slim/Slim/Router.php' );
1616
require_once ( dirname(__FILE__) . '/vendor/Slim/Slim/Environment.php' );
17+
require_once ( dirname(__FILE__) . '/vendor/Validation/Validation.php' );
1718
include_once ( dirname(__FILE__) . '/Structures.php' );
1819
include_once ( dirname(__FILE__) . '/Request.php' );
1920
include_once ( dirname(__FILE__) . '/../UI/include/Authentication.php' );
@@ -48,7 +49,7 @@ class Model
4849
/**
4950
* @var Component $_com Die Definition der Ausgänge
5051
*/
51-
private $_com = null;
52+
public $_com = null;
5253

5354

5455
private $_noInfo = null;
@@ -608,7 +609,7 @@ public function call($linkName, $params, $body, $positiveStatus, callable $posit
608609
{
609610
$link=CConfig::getLink($this->_conf->getLinks( ),$linkName);
610611
$instructions = $this->_com->instruction('',true);
611-
612+
612613
// ermittle den zutreffenden Ausgang
613614
$selectedInstruction=null;
614615
foreach($instructions as $instruction){

Assistants/Request.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,62 @@ public static function normalizeURL($target)
109109
}
110110
return $target;
111111
}
112+
113+
public static function download($tempTarget, $target, $responseHeader=true, $header=array())
114+
{
115+
$target = self::normalizeURL($target);
116+
117+
$result = array();
118+
try{
119+
$fp = fopen($tempTarget.'_2', 'w+');
120+
$ch = curl_init($target);
121+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
122+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
123+
curl_setopt($ch, CURLOPT_FILE, $fp);
124+
125+
if ($responseHeader){
126+
curl_setopt($ch, CURLOPT_HEADER, true);
127+
}
128+
129+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
130+
//curl_setopt($ch, CURLOPT_USERAGENT,'Codular Sample cURL Request');
131+
curl_setopt($ch, CURLOPT_TIMEOUT, 120); // 120 Sekunden
132+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // 120 Sekunden
133+
134+
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
135+
136+
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
137+
138+
$content = curl_exec($ch);
139+
// get the request result
140+
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
141+
142+
if ($header_size > 0){
143+
fseek($fp,0);
144+
$result['headers'] = self::http_parse_headers(fread($fp, $header_size));
145+
}
146+
fseek($fp,$header_size);
147+
$fp2 = fopen($tempTarget, 'w+');
148+
while (!feof($fp)) fwrite($fp2, fread($fp, 8192));
149+
fclose($fp2);
150+
fclose($fp);
151+
unlink($tempTarget.'_2');
152+
153+
// seperates the content part
154+
$result['content'] = "";
155+
156+
// sets the received status code
157+
$result['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
158+
curl_close($ch);
159+
160+
}catch(Exception $e){
161+
$result = array();
162+
$result['status'] = 408;
163+
$result['content'] = '';
164+
$result['headers'] = array();
165+
}
166+
return $result;
167+
}
112168

113169
/**
114170
* performs a custom request

DB/CGate/CGate.php

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,34 @@
1414
include_once ( dirname(__FILE__) . '/../../UI/include/Authentication.php' );
1515

1616
/**
17-
* ???
17+
* die Klasse CGate stellt gesicherte Zugriffe auf interne Komponenten bereit
18+
* hierzu gehört die Komponente DBGate, deren Tabellen die Profile, Benutzer und Regeln definieren
19+
*
20+
* Es gibt die Zugangsarten
21+
* -> noAuth = keine Authentifizierung
22+
* -> httpAuth = die HTTP-Standardanmeldung im Header unter "Authorization"
23+
* siehe https://de.wikipedia.org/wiki/HTTP-Authentifizierung
24+
* -> tokenAuth = die Angabe eines Tokens im Header unter "PRIVATE-TOKEN" (ist in der gateauth-Tabelle dann der "GA_login")
1825
*/
1926
class CGate extends Model
2027
{
2128

2229
/**
23-
* ???
30+
* Konstruktor
2431
*/
2532
public function __construct( )
2633
{
34+
// hier wird die Model-Klasse gestartet
2735
parent::__construct('', dirname(__FILE__), $this, false, false, array('addRequestToParams'=>true));
2836
$this->run();
2937
}
3038

3139
/**
32-
* ???
40+
* diese Methode bearbeitet die Anfragen
3341
*/
3442
public function request( $callName, $input, $params = array() )
3543
{
36-
$authType = 'noAuth';
44+
$authType = 'noAuth'; // das ist der default-Anmeldetyp, wenn kein anderer erkannt wird
3745
$profile = $params['profile'];
3846
$component = $params['component'];
3947
$order = '/'.implode('/',$params['path']);
@@ -48,30 +56,36 @@ public function request( $callName, $input, $params = array() )
4856
$login = $headers['PHP_AUTH_USER'];
4957
$passwd = (isset($headers['PHP_AUTH_PW']) ? $headers['PHP_AUTH_PW'] : '');
5058
$authType = 'httpAuth';
59+
} elseif (isset($headers['HTTP_PRIVATE_TOKEN'])){
60+
// wir prüfen nun ob eine Authentifizierung über einen Token gewollt ist
61+
$login = $headers['HTTP_PRIVATE_TOKEN'];
62+
$passwd = null;
63+
$authType = 'tokenAuth';
5164
}
5265

5366
$positive = function($gateProfile, $method, $order, $component, $body, $authType, $login, $passwd) {
54-
$gateProfile = $gateProfile[0];
67+
// wenn diese Funktion aufgerufen wird, dann existiert das Profil und dazu der Login.
68+
// Wir wissen aber noch nicht, ob er sich wirklich korrekt angemeldet hat, sofern noch ein Passwort
69+
// erforderlich ist
70+
71+
$gateProfile = $gateProfile[0]; // dieses Profil entstammt der Datenbank, wenn dort Profil und Nutzername gefunden wurden
5572

5673
$auths = $gateProfile->getAuths();
57-
$accepted = false;
74+
$accepted = false; // dieses Flag gibt an, ob der Zugang erfolgreich gewährt wurde
5875

59-
$authentication = new Authentication();
60-
6176
foreach($auths as $auth){
6277
$authType = $auth->getType();
63-
if ($authType == 'noAuth'){
78+
if ($authType == 'tokenAuth'){
79+
// wir gelangen nur an diesen Punkt, wenn es den entsprechenden Token in der Datenbank als
80+
// 'login' gibt, daher ist der Zugang dann erlaubt
81+
$accepted = true;
82+
break;
83+
} elseif ($authType == 'noAuth'){
84+
// es ist keine weitere Prüfung erforderlich
6485
$accepted = true;
6586
break;
6687
} elseif ($authType == 'httpAuth'){
67-
$params = $auth->getParams();
68-
69-
/*$salt = '';
70-
if (isset($params['salt'])){
71-
$salt = $params['salt'];
72-
}
73-
74-
$hashedPasswd = $authentication->hashPassword($passwd, $salt);*/
88+
//$params = $auth->getParams();
7589

7690
if ($auth->getLogin() == $login && $auth->getPasswd() == $passwd){
7791
$accepted = true;
@@ -95,6 +109,9 @@ public function request( $callName, $input, $params = array() )
95109

96110
// nun muss geprüft werden, ob der Aufruf auch erlaubt ist
97111
if (in_array("Slim\\Slim", get_declared_classes())) {
112+
113+
// hier wird slim vorbereitet, um später für uns zu prüfen, ob eine der Regelpfade auf
114+
// unsere Anfrage passt
98115
$router = new \Slim\Router();
99116
foreach($rules as $rule){
100117
if ($rule->getType() == 'httpCall' && $rule->getComponent() == $component){
@@ -153,6 +170,7 @@ public function request( $callName, $input, $params = array() )
153170
if ($authType == 'noAuth'){
154171
return Model::call('getComponentProfileWithAuth', array('profName'=>$profile, 'authType'=>$authType, 'component'=>$component), '', 200, $positive, array('method'=>$method, 'order'=>$order, 'component'=>$component, 'body'=>$input, 'authType'=>$authType, 'login'=>$login, 'passwd'=>$passwd), 'Model::isRejected', array(), 'GateProfile');
155172
} else {
173+
// es ist eine andere Zugangsart, sodass auch geprüft wird, ob es eine Anmeldung mit dem entsprechenden Nutzernamen gibt
156174
return Model::call('getComponentProfileWithAuthLogin', array('login'=>$login, 'profName'=>$profile, 'authType'=>$authType, 'component'=>$component), '', 200, $positive, array('method'=>$method, 'order'=>$order, 'component'=>$component, 'body'=>$input, 'authType'=>$authType, 'login'=>$login, 'passwd'=>$passwd), 'Model::isRejected', array(), 'GateProfile');
157175
}
158176
}

DB/CHelp/CHelp.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,27 @@ public static function deleteDir($path)
246246
}
247247
return false;
248248
}
249+
250+
public function getApiProfiles( $callName, $input, $params = array() )
251+
{
252+
$myName = $this->_component->_conf->getName();
253+
$profiles = array();
254+
$profiles['readonly'] = GateProfile::createGateProfile(null,'readonly');
255+
$profiles['readonly']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /help/:path+',null));
256+
$profiles['readonly']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /status',null));
257+
258+
$profiles['general'] = GateProfile::createGateProfile(null,'general');
259+
$profiles['general']->setRules($profiles['readonly']->getRules());
260+
$profiles['general']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'DELETE /platform/:path+',null));
261+
$profiles['general']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'POST /platform/:path+',null));
262+
$profiles['general']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /link/exists/platform',null));
263+
264+
$profiles['develop'] = GateProfile::createGateProfile(null,'develop');
265+
$profiles['develop']->setRules(array_merge($profiles['general']->getRules(), $this->_component->_com->apiRulesDevelop($myName)));
266+
267+
$profiles['public'] = GateProfile::createGateProfile(null,'public');
268+
$profiles['public']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /help/:path+',null));
269+
$profiles['public']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /status',null));
270+
return Model::isOk(array_values($profiles));
271+
}
249272
}

DB/CHelp/Commands.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,12 @@
4040
"inputType": "",
4141
"method": "GET",
4242
"path": "/link/exists/platform"
43+
},
44+
{
45+
"name": "getApiProfiles",
46+
"outputType": "GateProfile",
47+
"inputType": "",
48+
"method": "GET",
49+
"path": "/api/profiles"
4350
}
4451
]

DB/CHelp/Component.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
{
2424
"name": "postPlatform",
2525
"target": "CInstall"
26+
},
27+
{
28+
"name": "getComponentProfiles",
29+
"target": "TApiConfiguration"
2630
}
2731
]
2832
}

DB/CSystem/CSystem.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,22 @@ public function getTimestamp( $callName, $input, $params = array())
4949
// returns the currect timestamp
5050
return Model::isOk(array('timestamp'=>microtime(true)));
5151
}
52+
53+
public function getApiProfiles( $callName, $input, $params = array() )
54+
{
55+
$myName = $this->_component->_conf->getName();
56+
$profiles = array();
57+
$profiles['readonly'] = GateProfile::createGateProfile(null,'readonly');
58+
$profiles['readonly']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /timestamp',null));
59+
60+
$profiles['general'] = GateProfile::createGateProfile(null,'general');
61+
$profiles['general']->setRules($profiles['readonly']->getRules());
62+
63+
$profiles['develop'] = GateProfile::createGateProfile(null,'develop');
64+
$profiles['develop']->setRules(array_merge($profiles['general']->getRules(), $this->_component->_com->apiRulesDevelop($myName)));
65+
66+
$profiles['public'] = GateProfile::createGateProfile(null,'public');
67+
$profiles['public']->addRule(GateRule::createGateRule(null,'httpCall',$myName,'GET /timestamp',null));
68+
return Model::isOk(array_values($profiles));
69+
}
5270
}

DB/CSystem/Commands.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
"name": "getTimestamp",
44
"method": "GET",
55
"path": "/timestamp"
6+
},
7+
{
8+
"name": "getApiProfiles",
9+
"outputType": "GateProfile",
10+
"inputType": "",
11+
"method": "GET",
12+
"path": "/api/profiles"
613
}
714
]

DB/CSystem/Component.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
{
1414
"name": "request",
1515
"target": "CLocalObjectRequest"
16+
},
17+
{
18+
"name": "getComponentProfiles",
19+
"target": "TApiConfiguration"
1620
}
1721
]
1822
}

0 commit comments

Comments
 (0)