Example #1
0
 private function error($errors)
 {
     Application::$template = false;
     header("Content-Type: application/json");
     echo json_encode(array('error' => $errors));
     die;
 }
Example #2
0
 public function getContents()
 {
     User::log("Logged out");
     $_SESSION = array();
     Application::$template = "login.tpl";
     Application::redirect("/");
 }
Example #3
0
 public function getContents()
 {
     User::log("Logged out");
     $_SESSION = array();
     header("Location: " . Application::getLink("/"));
     Application::$template = "login.tpl";
     return "You have been logged out.";
 }
 public function get($params)
 {
     ntentan\logger\Logger::info("Reading Notifications " . print_r($_SESSION['notifications'], true));
     Application::$template = false;
     header('Content-Type: application/json');
     $response = json_encode($_SESSION['notifications']);
     $_SESSION['notifications'] = array();
     return $response;
 }
Example #5
0
 public function __construct()
 {
     if (substr($_REQUEST["q"], 0, 10) == "system/api") {
         Application::$template = "";
     }
     $this->format = isset($_REQUEST["__api_format"]) ? $_REQUEST["__api_format"] : $this->format;
     unset($_REQUEST["__api_format"]);
     unset($_REQUEST["q"]);
     if ($_SESSION["logged_in"] == false && $_GET["q"] != "system/api/login") {
         print $this->format(array("success" => false, "status" => 101, "message" => "Not authenticated"));
         die;
     }
 }
Example #6
0
 /**
  * The default page which shows the login form.
  * @see lib/controllers/Controller#getContents()
  */
 public function getContents()
 {
     Application::addStylesheet("css/login.css");
     Application::$template = "login.tpl";
     Application::setTitle("Login");
     if ($_SESSION["logged_in"]) {
         Application::redirect(Application::getLink("/"));
     }
     $form = new Form();
     $form->setRenderer("default");
     $username = new TextField("Username", "username");
     $form->add($username);
     $password = new PasswordField("Password", "password");
     $form->add($password);
     $form->setSubmitValue("Login");
     $form->setCallback("{$this->getClassName()}::callback", $this);
     return $form->render();
 }
Example #7
0
 public function __construct()
 {
     ini_set('html_errors', 'Off');
     if (substr($_REQUEST["q"], 0, 10) == "system/api") {
         Application::$template = "";
     }
     $this->format = isset($_REQUEST["__api_format"]) ? $_REQUEST["__api_format"] : $this->format;
     unset($_REQUEST["__api_format"]);
     unset($_REQUEST["q"]);
     if (isset($_REQUEST['__api_key']) && isset($_REQUEST['__api_signature'])) {
         foreach ($_POST as $key => $value) {
             $aggregatedKey .= $key . substr($_POST[$key], 0, 15);
         }
         foreach ($_GET as $key => $value) {
             if ($key == '__api_key' || $key == '__api_signature' || $key == '__api_format' || $key == '__api_session_id' || $key == 'q') {
                 continue;
             }
             $aggregatedKey .= $key . substr($_GET[$key], 0, 15);
         }
         try {
             @($apiKey = reset(Model::load('system.api_keys')->setQueryResolve(false)->getWithField2('key', $_REQUEST['__api_key'])));
             if ($apiKey['active'] == 't') {
                 $signature = sha1($aggregatedKey . $apiKey['secret']);
                 if ($signature == $_GET['__api_signature']) {
                     $_SESSION['logged_in'] = true;
                     $_SESSION['user_id'] = $apiKey['user_id'];
                 }
             }
         } catch (Exception $e) {
             print $this->format(array("success" => false, "message" => $e->getMessage()));
             die;
         }
     }
     if ($_SESSION["logged_in"] == false && $_GET["q"] != "api/login") {
         print $this->format(array("success" => false, "status" => 101, "message" => "Not authenticated"));
         die;
     }
 }
