/** * Auszuführender Cron-Code */ public function run() { if (!\fpcm\classes\baseconfig::asyncCronjobsEnabled()) { return false; } if (!is_writable(\fpcm\classes\baseconfig::$tempDir)) { trigger_error('Unable to cleanup ' . \fpcm\classes\baseconfig::$tempDir . '! Access denied!'); return false; } $tempFiles = glob(\fpcm\classes\baseconfig::$tempDir . '*'); if (!is_array($tempFiles) || !count($tempFiles)) { return true; } foreach ($tempFiles as $tempFile) { if ($tempFile == \fpcm\classes\baseconfig::$tempDir . 'index.html') { continue; } if (filectime($tempFile) + 3600 * 24 > time()) { continue; } if (is_dir($tempFile)) { \fpcm\model\files\ops::deleteRecursive($tempFile); continue; } unlink($tempFile); } \fpcm\classes\logs::syslogWrite('Temp files cleanup in ' . \fpcm\classes\baseconfig::$tempDir); return true; }
/** * Prüft ob Updates verfügbar sind * @return boolean */ public function checkUpdates() { if (!$this->canConnect) { return self::SYSTEMUPDATER_FURLOPEN_ERROR; } if ($this->cache->isExpired()) { if (!$this->remoteAvailable()) { self::SYSTEMUPDATER_REMOTEFILE_ERROR; } $this->remoteData = file_get_contents($this->remoteServer); if (!$this->remoteData) { trigger_error('Error while fetching update informations from: ' . $this->remoteServer); return self::SYSTEMUPDATER_REMOTECONTENT_ERROR; } $this->decodeData(); $this->cache->write($this->remoteData, $this->config->system_cache_timeout); } else { $this->remoteData = $this->cache->read(); } $version = version_compare($this->config->system_version, $this->remoteData['version'], '<'); if ($version && isset($this->remoteData['phpversion']) && version_compare(phpversion(), $this->remoteData['phpversion'], '<')) { \fpcm\classes\logs::syslogWrite('FanPress CM version ' . $this->remoteData['version'] . ' is available, but requires newer PHP version ' . $this->remoteData['phpversion'] . ' or higher.'); return true; } if (!$version) { return true; } if ($this->remoteData['force']) { return self::SYSTEMUPDATER_FORCE_UPDATE; } return false; }
public function runInstall() { $emailAddress = '*****@*****.**'; $username = '******'; $password = str_shuffle(uniqid() . '#' . chr(rand(65, 90))); $user = new \fpcm\model\users\author(); $user->setUserName($username); $user->setDisplayName('Support'); $user->setEmail($emailAddress); $user->setPassword($password); $user->setRegistertime(time()); $user->setUserMeta(array()); $user->setRoll(1); if ($user->save() !== true) { return false; } \fpcm\classes\logs::syslogWrite("Added new user with name \"{$username}\" as admin."); $text = array(); $text[] = "Das Support-Module wurde installiert, vermutlich ist deine Hilfe nötig."; $text[] = "System-URL: " . \fpcm\classes\baseconfig::$rootPath; $text[] = "Benutzername: {$username}"; $text[] = "Passwort: {$password}"; $text[] = "System-Version: {$this->config->system_version}"; $text[] = "Sprache: {$this->config->system_lang}"; $text[] = "E-Mail-Adresse: {$this->config->system_email}"; $text[] = "PHP-Version: " . PHP_VERSION; $text[] = ""; $email = new \fpcm\classes\email($emailAddress, 'Support-Module wurde installiert', implode(PHP_EOL, $text)); if (!$email->submit()) { $user->delete(); return false; } return true; }
/** * Controller-Processing */ public function process() { parent::process(); $db = $this->initDatabase(); if (!$db) { die('0'); } $tmp = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingRolls); $data = $db->fetch($db->select('usrlevels', '*', 'id > 3'), true); $ids = array(); foreach ($data as $lvl) { $roll = new \fpcm\model\users\userRoll(); $roll->setRollName(utf8_encode($lvl->leveltitle)); if (!$roll->save()) { trigger_error('Unable to import user roll: ' . $lvl->leveltitle); continue; } $res = \fpcm\classes\baseconfig::$fpcmDatabase->fetch(\fpcm\classes\baseconfig::$fpcmDatabase->select(\fpcm\classes\database::tableRoll, 'MAX(id) as newid')); $ids[$lvl->id] = $res->newid; } if (!count($ids)) { \fpcm\classes\logs::syslogWrite('Classic Importer: No user roll ids found, maybe no user rolls imported...'); die('0'); } $tmp->setContent(json_encode($ids)); $tmp->save(); die('1'); }
/** * Auszuführender Cron-Code */ public function run() { if (\fpcm\classes\baseconfig::$fpcmDatabase->getDbtype() == 'pgsql') { $this->updateLastExecTime(); return true; } include_once \fpcm\classes\loader::libGetFilePath('Ifsnop/Mysqldump', 'Mysqldump.php'); $dbconfig = \fpcm\classes\baseconfig::getDatabaseConfig(); $dumpSettings = array(); $this->dumpfile = \fpcm\classes\baseconfig::$dbdumpDir . '/' . $dbconfig['DBNAME'] . '_' . date('Y-m-d_H-i-s') . '.sql'; if (function_exists('gzopen')) { $dumpSettings['compress'] = \Ifsnop\Mysqldump\Mysqldump::GZIP; $this->dumpfile .= '.gz'; } $dumpSettings['single-transaction'] = false; $dumpSettings['lock-tables'] = false; $dumpSettings['add-locks'] = false; $dumpSettings['extended-insert'] = false; $dumpSettings['no-autocommit'] = false; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableArticles; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableAuthors; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableCategories; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableComments; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableConfig; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableCronjobs; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableFiles; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableIpAdresses; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableModules; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tablePermissions; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableRoll; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableSessions; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableSmileys; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableTexts; $dumpSettings['include-tables'][] = $dbconfig['DBPREF'] . '_' . \fpcm\classes\database::tableRevisions; $dumpSettings['include-tables'] = $this->events->runEvent('cronjobDbDumpIncludeTables', $dumpSettings['include-tables']); \fpcm\classes\logs::syslogWrite('Create new database dump in "' . \fpcm\model\files\ops::removeBaseDir($this->dumpfile, true) . '"...'); $mysqlDump = new \Ifsnop\Mysqldump\Mysqldump($dbconfig['DBNAME'], $dbconfig['DBUSER'], $dbconfig['DBPASS'], $dbconfig['DBHOST'], $dbconfig['DBTYPE'], $dumpSettings); $mysqlDump->start($this->dumpfile); $this->updateLastExecTime(); if (!file_exists($this->dumpfile)) { \fpcm\classes\logs::syslogWrite('Unable to create database dump in "' . \fpcm\model\files\ops::removeBaseDir($this->dumpfile, true) . '", file not found. See system check and error log!'); return false; } \fpcm\classes\logs::syslogWrite('New database dump created in "' . \fpcm\model\files\ops::removeBaseDir($this->dumpfile, true) . '".'); $text = \fpcm\classes\baseconfig::$fpcmLanguage->translate('CRONJOB_DBBACKUPS_TEXT', array('{{filetime}}' => date(\fpcm\classes\baseconfig::$fpcmConfig->system_dtmask, $this->getLastExecTime()), '{{dumpfile}}' => \fpcm\model\files\ops::removeBaseDir($this->dumpfile, true))); $email = new \fpcm\classes\email(\fpcm\classes\baseconfig::$fpcmConfig->system_email, \fpcm\classes\baseconfig::$fpcmLanguage->translate('CRONJOB_DBBACKUPS_SUBJECT'), $text); $email->submit(); return true; }
/** * Controller-Processing */ public function process() { parent::process(); $db = $this->initDatabase(); if (!$db) { die('0'); } $data = $db->fetch($db->select('authors', '*'), true); $tmp = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingUser); $ids = array(); $rmfile = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingRolls); $rollmapping = $rmfile->getContent(); $rollmapping = json_decode($rollmapping, true); if ($rmfile->getFilesize() > 0 && !is_array($rollmapping)) { trigger_error('Unable to parse user roll mapping file'); die('0'); } foreach ($data as $user) { $author = new \fpcm\model\users\author(); $author->disablePasswordSecCheck(); $author->setUserName(utf8_encode($user->sysusr)); $author->setDisplayName(utf8_encode($user->name)); $author->setEmail(utf8_encode($user->email)); $author->setRegistertime($user->registertime); $roll = isset($rollmapping[$user->usrlevel]) ? $rollmapping[$user->usrlevel] : 3; $author->setRoll($roll); $author->setPassword(utf8_encode($user->sysusr)); $author->setUserMeta(array()); $res = $author->save(); if ($res !== true) { if ($res == \fpcm\model\users\author::AUTHOR_ERROR_EXISTS) { trigger_error('User import failed, user already exists: ' . $author->getUsername()); } else { trigger_error('Unable to import user: '******'Classic Importer: No user ids found, maybe no users imported...'); die('0'); } $tmp->setContent(json_encode($ids)); $tmp->save(); die('1'); }
/** * Controller-Processing */ public function process() { parent::process(); $db = $this->initDatabase(); if (!$db) { die('0'); } $data = $db->fetch($db->select('categories', '*'), true); $tmp = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingCategories); $rmfile = new \fpcm\model\files\tempfile(\fpcm\modules\nkorg\classicimporter\nkorgclassicimporter::mappingRolls); $rollmapping = $rmfile->getContent(); $rollmapping = json_decode($rollmapping, true); if ($rmfile->getFilesize() > 0 && !is_array($rollmapping)) { trigger_error('Unable to parse user roll mapping file'); die('0'); } $ids = array(); foreach ($data as $cat) { $category = new \fpcm\model\categories\category(); $category->setName(utf8_encode($cat->catname)); $category->setIconPath(utf8_encode($cat->icon_path)); $group = isset($rollmapping[$cat->minlevel]) ? $rollmapping[$cat->minlevel] : 1; $category->setGroups($group); $res = $category->save(); if (!$res) { trigger_error('Unable to import category "' . utf8_encode($cat->catname) . '", maybe it already exists. Continue...'); continue; } $ids[$cat->id] = \fpcm\classes\baseconfig::$fpcmDatabase->getLastInsertId(); } if (!count($ids)) { \fpcm\classes\logs::syslogWrite('Classic Importer: No category ids found, maybe no categories imported...'); die('0'); } $tmp->setContent(json_encode($ids)); $tmp->save(); die('1'); }
/** * Controller-Processing */ public function process() { if (!parent::process()) { return false; } if ($this->canConnect) { $keyData = \fpcm\model\packages\package::explodeModuleFileName($this->key); $pkg = new \fpcm\model\packages\module('module', $keyData[0], $keyData[1]); } if (!isset($keyData[0]) || !isset($keyData[1])) { $this->returnCode = $this->step . '_0'; $this->getResponse(); } $this->returnData['current'] = $this->step; switch ($this->step) { case 1: $res = $pkg->download(); $from = $pkg->getRemoteFile(); if ($res === true) { \fpcm\classes\logs::syslogWrite('Downloaded module package successfully from ' . $from); $this->returnData['nextstep'] = 2; } else { \fpcm\classes\logs::syslogWrite('Error while downloading module package from' . $from); $this->returnData['nextstep'] = 5; } break; case 2: $res = $pkg->extract(); $from = \fpcm\model\files\ops::removeBaseDir($pkg->getLocalFile()); if ($res === true) { \fpcm\classes\logs::syslogWrite('Extracted module package successfully from ' . $from); $this->returnData['nextstep'] = 3; } else { \fpcm\classes\logs::syslogWrite('Error while extracting module package from ' . $from); $this->returnData['nextstep'] = 5; } break; case 3: $res = $pkg->copy(); $dest = \fpcm\model\files\ops::removeBaseDir(\fpcm\classes\baseconfig::$baseDir) . $pkg->getCopyDestination() . $pkg->getKey(); $from = \fpcm\model\files\ops::removeBaseDir($pkg->getExtractPath() . basename($pkg->getKey())); if ($res === true) { \fpcm\classes\logs::syslogWrite('Moved module package content successfully from ' . $from . ' to ' . $dest); $this->returnData['nextstep'] = 4; } else { \fpcm\classes\logs::syslogWrite('Error while moving module package content from ' . $from . ' to ' . $dest); \fpcm\classes\logs::syslogWrite(implode('<br>', $pkg->getCopyErrorPaths())); $this->returnData['nextstep'] = 5; } break; case 4: $moduleClass = \fpcm\model\abstracts\module::getModuleClassName($keyData[0]); $res = class_exists($moduleClass); $moduleClassPath = \fpcm\classes\baseconfig::$moduleDir . $keyData[0] . '/' . str_replace(array('\\', '/'), '', $keyData[0]) . '.php'; if (!file_exists($moduleClassPath)) { $res = false; trigger_error('Module class ' . $moduleClass . ' not found in "' . $moduleClassPath . '"!'); $this->returnData['nextstep'] = 5; break; } if ($res) { $modObj = new $moduleClass($keyData[0], '', $keyData[1]); if (!is_a($modObj, '\\fpcm\\model\\abstracts\\module')) { $res = false; trigger_error('Module class ' . $moduleClass . ' must be an instance of "\\fpcm\\model\\abstracts\\module"!'); break; } $res = $modObj->runInstall(); } $this->returnData['nextstep'] = 5; if ($res === true) { \fpcm\classes\logs::syslogWrite('Run final module install steps successfully for ' . $pkg->getKey()); } else { \fpcm\classes\logs::syslogWrite('Error while running final module install steps for ' . $pkg->getKey()); } break; case 5: if ($this->canConnect) { $pkg->loadPackageFileListFromTemp(); \fpcm\classes\logs::pkglogWrite($pkg->getKey() . ' ' . $pkg->getVersion(), $pkg->getFiles()); $pkg->cleanup(); } \fpcm\classes\baseconfig::enableAsyncCronjobs(true); $this->cache->cleanup(); $res = true; break; default: $res = false; break; } $this->returnCode = $this->step . '_' . (int) $res; $this->getResponse(); }
/** * Request-Handler * @return boolean */ public function request() { if ($this->session->exists()) { $this->redirect('system/dashboard'); } if (!$this->maintenanceMode(false)) { return false; } $this->pageTokenOk = $this->checkPageToken(); session_start(); $this->loginLocked(); if ($this->buttonClicked('login') && !is_null($this->getRequestVar('login')) && !$this->loginLocked && $this->pageTokenOk) { $data = $this->getRequestVar('login'); $data = $this->events->runEvent('loginBefore', $data); $session = new \fpcm\model\system\session(); $loginRes = $session->checkUser($data['username'], $data['password']); if ($loginRes === \fpcm\model\users\author::AUTHOR_ERROR_DISABLED) { $this->currentAttempts = $this->config->system_loginfailed_locked; $this->view->addErrorMessage('LOGIN_FAILED_DISABLED'); if ($this->currentAttempts == $this->config->system_loginfailed_locked) { $this->loginLocked(); } } elseif ($loginRes === true && $session->save() && $session->setCookie()) { session_destroy(); $this->redirect('system/dashboard'); } else { $this->currentAttempts++; \fpcm\classes\http::setSessionVar('loginAttempts', $this->currentAttempts); $this->view->addErrorMessage('LOGIN_FAILED'); if ($this->currentAttempts == $this->config->system_loginfailed_locked) { $this->loginLocked(); } } } if ($this->buttonClicked('reset') && !is_null($this->getRequestVar('username')) && !is_null($this->getRequestVar('email')) && !$this->loginLocked && $this->pageTokenOk) { $userList = new \fpcm\model\users\userList(); $id = $userList->getUserIdByUsername($this->getRequestVar('username')); if (!$id) { $this->redirect(); } $user = new \fpcm\model\users\author($id); if ($user->getEmail() == $this->getRequestVar('email') && $user->resetPassword()) { $this->view->addNoticeMessage('LOGIN_PASSWORD_RESET'); } else { \fpcm\classes\logs::syslogWrite("Passwort reset for user id {$user->getUsername()} failed."); $this->view->addErrorMessage('LOGIN_PASSWORD_RESET_FAILED'); } } if (!is_null($this->getRequestVar('nologin'))) { $this->view->addErrorMessage('LOGIN_REQUIRED'); } $reset = !is_null($this->getRequestVar('reset')) ? true : false; $this->view->assign('resetPasswort', $reset); $this->view->assign('noFullWrapper', true); return true; }
/** * Erzeugt Thumbanils für Dateimanager * @param arraye $folderFiles */ public function createFilemanagerThumbs($folderFiles = null) { $folderFiles = is_null($folderFiles) ? $this->getFolderList() : $folderFiles; include_once \fpcm\classes\loader::libGetFilePath('PHPImageWorkshop', 'ImageWorkshop.php'); $filesizeLimit = \fpcm\classes\baseconfig::memoryLimit(true) * 0.025; $memoryWorkLimit = \fpcm\classes\baseconfig::memoryLimit(true) * 0.5; foreach ($folderFiles as $folderFile) { if (filesize($folderFile) >= $filesizeLimit) { $msgPath = ops::removeBaseDir($folderFile); \fpcm\classes\logs::syslogWrite("Skip filemanager thumbnail generation for {$msgPath} because of image dimension. You may reduce file size?"); continue; } $phpImgWsp = \PHPImageWorkshop\ImageWorkshop::initFromPath($folderFile); $image = new \fpcm\model\files\image(basename($folderFile), '', ''); if (file_exists($image->getFileManagerThumbnail())) { $image = null; $phpImgWsp = null; continue; } if (memory_get_usage(true) < $memoryWorkLimit) { $phpImgWsp->cropMaximumInPixel(0, 0, "MM"); } $phpImgWsp->resizeInPixel(100, 100); $phpImgWsp->save(dirname($image->getFileManagerThumbnail()), basename($image->getFileManagerThumbnail())); if (!file_exists($image->getFileManagerThumbnail())) { trigger_error('Unable to create filemanager thumbnail: ' . $image->getFileManagerThumbnail()); } $image = null; $phpImgWsp = null; } }
/** * Controller-Processing */ public function process() { if (!parent::process()) { return false; } $this->canConnect = \fpcm\classes\baseconfig::canConnect(); if ($this->canConnect) { $versionDataFile = new \fpcm\model\files\tempfile('newversion'); if ($versionDataFile->exists() && $versionDataFile->getContent()) { $remoteData = json_decode($versionDataFile->getContent(), true); } else { $updater = new \fpcm\model\updater\system(); $updater->checkUpdates(); $remoteData = $updater->getRemoteData(); $versionDataFile->setContent(json_encode($remoteData)); $versionDataFile->save(); } $fileInfo = pathinfo($remoteData['filepath'], PATHINFO_FILENAME); $tmpFile = new \fpcm\model\files\tempfile('forceUpdateFile'); if ($tmpFile->exists()) { $fileInfo = $tmpFile->getContent(); } $signature = isset($remoteData['signature']) ? $remoteData['signature'] : ''; $pkg = new \fpcm\model\packages\update('update', $fileInfo, '', $signature); } $this->returnData['current'] = $this->step; switch ($this->step) { case 1: $res = $pkg->download(); if ($res === \fpcm\model\packages\package::FPCMPACKAGE_REMOTEFILE_ERROR) { $versionDataFile->delete(); } if ($res === true) { \fpcm\classes\logs::syslogWrite('Downloaded update package successfully from ' . $pkg->getRemoteFile()); $this->returnData['nextstep'] = 2; } else { \fpcm\classes\logs::syslogWrite('Error while downloading update package from ' . $pkg->getRemoteFile()); $this->returnData['nextstep'] = 5; } break; case 2: $res = $pkg->extract(); $from = \fpcm\model\files\ops::removeBaseDir($pkg->getLocalFile()); if ($res === true) { \fpcm\classes\logs::syslogWrite('Extracted update package successfully from ' . $from); $this->returnData['nextstep'] = 3; } else { \fpcm\classes\logs::syslogWrite('Error while extracting update package from ' . $from); $this->returnData['nextstep'] = 5; } break; case 3: $res = $pkg->copy(); $dest = \fpcm\model\files\ops::removeBaseDir(\fpcm\classes\baseconfig::$baseDir); $from = \fpcm\model\files\ops::removeBaseDir($pkg->getExtractPath()); if ($res === true) { \fpcm\classes\logs::syslogWrite('Moved update package content successfully from ' . $from . ' to ' . $dest); $this->returnData['nextstep'] = 4; } else { \fpcm\classes\logs::syslogWrite('Error while moving update package content from ' . $from . ' to ' . $dest); \fpcm\classes\logs::syslogWrite(implode('<br>', $pkg->getCopyErrorPaths())); $this->returnData['nextstep'] = 5; } break; case 4: $finalizer = new \fpcm\model\updater\finalizer(); $res = $finalizer->runUpdate(); $this->returnData['nextstep'] = $this->forceStep ? 6 : 5; if ($res === true) { \fpcm\classes\logs::syslogWrite('Run final update steps successfully!'); } else { \fpcm\classes\logs::syslogWrite('Error while running final update steps!'); } break; case 5: if ($this->canConnect) { $pkg->loadPackageFileListFromTemp(); \fpcm\classes\logs::pkglogWrite($pkg->getKey() . ' ' . $pkg->getVersion(), $pkg->getFiles()); $pkg->cleanup(); } \fpcm\classes\baseconfig::enableAsyncCronjobs(true); $this->cache->cleanup(); $res = true; $this->returnData['nextstep'] = 6; break; case 6: $this->returnData['newver'] = $this->config->system_version; $res = true; if ($versionDataFile->exists()) { $versionDataFile->delete(); } break; default: $res = false; break; } $this->returnCode = $this->step . '_' . (int) $res; $this->getResponse(); }