Exemple #1
0
 public function run()
 {
     try {
         $this->oRequest = $this->_run();
         $oRequest =& $this->oRequest;
         $this->sServiceModule = $oRequest->module;
         $this->sServiceMethod = $oRequest->method;
         $this->sServiceToken = $oRequest->token;
         FlexiLogger::info(__METHOD__, "Running service: " . $this->sServiceModule . "::" . $this->sServiceMethod);
         FlexiLogger::debug(__METHOD__, "Token: " . $this->sServiceToken);
         //throw new Exception("Token: " . $this->sServiceToken);
         //if ($this->sServiceMethod!="login") throw new Exception("Token: " . $this->sServiceToken);
         FlexiConfig::getLoginHandler()->doLoginByToken($this->sServiceToken);
         //if ($this->sServiceMethod!="login") throw new Exception("Logged in as: " . FlexiConfig::getLoginHandler()->getLoggedInUserId());
         FlexiLogger::debug(__METHOD__, "Logged in as: " . FlexiConfig::getLoginHandler()->getLoggedInUserId());
         $this->mRequestData = array();
         if (isset($oRequest->data)) {
             $this->mRequestData = $oRequest->data;
         }
         $mResult = FlexiController::getInstance()->runService($this->sServiceModule, $this->sServiceMethod, $this->mRequestData);
         unset($mResult["control"]);
         FlexiLogger::debug(__METHOD__, "Done service: " . $this->sServiceModule . "::" . $this->sServiceMethod);
         echo $this->returnResult($mResult);
     } catch (Exception $e) {
         echo $this->returnResult(array("status" => false, "return" => null, "msg" => $e->getMessage()));
     }
 }
Exemple #2
0
 public function onEvent($event, $oModel)
 {
     $sTable = $oModel->getMeta("type");
     FlexiLogger::debug(__METHOD__, $sTable . ", Event: " . $event);
     $sMethod = "on" . $event;
     FlexiLogger::debug(__METHOD__, $sTable . ", Method: " . $sMethod);
     if (isset(self::$aValidator[$sTable])) {
         if (is_array(self::$aValidator[$sTable])) {
             foreach (self::$aValidator[$sTable] as $oClass) {
                 if (method_exists($oClass, $sMethod)) {
                     FlexiLogger::debug(__METHOD__, "Calling: " . $sTable . ": " . $sMethod);
                     $oClass->{$sMethod}($oModel);
                 }
             }
             //is array
         } else {
             if (method_exists(self::$aValidator[$sTable], $sMethod)) {
                 FlexiLogger::info(__METHOD__, "Calling: " . $sTable . ": " . $sMethod);
                 self::$aValidator[$sTable]->{$sMethod}($oModel);
             }
         }
         //if is direct
     }
     //if exists table event
 }
 public function getIDField($type)
 {
     FlexiLogger::debug(__METHOD__, "Getting id: " . $type);
     if (isset(FlexiModelUtil::$aTableId[$type])) {
         FlexiLogger::debug(__METHOD__, "Is set: " . FlexiModelUtil::$aTableId[$type]);
         return FlexiModelUtil::$aTableId[$type];
     }
     return parent::getIDField($type);
 }
 public function doLogin($asLoginId, $asLoginPass, $asConfig = array())
 {
     $bResult = $this->doFlexiAdminLogin($asLoginId, $asLoginPass);
     FlexiLogger::debug(__METHOD__, "FlexiAdminLogin: "******"success" : "fail"));
     if (!$bResult) {
         $bResult = $this->onLogin($asLoginId, $asLoginPass, $asConfig);
     }
     return $bResult;
 }
 /**
  * Called to return request object
  * @return request object
  */
 public function _run()
 {
     $sRaw = $this->getDecodedData();
     //FlexiLogger::error(__METHOD__, "Running: " . serialize($sRaw));
     FlexiLogger::debug(__METHOD__, "Running2: " . print_r($sRaw, true));
     $oRequest = json_decode($sRaw);
     //FlexiLogger::error(__METHOD__, "JSON: " . serialize($oRequest));
     return $oRequest;
 }
Exemple #6
0
 public function startSession()
 {
     if (is_null($this->session)) {
         FlexiLogger::debug(__METHOD__, "starting session");
         $this->session = $this->facebook->getSession();
         FlexiLogger::debug(__METHOD__, serialize($this->session));
     }
     return $this->session;
 }
