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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
|
<?php
error_reporting(2147483647);
require_once "lib/SpotClassAutoload.php";
require_once "lib/SpotTranslation.php";
#- main() -#
try {
SpotTranslation::initialize('en_US');
SpotTiming::enable();
SpotTiming::start('total');
SpotTiming::start('settings');
require_once "settings.php";
SpotTiming::stop('settings');
# database object
$db = new SpotDb($settings['db']);
$db->connect();
/*
* Create the setting object as soon as possible because
* we need it for a lot of stuff
*/
$settings = SpotSettings::singleton($db, $settings);
/*
* Disable the timing part as soon as possible because it
* gobbles memory
*/
if (!$settings->get('enable_timing')) {
SpotTiming::disable();
} # if
/*
* 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
# helper functions for passed variables
$req = new SpotReq();
$req->initialize($settings);
$page = $req->getDef('page', 'index');
# Retrieve the users object of the user which is logged on
SpotTiming::start('auth');
$spotUserSystem = new SpotUserSystem($db, $settings);
if ($req->doesExist('apikey')) {
$currentSession = $spotUserSystem->verifyApi($req->getDef('apikey', ''));
} else {
$currentSession = $spotUserSystem->useOrStartSession(false);
} # if
/*
* If three is no user object, we don't have a security system
* either. Without a security system we cannot boot, so fatal
*/
if ($currentSession === false) {
if ($req->doesExist('apikey')) {
$currentSession = $spotUserSystem->useOrStartSession(true);
throw new PermissionDeniedException(SpotSecurity::spotsec_consume_api, 'invalid API key');
} else {
throw new SqlErrorException("Unable to create session");
} # else
} # if
SpotTiming::stop('auth');
/*
* And check if the security groups need updating
*/
if (!$currentSession['security']->securityValid()) {
throw new SecurityNotUpgradedException();
} # if
# User session has been loaded, let's translate the categories
if ($currentSession['user']['prefs']['user_language'] != 'en_US') {
SpotTranslation::initialize($currentSession['user']['prefs']['user_language']);
} # if
SpotCategories::startTranslation();
/*
* Let the form handler know what userid we are using so
* we can make the CSRF cookie be user-bounded
*/
$req->setUserId($currentSession['user']['userid']);
/*
* Only now it is safe to check wether the user is actually alowed
* to authenticate with an API key
*/
if ($req->doesExist('apikey')) {
/*
* To use the Spotweb API we need the actual permission
*/
$currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_consume_api, '');
/*
* but we also need a specific permission, because else things could
* be automated which we simply do not want to be automated
*/
$currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_consume_api, $page);
} # if
SpotTiming::start('renderpage');
switch($page) {
case 'render' : {
$page = new SpotPage_render($db, $settings, $currentSession, $req->getDef('tplname', ''),
Array('search' => $req->getDef('search', $spotUserSystem->getIndexFilter($currentSession['user']['userid'])),
'data' => $req->getDef('data', array()),
'messageid' => $req->getDef('messageid', ''),
'pagenr' => $req->getDef('pagenr', 0),
'perpage' => $req->getDef('perpage', 10),
'sortby' => $req->getDef('sortby', ''),
'sortdir' => $req->getDef('sortdir', '')));
$page->render();
break;
} # render
case 'getspot' : {
if (strpos($_SERVER['HTTP_USER_AGENT'], "SABnzbd+") === 0) {
$page = new SpotPage_getnzb($db, $settings, $currentSession,
Array('messageid' => $req->getDef('messageid', ''),
'action' => $req->getDef('action', 'display'),
'username' => $req->getDef('username', ''),
'apikey' => $req->getDef('apikey', '')));
} else {
$page = new SpotPage_getspot($db, $settings, $currentSession, $req->getDef('messageid', ''));
} # else
$page->render();
break;
} # getspot
case 'getnzb' : {
$page = new SpotPage_getnzb($db, $settings, $currentSession,
Array('messageid' => $req->getDef('messageid', ''),
'action' => $req->getDef('action', 'display'),
'username' => $req->getDef('username', ''),
'apikey' => $req->getDef('apikey', '')));
$page->render();
break;
}
case 'getnzbmobile' : {
$page = new SpotPage_getnzbmobile($db, $settings, $currentSession,
Array('messageid' => $req->getDef('messageid', ''),
'action' => $req->getDef('action', 'display')));
$page->render();
break;
} # getnzbmobile
case 'erasedls' : {
$page = new SpotPage_erasedls($db, $settings, $currentSession);
$page->render();
break;
} # erasedls
case 'catsjson' : {
$page = new SpotPage_catsjson(
$db,
$settings,
$currentSession,
Array('search' => $req->getDef('search', $spotUserSystem->getIndexFilter($currentSession['user']['userid'])),
'subcatz' => $req->getDef('subcatz', '*'),
'category' => $req->getDef('category', '*'),
'rendertype' => $req->getDef('rendertype', 'tree'),
'disallowstrongnot' => $req->getDef('disallowstrongnot', '')));
$page->render();
break;
} # getspot
case 'markallasread' : {
$page = new SpotPage_markallasread($db, $settings, $currentSession);
$page->render();
break;
} # markallasread
case 'getimage' : {
$page = new SpotPage_getimage($db, $settings, $currentSession,
Array('messageid' => $req->getDef('messageid', ''),
'image' => $req->getDef('image', Array())));
$page->render();
break;
}
case 'newznabapi' : {
$page = new SpotPage_newznabapi($db, $settings, $currentSession,
Array('t' => $req->getDef('t', ''),
'messageid' => $req->getDef('id', ''),
'apikey' => $req->getDef('apikey', ''),
'q' => $req->getDef('q', ''),
'limit' => $req->getDef('limit', ''),
'cat' => $req->getDef('cat', ''),
'imdbid' => $req->getDef('imdbid', ''),
'artist' => $req->getDef('artist', ''),
'rid' => $req->getDef('rid', ''),
'season' => $req->getDef('season', ''),
'ep' => $req->getDef('ep', ''),
'o' => $req->getDef('o', ''),
'extended' => $req->getDef('extended', ''),
'maxage' => $req->getDef('maxage', ''),
'offset' => $req->getDef('offset', ''),
'del' => $req->getDef('del', '')
)
);
$page->render();
break;
} # api
case 'rss' : {
$page = new SpotPage_rss($db, $settings, $currentSession,
Array('search' => $req->getDef('search', $spotUserSystem->getIndexFilter($currentSession['user']['userid'])),
'page' => $req->getDef('page', 0),
'sortby' => $req->getDef('sortby', ''),
'sortdir' => $req->getDef('sortdir', ''),
'username' => $req->getDef('username', ''),
'apikey' => $req->getDef('apikey', ''))
);
$page->render();
break;
} # rss
case 'statics' : {
$page = new SpotPage_statics($db, $settings, $currentSession,
Array('type' => $req->getDef('type', '')));
$page->render();
break;
} # statics
case 'createuser' : {
$page = new SpotPage_createuser($db, $settings, $currentSession,
Array('createuserform' => $req->getForm('createuserform')));
$page->render();
break;
} # createuser
case 'editsettings' : {
$page = new SpotPage_editsettings($db, $settings, $currentSession,
Array('editsettingsform' => $req->getForm('editsettingsform')));
$page->render();
break;
} # editsettings
case 'edituserprefs' : {
$page = new SpotPage_edituserprefs($db, $settings, $currentSession,
Array('edituserprefsform' => $req->getForm('edituserprefsform'),
'userid' => $req->getDef('userid', ''),
'data' => $req->getDef('data', array()),
'dialogembedded' => $req->getDef('dialogembedded', 0)));
$page->render();
break;
} # edituserprefs
case 'editsecgroup' : {
$page = new SpotPage_editsecgroup($db, $settings, $currentSession,
Array('editsecgroupform' => $req->getForm('editsecgroupform'),
'groupid' => $req->getDef('groupid', 0)));
$page->render();
break;
} # editsecgroup
case 'editfilter' : {
$page = new SpotPage_editfilter($db, $settings, $currentSession,
Array('editfilterform' => $req->getForm('editfilterform'),
'orderfilterslist' => $req->getDef('orderfilterslist', array()),
'search' => $req->getDef('search', array()),
'sorton' => $req->getDef('sortby', ''),
'sortorder' => $req->getDef('sortdir', ''),
'filterid' => $req->getDef('filterid', 0),
'data' => $req->getDef('data', array())));
$page->render();
break;
} # editfilter
case 'edituser' : {
$page = new SpotPage_edituser($db, $settings, $currentSession,
Array('edituserform' => $req->getForm('edituserform'),
'userid' => $req->getDef('userid', '')));
$page->render();
break;
} # edituser
case 'login' : {
$page = new SpotPage_login($db, $settings, $currentSession,
Array('loginform' => $req->getForm('loginform'),
'data' => $req->getDef('data', array())));
$page->render();
break;
} # login
case 'postcomment' : {
$page = new SpotPage_postcomment($db, $settings, $currentSession,
Array('commentform' => $req->getForm('postcommentform'),
'inreplyto' => $req->getDef('inreplyto', '')));
$page->render();
break;
} # postcomment
case 'postspot' : {
$page = new SpotPage_postspot($db, $settings, $currentSession,
Array('spotform' => $req->getForm('newspotform')));
$page->render();
break;
} # postspot
case 'reportpost' : {
$page = new SpotPage_reportpost($db, $settings, $currentSession,
Array ('reportform' => $req->getForm('postreportform'),
'inreplyto' => $req->getDef('inreplyto', '')));
$page->render();
break;
} # reportpost
case 'versioncheck' : {
$page = new SpotPage_versioncheck($db, $settings, $currentSession);
$page->render();
break;
} # versioncheck
case 'blacklistspotter' : {
$page = new SpotPage_blacklistspotter($db, $settings, $currentSession,
Array ('blform' => $req->getForm('blacklistspotterform')));
$page->render();
break;
} # blacklistspotter
case 'logout' : {
$page = new SpotPage_logout($db, $settings, $currentSession);
$page->render();
break;
} # logout
case 'sabapi' : {
$page = new SpotPage_sabapi($db, $settings, $currentSession);
$page->render();
break;
} # sabapi
case 'nzbhandlerapi' : {
$page = new SpotPage_nzbhandlerapi($db, $settings, $currentSession);
$page->render();
break;
} # nzbhandlerapi
case 'twitteroauth' : {
$page = new SpotPage_twitteroauth($db, $settings, $currentSession,
Array('action' => $req->getDef('action', ''),
'pin' => $req->getDef('pin', '')));
$page->render();
break;
} # twitteroauth
case 'statistics' : {
$page = new SpotPage_statistics($db, $settings, $currentSession,
Array('limit' => $req->getDef('limit', '')));
$page->render();
break;
} # statistics
default : {
SpotTiming::start('renderpage->case-default');
if (@$_SERVER['HTTP_X_PURPOSE'] == 'preview') {
$page = new SpotPage_getimage($db, $settings, $currentSession,
Array('messageid' => $req->getDef('messageid', ''),
'image' => array('type' => 'speeddial')));
} else {
$page = new SpotPage_index($db, $settings, $currentSession,
Array('search' => $req->getDef('search', $spotUserSystem->getIndexFilter($currentSession['user']['userid'])),
'pagenr' => $req->getDef('pagenr', 0),
'sortby' => $req->getDef('sortby', ''),
'sortdir' => $req->getDef('sortdir', ''),
'messageid' => $req->getDef('messageid', ''),
'action' => $req->getDef('action', ''),
'data' => $req->getDef('data', array()))
);
} # if
SpotTiming::stop('renderpage->case-default');
$page->render();
break;
} # default
} # switch
SpotTiming::stop('renderpage');
# timing
SpotTiming::stop('total');
# enable of disable de timer
if (($settings->get('enable_timing')) && (!in_array($req->getDef('page', ''), array('catsjson', 'statics', 'getnzb', 'getnzbmobile', 'markallasread', 'rss', 'newznabapi')))) {
SpotTiming::display();
} # if
}
catch(PermissionDeniedException $x) {
/*
* We try to render a permission denied error using the already created
* renderer first. We do this, so pages which are supposed to output
* XML, can also output their errors using XML.
*
* If no page is initiated just yet, we create an basic renderer object
* to render an error page
*/
if (! ($page instanceof SpotPage_Abs)) {
$page = new SpotPage_render($db, $settings, $currentSession, '', array());
} # if
$page->permissionDenied($x, $page, $req->getHttpReferer());
} # PermissionDeniedException
catch(InvalidOwnSettingsSettingException $x) {
echo "There is an error in your ownsettings.php<br><br>" . PHP_EOL;
echo nl2br($x->getMessage());
} # InvalidOwnSettingsSettingException
catch(OwnsettingsCreatedOutputException $x) {
echo "ownsettings.php or dbsettings.inc.php created output. Please make sure theese files do not contain a PHP closing tag ( ?> ) and no information before the PHP opening tag ( <?php )<br><br>" . PHP_EOL;
echo nl2br($x->getMessage());
} # OwnsettingsCreatedOutputException
catch(SchemaNotUpgradedException $x) {
echo "Database schema has been changed. Please run 'upgrade-db.php' from an console window";
} # SchemaNotUpgradedException
catch(SecurityNotUpgradedException $x) {
echo "Spotweb contains updated security settings. Please run 'upgrade-db.php' from a console window";
} # SecurityNotUpgradedException
catch(SettingsNotUpgradedException $x) {
echo "Spotweb contains updated global settings settings. Please run 'upgrade-db.php' from a console window";
} # SecurityNotUpgradedException
catch(DatabaseConnectionException $x) {
echo "Unable to connect to database: <br>";
echo nl2br($x->getMessage()) . PHP_EOL . '<br>';
echo "<br><br>Please make sure your database server is up and running and your connection parameters are set<br>" . PHP_EOL;
} # DatabaseConnectionException
catch(Exception $x) {
echo 'SpotWeb v' . SPOTWEB_VERSION . ' on PHP v' . PHP_VERSION . ' crashed' . PHP_EOL;
if ((isset($settings) && is_object($settings) && $settings->get('enable_stacktrace')) || (!isset($settings))) {
var_dump($x);
} # if
echo $x->getMessage();
error_log('SpotWeb Exception occured: ' . $x->getMessage());
} # catch
|