Rev 978 | Rev 1086 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 978 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 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 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | class OIDplusPagePublicFreeOID extends OIDplusPagePluginPublic { |
22 | class OIDplusPagePublicFreeOID extends OIDplusPagePluginPublic { |
23 | 23 | ||
24 | private static function getFreeRootOid($with_ns) { |
24 | private static function getFreeRootOid($with_ns) { |
25 | return ($with_ns ? 'oid:' : '').OIDplus::config()->getValue('freeoid_root_oid'); |
25 | return ($with_ns ? 'oid:' : '').OIDplus::config()->getValue('freeoid_root_oid'); |
26 | } |
26 | } |
27 | 27 | ||
28 | public static function alreadyHasFreeOid($email, $getId = false){ |
28 | public static function alreadyHasFreeOid($email, $getId = false){ |
29 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ? and id like ? order by ".OIDplus::db()->natOrder('id'), array($email, self::getFreeRootOid(true).'.%')); |
29 | $res = OIDplus::db()->query("select id from ###objects where ra_email = ? and id like ? order by ".OIDplus::db()->natOrder('id'), array($email, self::getFreeRootOid(true).'.%')); |
30 | while ($row = $res->fetch_array()) { |
30 | while ($row = $res->fetch_array()) { |
31 | return $getId ? $row['id'] : true; |
31 | return $getId ? $row['id'] : true; |
32 | } |
32 | } |
33 | return $getId ? null : false; |
33 | return $getId ? null : false; |
34 | } |
34 | } |
35 | 35 | ||
36 | public function action($actionID, $params) { |
36 | public function action($actionID, $params) { |
37 | if (empty(self::getFreeRootOid(false))) throw new OIDplusException(_L('FreeOID service not available. Please ask your administrator.')); |
37 | if (empty(self::getFreeRootOid(false))) throw new OIDplusException(_L('FreeOID service not available. Please ask your administrator.')); |
38 | 38 | ||
39 | if ($actionID == 'request_freeoid') { |
39 | if ($actionID == 'request_freeoid') { |
40 | _CheckParamExists($params, 'email'); |
40 | _CheckParamExists($params, 'email'); |
41 | $email = $params['email']; |
41 | $email = $params['email']; |
42 | 42 | ||
43 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
43 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
44 | throw new OIDplusException(_L('This email address already has a FreeOID registered (%1)', $already_registered_oid)); |
44 | throw new OIDplusException(_L('This email address already has a FreeOID registered (%1)', $already_registered_oid)); |
45 | } |
45 | } |
46 | 46 | ||
47 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
47 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
48 | throw new OIDplusException(_L('Invalid email address')); |
48 | throw new OIDplusException(_L('Invalid email address')); |
49 | } |
49 | } |
50 | 50 | ||
51 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
51 | OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha'); |
52 | 52 | ||
53 | $root_oid = self::getFreeRootOid(false); |
53 | $root_oid = self::getFreeRootOid(false); |
54 | OIDplus::logger()->log("[INFO]OID(oid:$root_oid)+RA($email)!", "Requested a free OID for email '$email' to be placed into root '$root_oid'"); |
54 | OIDplus::logger()->log("[INFO]OID(oid:$root_oid)+RA($email)!", "Requested a free OID for email '$email' to be placed into root '$root_oid'"); |
55 | 55 | ||
56 | $timestamp = time(); |
56 | $timestamp = time(); |
57 | $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)); |
57 | $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)); |
58 | 58 | ||
59 | $message = file_get_contents(__DIR__ . '/request_msg.tpl'); |
59 | $message = file_get_contents(__DIR__ . '/request_msg.tpl'); |
60 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
60 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
61 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
61 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
62 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
62 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
63 | $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message); |
63 | $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message); |
64 | 64 | ||
65 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID request', $message); |
65 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID request', $message); |
66 | 66 | ||
67 | return array("status" => 0); |
67 | return array("status" => 0); |
68 | 68 | ||
69 | } else if ($actionID == 'activate_freeoid') { |
69 | } else if ($actionID == 'activate_freeoid') { |
70 | _CheckParamExists($params, 'email'); |
70 | _CheckParamExists($params, 'email'); |
71 | _CheckParamExists($params, 'auth'); |
71 | _CheckParamExists($params, 'auth'); |
72 | _CheckParamExists($params, 'timestamp'); |
72 | _CheckParamExists($params, 'timestamp'); |
73 | 73 | ||
74 | $email = $params['email']; |
74 | $email = $params['email']; |
75 | $auth = $params['auth']; |
75 | $auth = $params['auth']; |
76 | $timestamp = $params['timestamp']; |
76 | $timestamp = $params['timestamp']; |
77 | 77 | ||
78 | if (!OIDplus::authUtils()->validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) { |
78 | if (!OIDplus::authUtils()->validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) { |
79 | throw new OIDplusException(_L('Invalid auth key')); |
79 | throw new OIDplusException(_L('Invalid auth key')); |
80 | } |
80 | } |
81 | 81 | ||
82 | if ((OIDplus::config()->getValue('max_ra_invite_time') > 0) && (time()-$timestamp > OIDplus::config()->getValue('max_ra_invite_time'))) { |
82 | if ((OIDplus::config()->getValue('max_ra_invite_time') > 0) && (time()-$timestamp > OIDplus::config()->getValue('max_ra_invite_time'))) { |
83 | throw new OIDplusException(_L('Invitation expired!')); |
83 | throw new OIDplusException(_L('Invitation expired!')); |
84 | } |
84 | } |
85 | 85 | ||
86 | // 1. step: Check entered data and add the RA to the database |
86 | // 1. step: Check entered data and add the RA to the database |
87 | 87 | ||
88 | $ra = new OIDplusRA($email); |
88 | $ra = new OIDplusRA($email); |
89 | if (!$ra->existing()) { |
89 | if (!$ra->existing()) { |
90 | _CheckParamExists($params, 'password1'); |
90 | _CheckParamExists($params, 'password1'); |
91 | _CheckParamExists($params, 'password2'); |
91 | _CheckParamExists($params, 'password2'); |
92 | _CheckParamExists($params, 'ra_name'); |
92 | _CheckParamExists($params, 'ra_name'); |
93 | 93 | ||
94 | $password1 = $params['password1']; |
94 | $password1 = $params['password1']; |
95 | $password2 = $params['password2']; |
95 | $password2 = $params['password2']; |
96 | $ra_name = $params['ra_name']; |
96 | $ra_name = $params['ra_name']; |
97 | 97 | ||
98 | if ($password1 !== $password2) { |
98 | if ($password1 !== $password2) { |
99 | throw new OIDplusException(_L('Passwords do not match')); |
99 | throw new OIDplusException(_L('Passwords do not match')); |
100 | } |
100 | } |
101 | 101 | ||
102 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
102 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
103 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
103 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
104 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
104 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
105 | } |
105 | } |
106 | 106 | ||
107 | if (empty($ra_name)) { |
107 | if (empty($ra_name)) { |
108 | throw new OIDplusException(_L('Please enter your personal name or the name of your group.')); |
108 | throw new OIDplusException(_L('Please enter your personal name or the name of your group.')); |
109 | } |
109 | } |
110 | 110 | ||
111 | $ra->register_ra($password1); |
111 | $ra->register_ra($password1); |
112 | $ra->setRaName($ra_name); |
112 | $ra->setRaName($ra_name); |
113 | } else { |
113 | } else { |
114 | // RA already exists (e.g. was logged in using Google OAuth) |
114 | // RA already exists (e.g. was logged in using Google OAuth) |
115 | $ra_name = $ra->raName(); |
115 | $ra_name = $ra->raName(); |
116 | } |
116 | } |
117 | 117 | ||
118 | // 2. step: Add the new OID to the database |
118 | // 2. step: Add the new OID to the database |
119 | 119 | ||
120 | $url = isset($params['url']) ? $params['url'] : ''; |
120 | $url = isset($params['url']) ? $params['url'] : ''; |
121 | $title = isset($params['title']) ? $params['title'] : ''; |
121 | $title = isset($params['title']) ? $params['title'] : ''; |
122 | 122 | ||
123 | $root_oid = self::getFreeRootOid(false); |
123 | $root_oid = self::getFreeRootOid(false); |
124 | $new_oid = OIDplusOid::parse('oid:'.$root_oid)->appendArcs($this->freeoid_max_id()+1)->nodeId(false); |
124 | $new_oid = OIDplusOid::parse('oid:'.$root_oid)->appendArcs($this->freeoid_max_id()+1)->nodeId(false); |
125 | 125 | ||
126 | OIDplus::logger()->log("[INFO]OID(oid:$root_oid)+OIDRA(oid:$root_oid)!", "Child OID '$new_oid' added automatically by '$email' (RA Name: '$ra_name')"); |
126 | OIDplus::logger()->log("[INFO]OID(oid:$root_oid)+OIDRA(oid:$root_oid)!", "Child OID '$new_oid' added automatically by '$email' (RA Name: '$ra_name')"); |
127 | OIDplus::logger()->log("[INFO]OID(oid:$new_oid)+[OK]RA($email)!", "Free OID '$new_oid' activated (RA Name: '$ra_name')"); |
127 | OIDplus::logger()->log("[INFO]OID(oid:$new_oid)+[OK]RA($email)!", "Free OID '$new_oid' activated (RA Name: '$ra_name')"); |
128 | 128 | ||
129 | if ((!empty($url)) && (substr($url, 0, 4) != 'http')) $url = 'http://'.$url; |
129 | if ((!empty($url)) && (substr($url, 0, 4) != 'http')) $url = 'http://'.$url; |
130 | 130 | ||
131 | $description = ''; // '<p>'.htmlentities($ra_name).'</p>'; |
131 | $description = ''; // '<p>'.htmlentities($ra_name).'</p>'; |
132 | if (!empty($url)) { |
132 | if (!empty($url)) { |
133 | $description .= '<p>'._L('More information at %1','<a href="'.htmlentities($url).'">'.htmlentities($url).'</a>').'</p>'; |
133 | $description .= '<p>'._L('More information at %1','<a href="'.htmlentities($url).'">'.htmlentities($url).'</a>').'</p>'; |
134 | } |
134 | } |
135 | 135 | ||
136 | if (empty($title)) $title = $ra_name; |
136 | if (empty($title)) $title = $ra_name; |
137 | 137 | ||
138 | try { |
138 | try { |
139 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')-strlen('oid:'); |
139 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')-strlen('oid:'); |
140 | if (strlen($new_oid) > $maxlen) { |
140 | if (strlen($new_oid) > $maxlen) { |
141 | throw new OIDplusException(_L('The resulting OID %1 is too long (max allowed length: %2)',$new_oid,$maxlen)); |
141 | throw new OIDplusException(_L('The resulting OID %1 is too long (max allowed length: %2)',$new_oid,$maxlen)); |
142 | } |
142 | } |
143 | 143 | ||
144 | 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)); |
144 | 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)); |
145 | OIDplusObject::resetObjectInformationCache(); |
145 | OIDplusObject::resetObjectInformationCache(); |
146 | } catch (Exception $e) { |
146 | } catch (\Exception $e) { |
147 | $ra->delete(); |
147 | $ra->delete(); |
148 | throw $e; |
148 | throw $e; |
149 | } |
149 | } |
150 | 150 | ||
151 | // Send delegation report email to admin |
151 | // Send delegation report email to admin |
152 | 152 | ||
153 | $message = "OID delegation report\n"; |
153 | $message = "OID delegation report\n"; |
154 | $message .= "\n"; |
154 | $message .= "\n"; |
155 | $message .= "OID: ".$new_oid."\n";; |
155 | $message .= "OID: ".$new_oid."\n";; |
156 | $message .= "\n"; |
156 | $message .= "\n"; |
157 | $message .= "RA Name: $ra_name\n"; |
157 | $message .= "RA Name: $ra_name\n"; |
158 | $message .= "RA eMail: $email\n"; |
158 | $message .= "RA eMail: $email\n"; |
159 | $message .= "URL for more information: $url\n"; |
159 | $message .= "URL for more information: $url\n"; |
160 | $message .= "OID Name: $title\n"; |
160 | $message .= "OID Name: $title\n"; |
161 | $message .= "\n"; |
161 | $message .= "\n"; |
162 | $message .= "More details: ".OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL)."?goto=oid%3A$new_oid\n"; |
162 | $message .= "More details: ".OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL)."?goto=oid%3A$new_oid\n"; |
163 | 163 | ||
164 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title')." - OID $new_oid registered", $message); |
164 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title')." - OID $new_oid registered", $message); |
165 | 165 | ||
166 | // Send delegation information to user |
166 | // Send delegation information to user |
167 | 167 | ||
168 | $message = file_get_contents(__DIR__ . '/allocated_msg.tpl'); |
168 | $message = file_get_contents(__DIR__ . '/allocated_msg.tpl'); |
169 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
169 | $message = str_replace('{{SYSTEM_URL}}', OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL), $message); |
170 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
170 | $message = str_replace('{{SYSTEM_TITLE}}', OIDplus::config()->getValue('system_title'), $message); |
171 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
171 | $message = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $message); |
172 | $message = str_replace('{{NEW_OID}}', $new_oid, $message); |
172 | $message = str_replace('{{NEW_OID}}', $new_oid, $message); |
173 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID allocated', $message); |
173 | OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Free OID allocated', $message); |
174 | 174 | ||
175 | return array( |
175 | return array( |
176 | "new_oid" => $new_oid, |
176 | "new_oid" => $new_oid, |
177 | "status" => 0 |
177 | "status" => 0 |
178 | ); |
178 | ); |
179 | } else { |
179 | } else { |
180 | throw new OIDplusException(_L('Unknown action ID')); |
180 | throw new OIDplusException(_L('Unknown action ID')); |
181 | } |
181 | } |
182 | } |
182 | } |
183 | 183 | ||
184 | public function init($html=true) { |
184 | public function init($html=true) { |
185 | 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) { |
185 | 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) { |
186 | if (($value != '') && !oid_valid_dotnotation($value,false,false,1)) { |
186 | if (($value != '') && !oid_valid_dotnotation($value,false,false,1)) { |
187 | throw new OIDplusException(_L('Please enter a valid OID in dot notation or nothing')); |
187 | throw new OIDplusException(_L('Please enter a valid OID in dot notation or nothing')); |
188 | } |
188 | } |
189 | }); |
189 | }); |
190 | } |
190 | } |
191 | 191 | ||
192 | public function gui($id, &$out, &$handled) { |
192 | public function gui($id, &$out, &$handled) { |
193 | if (empty(self::getFreeRootOid(false))) return; |
193 | if (empty(self::getFreeRootOid(false))) return; |
194 | 194 | ||
195 | if (explode('$',$id)[0] == 'oidplus:com.viathinksoft.freeoid') { |
195 | if (explode('$',$id)[0] == 'oidplus:com.viathinksoft.freeoid') { |
196 | $handled = true; |
196 | $handled = true; |
197 | 197 | ||
198 | $out['title'] = _L('Register a free OID'); |
198 | $out['title'] = _L('Register a free OID'); |
199 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
199 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
200 | 200 | ||
201 | // Note: We are using the highest OID instead of the rowcount, because there might be OIDs which could have been deleted in between |
201 | // Note: We are using the highest OID instead of the rowcount, because there might be OIDs which could have been deleted in between |
202 | $highest_id = $this->freeoid_max_id(); |
202 | $highest_id = $this->freeoid_max_id(); |
203 | 203 | ||
204 | $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>'; |
204 | $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>'; |
205 | 205 | ||
206 | try { |
206 | try { |
207 | $out['text'] .= ' |
207 | $out['text'] .= ' |
208 | <form id="freeOIDForm" action="javascript:void(0);" onsubmit="return OIDplusPagePublicFreeOID.freeOIDFormOnSubmit();"> |
208 | <form id="freeOIDForm" action="javascript:void(0);" onsubmit="return OIDplusPagePublicFreeOID.freeOIDFormOnSubmit();"> |
209 | '._L('E-Mail').': <input type="text" id="email" value=""/><br><br> |
209 | '._L('E-Mail').': <input type="text" id="email" value=""/><br><br> |
210 | '.OIDplus::getActiveCaptchaPlugin()->captchaGenerate().' |
210 | '.OIDplus::getActiveCaptchaPlugin()->captchaGenerate().' |
211 | <br> |
211 | <br> |
212 | <input type="submit" value="'._L('Request a free OID').'"> |
212 | <input type="submit" value="'._L('Request a free OID').'"> |
213 | </form>'; |
213 | </form>'; |
214 | 214 | ||
215 | $obj = OIDplusOid::parse(self::getFreeRootOid(true)); |
215 | $obj = OIDplusOid::parse(self::getFreeRootOid(true)); |
216 | 216 | ||
217 | if (file_exists(__DIR__ . '/tos$'.OIDplus::getCurrentLang().'.html')) { |
217 | if (file_exists(__DIR__ . '/tos$'.OIDplus::getCurrentLang().'.html')) { |
218 | $tos = file_get_contents(__DIR__ . '/tos$'.OIDplus::getCurrentLang().'.html'); |
218 | $tos = file_get_contents(__DIR__ . '/tos$'.OIDplus::getCurrentLang().'.html'); |
219 | } else { |
219 | } else { |
220 | $tos = file_get_contents(__DIR__ . '/tos.html'); |
220 | $tos = file_get_contents(__DIR__ . '/tos.html'); |
221 | } |
221 | } |
222 | 222 | ||
223 | list($html, $js, $css) = extractHtmlContents($tos); |
223 | list($html, $js, $css) = extractHtmlContents($tos); |
224 | $tos = ''; |
224 | $tos = ''; |
225 | if (!empty($js)) $tos .= "<script>\n$js\n</script>"; |
225 | if (!empty($js)) $tos .= "<script>\n$js\n</script>"; |
226 | if (!empty($css)) $tos .= "<style>\n$css\n</style>"; |
226 | if (!empty($css)) $tos .= "<style>\n$css\n</style>"; |
227 | $tos .= stripHtmlComments($html); |
227 | $tos .= stripHtmlComments($html); |
228 | 228 | ||
229 | $tos = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $tos); |
229 | $tos = str_replace('{{ADMIN_EMAIL}}', OIDplus::config()->getValue('admin_email'), $tos); |
230 | if ($obj) { |
230 | if ($obj) { |
231 | $tos = str_replace('{{ROOT_OID}}', $obj->getDotNotation(), $tos); |
231 | $tos = str_replace('{{ROOT_OID}}', $obj->getDotNotation(), $tos); |
232 | $tos = str_replace('{{ROOT_OID_ASN1}}', $obj->getAsn1Notation(), $tos); |
232 | $tos = str_replace('{{ROOT_OID_ASN1}}', $obj->getAsn1Notation(), $tos); |
233 | $tos = str_replace('{{ROOT_OID_IRI}}', $obj->getIriNotation(), $tos); |
233 | $tos = str_replace('{{ROOT_OID_IRI}}', $obj->getIriNotation(), $tos); |
234 | } |
234 | } |
235 | $out['text'] .= $tos; |
235 | $out['text'] .= $tos; |
236 | 236 | ||
237 | if (OIDplus::config()->getValue('freeoid_root_oid') == '1.3.6.1.4.1.37476.9000') { |
237 | if (OIDplus::config()->getValue('freeoid_root_oid') == '1.3.6.1.4.1.37476.9000') { |
238 | $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).'); |
238 | $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).'); |
239 | $out['text'] .= ' - <a '.OIDplus::gui()->link('aid:D276000186F1').'>'._L('More information').'</a></p>'; |
239 | $out['text'] .= ' - <a '.OIDplus::gui()->link('aid:D276000186F1').'>'._L('More information').'</a></p>'; |
240 | } |
240 | } |
241 | } catch (Exception $e) { |
241 | } catch (\Exception $e) { |
242 | $out['text'] = _L('Error: %1',$e->getMessage()); |
242 | $out['text'] = _L('Error: %1',$e->getMessage()); |
243 | } |
243 | } |
244 | } else if (explode('$',$id)[0] == 'oidplus:com.viathinksoft.freeoid.activate_freeoid') { |
244 | } else if (explode('$',$id)[0] == 'oidplus:com.viathinksoft.freeoid.activate_freeoid') { |
245 | $handled = true; |
245 | $handled = true; |
246 | 246 | ||
247 | $email = explode('$',$id)[1]; |
247 | $email = explode('$',$id)[1]; |
248 | $timestamp = explode('$',$id)[2]; |
248 | $timestamp = explode('$',$id)[2]; |
249 | $auth = explode('$',$id)[3]; |
249 | $auth = explode('$',$id)[3]; |
250 | 250 | ||
251 | $out['title'] = _L('Activate Free OID'); |
251 | $out['title'] = _L('Activate Free OID'); |
252 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
252 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
253 | 253 | ||
254 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
254 | if ($already_registered_oid = $this->alreadyHasFreeOid($email, true)) { |
255 | throw new OIDplusException(_L('This email address already has a FreeOID registered (%1)', $already_registered_oid)); |
255 | throw new OIDplusException(_L('This email address already has a FreeOID registered (%1)', $already_registered_oid)); |
256 | } else { |
256 | } else { |
257 | if (!OIDplus::authUtils()->validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) { |
257 | if (!OIDplus::authUtils()->validateAuthKey('com.viathinksoft.freeoid.activate_freeoid;'.$email.';'.$timestamp, $auth)) { |
258 | $out['icon'] = 'img/error.png'; |
258 | $out['icon'] = 'img/error.png'; |
259 | $out['text'] = _L('Invalid authorization. Is the URL OK?'); |
259 | $out['text'] = _L('Invalid authorization. Is the URL OK?'); |
260 | } else { |
260 | } else { |
261 | $ra = new OIDplusRA($email); |
261 | $ra = new OIDplusRA($email); |
262 | $ra_existing = $ra->existing(); |
262 | $ra_existing = $ra->existing(); |
263 | 263 | ||
264 | $out['text'] = '<p>'._L('eMail-Address').': <b>'.$email.'</b></p>'; |
264 | $out['text'] = '<p>'._L('eMail-Address').': <b>'.$email.'</b></p>'; |
265 | 265 | ||
266 | $out['text'] .= ' <form id="activateFreeOIDForm" action="javascript:void(0);" onsubmit="return OIDplusPagePublicFreeOID.activateFreeOIDFormOnSubmit();">'; |
266 | $out['text'] .= ' <form id="activateFreeOIDForm" action="javascript:void(0);" onsubmit="return OIDplusPagePublicFreeOID.activateFreeOIDFormOnSubmit();">'; |
267 | $out['text'] .= ' <input type="hidden" id="email" value="'.htmlentities($email).'"/>'; |
267 | $out['text'] .= ' <input type="hidden" id="email" value="'.htmlentities($email).'"/>'; |
268 | $out['text'] .= ' <input type="hidden" id="timestamp" value="'.htmlentities($timestamp).'"/>'; |
268 | $out['text'] .= ' <input type="hidden" id="timestamp" value="'.htmlentities($timestamp).'"/>'; |
269 | $out['text'] .= ' <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>'; |
269 | $out['text'] .= ' <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>'; |
270 | 270 | ||
271 | if ($ra_existing) { |
271 | if ($ra_existing) { |
272 | $out['text'] .= ' '._L('Your personal name or the name of your group').':<br><b>'.htmlentities($ra->raName()).'</b><br><br>'; |
272 | $out['text'] .= ' '._L('Your personal name or the name of your group').':<br><b>'.htmlentities($ra->raName()).'</b><br><br>'; |
273 | } else { |
273 | } else { |
274 | $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 |
274 | $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 |
275 | } |
275 | } |
276 | $out['text'] .= ' '._L('Title of your OID (usually equal to your name, optional)').':<br><input type="text" id="title" value=""/><br><br>'; |
276 | $out['text'] .= ' '._L('Title of your OID (usually equal to your name, optional)').':<br><input type="text" id="title" value=""/><br><br>'; |
277 | $out['text'] .= ' '._L('URL for more information about your project(s) (optional)').':<br><input type="text" id="url" value=""/><br><br>'; |
277 | $out['text'] .= ' '._L('URL for more information about your project(s) (optional)').':<br><input type="text" id="url" value=""/><br><br>'; |
278 | 278 | ||
279 | if (!$ra_existing) { |
279 | if (!$ra_existing) { |
280 | $out['text'] .= ' <div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
280 | $out['text'] .= ' <div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
281 | $out['text'] .= ' <div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
281 | $out['text'] .= ' <div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
282 | } |
282 | } |
283 | $out['text'] .= ' <br><input type="submit" value="'._L('Register').'">'; |
283 | $out['text'] .= ' <br><input type="submit" value="'._L('Register').'">'; |
284 | $out['text'] .= ' </form>'; |
284 | $out['text'] .= ' </form>'; |
285 | } |
285 | } |
286 | } |
286 | } |
287 | } |
287 | } |
288 | } |
288 | } |
289 | 289 | ||
290 | public function publicSitemap(&$out) { |
290 | public function publicSitemap(&$out) { |
291 | if (empty(self::getFreeRootOid(false))) return; |
291 | if (empty(self::getFreeRootOid(false))) return; |
292 | $out[] = 'oidplus:com.viathinksoft.freeoid'; |
292 | $out[] = 'oidplus:com.viathinksoft.freeoid'; |
293 | } |
293 | } |
294 | 294 | ||
295 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
295 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
296 | if (empty(self::getFreeRootOid(false))) return false; |
296 | if (empty(self::getFreeRootOid(false))) return false; |
297 | 297 | ||
298 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
298 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
299 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
299 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
300 | } else { |
300 | } else { |
301 | $tree_icon = null; // default icon (folder) |
301 | $tree_icon = null; // default icon (folder) |
302 | } |
302 | } |
303 | 303 | ||
304 | $json[] = array( |
304 | $json[] = array( |
305 | 'id' => 'oidplus:com.viathinksoft.freeoid', |
305 | 'id' => 'oidplus:com.viathinksoft.freeoid', |
306 | 'icon' => $tree_icon, |
306 | 'icon' => $tree_icon, |
307 | 'text' => _L('Register a free OID') |
307 | 'text' => _L('Register a free OID') |
308 | ); |
308 | ); |
309 | 309 | ||
310 | return true; |
310 | return true; |
311 | } |
311 | } |
312 | 312 | ||
313 | # --- |
313 | # --- |
314 | 314 | ||
315 | protected static function freeoid_max_id() { |
315 | protected static function freeoid_max_id() { |
316 | $res = OIDplus::db()->query("select id from ###objects where id like ? order by ".OIDplus::db()->natOrder('id'), array(self::getFreeRootOid(true).'.%')); |
316 | $res = OIDplus::db()->query("select id from ###objects where id like ? order by ".OIDplus::db()->natOrder('id'), array(self::getFreeRootOid(true).'.%')); |
317 | $highest_id = 0; |
317 | $highest_id = 0; |
318 | while ($row = $res->fetch_array()) { |
318 | while ($row = $res->fetch_array()) { |
319 | $arc = substr_count(self::getFreeRootOid(false), '.')+1; |
319 | $arc = substr_count(self::getFreeRootOid(false), '.')+1; |
320 | $highest_id = explode('.',$row['id'])[$arc]; |
320 | $highest_id = explode('.',$row['id'])[$arc]; |
321 | } |
321 | } |
322 | return $highest_id; |
322 | return $highest_id; |
323 | } |
323 | } |
324 | 324 | ||
325 | public function tree_search($request) { |
325 | public function tree_search($request) { |
326 | return false; |
326 | return false; |
327 | } |
327 | } |
328 | } |
328 | } |
329 | 329 |