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

NathanGibbs3 / BASE / 590

pending completion
590

push

travis-ci-com

NathanGibbs3
20230420 Fix CI build breakage. 2

2755 of 16977 relevant lines covered (16.23%)

21.61 hits per line

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

94.12
/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();
20✔
29
                if ( method_exists($this, $SCname) ){
20✔
30
                        $SCargs = func_get_args();
20✔
31
                        call_user_func_array(array($this, $SCname), $SCargs);
20✔
32
                }else{
6✔
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
        }
14✔
42

43
        function BaseCapsRegistry(){ // PHP 4x constructor.
44
                GLOBAL $Use_Auth_System, $BASE_Language, $event_cache_auto_update,
14✔
45
                $colored_alerts, $archive_exists, $BASE_VERSION, $BASE_installID;
8✔
46
                // Automatically detect capabilities.
47
                $this->BCReg['PHP'] = array(); // PHP Capabilities.
20✔
48
                $this->BCReg['BASE'] = array(); // BASE Capabilities.
20✔
49
                // PHP
50
                $phpv = phpversion();
20✔
51
                $phpv = explode('.', $phpv);
20✔
52
                // Account for x.x.xXX subversions possibly having text like 4.0.4pl1
53
                if( is_numeric(substr($phpv[2], 1, 1)) ){ // No Text
20✔
54
                        $phpv[2] = substr($phpv[2], 0, 2);
20✔
55
                }else{
6✔
56
                        $phpv[2] = substr($phpv[2], 0, 1);
×
57
                }
58
                $this->AddCap('PHP_Ver', implode('.', $phpv));
20✔
59
                if( function_exists('mail') ){ // PHP Mail
20✔
60
                        $this->AddCap('PHP_Mail');
20✔
61
                }
6✔
62
                if( function_exists('imagecreate') ){ // PHP GD
20✔
63
                        $this->AddCap('PHP_GD');
20✔
64
                }
6✔
65
                // BASE Version Info, change on new release.
66
                $Ver = '1.4.5'; // Official Release
20✔
67
                $Lady = 'lilias'; // Official Release Name
20✔
68
                // Last Dev Merge to master branch, change on new merge.
69
                $LPM = '2023-04-13';
20✔
70
                // Switch this off and update the official release Unit Test when
71
                // pushing a new release to master.
72
                $Dev = true; // Is this a Development build?
20✔
73
                if ( $Dev ){
20✔
74
                        $BVer = "$Ver-0.0.1 (Jayme)+$LPM";
20✔
75
                }else{
6✔
76
                        $BVer = "$Ver ($Lady)";
×
77
                }
78
                // Example Version String Official 1.4.5 (lilias)
79
                // Example Version String Dev 1.4.5-0.0.1 (Jayme)
80
                $this->AddCap('BASE_Ver',$BVer);
20✔
81
                $this->AddCap('BASE_Lady',$Lady);
20✔
82
                $this->AddCap('BASE_LPM',$LPM);
20✔
83
                $this->AddCap('BASE_Dev',$Dev);
20✔
84
                // BASE Capabilities Info, loaded from config file.
85
                if( LoadedString($BASE_installID) ){ // BASE InstallID
20✔
86
                        $this->AddCap('BASE_InID', $BASE_installID);
20✔
87
                }
6✔
88
                if( $Use_Auth_System != 0 ){ // Auth system On.
20✔
89
                        $this->AddCap('BASE_Auth');
20✔
90
                }
6✔
91
                if( LoadedString($BASE_Language) ){ // UI Lang.
20✔
92
                        $this->AddCap('BASE_Lang', $BASE_Language);
×
93
                }
94
                if( $archive_exists != 0 ){ // Archive DB On.
20✔
95
                        $this->AddCap('BASE_ADB');
×
96
                }
97
                if( $event_cache_auto_update != 0 ){ // Event Cache Update.
20✔
98
                        $this->AddCap('BASE_ECU');
×
99
                }
100
                if( $colored_alerts != 0 ){ // Colored Alerts
20✔
101
                        $this->AddCap('BASE_UICA');
×
102
                }
103
                // Libs
104
                if ( PearInc('Mail', '', 'Mail') ){ // PEAR::MAIL
20✔
105
                        $this->AddCap('Mail');
20✔
106
                }
6✔
107
                if ( PearInc('Mime', 'Mail', 'mime') ){ // PEAR::MAIL_Mime
20✔
108
                        $this->AddCap('Mime');
20✔
109
                }
6✔
110
//                PEAR::DB
111
//    @include "DB.php";
112
//    if (class_exists("DB"))
113
//    {
114
//      $this->BCReg[CAPA_PEARDB] = true;
115
//    } else {
116
//      $this->BCReg[CAPA_PEARDB] = false;
117
//    }
118

119
                // @codeCoverageIgnoreStart
120
                if (
121
                        !getenv('TRAVIS')
122
                        && !(
123
                                $BASE_VERSION == '0.0.0 (Joette)'
124
                                && $BASE_installID == 'Test Runner'
125
                        )
126
                ){ // God awful hack to keep this code from running under test. As
127
                        // Image_Graph is not currently maintained and throws
128
                        //deprecation errors because of PHP 4x constructors.
129
                        if ( PearInc('Graphing', 'Image', 'Graph') ){ // PEAR::Image_Graph
130
                                $this->AddCap('Graph');
131
                        }
132
                }
133
                // @codeCoverageIgnoreEnd
134
                // Add checks here as needed.
135
        }
