|
26 | 26 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
27 | 27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
28 | 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | | -*/ |
30 | | - |
31 | | -/* |
32 | | - This function returns a string that describes the installed |
33 | | - Linux distribution. e.g. debian40 for Debian GNU/Linux 4.0 |
34 | | -*/ |
35 | | - |
36 | | - |
37 | | - |
38 | | -/* |
39 | | -Comments to completion forever ;-) |
40 | | -commandline arguments |
41 | | -$argv[1] |
42 | | -
|
43 | | -
|
44 | | -<? |
45 | | -echo "Total argument passed are : $argc \n"; |
46 | | -for( $i = 0 ; $i <= $argc -1 ;$i++) |
47 | | -{ |
48 | | -echo "Argument $i : $argv[$i] \n"; |
49 | | -} |
50 | | -?> |
51 | | -
|
52 | 29 | */ |
53 | 30 | error_reporting(E_ALL|E_STRICT); |
54 | 31 |
|
|
59 | 36 | //** IMPORTANT! |
60 | 37 | // This is the same code as in server/lib/classes/monitor_tools.inc.php |
61 | 38 | // So if you change it here, you also have to change it in there! |
| 39 | +// |
| 40 | +// This function returns a string that describes the installed |
| 41 | +// Linux distribution. e.g. debian40 for Debian GNU/Linux 4.0 |
| 42 | + |
62 | 43 | function get_distname() { |
63 | 44 |
|
64 | 45 | $distname = ''; |
65 | 46 | $distver = ''; |
66 | 47 | $distid = ''; |
67 | 48 | $distbaseid = ''; |
68 | 49 |
|
69 | | - //** Debian or Ubuntu |
70 | | - if (is_file('/etc/os-release') && stristr(file_get_contents('/etc/os-release'), 'Ubuntu')) { |
71 | | - $os_release = file_get_contents('/etc/os-release'); |
72 | | - if (strstr(trim($os_release), 'LTS')) { |
73 | | - $lts = " LTS"; |
74 | | - } else { |
75 | | - $lts = ""; |
76 | | - } |
77 | | - |
78 | | - preg_match("/.*VERSION=\"(.*)\".*/ui", $os_release, $ver); |
79 | | - $ver = str_replace("LTS", "", $ver[1]); |
80 | | - $ver = explode(" ", $ver, 2); |
81 | | - $relname = end($ver); |
82 | | - $relname = "(" . trim(trim($relname), "()") . ")"; |
83 | | - $distname = 'Ubuntu'; |
84 | | - $ver = reset($ver); |
85 | | - if($ver == "16.04") { |
86 | | - $distid = 'ubuntu1604'; |
87 | | - } else { |
88 | | - $distid = 'debian40'; |
89 | | - } |
90 | | - $distbaseid = 'debian'; |
91 | | - $distver = $ver . $lts . " " . $relname; |
92 | | - swriteln("Operating System: " . $distver . "\n"); |
93 | | - } //** Debian / Ubuntu |
94 | | - elseif(file_exists('/etc/debian_version')) { |
95 | | - if (strstr(trim(file_get_contents('/etc/issue')), 'Ubuntu')) { |
96 | | - if (strstr(trim(file_get_contents('/etc/issue')), 'LTS')) { |
97 | | - $lts=" LTS"; |
| 50 | + //** Debian or Ubuntu |
| 51 | + if(file_exists('/etc/debian_version')) { |
| 52 | + |
| 53 | + // Check if this is Ubuntu and not Debian |
| 54 | + if (strstr(trim(file_get_contents('/etc/issue')), 'Ubuntu') || (is_file('/etc/os-release') && stristr(file_get_contents('/etc/os-release'), 'Ubuntu'))) { |
| 55 | + |
| 56 | + $issue = file_get_contents('/etc/issue'); |
| 57 | + |
| 58 | + // Use content of /etc/issue file |
| 59 | + if(strstr($issue,'Ubuntu')) { |
| 60 | + if (strstr(trim($issue), 'LTS')) { |
| 61 | + $lts=" LTS"; |
| 62 | + } else { |
| 63 | + $lts=""; |
| 64 | + } |
| 65 | + |
| 66 | + $distname = 'Ubuntu'; |
| 67 | + $distid = 'debian40'; |
| 68 | + $distbaseid = 'debian'; |
| 69 | + $ver = explode(' ', $issue); |
| 70 | + $ver = array_filter($ver); |
| 71 | + $ver = next($ver); |
| 72 | + $mainver = explode('.', $ver); |
| 73 | + $mainver = array_filter($mainver); |
| 74 | + $mainver = current($mainver).'.'.next($mainver); |
| 75 | + // Use content of /etc/os-release file |
98 | 76 | } else { |
99 | | - $lts=""; |
| 77 | + $os_release = file_get_contents('/etc/os-release'); |
| 78 | + if (strstr(trim($os_release), 'LTS')) { |
| 79 | + $lts = " LTS"; |
| 80 | + } else { |
| 81 | + $lts = ""; |
| 82 | + } |
| 83 | + |
| 84 | + $distname = 'Ubuntu'; |
| 85 | + $distid = 'debian40'; |
| 86 | + $distbaseid = 'debian'; |
| 87 | + |
| 88 | + preg_match("/.*VERSION=\"(.*)\".*/ui", $os_release, $ver); |
| 89 | + $ver = str_replace("LTS", "", $ver[1]); |
| 90 | + $ver = explode(" ", $ver, 2); |
| 91 | + $ver = reset($ver); |
| 92 | + $mainver = $ver; |
100 | 93 | } |
101 | | - |
102 | | - $issue=file_get_contents('/etc/issue'); |
103 | | - $distname = 'Ubuntu'; |
104 | | - $distid = 'debian40'; |
105 | | - $distbaseid = 'debian'; |
106 | | - $ver = explode(' ', $issue); |
107 | | - $ver = array_filter($ver); |
108 | | - $ver = next($ver); |
109 | | - $mainver = explode('.', $ver); |
110 | | - $mainver = array_filter($mainver); |
111 | | - $mainver = current($mainver).'.'.next($mainver); |
112 | 94 | switch ($mainver){ |
113 | 95 | case "16.04": |
114 | 96 | $relname = "(Xenial Xerus)"; |
115 | | - $distid = 'ubuntu1604'; |
| 97 | + $distconfid = 'ubuntu1604'; |
116 | 98 | break; |
117 | 99 | case "15.10": |
118 | 100 | $relname = "(Wily Werewolf)"; |
@@ -187,7 +169,7 @@ function get_distname() { |
187 | 169 | $relname = "UNKNOWN"; |
188 | 170 | } |
189 | 171 | $distver = $ver.$lts." ".$relname; |
190 | | - swriteln("Operating System: ".$distver."\n"); |
| 172 | + swriteln("Operating System: ".$distname.' '.$distver."\n"); |
191 | 173 | } elseif(trim(file_get_contents('/etc/debian_version')) == '4.0') { |
192 | 174 | $distname = 'Debian'; |
193 | 175 | $distver = '4.0'; |
@@ -307,7 +289,8 @@ function get_distname() { |
307 | 289 | } elseif(stristr($content, 'CentOS Linux release 7.2')) { |
308 | 290 | $distname = 'CentOS'; |
309 | 291 | $distver = 'Unknown'; |
310 | | - $distid = 'centos72'; |
| 292 | + $distid = 'centos70'; |
| 293 | + $distconfid = 'centos72'; |
311 | 294 | $distbaseid = 'fedora'; |
312 | 295 | swriteln("Operating System: CentOS 7.2\n"); |
313 | 296 | } elseif(stristr($content, 'CentOS Linux release 7')) { |
@@ -340,8 +323,11 @@ function get_distname() { |
340 | 323 | } else { |
341 | 324 | die('Unrecognized GNU/Linux distribution'); |
342 | 325 | } |
| 326 | + |
| 327 | + // Set $distconfid to distid, if no different id for the config is defined |
| 328 | + if(!isset($distconfid)) $distconfid = $distid; |
343 | 329 |
|
344 | | - return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'baseid' => $distbaseid); |
| 330 | + return array('name' => $distname, 'version' => $distver, 'id' => $distid, 'confid' => $distconfid, 'baseid' => $distbaseid); |
345 | 331 | } |
346 | 332 |
|
347 | 333 | function sread() { |
|
0 commit comments