Subversion Repositories oidplus

Rev

Rev 783 | Rev 800 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 783 Rev 790
Line 56... Line 56...
56
                        _CheckParamExists($params, 'id');
56
                        _CheckParamExists($params, 'id');
57
                        $id = $params['id'];
57
                        $id = $params['id'];
58
                        $obj = OIDplusObject::parse($id);
58
                        $obj = OIDplusObject::parse($id);
59
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
59
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id));
60
 
60
 
61
                        if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) {
61
                        if (!OIDplus::db()->query("select id from ###objects where id = ?", array($id))->any()) {
62
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
62
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
63
                        }
63
                        }
64
 
64
 
65
                        // Check if permitted
65
                        // Check if permitted
66
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'));
66
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'));
Line 86... Line 86...
86
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
86
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
87
                                do {
87
                                do {
88
                                        $res = OIDplus::db()->query("select tchild.id from ###objects tchild " .
88
                                        $res = OIDplus::db()->query("select tchild.id from ###objects tchild " .
89
                                                                    "left join ###objects tparent on tparent.id = tchild.parent " .
89
                                                                    "left join ###objects tparent on tparent.id = tchild.parent " .
90
                                                                    "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%'));
90
                                                                    "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%'));
91
                                        if ($res->num_rows() == 0) break;
91
                                        if (!$res->any()) break;
92
 
92
 
93
                                        while ($row = $res->fetch_array()) {
93
                                        while ($row = $res->fetch_array()) {
94
                                                $id_to_delete = $row['id'];
94
                                                $id_to_delete = $row['id'];
95
                                                OIDplus::logger()->log("[CRIT]OIDRA($id_to_delete)!", "Lost ownership of object '$id_to_delete' because one of the superior objects ('$id') was recursively deleted");
95
                                                OIDplus::logger()->log("[CRIT]OIDRA($id_to_delete)!", "Lost ownership of object '$id_to_delete' because one of the superior objects ('$id') was recursively deleted");
96
                                                OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete));
96
                                                OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete));
Line 120... Line 120...
120
                        _CheckParamExists($params, 'id');
120
                        _CheckParamExists($params, 'id');
121
                        $id = $params['id'];
121
                        $id = $params['id'];
122
                        $obj = OIDplusObject::parse($id);
122
                        $obj = OIDplusObject::parse($id);
123
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
123
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id));
124
 
124
 
125
                        if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) {
125
                        if (!OIDplus::db()->query("select id from ###objects where id = ?", array($id))->any()) {
126
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
126
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
127
                        }
127
                        }
128
 
128
 
129
                        // Check if permitted
129
                        // Check if permitted
130
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'));
130
                        if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'));
Line 224... Line 224...
224
                        $status = 0;
224
                        $status = 0;
225
 
225
 
226
                        if (!empty($new_ra)) {
226
                        if (!empty($new_ra)) {
227
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra));
227
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra));
228
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
228
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
229
                                if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
229
                                if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
230
                        }
230
                        }
231
 
231
 
232
                        if ($obj::ns() == 'oid') {
232
                        if ($obj::ns() == 'oid') {
233
                                if ($obj->isWellKnown()) {
233
                                if ($obj->isWellKnown()) {
234
                                        $status += 4;
234
                                        $status += 4;
Line 252... Line 252...
252
                        _CheckParamExists($params, 'id');
252
                        _CheckParamExists($params, 'id');
253
                        $id = $params['id'];
253
                        $id = $params['id'];
254
                        $obj = OIDplusObject::parse($id);
254
                        $obj = OIDplusObject::parse($id);
255
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id));
255
                        if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE2',$id));
256
 
256
 
257
                        if (OIDplus::db()->query("select id from ###objects where id = ?", array($id))->num_rows() == 0) {
257
                        if (!OIDplus::db()->query("select id from ###objects where id = ?", array($id))->any()) {
258
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
258
                                throw new OIDplusException(_L('Object %1 does not exist',$id));
259
                        }
259
                        }
260
 
260
 
261
                        // Check if allowed
261
                        // Check if allowed
262
                        if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'));
262
                        if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'));
Line 312... Line 312...
312
                        // Check if you have write rights on the parent (to create a new object)
312
                        // Check if you have write rights on the parent (to create a new object)
313
                        _CheckParamExists($params, 'parent');
313
                        _CheckParamExists($params, 'parent');
314
                        $objParent = OIDplusObject::parse($params['parent']);
314
                        $objParent = OIDplusObject::parse($params['parent']);
315
                        if ($objParent === null) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent']));
315
                        if ($objParent === null) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent']));
316
 
316
 
317
                        if (!$objParent->isRoot() && (OIDplus::db()->query("select id from ###objects where id = ?", array($objParent->nodeId()))->num_rows() == 0)) {
317
                        if (!$objParent->isRoot() && (!OIDplus::db()->query("select id from ###objects where id = ?", array($objParent->nodeId()))->any())) {
318
                                throw new OIDplusException(_L('Parent object %1 does not exist','".($objParent->nodeId())."'));
318
                                throw new OIDplusException(_L('Parent object %1 does not exist','".($objParent->nodeId())."'));
319
                        }
319
                        }
320
 
320
 
321
                        if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'));
321
                        if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'));
322
 
322
 
Line 342... Line 342...
342
                        // Note: At addString() and parse(), the syntax of the ID will be checked
342
                        // Note: At addString() and parse(), the syntax of the ID will be checked
343
                        $id = $objParent->addString($params['id']);
343
                        $id = $objParent->addString($params['id']);
344
 
344
 
345
                        // Check, if the OID exists
345
                        // Check, if the OID exists
346
                        $test = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
346
                        $test = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
347
                        if ($test->num_rows() >= 1) {
347
                        if ($test->any()) {
348
                                throw new OIDplusException(_L('Object %1 already exists!',$id));
348
                                throw new OIDplusException(_L('Object %1 already exists!',$id));
349
                        }
349
                        }
350
 
350
 
351
                        $obj = OIDplusObject::parse($id);
351
                        $obj = OIDplusObject::parse($id);
352
                                if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
352
                                if ($obj === null) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id));
