/** * Process condition and do action * @param Handler $handler Handler ORM * @param Audit $audit Audit ORM * @return boolean Return TRUE if successful, FALSE otherwise */ public function process(Audit $audit) { $ret = true; $update = new UpdateFile(); $updateIterator = $update->getIteratorByQueue(); foreach ($updateIterator as $updateFile) { $updateFile->queue = 0; $alterTable = new AlterTable(); $ret = $alterTable->generateSqlChanges($updateFile->getUploadFilename()); if ($ret === true) { $alterTable->executeSqlChanges(); //$updateFile->active = 0; $updateFile->status = 'Completed'; $updateFile->persist(); } else { $updateFile->status = 'Error: ' . $ret; $updateFile->persist(); } } return $ret; }
/** * Verify the Ed25519 signature of the update file against the * supplier's public key. * * Dear future security auditors: This is important. * * @param UpdateInfo $info * @param UpdateFile $file * @return bool */ public function verifyUpdateSignature(UpdateInfo $info, UpdateFile $file) : bool { $debugArgs = ['path' => $file->getPath(), 'supplier' => $info->getSupplierName(), 'name' => $info->getPackageName()]; $this->log('Checking update signature...', LogLevel::DEBUG, $debugArgs); $ret = false; foreach ($this->supplier->getSigningKeys() as $key) { if ($key['type'] !== 'signing') { continue; } $ret = $ret || File::verify($file->getPath(), $key['key'], $info->getSignature(true)); } $this->log('Signature result: ' . ($ret ? 'true' : 'false'), LogLevel::DEBUG, $debugArgs); return $ret; }
public function processDeleteAction() { $param = $this->_getParam('id'); $ids = explode(',', $param); $ret = false; foreach ($ids as $updateFileId) { if (!$updateFileId > 0) { continue; } $ret = true; $updateFile = new UpdateFile(); $updateFile->updateFileId = (int) $updateFileId; $updateFile->populate(); if (!strlen($updateFile->version) > 0) { continue; } //$updateFile->active = 0; $updateFile->setPersistMode(WebVista_Model_ORM::DELETE); $updateFile->persist(); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($ret); }
public function runAction() { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $request = $this->getRequest(); $id = $request->getParam('id'); $cache = MyDiff_Cache::init(); $comparison = $cache->load('comparison' . $id); $options = $cache->load('options' . $id); if (!$id || !$comparison || !$options) { throw new MyDiff_Exception("Missing options, please go back and try again."); } // Remove tables not submitted foreach ($comparison->databases as $i => $database) { $database->useTables(array_keys($options['database'][$i]['table'])); $database->connect(); } if (!is_numeric($options['type']['srcdb'])) { return false; // can't happen } // Select source db $dbcnt = count($comparison->databases); $comparison->sourcedb = $comparison->databases[$options['type']['srcdb']]; for ($i = 0; $i < $dbcnt; $i++) { // for multiple target db next implementation if ($i != $options['type']['srcdb']) { $comparison->targetdb = $comparison->databases[$i]; } } $upFile = new UpdateFile($comparison, $options); // Do compare types if (isset($options['type']['schema'])) { $comparison->schema($comparison->targetdb, $comparison->sourcedb); $upFile->writeSchema(); } if (isset($options['type']['data'])) { $showChanges = isset($options['type']['showchanges']); $comparison->data(isset($options['type']['replace']), $options['type']['algorithm'], $upFile, $showChanges, $comparison->targetdb, $comparison->sourcedb); if ($showChanges) { // Build a list of rows that have changed $data = array(); $tables = array($comparison->targetdb->getTables(), $comparison->sourcedb->getTables()); foreach ($tables[0] as $tableName => $table) { if (!$table->hasDiffs('MyDiff_Diff_Table_New')) { $rows = array($tables[0][$tableName]->getRows(), isset($tables[1][$tableName]) ? $tables[1][$tableName]->getRows() : array()); // remove values that don't exist in original if (!isset($options['type']['allfields']) && !empty($rows[0]) && !empty($rows[1])) { foreach ($rows[1] as &$row) { $row->data = array_intersect_key($row->data, reset($rows[0])->data); } } $rows = array_merge($rows[0], $rows[1]); $data[] = array('table' => $table, 'rows' => $rows); } } // fill rows for new tables foreach ($tables[1] as $tableName => $table) { if ($table->hasDiffs('MyDiff_Diff_Table_New')) { $rows = $tables[1][$tableName]->getRows(); $data[] = array('table' => $table, 'rows' => $rows); } } $this->view->data = $data; } } $upFile->closeFile(); unset($upFile); $this->view->comparison = $comparison; $this->view->options = $options; $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = $endtime - $starttime; $this->view->id = $id; $this->view->totaltime = $totaltime; $this->view->totalmem = memory_get_peak_usage(true); }
public function processRegistrationAction() { $updateFileId = (int) $this->_getParam('updateFileId'); $data = array(); $users = array(); $xml = new SimpleXMLElement('<clearhealth/>'); $xml->addChild('apiKey', Zend_Registry::get('config')->healthcloud->apiKey); $xml->addChild('authorizingUserId', (int) Zend_Auth::getInstance()->getIdentity()->personId); $xml->addChild('authorizingUser', Zend_Auth::getInstance()->getIdentity()->username); foreach (User::listActiveUsers() as $user) { $xmlUser = $xml->addChild('user'); $xmlUser->addChild('userId', (int) $user->personId); $xmlUser->addChild('username', (string) $user->username); } $ch = curl_init(); $url = Zend_Registry::get('config')->healthcloud->updateServerUrl . '/activate-users'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML()); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); try { $response = curl_exec($ch); if (curl_errno($ch)) { throw new Exception(curl_error($ch)); } curl_close($ch); trigger_error($response); $responseXml = new SimpleXMLElement($response); if ($responseXml->error) { throw new Exception((string) $responseXml->error->errorMsg, (string) $responseXml->error->errorCode); } $data['data'] = (string) $responseXml->response; $updateFile = new UpdateFile(); $updateFile->updateFileId = $updateFileId; $updateFile->populate(); $updateFile->install(); } catch (Exception $e) { $error = $e->getMessage(); trigger_error($error); $data['error'] = $error; } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($data); }
public function viewDetailsAction() { $updateFileId = (int) $this->_getParam('updateFileId'); $updateFile = new UpdateFile(); $updateFile->updateFileId = $updateFileId; $updateFile->populate(); $alterTable = new AlterTable(); $this->view->name = $updateFile->channel . ': ' . $updateFile->name; $this->view->data = $alterTable->generateChanges($updateFile->data); $this->render('view-details'); }