Exemple #7
0
 public function methodTestremote()
 {
     FlexiLogger::debug(__METHOD__, "starting");
     $sURL = FlexiConfig::$sBaseURL . "remote.php";
     $oData = array("testme" => "xyz");
     $oClient = new FlexiRemoteJSONClient();
     $oClient->setContent($oData);
     $bResult = $oClient->callRemote($sURL, "xxx", "test");
     FlexiLogger::debug(__METHOD__, "Result status: " . serialize($bResult));
     var_dump($oClient->getResultReturned());
     return true;
 }
 public function getIDField($type)
 {
     if (gettype($type) != "string") {
         throw new FlexiException("Type must be string: " . gettype($type), ERROR_UNKNOWNTYPE);
     }
     FlexiLogger::debug(__METHOD__, "Getting id: " . $type);
     if (isset(FlexiModelUtil::$aTableId[$type])) {
         //FlexiLogger::info(__METHOD__, "Is set: " . FlexiModelUtil::$aTableId[$type]);
         return FlexiModelUtil::$aTableId[$type];
     }
     return parent::getIDField($type);
 }
Exemple #9
0
 public function serviceSyncTable($oData)
 {
     FlexiLogger::debug(__METHOD__, "Running");
     //var_dump($aData["type"]);
     //FlexiLogger::error(__METHOD__, print_r($oData, true));
     $aTable = $oData->tables;
     $sType = $oData->type;
     $aMessage = array();
     FlexiLogger::info(__METHOD__, "Sync type: " . $sType);
     $oUtil = FlexiModelUtil::getInstance();
     foreach ($aTable as $sTable => $aTableSetting) {
         $aRow = $aTableSetting->rows;
         $sIDField = $aTableSetting->idfield;
         //FlexiLogger::error(__METHOD__, $sTable);
         $oModel = $oUtil->getRedBeanModel($sTable);
         if ($sType == "fullsync") {
             FlexiLogger::info(__METHOD__, "Clearing table: " . $sTable);
             if ($oUtil->getRedBeanDB()->tableExists($sTable)) {
                 $oUtil->getRedBeanExecute("delete from " . $sTable);
             }
         }
         if (count($aRow) > 0) {
             $sFields = implode(",", array_keys((array) $aRow[0]));
         }
         $oUtil->setRedBeanTableIdField($sTable, $sIDField);
         FlexiLogger::debug(__METHOD__, $sTable . ", fields: " . $sFields);
         foreach ($aRow as $oRow) {
             $oRowData = (array) $oRow;
             $oModel = $oUtil->getRedBeanModel($sTable);
             //        $sPrimaryField = "id";
             //        if (isset($oRowData[$sPrimaryField])) {
             //          $oModel = $oUtil->getRedBeanModel($sTable, $oRowData[$sPrimaryField]);
             //        } else {
             //          $oModel = $oUtil->getRedBeanModel($sTable);
             //        }
             //FlexiLogger::info(__METHOD__, "Type: " . $oModel->getMeta("type"));
             $oModel->import($oRowData, $sFields);
             FlexiLogger::info(__METHOD__, "model: " . $sTable . ", values: " . print_r($oModel->export(), true));
             $oUtil->insertOrUpdateRedBean($oModel);
             unset($oModel);
         }
         //each records
         $aMessage[] = "Imported: " . $sTable . ", cnt: " . count($aRow);
         FlexiLogger::info(__METHOD__, "Imported: " . $sTable . ", cnt: " . count($aRow));
         //if (1==1) { break; }
     }
     //each table
     $this->unsetToken();
     FlexiLogger::info(__METHOD__, "Done");
     return array("msg" => implode("\r\n<br/>", $aMessage));
 }
 public function checkIfExistsUserEmail($sEmail, $iId = null)
 {
     FlexiLogger::debug(__METHOD__, "checking email: " . $sEmail);
     if (empty($sEmail)) {
         return false;
     }
     $oQuery = FlexiModelUtil::getDBQuery("ModxWebUsers u", "flexiphp/base/FlexiAdminUser")->leftJoin("u.Attributes a");
     if (!empty($iId)) {
         $oModel = $oQuery->where("a.email=? and u.id=?", array($sEmail, $iId))->fetchOne();
         return $oModel != null && $oModel !== false;
     } else {
         $oModel = $oQuery->where("a.email=?", array($sEmail))->fetchOne();
         return $oModel != null && $oModel !== false;
     }
 }
