/**
  * Filling the config object with individual testcase data.
  */
 protected function setUp()
 {
     $dbFactory = new Factory();
     if (!isset($this->db)) {
         Registry::remove('db');
         $config = $this->getConfig();
         $this->db = $dbFactory->getInstanceByConfig($config);
         Registry::set('db', $this->db);
     }
     if ($this->db === false) {
         $this->markTestIncomplete('Necessary DB configuration is not set.');
         parent::setUp();
         return;
     }
     /*
      * Deleting all tables from the db and setting up the db using the given schema.
      */
     $sql = 'SHOW TABLES';
     $tableList = $this->db->queryList($sql);
     foreach ($tableList as $table) {
         $sql = 'DROP TABLE ' . $table;
         $this->db->query($sql);
     }
     $this->db->queryMulti($this->getSchemaSQLQueries());
     parent::setUp();
 }
Esempio n. 2
0
 /**
  * Filling the config object with individual testcase data and injecting it into the registry.
  */
 public static function setConfigInRegistry($configData)
 {
     if (static::$config === null) {
         if (!Registry::has('config') && file_exists(CONFIG_PATH . '/config.php')) {
             static::$config = new Config();
             static::$config->loadConfigFromFile(CONFIG_PATH . '/config.php');
             foreach ($configData as $configKey => $configValue) {
                 static::$config->set($configKey, $configValue);
             }
         }
     }
     Registry::remove('config');
     Registry::set('config', self::$config);
 }
