summaryrefslogtreecommitdiffstats
path: root/lib/util.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.php')
-rwxr-xr-xlib/util.php203
1 files changed, 82 insertions, 121 deletions
diff --git a/lib/util.php b/lib/util.php
index fc50123b4fe..374baa43dbe 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -111,7 +111,7 @@ class OC_Util {
* @return string
*/
public static function getEditionString() {
- return '';
+ return '';
}
/**
@@ -166,7 +166,7 @@ class OC_Util {
* @param int timestamp $timestamp
* @param bool dateOnly option to ommit time from the result
*/
- public static function formatDate( $timestamp, $dateOnly=false) {
+ public static function formatDate( $timestamp, $dateOnly=false) {
if(isset($_SESSION['timezone'])) {//adjust to clients timezone if we know it
$systemTimeZone = intval(date('O'));
$systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100);
@@ -176,37 +176,8 @@ class OC_Util {
}
$l=OC_L10N::get('lib');
return $l->l($dateOnly ? 'date' : 'datetime', $timestamp);
- }
-
- /**
- * Shows a pagenavi widget where you can jump to different pages.
- *
- * @param int $pagecount
- * @param int $page
- * @param string $url
- * @return OC_Template
- */
- public static function getPageNavi($pagecount, $page, $url) {
-
- $pagelinkcount=8;
- if ($pagecount>1) {
- $pagestart=$page-$pagelinkcount;
- if($pagestart<0) $pagestart=0;
- $pagestop=$page+$pagelinkcount;
- if($pagestop>$pagecount) $pagestop=$pagecount;
-
- $tmpl = new OC_Template( '', 'part.pagenavi', '' );
- $tmpl->assign('page', $page);
- $tmpl->assign('pagecount', $pagecount);
- $tmpl->assign('pagestart', $pagestart);
- $tmpl->assign('pagestop', $pagestop);
- $tmpl->assign('url', $url);
- return $tmpl;
- }
}
-
-
/**
* check if the current server configuration is suitable for ownCloud
* @return array arrays with error messages and hints
@@ -340,14 +311,14 @@ class OC_Util {
if (isset($_REQUEST['redirect_url'])) {
$redirect_url = OC_Util::sanitizeHTML($_REQUEST['redirect_url']);
$parameters['redirect_url'] = urlencode($redirect_url);
- }
+ }
OC_Template::printGuestPage("", "login", $parameters);
}
/**
- * Check if the app is enabled, redirects to home if not
- */
+ * Check if the app is enabled, redirects to home if not
+ */
public static function checkAppEnabled($app) {
if( !OC_App::isEnabled($app)) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
@@ -356,9 +327,9 @@ class OC_Util {
}
/**
- * Check if the user is logged in, redirects to home if not. With
- * redirect URL parameter to the request URI.
- */
+ * Check if the user is logged in, redirects to home if not. With
+ * redirect URL parameter to the request URI.
+ */
public static function checkLoggedIn() {
// Check if we are a user
if( !OC_User::isLoggedIn()) {
@@ -368,29 +339,20 @@ class OC_Util {
}
/**
- * Check if the user is a admin, redirects to home if not
- */
+ * Check if the user is a admin, redirects to home if not
+ */
public static function checkAdminUser() {
- // Check if we are a user
- self::checkLoggedIn();
- self::verifyUser();
- if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )) {
+ if( !OC_User::isAdminUser(OC_User::getUser())) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
exit();
}
}
/**
- * Check if the user is a subadmin, redirects to home if not
- * @return array $groups where the current user is subadmin
- */
+ * Check if the user is a subadmin, redirects to home if not
+ * @return array $groups where the current user is subadmin
+ */
public static function checkSubAdminUser() {
- // Check if we are a user
- self::checkLoggedIn();
- self::verifyUser();
- if(OC_Group::inGroup(OC_User::getUser(), 'admin')) {
- return true;
- }
if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' ));
exit();
@@ -399,42 +361,8 @@ class OC_Util {
}
/**
- * Check if the user verified the login with his password in the last 15 minutes
- * If not, the user will be shown a password verification page
- */
- public static function verifyUser() {
- if(OC_Config::getValue('enhancedauth', false) === true) {
- // Check password to set session
- if(isset($_POST['password'])) {
- if (OC_User::login(OC_User::getUser(), $_POST["password"] ) === true) {
- $_SESSION['verifiedLogin']=time() + OC_Config::getValue('enhancedauthtime', 15 * 60);
- }
- }
-
- // Check if the user verified his password
- if(!isset($_SESSION['verifiedLogin']) OR $_SESSION['verifiedLogin'] < time()) {
- OC_Template::printGuestPage("", "verify", array('username' => OC_User::getUser()));
- exit();
- }
- }
- }
-
- /**
- * Check if the user verified the login with his password
- * @return bool
- */
- public static function isUserVerified() {
- if(OC_Config::getValue('enhancedauth', false) === true) {
- if(!isset($_SESSION['verifiedLogin']) OR $_SESSION['verifiedLogin'] < time()) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Redirect to the user default page
- */
+ * Redirect to the user default page
+ */
public static function redirectToDefaultPage() {
if(isset($_REQUEST['redirect_url'])) {
$location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url']));
@@ -539,8 +467,11 @@ class OC_Util {
* @return array with sanitized strings or a single sanitized string, depends on the input parameter.
*/
public static function sanitizeHTML( &$value ) {
- if (is_array($value) || is_object($value)) array_walk_recursive($value, 'OC_Util::sanitizeHTML');
- else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4
+ if (is_array($value) || is_object($value)) {
+ array_walk_recursive($value, 'OC_Util::sanitizeHTML');
+ } else {
+ $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4
+ }
return $value;
}
@@ -582,20 +513,32 @@ class OC_Util {
}
- /**
- * Check if the ownCloud server can connect to the internet
- */
+ /**
+ * Check if the setlocal call doesn't work. This can happen if the right local packages are not available on the server.
+ */
+ public static function issetlocaleworking() {
+ $result=setlocale(LC_ALL, 'en_US.UTF-8');
+ if($result==false) {
+ return(false);
+ }else{
+ return(true);
+ }
+ }
+
+ /**
+ * Check if the ownCloud server can connect to the internet
+ */
public static function isinternetconnectionworking() {
// try to connect to owncloud.org to see if http connections to the internet are possible.
- $connected = @fsockopen("www.owncloud.org", 80);
+ $connected = @fsockopen("www.owncloud.org", 80);
if ($connected) {
fclose($connected);
return true;
}else{
// second try in case one server is down
- $connected = @fsockopen("apps.owncloud.com", 80);
+ $connected = @fsockopen("apps.owncloud.com", 80);
if ($connected) {
fclose($connected);
return true;
@@ -618,11 +561,11 @@ class OC_Util {
/**
- * @brief Generates a cryptographical secure pseudorandom string
- * @param Int with the length of the random string
- * @return String
- * Please also update secureRNG_available if you change something here
- */
+ * @brief Generates a cryptographical secure pseudorandom string
+ * @param Int with the length of the random string
+ * @return String
+ * Please also update secureRNG_available if you change something here
+ */
public static function generate_random_bytes($length = 30) {
// Try to use openssl_random_pseudo_bytes
@@ -654,9 +597,9 @@ class OC_Util {
}
/**
- * @brief Checks if a secure random number generator is available
- * @return bool
- */
+ * @brief Checks if a secure random number generator is available
+ * @return bool
+ */
public static function secureRNG_available() {
// Check openssl_random_pseudo_bytes
@@ -675,17 +618,17 @@ class OC_Util {
return false;
}
-
- /**
- * @Brief Get file content via curl.
- * @param string $url Url to get content
- * @return string of the response or false on error
- * This function get the content of a page via curl, if curl is enabled.
- * If not, file_get_element is used.
- */
-
+
+ /**
+ * @Brief Get file content via curl.
+ * @param string $url Url to get content
+ * @return string of the response or false on error
+ * This function get the content of a page via curl, if curl is enabled.
+ * If not, file_get_element is used.
+ */
+
public static function getUrlContent($url){
-
+
if (function_exists('curl_init')) {
$curl = curl_init();
@@ -695,23 +638,41 @@ class OC_Util {
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler");
+ if(OC_Config::getValue('proxy','')<>'') {
+ curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy'));
+ }
+ if(OC_Config::getValue('proxyuserpwd','')<>'') {
+ curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd'));
+ }
$data = curl_exec($curl);
curl_close($curl);
} else {
+ $contextArray = null;
+
+ if(OC_Config::getValue('proxy','')<>'') {
+ $contextArray = array(
+ 'http' => array(
+ 'timeout' => 10,
+ 'proxy' => OC_Config::getValue('proxy')
+ )
+ );
+ } else {
+ $contextArray = array(
+ 'http' => array(
+ 'timeout' => 10
+ )
+ );
+ }
+
$ctx = stream_context_create(
- array(
- 'http' => array(
- 'timeout' => 10
- )
- )
- );
+ $contextArray
+ );
$data=@file_get_contents($url, 0, $ctx);
}
-
return $data;
}
-
+
}