diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-08-10 13:40:47 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-08-10 13:40:47 -0400 |
commit | e1bde1a78eac82f981358e68af031d974ca81639 (patch) | |
tree | c9ccba7ab7aab6a5461a720d875c818bafad2b4a /lib | |
parent | 80660bdc071632f699ea2051d56f03cc887948e6 (diff) | |
parent | fbf86c6683da91c8cadad128e5ac7c0742aaffed (diff) | |
download | nextcloud-server-e1bde1a78eac82f981358e68af031d974ca81639.tar.gz nextcloud-server-e1bde1a78eac82f981358e68af031d974ca81639.zip |
Merge branch 'master' into sharing
Conflicts:
files/templates/index.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.php | 30 | ||||
-rw-r--r-- | lib/base.php | 9 | ||||
-rwxr-xr-x | lib/crypt.php | 72 | ||||
-rw-r--r-- | lib/files.php | 2 | ||||
-rw-r--r-- | lib/l10n.php | 7 | ||||
-rw-r--r-- | lib/log.php | 151 | ||||
-rw-r--r-- | lib/ocs.php | 28 | ||||
-rw-r--r-- | lib/user.php | 2 |
8 files changed, 104 insertions, 197 deletions
diff --git a/lib/app.php b/lib/app.php index f1363c8af5a..6a2e3078596 100644 --- a/lib/app.php +++ b/lib/app.php @@ -52,7 +52,7 @@ class OC_App{ } // Our very own core apps are hardcoded - foreach( array( 'admin', 'files', 'log', 'help', 'settings' ) as $app ){ + foreach( array( 'admin', 'files', 'help', 'settings' ) as $app ){ require( $app.'/appinfo/app.php' ); } @@ -136,7 +136,6 @@ class OC_App{ * This function returns all data it got via register(). */ public static function get(){ - // TODO: write function return OC_App::$apps; } @@ -199,14 +198,15 @@ class OC_App{ * entries are sorted by the key 'order' ascending. */ public static function getSettingsNavigation(){ + $l=new OC_L10N('core'); $admin=array( - array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "admin", "users.php" ), "name" => "Users", "icon" => OC_Helper::imagePath( "admin", "users.png" )), - array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "admin", "apps.php?installed" ), "name" => "Apps", "icon" => OC_Helper::imagePath( "admin", "apps.png" )), - array( "id" => "files_administration", "order" => 3, "href" => OC_Helper::linkTo( "files", "admin.php" ), "name" => "Files", "icon" => OC_Helper::imagePath( "files", "folder.png" )), + array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "admin", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "admin", "users.png" )), + array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "admin", "apps.php?installed" ), "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "admin", "apps.png" )), + array( "id" => "files_administration", "order" => 3, "href" => OC_Helper::linkTo( "files", "admin.php" ), "name" => $l->t("Files"), "icon" => OC_Helper::imagePath( "files", "folder.png" )), ); $settings=array( - array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "help", "index.php" ), "name" => "Help", "icon" => OC_Helper::imagePath( "help", "help.png" )), - array( "id" => "settings", "order" => 1, "href" => OC_Helper::linkTo( "settings", "index.php" ), "name" => "Personal", "icon" => OC_Helper::imagePath( "settings", "personal.png" )) + array( "id" => "help", "order" => 1000, "href" => OC_Helper::linkTo( "help", "index.php" ), "name" => $l->t("Help"), "icon" => OC_Helper::imagePath( "help", "help.png" )), + array( "id" => "settings", "order" => 1, "href" => OC_Helper::linkTo( "settings", "index.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.png" )) ); if( OC_Group::inGroup( $_SESSION["user_id"], "admin" )){ $settings=array_merge($admin,$settings); @@ -241,7 +241,7 @@ class OC_App{ if(is_file($appid)){ $file=$appid; }else{ - $file='apps/'.$appid.'/appinfo/info.xml'; + $file=OC::$SERVERROOT.'/apps/'.$appid.'/appinfo/info.xml'; if(!is_file($file)){ return array(); } @@ -331,4 +331,18 @@ class OC_App{ public static function registerPersonal($app,$page){ self::$personalForms[]='apps/'.$app.'/'.$page.'.php'; } + + /** + * get a list of all apps in the apps folder + */ + public static function getAllApps(){ + $apps=array(); + $dh=opendir(OC::$SERVERROOT.'/apps'); + while($file=readdir($dh)){ + if(is_file(OC::$SERVERROOT.'/apps/'.$file.'/appinfo/app.php')){ + $apps[]=$file; + } + } + return $apps; + } } diff --git a/lib/base.php b/lib/base.php index 51dee60d672..93b8e0b584d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -90,12 +90,19 @@ if(substr($scriptName,-1)=='/'){ } $WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen($SUBURI)); - +OC::$SERVERROOT=$SERVERROOT; +OC::$WEBROOT=$WEBROOT; if($WEBROOT!='' and $WEBROOT[0]!=='/'){ $WEBROOT='/'.$WEBROOT; } +// We are going to use OC::* instead of globels soon +OC::$WEBROOT = $WEBROOT; +OC::$SERVERROOT = $SERVERROOT; +OC::$DOCUMENTROOT = $DOCUMENTROOT; +OC::$SUBURI = $SUBURI; + // set the right include path set_include_path($SERVERROOT.'/lib'.PATH_SEPARATOR.$SERVERROOT.'/config'.PATH_SEPARATOR.$SERVERROOT.'/3rdparty'.PATH_SEPARATOR.get_include_path().PATH_SEPARATOR.$SERVERROOT); diff --git a/lib/crypt.php b/lib/crypt.php index baa433f9dcc..d75515cf2de 100755 --- a/lib/crypt.php +++ b/lib/crypt.php @@ -3,7 +3,6 @@ * ownCloud * * @author Frank Karlitschek - * @author Jakob Sack * @copyright 2010 Frank Karlitschek karlitschek@kde.org * * This library is free software; you can redistribute it and/or @@ -21,6 +20,15 @@ * */ + + +// Todo: +// Crypt/decrypt button in the userinterface +// transparent decrypt/encrpt in filesystem.php +// don't use a password directly as encryption key. but a key which is stored on the server and encrypted with the user password. -> password change faster + + + require_once('Crypt_Blowfish/Blowfish.php'); /** @@ -28,6 +36,19 @@ require_once('Crypt_Blowfish/Blowfish.php'); */ class OC_Crypt { + static $encription_extension='.encrypted'; + + public static function createkey( $passcode) { + // generate a random key + $key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999); + + // encrypt the key with the passcode of the user + $enckey=OC_Crypt::encrypt($key,$passcode); + + // Write the file + file_put_contents( "$SERVERROOT/config/encryption.key", $enckey ); + } + /** * @brief encrypts an content * @param $content the cleartext message you want to encrypt @@ -51,11 +72,56 @@ class OC_Crypt { * This function decrypts an content */ public static function decrypt( $content, $key) { - $bf = new Crypt_Blowfish($key); - return($bf->encrypt($contents)); + $bf = new Crypt_Blowfish($key); + return($bf->encrypt($contents)); } + /** + * @brief encryption of a file + * @param $filename + * @param $key the encryption key + * + * This function encrypts a file + */ + public static function encryptfile( $filename, $key) { + $handleread = fopen($filename, "rb"); + if($handleread<>FALSE) { + $handlewrite = fopen($filename.OC_Crypt::$encription_extension, "wb"); + while (!feof($handleread)) { + $content = fread($handleread, 8192); + $enccontent=OC_CRYPT::encrypt( $content, $key); + fwrite($handlewrite, $enccontent); + } + fclose($handlewrite); + unlink($filename); + } + fclose($handleread); + } + + + /** + * @brief decryption of a file + * @param $filename + * @param $key the decryption key + * + * This function decrypts a file + */ + public static function decryptfile( $filename, $key) { + $handleread = fopen($filename.OC_Crypt::$encription_extension, "rb"); + if($handleread<>FALSE) { + $handlewrite = fopen($filename, "wb"); + while (!feof($handleread)) { + $content = fread($handleread, 8192); + $enccontent=OC_CRYPT::decrypt( $content, $key); + fwrite($handlewrite, $enccontent); + } + fclose($handlewrite); + unlink($filename.OC_Crypt::$encription_extension); + } + fclose($handleread); + } + diff --git a/lib/files.php b/lib/files.php index d189a96fd89..eec1007de1f 100644 --- a/lib/files.php +++ b/lib/files.php @@ -144,7 +144,6 @@ class OC_Files { die('403 Forbidden'); } ob_end_clean(); -// OC_Log::event($_SESSION['username'],3,"$dir/$files"); if($zip){ readfile($filename); unlink($filename); @@ -206,7 +205,6 @@ class OC_Files { $fileHandle=OC_Filesystem::fopen($file, 'w'); if($fileHandle){ fclose($fileHandle); -// OC_Log::event($_SESSION['username'],4,"$dir/$name"); return true; }else{ return false; diff --git a/lib/l10n.php b/lib/l10n.php index 5271bd4e589..2d565ad0799 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -97,16 +97,17 @@ class OC_L10N{ /** * @brief Translating * @param $text The text we need a translation for + * @param $parameters default:array() Parameters for sprintf * @returns Translation or the same text * * Returns the translation. If no translation is found, $text will be * returned. */ - public function t($text){ + public function t($text, $parameters = array()){ if(array_key_exists($text, $this->translations)){ - return $this->translations[$text]; + return vsprintf( $this->translations[$text], $parameters ); } - return $text; + return vsprintf( $text, $parameters ); } /** diff --git a/lib/log.php b/lib/log.php deleted file mode 100644 index 1ed8e0e33c2..00000000000 --- a/lib/log.php +++ /dev/null @@ -1,151 +0,0 @@ -<?php -/** - * ownCloud - * - * @author Frank Karlitschek - * @author Jakob Sack - * @copyright 2010 Frank Karlitschek karlitschek@kde.org - * - * 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/>. - * - */ -/* - * - * The following SQL statement is just a help for developers and will not be - * executed! - * - * CREATE TABLE `log` ( - * `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - * `moment` DATETIME NOT NULL , - * `appid` VARCHAR( 255 ) NOT NULL , - * `user` VARCHAR( 255 ) NOT NULL , - * `action` VARCHAR( 255 ) NOT NULL , - * `info` TEXT NOT NULL - * ) ENGINE = MYISAM ; - * - */ - -/** - * This class is for logging - */ -class OC_Log { - /** - * @brief adds an entry to the log - * @param $appid id of the app - * @param $subject username - * @param $predicate action - * @param $object = null; additional information - * @returns true/false - * - * This function adds another entry to the log database - */ - public static function add( $appid, $subject, $predicate, $object = ' ' ){ - $query=OC_DB::prepare("INSERT INTO `*PREFIX*log`(moment,appid,`user`,action,info) VALUES(NOW(),?,?,?,?)"); - $result=$query->execute(array($appid,$subject,$predicate,$object)); - // Die if we have an error - if( PEAR::isError($result)) { - $entry = 'DB Error: "'.$result->getMessage().'"<br />'; - $entry .= 'Offending command was: '.$query.'<br />'; - error_log( $entry ); - die( $entry ); - } - return true; - } - - /** - * @brief Fetches log entries - * @param $filter = array(); array with filter options - * @returns array with entries - * - * This function fetches the log entries according to the filter options - * passed. - * - * $filter is an associative array. - * The following keys are optional: - * - from: all entries after this date - * - until: all entries until this date - * - user: username (default: current user) - * - app: only entries for this app - */ - public static function get( $filter = array()){ - $queryString='SELECT * FROM `*PREFIX*log` WHERE 1=1 ORDER BY moment DESC'; - $params=array(); - if(isset($filter['from'])){ - $queryString.='AND moment>? '; - array_push($params,$filter('from')); - } - if(isset($filter['until'])){ - $queryString.='AND moment<? '; - array_push($params,$filter('until')); - } - if(isset($filter['user'])){ - $queryString.='AND `user`=? '; - array_push($params,$filter('user')); - } - if(isset($filter['app'])){ - $queryString.='AND appid=? '; - array_push($params,$filter('app')); - } - $query=OC_DB::prepare($queryString); - $result=$query->execute($params)->fetchAll(); - if(count($result)>0 and is_numeric($result[0]['moment'])){ - foreach($result as &$row){ - $row['moment']=OC_Util::formatDate($row['moment']); - } - } - return $result; - - } - - /** - * @brief removes log entries - * @param $date delete entries older than this date - * @returns true/false - * - * This function deletes all entries that are older than $date. - */ - public static function deleteBefore( $date ){ - $query=OC_DB::prepare("DELETE FROM `*PREFIX*log` WHERE moment<?"); - $query->execute(array($date)); - return true; - } - - /** - * @brief removes all log entries - * @returns true/false - * - * This function deletes all log entries. - */ - public static function deleteAll(){ - $query=OC_DB::prepare("DELETE FROM `*PREFIX*log`"); - $query->execute(); - return true; - } - - /** - * @brief filter an array of log entries on action - * @param array $logs the log entries to filter - * @param array $actions an array of actions to filter for - * @returns array - */ - public static function filterAction($logs,$actions){ - $filteredLogs=array(); - foreach($logs as $log){ - if(array_search($log['action'],$actions)!==false){ - $filteredLogs[]=$log; - } - } - return $filteredLogs; - } -} diff --git a/lib/ocs.php b/lib/ocs.php index bcacfe704c0..536ee754e84 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -402,33 +402,7 @@ class OC_OCS { private static function activityGet($format,$page,$pagesize) { $user=OC_OCS::checkpassword(); - $query = OC_DB::prepare('select count(*) as co from *PREFIX*log'); - $result = $query->execute(); - $entry=$result->fetchRow(); - $totalcount=$entry['co']; - - $query=OC_DB::prepare('select id,timestamp,`user`,type,message from *PREFIX*log order by timestamp desc limit ?,?'); - $result = $query->execute(array(($page*$pagesize),$pagesize))->fetchAll(); - - $itemscount=count($result); - - $url='http://'.substr($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'],0,-11).''; - $xml=array(); - foreach($result as $i=>$log) { - $xml[$i]['id']=$log['id']; - $xml[$i]['personid']=$log['user']; - $xml[$i]['firstname']=$log['user']; - $xml[$i]['lastname']=''; - $xml[$i]['profilepage']=$url; - - $pic=$url.'/img/owncloud-icon.png'; - $xml[$i]['avatarpic']=$pic; - - $xml[$i]['timestamp']=date('c',$log['timestamp']); - $xml[$i]['type']=1; - $xml[$i]['message']=OC_Log::$TYPE[$log['type']].' '.strip_tags($log['message']); - $xml[$i]['link']=$url; - } + //TODO $txt=OC_OCS::generatexml($format,'ok',100,'',$xml,'activity','full',2,$totalcount,$pagesize); echo($txt); diff --git a/lib/user.php b/lib/user.php index 9b8f5fb13e7..a2ede8234be 100644 --- a/lib/user.php +++ b/lib/user.php @@ -193,7 +193,6 @@ class OC_User { if( $run && self::checkPassword( $uid, $password )){ $_SESSION['user_id'] = $uid; - OC_Log::add( "core", $_SESSION['user_id'], "login" ); OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid )); return true; } @@ -210,7 +209,6 @@ class OC_User { */ public static function logout(){ OC_Hook::emit( "OC_User", "logout", array()); - OC_Log::add( "core", $_SESSION['user_id'], "logout" ); $_SESSION['user_id'] = false; return true; } |