Esempio n. 3
0
 public function configAction()
 {
     $errors = array();
     if ($this->getRequest()->isPost()) {
         $_SESSION['install']['usage'] = $this->getRequest()->getPost('usage');
         $_SESSION['install']['modulesToInstall'][$_SESSION['install']['usage']] = $this->getRequest()->getPost('modulesToInstall');
         $_SESSION['install']['adminName'] = $this->getRequest()->getPost('adminName');
         $_SESSION['install']['adminPassword'] = $this->getRequest()->getPost('adminPassword');
         $_SESSION['install']['adminPassword2'] = $this->getRequest()->getPost('adminPassword2');
         $_SESSION['install']['adminEmail'] = $this->getRequest()->getPost('adminEmail');
         if (empty($_SESSION['install']['adminName'])) {
             $errors['adminName'] = 'fieldEmpty';
         }
         if (empty($_SESSION['install']['adminPassword'])) {
             $errors['adminPassword'] = '******';
         }
         if ($_SESSION['install']['adminPassword'] !== $_SESSION['install']['adminPassword2']) {
             $errors['adminPassword2'] = 'fieldDiffersPassword';
         }
         if (empty($_SESSION['install']['adminEmail'])) {
             $errors['adminEmail'] = 'fieldEmpty';
         } elseif (!filter_var($_SESSION['install']['adminEmail'], FILTER_VALIDATE_EMAIL)) {
             $errors['adminEmail'] = 'fieldEmail';
         }
         if (empty($errors)) {
             /*
              * Write install config.
              */
             $fileConfig = new \Ilch\Config\File();
             $fileConfig->set('dbEngine', $_SESSION['install']['dbEngine']);
             $fileConfig->set('dbHost', $_SESSION['install']['dbHost']);
             $fileConfig->set('dbUser', $_SESSION['install']['dbUser']);
             $fileConfig->set('dbPassword', $_SESSION['install']['dbPassword']);
             $fileConfig->set('dbName', $_SESSION['install']['dbName']);
             $fileConfig->set('dbPrefix', $_SESSION['install']['dbPrefix']);
             $fileConfig->saveConfigToFile(CONFIG_PATH . '/config.php');
             /*
              * Initialize install database.
              */
             $dbFactory = new \Ilch\Database\Factory();
             $db = $dbFactory->getInstanceByConfig($fileConfig);
             \Ilch\Registry::set('db', $db);
             $modulesToInstall = $_SESSION['install']['modulesToInstall'][$_SESSION['install']['usage']];
             if (!empty($modulesToInstall)) {
                 $modulesToInstall = array_merge(array('admin', 'article', 'user', 'page', 'media', 'comment', 'imprint', 'contact', 'privacy', 'statistic'), $modulesToInstall);
             } else {
                 $modulesToInstall = array('admin', 'article', 'user', 'page', 'media', 'comment', 'imprint', 'contact', 'privacy', 'statistic');
             }
             $moduleMapper = new \Modules\Admin\Mappers\Module();
             /*
              * Clear old tables.
              */
             $db->dropTablesByPrefix($db->getPrefix());
             foreach ($modulesToInstall as $module) {
                 $configClass = '\\Modules\\' . ucfirst($module) . '\\Config\\config';
                 $config = new $configClass($this->getTranslator());
                 $config->install();
                 if (!empty($config->config)) {
                     $moduleModel = new \Modules\Admin\Models\Module();
                     $moduleModel->setKey($config->config['key']);
                     if (isset($config->config['author'])) {
                         $moduleModel->setAuthor($config->config['author']);
                     }
                     if (isset($config->config['languages'])) {
                         foreach ($config->config['languages'] as $key => $value) {
                             $moduleModel->addContent($key, $value);
                         }
                     }
                     if (isset($config->config['system_module'])) {
                         $moduleModel->setSystemModule(true);
                     }
                     $moduleModel->setIconSmall($config->config['icon_small']);
                     $moduleMapper->save($moduleModel);
                 }
             }
             $menuMapper = new \Modules\Admin\Mappers\Menu();
             $menu1 = new \Modules\Admin\Models\Menu();
             $menu1->setId(1);
             $menu1->setTitle('Hauptmenü');
             $menuMapper->save($menu1);
             $menu2 = new \Modules\Admin\Models\Menu();
             $menu2->setId(2);
             $menu2->setTitle('Hauptmenü 2');
             $menuMapper->save($menu2);
             $sort = 0;
             $menuItem = new \Modules\Admin\Models\MenuItem();
             $menuItem->setMenuId(1);
             $menuItem->setParentId(0);
             $menuItem->setTitle('Menü');
             $menuItem->setType(0);
             $menuMapper->saveItem($menuItem);
             /*
              * Will not linked in menu
              */
             foreach ($modulesToInstall as $module) {
                 if (in_array($module, array('comment', 'shoutbox', 'admin', 'media', 'page', 'newsletter', 'statistic'))) {
                     continue;
                 }
                 $configClass = '\\Modules\\' . ucfirst($module) . '\\Config\\config';
                 $config = new $configClass($this->getTranslator());
                 $menuItem = new \Modules\Admin\Models\MenuItem();
                 $menuItem->setMenuId(1);
                 $menuItem->setSort($sort);
                 $menuItem->setParentId(1);
                 $menuItem->setType(3);
                 $menuItem->setModuleKey($config->config['key']);
                 $menuItem->setTitle($config->config['languages'][$this->getTranslator()->getLocale()]['name']);
                 $menuMapper->saveItem($menuItem);
                 $sort += 10;
             }
             $boxes = "INSERT INTO `[prefix]_menu_items` (`menu_id`, `sort`, `parent_id`, `page_id`, `box_id`, `box_key`, `type`, `title`, `href`, `module_key`) VALUES\n                        (1, 80, 0, 0, 0, 'user_login', 4, 'Login', '', ''),\n                        (1, 90, 0, 0, 0, 'admin_layoutswitch', 4, 'Layout', '', ''),\n                        (1, 100, 0, 0, 0, 'statistic_stats', 4, 'Statistik', '', ''),\n                        (1, 110, 0, 0, 0, 'statistic_online', 4, 'Online', '', ''),\n                        (2, 10, 0, 0, 0, 'admin_langswitch', 4, 'Sprache', '', ''),\n                        (2, 20, 0, 0, 0, 'article_article', 4, 'Letzte Artikel', '', ''),\n                        (2, 30, 0, 0, 0, 'article_categories', 4, 'Kategorien', '', ''),\n                        (2, 40, 0, 0, 0, 'article_archive', 4, 'Archive', '', '')";
             $db->queryMulti($boxes);
             unset($_SESSION['install']);
             $this->redirect(array('action' => 'finish'));
         }
         $this->getView()->set('errors', $errors);
     }
     foreach (array('modulesToInstall', 'usage', 'adminName', 'adminPassword', 'adminPassword2', 'adminEmail') as $name) {
         if (!empty($_SESSION['install'][$name])) {
             $this->getView()->set($name, $_SESSION['install'][$name]);
         }
     }
 }
 /**
  * Checks if a user id was given in the request and sets the user.
  *
  * If no user id is given a default user will be created.
  *
  * @param array $pluginData
  */
 public function __construct(array $pluginData)
 {
     if (!isset($pluginData['config'])) {
         return;
     }
     $userId = null;
     if (isset($_SESSION['user_id'])) {
         $userId = (int) $_SESSION['user_id'];
     }
     $mapper = new UserMapper();
     $user = $mapper->getUserById($userId);
     \Ilch\Registry::set('user', $user);
     if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && preg_match("/^[0-9a-zA-Z\\/.:]{7,}\$/", $_SERVER["HTTP_X_FORWARDED_FOR"])) {
         $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
     } elseif (preg_match("/^[0-9a-zA-Z\\/.:]{7,}\$/", $_SERVER["REMOTE_ADDR"])) {
         $ip = $_SERVER["REMOTE_ADDR"];
     } else {
         $ip = '128.0.0.1';
     }
     if (empty($_SERVER['PATH_INFO']) or strpos($_SERVER['PATH_INFO'], 'admin', 1)) {
         $site = '';
     } else {
         $site = $_SERVER['PATH_INFO'];
     }
     function statisticOS($useragent)
     {
         $osArray = array('Windows XP' => '=Windows NT 5.1|Windows XP=', 'Windows Vista' => '=Windows NT 6.0|Windows Vista=', 'Windows 7' => '=Windows NT 6.1|Windows 7=', 'Windows 8' => '=Windows NT 6.2|Windows 8=', 'Windows 8.1' => '=Windows NT 6.3|Windows 8.1=', 'Windows 10' => '=Windows NT 10.0|Windows 10=', 'Windows 2000' => '=Windows NT 5.0|Windows 2000=', 'Windows Server 2003\\Windows XP x64' => '=Windows NT 5\\.2|Windows Server 2003|Windows XP x64=', 'Windows NT' => '=Windows NT 4|WinNT4=', 'Windows 98' => '=Windows 98=', 'Windows 95' => '=Windows 95=', 'Android' => '=Android=', 'Linux' => '=Linux|Ubuntu|X11=', 'SunOs' => '=SunOS=', 'iPhone' => '=iPhone=', 'iPad' => '=iPad=', 'Mac OS' => '=Mac OS X=', 'Macintosh' => '=Mac_PowerPC|Macintosh=');
         foreach ($osArray as $os => $regex) {
             if (preg_match($regex, $useragent)) {
                 return $os;
             }
         }
         return 0;
     }
     $os = statisticOS($_SERVER['HTTP_USER_AGENT']);
     function statisticBrowser($useragent)
     {
         if (preg_match("=Firefox/([\\.a-zA-Z0-9]*)=", $useragent, $browser)) {
             return "Firefox " . $browser[1];
         } elseif (preg_match("=MSIE ([0-9]{1,2})\\.[0-9]{1,2}=", $useragent, $browser)) {
             return "Internet Explorer " . $browser[1];
         } elseif (preg_match("=rv:([0-9]{1,2})\\.[0-9]{1,2}=", $useragent, $browser)) {
             return "Internet Explorer " . $browser[1];
         } elseif (preg_match("=Opera[/ ]([0-9\\.]+)=", $useragent, $browser)) {
             return "Opera " . $browser[1];
         } elseif (preg_match("=OPR\\/([0-9\\.]*)=", $useragent, $browser)) {
             $tmp = explode('.', $browser[1]);
             if (count($tmp) > 2) {
                 $browser[1] = $tmp[0] . '.' . $tmp[1];
             }
             return "Opera " . $browser[1];
         } elseif (preg_match("=Edge/([0-9\\.]*)=", $useragent, $browser)) {
             $tmp = explode('.', $browser[1]);
             if (count($tmp) > 2) {
                 $browser[1] = $tmp[0] . '.' . $tmp[1];
             }
             return "Edge " . $browser[1];
         } elseif (preg_match("=Chrome/([0-9\\.]*)=", $useragent, $browser)) {
             $tmp = explode('.', $browser[1]);
             if (count($tmp) > 2) {
                 $browser[1] = $tmp[0] . '.' . $tmp[1];
             }
             return "Chrome " . $browser[1];
         } elseif (preg_match('=Safari/=', $useragent)) {
             if (preg_match('=Version/([\\.0-9]*)=', $useragent, $browser)) {
                 $version = ' ' . $browser[1];
             } else {
                 $version = '';
             }
             return "Safari" . $version;
         } elseif (preg_match("=Konqueror=", $useragent)) {
             return "Konqueror";
         } elseif (preg_match("=Netscape|Navigator=", $useragent)) {
             return "Netscape";
         } else {
             return 0;
         }
     }
     $browser = statisticBrowser($_SERVER['HTTP_USER_AGENT']);
     if (empty($_SERVER["HTTP_REFERER"])) {
         $referer = '';
     } else {
         $referer = $_SERVER["HTTP_REFERER"];
     }
     $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2);
     $statisticMapper = new \Modules\Statistic\Mappers\Statistic();
     $statisticMapper->saveVisit(array('user_id' => $userId, 'site' => $site, 'referer' => $referer, 'os' => $os, 'browser' => $browser, 'ip' => $ip, 'lang' => $lang));
     if ($pluginData['request']->getParam('language')) {
         $_SESSION['language'] = $pluginData['request']->getParam('language');
     }
     if ($pluginData['request']->getParam('ilch_layout')) {
         $_SESSION['layout'] = $pluginData['request']->getParam('ilch_layout');
     }
     $pluginData['translator']->setLocale($pluginData['config']->get('locale'));
     if (!empty($_SESSION['language'])) {
         $pluginData['translator']->setLocale($_SESSION['language']);
     }
 }
