public static function dbFactory() { $db_type = owa_coreAPI::getSetting('base', 'db_type'); $ret = owa_coreAPI::setupStorageEngine($db_type); if (!$ret) { owa_coreAPI::error(sprintf('Cannot locate proper db class at %s. Exiting.', $connection_class_path)); return; } else { $connection_class = 'owa_db_' . $db_type; $db = new $connection_class(owa_coreAPI::getSetting('base', 'db_host'), owa_coreAPI::getSetting('base', 'db_name'), owa_coreAPI::getSetting('base', 'db_user'), owa_coreAPI::getSetting('base', 'db_password'), owa_coreAPI::getSetting('base', 'db_force_new_connections'), owa_coreAPI::getSetting('base', 'db_make_persistant_connections')); return $db; } }
/** * Sends the email request notification. **/ function sendNotificationRequest($event, $advertiser, $targetUrl) { $appSettings = owa_coreAPI::supportClassFactory('ecoinsight', 'appSettings'); $url = $appSettings->getNotificationUrl(); if ($url == '') { return false; } if (substr_compare($url, '/', -strlen('/'), strlen('/')) == 0) { $url = substr($url, 0, strlen($url) - 1); } owa_coreAPI::debug('Preparing to notify endpoint - ' . $url); // Open the connection $httpSession = curl_init(); $data = $this->serializeRequest($event->get('guid'), $advertiser, $targetUrl, $event->get('user_name'), $event->get('user_email')); // Configure curl curl_setopt($httpSession, CURLOPT_URL, $url); curl_setopt($httpSession, CURLOPT_POST, 1); curl_setopt($httpSession, CURLOPT_RETURNTRANSFER, true); curl_setopt($httpSession, CURLOPT_FOLLOWLOCATION, true); curl_setopt($httpSession, CURLOPT_POSTFIELDS, $data); curl_setopt($httpSession, CURLOPT_FAILONERROR, true); curl_setopt($httpSession, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Content-length: " . strlen($data))); curl_setopt($httpSession, CURLOPT_SSL_VERIFYPEER, false); if (defined('ECO_HTTP_PROXY')) { curl_setopt($httpSession, CURLOPT_PROXY, ECO_HTTP_PROXY); } // Post the data $content = curl_exec($httpSession); $result = false; // If the response is 202 (Accepted), the notification has reached // the target server. If not, an error occured. // TODO: Log failures to a table for later retry or analysis. if (curl_getinfo($httpSession, CURLINFO_HTTP_CODE) != 202) { $msg = sprintf('Error occurred while sending notification: %s', curl_error($httpSession)); owa_coreAPI::error($msg); owa_coreAPI::error(curl_getinfo($httpSession)); } else { $result = true; } // Cleanup the connection. curl_close($httpSession); return $result; }
/** * Set the template file * @depricated * @param string $file */ function set_template($file = null) { if (!$file) { owa_coreAPI::error('No template file was specified.'); return false; } else { // check module's local modification template Directory if (file_exists($this->module_local_template_dir . $file)) { $this->file = $this->module_local_template_dir . $file; // check theme's template Directory } elseif (file_exists($this->theme_template_dir . $file)) { $this->file = $this->theme_template_dir . $file; // check module's template directory } elseif (file_exists($this->module_template_dir . $file)) { $this->file = $this->module_template_dir . $file; // throw error } else { $this->e->err(sprintf('%s was not found in any template directory.', $file)); return false; } return true; } }
function process_event_log($file) { // check to see if event log file exisits if (!file_exists($file)) { owa_coreAPI::debug("Event file does not exist at {$file}"); return false; } // check for access to db $db = owa_coreAPI::dbSingleton(); $db->connect(); if (!$db->isConnectionEstablished()) { owa_coreAPI::debug("Aborting processing of event log file. Could not connect to database."); return false; } //create lock file $this->create_lock_file(); // get event dispatcher $dispatch = owa_coreAPI::getEventDispatch(); // Create a new log file name $new_file_name = $this->queue_dir . time() . "." . getmypid(); $new_file = $new_file_name . ".processing"; // Rename current log file rename($file, $new_file) or die("Could not rename file"); owa_coreAPI::debug('renamed event file.'); // open file for reading $handle = @fopen($new_file, "r"); if ($handle) { while (!feof($handle)) { // Read row $buffer = fgets($handle, 14096); // big enough? // Parse the row $event = $this->parse_log_row($buffer); // Log event to the event queue if (!empty($event)) { //print_r($event); // debug owa_coreAPI::debug(sprintf('Processing: %s (%s)', '', $event->guid)); // send event object to event queue $ret = $dispatch->notify($event); // is the dispatch was not successful then add the event back into the queue. if ($ret != OWA_EHS_EVENT_HANDLED) { $dispatch->asyncNotify($event); } } else { owa_coreAPI::debug("No event found in log row. Must be end of file."); } } //Close file fclose($handle); // rename file to mark it as processed $processed_file_name = $new_file_name . ".processed"; rename($new_file, $processed_file_name) or die("Could not rename file"); owa_coreAPI::debug(sprintf('Processing Complete. Renaming File to %s', $processed_file_name)); //Delete processed file unlink($processed_file_name); owa_coreAPI::debug(sprintf('Deleting File %s', $processed_file_name)); //Delete Lock file unlink($this->lock_file); return true; } else { //could not open file for processing owa_coreAPI::error(sprintf('Could not open file %s. Terminating Run.', $new_file)); } }
/** * Writes the config file based on the default config file - but with the given database credentials * * @param array $config_values with the database setting keys */ public function createConfigFile($config_values) { if (file_exists(OWA_DIR . 'owa-config.php')) { owa_coreAPI::error("Your config file already exists. If you need to change your configuration, edit that file at: " . OWA_DIR . 'owa-config.php'); require_once OWA_DIR . 'owa-config.php'; return true; } if (!file_exists(OWA_DIR . 'owa-config-dist.php')) { $errorMsg = "We can't find the configuration file template. Are you sure you installed OWA's files correctly? Exiting."; owa_coreAPI::error($errorMsg); throw new Exception($errorMsg); } $configFileTemplate = file(OWA_DIR . 'owa-config-dist.php'); owa_coreAPI::debug('found sample config file.'); $handle = fopen(OWA_DIR . 'owa-config.php', 'w'); foreach ($configFileTemplate as $line_num => $line) { switch (substr($line, 0, 20)) { case "define('OWA_DB_TYPE'": fwrite($handle, str_replace("yourdbtypegoeshere", $config_values['db_type'], $line)); break; case "define('OWA_DB_NAME'": fwrite($handle, str_replace("yourdbnamegoeshere", $config_values['db_name'], $line)); break; case "define('OWA_DB_USER'": fwrite($handle, str_replace("yourdbusergoeshere", $config_values['db_user'], $line)); break; case "define('OWA_DB_PASSW": fwrite($handle, str_replace("yourdbpasswordgoeshere", $config_values['db_password'], $line)); break; case "define('OWA_DB_HOST'": fwrite($handle, str_replace("yourdbhostgoeshere", $config_values['db_host'], $line)); break; case "define('OWA_PUBLIC_U": fwrite($handle, str_replace("http://domain/path/to/owa/", $config_values['public_url'], $line)); break; case "define('OWA_NONCE_KE": fwrite($handle, str_replace("yournoncekeygoeshere", owa_coreAPI::secureRandomString(64), $line)); break; case "define('OWA_NONCE_SA": fwrite($handle, str_replace("yournoncesaltgoeshere", owa_coreAPI::secureRandomString(64), $line)); break; case "define('OWA_AUTH_KEY": fwrite($handle, str_replace("yourauthkeygoeshere", owa_coreAPI::secureRandomString(64), $line)); break; case "define('OWA_AUTH_SAL": fwrite($handle, str_replace("yourauthsaltgoeshere", owa_coreAPI::secureRandomString(64), $line)); break; default: fwrite($handle, $line); } } fclose($handle); chmod(OWA_DIR . 'owa-config.php', 0750); owa_coreAPI::debug('Config file created'); require_once OWA_DIR . 'owa-config.php'; return true; }