diff --git a/index.php b/index.php index 2f56510bfb..89c24cac52 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,8 @@ var_dump( $_SESSION ); if( OC_USER::isLoggedIn()){ if( $_GET["logout"] ){ OC_USER::logout(); - OC_TEMPLATE::printGuestPage( "", "logout" ); + header( "Location: $WEBROOT"); + exit(); } else{ header( "Location: ".OC_APPCONFIG::getValue( "core", "defaultpage", "files/index.php" )); diff --git a/lib/ocs.php b/lib/ocs.php index 2b1e706462..4e9e6522e8 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -400,16 +400,16 @@ class OC_OCS { * @return string xml/json */ private static function activityGet($format,$page,$pagesize) { - global $CONFIG_DBTABLEPREFIX; - $user=OC_OCS::checkpassword(); - - $result = OC_DB::query("select count(*) as co from {$CONFIG_DBTABLEPREFIX}log"); + + $query = OC_DB::prepare('select count(*) as co from *PREFIX*log'); + $result = $query->execute(); $entry=$result->fetchRow(); $totalcount=$entry['co']; - OC_DB::free_result($result); - - $result = OC_DB::select("select id,timestamp,user,type,message from {$CONFIG_DBTABLEPREFIX}log order by timestamp desc limit " . ($page*$pagesize) . ",$pagesize"); + + $query=OC_DB::prepare('select id,timestamp,user,type,message from *PREFIX*log order by timestamp desc limit ?,?'); + $result = $query->execute(array(($page*$pagesize),$pagesize))->fetchAll(); + $itemscount=count($result); $url='http://'.substr($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'],0,-11).''; @@ -512,24 +512,24 @@ class OC_OCS { * @return array */ public static function getData($user,$app="",$key="",$like=false) { - global $CONFIG_DBTABLEPREFIX; - $user=OC_DB::escape($user); - $key=OC_DB::escape($key); - $app=OC_DB::escape($app); $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy, needs to be replaced with a seperate user field the next time we break db compatibiliy $compareFunction=($like)?'LIKE':'='; if($app){ if (!trim($key)) { - $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata where app='$app' order by `timestamp` desc"); + $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? order by `timestamp` desc'); + $result=$query->execute(array($app))->fetchAll(); } else { - $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata where app='$app' and `key` $compareFunction '$key' order by `timestamp` desc"); + $query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? and `key` $compareFunction ? order by `timestamp` desc"); + $result=$query->execute(array($app,$key))->fetchAll(); } }else{ if (!trim($key)) { - $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata order by `timestamp` desc"); + $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata order by `timestamp` desc'); + $result=$query->execute()->fetchAll(); } else { - $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata where `key` $compareFunction '$key' order by `timestamp` desc"); + $query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where `key` $compareFunction ? order by `timestamp` desc"); + $result=$query->execute(array($key))->fetchAll(); } } $result=self::trimKeys($result,$user); @@ -545,20 +545,18 @@ class OC_OCS { * @return bool */ public static function setData($user, $app, $key, $value) { - global $CONFIG_DBTABLEPREFIX; - $app=OC_DB::escape($app); - $key=OC_DB::escape($key); - $user=OC_DB::escape($user); - $value=OC_DB::escape($value); $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy - //TODO: prepared statements, locking tables, fancy stuff, error checking/handling - $result=OC_DB::select("select count(*) as co from {$CONFIG_DBTABLEPREFIX}privatedata where `key` = '$key' and app = '$app'"); + //TODO: locking tables, fancy stuff, error checking/handling + $query=OC_DB::prepare("select count(*) as co from *PREFIX*privatedata where `key` = ? and app = ?"); + $result=$query->execute(array($key,$app))->fetchAll(); $totalcount=$result[0]['co']; if ($totalcount != 0) { - $result = OC_DB::query("update {$CONFIG_DBTABLEPREFIX}privatedata set value='$value', `timestamp` = now() where `key` = '$key' and app = '$app'"); + $query=OC_DB::prepare("update *PREFIX*privatedata set value=?, `timestamp` = now() where `key` = ? and app = ?"); + } else { - $result = OC_DB::query("insert into {$CONFIG_DBTABLEPREFIX}privatedata(app, `key`, value, `timestamp`) values('$app', '$key', '$value', now())"); + $result = OC_DB::prepare("insert into *PREFIX*privatedata(value, `key`, app, `timestamp`) values(?, ?, ?, now())"); } + $result = $query->execute(array($value,$key,$app)); if (PEAR::isError($result)){ $entry='DB Error: "'.$result->getMessage().'"
'; error_log($entry); @@ -576,13 +574,10 @@ class OC_OCS { * @return string xml/json */ public static function deleteData($user, $app, $key) { - global $CONFIG_DBTABLEPREFIX; - $app=OC_DB::escape($app); - $key=OC_DB::escape($key); - $user=OC_DB::escape($user); $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy //TODO: prepared statements, locking tables, fancy stuff, error checking/handling - $result = OC_DB::query("delete from {$CONFIG_DBTABLEPREFIX}privatedata where `key` = '$key' and app = '$app'"); + $query=OC_DB::prepare("delete from *PREFIX*privatedata where `key` = ? and app = ?"); + $result = $query->execute(array($key,$app)); if (PEAR::isError($result)){ $entry='DB Error: "'.$result->getMessage().'"
'; error_log($entry); diff --git a/plugins/publiclink/db_structure.xml b/plugins/publiclink/db_structure.xml new file mode 100644 index 0000000000..de63b03f44 --- /dev/null +++ b/plugins/publiclink/db_structure.xml @@ -0,0 +1,47 @@ + + + *dbname* + true + false + latin1 + + *dbprefix*publiclink + + + token + text + + true + 40 + + + path + text + + true + 128 + + + user + text + + + true + 64 + + + expire_time + timestamp + true + + + token + true + + token + ascending + + + +
+
diff --git a/plugins/publiclink/getfile.php b/plugins/publiclink/getfile.php new file mode 100644 index 0000000000..c579dc9246 --- /dev/null +++ b/plugins/publiclink/getfile.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/plugins/publiclink/lib_public.php b/plugins/publiclink/lib_public.php new file mode 100644 index 0000000000..494f84fdb7 --- /dev/null +++ b/plugins/publiclink/lib_public.php @@ -0,0 +1,77 @@ +execute(array($token,$path,$user,$expiretime)); + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
'; + $entry .= 'Offending command was: '.$result->getDebugInfo().'
'; + error_log( $entry ); + die( $entry ); + } + $this->token=$token; + } + } + + /** + * download a file shared by a public link + * @param string token + */ + public static function downloadFile($token){ + //remove expired links + $query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE expire_time < NOW() AND expire_time!=0"); + $query->execute(); + + //get the path and the user + $query=OC_DB::prepare("SELECT user,path FROM *PREFIX*publiclink WHERE token=?"); + $result=$query->execute(array($token)); + $data=$result->fetchAll(); + if(count($data)>0){ + $path=$data[0]['path']; + $user=$data[0]['user']; + + //login + $_SESSION['user_id']=$user; + + //prepare the filesystem + OC_UTIL::setupFS(); + + //get time mimetype and set the headers + $mimetype=OC_FILESYSTEM::getMimeType($path); + // header('Content-Disposition: attachment; filename="'.basename($path).'"'); + header('Content-Transfer-Encoding: binary'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Type: ' . $mimetype); + header('Content-Length: ' . OC_FILESYSTEM::filesize($path)); + + //download the file + ob_clean(); + OC_FILESYSTEM::readfile($path); + }else{ + header("HTTP/1.0 404 Not Found"); + echo '404 Not Found'; + die(); + } + } + + /** + * get the token for the public link + * @return string + */ + public function getToken(){ + return $this->token; + } + + private $token; +} +?> \ No newline at end of file diff --git a/plugins/publiclink/makelink.php b/plugins/publiclink/makelink.php new file mode 100644 index 0000000000..1de65e7ec6 --- /dev/null +++ b/plugins/publiclink/makelink.php @@ -0,0 +1,13 @@ +getToken(); +?> \ No newline at end of file diff --git a/plugins/publiclink/plugin.xml b/plugins/publiclink/plugin.xml new file mode 100755 index 0000000000..75abed6cf0 --- /dev/null +++ b/plugins/publiclink/plugin.xml @@ -0,0 +1,17 @@ + + + + publiclink + Simple file sharing by creating a public link to a file + 0.1 + AGPL + Robin Appelman + 1.1 + + + lib_public.php + + + db_structure.xml + +