• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 626

pending completion
626

push

travis-ci-com

NathanGibbs3
20230513 Closes #42 Closes #140 Closes #199
         Code Cleanup.

     File(s): base_common.php
            : base_conf.php.dist
            : includes/base_capabilities.php
            : setup/base_conf_contents.php
    Issue(s): #42
              New Config Var $AllowedClients.
              Does not need to be set on most configurations.
     File(s): base_qry_sqlcalls.php
            : includes/base_output_query.inc.php
              Code Cleanup.
     File(s): base_stat_alerts.php
            : base_stat_class.php
            : base_stat_iplink.php
            : base_stat_ports.php
            : base_stat_sensor.php
            : base_stat_uaddr.php
    Issue(s): #140 #199
     File(s): styles/base_common.css
              Set form margins to 0px.

46 of 46 new or added lines in 9 files covered. (100.0%)

3148 of 17531 relevant lines covered (17.96%)

23.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.52
/includes/base_capabilities.php
1
<?php
2
// Basic Analysis and Security Engine (BASE)
3
// Copyright (C) 2019-2023 Nathan Gibbs
4
// Copyright (C) 2004 BASE Project Team
5
// Copyright (C) 2000 Carnegie Mellon University
6
//
7
//   For license info: See the file 'base_main.php'
8
//
9
//       Project Lead: Nathan Gibbs
10
// Built upon work by: Kevin Johnson & the BASE Project Team
11
//                     Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
12
//
13
//            Purpose: Capabilities registry to identify what functionality
14
//                     is available on the currently running PHP install.
15
//                     This will allow us to vary functionality on the fly.
16
//
17
//          Author(s): Nathan Gibbs
18
//                     Kevin Johnson
19
//                     Chris Shepherd
20
// Ensure the conf file has been loaded. Prevent direct access to this file.
21
defined('_BASE_INC') or die('Accessing this file directly is not allowed.');
22