Exemple #11
0
 public static function triggerEvent($sName, &$args = null)
 {
     FlexiLogger::debug(__METHOD__, "Name: " . $sName);
     $aFunc = self::getEvent($sName);
     foreach ($aFunc as $sFunc) {
         FlexiLogger::debug(__METHOD__, "Function: " . $sFunc);
         $bIsClass = strpos($sFunc, "::") !== false ? true : false;
         if ($bIsClass) {
             list($sClass, $sMethod) = explode("::", $sFunc);
             FlexiLogger::debug(__METHOD__, "Class: " . $sClass . ", method: " . $sMethod);
             call_user_func(array($sClass, $sMethod), $args);
         } else {
             call_user_func($sFunc, $args);
         }
     }
     //end foreach
 }
 public function checkIfExistsUserEmail($sEmail, $iId = null)
 {
     FlexiLogger::debug(__METHOD__, "checking email: " . $sEmail);
     if (empty($sEmail)) {
         return false;
     }
     if (!empty($iId)) {
         $oModel = FlexiModelUtil::getInstance()->getRedbeanFetchOne("select * from " . FlexiConfig::$sDBPrefix . " where user_id=:id and email=:email", array(":id" => $iId, ":email" => $sEmail));
         if (!empty($oModel["user_id"])) {
             return true;
         }
         return false;
     } else {
         $oModel = FlexiModelUtil::getInstance()->getRedbeanFetchOne("select * from " . FlexiConfig::$sDBPrefix . " where email=:email", array(":email", $sEmail));
         if (!empty($oModel["user_id"])) {
             return true;
         }
         return false;
     }
 }
Exemple #13
0
 function methodModXProcessform()
 {
     $iId = $this->getRequest("rid");
     $aForm = $this->loadForm();
     if (!empty($iId)) {
         $oModel = $this->getDBQuery("ModxWebUsers")->where("id=?", array($iId))->fetchOne();
         if ($oModel === false) {
             FlexiLogger::error(__METHOD__, "Record not found.");
             $this->addMessage("Record not found", "error");
             return $this->renderForm($aForm);
         }
         $oModel = $this->getModelFromForm($oModel, $aForm["form"]);
     } else {
         $oModel = $this->getModelFromForm("ModxWebUsers", $aForm["form"]);
     }
     $oModel->Attributes->fullname = $aForm["form"]["txtFullName"]["#value"];
     //$oModel->dob 					= "1980-01-01";
     if (!$this->validateFormByModel($aForm["form"], $oModel) || !$this->validateForm($aForm["form"])) {
         FlexiLogger::error(__METHOD__, "Validation failed: " . $oModel->getErrorStackAsString());
         $this->addMessage("Validation failed", "error");
         return $this->renderForm($aForm);
     }
     FlexiLogger::debug(__METHOD__, "ok");
     try {
         $oModel->replace();
         $oGroupModel = $this->getModelInstance("ModxWebGroups");
         $oGroupModel->webuser = $oModel->id;
         $oGroupModel->webgroup = 2;
         //hardcoded to registered user
         $oGroupModel->replace();
         //$this->oView->addVar("message", "saved.");
         $this->addMessage("Saved", "success");
         return $this->runControl("default");
     } catch (Exception $e) {
         FlexiLogger::error(__METHOD__, "Save failed:" . $e->getMessage());
         $this->addMessage("Error saving: " . $e->getMessage(), "error");
         return $this->runControl("form");
     }
 }
