diff options
-rw-r--r-- | apps/bookmarks/addBm.php | 7 | ||||
-rw-r--r-- | apps/bookmarks/index.php | 7 | ||||
-rw-r--r-- | apps/calendar/export.php | 7 | ||||
-rw-r--r-- | apps/calendar/index.php | 5 | ||||
-rw-r--r-- | apps/contacts/index.php | 5 | ||||
-rw-r--r-- | apps/files_publiclink/admin.php | 5 | ||||
-rw-r--r-- | apps/files_sharing/list.php | 7 | ||||
-rw-r--r-- | apps/media/index.php | 5 | ||||
-rw-r--r-- | files/admin.php | 7 | ||||
-rw-r--r-- | files/ajax/download.php | 5 | ||||
-rw-r--r-- | files/download.php | 5 | ||||
-rw-r--r-- | files/index.php | 5 | ||||
-rw-r--r-- | files/settings.php | 5 | ||||
-rw-r--r-- | index.php | 8 | ||||
-rw-r--r-- | lib/util.php | 31 | ||||
-rw-r--r-- | search/ajax/search.php | 7 | ||||
-rw-r--r-- | search/index.php | 8 | ||||
-rw-r--r-- | settings/admin.php | 11 | ||||
-rw-r--r-- | settings/apps.php | 5 | ||||
-rw-r--r-- | settings/help.php | 5 | ||||
-rw-r--r-- | settings/personal.php | 5 | ||||
-rw-r--r-- | settings/settings.php | 7 | ||||
-rw-r--r-- | settings/users.php | 5 |
23 files changed, 63 insertions, 104 deletions
diff --git a/apps/bookmarks/addBm.php b/apps/bookmarks/addBm.php index 2dab33afb22..b62fcdfbeb0 100644 --- a/apps/bookmarks/addBm.php +++ b/apps/bookmarks/addBm.php @@ -24,10 +24,7 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( 'Location: '.OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); require_once('bookmarksHelper.php'); @@ -45,4 +42,4 @@ $tmpl->assign('URL', htmlentities($metadata['url'])); $tmpl->assign('TITLE', htmlentities($metadata['title'])); $tmpl->assign('DESCRIPTION', htmlentities($metadata['description'])); -$tmpl->printPage();
\ No newline at end of file +$tmpl->printPage(); diff --git a/apps/bookmarks/index.php b/apps/bookmarks/index.php index ba9f7cc0c61..45c9a52f557 100644 --- a/apps/bookmarks/index.php +++ b/apps/bookmarks/index.php @@ -24,10 +24,7 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); OC_App::setActiveNavigationEntry( 'bookmarks_index' ); @@ -36,4 +33,4 @@ OC_Util::addStyle('bookmarks', 'bookmarks'); $tmpl = new OC_Template( 'bookmarks', 'list', 'user' ); -$tmpl->printPage();
\ No newline at end of file +$tmpl->printPage(); diff --git a/apps/calendar/export.php b/apps/calendar/export.php index f03a5d23e68..d5ca5eeedad 100644 --- a/apps/calendar/export.php +++ b/apps/calendar/export.php @@ -18,14 +18,11 @@ * MA 02111-1307 USA * *************************************************/ require_once ("../../lib/base.php"); -if(!OC_USER::isLoggedIn()) { - header("Location: " . OC_HELPER::linkTo("", "index.php")); - exit; -} +OC_Util::checkLoggedIn(); $cal = $_GET["calid"]; $calendar = OC_Calendar_Calendar::findCalendar($cal); if($calendar["userid"] != OC_User::getUser()){ - header("Location: " . OC_HELPER::linkTo("", "index.php")); + header( 'Location: '.OC_Helper::linkTo('', 'index.php')); exit; } $calobjects = OC_Calendar_Object::all($cal); diff --git a/apps/calendar/index.php b/apps/calendar/index.php index c9fc9889d40..c93ea93bb6c 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -18,10 +18,7 @@ * MA 02111-1307 USA * *************************************************/ require_once ("../../lib/base.php"); -if(!OC_USER::isLoggedIn()) { - header("Location: " . OC_HELPER::linkTo("", "index.php")); - exit; -} +OC_Util::checkLoggedIn(); // Create default calendar ... $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); if( count($calendars) == 0){ diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 8013f19d31f..c9cf348dfd7 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -28,10 +28,7 @@ function contacts_namesort($a,$b){ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( 'Location: '.OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); // Check if the user has an addressbook $addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser()); diff --git a/apps/files_publiclink/admin.php b/apps/files_publiclink/admin.php index 33d8f04a603..03d7a2ff6c5 100644 --- a/apps/files_publiclink/admin.php +++ b/apps/files_publiclink/admin.php @@ -28,10 +28,7 @@ require_once( 'lib_public.php' ); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); OC_App::setActiveNavigationEntry( "files_publiclink_administration" ); diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php index 0a11f438eb7..a5f99f38041 100644 --- a/apps/files_sharing/list.php +++ b/apps/files_sharing/list.php @@ -23,10 +23,7 @@ require_once('../../lib/base.php'); require_once('lib_share.php'); -if (!OC_User::isLoggedIn()){ - header( "Location: ".OC_HELPER::linkTo( "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); OC_App::setActiveNavigationEntry("files_sharing_list"); @@ -36,4 +33,4 @@ $tmpl = new OC_Template("files_sharing", "list", "user"); $tmpl->assign("shared_items", OC_Share::getMySharedItems()); $tmpl->printPage(); -?>
\ No newline at end of file +?> diff --git a/apps/media/index.php b/apps/media/index.php index fe724b45ddf..578ab7e3c34 100644 --- a/apps/media/index.php +++ b/apps/media/index.php @@ -25,10 +25,7 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); require_once('lib_collection.php'); require_once('lib_scanner.php'); diff --git a/files/admin.php b/files/admin.php index db47bc7c033..09237dfc1d5 100644 --- a/files/admin.php +++ b/files/admin.php @@ -25,12 +25,7 @@ // Init owncloud require_once('../lib/base.php'); - -// Check if we are a user -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ - header( "Location: ".OC_Helper::linkTo( "files", "index.php" )); - exit(); -} +OC_User::checkAdminUser(); $htaccessWorking=(getenv('htaccessWorking')=='true'); if(isset($_POST['maxUploadSize'])){ diff --git a/files/ajax/download.php b/files/ajax/download.php index 4c756f9b190..198069f3fa1 100644 --- a/files/ajax/download.php +++ b/files/ajax/download.php @@ -25,10 +25,7 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); $files = $_GET["files"]; $dir = $_GET["dir"]; diff --git a/files/download.php b/files/download.php index ccd3eb43d8e..c8a2692d015 100644 --- a/files/download.php +++ b/files/download.php @@ -25,10 +25,7 @@ require_once('../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); $filename = $_GET["file"]; diff --git a/files/index.php b/files/index.php index 3d62c3385fa..bba8dc4951e 100644 --- a/files/index.php +++ b/files/index.php @@ -26,10 +26,7 @@ require_once('../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); // Load the files we need OC_Util::addStyle( "files", "files" ); diff --git a/files/settings.php b/files/settings.php index 2bbcb2acd3a..c47eb130095 100644 --- a/files/settings.php +++ b/files/settings.php @@ -26,10 +26,7 @@ require_once('../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); // Load the files we need OC_Util::addStyle( "files", "files" ); diff --git a/index.php b/index.php index 46105a106fb..23bc4fb7764 100644 --- a/index.php +++ b/index.php @@ -48,8 +48,7 @@ elseif(OC_User::isLoggedIn()) { exit(); } else { - header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); - exit(); + OC_Util::redirectToDefaultPage(); } } @@ -61,7 +60,7 @@ elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) { if(OC_User::userExists($_COOKIE['oc_username']) && OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") == $_COOKIE['oc_token']) { OC_User::setUserId($_COOKIE['oc_username']); - header("Location: ". OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); + OC_Util::redirectToDefaultPage(); } else { OC_Template::printGuestPage("", "login", array("error" => true)); @@ -72,7 +71,6 @@ elseif(isset($_COOKIE["oc_remember_login"]) && $_COOKIE["oc_remember_login"]) { elseif(isset($_POST["user"]) && isset($_POST['password'])) { OC_App::loadApps(); if(OC_User::login($_POST["user"], $_POST["password"])) { - header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); if(!empty($_POST["remember_login"])){ error_log("Setting remember login to cookie"); $token = md5($_POST["user"].time()); @@ -82,7 +80,7 @@ elseif(isset($_POST["user"]) && isset($_POST['password'])) { else { OC_User::unsetMagicInCookie(); } - exit(); + OC_Util::redirectToDefaultPage(); } else { if(isset($_COOKIE["oc_username"])){ diff --git a/lib/util.php b/lib/util.php index 2f74bfe5841..51d8cc4d643 100644 --- a/lib/util.php +++ b/lib/util.php @@ -246,4 +246,35 @@ class OC_Util { return $errors; } + + /** + * Check if the user is logged in, redirects to home if not + */ + public static function checkLoggedIn(){ + // Check if we are a user + if( !OC_User::isLoggedIn()){ + header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true)); + exit(); + } + } + + /** + * Check if the user is a admin, redirects to home if not + */ + public static function checkAdminUser(){ + // Check if we are a user + self::checkLoggedIn(); + if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ + header( 'Location: '.OC_Helper::linkTo( '', 'index.php' , true)); + exit(); + } + } + + /** + * Redirect to the user default page + */ + public static function redirectToDefaultPage(){ + header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php')); + exit(); + } } diff --git a/search/ajax/search.php b/search/ajax/search.php index c65fbbc63fa..9472f97e189 100644 --- a/search/ajax/search.php +++ b/search/ajax/search.php @@ -26,10 +26,7 @@ require_once('../../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); $query=(isset($_GET['query']))?$_GET['query']:''; if($query){ @@ -39,4 +36,4 @@ if($query){ echo 'false'; } -?>
\ No newline at end of file +?> diff --git a/search/index.php b/search/index.php index c781c31f549..518695c56d2 100644 --- a/search/index.php +++ b/search/index.php @@ -26,10 +26,7 @@ require_once('../lib/base.php'); // Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); - exit(); -} +OC_Util::checkLoggedIn(); // Load the files we need OC_Util::addStyle( 'search', 'search' ); @@ -38,8 +35,7 @@ $query=(isset($_POST['query']))?$_POST['query']:''; if($query){ $results=OC_Search::search($query); }else{ - header("Location: ".OC::$WEBROOT.'/'.OC_Appconfig::getValue("core", "defaultpage", "files/index.php")); - exit(); + OC_Util::redirectToDefaultPage(); } $resultTypes=array(); diff --git a/settings/admin.php b/settings/admin.php index 15559a150e5..81ed6aa9516 100644 --- a/settings/admin.php +++ b/settings/admin.php @@ -6,14 +6,7 @@ */ require_once('../lib/base.php'); -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ - header( "Location: ".OC_Helper::linkTo( '', "index.php" )); - exit(); -} +OC_Util::checkAdminUser(); OC_Util::addStyle( "settings", "settings" ); OC_App::setActiveNavigationEntry( "admin" ); @@ -24,4 +17,4 @@ $tmpl->assign('forms',array()); foreach($forms as $form){ $tmpl->append('forms',$form); } -$tmpl->printPage();
\ No newline at end of file +$tmpl->printPage(); diff --git a/settings/apps.php b/settings/apps.php index 337a52fd416..672cb18775e 100644 --- a/settings/apps.php +++ b/settings/apps.php @@ -22,10 +22,7 @@ */ require_once('../lib/base.php'); -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkAdminUser(); // Load the files we need OC_Util::addStyle( "settings", "settings" ); diff --git a/settings/help.php b/settings/help.php index f8a2f9b8bf9..48fcec32782 100644 --- a/settings/help.php +++ b/settings/help.php @@ -6,10 +6,7 @@ */ require_once('../lib/base.php'); -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); // Load the files we need diff --git a/settings/personal.php b/settings/personal.php index e6d2d44db76..aea997aff22 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -6,10 +6,7 @@ */ require_once('../lib/base.php'); -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); // Highlight navigation entry OC_Util::addScript( "settings", "personal" ); diff --git a/settings/settings.php b/settings/settings.php index 724cf63aaf7..b08cb08db09 100644 --- a/settings/settings.php +++ b/settings/settings.php @@ -6,10 +6,7 @@ */ require_once('../lib/base.php'); -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkLoggedIn(); OC_Util::addStyle( "settings", "settings" ); OC_App::setActiveNavigationEntry( "settings" ); @@ -20,4 +17,4 @@ $tmpl->assign('forms',array()); foreach($forms as $form){ $tmpl->append('forms',$form); } -$tmpl->printPage();
\ No newline at end of file +$tmpl->printPage(); diff --git a/settings/users.php b/settings/users.php index 5aae4ce43ef..9ca2cb369f7 100644 --- a/settings/users.php +++ b/settings/users.php @@ -6,10 +6,7 @@ */ require_once('../lib/base.php'); -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ - header( "Location: ".OC_Helper::linkTo( "", "index.php" )); - exit(); -} +OC_Util::checkAdminUser(); // We have some javascript foo! OC_Util::addScript( 'settings', 'users' ); |