Esempio n. 5
0
 /**
  * Tests if the access for a user can be returned.
  */
 public function testHasAccess()
 {
     $group = new Group();
     $group->setId(3);
     $group->setName('Testgroup');
     $user = new User();
     $user->setId(123);
     $user->addGroup($group);
     $dbMock = $this->getMock('Ilch_Database', array('queryCell'));
     $dbMock->expects($this->once())->method('queryCell')->with($this->logicalAnd($this->stringContains('FROM [prefix]_groups_access'), $this->stringContains('INNER JOIN `[prefix]_modules`'), $this->stringContains('user')))->will($this->returnValue('0'));
     Registry::remove('db');
     Registry::set('db', $dbMock);
     $this->assertEquals(0, $user->hasAccess('module_user'));
 }
Esempio n. 6
0
error_reporting(E_ALL);
session_start();
header('Content-Type: text/html; charset=utf-8');
$serverTimeZone = @date_default_timezone_get();
date_default_timezone_set('UTC');
define('VERSION', '2.0.0');
define('ILCH_SERVER', 'http://www.ilch.de/ilch2');
define('SERVER_TIMEZONE', $serverTimeZone);
define('DEFAULT_MODULE', 'page');
define('DEFAULT_LAYOUT', 'index');
/*
 * Path could not be under root.
 */
define('APPLICATION_PATH', __DIR__ . '/application');
define('CONFIG_PATH', APPLICATION_PATH);
$rewriteBaseParts = explode('index.php', str_replace('Index.php', 'index.php', $_SERVER['PHP_SELF']));
$rewriteBaseParts = rtrim(reset($rewriteBaseParts), '/');
define('REWRITE_BASE', $rewriteBaseParts);
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http';
define('BASE_URL', $protocol . '://' . $_SERVER['HTTP_HOST'] . REWRITE_BASE);
require_once APPLICATION_PATH . '/libraries/Ilch/Loader.php';
$loader = new \Ilch\Loader();
$loader->registNamespace('Thumb');
\Ilch\Registry::set('startTime', microtime(true));
try {
    $page = new \Ilch\Page();
    $page->loadCms();
    $page->loadPage();
} catch (Exception $ex) {
    print 'An unexpected error occurred: ' . $ex->getMessage();
}