public function __construct() { parent::sessionStart(); $filterArgs = array('tm_key' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'downloadToken' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'source' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'target' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH)); $__postInput = filter_var_array($_REQUEST, $filterArgs); //NOTE: This is for debug purpose only, //NOTE: Global $_POST Overriding from CLI Test scripts //$__postInput = filter_var_array( $_POST, $filterArgs ); $this->tm_key = $__postInput['tm_key']; $this->source = $__postInput['source']; $this->target = $__postInput['target']; $this->downloadToken = $__postInput['downloadToken']; parent::disableSessions(); $userIsLogged = isset($_SESSION['cid']) && !empty($_SESSION['cid']); if (!$userIsLogged) { $output = "<pre>\n"; $output .= " - REQUEST URI: " . print_r(@$_SERVER['REQUEST_URI'], true) . "\n"; $output .= " - REQUEST Message: " . print_r($_REQUEST, true) . "\n"; $output .= "\n\t"; $output .= "Aborting...\n"; $output .= "</pre>"; Log::$fileName = 'php_errors.txt'; Log::doLog($output); Utils::sendErrMailReport($output, "Download TMX Error: user Not Logged"); $this->unlockToken(); exit; } $this->uid = isset($_SESSION['uid']) && !empty($_SESSION['uid']) ? $_SESSION['uid'] : null; $this->userMail = isset($_SESSION['cid']) && !empty($_SESSION['cid']) ? $_SESSION['cid'] : null; $this->tmxHandler = new TMSService(); $this->tmxHandler->setTmKey($this->tm_key); }
public function doAction() { switch ($this->__postInput['exec']) { case 'stayAnonymous': unset($_SESSION['_anonym_pid']); unset($_SESSION['incomingUrl']); unset($_SESSION['_newProject']); break; case 'ping': $db = Database::obtain(); $db->query("SELECT 1"); $this->result['data'] = array("OK", time()); break; case 'checkTMKey': //get MyMemory apiKey service $tmxHandler = new TMSService(); $tmxHandler->setTmKey($this->__postInput['tm_key']); //validate the key try { $keyExists = $tmxHandler->checkCorrectKey(); } catch (Exception $e) { /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */ Log::doLog($e->getMessage()); } if (!isset($keyExists) || $keyExists === false) { $this->result['errors'][] = array("code" => -9, "message" => "TM key is not valid."); Log::doLog(__METHOD__ . " -> TM key is not valid."); $this->result['success'] = false; } else { $this->result['errors'] = array(); $this->result['success'] = true; } break; } }
/** * When Called it perform the controller action to retrieve/manipulate data * * @return void */ function doAction() { //if some error occured, stop execution. if (count(@$this->result['errors'])) { return; } try { $tmService = new TMSService(); $tmService->setTmKey($this->key); //validate the key try { $keyExists = $tmService->checkCorrectKey(); } catch (Exception $e) { /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */ Log::doLog($e->getMessage()); } if (!isset($keyExists) || $keyExists === false) { Log::doLog(__METHOD__ . " -> TM key is not valid."); throw new Exception("TM key is not valid.", -4); } $tmKeyStruct = new TmKeyManagement_TmKeyStruct(); $tmKeyStruct->key = $this->key; $tmKeyStruct->name = $this->description; $tmKeyStruct->tm = true; $tmKeyStruct->glos = true; $mkDao = new TmKeyManagement_MemoryKeyDao(Database::obtain()); $memoryKeyToUpdate = new TmKeyManagement_MemoryKeyStruct(); $memoryKeyToUpdate->uid = $this->uid; $memoryKeyToUpdate->tm_key = $tmKeyStruct; switch ($this->exec) { case 'delete': $userMemoryKeys = $mkDao->disable($memoryKeyToUpdate); break; case 'update': $userMemoryKeys = $mkDao->update($memoryKeyToUpdate); break; case 'newKey': $userMemoryKeys = $mkDao->create($memoryKeyToUpdate); break; default: throw new Exception("Unexpected Exception", -4); } if (!$userMemoryKeys) { throw new Exception("This key wasn't found in your keyring.", -3); } } catch (Exception $e) { $this->result['data'] = 'KO'; $this->result['errors'][] = array("code" => $e->getCode(), "message" => $e->getMessage()); } }
public function doAction() { switch ($this->__postInput['exec']) { case 'stayAnonymous': unset($_SESSION['_anonym_pid']); unset($_SESSION['incomingUrl']); unset($_SESSION['_newProject']); break; case 'ping': $db = Database::obtain(); $db->query("SELECT 1"); $this->result['data'] = array("OK", time()); break; case 'checkTMKey': //get MyMemory apiKey service $tmxHandler = new TMSService(); $tmxHandler->setTmKey($this->__postInput['tm_key']); //validate the key try { $keyExists = $tmxHandler->checkCorrectKey(); } catch (Exception $e) { /* PROVIDED KEY IS NOT VALID OR WRONG, $keyExists IS NOT SET */ Log::doLog($e->getMessage()); } if (!isset($keyExists) || $keyExists === false) { $this->result['errors'][] = array("code" => -9, "message" => "TM key is not valid."); Log::doLog(__METHOD__ . " -> TM key is not valid."); $this->result['success'] = false; } else { $this->result['errors'] = array(); $this->result['success'] = true; } break; case 'clearNotCompletedUploads': try { Utils::deleteDir(INIT::$UPLOAD_REPOSITORY . '/' . $_COOKIE['upload_session'] . '/'); } catch (Exception $e) { Log::doLog("ajaxUtils::clearNotCompletedUploads : " . $e->getMessage()); } setcookie("upload_session", null, -1, '/'); unset($_COOKIE['upload_session']); break; } }