14✔
136

137
        // Caps Reg Management.
138
        function AddCap( $cap = '', $val = true ){
139
                $Ret = false;
100✔
140
                $EMPfx = 'BASE Security Alert ' . __FUNCTION__ . ': ';
100✔
141
                if( LoadedString($cap) ){
100✔
142
                        $SRF = false; // SubRegistry Flag
80✔
143
                        $SRegs = explode('_', $cap);
80✔
144
                        if( count($SRegs) > 1 ){ // SubReg?
80✔
145
                                $SRF = true;
40✔
146
                                $tmp = $SRegs[0];
40✔
147
                        }else{
12✔
148
                                $tmp = $cap;
60✔
149
                        }
150
                        if( base_array_key_exists($tmp, $this->BCReg) ){ // Is Cap?
80✔
151
                                if( is_array($this->BCReg[$tmp]) ){ // Is SubReg?
60✔
152
                                        // This check also limits SubReg overwrites.
153
                                        if ( $SRF ){ // Are we using a SubReg Value?
40✔
154
                                                $Ret = true; // Set PHP & BASE Caps.
40✔
155
                                                if(
156
                                                        !base_array_key_exists(
40✔
157
                                                                $SRegs[1], $this->BCReg[$tmp]
40✔
158
                                                        )
12✔
159
                                                ){ // Write Lock
12✔
160
                                                        $this->BCReg[$tmp][$SRegs[1]] = $val;
20✔
161
                                                }else{
6✔
162
                                                        error_log(
20✔
163
                                                                $EMPfx . "SubReg: $cap tampering detected."
34✔
164
                                                        );
6✔
165
                                                }
166
                                        }else{
12✔
167
                                                error_log($EMPfx . "SubReg: $tmp tampering detected.");
28✔
168
                                        }
169
                                }else{ // Cap Overwrite
12✔
170
                                        $Ret = true;
20✔
171
                                        $this->BCReg[$cap] = $val;
48✔
172
                                }
173
                        }else{ // Cap Add
18✔
174
                                $Ret = true;
40✔
175
                                $this->BCReg[$cap] = $val;
40✔
176
                        }
177
                }
24✔
178
                return $Ret;
100✔
179
        }
180

