From 31c9379c46455d7cf1bb9977ab30f7196cba2d10 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 18 May 2010 18:03:02 -0400 Subject: Add back needed functions --- etc/inc/system.inc | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'etc/inc/system.inc') diff --git a/etc/inc/system.inc b/etc/inc/system.inc index da34e66..c8d200f 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -1345,6 +1345,8 @@ function system_check_reset_button() { if(!$g['platform'] == "nanobsd") return 0; + $specplatform = system_identify_specific_platform(); + if ($specplatform['name'] != "wrap" && $specplatform['name'] != "alix") return 0; @@ -1371,4 +1373,82 @@ EOD; return 0; } +/* attempt to identify the specific platform (for embedded systems) + Returns an array with two elements: + name => platform string (e.g. 'wrap', 'alix' etc.) + descr => human-readable description (e.g. "PC Engines WRAP") +*/ +function system_identify_specific_platform() { + global $g; + + if ($g['platform'] == 'generic-pc') + return array('name' => 'generic-pc', 'descr' => "Generic PC"); + + if ($g['platform'] == 'generic-pc-cdrom') + return array('name' => 'generic-pc-cdrom', 'descr' => "Generic PC (CD-ROM)"); + + /* the rest of the code only deals with 'embedded' platforms */ + if ($g['platform'] != 'embedded') + return array('name' => $g['platform'], 'descr' => $g['platform']); + + $dmesg = system_get_dmesg_boot(); + + if (strpos($dmesg, "PC Engines WRAP") !== false) + return array('name' => 'wrap', 'descr' => 'PC Engines WRAP'); + + if (strpos($dmesg, "PC Engines ALIX") !== false) + return array('name' => 'alix', 'descr' => 'PC Engines ALIX'); + + if (preg_match("/Soekris net45../", $dmesg, $matches)) + return array('name' => 'net45xx', 'descr' => $matches[0]); + + if (preg_match("/Soekris net48../", $dmesg, $matches)) + return array('name' => 'net48xx', 'descr' => $matches[0]); + + if (preg_match("/Soekris net55../", $dmesg, $matches)) + return array('name' => 'net55xx', 'descr' => $matches[0]); + + /* unknown embedded platform */ + return array('name' => 'embedded', 'descr' => 'embedded (unknown)'); +} + +function system_get_dmesg_boot() { + global $g; + + if (!file_exists("{$g['varlog_path']}/dmesg.boot")) + system_dmesg_save(); + + return file_get_contents("{$g['varlog_path']}/dmesg.boot"); +} + +function system_dmesg_save() { + global $g; + + if (file_exists("{$g['varlog_path']}/dmesg.boot")) + return 0; /* nothing to do */ + + exec("/sbin/dmesg", $dmesg); + + /* find last copyright line (output from previous boots may be present) */ + $lastcpline = 0; + + for ($i = 0; $i < count($dmesg); $i++) { + if (strstr($dmesg[$i], "Copyright (c) 1992-")) + $lastcpline = $i; + } + + $fd = fopen("{$g['varlog_path']}/dmesg.boot", "w"); + if (!$fd) { + printf("Error: cannot open dmesg.boot in system_dmesg_save().\n"); + return 1; + } + + for ($i = $lastcpline; $i < count($dmesg); $i++) + fwrite($fd, $dmesg[$i] . "\n"); + + fclose($fd); + + return 0; +} + ?> \ No newline at end of file -- cgit v1.1