Example #8
0
 public function getContents()
 {
     //          if(Configuration::get('attempt_counter') == null || Configuration::get('attempt_counter') === '0')
     //        {
     //            Configuration::set('attempt_counter',0);
     //        }
     Application::addStylesheet("css/login.css");
     Application::$template = "login.tpl";
     Application::setTitle("Login");
     if ($_SESSION["logged_in"]) {
         Application::redirect("/");
     }
     $form = new Form();
     $form->setRenderer("default");
     $username = new TextField("Username", "username");
     $form->add($username);
     $password = new PasswordField("Password", "password");
     $password->setEncrypted(false);
     $form->add($password);
     $form->setSubmitValue("Login");
     $form->setValidatorCallback("{$this->getClassName()}::callback");
     $form->setShowClear(false);
     return $form->render();
 }
Example #9
0
 /**
  * Outputs the application. This calls all the template files and outputs the
  * final application in HTML.
  */
 public static function render()
 {
     $t = Application::$templateEngine;
     if ($_GET["q"] == "") {
         $_GET["q"] = "dashboard";
     }
     $path = explode("/", $_GET["q"]);
     Application::$template = "main.tpl";
     require SOFTWARE_HOME . "app/bootstrap.php";
     $t->assign('prefix', Application::$prefix);
     Application::setTitle();
     $module = Controller::load($path);
     if (Application::$cli) {
         ob_start();
     }
     if (Application::$template == "") {
         print $module->content;
     } else {
         $t->assign('content', $module->content);
         $t->assign('module_name', $module->label);
         $t->assign('module_description', $module->description);
         foreach (array_keys(Application::$menus) as $key) {
             $t->assign($key, Menu::getContents($key));
         }
         $t->assign('stylesheets', Application::$stylesheets);
         $t->assign('styles', $t->fetch('stylesheets.tpl'));
         $t->assign('javascripts', Application::$javascripts);
         $t->assign('scripts', $t->fetch('javascripts.tpl'));
         $t->assign('title', Application::$title);
         $t->display(Application::$template);
     }
     if (Application::$cli) {
         if (Application::$cliOutput == "") {
             print ob_get_clean();
         } else {
             file_put_contents(Application::$cliOutput, ob_get_clean());
         }
     }
 }
Example #10
0
 /**
  * Outputs the application. This method is the final stage in the application
  * lifecyle which calls all the template files and outputs the
  * final application in HTML. 
  */
 public static function render()
 {
     $t = Application::$templateEngine;
     if ($_GET["q"] == "") {
         $_GET["q"] = Application::$defaultRoute;
     }
     $path = explode("/", $_GET["q"]);
     Application::$template = "main.tpl";
     $t->assign('prefix', Application::$prefix);
     Application::setTitle();
     $module = Controller::load($path);
     if (Application::$cli) {
         ob_start();
     }
     if (Application::$template == "") {
         print $module->content;
     } else {
         $t->assign('content', $module->content);
         $t->assign('module_name', $module->label);
         $t->assign('module_description', $module->description);
         $t->assign('side_menu_hidden', self::$sideMenuHidden);
         foreach (array_keys(Application::$menus) as $key) {
             $t->assign($key, Menu::getContents($key));
         }
         $t->assign('stylesheets', Application::$stylesheets);
         $t->assign('styles', $t->fetch('stylesheets.tpl'));
         $t->assign('javascripts', Application::$javascripts);
         $t->assign('scripts', $t->fetch('javascripts.tpl'));
         $t->assign('title', Application::$title);
         $t->assign('session', $_SESSION);
         $t->assign('info', array_merge(is_array($_SESSION['notes']) ? $_SESSION['notes'] : array(), self::$notes));
         $t->display(Application::$template);
     }
     if (Application::$cli) {
         if (Application::$cliOutput == "") {
             print ob_get_clean();
         } else {
             file_put_contents(Application::$cliOutput, ob_get_clean());
         }
     }
 }
