aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-07-31 15:00:04 -0400
committerMichael Gapczynski <mtgap@owncloud.com>2012-07-31 15:00:04 -0400
commit94ce8f2168bdd9897f54ec433ad7017fb3db1cc8 (patch)
treedb031ac7fd4788be6593e258d170c8f134533e4b /lib
parent269922543eaf9e69dbf5a15fa0ba34704040b09c (diff)
parentdfae77dec1650f171d09d4bde88ab74029f6e8c7 (diff)
downloadnextcloud-server-94ce8f2168bdd9897f54ec433ad7017fb3db1cc8.tar.gz
nextcloud-server-94ce8f2168bdd9897f54ec433ad7017fb3db1cc8.zip
Merge branch 'master' into share_api
Conflicts: apps/contacts/lib/app.php apps/files_sharing/js/share.js
Diffstat (limited to 'lib')
-rwxr-xr-xlib/app.php13
-rw-r--r--lib/connector/sabre/directory.php22
-rw-r--r--lib/connector/sabre/file.php13
-rw-r--r--lib/connector/sabre/node.php35
-rw-r--r--lib/db.php2
-rw-r--r--lib/filesystem.php8
-rw-r--r--lib/filesystemview.php67
-rw-r--r--lib/group.php13
-rw-r--r--lib/json.php12
-rw-r--r--lib/l10n/ca.php25
-rw-r--r--lib/l10n/de.php25
-rw-r--r--lib/l10n/el.php25
-rw-r--r--lib/l10n/fi_FI.php22
-rw-r--r--lib/l10n/sl.php22
-rw-r--r--lib/l10n/sv.php25
-rw-r--r--lib/mail.php3
-rw-r--r--lib/public/app.php15
-rw-r--r--lib/subadmin.php181
-rw-r--r--lib/user.php37
-rwxr-xr-xlib/util.php19
20 files changed, 534 insertions, 50 deletions
diff --git a/lib/app.php b/lib/app.php
index 56132c08671..d1018c37aa7 100755
--- a/lib/app.php
+++ b/lib/app.php
@@ -292,16 +292,21 @@ class OC_App{
if (OC_User::isLoggedIn()) {
// personal menu
$settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" ));
-
+
// if there're some settings forms
if(!empty(self::$settingsForms))
// settings menu
$settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" ));
-
- // if the user is an admin
- if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
+
+ //SubAdmins are also allowed to access user management
+ if(OC_SubAdmin::isSubAdmin($_SESSION["user_id"]) || OC_Group::inGroup( $_SESSION["user_id"], "admin" )){
// admin users menu
$settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
+ }
+
+
+ // if the user is an admin
+ if(OC_Group::inGroup( $_SESSION["user_id"], "admin" )) {
// admin apps menu
$settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php" ).'?installed', "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index 0842fc4fc65..7f8434c7151 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -52,7 +52,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
$newPath = $this->path . '/' . $name;
OC_Filesystem::file_put_contents($newPath,$data);
- return OC_Connector_Sabre_Node::getETagPropertyForFile($newPath);
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
/**
@@ -170,5 +170,25 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
}
+ /**
+ * Returns a list of properties for this nodes.;
+ *
+ * The properties list is a list of propertynames the client requested,
+ * encoded as xmlnamespace#tagName, for example:
+ * http://www.example.org/namespace#author
+ * If the array is empty, all properties should be returned
+ *
+ * @param array $properties
+ * @return void
+ */
+ public function getProperties($properties) {
+ $props = parent::getProperties($properties);
+ if (in_array(self::GETETAG_PROPERTYNAME, $properties)
+ && !isset($props[self::GETETAG_PROPERTYNAME])) {
+ $props[self::GETETAG_PROPERTYNAME] =
+ OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
+ }
+ return $props;
+ }
}
diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php
index 80f0a0ab4d8..9d571fceb0d 100644
--- a/lib/connector/sabre/file.php
+++ b/lib/connector/sabre/file.php
@@ -47,7 +47,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
OC_Filesystem::file_put_contents($this->path,$data);
- return OC_Connector_Sabre_Node::getETagPropertyForFile($this->path);
+ return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
}
/**
@@ -98,7 +98,16 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
if (isset($properties[self::GETETAG_PROPERTYNAME])) {
return $properties[self::GETETAG_PROPERTYNAME];
}
- return $this->getETagPropertyForFile($this->path);
+ return $this->getETagPropertyForPath($this->path);
+ }
+
+ /**
+ * Creates a ETag for this path.
+ * @param string $path Path of the file
+ * @return string|null Returns null if the ETag can not effectively be determined
+ */
+ static protected function createETag($path) {
+ return OC_Filesystem::hash('md5', $path);
}
/**
diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php
index 663970487fb..f268f8b57c4 100644
--- a/lib/connector/sabre/node.php
+++ b/lib/connector/sabre/node.php
@@ -204,12 +204,21 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
}
/**
+ * Creates a ETag for this path.
+ * @param string $path Path of the file
+ * @return string|null Returns null if the ETag can not effectively be determined
+ */
+ static protected function createETag($path) {
+ return uniqid('', true);
+ }
+
+ /**
* Returns the ETag surrounded by double-quotes for this path.
* @param string $path Path of the file
* @return string|null Returns null if the ETag can not effectively be determined
*/
- static public function getETagPropertyForFile($path) {
- $tag = OC_Filesystem::hash('md5', $path);
+ static public function getETagPropertyForPath($path) {
+ $tag = self::createETag($path);
if (empty($tag)) {
return null;
}
@@ -223,8 +232,24 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
* Remove the ETag from the cache.
* @param string $path Path of the file
*/
- static public function removeETagPropertyForFile($path) {
- $query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties WHERE userid = ? AND propertypath = ? AND propertyname = ?' );
- $query->execute( array( OC_User::getUser(), $path, self::GETETAG_PROPERTYNAME ));
+ static public function removeETagPropertyForPath($path) {
+ // remove tags from this and parent paths
+ $paths = array();
+ while ($path != '/' && $path != '') {
+ $paths[] = $path;
+ $path = dirname($path);
+ }
+ if (empty($paths)) {
+ return;
+ }
+ $paths[] = $path;
+ $path_placeholders = join(',', array_fill(0, count($paths), '?'));
+ $query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties'
+ .' WHERE userid = ?'
+ .' AND propertyname = ?'
+ .' AND propertypath IN ('.$path_placeholders.')'
+ );
+ $vals = array( OC_User::getUser(), self::GETETAG_PROPERTYNAME );
+ $query->execute(array_merge( $vals, $paths ));
}
}
diff --git a/lib/db.php b/lib/db.php
index 6971fe4a583..f1928e68236 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -43,7 +43,7 @@ class OC_DB {
*/
private static function getDBBackend(){
$backend=self::BACKEND_MDB2;
- if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
+ if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (installation always needs to be done my mdb2)
$type = OC_Config::getValue( "dbtype", "sqlite" );
if($type=='sqlite3') $type='sqlite';
$drivers=PDO::getAvailableDrivers();
diff --git a/lib/filesystem.php b/lib/filesystem.php
index e5817a1bc82..72d3711e9a2 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -495,8 +495,12 @@ class OC_Filesystem{
}
static public function removeETagHook($params) {
- $path=$params['path'];
- OC_Connector_Sabre_Node::removeETagPropertyForFile($path);
+ if (isset($params['path'])) {
+ $path=$params['path'];
+ } else {
+ $path=$params['oldpath'];
+ }
+ OC_Connector_Sabre_Node::removeETagPropertyForPath($path);
}
}
OC_Hook::connect('OC_Filesystem','post_write', 'OC_Filesystem','removeETagHook');
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index af1a578ec6a..a488b4953d5 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -244,49 +244,54 @@ class OC_FilesystemView {
}
public function file_put_contents($path, $data) {
if(is_resource($data)) {//not having to deal with streams in file_put_contents makes life easier
- $exists = $this->file_exists($path);
- $run = true;
- if(!$exists) {
+ $absolutePath = $this->getAbsolutePath($path);
+ if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) {
+ $path = $this->getRelativePath($absolutePath);
+ $exists = $this->file_exists($path);
+ $run = true;
+ if(!$exists) {
+ OC_Hook::emit(
+ OC_Filesystem::CLASSNAME,
+ OC_Filesystem::signal_create,
+ array(
+ OC_Filesystem::signal_param_path => $path,
+ OC_Filesystem::signal_param_run => &$run
+ )
+ );
+ }
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_create,
+ OC_Filesystem::signal_write,
array(
OC_Filesystem::signal_param_path => $path,
OC_Filesystem::signal_param_run => &$run
)
);
- }
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_write,
- array(
- OC_Filesystem::signal_param_path => $path,
- OC_Filesystem::signal_param_run => &$run
- )
- );
- if(!$run) {
- return false;
- }
- $target=$this->fopen($path, 'w');
- if($target) {
- $count=OC_Helper::streamCopy($data, $target);
- fclose($target);
- fclose($data);
- if(!$exists) {
+ if(!$run) {
+ return false;
+ }
+ $target=$this->fopen($path, 'w');
+ if($target) {
+ $count=OC_Helper::streamCopy($data, $target);
+ fclose($target);
+ fclose($data);
+ if(!$exists) {
+ OC_Hook::emit(
+ OC_Filesystem::CLASSNAME,
+ OC_Filesystem::signal_post_create,
+ array( OC_Filesystem::signal_param_path => $path)
+ );
+ }
OC_Hook::emit(
OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_create,
+ OC_Filesystem::signal_post_write,
array( OC_Filesystem::signal_param_path => $path)
);
+ OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
+ return $count > 0;
+ }else{
+ return false;
}
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_post_write,
- array( OC_Filesystem::signal_param_path => $path)
- );
- return $count > 0;
- }else{
- return false;
}
}else{
return $this->basicOperation('file_put_contents', $path, array('create', 'write'), $data);
diff --git a/lib/group.php b/lib/group.php
index eb6a5828095..a3bdbf9e003 100644
--- a/lib/group.php
+++ b/lib/group.php
@@ -271,4 +271,17 @@ class OC_Group {
}
return $users;
}
+
+ /**
+ * @brief get a list of all users in several groups
+ * @param array $gids
+ * @returns array with user ids
+ */
+ public static function usersInGroups($gids){
+ $users = array();
+ foreach($gids as $gid){
+ $users = array_merge(array_diff(self::usersInGroup($gid), $users), $users);
+ }
+ return $users;
+ }
}
diff --git a/lib/json.php b/lib/json.php
index b46878375d5..3d9d5c96fa3 100644
--- a/lib/json.php
+++ b/lib/json.php
@@ -64,6 +64,18 @@ class OC_JSON{
exit();
}
}
+
+ /**
+ * Check if the user is a subadmin, send json error msg if not
+ */
+ public static function checkSubAdminUser(){
+ self::checkLoggedIn();
+ if(!OC_Group::inGroup(OC_User::getUser(),'admin') && !OC_SubAdmin::isSubAdmin(OC_User::getUser())){
+ $l = OC_L10N::get('core');
+ self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
+ exit();
+ }
+ }
/**
* Send json error msg
diff --git a/lib/l10n/ca.php b/lib/l10n/ca.php
new file mode 100644
index 00000000000..8e4c30caec9
--- /dev/null
+++ b/lib/l10n/ca.php
@@ -0,0 +1,25 @@
+<?php $TRANSLATIONS = array(
+"Help" => "Ajuda",
+"Personal" => "Personal",
+"Settings" => "Configuració",
+"Users" => "Usuaris",
+"Apps" => "Aplicacions",
+"Admin" => "Administració",
+"ZIP download is turned off." => "La baixada en ZIP està desactivada.",
+"Files need to be downloaded one by one." => "Els fitxers s'han de baixar d'un en un.",
+"Back to Files" => "Torna a Fitxers",
+"Selected files too large to generate zip file." => "Els fitxers seleccionats son massa grans per generar un fitxer zip.",
+"Application is not enabled" => "L'aplicació no està habilitada",
+"Authentication error" => "Error d'autenticació",
+"Token expired. Please reload page." => "El testimoni ha expirat. Torneu a carregar la pàgina.",
+"seconds ago" => "segons enrere",
+"1 minute ago" => "fa 1 minut",
+"%d minutes ago" => "fa %d minuts",
+"today" => "avui",
+"yesterday" => "ahir",
+"%d days ago" => "fa %d dies",
+"last month" => "el mes passat",
+"months ago" => "mesos enrere",
+"last year" => "l'any passat",
+"years ago" => "fa anys"
+);
diff --git a/lib/l10n/de.php b/lib/l10n/de.php
new file mode 100644
index 00000000000..d3548c7a134
--- /dev/null
+++ b/lib/l10n/de.php
@@ -0,0 +1,25 @@
+<?php $TRANSLATIONS = array(
+"Help" => "Hilfe",
+"Personal" => "Persönlich",
+"Settings" => "Einstellungen",
+"Users" => "Benutzer",
+"Apps" => "Apps",
+"Admin" => "Administrator",
+"ZIP download is turned off." => "ZIP-Download ist deaktiviert.",
+"Files need to be downloaded one by one." => "Die Dateien müssen einzeln heruntergeladen werden.",
+"Back to Files" => "Zurück zu \"Dateien\"",
+"Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine zip-Datei zu generieren.",
+"Application is not enabled" => "Anwendung ist nicht aktiviert",
+"Authentication error" => "Authentifizierungs-Fehler",
+"Token expired. Please reload page." => "Token abgelaufen. Bitte Seite neuladen.",
+"seconds ago" => "vor wenigen Sekunden",
+"1 minute ago" => "Vor einer Minute",
+"%d minutes ago" => "Vor %d Minuten",
+"today" => "Heute",
+"yesterday" => "Gestern",
+"%d days ago" => "Vor %d Tagen",
+"last month" => "Letzten Monat",
+"months ago" => "Vor Monaten",
+"last year" => "Letztes Jahr",
+"years ago" => "Vor Jahren"
+);
diff --git a/lib/l10n/el.php b/lib/l10n/el.php
new file mode 100644
index 00000000000..d9f272258e1
--- /dev/null
+++ b/lib/l10n/el.php
@@ -0,0 +1,25 @@
+<?php $TRANSLATIONS = array(
+"Help" => "Βοήθεια",
+"Personal" => "Προσωπικά",
+"Settings" => "Ρυθμίσεις",
+"Users" => "Χρήστες",
+"Apps" => "Εφαρμογές",
+"Admin" => "Διαχειριστής",
+"ZIP download is turned off." => "Η λήψη ZIP απενεργοποιήθηκε.",
+"Files need to be downloaded one by one." => "Τα αρχεία πρέπει να ληφθούν ένα-ένα.",
+"Back to Files" => "Πίσω στα Αρχεία",
+"Selected files too large to generate zip file." => "Τα επιλεγμένα αρχεία είναι μεγάλα ώστε να δημιουργηθεί αρχείο zip.",
+"Application is not enabled" => "Δεν ενεργοποιήθηκε η εφαρμογή",
+"Authentication error" => "Σφάλμα πιστοποίησης",
+"Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ επανα-φορτώστε την σελίδα.",
+"seconds ago" => "δευτερόλεπτα πριν",
+"1 minute ago" => "1 λεπτό πριν",
+"%d minutes ago" => "%d λεπτά πριν",
+"today" => "σήμερα",
+"yesterday" => "χθές",
+"%d days ago" => "%d ημέρες πριν",
+"last month" => "τον προηγούμενο μήνα",
+"months ago" => "μήνες πριν",
+"last year" => "τον προηγούμενο χρόνο",
+"years ago" => "χρόνια πριν"
+);
diff --git a/lib/l10n/fi_FI.php b/lib/l10n/fi_FI.php
new file mode 100644
index 00000000000..81f4aa95840
--- /dev/null
+++ b/lib/l10n/fi_FI.php
@@ -0,0 +1,22 @@
+<?php $TRANSLATIONS = array(
+"Help" => "Ohje",
+"Settings" => "Asetukset",
+"Users" => "Käyttäjät",
+"Apps" => "Sovellukset",
+"Admin" => "Ylläpitäjä",
+"ZIP download is turned off." => "ZIP-lataus on poistettu käytöstä.",
+"Files need to be downloaded one by one." => "Tiedostot on ladattava yksittäin.",
+"Back to Files" => "Takaisin tiedostoihin",
+"Selected files too large to generate zip file." => "Valitut tiedostot ovat liian suurikokoisia mahtuakseen zip-tiedostoon.",
+"Authentication error" => "Todennusvirhe",
+"seconds ago" => "sekuntia sitten",
+"1 minute ago" => "1 minuutti sitten",
+"%d minutes ago" => "%d minuuttia sitten",
+"today" => "tänään",
+"yesterday" => "eilen",
+"%d days ago" => "%d päivää sitten",
+"last month" => "viime kuussa",
+"months ago" => "kuukautta sitten",
+"last year" => "viime vuonna",
+"years ago" => "vuotta sitten"
+);
diff --git a/lib/l10n/sl.php b/lib/l10n/sl.php
new file mode 100644
index 00000000000..7889335d975
--- /dev/null
+++ b/lib/l10n/sl.php
@@ -0,0 +1,22 @@
+<?php $TRANSLATIONS = array(
+"Help" => "Pomoč",
+"Personal" => "Osebno",
+"Settings" => "Nastavitve",
+"Users" => "Uporabniki",
+"Apps" => "Aplikacije",
+"Admin" => "Skrbnik",
+"ZIP download is turned off." => "ZIP prenos je onemogočen.",
+"Files need to be downloaded one by one." => "Datoteke morajo biti prenešene posamezno.",
+"Back to Files" => "Nazaj na datoteke",
+"Selected files too large to generate zip file." => "Izbrane datoteke so prevelike, da bi lahko ustvarili zip datoteko.",
+"Application is not enabled" => "Aplikacija ni omogočena",
+"Authentication error" => "Napaka overitve",
+"Token expired. Please reload page." => "Žeton je potekel. Prosimo, če spletno stran znova naložite.",
+"1 minute ago" => "pred minuto",
+"%d minutes ago" => "pred %d minutami",
+"today" => "danes",
+"yesterday" => "včeraj",
+"%d days ago" => "pred %d dnevi",
+"last month" => "prejšnji mesec",
+"last year" => "lani"
+);
diff --git a/lib/l10n/sv.php b/lib/l10n/sv.php
new file mode 100644
index 00000000000..4d9a63c34b1
--- /dev/null
+++ b/lib/l10n/sv.php
@@ -0,0 +1,25 @@
+<?php $TRANSLATIONS = array(
+"Help" => "Hjälp",
+"Personal" => "Personligt",
+"Settings" => "Inställningar",
+"Users" => "Användare",
+"Apps" => "Program",
+"Admin" => "Admin",
+"ZIP download is turned off." => "Nedladdning av ZIP är avstängd.",
+"Files need to be downloaded one by one." => "Filer laddas ner en åt gången.",
+"Back to Files" => "Tillbaka till Filer",
+"Selected files too large to generate zip file." => "Valda filer är för stora för att skapa zip-fil.",
+"Application is not enabled" => "Applikationen är inte aktiverad",
+"Authentication error" => "Fel vid autentisering",
+"Token expired. Please reload page." => "Ogiltig token. Ladda om sidan.",
+"seconds ago" => "sekunder sedan",
+"1 minute ago" => "1 minut sedan",
+"%d minutes ago" => "%d minuter sedan",
+"today" => "idag",
+"yesterday" => "igår",
+"%d days ago" => "%d dagar sedan",
+"last month" => "förra månaden",
+"months ago" => "månader sedan",
+"last year" => "förra året",
+"years ago" => "år sedan"
+);
diff --git a/lib/mail.php b/lib/mail.php
index 7eb2c4770c5..0ac9a97c1bf 100644
--- a/lib/mail.php
+++ b/lib/mail.php
@@ -83,7 +83,8 @@ class OC_Mail {
unset($mailo);
OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
} catch (Exception $exception) {
- OC_Log::write('mail', $exception->getMessage(), OC_Log::DEBUG);
+ OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
+ throw($exception);
}
}
diff --git a/lib/public/app.php b/lib/public/app.php
index 28411933beb..5689f53ffb2 100644
--- a/lib/public/app.php
+++ b/lib/public/app.php
@@ -35,6 +35,21 @@ namespace OCP;
*/
class App {
/**
+ * @brief Makes owncloud aware of this app
+ * @brief This call is deprecated and not necessary to use.
+ * @param $data array with all information
+ * @returns true/false
+ *
+ * @deprecated this method is deprecated
+ * Do not call it anymore
+ * It'll remain in our public API for compatibility reasons
+ *
+ */
+ public static function register( $data ){
+ return \OC_App::register( $data );
+ }
+
+ /**
* @brief adds an entry to the navigation
* @param $data array containing the data
* @returns true/false
diff --git a/lib/subadmin.php b/lib/subadmin.php
new file mode 100644
index 00000000000..0806f27a6bd
--- /dev/null
+++ b/lib/subadmin.php
@@ -0,0 +1,181 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Georg Ehrke
+ * @copyright 2012 Georg Ehrke
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_SubAdmin', 'post_deleteUser');
+OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC_SubAdmin', 'post_deleteGroup');
+/**
+ * This class provides all methods needed for managing groups.
+ *
+ * Hooks provided:
+ * post_createSubAdmin($gid)
+ * post_deleteSubAdmin($gid)
+ */
+class OC_SubAdmin{
+
+ /**
+ * @brief add a SubAdmin
+ * @param $uid uid of the SubAdmin
+ * @param $gid gid of the group
+ * @return boolean
+ */
+ public static function createSubAdmin($uid, $gid){
+ $stmt = OC_DB::prepare('INSERT INTO *PREFIX*group_admin (gid,uid) VALUES(?,?)');
+ $result = $stmt->execute(array($gid, $uid));
+ OC_Hook::emit( "OC_SubAdmin", "post_createSubAdmin", array( "gid" => $gid ));
+ return true;
+ }
+
+ /**
+ * @brief delete a SubAdmin
+ * @param $uid uid of the SubAdmin
+ * @param $gid gid of the group
+ * @return boolean
+ */
+ public static function deleteSubAdmin($uid, $gid){
+ $stmt = OC_DB::prepare('DELETE FROM *PREFIX*group_admin WHERE gid = ? AND uid = ?');
+ $result = $stmt->execute(array($gid, $uid));
+ OC_Hook::emit( "OC_SubAdmin", "post_deleteSubAdmin", array( "gid" => $gid ));
+ return true;
+ }
+
+ /**
+ * @brief get groups of a SubAdmin
+ * @param $uid uid of the SubAdmin
+ * @return array
+ */
+ public static function getSubAdminsGroups($uid){
+ $stmt = OC_DB::prepare('SELECT gid FROM *PREFIX*group_admin WHERE uid = ?');
+ $result = $stmt->execute(array($uid));
+ $gids = array();
+ while($row = $result->fetchRow()){
+ $gids[] = $row['gid'];
+ }
+ return $gids;
+ }
+
+ /**
+ * @brief get SubAdmins of a group
+ * @param $gid gid of the group
+ * @return array
+ */
+ public static function getGroupsSubAdmins($gid){
+ $stmt = OC_DB::prepare('SELECT uid FROM *PREFIX*group_admin WHERE gid = ?');
+ $result = $stmt->execute(array($gid));
+ $uids = array();
+ while($row = $result->fetchRow()){
+ $uids[] = $row['uid'];
+ }
+ return $uids;
+ }
+
+ /**
+ * @brief get all SubAdmins
+ * @return array
+ */
+ public static function getAllSubAdmins(){
+ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*group_admin');
+ $result = $stmt->execute();
+ $subadmins = array();
+ while($row = $result->fetchRow()){
+ $subadmins[] = $row;
+ }
+ return $subadmins;
+ }
+
+ /**
+ * @brief checks if a user is a SubAdmin of a group
+ * @param $uid uid of the subadmin
+ * @param $gid gid of the group
+ * @return bool
+ */
+ public static function isSubAdminofGroup($uid, $gid){
+ $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin where uid = ? AND gid = ?');
+ $result = $stmt->execute(array($uid, $gid));
+ $result = $result->fetchRow();
+ if($result['count'] >= 1){
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @brief checks if a user is a SubAdmin
+ * @param $uid uid of the subadmin
+ * @return bool
+ */
+ public static function isSubAdmin($uid){
+ $stmt = OC_DB::prepare('SELECT COUNT(*) as count FROM *PREFIX*group_admin WHERE uid = ?');
+ $result = $stmt->execute(array($uid));
+ $result = $result->fetchRow();
+ if($result['count'] > 0){
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @brief checks if a user is a accessible by a subadmin
+ * @param $subadmin uid of the subadmin
+ * @param $user uid of the user
+ * @return bool
+ */
+ public static function isUserAccessible($subadmin, $user){
+ if(!self::isSubAdmin($subadmin)){
+ return false;
+ }
+ $accessiblegroups = self::getSubAdminsGroups($subadmin);
+ foreach($accessiblegroups as $accessiblegroup){
+ if(OC_Group::inGroup($user, $accessiblegroup)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * @brief alias for self::isSubAdminofGroup()
+ */
+ public static function isGroupAccessible($subadmin, $group){
+ return self::isSubAdminofGroup($subadmin, $group);
+ }
+
+ /**
+ * @brief delete all SubAdmins by uid
+ * @param $parameters
+ * @return boolean
+ */
+ public static function post_deleteUser($parameters){
+ $stmt = OC_DB::prepare('DELETE FROM *PREFIX*group_admin WHERE uid = ?');
+ $result = $stmt->execute(array($parameters['uid']));
+ return true;
+ }
+
+ /**
+ * @brief delete all SubAdmins8 by gid
+ * @param $parameters
+ * @return boolean
+ */
+ public static function post_deleteGroup($parameters){
+ $stmt = OC_DB::prepare('DELETE FROM *PREFIX*group_admin WHERE gid = ?');
+ $result = $stmt->execute(array($parameters['gid']));
+ return true;
+ }
+}
diff --git a/lib/user.php b/lib/user.php
index 681fd82b99a..95177bc77de 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -208,8 +208,9 @@ class OC_User {
OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid ));
if( $run ){
- $uid=self::checkPassword( $uid, $password );
- if($uid){
+ $uid = self::checkPassword( $uid, $password );
+ $enabled = self::isEnabled($uid);
+ if($uid && $enabled){
session_regenerate_id(true);
self::setUserId($uid);
OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password ));
@@ -363,6 +364,38 @@ class OC_User {
}
return false;
}
+
+ /**
+ * disables a user
+ * @param string $userid the user to disable
+ */
+ public static function disableUser($userid){
+ $query = "INSERT INTO *PREFIX*preferences (`userid`, `appid`, `configkey`, `configvalue`) VALUES(?, ?, ?, ?)";
+ $query = OC_DB::prepare($query);
+ $query->execute(array($userid, 'core', 'enabled', 'false'));
+ }
+
+ /**
+ * enable a user
+ * @param string $userid
+ */
+ public static function enableUser($userid){
+ $query = "DELETE FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ? AND configvalue = ?";
+ $query = OC_DB::prepare($query);
+ $query->execute(array($userid, 'core', 'enabled', 'false'));
+ }
+
+ /**
+ * checks if a user is enabled
+ * @param string $userid
+ * @return bool
+ */
+ public static function isEnabled($userid){
+ $query = "SELECT userid FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ? AND configvalue = ?";
+ $query = OC_DB::prepare($query);
+ $results = $query->execute(array($userid, 'core', 'enabled', 'false'));
+ return $results->numRows() ? false : true;
+ }
/**
* @brief Set cookie value to use in next page load
diff --git a/lib/util.php b/lib/util.php
index 0c563278cc5..6e62ed9bf58 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -66,7 +66,7 @@ class OC_Util {
* @return array
*/
public static function getVersion(){
- return array(4,80,1);
+ return array(4,81,2);
}
/**
@@ -319,6 +319,23 @@ class OC_Util {
}
/**
+ * 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();
+ 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();
+ }
+ return true;
+ }
+
+ /**
* Redirect to the user default page
*/
public static function redirectToDefaultPage(){