Ejemplo n.º 1
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
}
Ejemplo n.º 2
0
  * working directory to a directory the script is in
  */
 if (@(!file_exists(getcwd() . '/' . basename($argv[0])))) {
     chdir(dirname(__FILE__));
 }
 # if
 require_once "lib/SpotClassAutoload.php";
 SpotClassAutoload::register();
 require_once "lib/Bootstrap.php";
 /*
  * Create a DAO factory. We cannot use the bootstrapper here,
  * because it validates for a valid settings etc. version.
  */
 $bootstrap = new Bootstrap();
 $daoFactory = $bootstrap->getDaoFactory();
 $settings = $bootstrap->getSettings($daoFactory, true);
 $dbSettings = $bootstrap->getDbSettings();
 /*
  * Try to create the directory, we hardcode it here because
  * it cannot be made configurable in the database anyway
  * and this is just the lazy way out, really
  */
 $daoFactory->setCachePath('./cache/');
 $cacheDao = $daoFactory->getCacheDao();
 if (!is_dir('./cache')) {
     mkdir('./cache', 0777);
 }
 # if
 /*
  * Now try to get all current cache items
  */
Ejemplo n.º 3
0
 /*
  * Make sure we are not run from the server, an db upgrade can take too much time and
  * will easily be aborted by either a database, apache or browser timeout
  */
 SpotCommandline::initialize(array('reset-groupmembership', 'reset-securitygroups', 'reset-filters'), array('reset-groupmembership' => false, 'reset-securitygroups' => false, 'reset-filters' => false, 'set-systemtype' => false, 'reset-password' => false, 'mass-userprefchange' => false));
 if (!SpotCommandline::isCommandline()) {
     die("upgrade-db.php can only be run from the console, it cannot be run from the web browser");
 }
 # if
 /*
  * Create a DAO factory. We cannot use the bootstrapper here,
  * because it validates for a valid settings etc. version.
  */
 $bootstrap = new Bootstrap();
 $daoFactory = $bootstrap->getDaoFactory();
 $settings = $bootstrap->getSettings($daoFactory, false);
 $dbSettings = $bootstrap->getDbSettings();
 /*
  * And actually start updating or creating the schema and settings
  */
 echo "Updating schema..(" . $dbSettings['engine'] . ")" . PHP_EOL;
 $svcUpgradeBase = new Services_Upgrade_Base($daoFactory, $settings, $dbSettings['engine']);
 $svcUpgradeBase->database();
 echo "Schema update done" . PHP_EOL;
 echo "Updating settings" . PHP_EOL;
 $svcUpgradeBase->settings();
 $svcUpgradeBase->usenetState();
 echo "Settings update done" . PHP_EOL;
 $svcUpgradeBase->users($settings);
 echo "Updating users" . PHP_EOL;
 echo "Users' update done" . PHP_EOL;