Exemple #14
0
 /**
  * Do call to remote url
  * @param String $asURL
  * @param String $asModule
  * @param String $asMethod
  * @return boolean: true/false
  */
 public function callRemote($asURL = "http://localhost", $asModule = "", $asMethod = "")
 {
     FlexiLogger::debug(__METHOD__, "Calling URL: " . $asURL);
     $bDebug = false;
     $sURL = $asURL;
     $sModule = empty($asModule) ? "default" : $asModule;
     $sMethod = empty($asMethod) ? "default" : $asMethod;
     //$sURL = "temp/bloomberg-stocks.html";
     $aHeader = $this->getHeaders();
     $opts = array('http' => array('method' => "POST", 'header' => implode("\r\n", $aHeader), 'content' => $this->getRequestContent($sModule, $sMethod)));
     FlexiLogger::debug(__METHOD__, "Content: " . $opts["http"]["content"]);
     $context = stream_context_create($opts);
     FlexiLogger::debug(__METHOD__, "Processing URL: " . $sURL);
     $sResult = file_get_contents($sURL, false, $context);
     if ($sResult === false || empty($sResult)) {
         throw new Exception("Remote returned empty or false");
     }
     try {
         $this->mResult = FlexiCryptUtil::b64Decrypt($sResult, $this->sRemoteKey);
     } catch (Exception $e) {
         throw new Exception($e->getMessage() . "<br/>\nOriginal Remote result: " . $sResult);
     }
     //echo "<hr/>";
     if ($bDebug) {
         echo "\r\n" . __METHOD__ . ": " . $sResult . "<Br/>\r\n";
     }
     //var_dump($this->mResult);
     if (empty($this->mResult)) {
         throw new Exception("Unknown result: " . $sResult);
     }
     FlexiLogger::debug(__METHOD__, "Result raw: " . $this->mResult);
     $aResult = $this->getResult();
     if (empty($aResult)) {
         throw new Exception("Remote returned malformed result: " . $sResult);
     }
     return $aResult->status;
 }
 public function onLogout()
 {
     FlexiLogger::debug(__METHOD__, "Logging-out");
     unset($_SESSION["sess_adminname"]);
     unset($_SESSION["sess_username"]);
     unset($_SESSION["sess_userid"]);
     return true;
 }
 public function onLogout($context = "web")
 {
     FlexiLogger::debug(__METHOD__, "Logging-out");
     unset($_SESSION[$context . "Validated"]);
     //$_SESSION["webInternalKey"] = null;
     $_SESSION[$context . 'Shortname'] = null;
     //$_SESSION['userid'] = null;
     return true;
 }
Exemple #17
0
 public function getNewController($sControl, $oView, $sMethodName, $sModulePath)
 {
     $sClassName = $sControl . "Controller";
     $sBaseDir = $this->env["basedir"];
     $sModulePath = "";
     //echo "trying: " . $sControl;
     FlexiLogger::debug(__METHOD__, "Env.BaseDir: " . $sBaseDir . ", cwd: " . getcwd() . ", modpath: " . FlexiConfig::$sModulePath);
     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . FlexiConfig::$sModulePath . "/" . $sControl);
     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sBaseDir . "/modules/" . $sControl);
     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sBaseDir . "/base/" . $sControl);
     if (is_file(FlexiConfig::$sModulePath . "/" . $sControl . "/controller.php")) {
         $sModulePath = FlexiConfig::$sModulePath . "/" . $sControl;
         require_once $sModulePath . "/controller.php";
     } else {
         if (is_file(FlexiConfig::$sModulePath . "/" . strtolower($sControl) . "/controller.php")) {
             $sModulePath = FlexiConfig::$sModulePath . "/" . strtolower($sControl);
             require_once $sModulePath . "/controller.php";
         } else {
             if (is_file($sBaseDir . "/modules/" . $sControl . "/controller.php")) {
                 $sModulePath = $sBaseDir . "/modules/" . $sControl;
                 FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                 require_once $sModulePath . "/controller.php";
             } else {
                 if (is_file($sBaseDir . "/modules/" . strtolower($sControl) . "/controller.php")) {
                     $sModulePath = $sBaseDir . "/modules/" . strtolower($sControl);
                     FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                     require_once $sModulePath . "/controller.php";
                 } else {
                     if (is_file($sBaseDir . "/base/" . $sControl . "/controller.php")) {
                         $sModulePath = $sBaseDir . "/base/" . $sControl;
                         FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                         require_once $sModulePath . "/controller.php";
                     } else {
                         if (is_file($sBaseDir . "/base/" . strtolower($sControl) . "/controller.php")) {
                             $sModulePath = $sBaseDir . "/base/" . strtolower($sControl);
                             FlexiLogger::debug(__METHOD__, "Checking sModulePath: " . $sModulePath);
                             require_once $sModulePath . "/controller.php";
                         }
                     }
                 }
             }
         }
     }
     if (!class_exists($sClassName)) {
         //echo "not found: " . $sClassName;
         FlexiLogger::error(__METHOD__, "module: " . $sControl . " is missing.");
         throw new Exception("No such class: " . $sClassName);
         return;
     }
     FlexiLogger::debug(__METHOD__, "found module: " . $sControl . " at " . $sModulePath);
     //echo "found module: " . $sControl . " at " . $sModulePath;
     //echo "setting controllerpath: " . $sControl . "=>" . $sModulePath;
     $this->aControllerPath[strtolower($sControl)] = $sModulePath;
     //echo "initialising class: " . $sClassName;
     $oClass = new $sClassName($oView, $sMethodName, $sModulePath);
     //echo "xxxx";
     if (!is_subclass_of($oClass, "FlexiBaseController")) {
         //echo "no class of: " . $sClassName;
         throw new FlexiException("Class: " . $sClassName . " is not of type FlexiBaseController", 500);
     }
     //echo "ok: " .$sClassName;
     return $oClass;
 }
