Subversion Repositories oidplus

Rev

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