181
        function DelCap( $cap = '' ){
182
                $Ret = false;
80✔
183
                $EMPfx = 'BASE Security Alert ' . __FUNCTION__ . ': ';
80✔
184
                if( LoadedString($cap) ){
80✔
185
                        $SRF = false; // SubRegistry Flag
60✔
186
                        $SRegs = explode('_', $cap);
60✔
187
                        if( count($SRegs) > 1 ){ // SubReg?
60✔
188
                                $SRF = true;
20✔
189
                                $tmp = $SRegs[0];
20✔
190
                        }else{
6✔
191
                                $tmp = $cap;
40✔
192
                        }
193
                        if( base_array_key_exists($tmp, $this->BCReg) ){ // Is Cap?
60✔
194
                                if( is_array($this->BCReg[$tmp]) ){ // Is SubReg?
40✔
195
                                        $Ret = true; // Fake it. :-)
20✔
196
                                        error_log($EMPfx . "SubReg: $cap tampering detected.");
20✔
197
                                }else{ // Cap Delete.
6✔
198
                                        $Ret = true;
20✔
199
                                        unset($this->BCReg[$cap]);
34✔
200
                                }
201
                        }else{ // Delete non existant Cap.
12✔
202
                                $Ret = true; // Fake it. :-)
20✔
203
                                error_log($EMPfx . "Reg: $tmp tampering detected.");
20✔
204
                        }
205
                }
18✔
206
                return $Ret;
80✔
207
        }
208

209
        // Capability checking functions.
210
        function GetCap( $cap = '' ){
211
                $Ret = false;
160✔
212
                if( LoadedString($cap) ){
160✔
213
                        $SRF = false; // SubRegistry Flag
140✔
214
                        $SRegs = explode('_', $cap);
140✔
215
                        if( count($SRegs) > 1 ){ // SubReg?
140✔
216
                                $SRF = true;
40✔
217
                                $tmp = $SRegs[0];
40✔
218
                        }else{
12✔
219
                                $tmp = $cap;
100✔
220
                        }
221
                        if( base_array_key_exists($tmp, $this->BCReg) ){ // Is Cap?
140✔
222
                                if( is_array($this->BCReg[$tmp]) ){ // Is SubReg?
120✔
223
                                        if ( $SRF ){ // Are we looking for a SubReg Value?
60✔
224
                                                // Check PHP & BASE Caps.
225
                                                if(
226
                                                        base_array_key_exists(
40✔
227
                                                                $SRegs[1], $this->BCReg[$tmp]
40✔
228
                                                        )
12✔
229
                                                ){
12✔
230
                                                        $Ret = $this->BCReg[$tmp][$SRegs[1]];
40✔
231
                                                }
12✔
232
                                        }else{ // Return Entire SubReg.
12✔
233
                                                $Ret = $this->BCReg[$tmp];
48✔
234
                                        }
235
                                }else{
18✔
236
                                        $Ret = $this->BCReg[$cap];
60✔
237
                                }
238
                        }
36✔
239
                }
42✔
240
                return $Ret;
160✔
241
        }
242

243
        // @codeCoverageIgnoreStart
244
        // This output will be installation dependent.
245
        // Testing would be problematic.
246

247
        function DumpCaps(){
248
                $DI = array();
249
                $DD = array();
250
                $Libs = array();
251
                foreach( $this->BCReg as $key => $val ){
252
                        if( is_array($this->BCReg[$key]) ){
253
                                continue;
254
                        }
255
                        $Libs[$key] = $val;
256
                }
257
                foreach( $this->GetCap('PHP') as $key => $val ){
258
                        array_push($DD, $key);
259
                        array_push($DI, $val);
260
                }
261
                DDT($DI, $DD, 'PHP Caps', '', '', 1);
262
                $DI = array();
263
                $DD = array();
264
                foreach( $this->GetCap('BASE') as $key => $val ){
265
                        array_push($DD, $key);
266
                        array_push($DI, $val);
267
                }
268
                DDT($DI, $DD, 'BASE Caps', '', '', 1);
269
                $DI = array();
270
                $DD = array();
271
                foreach( $Libs as $key => $val ){
272
                        array_push($DD, $key);
273
                        array_push($DI, $val);
274
                }
275
                DDT($DI, $DD, 'PEAR Libs', '', '', 1);
276
        }
277

278
        // @codeCoverageIgnoreEnd
279

280
}
281
?>
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