Commit 3829460a authored by Thomas Mueller's avatar Thomas Mueller
Browse files

adding space between) and {

parent 785aa751
......@@ -33,7 +33,7 @@ $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')
$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size));
if($_POST) {
if(isset($_POST['maxUploadSize'])){
if(isset($_POST['maxUploadSize'])) {
if(($setMaxSize = OC_Files::setUploadLimit(OCP\Util::computerFileSize($_POST['maxUploadSize']))) !== false) {
$maxUploadFilesize = OCP\Util::humanFileSize($setMaxSize);
}
......
......@@ -17,7 +17,7 @@ $data = array();
if($doBreadcrumb) {
$breadcrumb = array();
$pathtohere = "/";
foreach( explode( "/", $dir ) as $i ){
foreach( explode( "/", $dir ) as $i ) {
if( $i != "" ) {
$pathtohere .= "$i/";
$breadcrumb[] = array( "dir" => $pathtohere, "name" => $i );
......@@ -32,7 +32,7 @@ if($doBreadcrumb) {
// make filelist
$files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] );
$files[] = $i;
}
......
......@@ -35,7 +35,7 @@ $dir = $_POST['dir'];
$error='';
$totalSize=0;
foreach($files['size'] as $size){
foreach($files['size'] as $size) {
$totalSize+=$size;
}
if($totalSize>OC_Filesystem::free_space('/')) {
......@@ -46,7 +46,7 @@ if($totalSize>OC_Filesystem::free_space('/')) {
$result=array();
if(strpos($dir, '..') === false) {
$fileCount=count($files['name']);
for($i=0;$i<$fileCount;$i++){
for($i=0;$i<$fileCount;$i++) {
$target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
$meta=OC_FileCache_Cached::get($target);
......
......@@ -23,14 +23,14 @@
// only need filesystem apps
$RUNTIME_APPTYPES=array('filesystem','authentication');
OC_App::loadApps($RUNTIME_APPTYPES);
if(!OC_User::isLoggedIn()){
if(!isset($_SERVER['PHP_AUTH_USER'])){
if(!OC_User::isLoggedIn()) {
if(!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="ownCloud Server"');
header('HTTP/1.0 401 Unauthorized');
echo 'Valid credentials must be supplied';
exit();
} else {
if(!OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])){
if(!OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
exit();
}
}
......
......@@ -5,7 +5,7 @@ $installedVersion=OCP\Config::getAppValue('files', 'installed_version');
if (version_compare($installedVersion, '1.1.4', '<')) {
$query = OC_DB::prepare( "SELECT `propertyname`, `propertypath`, `userid` FROM `*PREFIX*properties`" );
$result = $query->execute();
while( $row = $result->fetchRow()){
while( $row = $result->fetchRow()) {
$query = OC_DB::prepare( 'UPDATE `*PREFIX*properties` SET `propertyname` = ? WHERE `userid` = ? AND `propertypath` = ?' );
$query->execute( array( preg_replace("/^{.*}/", "", $row["propertyname"]),$row["userid"], $row["propertypath"] ));
}
......
......@@ -29,7 +29,7 @@ OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if(!OC_Filesystem::file_exists($filename)){
if(!OC_Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OCP\Template( '', '404', 'guest' );
$tmpl->assign('file',$filename);
......
......@@ -31,7 +31,7 @@ OCP\Util::addscript( 'files', 'jquery.fileupload' );
OCP\Util::addscript( 'files', 'files' );
OCP\Util::addscript( 'files', 'filelist' );
OCP\Util::addscript( 'files', 'fileactions' );
if(!isset($_SESSION['timezone'])){
if(!isset($_SESSION['timezone'])) {
OCP\Util::addscript( 'files', 'timezone' );
}
OCP\App::setActiveNavigationEntry( 'files_index' );
......@@ -44,9 +44,9 @@ if(!OC_Filesystem::is_dir($dir.'/')) {
}
$files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
$i['date'] = OCP\Util::formatDate($i['mtime'] );
if($i['type']=='file'){
if($i['type']=='file') {
$fileinfo=pathinfo($i['name']);
$i['basename']=$fileinfo['filename'];
if (!empty($fileinfo['extension'])) {
......@@ -56,7 +56,7 @@ foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
$i['extension']='';
}
}
if($i['directory']=='/'){
if($i['directory']=='/') {
$i['directory']='';
}
$files[] = $i;
......@@ -65,8 +65,8 @@ foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
// Make breadcrumb
$breadcrumb = array();
$pathtohere = '';
foreach( explode( '/', $dir ) as $i ){
if( $i != '' ){
foreach( explode( '/', $dir ) as $i ) {
if( $i != '' ) {
$pathtohere .= '/'.str_replace('+','%20', urlencode($i));
$breadcrumb[] = array( 'dir' => $pathtohere, 'name' => $i );
}
......
......@@ -36,7 +36,7 @@ OCP\Util::addscript( "files", "files" );
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$files = array();
foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
foreach( OC_Files::getdirectorycontent( $dir ) as $i ) {
$i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] );
$files[] = $i;
}
......@@ -44,8 +44,8 @@ foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
// Make breadcrumb
$breadcrumb = array();
$pathtohere = "/";
foreach( explode( "/", $dir ) as $i ){
if( $i != "" ){
foreach( explode( "/", $dir ) as $i ) {
if( $i != "" ) {
$pathtohere .= "$i/";
$breadcrumb[] = array( "dir" => $pathtohere, "name" => $i );
}
......
......@@ -10,7 +10,7 @@ OCP\Util::connectHook('OC_User','post_login','OC_Crypt','loginListener');
stream_wrapper_register('crypt','OC_CryptStream');
if(!isset($_SESSION['enckey']) and OCP\User::isLoggedIn()){//force the user to re-loggin if the encryption key isn't unlocked (happens when a user is logged in before the encryption app is enabled)
if(!isset($_SESSION['enckey']) and OCP\User::isLoggedIn()) {//force the user to re-loggin if the encryption key isn't unlocked (happens when a user is logged in before the encryption app is enabled)
OCP\User::logout();
header("Location: ".OC::$WEBROOT.'/');
exit();
......
......@@ -39,18 +39,18 @@ require_once 'Crypt_Blowfish/Blowfish.php';
class OC_Crypt {
static private $bf = null;
public static function loginListener($params){
public static function loginListener($params) {
self::init($params['uid'],$params['password']);
}
public static function init($login,$password) {
$view=new OC_FilesystemView('/');
if(!$view->file_exists('/'.$login)){
if(!$view->file_exists('/'.$login)) {
$view->mkdir('/'.$login);
}
OC_FileProxy::$enabled=false;
if(!$view->file_exists('/'.$login.'/encryption.key')){// does key exist?
if(!$view->file_exists('/'.$login.'/encryption.key')) {// does key exist?
OC_Crypt::createkey($login,$password);
}
$key=$view->file_get_contents('/'.$login.'/encryption.key');
......@@ -66,14 +66,14 @@ class OC_Crypt {
*
* if the key is left out, the default handeler will be used
*/
public static function getBlowfish($key=''){
if($key){
public static function getBlowfish($key='') {
if($key) {
return new Crypt_Blowfish($key);
}else{
if(!isset($_SESSION['enckey'])){
if(!isset($_SESSION['enckey'])) {
return false;
}
if(!self::$bf){
if(!self::$bf) {
self::$bf=new Crypt_Blowfish($_SESSION['enckey']);
}
return self::$bf;
......@@ -96,7 +96,7 @@ class OC_Crypt {
}
public static function changekeypasscode($oldPassword, $newPassword) {
if(OCP\User::isLoggedIn()){
if(OCP\User::isLoggedIn()) {
$username=OCP\USER::getUser();
$view=new OC_FilesystemView('/'.$username);
......@@ -179,7 +179,7 @@ class OC_Crypt {
while (!feof($handleread)) {
$content = fread($handleread, 8192);
$enccontent=OC_CRYPT::decrypt( $content, $key);
if(feof($handleread)){
if(feof($handleread)) {
$enccontent=rtrim($enccontent, "\0");
}
fwrite($handlewrite, $enccontent);
......@@ -192,9 +192,9 @@ class OC_Crypt {
/**
* encrypt data in 8192b sized blocks
*/
public static function blockEncrypt($data, $key=''){
public static function blockEncrypt($data, $key='') {
$result='';
while(strlen($data)){
while(strlen($data)) {
$result.=self::encrypt(substr($data,0,8192),$key);
$data=substr($data,8192);
}
......@@ -204,13 +204,13 @@ class OC_Crypt {
/**
* decrypt data in 8192b sized blocks
*/
public static function blockDecrypt($data, $key='',$maxLength=0){
public static function blockDecrypt($data, $key='',$maxLength=0) {
$result='';
while(strlen($data)){
while(strlen($data)) {
$result.=self::decrypt(substr($data,0,8192),$key);
$data=substr($data,8192);
}
if($maxLength>0){
if($maxLength>0) {
return substr($result,0,$maxLength);
}else{
return rtrim($result, "\0");
......
......@@ -36,18 +36,18 @@ class OC_CryptStream{
private $size;
private static $rootView;
public function stream_open($path, $mode, $options, &$opened_path){
if(!self::$rootView){
public function stream_open($path, $mode, $options, &$opened_path) {
if(!self::$rootView) {
self::$rootView=new OC_FilesystemView('');
}
$path=str_replace('crypt://','',$path);
if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])){
if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) {
$this->source=self::$sourceStreams[basename($path)]['stream'];
$this->path=self::$sourceStreams[basename($path)]['path'];
$this->size=self::$sourceStreams[basename($path)]['size'];
}else{
$this->path=$path;
if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+'){
if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+') {
$this->size=0;
}else{
$this->size=self::$rootView->filesize($path,$mode);
......@@ -55,55 +55,55 @@ class OC_CryptStream{
OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file
$this->source=self::$rootView->fopen($path,$mode);
OC_FileProxy::$enabled=true;
if(!is_resource($this->source)){
if(!is_resource($this->source)) {
OCP\Util::writeLog('files_encryption','failed to open '.$path,OCP\Util::ERROR);
}
}
if(is_resource($this->source)){
if(is_resource($this->source)) {
$this->meta=stream_get_meta_data($this->source);
}
return is_resource($this->source);
}
public function stream_seek($offset, $whence=SEEK_SET){
public function stream_seek($offset, $whence=SEEK_SET) {
$this->flush();
fseek($this->source,$offset,$whence);
}
public function stream_tell(){
public function stream_tell() {
return ftell($this->source);
}
public function stream_read($count){
public function stream_read($count) {
//$count will always be 8192 https://bugs.php.net/bug.php?id=21641
//This makes this function a lot simpler but will breake everything the moment it's fixed
$this->writeCache='';
if($count!=8192){
if($count!=8192) {
OCP\Util::writeLog('files_encryption','php bug 21641 no longer holds, decryption will not work',OCP\Util::FATAL);
die();
}
$pos=ftell($this->source);
$data=fread($this->source,8192);
if(strlen($data)){
if(strlen($data)) {
$result=OC_Crypt::decrypt($data);
}else{
$result='';
}
$length=$this->size-$pos;
if($length<8192){
if($length<8192) {
$result=substr($result,0,$length);
}
return $result;
}
public function stream_write($data){
public function stream_write($data) {
$length=strlen($data);
$currentPos=ftell($this->source);
if($this->writeCache){
if($this->writeCache) {
$data=$this->writeCache.$data;
$this->writeCache='';
}
if($currentPos%8192!=0){
if($currentPos%8192!=0) {
//make sure we always start on a block start
fseek($this->source,-($currentPos%8192),SEEK_CUR);
$encryptedBlock=fread($this->source,8192);
......@@ -113,8 +113,8 @@ class OC_CryptStream{
fseek($this->source,-($currentPos%8192),SEEK_CUR);
}
$currentPos=ftell($this->source);
while($remainingLength=strlen($data)>0){
if($remainingLength<8192){
while($remainingLength=strlen($data)>0) {
if($remainingLength<8192) {
$this->writeCache=$data;
$data='';
}else{
......@@ -127,8 +127,8 @@ class OC_CryptStream{
return $length;
}
public function stream_set_option($option,$arg1,$arg2){
switch($option){
public function stream_set_option($option,$arg1,$arg2) {
switch($option) {
case STREAM_OPTION_BLOCKING:
stream_set_blocking($this->source,$arg1);
break;
......@@ -140,33 +140,33 @@ class OC_CryptStream{
}
}
public function stream_stat(){
public function stream_stat() {
return fstat($this->source);
}
public function stream_lock($mode){
public function stream_lock($mode) {
flock($this->source,$mode);
}
public function stream_flush(){
public function stream_flush() {
return fflush($this->source);
}
public function stream_eof(){
public function stream_eof() {
return feof($this->source);
}
private function flush(){
if($this->writeCache){
private function flush() {
if($this->writeCache) {
$encrypted=OC_Crypt::encrypt($this->writeCache);
fwrite($this->source,$encrypted);
$this->writeCache='';
}
}
public function stream_close(){
public function stream_close() {
$this->flush();
if($this->meta['mode']!='r' and $this->meta['mode']!='rb'){
if($this->meta['mode']!='r' and $this->meta['mode']!='rb') {
OC_FileCache::put($this->path,array('encrypted'=>true,'size'=>$this->size),'');
}
return fclose($this->source);
......
......@@ -34,21 +34,21 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @param string $path
* @return bool
*/
private static function shouldEncrypt($path){
if(is_null(self::$enableEncryption)){
private static function shouldEncrypt($path) {
if(is_null(self::$enableEncryption)) {
self::$enableEncryption=(OCP\Config::getAppValue('files_encryption','enable_encryption','true')=='true');
}
if(!self::$enableEncryption){
if(!self::$enableEncryption) {
return false;
}
if(is_null(self::$blackList)){
if(is_null(self::$blackList)) {
self::$blackList=explode(',',OCP\Config::getAppValue('files_encryption','type_blacklist','jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg'));
}
if(self::isEncrypted($path)){
if(self::isEncrypted($path)) {
return true;
}
$extension=substr($path,strrpos($path,'.')+1);
if(array_search($extension,self::$blackList)===false){
if(array_search($extension,self::$blackList)===false) {
return true;
}
}
......@@ -58,13 +58,13 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
* @param string $path
* @return bool
*/
private static function isEncrypted($path){
private static function isEncrypted($path) {
$metadata=OC_FileCache_Cached::get($path,'');
return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
}
public function preFile_put_contents($path,&$data){
if(self::shouldEncrypt($path)){
public function preFile_put_contents($path,&$data) {
if(self::shouldEncrypt($path)) {
if (!is_resource($data)) {//stream put contents should have been converter to fopen
$size=strlen($data);
$data=OC_Crypt::blockEncrypt($data);
......@@ -73,24 +73,24 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
}
}
public function postFile_get_contents($path,$data){
if(self::isEncrypted($path)){
public function postFile_get_contents($path,$data) {
if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,'');
$data=OC_Crypt::blockDecrypt($data,'',$cached['size']);
}
return $data;
}
public function postFopen($path,&$result){
if(!$result){
public function postFopen($path,&$result) {
if(!$result) {
return $result;
}
$meta=stream_get_meta_data($result);
if(self::isEncrypted($path)){
if(self::isEncrypted($path)) {
fclose($result);
$result=fopen('crypt://'.$path,$meta['mode']);
}elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb'){
if(OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0){
}elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') {
if(OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0) {
//first encrypt the target file so we don't end up with a half encrypted file
OCP\Util::writeLog('files_encryption','Decrypting '.$path.' before writing',OCP\Util::DEBUG);
$tmp=fopen('php://temp');
......@@ -104,23 +104,23 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
return $result;
}
public function postGetMimeType($path,$mime){
if(self::isEncrypted($path)){
public function postGetMimeType($path,$mime) {
if(self::isEncrypted($path)) {
$mime=OCP\Files::getMimeType('crypt://'.$path,'w');
}
return $mime;
}
public function postStat($path,$data){
if(self::isEncrypted($path)){
public function postStat($path,$data) {
if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,'');
$data['size']=$cached['size'];
}
return $data;
}
public function postFileSize($path,$size){
if(self::isEncrypted($path)){
public function postFileSize($path,$size) {
if(self::isEncrypted($path)) {
$cached=OC_FileCache_Cached::get($path,'');
return $cached['size'];
}else{
......
......@@ -7,6 +7,6 @@
<option selected="selected" value="<?php echo $type;?>"><?php echo $type;?></option>
<?php endforeach;?>
</select>
<input type='checkbox' id='enable_encryption' <?php if($_['encryption_enabled']){echo 'checked="checked"';} ?>></input><label for='enable_encryption'><?php echo $l->t('Enable Encryption')?></label>
<input type='checkbox' id='enable_encryption' <?php if($_['encryption_enabled']) {echo 'checked="checked"';} ?>></input><label for='enable_encryption'><?php echo $l->t('Enable Encryption')?></label>
</fieldset>
</form>
......@@ -7,7 +7,7 @@
*/
class Test_Encryption extends UnitTestCase {
function testEncryption(){
function testEncryption() {
$key=uniqid();
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$source=file_get_contents($file); //nice large text file
......@@ -54,7 +54,7 @@ class Test_Encryption extends UnitTestCase {
}
function testBinary(){
function testBinary() {
$key=uniqid();
$file=__DIR__.'/binary';
......
......@@ -10,7 +10,7 @@ class Test_CryptProxy extends UnitTestCase {
private $oldConfig;
private $oldKey;
public function setUp(){
public function setUp() {
$user=OC_User::getUser();
$this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true');
......@@ -40,14 +40,14 @@ class Test_CryptProxy extends UnitTestCase {
$rootView->mkdir('/'.$user.'/files');
}
public function tearDown(){
public function tearDown() {
OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig);
if(!is_null($this->oldKey)){
if(!is_null($this->oldKey)) {
$_SESSION['enckey']=$this->oldKey;
}
}
public function testSimple(){
public function testSimple() {
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$original=file_get_contents($file);
......@@ -64,7 +64,7 @@ class Test_CryptProxy extends UnitTestCase {
}
public function testView(){
public function testView() {
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$original=file_get_contents($file);
......@@ -86,7 +86,7 @@ class Test_CryptProxy extends UnitTestCase {
$this->assertEqual($original,$fromFile);
}
public function testBinary(){
public function testBinary() {
$file=__DIR__.'/binary';
$original=file_get_contents($file);
......
......@@ -9,7 +9,7 @@
class Test_CryptStream extends UnitTestCase {
private $tmpFiles=array();
function testStream(){
function testStream() {
$stream=$this->getStream('test1','w',strlen('foobar'));
fwrite($stream,'foobar');
fclose($stream);
......@@ -40,11 +40,11 @@ class Test_CryptStream extends UnitTestCase {
* @param int size
* @return resource
*/
function getStream($id,$mode,$size){
if($id===''){
function getStream($id,$mode,$size) {
if($id==='') {
$id=uniqid();
}
if(!isset($this->tmpFiles[$id])){
if(!isset($this->tmpFiles[$id])) {
$file=OCP\Files::tmpFile();
$this->tmpFiles[$id]=$file;
}else{
......@@ -55,7 +55,7 @@ class Test_CryptStream extends UnitTestCase {