Rev 13 | Rev 44 | 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')"); |
||
37 | 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 | 38 | 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', '')"); |
13 | daniel-mar | 39 | } |
40 | |||
2 | daniel-mar | 41 | public function __construct() { |
13 | daniel-mar | 42 | $this->loadConfig(); |
2 | daniel-mar | 43 | } |
44 | |||
45 | public function systemTitle() { |
||
13 | daniel-mar | 46 | return trim($this->values['system_title']); |
2 | daniel-mar | 47 | } |
48 | |||
49 | public function globalCC() { |
||
13 | daniel-mar | 50 | return trim($this->values['global_cc']); |
2 | daniel-mar | 51 | } |
52 | |||
53 | public function minRaPasswordLength() { |
||
13 | daniel-mar | 54 | return $this->values['ra_min_password_length']; |
2 | daniel-mar | 55 | } |
56 | |||
57 | /* hardcoded in setup/ , because during installation, we dont have a settings database |
||
58 | public function minAdminPasswordLength() { |
||
59 | return 6; |
||
60 | } |
||
61 | */ |
||
62 | |||
63 | public function maxInviteTime() { |
||
13 | daniel-mar | 64 | return $this->values['max_ra_invite_time']; |
2 | daniel-mar | 65 | } |
66 | |||
67 | public function maxPasswordResetTime() { |
||
13 | daniel-mar | 68 | return $this->values['max_ra_pwd_reset_time']; |
2 | daniel-mar | 69 | } |
70 | |||
71 | public function oidinfoExportProtected() { |
||
14 | daniel-mar | 72 | return $this->values['oidinfo_export_protected'] == '1'; |
2 | daniel-mar | 73 | } |
74 | |||
12 | daniel-mar | 75 | public function authToken() { |
13 | daniel-mar | 76 | $val = trim($this->values['whois_auth_token']); |
77 | return empty($val) ? false : $val; |
||
12 | daniel-mar | 78 | } |
14 | daniel-mar | 79 | |
80 | public function setValue($name, $value) { |
||
81 | // Check for valid values |
||
82 | |||
83 | if ($name == 'system_title') { |
||
84 | if (empty($value)) { |
||
85 | throw new Exception("Please enter a value for the system title."); |
||
86 | |||
87 | } |
||
88 | } |
||
89 | if ($name == 'global_cc') { |
||
90 | if (!empty($value) && !oiddb_valid_email($value)) { |
||
91 | throw new Exception("This is not a correct email address"); |
||
92 | } |
||
93 | } |
||
94 | if ($name == 'ra_min_password_length') { |
||
95 | if (!is_numeric($value) || ($value < 1)) { |
||
96 | throw new Exception("Please enter a valid password length."); |
||
97 | } |
||
98 | } |
||
99 | if (($name == 'max_ra_invite_time') || ($name == 'max_ra_pwd_reset_time')) { |
||
100 | if (!is_numeric($value) || ($value < 0)) { |
||
101 | throw new Exception("Please enter a valid value."); |
||
102 | } |
||
103 | } |
||
104 | if ($name == 'oidinfo_export_protected') { |
||
105 | if (($value != '0') && ($value != '1')) { |
||
106 | throw new Exception("Please enter either 0 or 1."); |
||
107 | } |
||
108 | } |
||
109 | if ($name == 'whois_auth_token') { |
||
110 | $test_value = preg_replace('@[0-9a-zA-Z]*@', '', $value); |
||
111 | if ($test_value != '') { |
||
112 | throw new Exception("Only characters and numbers are allowed as authentication token."); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | // Now change the value in the database |
||
117 | |||
118 | 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)."'")) { |
||
119 | throw new Exception(OIDplus::db()->error()); |
||
120 | } |
||
121 | } |
||
122 | |||
2 | daniel-mar | 123 | } |