1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
<?php
class SpotSettingsUpgrader {
private $_db;
private $_settings;
function __construct(SpotDb $db, SpotSettings $settings) {
$this->_db = $db;
$this->_settings = $settings;
} # ctor
function update() {
/*
* Make sure some versionumbers are always in the db, so
* comparisons always work
*/
$this->setIfNot("settingsversion", "0.00");
$this->setIfNot("securityversion", "0.00");
if ($this->_settings->get('settingsversion') < 0.15) {
$this->remove('system_languages');
} # if
$this->createServerKeys($this->_settings->get('openssl_cnf_path'));
$this->createPasswordSalt();
$this->setupNewsgroups();
$this->createRsaKeys();
$this->createXsrfSecret();
$this->remove('sabnzbdurltpl');
$this->remove('sabnzbdurl');
$this->remove('recompress_nzb');
$this->remove('available_languages');
$this->remove('featureversion');
$this->remove('max_newcount');
$this->remove('action');
$this->remove('submitedit');
$this->setIfNot('cookie_expires', 30);
$this->setIfNot('sendwelcomemail', true);
$this->setIfNot('twitter_consumer_key', 'LRJCpeHASigYtWEmxoNPA');
$this->setIfNot('twitter_consumer_secret', 'QvwZglJNpzAnoVDt40uUyu5dRDlVFVs4ddxfEkYp7A'); // This secret can be shared
$this->setIfNot('boxcar_api_key', 'pOQM9O2AnEWL0RjSoHln');
$this->setIfNot('boxcar_api_secret', '7CwTFfX7KeAKfjM1DJjg5s9qcHm4cwmLkxQgW9fe'); // This secret can be shared
$this->setIfNot('auditlevel', 0); // No auditing
$this->setIfNot('system_languages', array('nl_NL' => 'Nederlands', 'en_US' => 'English'));
$this->setIfNot('retention', 0);
$this->setIfNot('retentiontype', 'fullonly');
$this->setIfNot('deny_robots', true);
$this->setIfNot('nntp_nzb', array('host' => '', 'user' => '', 'pass' => '', 'enc' => false, 'port' => 119, 'buggy' => false));
$this->setIfNot('nntp_hdr', array('host' => '', 'user' => '', 'pass' => '', 'enc' => false, 'port' => 119, 'buggy' => false));
$this->setIfNot('nntp_post', array('host' => '', 'user' => '', 'pass' => '', 'enc' => false, 'port' => 119, 'buggy' => false));
$this->setIfNot('retrieve_newer_than', 0);
$this->setIfNot('retrieve_full', false);
$this->setIfNot('prefetch_image', false);
$this->setIfNot('prefetch_nzb', false);
$this->setIfNot('retrieve_comments', true);
$this->setIfNot('retrieve_full_comments', false);
$this->setIfNot('retrieve_reports', true);
$this->setIfNot('retrieve_increment', 1000);
$this->setIfNot('spot_moderation', 'act');
$this->setIfNot('prepare_statistics', true);
$this->setIfNot('external_blacklist', true);
$this->setIfNot('blacklist_url', 'http://jij.haatmij.nl/spotnet/blacklist.txt');
$this->setIfNot('external_whitelist', true);
$this->setIfNot('whitelist_url', 'http://jij.haatmij.nl/spotnet/whitelist.txt');
$this->setIfNot('enable_timing', false);
$this->setIfNot('enable_stacktrace', true);
$this->setIfNot('systemfrommail', 'spotweb@example.com');
$this->setIfNot('customcss', '');
$this->setIfNot('systemtype', 'public');
$this->setIfNot('newuser_grouplist',
array(
Array('groupid' => 2, 'prio' => 1), // Group ID 2 == Anonymous users, open system
Array('groupid' => 3, 'prio' => 2) // Group ID 3 == Authenticated users
));
$this->setIfNot('nonauthenticated_userid', 1);
$this->setIfNot('custom_admin_userid', 2);
$this->setIfNot('valid_templates',
array(
'we1rdo' => 'we1rdo'
));;
$this->updateSettingsVersion();
} # update()
/*
* Create a setting only if no other value is set
*/
function setIfNot($name, $value) {
if ($this->_settings->exists($name)) {
return ;
} # if
$this->_settings->set($name,$value);
} # setIfNot
/*
* Remove a setting, silently fails if not set
*/
function remove($name) {
$this->_settings->remove($name);
} # remove
/*
* Update the current settingsversion number
*/
function updateSettingsVersion() {
$this->_settings->set('settingsversion', SPOTWEB_SETTINGS_VERSION);
} # updateSettingsVersion
/*
* Create the server private and public keys
*/
function createServerKeys($openSslCnfPath) {
$spotSigning = Services_Signing_Base::newServiceSigning();
$x = $spotSigning->createPrivateKey($openSslCnfPath);
$this->setIfNot('publickey', $x['public']);
$this->setIfNot('privatekey', $x['private']);
} # createServerKeys
/*
* Create the RSA keys
*/
function createRsaKeys() {
/*
* RSA Keys
*
* These are used to validate spots and moderator messages
*/
$rsaKeys = array();
$rsaKeys[2] = array('modulo' => 'ys8WSlqonQMWT8ubG0tAA2Q07P36E+CJmb875wSR1XH7IFhEi0CCwlUzNqBFhC+P',
'exponent' => 'AQAB');
$rsaKeys[3] = array('modulo' => 'uiyChPV23eguLAJNttC/o0nAsxXgdjtvUvidV2JL+hjNzc4Tc/PPo2JdYvsqUsat',
'exponent' => 'AQAB');
$rsaKeys[4] = array('modulo' => '1k6RNDVD6yBYWR6kHmwzmSud7JkNV4SMigBrs+jFgOK5Ldzwl17mKXJhl+su/GR9',
'exponent' => 'AQAB');
$this->setIfNot('rsa_keys', $rsaKeys);
} # createRsaKeys
/*
* Create an xsrf secret
*/
function createXsrfSecret() {
$userSystem = new SpotUserSystem($this->_db, $this->_settings);
$secret = substr($userSystem->generateUniqueId(), 0, 8);
$this->setIfNot('xsrfsecret', $secret);
} # createXsrfSecret
/*
* Create the servers' password salt
*/
function createPasswordSalt() {
$userSystem = new SpotUserSystem($this->_db, $this->_settings);
$salt = $userSystem->generateUniqueId() . $userSystem->generateUniqueId();
$this->setIfNot('pass_salt', $salt);
} # createPasswordSalt
/*
* Define the standard Spotnet groups
*/
function setupNewsgroups() {
$this->setIfNot('hdr_group', 'free.pt');
$this->setIfNot('nzb_group', 'alt.binaries.ftd');
$this->setIfNot('comment_group', 'free.usenet');
$this->setIfNot('report_group', 'free.willey');
} # setupNewsgroups()
/*
* Change a systems' systemtype
*/
function setSystemType($systemType) {
/*
* Depending on the system type, we will have to make some additional
* adjustments.
*/
switch($systemType) {
case 'public' : {
# Public sites should be indexable by a search engine
$this->_settings->set('deny_robots', false);
# Public systems should not show a public visible stack trace either
$this->setIfNot('enable_stacktrace', true);
# Reset the new users' group membership, id 2 is anonymous, 3 = authenticated
$this->_settings->set('newuser_grouplist', array( Array('groupid' => 2, 'prio' => 1), Array('groupid' => 3, 'prio' => 2) ));
/*
* The default anonymous user should be set to 1
*/
$this->_settings->set('nonauthenticated_userid', 1);
break;
} # public
case 'shared' : {
# Shared sites might be indexable by a search engine
$this->_settings->set('deny_robots', false);
# Reset the new users' group membership, id 2 is anonymous, 3 = authenticated, 4 = trusted
$this->_settings->set('newuser_grouplist', array(
Array('groupid' => 2, 'prio' => 1),
Array('groupid' => 3, 'prio' => 2),
Array('groupid' => 4, 'prio' => 3)
));
/*
* The default anonymous user should be set to 1, and this user is only placed
* into the closed system group
*/
$this->_settings->set('nonauthenticated_userid', 1);
break;
} # shared
case 'single' : {
# Private/single owner sites should not be indexable by a search engine
$this->_settings->set('deny_robots', true);
# Reset the new users' group membership, id 2 is anonymous, 3 = authenticated, 4 = trusted, 5 = admin
$this->_settings->set('newuser_grouplist', array(
Array('groupid' => 2, 'prio' => 1),
Array('groupid' => 3, 'prio' => 2),
Array('groupid' => 4, 'prio' => 3),
Array('groupid' => 5, 'prio' => 4)
));
# The default anonymous user should be set to the custom admin use
$this->_settings->set('nonauthenticated_userid', $this->_settings->get('custom_admin_userid'));
break;
} # single
default : throw new Exception("Unknown system type defined: '" . $systemType . "'");
} # switch
# Update the systems' type to our given setting
$this->_settings->set('systemtype', $systemType);
} # setSystemType
} # SpotSettingsUpgrader
|