commit
f2dcab50b5
@ -0,0 +1,253 @@ |
||||
<?php |
||||
# |
||||
# Portable PHP password hashing framework. |
||||
# |
||||
# Version 0.3 / genuine. |
||||
# |
||||
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in |
||||
# the public domain. Revised in subsequent years, still public domain. |
||||
# |
||||
# There's absolutely no warranty. |
||||
# |
||||
# The homepage URL for this framework is: |
||||
# |
||||
# http://www.openwall.com/phpass/ |
||||
# |
||||
# Please be sure to update the Version line if you edit this file in any way. |
||||
# It is suggested that you leave the main version number intact, but indicate |
||||
# your project name (after the slash) and add your own revision information. |
||||
# |
||||
# Please do not change the "private" password hashing method implemented in |
||||
# here, thereby making your hashes incompatible. However, if you must, please |
||||
# change the hash type identifier (the "$P$") to something different. |
||||
# |
||||
# Obviously, since this code is in the public domain, the above are not |
||||
# requirements (there can be none), but merely suggestions. |
||||
# |
||||
class PasswordHash { |
||||
var $itoa64; |
||||
var $iteration_count_log2; |
||||
var $portable_hashes; |
||||
var $random_state; |
||||
|
||||
function PasswordHash($iteration_count_log2, $portable_hashes) |
||||
{ |
||||
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
||||
|
||||
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) |
||||
$iteration_count_log2 = 8; |
||||
$this->iteration_count_log2 = $iteration_count_log2; |
||||
|
||||
$this->portable_hashes = $portable_hashes; |
||||
|
||||
$this->random_state = microtime(); |
||||
if (function_exists('getmypid')) |
||||
$this->random_state .= getmypid(); |
||||
} |
||||
|
||||
function get_random_bytes($count) |
||||
{ |
||||
$output = ''; |
||||
if (is_readable('/dev/urandom') && |
||||
($fh = @fopen('/dev/urandom', 'rb'))) { |
||||
$output = fread($fh, $count); |
||||
fclose($fh); |
||||
} |
||||
|
||||
if (strlen($output) < $count) { |
||||
$output = ''; |
||||
for ($i = 0; $i < $count; $i += 16) { |
||||
$this->random_state = |
||||
md5(microtime() . $this->random_state); |
||||
$output .= |
||||
pack('H*', md5($this->random_state)); |
||||
} |
||||
$output = substr($output, 0, $count); |
||||
} |
||||
|
||||
return $output; |
||||
} |
||||
|
||||
function encode64($input, $count) |
||||
{ |
||||
$output = ''; |
||||
$i = 0; |
||||
do { |
||||
$value = ord($input[$i++]); |
||||
$output .= $this->itoa64[$value & 0x3f]; |
||||
if ($i < $count) |
||||
$value |= ord($input[$i]) << 8; |
||||
$output .= $this->itoa64[($value >> 6) & 0x3f]; |
||||
if ($i++ >= $count) |
||||
break; |
||||
if ($i < $count) |
||||
$value |= ord($input[$i]) << 16; |
||||
$output .= $this->itoa64[($value >> 12) & 0x3f]; |
||||
if ($i++ >= $count) |
||||
break; |
||||
$output .= $this->itoa64[($value >> 18) & 0x3f]; |
||||
} while ($i < $count); |
||||
|
||||
return $output; |
||||
} |
||||
|
||||
function gensalt_private($input) |
||||
{ |
||||
$output = '$P$'; |
||||
$output .= $this->itoa64[min($this->iteration_count_log2 + |
||||
((PHP_VERSION >= '5') ? 5 : 3), 30)]; |
||||
$output .= $this->encode64($input, 6); |
||||
|
||||
return $output; |
||||
} |
||||
|
||||
function crypt_private($password, $setting) |
||||
{ |
||||
$output = '*0'; |
||||
if (substr($setting, 0, 2) == $output) |
||||
$output = '*1'; |
||||
|
||||
$id = substr($setting, 0, 3); |
||||
# We use "$P$", phpBB3 uses "$H$" for the same thing |
||||
if ($id != '$P$' && $id != '$H$') |
||||
return $output; |
||||
|
||||
$count_log2 = strpos($this->itoa64, $setting[3]); |
||||
if ($count_log2 < 7 || $count_log2 > 30) |
||||
return $output; |
||||
|
||||
$count = 1 << $count_log2; |
||||
|
||||
$salt = substr($setting, 4, 8); |
||||
if (strlen($salt) != 8) |
||||
return $output; |
||||
|
||||
# We're kind of forced to use MD5 here since it's the only |
||||
# cryptographic primitive available in all versions of PHP |
||||
# currently in use. To implement our own low-level crypto |
||||
# in PHP would result in much worse performance and |
||||
# consequently in lower iteration counts and hashes that are |
||||
# quicker to crack (by non-PHP code). |
||||
if (PHP_VERSION >= '5') { |
||||
$hash = md5($salt . $password, TRUE); |
||||
do { |
||||
$hash = md5($hash . $password, TRUE); |
||||
} while (--$count); |
||||
} else { |
||||
$hash = pack('H*', md5($salt . $password)); |
||||
do { |
||||
$hash = pack('H*', md5($hash . $password)); |
||||
} while (--$count); |
||||
} |
||||
|
||||
$output = substr($setting, 0, 12); |
||||
$output .= $this->encode64($hash, 16); |
||||
|
||||
return $output; |
||||
} |
||||
|
||||
function gensalt_extended($input) |
||||
{ |
||||
$count_log2 = min($this->iteration_count_log2 + 8, 24); |
||||
# This should be odd to not reveal weak DES keys, and the |
||||
# maximum valid value is (2**24 - 1) which is odd anyway. |
||||
$count = (1 << $count_log2) - 1; |
||||
|
||||
$output = '_'; |
||||
$output .= $this->itoa64[$count & 0x3f]; |
||||
$output .= $this->itoa64[($count >> 6) & 0x3f]; |
||||
$output .= $this->itoa64[($count >> 12) & 0x3f]; |
||||
$output .= $this->itoa64[($count >> 18) & 0x3f]; |
||||
|
||||
$output .= $this->encode64($input, 3); |
||||
|
||||
return $output; |
||||
} |
||||
|
||||
function gensalt_blowfish($input) |
||||
{ |
||||
# This one needs to use a different order of characters and a |
||||
# different encoding scheme from the one in encode64() above. |
||||
# We care because the last character in our encoded string will |
||||
# only represent 2 bits. While two known implementations of |
||||
# bcrypt will happily accept and correct a salt string which |
||||
# has the 4 unused bits set to non-zero, we do not want to take |
||||
# chances and we also do not want to waste an additional byte |
||||
# of entropy. |
||||
$itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
||||
|
||||
$output = '$2a$'; |
||||
$output .= chr(ord('0') + $this->iteration_count_log2 / 10); |
||||
$output .= chr(ord('0') + $this->iteration_count_log2 % 10); |
||||
$output .= '$'; |
||||
|
||||
$i = 0; |
||||
do { |
||||
$c1 = ord($input[$i++]); |
||||
$output .= $itoa64[$c1 >> 2]; |
||||
$c1 = ($c1 & 0x03) << 4; |
||||
if ($i >= 16) { |
||||
$output .= $itoa64[$c1]; |
||||
break; |
||||
} |
||||
|
||||
$c2 = ord($input[$i++]); |
||||
$c1 |= $c2 >> 4; |
||||
$output .= $itoa64[$c1]; |
||||
$c1 = ($c2 & 0x0f) << 2; |
||||
|
||||
$c2 = ord($input[$i++]); |
||||
$c1 |= $c2 >> 6; |
||||
$output .= $itoa64[$c1]; |
||||
$output .= $itoa64[$c2 & 0x3f]; |
||||
} while (1); |
||||
|
||||
return $output; |
||||
} |
||||
|
||||
function HashPassword($password) |
||||
{ |
||||
$random = ''; |
||||
|
||||
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { |
||||
$random = $this->get_random_bytes(16); |
||||
$hash = |
||||
crypt($password, $this->gensalt_blowfish($random)); |
||||
if (strlen($hash) == 60) |
||||
return $hash; |
||||
} |
||||
|
||||
if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
||||
if (strlen($random) < 3) |
||||
$random = $this->get_random_bytes(3); |
||||
$hash = |
||||
crypt($password, $this->gensalt_extended($random)); |
||||
if (strlen($hash) == 20) |
||||
return $hash; |
||||
} |
||||
|
||||
if (strlen($random) < 6) |
||||
$random = $this->get_random_bytes(6); |
||||
$hash = |
||||
$this->crypt_private($password, |
||||
$this->gensalt_private($random)); |
||||
if (strlen($hash) == 34) |
||||
return $hash; |
||||
|
||||
# Returning '*' on error is safe here, but would _not_ be safe |
||||
# in a crypt(3)-like function used _both_ for generating new |
||||
# hashes and for validating passwords against existing hashes. |
||||
return '*'; |
||||
} |
||||
|
||||
function CheckPassword($password, $stored_hash) |
||||
{ |
||||
$hash = $this->crypt_private($password, $stored_hash); |
||||
if ($hash[0] == '*') |
||||
$hash = crypt($password, $stored_hash); |
||||
|
||||
return $hash == $stored_hash; |
||||
} |
||||
} |
||||
|
||||
?> |
||||
@ -0,0 +1,21 @@ |
||||
#
|
||||
# Written by Solar Designer and placed in the public domain.
|
||||
# See crypt_private.c for more information.
|
||||
#
|
||||
CC = gcc
|
||||
LD = $(CC)
|
||||
RM = rm -f
|
||||
CFLAGS = -Wall -O2 -fomit-frame-pointer -funroll-loops
|
||||
LDFLAGS = -s
|
||||
LIBS = -lcrypto
|
||||
|
||||
all: crypt_private-test |
||||
|
||||
crypt_private-test: crypt_private-test.o |
||||
$(LD) $(LDFLAGS) $(LIBS) crypt_private-test.o -o $@
|
||||
|
||||
crypt_private-test.o: crypt_private.c |
||||
$(CC) -c $(CFLAGS) crypt_private.c -DTEST -o $@
|
||||
|
||||
clean: |
||||
$(RM) crypt_private-test*
|
||||
@ -0,0 +1,106 @@ |
||||
/*
|
||||
* This code exists for the sole purpose to serve as another implementation |
||||
* of the "private" password hashing method implemened in PasswordHash.php |
||||
* and thus to confirm that these password hashes are indeed calculated as |
||||
* intended. |
||||
* |
||||
* Other uses of this code are discouraged. There are much better password |
||||
* hashing algorithms available to C programmers; one of those is bcrypt: |
||||
* |
||||
* http://www.openwall.com/crypt/
|
||||
* |
||||
* Written by Solar Designer <solar at openwall.com> in 2005 and placed in |
||||
* the public domain. |
||||
* |
||||
* There's absolutely no warranty. |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
#include <openssl/md5.h> |
||||
|
||||
#ifdef TEST |
||||
#include <stdio.h> |
||||
#endif |
||||
|
||||
static char *itoa64 = |
||||
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
||||
|
||||
static void encode64(char *dst, char *src, int count) |
||||
{ |
||||
int i, value; |
||||
|
||||
i = 0; |
||||
do { |
||||
value = (unsigned char)src[i++]; |
||||
*dst++ = itoa64[value & 0x3f]; |
||||
if (i < count) |
||||
value |= (unsigned char)src[i] << 8; |
||||
*dst++ = itoa64[(value >> 6) & 0x3f]; |
||||
if (i++ >= count) |
||||
break; |
||||
if (i < count) |
||||
value |= (unsigned char)src[i] << 16; |
||||
*dst++ = itoa64[(value >> 12) & 0x3f]; |
||||
if (i++ >= count) |
||||
break; |
||||
*dst++ = itoa64[(value >> 18) & 0x3f]; |
||||
} while (i < count); |
||||
} |
||||
|
||||
char *crypt_private(char *password, char *setting) |
||||
{ |
||||
static char output[35]; |
||||
MD5_CTX ctx; |
||||
char hash[MD5_DIGEST_LENGTH]; |
||||
char *p, *salt; |
||||
int count_log2, length, count; |
||||
|
||||
strcpy(output, "*0"); |
||||
if (!strncmp(setting, output, 2)) |
||||
output[1] = '1'; |
||||
|
||||
if (strncmp(setting, "$P$", 3)) |
||||
return output; |
||||
|
||||
p = strchr(itoa64, setting[3]); |
||||
if (!p) |
||||
return output; |
||||
count_log2 = p - itoa64; |
||||
if (count_log2 < 7 || count_log2 > 30) |
||||
return output; |
||||
|
||||
salt = setting + 4; |
||||
if (strlen(salt) < 8) |
||||
return output; |
||||
|
||||
length = strlen(password); |
||||
|
||||
MD5_Init(&ctx); |
||||
MD5_Update(&ctx, salt, 8); |
||||
MD5_Update(&ctx, password, length); |
||||
MD5_Final(hash, &ctx); |
||||
|
||||
count = 1 << count_log2; |
||||
do { |
||||
MD5_Init(&ctx); |
||||
MD5_Update(&ctx, hash, MD5_DIGEST_LENGTH); |
||||
MD5_Update(&ctx, password, length); |
||||
MD5_Final(hash, &ctx); |
||||
} while (--count); |
||||
|
||||
memcpy(output, setting, 12); |
||||
encode64(&output[12], hash, MD5_DIGEST_LENGTH); |
||||
|
||||
return output; |
||||
} |
||||
|
||||
#ifdef TEST |
||||
int main(int argc, char **argv) |
||||
{ |
||||
if (argc != 3) return 1; |
||||
|
||||
puts(crypt_private(argv[1], argv[2])); |
||||
|
||||
return 0; |
||||
} |
||||
#endif |
||||
@ -0,0 +1,72 @@ |
||||
<?php |
||||
# |
||||
# This is a test program for the portable PHP password hashing framework. |
||||
# |
||||
# Written by Solar Designer and placed in the public domain. |
||||
# See PasswordHash.php for more information. |
||||
# |
||||
|
||||
require 'PasswordHash.php'; |
||||
|
||||
header('Content-type: text/plain'); |
||||
|
||||
$ok = 0; |
||||
|
||||
# Try to use stronger but system-specific hashes, with a possible fallback to |
||||
# the weaker portable hashes. |
||||
$t_hasher = new PasswordHash(8, FALSE); |
||||
|
||||
$correct = 'test12345'; |
||||
$hash = $t_hasher->HashPassword($correct); |
||||
|
||||
print 'Hash: ' . $hash . "\n"; |
||||
|
||||
$check = $t_hasher->CheckPassword($correct, $hash); |
||||
if ($check) $ok++; |
||||
print "Check correct: '" . $check . "' (should be '1')\n"; |
||||
|
||||
$wrong = 'test12346'; |
||||
$check = $t_hasher->CheckPassword($wrong, $hash); |
||||
if (!$check) $ok++; |
||||
print "Check wrong: '" . $check . "' (should be '0' or '')\n"; |
||||
|
||||
unset($t_hasher); |
||||
|
||||
# Force the use of weaker portable hashes. |
||||
$t_hasher = new PasswordHash(8, TRUE); |
||||
|
||||
$hash = $t_hasher->HashPassword($correct); |
||||
|
||||
print 'Hash: ' . $hash . "\n"; |
||||
|
||||
$check = $t_hasher->CheckPassword($correct, $hash); |
||||
if ($check) $ok++; |
||||
print "Check correct: '" . $check . "' (should be '1')\n"; |
||||
|
||||
$check = $t_hasher->CheckPassword($wrong, $hash); |
||||
if (!$check) $ok++; |
||||
print "Check wrong: '" . $check . "' (should be '0' or '')\n"; |
||||
|
||||
# A correct portable hash for 'test12345'. |
||||
# Please note the use of single quotes to ensure that the dollar signs will |
||||
# be interpreted literally. Of course, a real application making use of the |
||||
# framework won't store password hashes within a PHP source file anyway. |
||||
# We only do this for testing. |
||||
$hash = '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0'; |
||||
|
||||
print 'Hash: ' . $hash . "\n"; |
||||
|
||||
$check = $t_hasher->CheckPassword($correct, $hash); |
||||
if ($check) $ok++; |
||||
print "Check correct: '" . $check . "' (should be '1')\n"; |
||||
|
||||
$check = $t_hasher->CheckPassword($wrong, $hash); |
||||
if (!$check) $ok++; |
||||
print "Check wrong: '" . $check . "' (should be '0' or '')\n"; |
||||
|
||||
if ($ok == 6) |
||||
print "All tests have PASSED\n"; |
||||
else |
||||
print "Some tests have FAILED\n"; |
||||
|
||||
?> |
||||
@ -0,0 +1,12 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
require_once('../../../../lib/base.php'); |
||||
OC_JSON::checkLoggedIn(); |
||||
$firstday = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstday', 'mo'); |
||||
OC_JSON::encodedPrint(array('firstday' => $firstday)); |
||||
?> |
||||
@ -0,0 +1,17 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
require_once('../../../../lib/base.php'); |
||||
OC_JSON::checkLoggedIn(); |
||||
if(isset($_POST["firstday"])){ |
||||
OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'firstday', $_POST["firstday"]); |
||||
OC_JSON::success(); |
||||
}else{ |
||||
OC_JSON::error(); |
||||
} |
||||
?> |
||||
|
||||
@ -1,26 +1,25 @@ |
||||
<?php |
||||
if(version_compare(PHP_VERSION, '5.3.0', '>=')){ |
||||
$l=new OC_L10N('calendar'); |
||||
OC::$CLASSPATH['OC_Calendar_App'] = 'apps/calendar/lib/app.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php'; |
||||
OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php'; |
||||
OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); |
||||
OC_Util::addScript('calendar','loader'); |
||||
OC_Util::addScript('3rdparty', 'chosen/chosen.jquery.min'); |
||||
OC_Util::addStyle('3rdparty', 'chosen/chosen'); |
||||
OC_App::register( array( |
||||
'order' => 10, |
||||
'id' => 'calendar', |
||||
'name' => 'Calendar' )); |
||||
OC_App::addNavigationEntry( array( |
||||
'id' => 'calendar_index', |
||||
'order' => 10, |
||||
'href' => OC_Helper::linkTo( 'calendar', 'index.php' ), |
||||
'icon' => OC_Helper::imagePath( 'calendar', 'icon.svg' ), |
||||
'name' => $l->t('Calendar'))); |
||||
OC_App::registerPersonal('calendar', 'settings'); |
||||
require_once('apps/calendar/lib/search.php'); |
||||
} |
||||
$l=new OC_L10N('calendar'); |
||||
OC::$CLASSPATH['OC_Calendar_App'] = 'apps/calendar/lib/app.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php'; |
||||
OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php'; |
||||
OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php'; |
||||
OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php'; |
||||
OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); |
||||
OC_Hook::connect('OC_DAV', 'initialize', 'OC_Calendar_Hooks', 'initializeCalDAV'); |
||||
OC_Util::addScript('calendar','loader'); |
||||
OC_App::register( array( |
||||
'order' => 10, |
||||
'id' => 'calendar', |
||||
'name' => 'Calendar' )); |
||||
OC_App::addNavigationEntry( array( |
||||
'id' => 'calendar_index', |
||||
'order' => 10, |
||||
'href' => OC_Helper::linkTo( 'calendar', 'index.php' ), |
||||
'icon' => OC_Helper::imagePath( 'calendar', 'icon.svg' ), |
||||
'name' => $l->t('Calendar'))); |
||||
OC_App::registerPersonal('calendar', 'settings'); |
||||
OC_Search::registerProvider('OC_Search_Provider_Calendar'); |
||||
|
||||
|
||||
@ -0,0 +1,14 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
OC::$CLASSPATH['OC_Archive'] = 'apps/files_archive/lib/archive.php'; |
||||
foreach(array('ZIP') as $type){ |
||||
OC::$CLASSPATH['OC_Archive_'.$type] = 'apps/files_archive/lib/'.strtolower($type).'.php'; |
||||
} |
||||
|
||||
OC::$CLASSPATH['OC_Filestorage_Archive']='apps/files_archive/lib/storage.php'; |
||||
@ -0,0 +1,10 @@ |
||||
<?xml version="1.0"?> |
||||
<info> |
||||
<id>files_archive</id> |
||||
<name>Archive support</name> |
||||
<description>Transparent opening of archives</description> |
||||
<version>0.1</version> |
||||
<licence>AGPL</licence> |
||||
<author>Robin Appelman</author> |
||||
<require>3</require> |
||||
</info> |
||||
@ -0,0 +1,99 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
abstract class OC_Archive{ |
||||
/** |
||||
* open any of the supporeted archive types |
||||
* @param string path |
||||
* @return OC_Archive |
||||
*/ |
||||
public static function open($path){ |
||||
$ext=substr($path,strrpos($path,'.')); |
||||
switch($ext){ |
||||
case '.zip': |
||||
return new OC_Archive_ZIP($path); |
||||
} |
||||
} |
||||
|
||||
abstract function __construct($source); |
||||
/** |
||||
* add an empty folder to the archive |
||||
* @param string path |
||||
* @return bool |
||||
*/ |
||||
abstract function addFolder($path); |
||||
/** |
||||
* add a file to the archive |
||||
* @param string path |
||||
* @param string source either a local file or string data |
||||
* @return bool |
||||
*/ |
||||
abstract function addFile($path,$source=''); |
||||
/** |
||||
* rename a file or folder in the archive |
||||
* @param string source |
||||
* @param string dest |
||||
* @return bool |
||||
*/ |
||||
abstract function rename($source,$dest); |
||||
/** |
||||
* get the uncompressed size of a file in the archive |
||||
* @param string path |
||||
* @return int |
||||
*/ |
||||
abstract function filesize($path); |
||||
/** |
||||
* get the last modified time of a file in the archive |
||||
* @param string path |
||||
* @return int |
||||
*/ |
||||
abstract function mtime($path); |
||||
/** |
||||
* get the files in a folder |
||||
* @param path |
||||
* @return array |
||||
*/ |
||||
abstract function getFolder($path); |
||||
/** |
||||
*get all files in the archive |
||||
* @return array |
||||
*/ |
||||
abstract function getFiles(); |
||||
/** |
||||
* get the content of a file |
||||
* @param string path |
||||
* @return string |
||||
*/ |
||||
abstract function getFile($path); |
||||
/** |
||||
* extract a single file from the archive |
||||
* @param string path |
||||
* @param string dest |
||||
* @return bool |
||||
*/ |
||||
abstract function extractFile($path,$dest); |
||||
/** |
||||
* check if a file or folder exists in the archive |
||||
* @param string path |
||||
* @return bool |
||||
*/ |
||||
abstract function fileExists($path); |
||||
/** |
||||
* remove a file or folder from the archive |
||||
* @param string path |
||||
* @return bool |
||||
*/ |
||||
abstract function remove($path); |
||||
/** |
||||
* get a file handler |
||||
* @param string path |
||||
* @param string mode |
||||
* @return resource |
||||
*/ |
||||
abstract function getStream($path,$mode); |
||||
} |
||||
@ -0,0 +1,102 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
class OC_Filestorage_Archive extends OC_Filestorage_Common{ |
||||
/** |
||||
* underlying local storage used for missing functions |
||||
* @var OC_Archive |
||||
*/ |
||||
private $archive; |
||||
private $path; |
||||
|
||||
private function stripPath($path){//files should never start with / |
||||
if(substr($path,0,1)=='/'){ |
||||
return substr($path,1); |
||||
} |
||||
return $path; |
||||
} |
||||
|
||||
public function __construct($params){ |
||||
$this->archive=OC_Archive::open($params['archive']); |
||||
$this->path=$params['archive']; |
||||
} |
||||
|
||||
public function mkdir($path){ |
||||
$path=$this->stripPath($path); |
||||
return $this->archive->addFolder($path); |
||||
} |
||||
public function rmdir($path){ |
||||
$path=$this->stripPath($path); |
||||
return $this->archive->remove($path.'/'); |
||||
} |
||||
public function opendir($path){ |
||||
$path=$this->stripPath($path); |
||||
$content=$this->archive->getFolder($path); |
||||
foreach($content as &$file){ |
||||
if(substr($file,-1)=='/'){ |
||||
$file=substr($file,0,-1); |
||||
} |
||||
} |
||||
$id=md5($this->path.$path); |
||||
OC_FakeDirStream::$dirs[$id]=$content; |
||||
return opendir('fakedir://'.$id); |
||||
} |
||||
public function stat($path){ |
||||
$ctime=filectime($this->path); |
||||
$path=$this->stripPath($path); |
||||
if($path==''){ |
||||
$stat=stat($this->path); |
||||
}else{ |
||||
$stat=array(); |
||||
$stat['mtime']=$this->archive->mtime($path); |
||||
$stat['size']=$this->archive->filesize($path); |
||||
} |
||||
$stat['ctime']=$ctime; |
||||
return $stat; |
||||
} |
||||
public function filetype($path){ |
||||
$path=$this->stripPath($path); |
||||
if($path==''){ |
||||
return 'dir'; |
||||
} |
||||
return $this->archive->fileExists($path.'/')?'dir':'file'; |
||||
} |
||||
public function is_readable($path){ |
||||
return is_readable($this->path); |
||||
} |
||||
public function is_writable($path){ |
||||
return is_writable($this->path); |
||||
} |
||||
public function file_exists($path){ |
||||
$path=$this->stripPath($path); |
||||
if($path==''){ |
||||
return file_exists($this->path); |
||||
} |
||||
return $this->archive->fileExists($path) or $this->archive->fileExists($path.'/'); |
||||
} |
||||
public function unlink($path){ |
||||
$path=$this->stripPath($path); |
||||
return $this->archive->remove($path); |
||||
} |
||||
public function fopen($path,$mode){ |
||||
$path=$this->stripPath($path); |
||||
return $this->archive->getStream($path,$mode); |
||||
} |
||||
public function free_space($path){ |
||||
return 0; |
||||
} |
||||
public function touch($path, $mtime=null){ |
||||
if(is_null($mtime)){ |
||||
$tmpFile=OC_Helper::tmpFile(); |
||||
$this->archive->extractFile($path,$tmpFile); |
||||
$this->archive->addfile($path,$tmpFile); |
||||
}else{ |
||||
return false;//not supported |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,182 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
class OC_Archive_ZIP extends OC_Archive{ |
||||
/** |
||||
* @var ZipArchive zip |
||||
*/ |
||||
private $zip=null; |
||||
private $contents=array(); |
||||
private $success=false; |
||||
private $path; |
||||
|
||||
function __construct($source){ |
||||
$this->path=$source; |
||||
$this->zip=new ZipArchive(); |
||||
if($this->zip->open($source,ZipArchive::CREATE)){ |
||||
}else{ |
||||
OC_LOG::write('files_archive','Error while opening archive '.$source,OC_Log::WARN); |
||||
} |
||||
} |
||||
/** |
||||
* add an empty folder to the archive |
||||
* @param string path |
||||
* @return bool |
||||
*/ |
||||
function addFolder($path){ |
||||
return $this->zip->addEmptyDir($path); |
||||
} |
||||
/** |
||||
* add a file to the archive |
||||
* @param string path |
||||
* @param string source either a local file or string data |
||||
* @return bool |
||||
*/ |
||||
function addFile($path,$source=''){ |
||||
if(file_exists($source)){ |
||||
$result=$this->zip->addFile($source,$path); |
||||
}else{ |
||||
$result=$this->zip->addFromString($path,$source); |
||||
} |
||||
if($result){ |
||||
$this->zip->close();//close and reopen to save the zip |
||||
$this->zip->open($this->path); |
||||
} |
||||
return $result; |
||||
} |
||||
/** |
||||
* rename a file or folder in the archive |
||||
* @param string source |
||||
* @param string dest |
||||
* @return bool |
||||
*/ |
||||
function rename($source,$dest){ |
||||
return $this->zip->renameName($source,$dest); |
||||
} |
||||
/** |
||||
* get the uncompressed size of a file in the archive |
||||
* @param string path |
||||
* @return int |
||||
*/ |
||||
function filesize($path){ |
||||
$stat=$this->zip->statName($path); |
||||
return $stat['size']; |
||||
} |
||||
/** |
||||
* get the last modified time of a file in the archive |
||||
* @param string path |
||||
* @return int |
||||
*/ |
||||
function mtime($path){ |
||||
$stat=$this->zip->statName($path); |
||||
return $stat['mtime']; |
||||
} |
||||
/** |
||||
* get the files in a folder |
||||
* @param path |
||||
* @return array |
||||
*/ |
||||
function getFolder($path){ |
||||
$files=$this->getFiles(); |
||||
$folderContent=array(); |
||||
$pathLength=strlen($path); |
||||
foreach($files as $file){ |
||||
if(substr($file,0,$pathLength)==$path and $file!=$path){ |
||||
if(strrpos(substr($file,0,-1),'/')<=$pathLength){ |
||||
$folderContent[]=substr($file,$pathLength); |
||||
} |
||||
} |
||||
} |
||||
return $folderContent; |
||||
} |
||||
/** |
||||
*get all files in the archive |
||||
* @return array |
||||
*/ |
||||
function getFiles(){ |
||||
if(count($this->contents)){ |
||||
return $this->contents; |
||||
} |
||||
$fileCount=$this->zip->numFiles; |
||||
$files=array(); |
||||
for($i=0;$i<$fileCount;$i++){ |
||||
$files[]=$this->zip->getNameIndex($i); |
||||
} |
||||
$this->contents=$files; |
||||
return $files; |
||||
} |
||||
/** |
||||
* get the content of a file |
||||
* @param string path |
||||
* @return string |
||||
*/ |
||||
function getFile($path){ |
||||
return $this->zip->getFromName($path); |
||||
} |
||||
/** |
||||
* extract a single file from the archive |
||||
* @param string path |
||||
* @param string dest |
||||
* @return bool |
||||
*/ |
||||
function extractFile($path,$dest){ |
||||
$fp = $this->zip->getStream($path); |
||||
file_put_contents($dest,$fp); |
||||
} |
||||
/** |
||||
* check if a file or folder exists in the archive |
||||
* @param string path |
||||
* @return bool |
||||
*/ |
||||
function fileExists($path){ |
||||
return $this->zip->locateName($path)!==false; |
||||
} |
||||
/** |
||||
* remove a file or folder from the archive |
||||
* @param string path |
||||
* @return bool |
||||
*/ |
||||
function remove($path){ |
||||
return $this->zip->deleteName($path); |
||||
} |
||||
/** |
||||
* get a file handler |
||||
* @param string path |
||||
* @param string mode |
||||
* @return resource |
||||
*/ |
||||
function getStream($path,$mode){ |
||||
if($mode=='r' or $mode=='rb'){ |
||||
return $this->zip->getStream($path); |
||||
}else{//since we cant directly get a writable stream, make a temp copy of the file and put it back in the archive when the stream is closed |
||||
if(strrpos($path,'.')!==false){ |
||||
$ext=substr($path,strrpos($path,'.')); |
||||
}else{ |
||||
$ext=''; |
||||
} |
||||
$tmpFile=OC_Helper::tmpFile($ext); |
||||
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); |
||||
if($this->fileExists($path)){ |
||||
$this->extractFile($path,$tmpFile); |
||||
} |
||||
self::$tempFiles[$tmpFile]=$path; |
||||
return fopen('close://'.$tmpFile,$mode); |
||||
} |
||||
} |
||||
|
||||
private static $tempFiles=array(); |
||||
/** |
||||
* write back temporary files |
||||
*/ |
||||
function writeBack($tmpFile){ |
||||
if(isset(self::$tempFiles[$tmpFile])){ |
||||
$this->addFile(self::$tempFiles[$tmpFile],$tmpFile); |
||||
unlink($tmpFile); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,97 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
abstract class Test_Archive extends UnitTestCase { |
||||
/** |
||||
* @var OC_Archive |
||||
*/ |
||||
protected $instance; |
||||
|
||||
/** |
||||
* get the existing test archive |
||||
* @return OC_Archive |
||||
*/ |
||||
abstract protected function getExisting(); |
||||
/** |
||||
* get a new archive for write testing |
||||
* @return OC_Archive |
||||
*/ |
||||
abstract protected function getNew(); |
||||
|
||||
public function testGetFiles(){ |
||||
$this->instance=$this->getExisting(); |
||||
$allFiles=$this->instance->getFiles(); |
||||
$expected=array('lorem.txt','logo-wide.png','dir/','dir/lorem.txt'); |
||||
$this->assertEqual(4,count($allFiles)); |
||||
foreach($expected as $file){ |
||||
$this->assertNotIdentical(false,array_search($file,$allFiles),'cant find '.$file.' in archive'); |
||||
$this->assertTrue($this->instance->fileExists($file)); |
||||
} |
||||
$this->assertFalse($this->instance->fileExists('non/existing/file')); |
||||
|
||||
$rootContent=$this->instance->getFolder(''); |
||||
$expected=array('lorem.txt','logo-wide.png','dir/'); |
||||
$this->assertEqual(3,count($rootContent)); |
||||
foreach($expected as $file){ |
||||
$this->assertNotIdentical(false,array_search($file,$rootContent),'cant find '.$file.' in archive'); |
||||
} |
||||
|
||||
$dirContent=$this->instance->getFolder('dir/'); |
||||
$expected=array('lorem.txt'); |
||||
$this->assertEqual(1,count($dirContent)); |
||||
foreach($expected as $file){ |
||||
$this->assertNotIdentical(false,array_search($file,$dirContent),'cant find '.$file.' in archive'); |
||||
} |
||||
} |
||||
|
||||
public function testContent(){ |
||||
$this->instance=$this->getExisting(); |
||||
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; |
||||
$textFile=$dir.'/lorem.txt'; |
||||
$this->assertEqual(file_get_contents($textFile),$this->instance->getFile('lorem.txt')); |
||||
|
||||
$tmpFile=OC_Helper::tmpFile('.txt'); |
||||
$this->instance->extractFile('lorem.txt',$tmpFile); |
||||
$this->assertEqual(file_get_contents($textFile),file_get_contents($tmpFile)); |
||||
} |
||||
|
||||
public function testWrite(){ |
||||
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; |
||||
$textFile=$dir.'/lorem.txt'; |
||||
$this->instance=$this->getNew(); |
||||
$this->assertEqual(0,count($this->instance->getFiles())); |
||||
$this->instance->addFile('lorem.txt',$textFile); |
||||
$this->assertEqual(1,count($this->instance->getFiles())); |
||||
$this->assertTrue($this->instance->fileExists('lorem.txt')); |
||||
|
||||
$this->assertEqual(file_get_contents($textFile),$this->instance->getFile('lorem.txt')); |
||||
$this->instance->addFile('lorem.txt','foobar'); |
||||
$this->assertEqual('foobar',$this->instance->getFile('lorem.txt')); |
||||
} |
||||
|
||||
public function testReadStream(){ |
||||
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; |
||||
$this->instance=$this->getExisting(); |
||||
$fh=$this->instance->getStream('lorem.txt','r'); |
||||
$this->assertTrue($fh); |
||||
$content=fread($fh,$this->instance->filesize('lorem.txt')); |
||||
fclose($fh); |
||||
$this->assertEqual(file_get_contents($dir.'/lorem.txt'),$content); |
||||
} |
||||
public function testWriteStream(){ |
||||
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; |
||||
$this->instance=$this->getNew(); |
||||
$fh=$this->instance->getStream('lorem.txt','w'); |
||||
$source=fopen($dir.'/lorem.txt','r'); |
||||
OC_Helper::streamCopy($source,$fh); |
||||
fclose($source); |
||||
fclose($fh); |
||||
$this->assertTrue($this->instance->fileExists('lorem.txt')); |
||||
$this->assertEqual(file_get_contents($dir.'/lorem.txt'),$this->instance->getFile('lorem.txt')); |
||||
} |
||||
} |
||||
@ -0,0 +1,25 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
class Test_Filestorage_Archive_Zip extends Test_FileStorage { |
||||
/** |
||||
* @var string tmpDir |
||||
*/ |
||||
private $tmpFile; |
||||
|
||||
public function setUp(){ |
||||
$this->tmpFile=OC_Helper::tmpFile('.zip'); |
||||
$this->instance=new OC_Filestorage_Archive(array('archive'=>$this->tmpFile)); |
||||
} |
||||
|
||||
public function tearDown(){ |
||||
unlink($this->tmpFile); |
||||
} |
||||
} |
||||
|
||||
?> |
||||
@ -0,0 +1,20 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
require_once('archive.php'); |
||||
|
||||
class Test_Archive_ZIP extends Test_Archive{ |
||||
protected function getExisting(){ |
||||
$dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; |
||||
return new OC_Archive_ZIP($dir.'/data.zip'); |
||||
} |
||||
|
||||
protected function getNew(){ |
||||
return new OC_Archive_ZIP(OC_Helper::tmpFile('.zip')); |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
OC::$CLASSPATH['OC_Crypt'] = 'apps/files_encryption/lib/crypt.php'; |
||||
OC::$CLASSPATH['OC_CryptStream'] = 'apps/files_encryption/lib/cryptstream.php'; |
||||
OC::$CLASSPATH['OC_FileProxy_Encryption'] = 'apps/files_encryption/lib/proxy.php'; |
||||
|
||||
OC_FileProxy::register(new OC_FileProxy_Encryption()); |
||||
|
||||
OC_Hook::connect('OC_User','post_login','OC_Crypt','loginListener'); |
||||
|
||||
stream_wrapper_register('crypt','OC_CryptStream'); |
||||
|
||||
if(!isset($_SESSION['enckey']) and OC_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) |
||||
OC_User::logout(); |
||||
header("Location: ".OC::$WEBROOT.'/'); |
||||
exit(); |
||||
} |
||||
|
||||
OC_App::registerAdmin('files_encryption', 'settings'); |
||||
@ -0,0 +1,10 @@ |
||||
<?xml version="1.0"?> |
||||
<info> |
||||
<id>files_encryption</id> |
||||
<name>Encryption</name> |
||||
<description>Server side encryption of files</description> |
||||
<version>0.1</version> |
||||
<licence>AGPL</licence> |
||||
<author>Robin Appelman</author> |
||||
<require>3</require> |
||||
</info> |
||||
@ -0,0 +1,19 @@ |
||||
/** |
||||
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com> |
||||
* This file is licensed under the Affero General Public License version 3 or later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
|
||||
$(document).ready(function(){ |
||||
$('#encryption_blacklist').multiSelect({ |
||||
oncheck:blackListChange, |
||||
onuncheck:blackListChange, |
||||
createText:'...', |
||||
}); |
||||
|
||||
function blackListChange(){ |
||||
var blackList=$('#encryption_blacklist').val().join(','); |
||||
OC.AppConfig.setValue('files_encryption','type_blacklist',blackList); |
||||
} |
||||
}) |
||||
@ -0,0 +1,153 @@ |
||||
<?php |
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Robin Appelman |
||||
* @copyright 2011 Robin Appelman icewind1991@gmail.com |
||||
* |
||||
* 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/>. |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* transparently encrypted filestream |
||||
* |
||||
* you can use it as wrapper around an existing stream by setting OC_CryptStream::$sourceStreams['foo']=array('path'=>$path,'stream'=>$stream) |
||||
* and then fopen('crypt://streams/foo'); |
||||
*/ |
||||
|
||||
class OC_CryptStream{ |
||||
public static $sourceStreams=array(); |
||||
private $source; |
||||
private $path; |
||||
private $readBuffer;//for streams that dont support seeking |
||||
private $meta=array();//header/meta for source stream |
||||
|
||||
public function stream_open($path, $mode, $options, &$opened_path){ |
||||
$path=str_replace('crypt://','',$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']; |
||||
}else{ |
||||
$this->path=$path; |
||||
OC_Log::write('files_encryption','open encrypted '.$path. ' in '.$mode,OC_Log::DEBUG); |
||||
OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file |
||||
$this->source=OC_FileSystem::fopen($path,$mode); |
||||
OC_FileProxy::$enabled=true; |
||||
if(!is_resource($this->source)){ |
||||
OC_Log::write('files_encryption','failed to open '.$path,OC_Log::ERROR); |
||||
} |
||||
} |
||||
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){ |
||||
fseek($this->source,$offset,$whence); |
||||
} |
||||
|
||||
public function stream_tell(){ |
||||
return ftell($this->source); |
||||
} |
||||
|
||||
public function stream_read($count){ |
||||
$pos=0; |
||||
$currentPos=ftell($this->source); |
||||
$offset=$currentPos%8192; |
||||
$result=''; |
||||
if($offset>0){ |
||||
if($this->meta['seekable']){ |
||||
fseek($this->source,-$offset,SEEK_CUR);//if seeking isnt supported the internal read buffer will be used |
||||
}else{ |
||||
$pos=strlen($this->readBuffer); |
||||
$result=$this->readBuffer; |
||||
} |
||||
} |
||||
while($count>$pos){ |
||||
$data=fread($this->source,8192); |
||||
$pos+=8192; |
||||
if(strlen($data)){ |
||||
$result.=OC_Crypt::decrypt($data); |
||||
} |
||||
} |
||||
if(!$this->meta['seekable']){ |
||||
$this->readBuffer=substr($result,$count); |
||||
} |
||||
return substr($result,0,$count); |
||||
} |
||||
|
||||
public function stream_write($data){ |
||||
$length=strlen($data); |
||||
$written=0; |
||||
$currentPos=ftell($this->source); |
||||
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); |
||||
fseek($this->source,-($currentPos%8192),SEEK_CUR); |
||||
$block=OC_Crypt::decrypt($encryptedBlock); |
||||
$data=substr($block,0,$currentPos%8192).$data; |
||||
} |
||||
while(strlen($data)>0){ |
||||
if(strlen($data)<8192){ |
||||
//fetch the current data in that block and append it to the input so we always write entire blocks |
||||
$oldPos=ftell($this->source); |
||||
$encryptedBlock=fread($this->source,8192); |
||||
fseek($this->source,$oldPos); |
||||
$block=OC_Crypt::decrypt($encryptedBlock); |
||||
$data.=substr($block,strlen($data)); |
||||
} |
||||
$encrypted=OC_Crypt::encrypt(substr($data,0,8192)); |
||||
fwrite($this->source,$encrypted); |
||||
$data=substr($data,8192); |
||||
} |
||||
return $length; |
||||
} |
||||
|
||||
public function stream_set_option($option,$arg1,$arg2){ |
||||
switch($option){ |
||||
case STREAM_OPTION_BLOCKING: |
||||
stream_set_blocking($this->source,$arg1); |
||||
break; |
||||
case STREAM_OPTION_READ_TIMEOUT: |
||||
stream_set_timeout($this->source,$arg1,$arg2); |
||||
break; |
||||
case STREAM_OPTION_WRITE_BUFFER: |
||||
stream_set_write_buffer($this->source,$arg1,$arg2); |
||||
} |
||||
} |
||||
|
||||
public function stream_stat(){ |
||||
return fstat($this->source); |
||||
} |
||||
|
||||
public function stream_lock($mode){ |
||||
flock($this->source,$mode); |
||||
} |
||||
|
||||
public function stream_flush(){ |
||||
return fflush($this->source); |
||||
} |
||||
|
||||
public function stream_eof(){ |
||||
return feof($this->source); |
||||
} |
||||
|
||||
public function stream_close(){ |
||||
OC_FileCache::put($this->path,array('encrypted'=>true)); |
||||
return fclose($this->source); |
||||
} |
||||
} |
||||
@ -0,0 +1,115 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Robin Appelman |
||||
* @copyright 2011 Robin Appelman icewind1991@gmail.com |
||||
* |
||||
* 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/>. |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* transparent encryption |
||||
*/ |
||||
|
||||
class OC_FileProxy_Encryption extends OC_FileProxy{ |
||||
private static $blackList=null; //mimetypes blacklisted from encryption |
||||
private static $metaData=array(); //metadata cache |
||||
|
||||
/** |
||||
* check if a file should be encrypted during write |
||||
* @param string $path |
||||
* @return bool |
||||
*/ |
||||
private static function shouldEncrypt($path){ |
||||
if(is_null(self::$blackList)){ |
||||
self::$blackList=explode(',',OC_Appconfig::getValue('files_encryption','type_blacklist','jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); |
||||
} |
||||
if(self::isEncrypted($path)){ |
||||
return true; |
||||
} |
||||
$extention=substr($path,strrpos($path,'.')+1); |
||||
if(array_search($extention,self::$blackList)===false){ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* check if a file is encrypted |
||||
* @param string $path |
||||
* @return bool |
||||
*/ |
||||
private static function isEncrypted($path){ |
||||
if(isset(self::$metaData[$path])){ |
||||
$metadata=self::$metaData[$path]; |
||||
}else{ |
||||
$metadata=OC_FileCache::getCached($path); |
||||
self::$metaData[$path]=$metadata; |
||||
} |
||||
return (bool)$metadata['encrypted']; |
||||
} |
||||
|
||||
public function preFile_put_contents($path,&$data){ |
||||
if(self::shouldEncrypt($path)){ |
||||
if (!is_resource($data)) {//stream put contents should have been converter to fopen |
||||
$data=OC_Crypt::blockEncrypt($data); |
||||
OC_FileCache::put($path,array('encrypted'=>true)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public function postFile_get_contents($path,$data){ |
||||
if(self::isEncrypted($path)){ |
||||
$data=OC_Crypt::blockDecrypt($data); |
||||
} |
||||
return $data; |
||||
} |
||||
|
||||
public function postFopen($path,&$result){ |
||||
if(!$result){ |
||||
return $result; |
||||
} |
||||
$meta=stream_get_meta_data($result); |
||||
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){ |
||||
//first encrypt the target file so we don't end up with a half encrypted file |
||||
OC_Log::write('files_encryption','Decrypting '.$path.' before writing',OC_Log::DEBUG); |
||||
$tmp=fopen('php://temp'); |
||||
while(!feof($result)){ |
||||
$chunk=fread($result,8192); |
||||
if($chunk){ |
||||
fwrite($tmp,$chunk); |
||||
} |
||||
} |
||||
fclose($result); |
||||
OC_Filesystem::file_put_contents($path,$tmp); |
||||
fclose($tmp); |
||||
} |
||||
$result=fopen('crypt://'.$path,$meta['mode']); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
public function postGetMimeType($path,$mime){ |
||||
if(self::isEncrypted($path)){ |
||||
$mime=OC_Helper::getMimeType('crypt://'.$path,'w'); |
||||
} |
||||
return $mime; |
||||
} |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2011 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
$tmpl = new OC_Template( 'files_encryption', 'settings'); |
||||
$blackList=explode(',',OC_Appconfig::getValue('files_encryption','type_blacklist','jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); |
||||
$tmpl->assign('blacklist',$blackList); |
||||
|
||||
OC_Util::addScript('files_encryption','settings'); |
||||
OC_Util::addScript('core','multiselect'); |
||||
|
||||
return $tmpl->fetchPage(); |
||||
@ -0,0 +1,11 @@ |
||||
<form id="calendar"> |
||||
<fieldset class="personalblock"> |
||||
<strong><?php echo $l->t('Encryption'); ?></strong>
|
||||
<?php echo $l->t("Exclude the following file types from encryption"); ?> |
||||
<select id='encryption_blacklist' title="<?php echo $l->t('None')?>" multiple="multiple">
|
||||
<?php foreach($_["blacklist"] as $type): ?> |
||||
<option selected="selected" value="<?php echo $type;?>"><?php echo $type;?></option>
|
||||
<?php endforeach;?> |
||||
</select> |
||||
</fieldset> |
||||
</form> |
||||
@ -0,0 +1,61 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* HTTP Bearer Authentication handler |
||||
* |
||||
* Use this class for easy http authentication setup |
||||
* |
||||
* @package Sabre |
||||
* @subpackage HTTP |
||||
* @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. |
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/) |
||||
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License |
||||
*/ |
||||
class Sabre_HTTP_BearerAuth extends Sabre_HTTP_AbstractAuth { |
||||
|
||||
/** |
||||
* Returns the supplied username and password. |
||||
* |
||||
* The returned array has two values: |
||||
* * 0 - username |
||||
* * 1 - password |
||||
* |
||||
* If nothing was supplied, 'false' will be returned |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function getUserPass() { |
||||
|
||||
// Apache and mod_php |
||||
if (($user = $this->httpRequest->getRawServerValue('PHP_AUTH_USER')) && ($pass = $this->httpRequest->getRawServerValue('PHP_AUTH_PW'))) { |
||||
|
||||
return array($user,$pass); |
||||
|
||||
} |
||||
|
||||
// Most other webservers |
||||
$auth = $this->httpRequest->getHeader('Authorization'); |
||||
|
||||
if (!$auth) return false; |
||||
|
||||
if (strpos(strtolower($auth),'bearer')!==0) return false; |
||||
|
||||
return explode(':', base64_decode(substr($auth, 7))); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Returns an HTTP 401 header, forcing login |
||||
* |
||||
* This should be called when username and password are incorrect, or not supplied at all |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function requireLogin() { |
||||
|
||||
$this->httpResponse->setHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"'); |
||||
$this->httpResponse->sendStatus(401); |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ownCloud |
||||
* |
||||
* Original: |
||||
* @author Frank Karlitschek |
||||
* @copyright 2010 Frank Karlitschek karlitschek@kde.org |
||||
* |
||||
* Adapted: |
||||
* @author Michiel de Jong, 2012 |
||||
* |
||||
* 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/>. |
||||
* |
||||
*/ |
||||
|
||||
|
||||
// Do not load FS ... |
||||
$RUNTIME_NOSETUPFS = true; |
||||
|
||||
require_once('../../../lib/base.php'); |
||||
OC_Util::checkAppEnabled('remoteStorage'); |
||||
require_once('Sabre/autoload.php'); |
||||
require_once('../lib_remoteStorage.php'); |
||||
|
||||
ini_set('default_charset', 'UTF-8'); |
||||
#ini_set('error_reporting', ''); |
||||
@ob_clean(); |
||||
|
||||
echo OC_remoteStorage::deleteToken(file_get_contents("php://input")); |
||||
@ -0,0 +1,8 @@ |
||||
h2 { font-size:2em; font-weight:bold; margin-bottom:1em; white-space:nowrap; } |
||||
ul.scopes { list-style:disc; } |
||||
ul.scopes li { white-space:nowrap; } |
||||
h2 img { width: 50% } |
||||
#oauth { margin:4em auto 2em; width:20em; } |
||||
#allow-auth { background-color:#5c3; text-shadow:#5e3 0 1px 0; color:#fff; |
||||
-webkit-box-shadow:0 1px 1px #fff, 0 1px 1px #5f3 inset; -moz-box-shadow:0 1px 1px #fff, 0 1px 1px #5f3 inset; box-shadow:0 1px 1px #fff, 0 1px 1px #5f3 inset; } |
||||
#deny-auth { padding:0; margin:.7em; border:0; background:none; font-size:1.2em; -moz-box-shadow: 0 0 0 #fff, 0 0 0 #fff inset; -webkit-box-shadow: 0 0 0 #fff, 0 0 0 #fff inset; box-shadow: 0 0 0 #fff, 0 0 0 #fff inset; } |
||||
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
@ -0,0 +1,7 @@ |
||||
<?php |
||||
|
||||
require_once('lib_remoteStorage.php'); |
||||
$tmpl = new OC_Template( 'remoteStorage', 'settings'); |
||||
|
||||
return $tmpl->fetchPage(); |
||||
?> |
||||
@ -0,0 +1,28 @@ |
||||
<fieldset class="personalblock"> |
||||
<?php |
||||
echo '<img src="/apps/remoteStorage/remoteStorage.png" style="width:16px"> ' |
||||
.'<strong>'.$l->t('remoteStorage').'</strong> user address: ' |
||||
.OC_User::getUser().'@'.$_SERVER['SERVER_NAME'] |
||||
.' (<a href="http://unhosted.org/">more info</a>)'; |
||||
?> |
||||
<p><em>Apps that currently have access to your ownCloud:</em></p> |
||||
<script> |
||||
function revokeToken(token) { |
||||
var xhr = new XMLHttpRequest(); |
||||
xhr.open('POST', '/apps/remoteStorage/ajax/revokeToken.php', true); |
||||
xhr.send(token); |
||||
} |
||||
</script> |
||||
<ul> |
||||
<?php |
||||
foreach(OC_remoteStorage::getAllTokens() as $token => $details) { |
||||
echo '<li onmouseover="' |
||||
.'document.getElementById(\'revoke_'.$token.'\').style.display=\'inline\';"' |
||||
.'onmouseout="document.getElementById(\'revoke_'.$token.'\').style.display=\'none\';"' |
||||
.'> <strong>'.$details['appUrl'].'</strong>: '.$details['categories'] |
||||
.' <a href="#" title="Revoke" class="action" style="display:none" id="revoke_'.$token.'" onclick="' |
||||
.'revokeToken(\''.$token.'\');this.parentNode.style.display=\'none\';"' |
||||
.'><img src="/core/img/actions/delete.svg"></a></li>'."\n"; |
||||
} |
||||
?></ul> |
||||
</fieldset> |
||||
@ -0,0 +1,35 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com> |
||||
* This file is licensed under the Affero General Public License version 3 or later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
require_once ("../../lib/base.php"); |
||||
OC_JSON::checkLoggedIn(); |
||||
$action=isset($_POST['action'])?$_POST['action']:$_GET['action']; |
||||
$result=false; |
||||
switch($action){ |
||||
case 'getValue': |
||||
$result=OC_Appconfig::getValue($_GET['app'],$_GET['key'],$_GET['default']); |
||||
break; |
||||
case 'setValue': |
||||
$result=OC_Appconfig::setValue($_POST['app'],$_POST['key'],$_POST['value']); |
||||
break; |
||||
case 'getApps': |
||||
$result=OC_Appconfig::getApps(); |
||||
break; |
||||
case 'getKeys': |
||||
$result=OC_Appconfig::getKeys($_GET['app']); |
||||
break; |
||||
case 'hasKey': |
||||
$result=OC_Appconfig::hasKey($_GET['app'],$_GET['key']); |
||||
break; |
||||
case 'deleteKey': |
||||
$result=OC_Appconfig::deleteKey($_POST['app'],$_POST['key']); |
||||
break; |
||||
case 'deleteApp': |
||||
$result=OC_Appconfig::deleteApp($_POST['app']); |
||||
break; |
||||
} |
||||
OC_JSON::success(array('data'=>$result)); |
||||
@ -0,0 +1,55 @@ |
||||
/** |
||||
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com> |
||||
* This file is licensed under the Affero General Public License version 3 or later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
OC.AppConfig={ |
||||
url:OC.filePath('core','ajax','appconfig.php'), |
||||
getCall:function(action,data,callback){ |
||||
data.action=action; |
||||
$.getJSON(OC.AppConfig.url,data,function(result){ |
||||
if(result.status='success'){ |
||||
if(callback){ |
||||
callback(result.data); |
||||
} |
||||
} |
||||
}); |
||||
}, |
||||
postCall:function(action,data,callback){ |
||||
data.action=action; |
||||
$.post(OC.AppConfig.url,data,function(result){ |
||||
if(result.status='success'){ |
||||
if(callback){ |
||||
callback(result.data); |
||||
} |
||||
} |
||||
},'json'); |
||||
}, |
||||
getValue:function(app,key,defaultValue,callback){ |
||||
if(typeof defaultValue=='function'){ |
||||
callback=defaultValue; |
||||
defaultValue=null; |
||||
} |
||||
OC.AppConfig.getCall('getValue',{app:app,key:key,default:defaultValue},callback); |
||||
}, |
||||
setValue:function(app,key,value){ |
||||
OC.AppConfig.postCall('setValue',{app:app,key:key,value:value}); |
||||
}, |
||||
getApps:function(callback){ |
||||
OC.AppConfig.getCall('getApps',{},callback); |
||||
}, |
||||
getKeys:function(app,callback){ |
||||
OC.AppConfig.getCall('getKeys',{app:app},callback); |
||||
}, |
||||
hasKey:function(app,key,callback){ |
||||
OC.AppConfig.getCall('hasKey',{app:app,key:key},callback); |
||||
}, |
||||
deleteKey:function(app,key){ |
||||
OC.AppConfig.postCall('deleteKey',{app:app,key:key}); |
||||
}, |
||||
deleteApp:function(app){ |
||||
OC.AppConfig.postCall('deleteApp',{app:app}); |
||||
}, |
||||
} |
||||
//TODO OC.Preferences
|
||||
@ -0,0 +1,145 @@ |
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Bartek Przybylski |
||||
* @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com |
||||
* |
||||
* 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/>.
|
||||
* |
||||
* todo(bartek): add select option in form |
||||
*/ |
||||
|
||||
/** |
||||
* this class ease usage of jquery dialogs |
||||
*/ |
||||
OCdialogs = { |
||||
/** |
||||
* displays alert dialog |
||||
* @param text content of dialog |
||||
* @param title dialog title |
||||
* @param callback which will be triggered when user press OK |
||||
*/ |
||||
alert:function(text, title, callback) { |
||||
var content = '<p><span class="ui-icon ui-icon-alert"></span>'+text+'</p>'; |
||||
OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback); |
||||
}, |
||||
/** |
||||
* displays info dialog |
||||
* @param text content of dialog |
||||
* @param title dialog title |
||||
* @param callback which will be triggered when user press OK |
||||
*/ |
||||
info:function(text, title, callback) { |
||||
var content = '<p><span class="ui-icon ui-icon-info"></span>'+text+'</p>'; |
||||
OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.OK_BUTTON, callback); |
||||
}, |
||||
/** |
||||
* displays confirmation dialog |
||||
* @param text content of dialog |
||||
* @param title dialog title |
||||
* @param callback which will be triggered when user press YES or NO (true or false would be passed to callback respectively) |
||||
*/ |
||||
confirm:function(text, title, callback) { |
||||
var content = '<p><span class="ui-icon ui-icon-notice"></span>'+text+'</p>'; |
||||
OCdialogs.message(content, title, OCdialogs.ALERT_DIALOG, OCdialogs.YES_NO_BUTTON, callback); |
||||
}, |
||||
/** |
||||
* prompt for user input |
||||
* @param text content of dialog |
||||
* @param title dialog title |
||||
* @param callback which will be triggered when user press OK (input text will be passed to callback) |
||||
*/ |
||||
prompt:function(text, title, callback) { |
||||
var content = '<p><span class="ui-icon ui-icon-pencil"></span>'+text+':<br/><input type="text" id="oc-dialog-prompt-input" style="width:90%"></p>'; |
||||
OCdialogs.message(content, title, OCdialogs.PROMPT_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); |
||||
}, |
||||
/** |
||||
* prompt user for input with custom form |
||||
* fields should be passed in following format: [{text:'prompt text', name:'return name', type:'input type'},...] |
||||
* @param fields to display
|
||||
* @param title dialog title |
||||
* @param callback which will be triggered when user press OK (user answers will be passed to callback in following format: [{name:'return name', value: 'user value'},...]) |
||||
*/ |
||||
form:function(fields, title, callback) { |
||||
var content = '<table>'; |
||||
for (var a in fields) { |
||||
content += '<tr><td>'+fields[a].text+'</td><td>'; |
||||
var type=fields[a].type; |
||||
if (type == 'text' || type == 'checkbox' || type == 'password') |
||||
content += '<input type="'+type+'" name="'+fields[a].name+'">'; |
||||
content += "</td></tr>" |
||||
} |
||||
content += "</table>"; |
||||
OCdialogs.message(content, title, OCdialogs.FORM_DIALOG, OCdialogs.OK_CANCEL_BUTTONS, callback); |
||||
}, |
||||
message:function(content, title, dialog_type, buttons, callback) { |
||||
var c_name = 'oc-dialog-'+OCdialogs.dialogs_counter+'-content'; |
||||
var c_id = '#'+c_name; |
||||
var d = '<div id="'+c_name+'" title="'+title+'">'+content+'</div>'; |
||||
$('body').append(d); |
||||
var b = []; |
||||
switch (buttons) { |
||||
case OCdialogs.YES_NO_BUTTONS: |
||||
b[1] = {text: t('dialogs', 'No'), click: function(){ if (callback != undefined) callback(false); $(c_id).dialog('close'); }}; |
||||
b[0] = {text: t('dialogs', 'Yes'), click: function(){ if (callback != undefined) callback(true); $(c_id).dialog('close');}}; |
||||
break; |
||||
case OCdialogs.OK_CANCEL_BUTTONS: |
||||
b[1] = {text: t('dialogs', 'Cancel'), click: function(){$(c_id).dialog('close'); }}; |
||||
case OCdialogs.OK_BUTTON: // fallthrough
|
||||
var f; |
||||
switch(dialog_type) { |
||||
case OCdialogs.ALERT_DIALOG: |
||||
f = function(){$(c_id).dialog('close'); }; |
||||
break; |
||||
case OCdialogs.PROMPT_DIALOG: |
||||
f = function(){OCdialogs.prompt_ok_handler(callback, c_id)}; |
||||
break; |
||||
case OCdialogs.FORM_DIALOG: |
||||
f = function(){OCdialogs.form_ok_handler(callback, c_id)}; |
||||
break; |
||||
} |
||||
b[0] = {text: t('dialogs', 'Ok'), click: f}; |
||||
break; |
||||
} |
||||
$(c_id).dialog({width: 4*$(document).width()/9, height: $(d).height() + 150, modal: false, buttons: b}); |
||||
OCdialogs.dialogs_counter++; |
||||
}, |
||||
// dialogs buttons types
|
||||
YES_NO_BUTTONS: 70, |
||||
OK_BUTTONS: 71, |
||||
OK_CANCEL_BUTTONS: 72, |
||||
// dialogs types
|
||||
ALERT_DIALOG: 80, |
||||
INFO_DIALOG: 81, |
||||
PROMPT_DIALOG: 82, |
||||
FORM_DIALOG: 83, |
||||
dialogs_counter: 0, |
||||
determineValue: function(element) { |
||||
switch ($(element).attr('type')) { |
||||
case 'checkbox': return $(element).attr('checked') != undefined; |
||||
} |
||||
return $(element).val(); |
||||
}, |
||||
prompt_ok_handler: function(callback, c_id){callback(true, $(c_id + " input#oc-dialog-prompt-input").val()); $(c_id).dialog('close');}, |
||||
form_ok_handler: function(callback, c_id) { |
||||
var r = []; |
||||
var c = 0; |
||||
$(c_id + ' input').each(function(i, elem) { |
||||
r[c] = {name: $(elem).attr('name'), value: OCdialogs.determineValue(elem)}; |
||||
c++; |
||||
}); |
||||
$(c_id).dialog('close'); |
||||
callback(r); |
||||
} |
||||
}; |
||||
@ -0,0 +1,77 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Jakob Sack |
||||
* @copyright 2012 Jakob Sack owncloud@jakobsack.de |
||||
* |
||||
* 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/>. |
||||
* |
||||
*/ |
||||
|
||||
require_once('lib/base.php'); |
||||
|
||||
// Backends we always need (auth, principal and files) |
||||
$backends = array( |
||||
'auth' => new OC_Connector_Sabre_Auth(), |
||||
'principal' => new OC_Connector_Sabre_Principal() |
||||
); |
||||
|
||||
// Root nodes |
||||
$nodes = array( |
||||
new Sabre_CalDAV_Principal_Collection($backends['principal']) |
||||
); |
||||
|
||||
// Plugins |
||||
$plugins = array( |
||||
new Sabre_DAV_Auth_Plugin($backends['auth'],'ownCloud'), |
||||
new Sabre_DAVACL_Plugin(), |
||||
new Sabre_DAV_Browser_Plugin(false) // Show something in the Browser, but no upload |
||||
); |
||||
|
||||
// Load the plugins etc we need for usual file sharing |
||||
$backends['lock'] = new OC_Connector_Sabre_Locks(); |
||||
$plugins[] = new Sabre_DAV_Locks_Plugin($backends['lock']); |
||||
// Add a RESTful user directory |
||||
// /files/$username/ |
||||
if( OC_User::isLoggedIn()){ |
||||
$currentuser = OC_User::getUser(); |
||||
$files = new Sabre_DAV_SimpleCollection('files'); |
||||
foreach( OC_User::getUsers() as $username ){ |
||||
if( $username == $currentuser ){ |
||||
$public = new OC_Connector_Sabre_Directory('.'); |
||||
$files->addChild( new Sabre_DAV_SimpleCollection( $username, $public->getChildren())); |
||||
} |
||||
else{ |
||||
$files->addChild(new Sabre_DAV_SimpleCollection( $username )); |
||||
} |
||||
} |
||||
$nodes[] = $files; |
||||
} |
||||
|
||||
// Get the other plugins and nodes |
||||
OC_Hook::emit( 'OC_DAV', 'initialize', array( 'backends' => &$backends, 'nodes' => &$nodes, 'plugins' => &$plugins )); |
||||
|
||||
// Fire up server |
||||
$server = new Sabre_DAV_Server($nodes); |
||||
$server->setBaseUri(OC::$WEBROOT.'/dav.php'); |
||||
|
||||
// Load additional plugins |
||||
foreach( $plugins as &$plugin ){ |
||||
$server->addPlugin( $plugin ); |
||||
} unset( $plugin ); // Always do this after foreach with references! |
||||
|
||||
// And off we go! |
||||
$server->exec(); |
||||
@ -1,45 +0,0 @@ |
||||
<?php |
||||
global $FAKEDIRS; |
||||
$FAKEDIRS=array(); |
||||
|
||||
class fakeDirStream{ |
||||
private $name; |
||||
private $data; |
||||
private $index; |
||||
|
||||
public function dir_opendir($path,$options){ |
||||
global $FAKEDIRS; |
||||
$url=parse_url($path); |
||||
$this->name=substr($path,strlen('fakedir://')); |
||||
$this->index=0; |
||||
if(isset($FAKEDIRS[$this->name])){ |
||||
$this->data=$FAKEDIRS[$this->name]; |
||||
}else{ |
||||
$this->data=array(); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public function dir_readdir(){ |
||||
if($this->index>=count($this->data)){ |
||||
return false; |
||||
} |
||||
$filename=$this->data[$this->index]; |
||||
$this->index++; |
||||
return $filename; |
||||
} |
||||
|
||||
public function dir_closedir() { |
||||
$this->data=false; |
||||
$this->name=''; |
||||
return true; |
||||
} |
||||
|
||||
public function dir_rewinddir() { |
||||
$this->index=0; |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
stream_wrapper_register("fakedir", "fakeDirStream"); |
||||
|
||||
@ -0,0 +1,151 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Michael Gapczynski |
||||
* @copyright 2012 Michael Gapczynski GapczynskiM@gmail.com |
||||
* |
||||
* 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/>. |
||||
*/ |
||||
|
||||
abstract class OC_Filestorage_Common extends OC_Filestorage { |
||||
|
||||
public function __construct($parameters){} |
||||
// abstract public function mkdir($path); |
||||
// abstract public function rmdir($path); |
||||
// abstract public function opendir($path); |
||||
public function is_dir($path){ |
||||
return $this->filetype($path)=='dir'; |
||||
} |
||||
public function is_file($path){ |
||||
return $this->filetype($path)=='file'; |
||||
} |
||||
// abstract public function stat($path); |
||||
// abstract public function filetype($path); |
||||
public function filesize($path) { |
||||
if($this->is_dir($path)){ |
||||
return 0;//by definition |
||||
}else{ |
||||
$stat = $this->stat($path); |
||||
return $stat['size']; |
||||
} |
||||
} |
||||
// abstract public function is_readable($path); |
||||
// abstract public function is_writable($path); |
||||
// abstract public function file_exists($path); |
||||
public function filectime($path) { |
||||
$stat = $this->stat($path); |
||||
return $stat['ctime']; |
||||
} |
||||
public function filemtime($path) { |
||||
$stat = $this->stat($path); |
||||
return $stat['mtime']; |
||||
} |
||||
public function fileatime($path) { |
||||
$stat = $this->stat($path); |
||||
return $stat['atime']; |
||||
} |
||||
public function file_get_contents($path) { |
||||
$handle = $this->fopen($path, "r"); |
||||
if(!$handle){ |
||||
return false; |
||||
} |
||||
$size=$this->filesize($path); |
||||
if($size==0){ |
||||
return ''; |
||||
} |
||||
return fread($handle, $size); |
||||
} |
||||
public function file_put_contents($path,$data) { |
||||
$handle = $this->fopen($path, "w"); |
||||
return fwrite($handle, $data); |
||||
} |
||||
// abstract public function unlink($path); |
||||
public function rename($path1,$path2){ |
||||
if($this->copy($path1,$path2)){ |
||||
return $this->unlink($path1); |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
public function copy($path1,$path2) { |
||||
$source=$this->fopen($path1,'r'); |
||||
$target=$this->fopen($path2,'w'); |
||||
$count=OC_Helper::streamCopy($source,$target); |
||||
return $count>0; |
||||
} |
||||
// abstract public function fopen($path,$mode); |
||||
public function getMimeType($path){ |
||||
if(!$this->file_exists($path)){ |
||||
return false; |
||||
} |
||||
if($this->is_dir($path)){ |
||||
return 'httpd/unix-directory'; |
||||
} |
||||
$source=$this->fopen($path,'r'); |
||||
if(!$source){ |
||||
return false; |
||||
} |
||||
$head=fread($source,8192);//8kb should suffice to determine a mimetype |
||||
$extention=substr($path,strrpos($path,'.')); |
||||
$tmpFile=OC_Helper::tmpFile($extention); |
||||
file_put_contents($tmpFile,$head); |
||||
$mime=OC_Helper::getMimeType($tmpFile); |
||||
unlink($tmpFile); |
||||
return $mime; |
||||
} |
||||
public function hash($type,$path,$raw){ |
||||
$tmpFile=$this->getLocalFile(); |
||||
$hash=hash($type,$tmpFile,$raw); |
||||
unlink($tmpFile); |
||||
return $hash; |
||||
} |
||||
// abstract public function free_space($path); |
||||
public function search($query){ |
||||
return $this->searchInDir($query); |
||||
} |
||||
public function getLocalFile($path){ |
||||
return $this->toTmpFile($path); |
||||
} |
||||
private function toTmpFile($path){//no longer in the storage api, still usefull here |
||||
$source=$this->fopen($path,'r'); |
||||
if(!$source){ |
||||
return false; |
||||
} |
||||
$extention=substr($path,strrpos($path,'.')); |
||||
$tmpFile=OC_Helper::tmpFile($extention); |
||||
$target=fopen($tmpFile,'w'); |
||||
$count=OC_Helper::streamCopy($source,$target); |
||||
return $tmpFile; |
||||
} |
||||
// abstract public function touch($path, $mtime=null); |
||||
|
||||
protected function searchInDir($query,$dir=''){ |
||||
$files=array(); |
||||
$dh=$this->opendir($dir); |
||||
if($dh){ |
||||
while($item=readdir($dh)){ |
||||
if ($item == '.' || $item == '..') continue; |
||||
if(strstr(strtolower($item),strtolower($query))!==false){ |
||||
$files[]=$dir.'/'.$item; |
||||
} |
||||
if($this->is_dir($dir.'/'.$item)){ |
||||
$files=array_merge($files,$this->searchInDir($query,$dir.'/'.$item)); |
||||
} |
||||
} |
||||
} |
||||
return $files; |
||||
} |
||||
} |
||||
@ -0,0 +1,75 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Robin Appelman |
||||
* @copyright 2012 Robin Appelman icewind@owncloud.com |
||||
* |
||||
* 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/>. |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* test implementation for OC_FileStorage_Common with OC_FileStorage_Local |
||||
*/ |
||||
|
||||
class OC_Filestorage_CommonTest extends OC_Filestorage_Common{ |
||||
/** |
||||
* underlying local storage used for missing functions |
||||
* @var OC_FileStorage_Local |
||||
*/ |
||||
private $storage; |
||||
|
||||
public function __construct($params){ |
||||
$this->storage=new OC_Filestorage_Local($params); |
||||
} |
||||
|
||||
public function mkdir($path){ |
||||
return $this->storage->mkdir($path); |
||||
} |
||||
public function rmdir($path){ |
||||
return $this->storage->rmdir($path); |
||||
} |
||||
public function opendir($path){ |
||||
return $this->storage->opendir($path); |
||||
} |
||||
public function stat($path){ |
||||
return $this->storage->stat($path); |
||||
} |
||||
public function filetype($path){ |
||||
return $this->storage->filetype($path); |
||||
} |
||||
public function is_readable($path){ |
||||
return $this->storage->is_readable($path); |
||||
} |
||||
public function is_writable($path){ |
||||
return $this->storage->is_writable($path); |
||||
} |
||||
public function file_exists($path){ |
||||
return $this->storage->file_exists($path); |
||||
} |
||||
public function unlink($path){ |
||||
return $this->storage->unlink($path); |
||||
} |
||||
public function fopen($path,$mode){ |
||||
return $this->storage->fopen($path,$mode); |
||||
} |
||||
public function free_space($path){ |
||||
return $this->storage->free_space($path); |
||||
} |
||||
public function touch($path, $mtime=null){ |
||||
return $this->storage->touch($path,$mtime); |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue