Rev 44 | Rev 60 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
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 | |||
20 | class OIDplusConfig { |
||
21 | |||
13 | daniel-mar | 22 | protected $values; |
23 | |||
24 | protected function loadConfig() { |
||
25 | $this->values = array(); |
||
26 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."config"); |
||
27 | while ($row = OIDplus::db()->fetch_object($res)) { |
||
28 | $this->values[$row->name] = $row->value; |
||
29 | } |
||
30 | |||
31 | // Add defaults |
||
32 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('system_title', 'What is the name of your RA?', 'OIDplus 2.0')"); |
||
33 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('global_cc', 'Global CC for all outgoing emails?', '')"); |
||
34 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('ra_min_password_length', 'Minimum length for RA passwords', '6')"); |
||
35 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('max_ra_invite_time', 'Max RA invite time in seconds (0 = infinite)', '0')"); |
||
36 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('max_ra_pwd_reset_time', 'Max RA password reset time in seconds (0 = infinite)', '0')"); |
||
44 | daniel-mar | 37 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('max_ra_email_change_time', 'Max RA email change time in seconds (0 = infinite)', '0')"); |
13 | daniel-mar | 38 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('oidinfo_export_protected', 'OID-info.com export interface protected (requires admin log in), values 0/1', '1')"); |
14 | daniel-mar | 39 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('whois_auth_token', 'OID-over-WHOIS authentication token to display confidential data', '')"); |
46 | daniel-mar | 40 | OIDplus::db()->query("insert into ".OIDPLUS_TABLENAME_PREFIX."config (name, description, value) values ('allow_ra_email_change', 'Allow that RAs change their email address (0/1)', '1')"); |
13 | daniel-mar | 41 | } |
42 | |||
2 | daniel-mar | 43 | public function __construct() { |
13 | daniel-mar | 44 | $this->loadConfig(); |
2 | daniel-mar | 45 | } |
46 | |||
47 | public function systemTitle() { |
||
13 | daniel-mar | 48 | return trim($this->values['system_title']); |
2 | daniel-mar | 49 | } |
50 | |||
51 | public function globalCC() { |
||
13 | daniel-mar | 52 | return trim($this->values['global_cc']); |
2 | daniel-mar | 53 | } |
54 | |||
55 | public function minRaPasswordLength() { |
||
13 | daniel-mar | 56 | return $this->values['ra_min_password_length']; |
2 | daniel-mar | 57 | } |
58 | |||
59 | /* hardcoded in setup/ , because during installation, we dont have a settings database |
||
60 | public function minAdminPasswordLength() { |
||
61 | return 6; |
||
62 | } |
||
63 | */ |
||
64 | |||
65 | public function maxInviteTime() { |
||
13 | daniel-mar | 66 | return $this->values['max_ra_invite_time']; |
2 | daniel-mar | 67 | } |
68 | |||
69 | public function maxPasswordResetTime() { |
||
13 | daniel-mar | 70 | return $this->values['max_ra_pwd_reset_time']; |
2 | daniel-mar | 71 | } |
72 | |||
44 | daniel-mar | 73 | public function maxEmailChangeTime() { |
74 | return $this->values['max_ra_email_change_time']; |
||
75 | } |
||
76 | |||
2 | daniel-mar | 77 | public function oidinfoExportProtected() { |
14 | daniel-mar | 78 | return $this->values['oidinfo_export_protected'] == '1'; |
2 | daniel-mar | 79 | } |
80 | |||
12 | daniel-mar | 81 | public function authToken() { |
13 | daniel-mar | 82 | $val = trim($this->values['whois_auth_token']); |
83 | return empty($val) ? false : $val; |
||
12 | daniel-mar | 84 | } |
14 | daniel-mar | 85 | |
46 | daniel-mar | 86 | public function allowRaChangeEMailAddress() { |
87 | return $this->values['allow_ra_email_change'] == '1'; |
||
88 | } |
||
89 | |||
14 | daniel-mar | 90 | public function setValue($name, $value) { |
91 | // Check for valid values |
||
92 | |||
93 | if ($name == 'system_title') { |
||
94 | if (empty($value)) { |
||
95 | throw new Exception("Please enter a value for the system title."); |
||
96 | |||
97 | } |
||
98 | } |
||
99 | if ($name == 'global_cc') { |
||
100 | if (!empty($value) && !oiddb_valid_email($value)) { |
||
101 | throw new Exception("This is not a correct email address"); |
||
102 | } |
||
103 | } |
||
104 | if ($name == 'ra_min_password_length') { |
||
105 | if (!is_numeric($value) || ($value < 1)) { |
||
106 | throw new Exception("Please enter a valid password length."); |
||
107 | } |
||
108 | } |
||
44 | daniel-mar | 109 | if (($name == 'max_ra_invite_time') || ($name == 'max_ra_pwd_reset_time') || ($name == 'max_ra_email_change_time')) { |
14 | daniel-mar | 110 | if (!is_numeric($value) || ($value < 0)) { |
111 | throw new Exception("Please enter a valid value."); |
||
112 | } |
||
113 | } |
||
46 | daniel-mar | 114 | if (($name == 'oidinfo_export_protected') || ($name == 'allow_ra_email_change')) { |
14 | daniel-mar | 115 | if (($value != '0') && ($value != '1')) { |
116 | throw new Exception("Please enter either 0 or 1."); |
||
117 | } |
||
118 | } |
||
119 | if ($name == 'whois_auth_token') { |
||
120 | $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value); |
||
121 | if ($test_value != '') { |
||
122 | throw new Exception("Only characters and numbers are allowed as authentication token."); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | // Now change the value in the database |
||
127 | |||
128 | if (!OIDplus::db()->query("update ".OIDPLUS_TABLENAME_PREFIX."config set value = '".OIDplus::db()->real_escape_string($value)."' where name = '".OIDplus::db()->real_escape_string($name)."'")) { |
||
129 | throw new Exception(OIDplus::db()->error()); |
||
130 | } |
||
131 | } |
||
132 | |||
2 | daniel-mar | 133 | } |