The following is a basic example of an SDL script to discover the Apache HTTPD web server.
Example 22.10. Basic Example Script
// // Apache HTTPD Server // $PRODUCT_NAME = "apachehttpd"; // Required $VENDOR_NAME = "Apache Foundation"; // Required Debug("Looking for Apache httpd web server"); $HttpdPaths = "/usr/apache/bin/httpd:/sbin/httpd:/usr/sbin/httpd:/usr/local/sbin/httpd:/usr/local/bin/httpd:/bin/httpd:/usr/bin/httpd"; $Paths = StrSplit(":", $HttpdPaths); foreach $path ($Paths) { Debug("Looking for $path"); if (PathExists($path, "FILE")) { if (HttpdProbe($path)) { break; } } } // // Probe using $HttpdPath as path to httpd // HttpdProbe(String_t $HttpdPath) { Debug("Probe using httpd ${HttpdPath}"); $CmdHandle = CmdOpen($HttpdPath, "-v"); while ($Line = CmdReadLine($CmdHandle)) { Debug("READ: ${Line}"); if (StrMatchN($Line, "Server version:", 15)) { Debug("Found version line."); if (StrRegExMatch($Line, "Apache")) { Debug("Matched line ${Line}"); // Line looks like: Server version: Apache/2.2.3 $Version = StrEdit(".*/", $Line, "", NULL); } } else { Debug("Check for built in ${Line}"); if (StrMatchN($Line, "Server built:", 13)) { Debug("Found built info."); $BuildDate = StrEdit("Server built:", $Line, "", NULL); $BuildDate = StrEdit("^.[ ]+", $BuildDate, "", NULL); } } } CmdClose($CmdHandle); if (!$Version) { Debug("No Version was found - skipping $HttpdPath"); Return(0); } $SoftInfo = SoftInfoCreate($PRODUCT_NAME, $Version); SoftInfoSet($SoftInfo, "VendorName", $VENDOR_NAME); SoftInfoSet($SoftInfo, "Desc", "HTTP Web Server"); SoftInfoSet($SoftInfo, "VendorName", $VENDOR_NAME); if ($BuildDate) { SoftInfoSet($SoftInfo, "BuildDate", $BuildDate); } if ($dir = PathDirName($HttpdPath)) { SoftInfoSet($SoftInfo, "BaseDir", $dir); } if ($size = FileSize($HttpdPath)) { SoftInfoSet($SoftInfo, "DiskUsage", $size); } SoftInfoAdd($SoftInfo); // Add to tree Return(1); }