@@ -64,7 +64,8 @@ public function __construct(){
6464 * @return string
6565 */
6666 public function hostname (){
67- $ dist = $ this ->get_os_type ();
67+ $ dist_temp = $ this ->get_os_type ();
68+ $ dist = isset ($ dist_temp ['type ' ]) ? $ dist_temp ['type ' ] : 'unknown ' ;
6869
6970 ob_start ();
7071 passthru ('hostname ' );
@@ -1228,7 +1229,8 @@ function rc_edit($service, $rl, $action){
12281229 global $ app ;
12291230 $ dist_init_scripts = $ app ->system ->server_conf ['dist_init_scripts ' ];
12301231 $ dist_runlevel = $ app ->system ->server_conf ['dist_runlevel ' ];
1231- $ dist = $ this ->get_os_type ();
1232+ $ dist_temp = $ this ->get_os_type ();
1233+ $ dist = isset ($ dist_temp ['type ' ]) ? $ dist_temp ['type ' ] : 'unknown ' ;
12321234 if (trim ($ dist_runlevel ) == '' ){ // falls es keine runlevel gibt (FreeBSD)
12331235 if ($ action == 'on ' ){
12341236 @symlink ($ dist_init_scripts .'/ ' .$ service , $ dist_init_scripts .'/ ' .$ service .'.sh ' );
@@ -1382,7 +1384,8 @@ function cat($file){
13821384 function daemon_init($daemon, $action){
13831385 //* $action = start|stop|restart|reload
13841386 global $app;
1385- $dist = $this->get_os_type();
1387+ $dist_temp = $this->get_os_type();
1388+ $dist = isset($dist_temp['type']) ? $dist_temp['type'] : 'unknown';
13861389 $dist_init_scripts = $this->server_conf['dist_init_scripts'];
13871390 if(!strstr($dist, 'freebsd')){
13881391 $app->log->caselog("$dist_init_scripts/$daemon $action &> /dev/null", $this->FILE, __LINE__);
@@ -1478,7 +1481,8 @@ function broadcast($ip, $netmask){
14781481 *
14791482 */
14801483 function network_info (){
1481- $ dist = $ this ->get_os_type ();
1484+ $ dist_temp = $ this ->get_os_type ();
1485+ $ dist = isset ($ dist_temp ['type ' ]) ? $ dist_temp ['type ' ] : 'unknown ' ;
14821486 ob_start ();
14831487 passthru ('ifconfig ' );
14841488 $ output = ob_get_contents ();
@@ -2370,53 +2374,89 @@ public function get_os_type() {
23702374 $ version = "unknown " ;
23712375 $ full_version = "unknown " ;
23722376
2373- if (file_exists ('/etc/redhat-release ' ) && (filesize ('/etc/redhat-release ' ) > 0 )) {
2377+ if (file_exists ('/etc/redhat-release ' ) && (filesize ('/etc/redhat-release ' ) > 0 )) {
23742378 $ dist = "redhat " ;
2375- if (file_exists ('/etc/os-release ' )) {
2379+ if (file_exists ('/etc/os-release ' )) {
23762380 $ os_release = file_get_contents ('/etc/os-release ' );
2377- if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2381+ if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
23782382 $ version = $ matches [1 ];
23792383 }
2384+ if (preg_match ('/PRETTY_NAME="([^"]+)"/ ' , $ os_release , $ matches )) {
2385+ $ full_version = $ matches [1 ];
2386+ }
23802387 }
2381- $ full_version = trim (file_get_contents ('/etc/redhat-release ' ));
2382- } elseif (file_exists ('/etc/debian_version ' ) && (filesize ('/etc/debian_version ' ) > 0 )) {
2388+ } elseif (file_exists ('/etc/debian_version ' ) && (filesize ('/etc/debian_version ' ) > 0 )) {
23832389 $ dist = "debian " ;
2384- if (file_exists ('/etc/os-release ' )) {
2390+ if (file_exists ('/etc/os-release ' )) {
23852391 $ os_release = file_get_contents ('/etc/os-release ' );
2386- if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2392+ /* if (preg_match('/VERSION_ID="([^"]+)"/', $os_release, $matches)) {
23872393 $version = $matches[1];
2394+ }*/
2395+ // This returns (at least for Debian 12) a more accurate version number
2396+ $ version = trim (file_get_contents ('/etc/debian_version ' ));
2397+
2398+ if (preg_match ('/PRETTY_NAME="([^"]+)"/ ' , $ os_release , $ matches )) {
2399+ $ full_version = $ matches [1 ];
23882400 }
23892401 }
2390- $ full_version = trim (file_get_contents ('/etc/debian_version ' ));
2391- } elseif (strstr (trim (file_get_contents ('/etc/issue ' )), 'Ubuntu ' ) || (is_file ('/etc/os-release ' ) && stristr (file_get_contents ('/etc/os-release ' ), 'Ubuntu ' ))) {
2402+ } elseif (strstr (trim (file_get_contents ('/etc/issue ' )), 'Ubuntu ' ) || (is_file ('/etc/os-release ' ) && stristr (file_get_contents ('/etc/os-release ' ), 'Ubuntu ' ))) {
23922403 $ dist = "ubuntu " ;
2393- if (file_exists ('/etc/os-release ' )) {
2404+ if (file_exists ('/etc/os-release ' )) {
23942405 $ os_release = file_get_contents ('/etc/os-release ' );
2395- if (preg_match ('/VERSION="([^"]+)"/ ' , $ os_release , $ matches )) {
2406+ if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2407+ $ version = $ matches [1 ];
2408+ }
2409+ if (preg_match ('/PRETTY_NAME="([^"]+)"/ ' , $ os_release , $ matches )) {
23962410 $ full_version = $ matches [1 ];
23972411 }
2398- if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2399- $ version = $ matches [1 ];
2412+ }
2413+
2414+ // There is no more SuSE-release file in newer (open)SuSE releases present to determine if it's something SuSE-like,
2415+ // so we have to use the os-release file to find out the dist type and version
2416+ } elseif (file_exists ('/etc/os-release ' ) && (filesize ('/etc/os-release ' ) > 0 )) {
2417+ if (file_exists ('/etc/os-release ' )) {
2418+ $ os_release = file_get_contents ('/etc/os-release ' );
2419+ if (preg_match ('/ID_LIKE="([^"]+)"$/ ' , $ os_release , $ matches )) {
2420+ $ dist_like = $ matches [1 ];
2421+ if (preg_match ('/\b(?:suse|opensuse)\b/ ' , $ dist_like , $ matches )) {
2422+ $ dist = "suse " ;
2423+ if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2424+ $ version = $ matches [1 ];
2425+ }
2426+ if (preg_match ('/PRETTY_NAME="([^"]+)"/ ' , $ os_release , $ matches )) {
2427+ $ full_version = $ matches [1 ];
2428+ }
2429+ }
24002430 }
24012431 }
2402- } elseif (file_exists ('/etc/SuSE -release ' ) && (filesize ('/etc/SuSE -release ' ) > 0 )) {
2403- $ dist = "suse " ;
2404- if (file_exists ('/etc/os-release ' )) {
2432+ } elseif (file_exists ('/etc/gentoo -release ' ) && (filesize ('/etc/gentoo -release ' ) > 0 )) {
2433+ $ dist = "gentoo " ;
2434+ if (file_exists ('/etc/os-release ' )) {
24052435 $ os_release = file_get_contents ('/etc/os-release ' );
2406- if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2436+ if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
24072437 $ version = $ matches [1 ];
24082438 }
2439+ // Gentoo's PRETTY_NAME doesn't include the version number, let's append it to the full_version string
2440+ if (preg_match ('/PRETTY_NAME="([^"]+)"/ ' , $ os_release , $ matches )) {
2441+ $ full_version = $ matches [1 ] . ' ' . $ version ;
2442+ }
24092443 }
2410- $ full_version = trim (file_get_contents ('/etc/SuSE-release ' ));
2411- } elseif (file_exists ('/etc/gentoo-release ' ) && (filesize ('/etc/gentoo-release ' ) > 0 )) {
2412- $ dist = "gentoo " ;
2413- if (file_exists ('/etc/os-release ' )) {
2444+ } elseif (file_exists ('/bin/freebsd-version ' ) && (filesize ('/bin/freebsd-version ' ) > 0 )) {
2445+ $ dist = "freebsd " ;
2446+ if (file_exists ('/etc/os-release ' )) {
24142447 $ os_release = file_get_contents ('/etc/os-release ' );
2415- if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
2448+ if (preg_match ('/VERSION_ID="([^"]+)"/ ' , $ os_release , $ matches )) {
24162449 $ version = $ matches [1 ];
24172450 }
2451+ if (preg_match ('/PRETTY_NAME="([^"]+)"/ ' , $ os_release , $ matches )) {
2452+ $ full_version = $ matches [1 ];
2453+ }
2454+ /*
2455+ if (preg_match('/^ID=([^"]+)$/', $os_release, $matches)) {
2456+ $dist = $matches[1];
2457+ }
2458+ */
24182459 }
2419- $ full_version = trim (file_get_contents ('/etc/gentoo-release ' ));
24202460 }
24212461
24222462 return [
0 commit comments