wb-2_10_x / branches / main / framework / SysInfo.php @ 10
1 |
<?php
|
---|---|
2 |
|
3 |
/*
|
4 |
* Copyright (C) 2016 Manuela v.d.Decken <manuela@isteam.de>
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
19 |
*/
|
20 |
|
21 |
/**
|
22 |
* Description of SysInfo
|
23 |
*
|
24 |
* @category Core
|
25 |
* @package Core_SystemInfo
|
26 |
* @copyright Manuela v.d.Decken <manuela@isteam.de>
|
27 |
* @author Manuela v.d.Decken <manuela@isteam.de>
|
28 |
* @license GNU General Public License 3.0
|
29 |
* @version 0.0.1
|
30 |
* @revision $Revision: 2 $
|
31 |
* @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
|
32 |
* @since File available since 18.07.2016
|
33 |
* @deprecated no / since 0000/00/00
|
34 |
* @description xxx
|
35 |
*/
|
36 |
class SysInfo |
37 |
{ |
38 |
const DIR_INCLUDE = false; |
39 |
const DIR_EXCLUDE = true; |
40 |
|
41 |
protected $bWbDbType = true; |
42 |
protected $oDb = null; |
43 |
protected $sTablePrefix = ''; |
44 |
protected $getOne = ''; |
45 |
|
46 |
public function __construct() |
47 |
{ |
48 |
if (class_exists('WbDdatabase', false)) { |
49 |
$this->oDb = WbDatabase::getInstance(); |
50 |
$this->sTablePrefix = $this->oDb->TablePrefix; |
51 |
$this->getOne = 'getOne'; |
52 |
} else {
|
53 |
$this->oDb = $GLOBALS['database']; |
54 |
$this->sTablePrefix = TABLE_PREFIX; |
55 |
$this->getOne = 'get_one'; |
56 |
} |
57 |
} |
58 |
|
59 |
public function getInterface() |
60 |
{ |
61 |
return PHP_SAPI; |
62 |
} |
63 |
|
64 |
public function isCgi() |
65 |
{ |
66 |
return (stripos(PHP_SAPI, 'cgi') !== false); |
67 |
} |
68 |
|
69 |
public function getWbVersion($bShowRev = false) |
70 |
{ |
71 |
return VERSION |
72 |
. (defined('WB_SP') ? ' '.WB_SP :'') |
73 |
. ($bShowRev ? '-r'.REVISION : ''); |
74 |
} |
75 |
|
76 |
public function getPhpVersion() |
77 |
{ |
78 |
return $this->stripNumber(PHP_VERSION); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* SysInfo::getOsVersion()
|
83 |
*
|
84 |
* @param bool $bFull
|
85 |
* 'a': This is the default. Contains all modes in the sequence "s n r v m".
|
86 |
* 's': Operating system name. eg. FreeBSD.
|
87 |
* 'n': Host name. eg. localhost.example.com.
|
88 |
* 'r': Release name. eg. 5.1.2-RELEASE.
|
89 |
* 'v': Version information. Varies a lot between operating systems.
|
90 |
* 'm': Machine type. eg. i386.
|
91 |
* @return string
|
92 |
*/
|
93 |
public function getOsVersion($bFull = false) |
94 |
{ |
95 |
$sRetval = php_uname(); |
96 |
$x = array(); |
97 |
if (!$bFull) { |
98 |
$xs = php_uname('s'); |
99 |
$xn = php_uname('n'); |
100 |
$xr = php_uname('r'); |
101 |
$xv = php_uname('v'); |
102 |
$xm = php_uname('m'); |
103 |
if (stristr($xv, 'ubuntu')!==false) { |
104 |
$xs = preg_replace('/^[^\~]*\~([^\s]+).*$/', '$1', $xv); |
105 |
} |
106 |
$sRetval = $xs; |
107 |
} |
108 |
return $sRetval; |
109 |
} |
110 |
|
111 |
public function getSqlServer() |
112 |
{ |
113 |
// 5.5.5-10.1.14-MariaDB
|
114 |
$sRetval = 'unknown'; |
115 |
$sql = 'SELECT VERSION( )'; |
116 |
if (($sValue = $this->oDb->{$this->getOne}($sql))) { |
117 |
$sRetval = $sValue; |
118 |
} |
119 |
$sql = 'SELECT LOWER(@@global.sql_mode) AS strictinfo'; |
120 |
if (($sValue = $this->oDb->{$this->getOne}($sql))) { |
121 |
$sRetval .= (stristr($sValue, 'strict') !== false) ? ' [STRICT]' : ''; |
122 |
} |
123 |
return $sRetval; |
124 |
} |
125 |
|
126 |
public function checkFolders(array $aFoldersList = null, $bMode = self::DIR_INCLUDE) |
127 |
{ |
128 |
// get install folder of application
|
129 |
$sInstallFolder = str_replace('\\', '/', dirname(__DIR__)).'/'; |
130 |
// Callback sanitize path
|
131 |
$cleanPath = function(&$sValue) { $sValue = rtrim(str_replace('\\', '/', $sValue), '/').'/'; }; |
132 |
// sanitize list of given folders
|
133 |
if (!$aFoldersList) { $aFoldersList = array(); } |
134 |
// sanitize folders in list
|
135 |
array_walk($aFoldersList, $cleanPath); |
136 |
// save old working dir
|
137 |
$sOldWorkDir = getcwd(); |
138 |
// change working dir
|
139 |
chdir($sInstallFolder); |
140 |
$aFoundFolders = glob('*', GLOB_MARK|GLOB_ONLYDIR); |
141 |
// sanitize folders in list
|
142 |
array_walk($aFoundFolders, $cleanPath); |
143 |
// restore old working dir
|
144 |
chdir($sOldWorkDir); |
145 |
if ($bMode != self::DIR_INCLUDE) { |
146 |
// leave only from $aFoldersList to test
|
147 |
$aFoldersToTest = array_diff($aFoundFolders, $aFoldersList); |
148 |
} else {
|
149 |
// remove all folders in $aFoldersList for test
|
150 |
$aFoldersToTest = array_intersect($aFoundFolders, $aFoldersList); |
151 |
} |
152 |
// exchange key<=>value
|
153 |
$aFoldersToTest = array_flip($aFoldersToTest); |
154 |
// set all values to false
|
155 |
array_walk($aFoldersToTest, function(&$value) { $value = false; }); |
156 |
// set value to true if folder is writeable
|
157 |
array_walk(
|
158 |
$aFoldersToTest,
|
159 |
function(&$value, $key) use ($sInstallFolder) { $value = is_writable($sInstallFolder.$key); } |
160 |
); |
161 |
return $aFoldersToTest; |
162 |
} |
163 |
|
164 |
/* ************************************************************************** */
|
165 |
/* */
|
166 |
/* ************************************************************************** */
|
167 |
protected function stripNumber($sValue) |
168 |
{ |
169 |
return preg_replace('/^([0-9.]+).*$/', '$1', $sValue); |
170 |
} |
171 |
} |
172 |
|