Exemple #18
0
 public function renderLayout()
 {
     //echo "class: " . get_class($this) . ", layout: " . $this->sLayoutTemplate;
     FlexiLogger::debug(__METHOD__, $this->sLayoutTemplate);
     foreach ($this->aViewVars as $sKey => $mValue) {
         $this->oView->addVar($sKey, $mValue);
     }
     //putting up messages
     $this->oView->addVar("#message", FlexiConfig::$aMessage);
     //echo "layout: " . $this->sLayoutTemplate;
     if (!$this->beforeRender()) {
         return;
     }
     //echo "layout: " . $this->sLayoutTemplate;
     if (!empty($this->sLayoutTemplate)) {
         //echo "has layout";
         $this->oView->addVar("header", $this->oView->render("header", null, $this->sModulePath));
         $this->oView->addVar("notice", $this->oView->render("notice", null, $this->sModulePath));
         //manually called in
         //$this->oView->addVar("body", $this->renderView());
         $this->oView->addVar("footer", $this->oView->render("footer", null, $this->sModulePath));
         //echo "ppp";
         if (FlexiConfig::$sFramework == "modx2") {
             //FlexiController::appendOutput("is render layout: " . $this->sLayoutTemplate);
             FlexiController::appendOutput($this->oView->render($this->sLayoutTemplate, null, $this->sModulePath));
         } else {
             echo $this->oView->render($this->sLayoutTemplate, null, $this->sModulePath);
         }
     } else {
         //echo __METHOD__.": no layout, viewname: " . $this->sRenderViewName;
         if (FlexiConfig::$sFramework == "modx2") {
             //FlexiController::appendOutput("is render non-layout");
             FlexiController::appendOutput($this->oView->getVar($this->sRenderViewName));
         } else {
             echo $this->oView->getVar($this->sRenderViewName);
         }
     }
     $this->afterRender();
     $this->unsetSession("#messages");
 }
Exemple #19
0
 public function methodDenied()
 {
     FlexiLogger::debug(__METHOD__, "ok");
     return true;
 }
Exemple #20
0
 /**
  * Get Doctrine query object
  * @param string name
  * @param string path (optional)
  * @return Doctrine_Record
  */
 public static function getDBQuery($asName, $asPath = null)
 {
     self::loadModel($asName, $asPath);
     FlexiLogger::debug(__METHOD__, "Loaded model: " . $asName);
     return Doctrine_Query::create()->from($asName);
 }
 public function hasPermission($sTitle)
 {
     if ($this->isSuperUser()) {
         return true;
     }
     global $modx;
     $bResult = $modx->hasPermission($sTitle);
     if (!$bResult) {
         $aGroups = $modx->getUserDocGroups(true);
         if ($aGroups != null) {
             foreach ($aGroups as $sGroup) {
                 //echo "Doc Group: " . $sGroup . " vs " . $sTitle . "\r\n<br/>";
                 FlexiLogger::Debug(__METHOD__, "Doc Group: " . $sGroup . " vs " . $sTitle);
                 if (strtolower(trim($sGroup)) == strtolower(trim($sTitle))) {
                     $bResult = true;
                     break;
                 }
             }
         } else {
             //echo "doc group empty";
             FlexiLogger::debug(__METHOD__, "Doc Group empty");
         }
     }
     return $bResult;
 }
 public function checkIfExistsUserEmail($sEmail, $iId = null)
 {
     FlexiLogger::debug(__METHOD__, "checking email: " . $sEmail);
     if (empty($sEmail)) {
         return false;
     }
     global $modx;
     $aWhere = array("Profile.email" => $sEmail);
     if (!empty($iId)) {
         $aWhere["id"] = $iId;
     }
     $oQuery = $modx->newQuery("modxUser")->where($aWhere);
     $oModel = $modx->getObject("modxUser", $oQuery);
     return !is_null($oModel);
 }
Exemple #23
0
 public static function doUnlockFile($sPath)
 {
     if (!isset(self::$aLocks[$sPath])) {
         throw new FlexiException("No such lock for path: " . $sPath, ERROR_IO_LOCK);
     }
     flock(self::$aLocks[$sPath], LOCK_UN);
     fclose(self::$aLocks[$sPath]);
     unset(self::$aLocks[$sPath]);
     FlexiLogger::debug(__METHOD__, "Unlocked: " . $sPath);
     return true;
 }