Пример #1
0
 /**
  * Open a new user service
  *
  * @param \psm\Service\Database $db
  * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session if NULL, one will be created
  */
 public function __construct(Database $db, SessionInterface $session = null)
 {
     $this->db_connection = $db->pdo();
     if (!psm_is_cli()) {
         if ($session == null) {
             $session = new Session();
             $session->start();
         }
         $this->session = $session;
         if (!defined('PSM_INSTALL') || !PSM_INSTALL) {
             // check the possible login actions:
             // 1. login via session data (happens each time user opens a page on your php project AFTER he has successfully logged in via the login form)
             // 2. login via cookie
             // if user has an active session on the server
             if (!$this->loginWithSessionData()) {
                 $this->loginWithCookieData();
             }
         }
     }
 }
Пример #2
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP Server Monitor.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package     phpservermon
 * @author      Pepijn Over <*****@*****.**>
 * @copyright   Copyright (c) 2008-2015 Pepijn Over <*****@*****.**>
 * @license     http://www.gnu.org/licenses/gpl.txt GNU GPL v3
 * @version     Release: @package_version@
 * @link        http://www.phpservermonitor.org/
 **/
// include main configuration and functionality
require_once __DIR__ . '/../src/bootstrap.php';
if (!psm_is_cli()) {
    die('This script can only be run from the command line.');
}
$cron_timeout = PSM_CRON_TIMEOUT;
// parse a couple of arguments
if (!empty($_SERVER['argv'])) {
    foreach ($_SERVER['argv'] as $argv) {
        $argi = explode('=', ltrim($argv, '--'));
        if (count($argi) !== 2) {
            continue;
        }
        switch ($argi[0]) {
            case 'uri':
                define('PSM_BASE_URL', $argi[1]);
                break;
            case 'timeout':
Пример #3
0
 /**
  * Run.
  *
  * The $mod param is in the format $module_$controller.
  * If the "_$controller" part is omitted, it will attempt to load
  * the controller with the same name as the module.
  * If no mod is given it will attempt to load the default module.
  * @param string $mod if empty, the mod getvar will be used, or fallback to default
  * @throws \InvalidArgumentException
  * @throws \LogicException
  */
 public function run($mod = null)
 {
     if (!psm_is_cli() && isset($_GET["logout"])) {
         $this->services['user']->doLogout();
         // logged out, redirect to login
         header('Location: ' . psm_build_url());
         die;
     }
     if ($mod === null) {
         $mod = psm_GET('mod', $this->default_module);
     }
     try {
         $controller = $this->getController($mod);
     } catch (\InvalidArgumentException $e) {
         // invalid module, try the default one
         // it that somehow also doesnt exist, we have a bit of an issue
         // and we really have no reason catch it
         $controller = $this->getController($this->default_module);
     }
     // get min required level for this controller and make sure the user matches
     $min_lvl = $controller->getMinUserLevelRequired();
     $action = null;
     if ($min_lvl < PSM_USER_ANONYMOUS) {
         // if user is not logged in, load login module
         if (!$this->services['user']->isUserLoggedIn()) {
             $controller = $this->getController('user_login');
         } elseif ($this->services['user']->getUserLevel() > $min_lvl) {
             $controller = $this->getController('error');
             $action = '401';
         }
     }
     $controller->setUser($this->services['user']);
     $response = $controller->initialize($action);
     if (!$response instanceof Response) {
         throw new \LogicException('Controller did not return a Response object.');
     }
     $response->send();
 }