23
class BaseCapsRegistry{ // Capabilities Registry class definition
24
        var $BCReg = array();  // Capabilities Registry.
25

26
        function __construct(){ // PHP 5+ constructor Shim.
27
                // Class/Method agnostic shim code.
28
                $SCname = get_class();
22✔
29
                if ( method_exists($this, $SCname) ){
22✔
30
                        $SCargs = func_get_args();
22✔
31
                        call_user_func_array(array($this, $SCname), $SCargs);
22✔
32
                }else{
8✔
33
                        // @codeCoverageIgnoreStart
34
                        // Should never execute.
35
                        trigger_error( // Will need to add this message to the TD.
36
                                "Class: $SCname No Legacy Constructor.\n",
37
                                E_USER_ERROR
38
                        );
39
                        // @codeCoverageIgnoreEnd
40
                }
41
        }
16✔
42

43
        function BaseCapsRegistry(){ // PHP 4x constructor.
44
                GLOBAL $Use_Auth_System, $BASE_Language, $event_cache_auto_update,
16✔
45
                $colored_alerts, $archive_exists, $BASE_VERSION, $BASE_installID,
8✔
46
                $debug_time_mode, $debug_mode, $BASE_urlpath, $domain;
8✔
47
                if( $debug_mode > 1 ){
22✔
48
                        KML('Init: Caps Registry', 2);
×
49
                }
50
                // Automatically detect capabilities.
51
                $this->BCReg['PHP'] = array(); // PHP Capabilities.
22✔
52
                $this->BCReg['BASE'] = array(); // BASE Capabilities.
22✔
53
                // PHP
54
                $this->AddCap('PHP_Ver', implode('.', GetPHPSV())); // PHP Version
22✔
55
                if( function_exists('mail') ){ // PHP Mail
22✔
56
                        $this->AddCap('PHP_Mail');
22✔
57
                }
8✔
58
                if( function_exists('imagecreate') ){ // PHP GD
22✔
59
                        $this->AddCap('PHP_GD');
22✔
60
                }
8✔
61
                if( defined('GMP_VERSION') ){
22✔
62
                        $this->AddCap('PHP_GMP', GMP_VERSION);
22✔
63
                }
8✔
64
                // BASE Kernel & RTL Registartion
65
                if ( SetConst('BASE_KERNEL', 'None') ){
22✔
66
                        $BKV = NULL;
22✔
67
                }else{
8✔
68
                        $BKV = BASE_KERNEL;
×
69
                }
70
                $this->AddCap('BASE_Kernel',$BKV);
22✔
71
                if ( SetConst('BASE_RTL', 'None') ){
22✔
72
                        $BRV = NULL;
×
73
                }else{
74
                        $BRV = BASE_RTL;
22✔
75
                }
76
                $this->AddCap('BASE_RTL',$BRV);
22✔
77
                // BASE Version Info, change on new release.
78
                $Ver = '1.4.5'; // Official Release
22✔
79
                $Lady = 'lilias'; // Official Release Name
22✔
80
                // Last Dev Merge to master branch, change on new merge.
81
                $LPM = '2023-05-12';
22✔
82
                // Switch this off and update the official release Unit Test when
83
                // pushing a new release to master.
84
                $Dev = true; // Is this a Development build?
22✔
85
                if ( $Dev ){
22✔
86
                        $BVer = "$Ver-0.0.1 (Jayme)+$LPM";
22✔
87
                }else{
8✔
88
                        $BVer = "$Ver ($Lady)";
×
89
                }
90
                // Example Version String Official 1.4.5 (lilias)
91
                // Example Version String Dev 1.4.5-0.0.1 (Jayme)
92
                $this->AddCap('BASE_Ver',$BVer);
22✔
93
                $this->AddCap('BASE_Lady',$Lady);
22✔
94
                $this->AddCap('BASE_LPM',$LPM);
22✔
95
                $this->AddCap('BASE_Dev',$Dev);
22✔
96
                // BASE Capabilities Info, loaded from config file.
97
                if( LoadedString($BASE_installID) ){ // BASE InstallID
22✔
98
                        $this->AddCap('BASE_InID', $BASE_installID);
22✔
99
                }
8✔
100
                if( intval($Use_Auth_System) != 0 ){ // Auth system On.
22✔
101
                        $this->AddCap('BASE_Auth');
22✔
102
                }
8✔
103
                if( intval($archive_exists) != 0 ){ // Archive DB On.
22✔
104
                        $this->AddCap('BASE_ADB');
×
105
                }
106
                // BASE Server side settings, loaded from config file.
107
                if( LoadedString($BASE_urlpath) ){ // BASE Url Path
22✔
108
                        $this->AddCap('BASE_SSUrlPath', $BASE_urlpath);
×
109
                }
110
                if( LoadedString($domain) ){ // BASE Cookie Domain
22✔
111
                        $this->AddCap('BASE_SSDomain', $domain);
×
112
                }
113
                if( $event_cache_auto_update != 0 ){ // Event Cache Update.
22✔
114
                        $this->AddCap('BASE_SSECU');
×
115
                }
116
                // BASE UI Settings
117
                if( LoadedString($BASE_Language) ){ // UI Lang.
22✔
118
                        $this->AddCap('BASE_UILang', $BASE_Language);
×
119
                }
120
                if( $colored_alerts != 0 ){ // Colored Alerts
22✔
121
                        $this->AddCap('BASE_UICA');
×
122
                }
123
                if( $debug_mode != 0 ){ // Debug Mode
22✔
124
                        $this->AddCap('BASE_UIDiag', $debug_mode);
×
125
                }
126
                if( $debug_time_mode != 0 ){ // Debug Time Mode
22✔
127
                        $this->AddCap('BASE_UIDiagTime', $debug_time_mode);
22✔
128
                }
8✔
129
                $this->AddCap('UIMode', 'Knl');
22✔
130
                // Libs
131
                if ( PearInc('Mail', '', 'Mail') ){ // PEAR::MAIL
22✔
132
                        $this->AddCap('Mail');
22✔
133
                }
8✔
134
                if ( PearInc('Mime', 'Mail', 'mime') ){ // PEAR::MAIL_Mime
22✔
135
                        $this->AddCap('Mime');
22✔
136
                }
8✔
137
//                PEAR::DB
138
//    @include "DB.php";
139
//    if (class_exists("DB"))
140
//    {
141
//      $this->BCReg[CAPA_PEARDB] = true;
142
//    } else {
143
//      $this->BCReg[CAPA_PEARDB] = false;
144
//    }
145

146
                // @codeCoverageIgnoreStart
147
                if (
148
                        !getenv('TRAVIS')
149
                        && !(
150
                                $BASE_VERSION == '0.0.0 (Joette)'
151
                                && $BASE_installID == 'Test Runner'
152
                        )
153
                ){ // God awful hack to keep this code from running under test. As
154
                        // Image_Graph is not currently maintained and throws
155
                        //deprecation errors because of PHP 4x constructors.
156
                        if ( PearInc('Graphing', 'Image', 'Graph') ){ // PEAR::Image_Graph
157
                                $this->AddCap('Graph');
158
                        }
159
                }
160
                // @codeCoverageIgnoreEnd
161
                // Add checks here as needed.
162
        }
16✔
163

164
        // Caps Reg Management.
165
        function AddCap( $cap = '', $val = true ){
166
                $Ret = false;
110✔
167
                $EMPfx = 'BASE Security Alert ' . __FUNCTION__ . ': ';
110✔
168
                if( LoadedString($cap) ){
110✔
169
                        $SRF = false; // SubRegistry Flag
88✔
170
                        $SRegs = explode('_', $cap);
88✔
171
                        if( count($SRegs) > 1 ){ // SubReg?
88✔
172
                                $SRF = true;
44✔
173
                                $tmp = $SRegs[0];
44✔
174
                        }else{
16✔
175
                                $tmp = $cap;
66✔
176
                        }
177
                        if( is_key($tmp, $this->BCReg) ){ // Is Cap?
88✔
178
                                if( is_array($this->BCReg[$tmp]) ){ // Is SubReg?
66✔
179
                                        // This check also limits SubReg overwrites.
180
                                        if ( $SRF ){ // Are we using a SubReg Value?
44✔
181
                                                $Ret = true; // Set PHP & BASE Caps.
44✔
182
                                                // Write Lock
183
                                                if( !is_key($SRegs[1], $this->BCReg[$tmp]) ){
44✔
184
                                                        $this->BCReg[$tmp][$SRegs[1]] = $val;
22✔
185
                                                }else{
8✔
186
                                                        error_log(
22✔
187
                                                                $EMPfx . "SubReg: $cap tampering detected."
36✔
188
                                                        );
8✔
189
                                                }
190
                                        }else{
16✔
191
                                                error_log($EMPfx . "SubReg: $tmp tampering detected.");
28✔
192
                                        }
193
                                }else{ // Cap Overwrite
16✔
194
                                        $Ret = true;
22✔
195
                                        $this->BCReg[$cap] = $val;
50✔
196
                                }
197
                        }else{ // Cap Add
24✔
198
                                $Ret = true;
44✔
199
                                $this->BCReg[$cap] = $val;
44✔
200
                        }
201
                }
32✔
202
                return $Ret;
110✔
203
        }
204

205
        function DelCap( $cap = '' ){
206
                $Ret = false;
88✔
207
                $EMPfx = 'BASE Security Alert ' . __FUNCTION__ . ': ';
88✔
208
                if( LoadedString($cap) ){
88✔
209
                        $SRF = false; // SubRegistry Flag
66✔
210
                        $SRegs = explode('_', $cap);
66✔
211
                        if( count($SRegs) > 1 ){ // SubReg?
66✔
212
                                $SRF = true;
22✔
213
                                $tmp = $SRegs[0];
22✔
214
                        }else{
8✔
215
                                $tmp = $cap;
44✔
216
                        }
217
                        if( is_key($tmp, $this->BCReg) ){ // Is Cap?
66✔
218
                                if( is_array($this->BCReg[$tmp]) ){ // Is SubReg?
44✔
219
                                        $Ret = true; // Fake it. :-)
22✔
220
                                        error_log($EMPfx . "SubReg: $cap tampering detected.");
22✔
221
                                }else{ // Cap Delete.
8✔
222
                                        $Ret = true;
22✔
223
                                        unset($this->BCReg[$cap]);
36✔
224
                                }
225
                        }else{ // Delete non existant Cap.
16✔
226
                                $Ret = true; // Fake it. :-)
22✔
227
                                error_log($EMPfx . "Reg: $tmp tampering detected.");
22✔
228
                        }
229
                }
24✔
230
                return $Ret;
88✔
231
        }
232

233
        // Capability checking functions.
234
        function GetCap( $cap = '' ){
235
                $Ret = false;
176✔
236
                if( LoadedString($cap) ){
176✔
237
                        $SRF = false; // SubRegistry Flag
154✔
238
                        $SRegs = explode('_', $cap);
154✔
239
                        if( count($SRegs) > 1 ){ // SubReg?
154✔
240
                                $SRF = true;
44✔
241
                                $tmp = $SRegs[0];
44✔
242
                        }else{
16✔
243
                                $tmp = $cap;
110✔
244
                        }
245
                        if( is_key($tmp, $this->BCReg) ){ // Is Cap?
154✔
246
                                if( is_array($this->BCReg[$tmp]) ){ // Is SubReg?
132✔
247
                                        if ( $SRF ){ // Are we looking for a SubReg Value?
66✔
248
                                                // Check PHP & BASE Caps.
249
                                                if( is_key($SRegs[1], $this->BCReg[$tmp]) ){
44✔
250
                                                        $Ret = $this->BCReg[$tmp][$SRegs[1]];
44✔
251
                                                }
16✔
252
                                        }else{ // Return Entire SubReg.
16✔
253
                                                $Ret = $this->BCReg[$tmp];
50✔
254
                                        }
255
                                }else{
24✔
256
                                        $Ret = $this->BCReg[$cap];
66✔
257
                                }
258
                        }
48✔
259
                }
56✔
260
                return $Ret;
176✔
261
        }
262

263
        // @codeCoverageIgnoreStart
264
        // This output will be installation dependent.
265
        // Testing would be problematic.
266

267
        function DumpCaps(){
268
                $DI = array();
269
                $DD = array();
270
                $Libs = array();
271
                foreach( $this->BCReg as $key => $val ){
272
                        if( is_array($this->BCReg[$key]) ){
273
                                continue;
274
                        }
275
                        $Libs[$key] = $val;
276
                }
277
                foreach( $this->GetCap('PHP') as $key => $val ){
278
                        array_push($DD, $key);
279
                        array_push($DI, $val);
280
                }
281
                DDT($DI, $DD, 'PHP Caps', '', '', 1);
282
                $DI = array();
283
                $DD = array();
284
                foreach( $this->GetCap('BASE') as $key => $val ){
285
                        array_push($DD, $key);
286
                        array_push($DI, $val);
287
                }
288
                DDT($DI, $DD, 'BASE Caps', '', '', 1);
289
                $DI = array();
290
                $DD = array();
291
                foreach( $Libs as $key => $val ){
292
                        array_push($DD, $key);
293
                        array_push($DI, $val);
294
                }
295
                DDT($DI, $DD, 'PEAR Libs', '', '', 1);
296
        }
297

298
        // @codeCoverageIgnoreEnd
299

300
}
301
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc