* Otherwise you can read it here: http://www.gnu.org/licenses/gpl-2.0.txt
*
*/
ini_set('include_path', '/usr/share/ossim/include/');
error_reporting(0);
ini_set("display_errors", "0");
ini_set('memory_limit', '2048M');
set_time_limit(0);
require_once 'av_handlers.php';
function write_log($exp_type, $log_message = '')
{
    echo '[' . gmdate('D M d h:i:s Y') . '] [' . $exp_type . '] ' . $log_message . "\n";
}
//
$db = new Ossim_db();
if (!@$db->test_connect()) {
    echo "[ERROR] Updating Software CPE: Unable to connect to DB";
    exit - 1;
}
$conn = $db->connect();
$conn->Execute('DROP TABLE IF EXISTS `alienvault`.`software_cpe_aux`');
$query = "CREATE TABLE `alienvault`.`software_cpe_aux` (\n\t\t\t`cpe` VARCHAR( 255 ) NOT NULL,\n\t\t\t`name` VARCHAR( 255 ) NOT NULL,\n\t\t\t`version` VARCHAR( 255 ) NOT NULL,\n\t\t\t`line` VARCHAR( 255 ) NOT NULL,\n\t\t\t`vendor` VARCHAR( 255 ) NOT NULL,\n\t\t    `plugin` VARCHAR(255) NOT NULL,\n\t\t\tPRIMARY KEY (  `cpe`  ),\n\t\t\tINDEX `line` (`line` ASC),\n\t\t\tINDEX `search` (`vendor` ASC, `name` ASC, `version` ASC)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$conn->Execute($query);
$file = "/usr/share/ossim-cd-tools/cpe/official-cpe-dictionary.xml";
if (file_exists($file)) {
    write_log('INFO', "Reading XML data from {$file}");
    $cpe_list = @simplexml_load_file($file);
    if (!$cpe_list) {
        write_log('ERROR', 'Unable to open ' . $file . ' or invalid XML format');
        $db->close();
        die;