Example #11
0
 /**
  * Constructor for the ModelController.
  * @param $model An instance of the Model class which represents the model
  *               to be used.
  */
 public function __construct($model = "")
 {
     global $redirectedPackage;
     $this->modelName = $this->modelName == "" ? $model : $this->modelName;
     $this->model = Model::load($this->modelName);
     $this->name = $this->model->name;
     $this->t = $t;
     $this->path = $path;
     $this->urlBase = $this->urlBase == '' ? ($redirectedPackage != '' ? "{$redirectedPackage}" : '') . $this->modelName : $this->urlBase;
     $this->urlPath = Application::$prefix . "/" . str_replace(".", "/", $this->urlBase);
     $this->permissionPrefix = $redirectedPackage . str_replace(".", "_", $this->modelName);
     $this->localPath = "app/modules/" . str_replace(".", "/", $this->urlBase);
     if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || $_REQUEST["__api_mode"] == "yes") {
         Application::$template = "";
         $this->apiMode = true;
         unset($_REQUEST["__api_mode"]);
         unset($_REQUEST["q"]);
     } else {
         $this->label = $this->model->label;
         $this->description = $this->model->description;
         Application::setTitle($this->label);
         $this->toolbar = new Toolbar();
         $this->table = new MultiModelTable(Application::$prefix . "/" . str_replace(".", "/", $this->urlBase) . "/");
         $this->table->useAjax = true;
     }
     $this->_showInMenu = $this->model->showInMenu == "false" ? false : true;
     if (file_exists($this->localPath . "/app.xml")) {
         $this->app = simplexml_load_file($this->localPath . "/app.xml");
     }
 }
Example #12
0
{
    if (!in_array($field, $existFields) || !isset($query)) {
        return [];
    }
    return makeSourceResponse($source::retrieveByField($field, "%" . urldecode($query) . "%", SimpleOrm::FETCH_MANY));
}
// главная страница
Macaw::get('/', function () {
    Application::sendHTMLString(Application::template(dirname(__FILE__) . "/templates/index.html", ['user' => checkAuth()]));
});
Macaw::get('/sign', function () {
    $user = getUser();
    if ($user) {
        redirect("/");
    } else {
        Application::sendHTMLString(Application::template(dirname(__FILE__) . "/templates/signin.html", []));
    }
});
Macaw::post('/sign', function () {
    $user = getUser();
    if ($user) {
        redirect("/");
    } else {
        $gump = new GUMP();
        $data = $gump->sanitize($_POST);
        $gump->validation_rules(array('password' => 'required', 'username' => 'required'));
        $validated_data = $gump->run($data);
        if ($validated_data && authUser($validated_data['username'], $validated_data['password'])) {
            redirect("/");
        } else {
            redirectToLogin();
Example #13
0
 /**
  * Outputs the application. This method is the final stage in the application
  * lifecyle which calls all the template files and outputs the
  * final application in HTML. 
  */
 public static function render()
 {
     $t = Application::$templateEngine;
     if ($_GET["q"] == "") {
         $_GET["q"] = Application::$defaultRoute;
     }
     $path = explode("/", $_GET["q"]);
     Application::$template = "main.tpl";
     $t->assign('prefix', Application::$prefix);
     Application::setTitle();
     $module = Controller::load($path);
     if (Application::$cli) {
         ob_start();
     }
     if (Application::$template == "" || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         header("x-controller-label: {$module->label}");
         header("x-controller-description: {$module->description}");
         echo $module->content;
     } else {
         $t->assign('content', $module->content);
         $t->assign('module_name', $module->label);
         $t->assign('module_description', $module->description);
         $t->assign('side_menu_hidden', self::$sideMenuHidden);
         foreach (array_keys(Application::$menus) as $key) {
             $t->assign($key, Menu::getContents($key));
         }
         $t->assign('stylesheets', Application::$stylesheets);
         $t->assign('styles', $t->fetch('stylesheets.tpl'));
         $t->assign('javascripts', Application::$javascripts);
         $t->assign('scripts', $t->fetch('javascripts.tpl'));
         $t->assign('title', Application::$title);
         $t->assign('session', $_SESSION);
         $t->assign('info', array_merge(is_array($_SESSION['notes']) ? $_SESSION['notes'] : array(), self::$notes));
         $t->display(Application::$template);
     }
 }