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

NathanGibbs3 / BASE / 627

pending completion
627

push

travis-ci-com

NathanGibbs3
Merge branch 'documentation' into devel

1766 of 6437 relevant lines covered (27.44%)

105.91 hits per line

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

90.76
/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, $BASE_IconSet;
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( intval($colored_alerts) != 0 ){ // Colored Alerts
22✔
118
                        $this->AddCap('BASE_UICA');
×
119
                }
120
                if(
121
                        !isset($BASE_IconSet) || !is_int($BASE_IconSet)
22✔
122
                        || $BASE_IconSet < 0
10✔
123
                ){ // Icon Set #
8✔
124
                                $BASE_IconSet = 0; // Default to 0 if something is not right.
22✔
125
                }
8✔
126
                $this->AddCap('BASE_UIConSet', $BASE_IconSet); // Icon Set #
22✔
127
                if( $debug_mode != 0 ){ // Debug Mode
22✔
128
                        $this->AddCap('BASE_UIDiag', $debug_mode);
×
129
                }
130
                if( $debug_time_mode != 0 ){ // Debug Time Mode
22✔
131
                        $this->AddCap('BASE_UIDiagTime', $debug_time_mode);
22✔
132
                }
8✔
133
                if( LoadedString($BASE_Language) ){ // UI Lang.
22✔
134
                        $this->AddCap('BASE_UILang', $BASE_Language);
×
135
                }
136
                $this->AddCap('UIMode', 'Knl');
22✔
137
                // Libs
138
                if ( PearInc('Mail', '', 'Mail') ){ // PEAR::MAIL
22✔
139
                        $this->AddCap('Mail');
22✔
140
                }
8✔
141
                if ( PearInc('Mime', 'Mail', 'mime') ){ // PEAR::MAIL_Mime
22✔
142
                        $this->AddCap('Mime');
22✔
143
                }
8✔
144
//                PEAR::DB
145
//    @include "DB.php";
146
//    if (class_exists("DB"))
147
//    {
148
//      $this->BCReg[CAPA_PEARDB] = true;
149
//    } else {
150
//      $this->BCReg[CAPA_PEARDB] = false;
151
//    }
152

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

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

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

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

270
        // @codeCoverageIgnoreStart
271
        // This output will be installation dependent.
272
        // Testing would be problematic.
273

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

305
        // @codeCoverageIgnoreEnd
306

307
}
308
?>
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