From 887f50e2461dddebacf7088950af326bc44716db Mon Sep 17 00:00:00 2001 From: Prabuddha Chakraborty Date: Thu, 19 Nov 2015 13:18:43 +0530 Subject: [PATCH] get_OS() function added --- php/utils.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/php/utils.php b/php/utils.php index f4051d67..8a2957ff 100644 --- a/php/utils.php +++ b/php/utils.php @@ -573,3 +573,32 @@ function get_named_sem_ver( $new_version, $original_version ) { function get_flag_value( $args, $flag, $default = null ) { return isset( $args[ $flag ] ) ? $args[ $flag ] : $default; } + +/** + * Return OS Information + * @return array + */ +function get_OS(){ + + if (strtolower(substr(PHP_OS, 0, 5)) === 'linux') + { + $vars = array(); + $files = glob('/etc/*-release'); + foreach ($files as $file) + { + $lines = array_filter(array_map(function($line) { + // split value from key + $parts = explode('=', $line); + // makes sure that "useless" lines are ignored (together with array_filter) + if (count($parts) !== 2) return false; + // remove quotes, if the value is quoted + $parts[1] = str_replace(array('"', "'"), '', $parts[1]); + return $parts; + }, file($file))); + foreach ($lines as $line) + $vars[$line[0]] = $line[1]; + } + } + return $vars ; +} +