Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 1270 → Rev 1271

/trunk/includes/classes/OIDplusObject.class.php
528,12 → 528,12
public function getParent()/*: ?OIDplusObject*/ {
if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
$res = OIDplus::db()->query("select parent from ###objects where id = ?", array($this->nodeId()));
if (!$res->any()) return null;
if ($res->any()) {
$row = $res->fetch_array();
$parent = $row['parent'];
$obj = OIDplusObject::parse($parent);
if ($obj) return $obj;
// TODO: Also implement one_up() like below
}
} else {
self::buildObjectInformationCache();
if (isset(self::$object_info_cache[$this->nodeId()])) {
541,6 → 541,7
$obj = OIDplusObject::parse($parent);
if ($obj) return $obj;
}
}
 
// If this OID does not exist, the SQL query "select parent from ..." does not work. So we try to find the next possible parent using one_up()
$cur = $this->one_up();
553,7 → 554,7
$cur = $cur->one_up();
if (!$cur) return null;
} while ($prev->nodeId() !== $cur->nodeId());
}
 
return null;
}
 
/trunk/plugins/viathinksoft/language/dede/messages.xml
1134,6 → 1134,14
</message>
<message>
<source><![CDATA[
Cannot verify that %1 has parent %2
]]></source>
<target><![CDATA[
Konnte nicht verifizieren, dass %1 ein untergeordnetes Objekt von %2 ist
]]></target>
</message>
<message>
<source><![CDATA[
Cannot write file %1
]]></source>
<target><![CDATA[
3222,6 → 3230,14
</message>
<message>
<source><![CDATA[
Input parameters
]]></source>
<target><![CDATA[
Eingabe-Parameter
]]></target>
</message>
<message>
<source><![CDATA[
Insert
]]></source>
<target><![CDATA[
4998,6 → 5014,14
</message>
<message>
<source><![CDATA[
Output parameters
]]></source>
<target><![CDATA[
Ausgabe-Parameter
]]></target>
</message>
<message>
<source><![CDATA[
PDO Password
]]></source>
<target><![CDATA[
5974,6 → 5998,14
</message>
<message>
<source><![CDATA[
Re-Create
]]></source>
<target><![CDATA[
Neu-Erstellen
]]></target>
</message>
<message>
<source><![CDATA[
Re-Install database (all data will be deleted)
]]></source>
<target><![CDATA[
5982,6 → 6014,14
</message>
<message>
<source><![CDATA[
Receive
]]></source>
<target><![CDATA[
Empfangen
]]></target>
</message>
<message>
<source><![CDATA[
Received error status code: %1
]]></source>
<target><![CDATA[
6102,6 → 6142,14
</message>
<message>
<source><![CDATA[
Remove
]]></source>
<target><![CDATA[
Entfernen
]]></target>
</message>
<message>
<source><![CDATA[
Repeat
]]></source>
<target><![CDATA[
8718,6 → 8766,14
</message>
<message>
<source><![CDATA[
e.g. %1
]]></source>
<target><![CDATA[
z.B. %1
]]></target>
</message>
<message>
<source><![CDATA[
eMail address does not exist anymore. It was probably already changed.
]]></source>
<target><![CDATA[
8782,6 → 8838,14
</message>
<message>
<source><![CDATA[
if it was created
]]></source>
<target><![CDATA[
wenn es erstellt wurde
]]></target>
</message>
<message>
<source><![CDATA[
including your database* (only OIDs)
]]></source>
<target><![CDATA[
8854,6 → 8918,14
</message>
<message>
<source><![CDATA[
optional
]]></source>
<target><![CDATA[
optional
]]></target>
</message>
<message>
<source><![CDATA[
or run <a href="%1">setup</a> again
]]></source>
<target><![CDATA[
/trunk/plugins/viathinksoft/objectTypes/fourcc/OIDplusFourCC.class.php
269,7 → 269,7
*/
public function one_up()/*: ?OIDplusFourCC*/ {
// A FourCC is a FourCC, there is no hierarchy
return null;
return self::parse(self::ns().':');
}
 
/**
/trunk/plugins/viathinksoft/objectTypes/guid/OIDplusGuid.class.php
241,7 → 241,7
*/
public function one_up()/*: ?OIDplusGuid*/ {
// A GUID is a GUID, there is no hierarchy
return null;
return self::parse(self::ns().':');
}
 
/**
/trunk/plugins/viathinksoft/publicPages/000_objects/OIDplusPagePublicObjects.class.php
68,15 → 68,64
if (str_starts_with($endpoint, 'objects/')) {
$id = substr($endpoint, strlen('objects/'));
if ($requestMethod == "GET"/*Select*/) {
// TODO: Implement GET
http_response_code(501);
return array("error" => "Not implemented");
$output = array();
 
$res = OIDplus::db()->query("select id, ra_email, comment, confidential, title, description from ###objects where id = ?", array($id));
if (!$res->any()) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404);
$row = $res->fetch_array();
 
//$output['id'] = $row['id'];
$output['ra_email'] = $row['ra_email'];
$output['comment'] = $row['comment'];
$output['confidential'] = $row['confidential'];
$output['title'] = $row['title'];
$output['description'] = $row['description'];
 
$output['asn1ids'] = array();
$res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($id));
while ($row_asn = $res_asn->fetch_array()) {
$output['asn1ids'][] = $row_asn['name'];
}
 
$output['iris'] = array();
$res_iri = OIDplus::db()->query("select name from ###iri where oid = ?", array($id));
while ($row_iri = $res_iri->fetch_array()) {
$output['iris'][] = $row_iri['name'];
}
 
http_response_code(200);
$output['status'] = 0/*OK*/;
return $output;
} else if ($requestMethod == "PUT"/*Replace*/) {
// TODO: Implement PUT
http_response_code(501);
return array("error" => "Not implemented");
$obj = OIDplusObject::parse($id);
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400);
 
$params = array();
$params['id'] = $id;
$params['ra_email'] = $_POST['ra_email'] ?? '';
$params['comment'] = $_POST['comment'] ?? '';
$params['confidential'] = $_POST['confidential'] ?? false;
$params['title'] = $_POST['title'] ?? '';
$params['description'] = $_POST['description'] ?? '';
$params['asn1ids'] = $_POST['asn1ids'] ?? array();
$params['iris'] = $_POST['iris'] ?? array();
 
if (OIDplusObject::exists($id)) {
// TODO: Problem: The superior RA cannot set title/description, so they cannot perform the PUT command!
$res = self::action('Update', $params);
} else {
$params['parent'] = $obj->getParent();
$params['id_fully_qualified'] = true;
$res = self::action('Insert', $params);
}
http_response_code(200);
return $res;
} else if ($requestMethod == "POST"/*Insert*/) {
$params = $_POST;
$obj = OIDplusObject::parse($id);
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
$params['parent'] = $obj->getParent();
$params['id_fully_qualified'] = true;
$params['id'] = $id;
$res = self::action('Insert', $params);
http_response_code(200);
94,7 → 143,8
http_response_code(200);
return $res;
} else {
throw new OIDplusException(_L("Unsupported request method"), null, 404);
//throw new OIDplusException(_L("Not implemented"), null, 501);
throw new OIDplusException(_L("Unsupported request method"), null, 400);
}
} else {
return false;
102,6 → 152,27
}
 
/**
* @param array $struct
* @return string
*/
private function array_to_html_ul_li(array $struct): string {
// TODO: put in includes/functions.inc.php
$res = '';
$res .= '<ul>';
foreach ($struct as $name => $val) {
$res .= '<li>';
if (is_array($val)) {
$res .= $name . self::array_to_html_ul_li($val);
} else {
$res .= $val;
}
$res .= '</li>';
}
$res .= '</ul>';
return $res;
}
 
/**
* Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
* Outputs information about valid endpoints
* @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented
109,17 → 180,80
*/
public function restApiInfo(string $kind='html'): string {
if ($kind === 'html') {
// TODO: Make a good documentation.....
$out = '<ul><li><b>Objects API</b> (Work in progress, not tested)<ul>';
$out .= '<li>GET objects/[id]<ul><li>Input parameters: None</li><li>Output parameters: WORK IN PROGRESS</li></ul></li>';
$out .= '<li>PUT objects/[id]<ul><li>Input parameters: WORK IN PROGRESS</li><li>Output parameters: WORK IN PROGRESS</li></ul></li>';
$out .= '<li>POST objects/[id]<ul><li>Input parameters: WORK IN PROGRESS</li><li>Output parameters: WORK IN PROGRESS</li></ul></li>';
$out .= '<li>PATCH objects/[id]<ul><li>Input parameters: ra_email (optional), comment (optional), iris (optional), asn1ids (optional), confidential (optional), title (optional), description (optional)</li><li>Output parameters: status|error</li></ul></li>';
$out .= '<li>DELETE objects/[id]<ul><li>Input parameters: None</li><li>Output parameters: status|error</li></ul></li>';
$out .= '</ul></li></ul>';
return $out;
$struct = [
"Objects API" => [
'('._L('Receive').') GET objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>' => [
_L('Input parameters') => [
'<i>'._L('None').'</i>'
],
_L('Output parameters') => [
'status|error',
'ra_email',
'comment',
'iris',
'asn1ids',
'confidential',
'title',
'description'
]
],
'('._L('Re-Create').') PUT objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>' => [
_L('Input parameters') => [
'ra_email ('._L('optional').')',
'comment ('._L('optional').')',
'iris ('._L('optional').')',
'asn1ids ('._L('optional').')',
'confidential ('._L('optional').')',
'title ('._L('optional').')',
'description ('._L('optional').')'
],
_L('Output parameters') => [
'status|error',
'inserted_id ('._L('if it was created').')'
]
],
'('._L('Create').') POST objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>' => [
_L('Input parameters') => [
'ra_email ('._L('optional').')',
'comment ('._L('optional').')',
'iris ('._L('optional').')',
'asn1ids ('._L('optional').')',
'confidential ('._L('optional').')',
'title ('._L('optional').')',
'description ('._L('optional').')'
],
_L('Output parameters') => [
'status|error',
'inserted_id'
]
],
'('._L('Update').') PATCH objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>' => [
_L('Input parameters') => [
'ra_email ('._L('optional').')',
'comment ('._L('optional').')',
'iris ('._L('optional').')',
'asn1ids ('._L('optional').')',
'confidential ('._L('optional').')',
'title ('._L('optional').')',
'description ('._L('optional').')'
],
_L('Output parameters') => [
'status|error'
]
],
'('._L('Remove').') DELETE objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>' => [
_L('Input parameters') => [
'<i>'._L('None').'</i>'
],
_L('Output parameters') => [
'status|error'
]
]
]
];
return self::array_to_html_ul_li($struct);
} else {
throw new OIDplusException(_L('Invalid REST API information format'));
throw new OIDplusException(_L('Invalid REST API information format'), null, 500);
}
}
 
142,7 → 276,7
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
 
if (!OIDplusObject::exists($id)) {
throw new OIDplusException(_L('Object %1 does not exist',$id));
throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404);
}
 
// Check if permitted
208,7 → 342,7
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
 
if (!OIDplusObject::exists($id)) {
throw new OIDplusException(_L('Object %1 does not exist',$id));
throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404);
}
 
// Check if permitted
230,13 → 364,13
assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
if (!$obj->isWellKnown()) {
if (isset($params['iris'])) {
$ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
$ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
$ids = array_map('trim',$ids);
$obj->replaceIris($ids, true);
}
 
if (isset($params['asn1ids'])) {
$ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
$ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
$ids = array_map('trim',$ids);
$obj->replaceAsn1Ids($ids, true);
}
283,13 → 417,13
assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
if (!$obj->isWellKnown()) {
if (isset($params['iris'])) {
$ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
$ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
$ids = array_map('trim',$ids);
$obj->replaceIris($ids, false);
}
 
if (isset($params['asn1ids'])) {
$ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
$ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
$ids = array_map('trim',$ids);
$obj->replaceAsn1Ids($ids, false);
}
370,7 → 504,7
}
 
// Action: Insert
// Parameters: parent, id, ra_email, confidential, iris, asn1ids
// Parameters: parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description
// Outputs: status=<0 Error, =0 Success, with following bitfields for further information:
// x+1 = RA is not registered
// x+2 = RA is not registered, but it cannot be invited
385,7 → 519,7
if (!$objParent->isRoot()) {
$idParent = $objParent->nodeId();
if (!OIDplusObject::exists($idParent)) {
throw new OIDplusException(_L('Parent object %1 does not exist',$idParent));
throw new OIDplusException(_L('Parent object %1 does not exist',$idParent), null, 404);
}
}
 
412,7 → 546,16
 
// Determine absolute OID name
// Note: At addString() and parse(), the syntax of the ID will be checked
if ($params['id_fully_qualified'] ?? false) {
$id = $params['id'];
$obj = OIDplusObject::parse($id);
$objParentTest = $obj->getParent();
if (!$objParentTest || !$objParentTest->equals($objParent)) throw new OIDplusException(_L('Cannot verify that %1 has parent %2', $obj->nodeId(), $objParent->nodeId()));
} else {
$id = $objParent->addString($params['id']);
$obj = OIDplusObject::parse($id);
}
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
 
// Check, if the OID exists
if (OIDplusObject::exists($id)) {
419,9 → 562,6
throw new OIDplusException(_L('Object %1 already exists!',$id));
}
 
$obj = OIDplusObject::parse($id);
if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
 
foreach (OIDplus::getAllPlugins() as $plugin) {
if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) {
$plugin->beforeObjectInsert($id, $params);
433,13 → 573,13
assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
if (!$obj->isWellKnown()) {
if (isset($params['iris'])) {
$ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
$ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
$ids = array_map('trim',$ids);
$obj->replaceIris($ids, true);
}
 
if (isset($params['asn1ids'])) {
$ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
$ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
$ids = array_map('trim',$ids);
$obj->replaceAsn1Ids($ids, true);
}
470,8 → 610,8
 
$confidential = isset($params['confidential']) && $params['confidential'] == 'true';
$comment = $params['comment'] ?? '';
$title = '';
$description = '';
$title = $params['title'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards!
$description = $params['description'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards!
 
if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
$maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
486,13 → 626,13
assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
if (!$obj->isWellKnown()) {
if (isset($params['iris'])) {
$ids = ($params['iris'] == '') ? array() : explode(',',$params['iris']);
$ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris']));
$ids = array_map('trim',$ids);
$obj->replaceIris($ids, false);
}
 
if (isset($params['asn1ids'])) {
$ids = ($params['asn1ids'] == '') ? array() : explode(',',$params['asn1ids']);
$ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids']));
$ids = array_map('trim',$ids);
$obj->replaceAsn1Ids($ids, false);
}
/trunk/plugins/viathinksoft/publicPages/000_objects/OIDplusPagePublicObjects.js
96,6 → 96,7
plugin:OIDplusPagePublicObjects.oid,
action:"Insert",
id:$("#id")[0].value,
id_fully_qualified:false,
ra_email:$("#ra_email")[0].value,
comment:$("#comment")[0].value,
asn1ids:($("#asn1ids")[0] ? $("#asn1ids")[0].value : null),