Rev 1293 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
1086 | daniel-mar | 5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
635 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
635 | daniel-mar | 21 | |
1086 | daniel-mar | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
||
24 | // phpcs:enable PSR1.Files.SideEffects |
||
25 | |||
635 | daniel-mar | 26 | class OIDplusPagePublicFreeOID extends OIDplusPagePluginPublic { |
27 | |||
1116 | daniel-mar | 28 | /** |
1121 | daniel-mar | 29 | * @param bool $with_ns |
30 | * @return string|null |
||
1116 | daniel-mar | 31 | * @throws OIDplusException |
32 | */ |
||
1121 | daniel-mar | 33 | private static function getFreeRootOid(bool $with_ns)/*: ?string*/ { |
34 | if (!in_array('ViaThinkSoft\OIDplus\OIDplusOid',OIDplus::getEnabledObjectTypes())) { |
||
35 | return null; |
||
36 | } else { |
||
37 | $res = ($with_ns ? 'oid:' : '').OIDplus::config()->getValue('freeoid_root_oid'); |
||
38 | return !empty($res) ? $res : null; |
||
39 | } |
||
635 | daniel-mar | 40 | } |
41 | |||
1116 | daniel-mar | 42 | /** |
1130 | daniel-mar | 43 | * @param string $email |
1121 | daniel-mar | 44 | * @param bool $getId |
1201 | daniel-mar | 45 | * @return string|null|bool If $getId=true, then returns ID or NULL. If $getId=False, then returns TRUE or FALSE. |
1116 | daniel-mar | 46 | * @throws OIDplusException |
47 | */ |
||
1201 | daniel-mar | 48 | public static function alreadyHasFreeOid(string $email, bool $getId = false) { |
1148 | daniel-mar | 49 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ? and id like ?", array($email, self::getFreeRootOid(true).'.%')); |
1156 | daniel-mar | 50 | $res->naturalSortByField('id'); |
1140 | daniel-mar | 51 | if ($row = $res->fetch_array()) { |
635 | daniel-mar | 52 | return $getId ? $row['id'] : true; |
53 | } |
||
54 | return $getId ? null : false; |
||
55 | } |
||
56 | |||
1116 | daniel-mar | 57 | /** |
58 | * @param array $params |
||
1143 | daniel-mar | 59 | * @return array |
1116 | daniel-mar | 60 | * @throws OIDplusException |
61 | * @throws OIDplusMailException |
||
62 | */ |
||
1293 | daniel-mar | 63 | private function action_Request(array $params): array { |
635 | daniel-mar | 64 | if (empty(self::getFreeRootOid(false))) throw new OIDplusException(_L('FreeOID service not available. Please ask your administrator.')); |
65 | |||
1293 | daniel-mar | 66 | _CheckParamExists($params, 'email'); |
67 | $email = $params['email']; |
||
635 | daniel-mar | 68 | |
1293 | daniel-mar | 69 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
70 | throw new OIDplusHtmlException(_L('This email address already has a FreeOID registered (%1)', '<a '.OIDplus::gui()->link($already_registered_oid).'>'.htmlentities($already_registered_oid).'</a>')); |
||
71 | } |
||
635 | daniel-mar | 72 | |
1293 | daniel-mar | 73 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
74 | throw new OIDplusException(_L('Invalid email address')); |
||
75 | } |
||
635 | daniel-mar | 76 | |
1293 | daniel-mar | 77 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
635 | daniel-mar | 78 | |
1293 | daniel-mar | 79 | $root_oid = self::getFreeRootOid(false); |
80 | OIDplus::logger()->log("V2:[INFO]OID(oid:%1)+RA(%2)", "Requested a free OID for email '%2' to be placed into root '%1'", $root_oid, $email); |
||
635 | daniel-mar | 81 | |
1293 | daniel-mar | 82 | $activate_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . '?goto='.urlencode('oidplus:com.viathinksoft.freeoid.activate_freeoid$'.$email.'$'.OIDplus::authUtils()->makeAuthKey(['40c87e20-f4fb-11ed-86ca-3c4a92df8582',$email])); |
635 | daniel-mar | 83 | |
1293 | daniel-mar | 84 | $message = file_get_contents(__DIR__ . '/request_msg.tpl'); |
85 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
||
86 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
||
87 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
||
88 | $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message); |
||
635 | daniel-mar | 89 | |
1293 | daniel-mar | 90 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID request', $message); |
635 | daniel-mar | 91 | |
1293 | daniel-mar | 92 | return array("status" => 0); |
93 | } |
||
635 | daniel-mar | 94 | |
1293 | daniel-mar | 95 | /** |
96 | * @param array $params |
||
97 | * @return array |
||
98 | * @throws OIDplusException |
||
99 | * @throws OIDplusMailException |
||
100 | */ |
||
101 | private function action_Activate(array $params): array { |
||
102 | if (empty(self::getFreeRootOid(false))) throw new OIDplusException(_L('FreeOID service not available. Please ask your administrator.')); |
||
635 | daniel-mar | 103 | |
1293 | daniel-mar | 104 | _CheckParamExists($params, 'email'); |
105 | _CheckParamExists($params, 'auth'); |
||
635 | daniel-mar | 106 | |
1293 | daniel-mar | 107 | $email = $params['email']; |
108 | $auth = $params['auth']; |
||
635 | daniel-mar | 109 | |
1293 | daniel-mar | 110 | if (!OIDplus::authUtils()->validateAuthKey(['40c87e20-f4fb-11ed-86ca-3c4a92df8582',$email], $auth, OIDplus::config()->getValue('max_ra_invite_time', -1))) { |
111 | throw new OIDplusException(_L('Invalid or expired authentication key')); |
||
112 | } |
||
635 | daniel-mar | 113 | |
1369 | daniel-mar | 114 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
115 | throw new OIDplusHtmlException(_L('This email address already has a FreeOID registered (%1)', '<a '.OIDplus::gui()->link($already_registered_oid).'>'.htmlentities($already_registered_oid).'</a>')); |
||
116 | } |
||
117 | |||
1293 | daniel-mar | 118 | // 1. step: Check entered data and add the RA to the database |
702 | daniel-mar | 119 | |
1293 | daniel-mar | 120 | $ra = new OIDplusRA($email); |
121 | if (!$ra->existing()) { |
||
122 | _CheckParamExists($params, 'password1'); |
||
123 | _CheckParamExists($params, 'password2'); |
||
124 | _CheckParamExists($params, 'ra_name'); |
||
635 | daniel-mar | 125 | |
1293 | daniel-mar | 126 | $password1 = $params['password1']; |
127 | $password2 = $params['password2']; |
||
128 | $ra_name = $params['ra_name']; |
||
635 | daniel-mar | 129 | |
1293 | daniel-mar | 130 | if ($password1 !== $password2) { |
131 | throw new OIDplusException(_L('Passwords do not match')); |
||
132 | } |
||
635 | daniel-mar | 133 | |
1293 | daniel-mar | 134 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
135 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
||
136 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
||
137 | } |
||
635 | daniel-mar | 138 | |
1293 | daniel-mar | 139 | if (empty($ra_name)) { |
140 | throw new OIDplusException(_L('Please enter your personal name or the name of your group.')); |
||
635 | daniel-mar | 141 | } |
142 | |||
1293 | daniel-mar | 143 | $ra->register_ra($password1); |
144 | $ra->setRaName($ra_name); |
||
145 | } else { |
||
146 | // RA already exists (e.g. was logged in using Google OAuth) |
||
147 | $ra_name = $ra->raName(); |
||
148 | } |
||
635 | daniel-mar | 149 | |
1293 | daniel-mar | 150 | // 2. step: Add the new OID to the database |
635 | daniel-mar | 151 | |
1293 | daniel-mar | 152 | $url = $params['url'] ?? ''; |
153 | $title = $params['title'] ?? ''; |
||
635 | daniel-mar | 154 | |
1293 | daniel-mar | 155 | $root_oid = self::getFreeRootOid(false); |
156 | $new_oid = OIDplusOid::parse('oid:'.$root_oid)->appendArcs($this->freeoid_max_id()+1)->nodeId(false); |
||
635 | daniel-mar | 157 | |
1293 | daniel-mar | 158 | OIDplus::logger()->log("V2:[INFO]OID(oid:%2)+OIDRA(oid:%2)", "Child OID '%1' added automatically by '%3' (RA Name: '%4')", $new_oid, $root_oid, $email, $ra_name); |
159 | OIDplus::logger()->log("V2:[INFO]OID(oid:%1)+[OK]RA(%3)", "Free OID '%1' activated (RA Name: '%4')", $new_oid, $root_oid, $email, $ra_name); |
||
635 | daniel-mar | 160 | |
1293 | daniel-mar | 161 | if ((!empty($url)) && (substr($url, 0, 4) != 'http')) $url = 'http://'.$url; |
635 | daniel-mar | 162 | |
1293 | daniel-mar | 163 | $description = ''; // '<p>'.htmlentities($ra_name).'</p>'; |
164 | if (!empty($url)) { |
||
165 | $description .= '<p>'._L('More information at %1','<a href="'.htmlentities($url).'">'.htmlentities($url).'</a>').'</p>'; |
||
166 | } |
||
635 | daniel-mar | 167 | |
1293 | daniel-mar | 168 | if (empty($title)) $title = $ra_name; |
635 | daniel-mar | 169 | |
1293 | daniel-mar | 170 | try { |
171 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')-strlen('oid:'); |
||
172 | if (strlen($new_oid) > $maxlen) { |
||
173 | throw new OIDplusException(_L('The resulting OID %1 is too long (max allowed length: %2)',$new_oid,$maxlen)); |
||
635 | daniel-mar | 174 | } |
175 | |||
1293 | daniel-mar | 176 | OIDplus::db()->query("insert into ###objects (id, ra_email, parent, title, description, confidential, created) values (?, ?, ?, ?, ?, ?, ".OIDplus::db()->sqlDate().")", array('oid:'.$new_oid, $email, self::getFreeRootOid(true), $title, $description, false)); |
177 | OIDplusObject::resetObjectInformationCache(); |
||
178 | } catch (\Exception $e) { |
||
179 | $ra->delete(); |
||
180 | throw $e; |
||
181 | } |
||
635 | daniel-mar | 182 | |
1293 | daniel-mar | 183 | // Send delegation report email to admin |
635 | daniel-mar | 184 | |
1293 | daniel-mar | 185 | $message = "OID delegation report\n"; |
186 | $message .= "\n"; |
||
187 | $message .= "OID: ".$new_oid."\n"; |
||
188 | $message .= "\n"; |
||
189 | $message .= "RA Name: $ra_name\n"; |
||
190 | $message .= "RA eMail: $email\n"; |
||
191 | $message .= "URL for more information: $url\n"; |
||
192 | $message .= "OID Name: $title\n"; |
||
193 | $message .= "\n"; |
||
194 | $message .= "More details: ".OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL)."?goto=oid%3A$new_oid\n"; |
||
635 | daniel-mar | 195 | |
1293 | daniel-mar | 196 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title')." - OID $new_oid registered", $message); |
635 | daniel-mar | 197 | |
1293 | daniel-mar | 198 | // Send delegation information to user |
635 | daniel-mar | 199 | |
1293 | daniel-mar | 200 | $message = file_get_contents(__DIR__ . '/allocated_msg.tpl'); |
201 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
||
202 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
||
203 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
||
204 | $message = str_replace('{{NEW_OID}}', $new_oid, $message); |
||
205 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID allocated', $message); |
||
206 | |||
207 | return array( |
||
208 | "new_oid" => $new_oid, |
||
209 | "status" => 0 |
||
210 | ); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @param string $actionID |
||
215 | * @param array $params |
||
216 | * @return array |
||
217 | * @throws OIDplusException |
||
218 | * @throws OIDplusMailException |
||
219 | */ |
||
220 | public function action(string $actionID, array $params): array { |
||
221 | if ($actionID == 'request_freeoid') { |
||
222 | return $this->action_Request($params); |
||
223 | } else if ($actionID == 'activate_freeoid') { |
||
224 | return $this->action_Activate($params); |
||
635 | daniel-mar | 225 | } else { |
1116 | daniel-mar | 226 | return parent::action($actionID, $params); |
635 | daniel-mar | 227 | } |
228 | } |
||
229 | |||
1116 | daniel-mar | 230 | /** |
231 | * @param bool $html |
||
232 | * @return void |
||
233 | * @throws OIDplusException |
||
234 | */ |
||
235 | public function init(bool $html=true) { |
||
635 | daniel-mar | 236 | OIDplus::config()->prepareConfigKey('freeoid_root_oid', 'Root-OID of free OID service (a service where visitors can create their own OID using email verification)', '', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
237 | if (($value != '') && !oid_valid_dotnotation($value,false,false,1)) { |
||
238 | throw new OIDplusException(_L('Please enter a valid OID in dot notation or nothing')); |
||
239 | } |
||
240 | }); |
||
241 | } |
||
242 | |||
1116 | daniel-mar | 243 | /** |
244 | * @param string $id |
||
245 | * @param array $out |
||
246 | * @param bool $handled |
||
247 | * @return void |
||
248 | * @throws OIDplusException |
||
249 | */ |
||
250 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 251 | if (empty(self::getFreeRootOid(false))) return; |
252 | |||
253 | if (explode('$',$id)[0] == 'oidplus:com.viathinksoft.freeoid') { |
||
254 | $handled = true; |
||
255 | |||
256 | $out['title'] = _L('Register a free OID'); |
||
801 | daniel-mar | 257 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
635 | daniel-mar | 258 | |
259 | // Note: We are using the highest OID instead of the rowcount, because there might be OIDs which could have been deleted in between |
||
260 | $highest_id = $this->freeoid_max_id(); |
||
261 | |||
262 | $out['text'] .= '<p>'._L('Currently <a %1>%2 free OIDs have been</a> registered. Please enter your email below to receive a free OID.',OIDplus::gui()->link(self::getFreeRootOid(true)),$highest_id).'</p>'; |
||
263 | |||
264 | try { |
||
265 | $out['text'] .= ' |
||
266 | <form id="freeOIDForm" action="javascript:void(0);" onsubmit="return OIDplusPagePublicFreeOID.freeOIDFormOnSubmit();"> |
||
702 | daniel-mar | 267 | '._L('E-Mail').': <input type="text" id="email" value=""/><br><br> |
268 | '.OIDplus::getActiveCaptchaPlugin()->captchaGenerate().' |
||
269 | <br> |
||
962 | daniel-mar | 270 | <input type="submit" value="'._L('Request a free OID').'"> |
635 | daniel-mar | 271 | </form>'; |
272 | |||
273 | $obj = OIDplusOid::parse(self::getFreeRootOid(true)); |
||
274 | |||
275 | if (file_exists(__DIR__ . '/tos$'.OIDplus::getCurrentLang().'.html')) { |
||
276 | $tos = file_get_contents(__DIR__ . '/tos$'.OIDplus::getCurrentLang().'.html'); |
||
277 | } else { |
||
278 | $tos = file_get_contents(__DIR__ . '/tos.html'); |
||
279 | } |
||
280 | |||
281 | list($html, $js, $css) = extractHtmlContents($tos); |
||
282 | $tos = ''; |
||
283 | if (!empty($js)) $tos .= "<script>\n$js\n</script>"; |
||
284 | if (!empty($css)) $tos .= "<style>\n$css\n</style>"; |
||
821 | daniel-mar | 285 | $tos .= stripHtmlComments($html); |
635 | daniel-mar | 286 | |
287 | $tos = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $tos); |
||
288 | if ($obj) { |
||
289 | $tos = str_replace('{{ROOT_OID}}', $obj->getDotNotation(), $tos); |
||
290 | $tos = str_replace('{{ROOT_OID_ASN1}}', $obj->getAsn1Notation(), $tos); |
||
291 | $tos = str_replace('{{ROOT_OID_IRI}}', $obj->getIriNotation(), $tos); |
||
292 | } |
||
293 | $out['text'] .= $tos; |
||
960 | daniel-mar | 294 | |
295 | if (OIDplus::config()->getValue('freeoid_root_oid') == '1.3.6.1.4.1.37476.9000') { |
||
296 | $out['text'] .= '<p>'._L('<b>Note:</b> Since September 2022, owners of FreeOID automatically receive a free ISO-7816 compliant <b>Application Identifier</b> (AID) with the format <code>D2:76:00:01:86:F0:(FreeOID):FF:(PIX)</code> (up to 64 bits application specific PIX, depending on the length of the FreeOID number).'); |
||
1201 | daniel-mar | 297 | $out['text'] .= ' - <a '.OIDplus::gui()->link('aid:D276000186F1').'>'._L('More information').'</a></p>'; |
960 | daniel-mar | 298 | } |
1050 | daniel-mar | 299 | } catch (\Exception $e) { |
1201 | daniel-mar | 300 | $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage()); |
301 | $out['text'] = _L('Error: %1',$htmlmsg); |
||
635 | daniel-mar | 302 | } |
303 | } else if (explode('$',$id)[0] == 'oidplus:com.viathinksoft.freeoid.activate_freeoid') { |
||
304 | $handled = true; |
||
305 | |||
306 | $email = explode('$',$id)[1]; |
||
1283 | daniel-mar | 307 | $auth = explode('$',$id)[2]; |
635 | daniel-mar | 308 | |
309 | $out['title'] = _L('Activate Free OID'); |
||
801 | daniel-mar | 310 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
635 | daniel-mar | 311 | |
312 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
||
1201 | daniel-mar | 313 | throw new OIDplusHtmlException(_L('This email address already has a FreeOID registered (%1)', '<a '.OIDplus::gui()->link($already_registered_oid).'>'.htmlentities($already_registered_oid).'</a>')); |
635 | daniel-mar | 314 | } else { |
1283 | daniel-mar | 315 | if (!OIDplus::authUtils()->validateAuthKey(['40c87e20-f4fb-11ed-86ca-3c4a92df8582',$email], $auth, OIDplus::config()->getValue('max_ra_invite_time', -1))) { |
1206 | daniel-mar | 316 | throw new OIDplusException(_L('Invalid authorization. Is the URL OK?'), $out['title']); |
635 | daniel-mar | 317 | } else { |
318 | $ra = new OIDplusRA($email); |
||
319 | $ra_existing = $ra->existing(); |
||
320 | |||
321 | $out['text'] = '<p>'._L('eMail-Address').': <b>'.$email.'</b></p>'; |
||
322 | |||
323 | $out['text'] .= ' <form id="activateFreeOIDForm" action="javascript:void(0);" onsubmit="return OIDplusPagePublicFreeOID.activateFreeOIDFormOnSubmit();">'; |
||
324 | $out['text'] .= ' <input type="hidden" id="email" value="'.htmlentities($email).'"/>'; |
||
325 | $out['text'] .= ' <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>'; |
||
326 | |||
327 | if ($ra_existing) { |
||
328 | $out['text'] .= ' '._L('Your personal name or the name of your group').':<br><b>'.htmlentities($ra->raName()).'</b><br><br>'; |
||
329 | } else { |
||
330 | $out['text'] .= ' '._L('Your personal name or the name of your group').':<br><input type="text" id="ra_name" value=""/><br><br>'; // TODO: disable autocomplete |
||
331 | } |
||
332 | $out['text'] .= ' '._L('Title of your OID (usually equal to your name, optional)').':<br><input type="text" id="title" value=""/><br><br>'; |
||
333 | $out['text'] .= ' '._L('URL for more information about your project(s) (optional)').':<br><input type="text" id="url" value=""/><br><br>'; |
||
334 | |||
335 | if (!$ra_existing) { |
||
336 | $out['text'] .= ' <div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
||
337 | $out['text'] .= ' <div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
||
338 | } |
||
339 | $out['text'] .= ' <br><input type="submit" value="'._L('Register').'">'; |
||
340 | $out['text'] .= ' </form>'; |
||
341 | } |
||
342 | } |
||
343 | } |
||
344 | } |
||
345 | |||
1116 | daniel-mar | 346 | /** |
347 | * @param array $out |
||
348 | * @return void |
||
349 | * @throws OIDplusException |
||
350 | */ |
||
351 | public function publicSitemap(array &$out) { |
||
635 | daniel-mar | 352 | if (empty(self::getFreeRootOid(false))) return; |
353 | $out[] = 'oidplus:com.viathinksoft.freeoid'; |
||
354 | } |
||
355 | |||
1116 | daniel-mar | 356 | /** |
357 | * @param array $json |
||
358 | * @param string|null $ra_email |
||
359 | * @param bool $nonjs |
||
360 | * @param string $req_goto |
||
361 | * @return bool |
||
362 | * @throws OIDplusException |
||
363 | */ |
||
364 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 365 | if (empty(self::getFreeRootOid(false))) return false; |
366 | |||
800 | daniel-mar | 367 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 368 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 369 | } else { |
370 | $tree_icon = null; // default icon (folder) |
||
371 | } |
||
372 | |||
373 | $json[] = array( |
||
374 | 'id' => 'oidplus:com.viathinksoft.freeoid', |
||
375 | 'icon' => $tree_icon, |
||
376 | 'text' => _L('Register a free OID') |
||
377 | ); |
||
378 | |||
379 | return true; |
||
380 | } |
||
381 | |||
382 | # --- |
||
383 | |||
1116 | daniel-mar | 384 | /** |
385 | * @return int |
||
386 | * @throws OIDplusException |
||
387 | */ |
||
388 | protected static function freeoid_max_id(): int { |
||
1148 | daniel-mar | 389 | $res = OIDplus::db()->query("select id from ###objects where id like ?", array(self::getFreeRootOid(true).'.%')); |
1156 | daniel-mar | 390 | $res->naturalSortByField('id'); |
635 | daniel-mar | 391 | $highest_id = 0; |
392 | while ($row = $res->fetch_array()) { |
||
393 | $arc = substr_count(self::getFreeRootOid(false), '.')+1; |
||
394 | $highest_id = explode('.',$row['id'])[$arc]; |
||
395 | } |
||
1143 | daniel-mar | 396 | return (int)$highest_id; |
635 | daniel-mar | 397 | } |
398 | |||
1116 | daniel-mar | 399 | /** |
400 | * @param string $request |
||
401 | * @return array|false |
||
402 | */ |
||
403 | public function tree_search(string $request) { |
||
635 | daniel-mar | 404 | return false; |
405 | } |
||
406 | } |