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