Line 424... Line 424...
424
 
424
 
425
                        if (!empty($ra_email)) {
425
                        if (!empty($ra_email)) {
426
                                // Do we need to notify that the RA does not exist?
426
                                // Do we need to notify that the RA does not exist?
427
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
427
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
428
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
428
                                $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite
429
                                if ($res->num_rows() == 0) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
429
                                if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2;
430
                        }
430
                        }
431
 
431
 
432
                        if ($obj::ns() == 'oid') {
432
                        if ($obj::ns() == 'oid') {
433
                                if ($obj->isWellKnown()) {
433
                                if ($obj->isWellKnown()) {
434
                                        $status += 4;
434
                                        $status += 4;
Line 525... Line 525...
525
                                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
525
                                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
526
                                                $parent = null; // $obj->getParent();
526
                                                $parent = null; // $obj->getParent();
527
                                                break;
527
                                                break;
528
                                        } else {
528
                                        } else {
529
                                                $res = OIDplus::db()->query("select * from ###objects where id = ?", array($obj->nodeId()));
529
                                                $res = OIDplus::db()->query("select * from ###objects where id = ?", array($obj->nodeId()));
530
                                                if ($res->num_rows() == 0) {
530
                                                if (!$res->any()) {
531
                                                        http_response_code(404);
531
                                                        http_response_code(404);
532
                                                        $out['title'] = _L('Object not found');
532
                                                        $out['title'] = _L('Object not found');
533
                                                        $out['icon'] = 'img/error_big.png';
533
                                                        $out['icon'] = 'img/error_big.png';
534
                                                        $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
534
                                                        $out['text'] = _L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>');
535
                                                        return;
535
                                                        return;
Line 559... Line 559...
559
                                        $parent_link_text = $parent->objectTypeTitle();
559
                                        $parent_link_text = $parent->objectTypeTitle();
560
                                        $out['text'] = '<p><a '.OIDplus::gui()->link($parent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
560
                                        $out['text'] = '<p><a '.OIDplus::gui()->link($parent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text'];
561
 
561
 
562
                                } else {
562
                                } else {
563
                                        $res_ = OIDplus::db()->query("select * from ###objects where id = ?", array($parent->nodeId()));
563
                                        $res_ = OIDplus::db()->query("select * from ###objects where id = ?", array($parent->nodeId()));
564
                                        if ($res_->num_rows() > 0) {
564
                                        if ($res_->any()) {
565
                                                $row_ = $res_->fetch_array();
565
                                                $row_ = $res_->fetch_array();
566
 
566
 
567
                                                $parent_title = $row_['title'];
567
                                                $parent_title = $row_['title'];
568
                                                if (empty($parent_title) && ($parent->ns() == 'oid')) {
568
                                                if (empty($parent_title) && ($parent->ns() == 'oid')) {
569
                                                        // If not title is available, then use an ASN.1 identifier
569
                                                        // If not title is available, then use an ASN.1 identifier
570
                                                        $res_ = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($parent->nodeId()));
570
                                                        $res_ = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($parent->nodeId()));
571
                                                        if ($res_->num_rows() > 0) {
571
                                                        if ($res_->any()) {
572
                                                                $row_ = $res_->fetch_array();
572
                                                                $row_ = $res_->fetch_array();
573
                                                                $parent_title = $row_['name']; // TODO: multiple ASN1 ids?
573
                                                                $parent_title = $row_['name']; // TODO: multiple ASN1 ids?
574
                                                        }
574
                                                        }
575
                                                }
575
                                                }
576
 
576
 
Line 739... Line 739...
739
                                $goto = $req_goto;
739
                                $goto = $req_goto;
740
                                $path = array();
740
                                $path = array();
741
                                while (true) {
741
                                while (true) {
742
                                        $path[] = $goto;
742
                                        $path[] = $goto;
743
                                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($goto));
743
                                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($goto));
744
                                        if ($res->num_rows() == 0) break;
744
                                        if (!$res->any()) break;
745
                                        $row = $res->fetch_array();
745
                                        $row = $res->fetch_array();
746
                                        $goto = $row['parent'];
746
                                        $goto = $row['parent'];
747
                                        if ($goto == '') continue;
747
                                        if ($goto == '') continue;
748
                                }
748
                                }
749
 
749
 
Line 929... Line 929...
929
                        }
929
                        }
930
                        $output .= '</tr>';
930
                        $output .= '</tr>';
931
                }
931
                }
932
 
932
 
933
                $result = OIDplus::db()->query("select * from ###objects where id = ?", array($parent));
933
                $result = OIDplus::db()->query("select * from ###objects where id = ?", array($parent));
934
                $parent_ra_email = $result->num_rows() > 0 ? $result->fetch_object()->ra_email : '';
934
                $parent_ra_email = $result->any() ? $result->fetch_object()->ra_email : '';
935
 
935
 
936
                // "Create OID" row
936
                // "Create OID" row
937
                if ($objParent->userHasWriteRights()) {
937
                if ($objParent->userHasWriteRights()) {
938
                        $output .= '<tr>';
938
                        $output .= '<tr>';
939
                        $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix();
939
                        $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix();