Skip to content

Commit

Permalink
Further steps in the removal of dependency on SpotsOveriew and SpotDb
Browse files Browse the repository at this point in the history
  • Loading branch information
spotweb committed Jul 3, 2012
1 parent 1a74065 commit 869d4a9
Show file tree
Hide file tree
Showing 55 changed files with 3,184 additions and 2,991 deletions.
886 changes: 419 additions & 467 deletions index.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function performAndPrintTests() {
<?php require_once "lib/services/Signing/Services_Signing_Base.php";
require_once "lib/services/Signing/Services_Signing_Php.php";
require_once "lib/services/Signing/Services_Signing_Openssl.php";
$spotSigning = Services_Signing_Base::newServiceSigning();
$spotSigning = Services_Signing_Base::factory();
$privKey = $spotSigning->createPrivateKey($settings['openssl_cnf_path']);

/* We need either one of those 3 extensions, so set the error flag manually */
Expand Down Expand Up @@ -517,7 +517,7 @@ function createSystem() {
/*
* Create a private/public key pair for this user
*/
$spotSigning = Services_Signing_Base::newServiceSigning();
$spotSigning = Services_Signing_Base::factory();
$userKey = $spotSigning->createPrivateKey($spotSettings->get('openssl_cnf_path'));
$spotUser['publickey'] = $userKey['public'];
$spotUser['privatekey'] = $userKey['private'];
Expand Down
168 changes: 168 additions & 0 deletions lib/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php
define('SPOTWEB_SETTINGS_VERSION', '0.24');
define('SPOTWEB_SECURITY_VERSION', '0.29');
define('SPOTDB_SCHEMA_VERSION', '0.58');
define('SPOTWEB_VERSION', '0.' . (SPOTDB_SCHEMA_VERSION * 100) . '.' . (SPOTWEB_SETTINGS_VERSION * 100) . '.' . (SPOTWEB_SECURITY_VERSION * 100));

/*
* Spotweb bootstrapping code.
*
* This class will initialize the registry and so other
* related stuff. Is required for all Spotweb related code.
*
*/

class Bootstrap {
static private $_dbSettings = null;

/*
* Boot up the Spotweb system
*/
public function boot() {
/*
* If we are run from another directory, try to change the current
* working directory to a directory the script is in
*/
if (@!file_exists(getcwd() . '/' . basename($argv[0]))) {
chdir(dirname(__FILE__));
} # if

$daoFactory = $this->getDaoFactory();
$settings = $this->getSettings($daoFactory);
$spotReq = $this->getSpotReq($settings);

/*
* Run the validation of the most basic systems
* in Spotweb
*/
$this->validate($settings);

/*
* Disable the timing part as soon as possible because it
* gobbles memory
*/
if (!$settings->get('enable_timing')) {
SpotTiming::disable();
} # if


return array($settings, $daoFactory, $spotReq);
} # boot


/*
* Returns the DAO factory used by all of
* Spotweb
*/
private function getDaoFactory() {
require "dbsettings.inc.php";

$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);

return $daoFactory;
} # getDaoFactory

/*
* Returns a sort of pre-flight check to see if
* everything is setup the way we like.
*/
private function validate(SpotSettings $settings) {
/*
* The basics has been setup, lets check if the schema needs
* updating
*/
if (!$settings->schemaValid()) {
throw new SchemaNotUpgradedException();
} # if

/*
* Does our global setting table need updating?
*/
if (!$settings->settingsValid()) {
throw new SettingsNotUpgradedException();
} # if

/*
* Because users are asked to modify ownsettings.php themselves, it is
* possible they create a mistake and accidentally create output from it.
*
* This output breaks a lot of stuff like download integration, image generation
* and more.
*
* We try to check if any output has been submitted, and if so, we refuse
* to continue to prevent all sorts of confusing bug reports
*/
if ((headers_sent()) || ((int) ob_get_length() > 0)) {
throw new OwnsettingsCreatedOutputException();
} # if
} # validate

/*
* Bootup the settings system
*/
private function getSettings(Dao_Factory $daoFactory) {
require_once "settings.php";
return SpotSettings::singleton($daoFactory->getSettingDao(), $settings);
} # getSettings

/*
* Initializes the NNTP access
*/
static public function createNntpEngine($type) {
/*
* Retrieve the NNTP header settings we can validate those
*/
$settings = Registry::get('settings');
$settings_nntp_hdr = $settings->get('nntp_hdr');

/*
* Make sure we have a valid NNTP configuration
*/
if (empty($settings_nntp_hdr['host'])) {
throw new MissingNntpConfigurationException();
} # if


switch ($type) {
case 'hdr' : return new Service_Nntp_Engine($settings_nntp_hdr); break;
case 'nzb' : {
$settings_nntp_bin = $settings->get('nntp_nzb');
if (empty($settings_nntp_nzb['host'])) {
return Registry::get('nntp_hdr');
} else {
return new Service_Nntp_Engine($settings_nntp_nzb);
} # else
} # nzb

case 'post' : {
$settings_nntp_post = $settings->get('nntp_post');
if (empty($settings_nntp_post['host'])) {
return Registry::get('nntp_hdr');
} else {
return new Service_Nntp_Engine($settings_nntp_post);
} # else
} # post

default : throw new Exception("Unknown NNTP type engine (" . $type . ") for registry creation");
} # switch
} # initNntpAccess

/*
* Instantiate an Request object
*/
private function getSpotReq(SpotSettings $settings) {
$req = new SpotReq();
$req->initialize($settings);

return $req;
} # getSpotReq

} # Bootstrap

38 changes: 19 additions & 19 deletions lib/SpotAudit.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php
class SpotAudit {
private $_db;
private $_user;
private $_settings;
private $_ipaddr;

function __construct(SpotDb $db, SpotSettings $settings, array $user, $ipaddr) {
$this->_db = $db;
$this->_user = $user;
$this->_settings = $settings;
$this->_ipaddr = $ipaddr;
} # ctor

function audit($perm, $objectid, $allowed) {
$this->_db->addAuditEntry($this->_user['userid'], $perm, $objectid, $allowed, $this->_ipaddr);
} # audit

} # class SpotAudit
<?php
class SpotAudit {
private $_auditDao;
private $_user;
private $_settings;
private $_ipaddr;

function __construct(Dao_Audit $auditDao, SpotSettings $settings, array $user, $ipaddr) {
$this->_auditDao = $auditDao;
$this->_user = $user;
$this->_settings = $settings;
$this->_ipaddr = $ipaddr;
} # ctor

function audit($perm, $objectid, $allowed) {
$this->_auditDao->addAuditEntry($this->_user['userid'], $perm, $objectid, $allowed, $this->_ipaddr);
} # audit

} # class SpotAudit
5 changes: 5 additions & 0 deletions lib/SpotClassAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function __autoload($class_name) {
return ;
} # if

if ($class_name == 'Registry') {
require_once "vendor/Lim_Registry/Registry.php";
return ;
} # if

require_once 'lib/' . $class_name . '.php';
} # default
} # switch
Expand Down
41 changes: 14 additions & 27 deletions lib/SpotDb.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
define('SPOTDB_SCHEMA_VERSION', '0.58');

class SpotDb {
public $_auditDao;
Expand All @@ -17,31 +16,18 @@ class SpotDb {
public $_spotStateListDao;
public $_nntpConfigDao;

private $_dbsettings = null;
private $_conn = null;
private $_daoFactory;

/*
* Constants used for updating the black/whitelist
*/
const spotterlist_Black = 1;
const spotterlist_White = 2;

function __construct($db) {
$this->_dbsettings = $db;
} # __ctor


/*
* Open connectie naar de database (basically factory), de 'engine' wordt uit de
* settings gehaald die mee worden gegeven in de ctor.
*/
function connect() {
SpotTiming::start(__FUNCTION__);

$dbCon = dbeng_abs::getDbFactory($this->_dbsettings['engine']);;
$daoFactory = Dao_Factory::getDAOFactory($this->_dbsettings['engine']);
function __construct(Dao_Factory $daoFactory) {
$this->_daoFactory = $daoFactory;

$daoFactory->setConnection($dbCon);
$this->_auditDao = $daoFactory->getAuditDao();
$this->_blackWhiteListDao = $daoFactory->getBlackWhiteListDao();
$this->_cacheDao = $daoFactory->getCacheDao();
Expand All @@ -50,31 +36,32 @@ function connect() {
$this->_sessionDao = $daoFactory->getSessionDao();
$this->_settingDao = $daoFactory->getSettingDao();
$this->_spotReportDao = $daoFactory->getSpotReportDao();
$this->_userFilterCountDao = $daoFactory->getUserFilterCountDao();
$this->_userFilterDao = $daoFactory->getUserFilterDao();
$this->_userFilterCountDao = $daoFactory->getUserFilterCountDao();
$this->_userDao = $daoFactory->getUserDao();
$this->_spotDao = $daoFactory->getSpotdao();
$this->_spotDao = $daoFactory->getSpotDao();
$this->_spotStateListDao = $daoFactory->getSpotStateListDao();
$this->_nntpConfigDao = $daoFactory->getNntpConfigDao();
} # __ctor


$dbCon->connect($this->_dbsettings['host'],
$this->_dbsettings['user'],
$this->_dbsettings['pass'],
$this->_dbsettings['dbname']);
$this->_conn = $dbCon;
SpotTiming::stop(__FUNCTION__);
/*
* Open connectie naar de database (basically factory), de 'engine' wordt uit de
* settings gehaald die mee worden gegeven in de ctor.
*/
function connect() {
} # connect

/*
* Geeft het database connectie object terug
*/
function getDbHandle() {
return $this->_conn;
return $this->_daoFactory->getConnection();
} # getDbHandle


function safe($x) {
return $this->_conn->safe($x);
return $this->_daoFactory->getConnection()->safe($x);
}

/* --------------------------- */
Expand Down
Loading

0 comments on commit 869d4a9

Please sign in to comment.