Subversion Repositories oidplus

Rev

Rev 1206 | 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 OIDplusPageAdminListRAs extends OIDplusPagePluginAdmin {
27
 
1116 daniel-mar 28
        /**
29
         * @param bool $html
30
         * @return void
31
         */
32
        public function init(bool $html=true) {
635 daniel-mar 33
                // Nothing
34
        }
35
 
1116 daniel-mar 36
        /**
37
         * @return array
38
         * @throws OIDplusConfigInitializationException
39
         * @throws OIDplusException
40
         */
41
        private function get_ralist(): array {
635 daniel-mar 42
                $tmp = array();
43
                if (OIDplus::db()->getSlang()->id() == 'mysql') {
1171 daniel-mar 44
                        $res = OIDplus::db()->query("select distinct BINARY(email) as distinct_email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive
635 daniel-mar 45
                } else {
1171 daniel-mar 46
                        $res = OIDplus::db()->query("select distinct email as distinct_email from ###ra"); // distinct in PGSQL is always case sensitive
635 daniel-mar 47
                }
48
                while ($row = $res->fetch_array()) {
1171 daniel-mar 49
                        $tmp[$row['distinct_email']] = 1;
635 daniel-mar 50
                }
51
                if (OIDplus::db()->getSlang()->id() == 'mysql') {
1171 daniel-mar 52
                        $res = OIDplus::db()->query("select distinct BINARY(ra_email) as distinct_ra_email from ###objects");
635 daniel-mar 53
                } else {
1171 daniel-mar 54
                        $res = OIDplus::db()->query("select distinct ra_email as distinct_ra_email from ###objects");
635 daniel-mar 55
                }
56
                while ($row = $res->fetch_array()) {
1171 daniel-mar 57
                        if (!isset($tmp[$row['distinct_ra_email']])) {
58
                                $tmp[$row['distinct_ra_email']] = 0;
635 daniel-mar 59
                        } else {
1171 daniel-mar 60
                                $tmp[$row['distinct_ra_email']] = 2;
635 daniel-mar 61
                        }
62
                }
63
                ksort($tmp);
64
 
65
                return $tmp;
66
        }
67
 
1116 daniel-mar 68
        /**
69
         * @param string $id
70
         * @param array $out
71
         * @param bool $handled
72
         * @return void
73
         * @throws OIDplusConfigInitializationException
74
         * @throws OIDplusException
75
         */
76
        public function gui(string $id, array &$out, bool &$handled) {
635 daniel-mar 77
                if ($id === 'oidplus:list_ra') {
78
                        $handled = true;
79
                        $out['title'] = _L('RA Listing');
801 daniel-mar 80
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
635 daniel-mar 81
 
82
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
1266 daniel-mar 83
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
635 daniel-mar 84
                        }
85
 
86
                        $out['text'] = '';
87
 
88
                        $tmp = $this->get_ralist();
89
 
90
                        $raCreatePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.130'); // OIDplusPageAdminCreateRa
91
                        if (!is_null($raCreatePlugin)) {
1172 daniel-mar 92
                                $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:create_ra').'>'._L('Create a new RA manually').'</a></p>';
635 daniel-mar 93
                        }
94
 
95
                        if (count($tmp) == 0) {
96
                                $out['text'] .= '<p>'._L('Currently there are no Registration Authorities.').'</p>';
97
                        }
98
 
99
                        foreach ($tmp as $ra_email => $registered) {
100
                                if (empty($ra_email)) {
101
                                        $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$').'>'._L('(Objects with undefined RA)').'</a></b></p>';
102
                                } else {
103
                                        if ($registered == 0) {
104
                                                $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$ra_email)).'>'.htmlentities($ra_email).'</a></b> '._L('(has objects, is not registered)').'</p>';
105
                                        }
106
                                        if ($registered == 1) {
107
                                                $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$ra_email)).'>'.htmlentities($ra_email).'</a></b> '._L('(registered, <font color="red">has no objects</font>)').'</p>';
108
                                        }
109
                                        if ($registered == 2) {
110
                                                $out['text'] .= '<p><b><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$ra_email)).'>'.htmlentities($ra_email).'</a></b></p>';
111
                                        }
112
                                }
113
                        }
114
                }
115
        }
116
 
1116 daniel-mar 117
        /**
118
         * @param array $json
119
         * @param string|null $ra_email
120
         * @param bool $nonjs
121
         * @param string $req_goto
122
         * @return bool
123
         * @throws OIDplusConfigInitializationException
124
         * @throws OIDplusException
125
         */
126
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 127
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
128
 
800 daniel-mar 129
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 130
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 131
                } else {
132
                        $tree_icon = null; // default icon (folder)
133
                }
134
 
135
                $children = array();
136
                $tmp = $this->get_ralist();
137
                foreach ($tmp as $ra_email => $registered) {
138
                        if (empty($ra_email)) {
139
                                $children[] = array(
140
                                        'id' => 'oidplus:rainfo$',
141
                                        'icon' => $tree_icon,
142
                                        'text' => _L('(Objects with undefined RA)')
143
                                );
144
                        } else {
145
                                if ($registered == 0) {
146
                                        $children[] = array(
147
                                                'id' => 'oidplus:rainfo$'.str_replace('@', '&', $ra_email),
148
                                                'icon' => $tree_icon,
149
                                                'text' => $ra_email.' <i>'._L('(has objects, is not registered)').'</i>'
150
                                        );
151
                                }
152
                                if ($registered == 1) {
153
                                        $children[] = array(
154
                                                'id' => 'oidplus:rainfo$'.$ra_email,
155
                                                'icon' => $tree_icon,
156
                                                'text' => $ra_email.' <i><font color="red">'._L('(has no objects)').'</font></i>'
157
                                        );
158
                                }
159
                                if ($registered == 2) {
160
                                        $children[] = array(
161
                                                'id' => 'oidplus:rainfo$'.$ra_email,
162
                                                'icon' => $tree_icon,
163
                                                'text' => $ra_email
164
                                        );
165
                                }
166
                        }
167
                }
168
 
169
                $json[] = array(
170
                        'id' => 'oidplus:list_ra',
171
                        'icon' => $tree_icon,
172
                        'text' => _L('List RAs'),
173
                        'children' => $children
174
                );
175
 
176
                return true;
177
        }
178
 
1116 daniel-mar 179
        /**
180
         * @param string $request
181
         * @return array|false
182
         */
183
        public function tree_search(string $request) {
635 daniel-mar 184
                // We don't need this, because the list of RAs is loaded without lazy-loading,
185
                // so the node does not need to be searched
186
                /*
187
                if (strpos($request, 'oidplus:rainfo$') === 0) {
188
                        if (OIDplus::authUtils()->isAdminLoggedIn()) {
189
                                return array('oidplus:login', ...dummy..., 'oidplus:list_ra', $request);
190
                        }
191
                }
192
                */
193
                return false;
194
        }
1116 daniel-mar 195
}