예제 #1
0
파일: SpotDb.php 프로젝트: niel/spotweb
 function connect()
 {
     SpotTiming::start(__FUNCTION__);
     /* 
      * Erase username/password so it won't show up in any stacktrace
      */
     # SQlite heeft geen username gedefinieerd
     if (isset($this->_dbsettings['user'])) {
         $tmpUser = $this->_dbsettings['user'];
         $this->_dbsettings['user'] = '******';
     }
     # if
     # en ook geen pass
     if (isset($this->_dbsettings['pass'])) {
         $tmpPass = $this->_dbsettings['pass'];
         $this->_dbsettings['pass'] = '******';
     }
     # if
     switch ($this->_dbsettings['engine']) {
         case 'mysql':
             $this->_conn = new dbeng_mysql($this->_dbsettings['host'], $tmpUser, $tmpPass, $this->_dbsettings['dbname']);
             $daoFactory = Dao_Factory::getDAOFactory("mysql");
             break;
         case 'pdo_mysql':
             $this->_conn = new dbeng_pdo_mysql($this->_dbsettings['host'], $tmpUser, $tmpPass, $this->_dbsettings['dbname']);
             $daoFactory = Dao_Factory::getDAOFactory("mysql");
             break;
         case 'pdo_pgsql':
             $this->_conn = new dbeng_pdo_pgsql($this->_dbsettings['host'], $tmpUser, $tmpPass, $this->_dbsettings['dbname']);
             $daoFactory = Dao_Factory::getDAOFactory("postgresql");
             break;
         case 'pdo_sqlite':
             $this->_conn = new dbeng_pdo_sqlite($this->_dbsettings['path']);
             $daoFactory = Dao_Factory::getDAOFactory("sqlite");
             break;
         default:
             throw new Exception('Unknown DB engine specified (' . $this->_dbsettings['engine'] . ', please choose pdo_pgsql, mysql or pdo_mysql');
     }
     # switch
     $daoFactory->setConnection($this->_conn);
     $this->_auditDao = $daoFactory->getAuditDao();
     $this->_blackWhiteListDao = $daoFactory->getBlackWhiteListDao();
     $this->_cacheDao = $daoFactory->getCacheDao();
     $this->_commentDao = $daoFactory->getCommentDao();
     $this->_notificationDao = $daoFactory->getNotificationDao();
     $this->_sessionDao = $daoFactory->getSessionDao();
     $this->_settingDao = $daoFactory->getSettingDao();
     $this->_spotReportDao = $daoFactory->getSpotReportDao();
     $this->_userFilterCountDao = $daoFactory->getUserFilterCountDao();
     $this->_userFilterDao = $daoFactory->getUserFilterDao();
     $this->_userDao = $daoFactory->getUserDao();
     $this->_spotDao = $daoFactory->getSpotdao();
     $this->_spotStateListDao = $daoFactory->getSpotStateListDao();
     $this->_nntpDao = $daoFactory->getNntpDao();
     $this->_conn->connect();
     SpotTiming::stop(__FUNCTION__);
 }
예제 #2
0
 /**
  * Returns the DAO factory used by all of
  * Spotweb
  *
  * @throws DatabaseConnectionException
  * @return Dao_Base_Factory
  */
 public function getDaoFactory()
 {
     SpotTiming::start(__CLASS__ . '::' . __FUNCTION__);
     @(include "dbsettings.inc.php");
     if (empty($dbsettings)) {
         throw new DatabaseConnectionException("No database settings have been entered, please use the 'install.php' wizard to install and configure Spotweb." . PHP_EOL . "If you are upgrading from an earlier version of Spotweb, please consult https://github.com/spotweb/spotweb/wiki/Frequently-asked-questions/ first");
     }
     # if
     /*
      * Store the DB settings so we can retrieve them later, if so desired,
      * we do overwrite the password to make sure it doesn't show up in a
      * stacktrace.
      */
     $this->_dbSettings = $dbsettings;
     $this->_dbSettings['pass'] = '******';
     $this->_dbSettings['user'] = '******';
     $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
     $dbCon->connect($dbsettings['host'], $dbsettings['user'], $dbsettings['pass'], $dbsettings['dbname']);
     $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
     $daoFactory->setConnection($dbCon);
     SpotTiming::stop(__CLASS__ . '::' . __FUNCTION__);
     return $daoFactory;
 }
