Пример #1
0
 function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Пример #2
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         if (!isset(self::$authenticationUser)) {
             throw new Exception("AuthenticationUser object is not initialized.");
         }
         self::$instance = new Authentication();
     }
     return self::$instance;
 }
Пример #3
0
/**
 * Return logged user instance
 *
 * @param void
 * @return User
 */
function &get_logged_user()
{
    static $instance = null;
    if ($instance === null) {
        $instance =& Authentication::instance();
    }
    // if
    if ($instance->provider) {
        return $instance->provider->getUser();
    } else {
        $return = null;
        return $return;
    }
    // if
}
 public function AllowedToAccess($module, $submodule, $action, $type)
 {
     if (Authentication::instance()->checkValidationAppClint() && Authorization::instance()->IsAllowedToAccess($module, $submodule, $action, $type, Authentication::instance()->getApplicationId())) {
         return true;
     } elseif (!Authentication::instance()->checkValidationAppClint() && Authorization::instance()->IsAllowedToAccess($module, $submodule, $action, $type, Authentication::instance()->getApplicationId())) {
         return true;
     } else {
         $dbMsg = SysLog::Instance()->getAllError();
         if (!empty($dbMsg)) {
             echo "<pre>";
             for ($i = 0; $i < count($dbMsg); $i++) {
                 echo $dbMsg[$i];
             }
             echo "</pre>";
         }
         Log::Instance()->SendLog('Gagal akses, request denied');
         die('You don\'t have permission to access this service');
     }
 }
 /**
  * Constructor
  *
  * @param Request $request
  * @return ApplicationController
  */
 function __construct($request)
 {
     parent::__construct($request);
     // Set detault layout for application pages
     $this->setLayout(array('module' => SYSTEM_MODULE, 'layout' => 'wireframe'));
     // Get Smarty instance... We need it
     $this->smarty =& Smarty::instance();
     // Load and init owner company
     $this->owner_company = get_owner_company();
     if (instance_of($this->owner_company, 'Company')) {
         cache_set('owner_company', $this->owner_company);
     } else {
         $this->httpError(HTTP_ERR_NOT_FOUND, 'Owner company is not defined');
     }
     // if
     $this->application =& application();
     $this->authentication =& Authentication::instance();
     $this->logged_user =& $this->authentication->provider->getUser();
     $this->wireframe =& Wireframe::instance();
     $this->wireframe->page_company = $this->owner_company;
     $this->theme_name = instance_of($this->logged_user, 'User') ? UserConfigOptions::getValue('theme', $this->logged_user) : ConfigOptions::getValue('theme');
     $this->smarty->assign(array('root_url' => ROOT_URL, 'assets_url' => ASSETS_URL));
     // Maintenance mode
     if (ConfigOptions::getValue('maintenance_enabled')) {
         if (instance_of($this->logged_user, 'User') && $this->logged_user->isAdministrator()) {
             $this->wireframe->addPageMessage(lang('System is in maintenance mode and can be used by administrators only. <a href=":url">Click here</a> to turn off maintenance mode', array('url' => assemble_url('admin_settings_maintenance'))), 'warning');
         } else {
             $additional_error_info = ConfigOptions::getValue('maintenance_message');
             if ($additional_error_info) {
                 $additional_error_info .= "\n\n";
             }
             // if
             $additional_error_info .= lang('When system is in maintenance mode, administrators can log in and access the system') . ": " . assemble_url('login');
             $this->smarty->assign('additional_error_info', $additional_error_info);
             if ($this->restrict_access_in_maintenance_mode) {
                 $this->httpError(503);
             }
             // if
         }
         // if
     }
     // if
     // Check permissions
     if ($this->login_required && !instance_of($this->logged_user, 'User')) {
         // If async don't redirect to loging, just server proper HTTP code
         if ($this->request->isAsyncCall()) {
             $this->httpError(HTTP_ERR_UNAUTHORIZED, null, true, true);
             // Not async? Redirect to login with extracted route data...
         } else {
             $params = array();
             if ($request->matched_route != 'login') {
                 $params['re_route'] = $request->matched_route;
                 foreach ($this->request->url_params as $k => $v) {
                     if ($k == 'module' || $k == 'controller' || $k == 'action') {
                         continue;
                     }
                     // if
                     $params["re_{$k}"] = $v;
                 }
                 // foreach
             }
             // if
             $this->redirectTo($this->login_route, $params);
         }
         // if
     }
     // if
     if (instance_of($this->logged_user, 'User') && !$this->logged_user->getSystemPermission('system_access')) {
         $this->authentication->provider->logUserOut();
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $loaded_modules = $this->application->getModules();
     $assets_query_string = 'v=' . $this->application->version . '&modules=';
     foreach ($loaded_modules as $loaded_module) {
         $assets_query_string .= $loaded_module->getName() . ',';
     }
     // foreach
     $this->smarty->assign(array('api_status' => API_STATUS, 'application' => $this->application, 'owner_company' => $this->owner_company, 'authentication' => $this->authentication, 'logged_user' => $this->logged_user, 'request' => $this->request, 'theme_name' => $this->theme_name, 'request_time' => $this->request_time, 'loaded_modules' => $this->application->getModules(), 'captcha_url' => ROOT_URL . '/captcha.php?id=' . md5(time()), 'assets_query_string' => $assets_query_string, 'js_disabled_url' => assemble_url('js_disabled')));
     $this->smarty->assign_by_ref('wireframe', $this->wireframe);
     js_assign(array('homepage_url' => ROOT_URL, 'assets_url' => ASSETS_URL, 'indicator_url' => get_image_url('indicator.gif'), 'big_indicator_url' => get_image_url('indicator_big.gif'), 'ok_indicator_url' => get_image_url('ok_indicator.gif'), 'warning_indicator_url' => get_image_url('warning_indicator.gif'), 'error_indicator_url' => get_image_url('error_indicator.gif'), 'pending_indicator_url' => get_image_url('pending_indicator.gif'), 'url_base' => URL_BASE, 'keep_alive_interval' => KEEP_ALIVE_INTERVAL, 'refresh_session_url' => assemble_url('refresh_session'), 'jump_to_project_url' => assemble_url('jump_to_project_widget'), 'quick_add_url' => assemble_url('quick_add'), 'path_info_through_query_string' => PATH_INFO_THROUGH_QUERY_STRING, 'image_picker_url' => assemble_url('image_picker'), 'copyright_removed' => LICENSE_COPYRIGHT_REMOVED, 'custom_tabs_manager' => assemble_url('custom_tabs_manager'), 'add_milestone_url' => assemble_url('project_milestones_add', array('project_id' => '--PROJECT_ID--')), 'add_checklist_url' => assemble_url('project_checklists_add', array('project_id' => '--PROJECT_ID--')), 'add_discussion_url' => assemble_url('project_discussions_add', array('project_id' => '--PROJECT_ID--')), 'add_file_url' => assemble_url('project_files_upload', array('project_id' => '--PROJECT_ID--')), 'add_page_url' => assemble_url('project_pages_add', array('project_id' => '--PROJECT_ID--')), 'add_ticket_url' => assemble_url('project_tickets_add', array('project_id' => '--PROJECT_ID--')), 'add_timerecord_url' => assemble_url('project_time_add', array('project_id' => '--PROJECT_ID--')), 'attachment_rename_url' => assemble_url('attachment_rename', array('project_id' => '--PROJECT_ID--', 'attachment_id' => '--ATTACHMENT_ID--')), 'attachment_copy_to_url' => assemble_url('attachment_copy_to', array('project_id' => '--PROJECT_ID--', 'attachment_id' => '--ATTACHMENT_ID--')), 'attachment_move_to_url' => assemble_url('attachment_move_to', array('project_id' => '--PROJECT_ID--', 'attachment_id' => '--ATTACHMENT_ID--')), 'image_uploader_url' => assemble_url('image_uploader'), 'render_comments_url' => assemble_url('render_comments'), 'move_task_url' => assemble_url('project_task_move', array('project_id' => '--PROJECT_ID--', 'task_id' => '--TASK_ID--')), 'get_collection_url' => assemble_url('collection'), 'quick_task_reminder_url' => assemble_url('project_task_quickreminder', array('project_id' => '--PROJECT_ID--', 'task_id' => '--TASK_ID--')), 'convert_to_ticket_url' => assemble_url('project_object_convert_to_ticket', array('project_id' => '--PROJECT_ID--', 'object_id' => '--OBJECT_ID--')), 'convert_to_milestone_url' => assemble_url('project_object_convert_to_milestone', array('project_id' => '--PROJECT_ID--', 'object_id' => '--OBJECT_ID--')), 'convert_to_page_url' => assemble_url('project_object_convert_to_page', array('project_id' => '--PROJECT_ID--', 'object_id' => '--OBJECT_ID--')), 'snooze_task_url' => assemble_url('project_task_snooze', array('project_id' => '--PROJECT_ID--', 'task_id' => '--TASK_ID--'))));
     if ($this->logged_user) {
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         if (!empty($_SESSION['pg_ttl'])) {
             mysql_query("update healingcrystals_user_visited_pages set title='" . mysql_real_escape_string($_SESSION['pg_ttl']) . "' where user_id='" . $this->logged_user->getId() . "' and access_time='" . date('Y-m-d H:i:s', $_SESSION['temp_time']) . "'");
         }
         $current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
         $pos = strpos($_SERVER['QUERY_STRING'], '%2F');
         if ($pos !== false) {
             $max_pages_count_per_user = 50;
             //require_once SMARTY_PATH . '/plugins/function.page_title.php';
             //$current_page_title = smarty_function_page_title(array('default' => 'Projects'));
             //$current_page_title = PageConstruction::getPageTitle();
             $_SESSION['temp_time'] = time();
             mysql_query("insert into healingcrystals_user_visited_pages (user_id, page_url, title, access_time) values ('" . $this->logged_user->getId() . "', '" . $current_url . "', '', '" . date('Y-m-d H:i:s', $_SESSION['temp_time']) . "')");
             //mysql_query("insert into healingcrystals_user_visited_pages (user_id, page_url, title, access_time) values ('" . $this->logged_user->getId() . "', '" . $current_url . "', '', now())");
             $query = "select count(*) as count from healingcrystals_user_visited_pages where user_id='" . $this->logged_user->getId() . "'";
             $result = mysql_query($query);
             $info = mysql_fetch_assoc($result);
             $current_count = $info['count'];
             if ($current_count > $max_pages_count_per_user) {
                 $querries = array();
                 $query = "select * from healingcrystals_user_visited_pages where user_id='" . $this->logged_user->getId() . "' order by access_time limit 0, " . ($current_count - $max_pages_count_per_user);
                 $result = mysql_query($query);
                 while ($info = mysql_fetch_assoc($result)) {
                     $querries[] = "delete from healingcrystals_user_visited_pages where user_id='" . $this->logged_user->getId() . "' and page_url='" . $info['page_url'] . "' and access_time='" . $info['access_time'] . "'";
                 }
             }
             foreach ($querries as $query) {
                 mysql_query($query);
             }
         }
         $_SESSION['pg_ttl'] = '';
         mysql_close($link);
     }
 }
 /**
  * Authenticate
  *
  * @param void
  * @return null
  */
 function authenticate()
 {
     $provider_class = AUTH_PROVIDER;
     use_auth_provider($provider_class);
     if (!class_exists($provider_class)) {
         use_error('ClassNotImplementedError');
         return new ClassNotImplementedError($provider_class);
     }
     // if
     $provider = new $provider_class();
     if (!instance_of($provider, 'AuthenticationProvider')) {
         return new InvalidInstanceError('provider', $provider, 'AuthenticationProvider');
     }
     // if
     $manager =& Authentication::instance($provider, false);
     $token = false;
     if (FORCE_QUERY_STRING) {
         if (ANGIE_QUERY_STRING) {
             $query_string_aprams = parse_string(ANGIE_QUERY_STRING);
             if (isset($query_string_aprams['token'])) {
                 $token = $query_string_aprams['token'];
             }
             // if
         }
         // if
     } else {
         $token = isset($_GET['token']) ? $_GET['token'] : false;
     }
     // if
     // Handle token based authentication
     if ($token !== false) {
         // Die if disabled or read-only with POST parameters
         if (API_STATUS == API_DISABLED || API_STATUS == API_READ_ONLY && count($_POST) > 0) {
             header('HTTP/1.1 403 Forbidden');
             print "<h1>HTTP/1.1 403 Forbidden</h1>\n";
             if (API_STATUS == API_DISABLED) {
                 print '<p>API is disabled</p>';
             } else {
                 print '<p>API is read-only</p>';
             }
             // if
             die;
         }
         // if
         // Get token and auth_id (old and new API key formats are supported)
         if (strpos($token, '-') !== false) {
             list($auth_id, $token) = explode('-', $token);
         } else {
             $auth_id = array_var($_GET, 'auth_id');
         }
         // if
         $user = null;
         if ($auth_id) {
             $user = Users::findById($auth_id);
         }
         // if
         if (instance_of($user, 'User') && $user->getToken() == $token) {
             $manager->provider->logUserIn($user, array('silent' => true));
             return true;
         } else {
             header('HTTP/1.1 403 Forbidden');
             print '<h1>HTTP/1.1 403 Forbidden</h1>';
             die;
         }
         // if
     }
     // if
     $manager->provider->initialize();
     return true;
 }
 /**
  * Initialize authentication
  * 
  * First we get authentication provider and then we create authentication 
  * manager instance...
  *
  * @param void
  * @return null
  */
 function authenticate()
 {
     $provider_class = AUTH_PROVIDER;
     use_auth_provider($provider_class);
     if (!class_exists($provider_class)) {
         use_error('ClassNotImplementedError');
         return new ClassNotImplementedError($provider_class);
     }
     // if
     $provider = new $provider_class();
     if (!instance_of($provider, 'AuthenticationProvider')) {
         return new InvalidInstanceError('provider', $provide, 'AuthenticationProvider');
     }
     // if
     $manager =& Authentication::instance($provider);
 }