예제 #3
0
function createSystem()
{
    global $settings;
    global $_testInstall_Ok;
    try {
        /*
         * The settings system is used to create a lot of output,
         * we swallow it all
         */
        ob_start();
        /*
         * Get the schema version and other constants
         */
        require_once "lib/Bootstrap.php";
        $bootstrap = new Bootstrap();
        /*
         * Now create the database
         */
        $dbsettings = $_SESSION['spotsettings']['db'];
        $dbCon = dbeng_abs::getDbFactory($dbsettings['engine']);
        $dbCon->connect($dbsettings['host'], $dbsettings['user'], $dbsettings['pass'], $dbsettings['dbname']);
        $daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']);
        $daoFactory->setConnection($dbCon);
        /*
         * The database must exist before we can get the Service_Settings_Base instance
         */
        $dbStruct = SpotStruct_abs::factory($dbsettings['engine'], $daoFactory->getConnection());
        $dbStruct->updateSchema();
        $spotSettings = $bootstrap->getSettings($daoFactory, false);
        $svcUpgradeBase = new Services_Upgrade_Base($daoFactory, $spotSettings, $dbsettings['engine']);
        /*
         * Create all the different settings (only the default) ones
         */
        $svcUpgradeBase->settings();
        /*
         * Create the users
         */
        $svcUpgradeBase->users();
        /*
         * print all the output as HTML comment for debugging
         */
        $dbCreateOutput = ob_get_contents();
        ob_end_clean();
        /*
         * Now it is time to do something with
         * the information the user has given to us
         */
        /*
         * Update the NNTP settings in the databas
         */
        $spotSettings->set('nntp_nzb', $_SESSION['spotsettings']['nntp']['nzb']);
        $spotSettings->set('nntp_hdr', $_SESSION['spotsettings']['nntp']['hdr']);
        $spotSettings->set('nntp_post', $_SESSION['spotsettings']['nntp']['post']);
        /*
         * Create the given user
         */
        $svcUserRecord = new Services_User_Record($daoFactory, $spotSettings);
        $spotUser = $_SESSION['spotsettings']['adminuser'];
        /*
         * and actually add the user
         */
        $spotUser['userid'] = $svcUserRecord->createUserRecord($spotUser)->getData('userid');
        /*
         * When the new user was created a random password was assigned, 
         * so now have to set the supplied password
         */
        $svcUserRecord->setUserPassword($spotUser);
        # Change the administrators' account password to that of this created user
        $adminUser = $svcUserRecord->getUser(SPOTWEB_ADMIN_USERID);
        $adminUser['newpassword1'] = $spotUser['newpassword1'];
        $svcUserRecord->setUserPassword($adminUser);
        # update the settings with our system type and our admin id
        $spotSettings->set('custom_admin_userid', $spotUser['userid']);
        $spotSettings->set('systemtype', $spotUser['systemtype']);
        # Set the system type
        $svcUpgradeBase->resetSystemType($spotUser['systemtype']);
        /* 
         * Create the necessary database connection information
         */
        $dbConnectionString = '';
        switch ($_SESSION['spotsettings']['db']['engine']) {
            case 'pdo_mysql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_mysql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # mysql
            # mysql
            case 'pdo_pgsql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_pgsql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # pdo_pgsql
        }
        # switch
        # Try to create the dbsettings.inc.php file for the user
        @file_put_contents("dbsettings.inc.php", "<?php" . PHP_EOL . $dbConnectionString);
        $createdDbSettings = file_exists("dbsettings.inc.php");
        showTemplate("step-final.inc.php", array('createdDbSettings' => $createdDbSettings, 'dbCreateOutput' => $dbCreateOutput, 'dbConnectionString' => $dbConnectionString));
    } catch (Exception $x) {
        showTemplate("fatalerror.inc.php", array('x' => $x));
    }
    # exception
}