From: Robin Appelman Date: Sat, 16 Apr 2011 10:35:21 +0000 (+0200) Subject: publiclink plugin X-Git-Tag: v3.0~267^2~558^2~147 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9dd0d90f69d7737d03b6747ae46394035396ef5b;p=nextcloud-server.git publiclink plugin Allows sharing files by creating a public link, no gui yet. --- diff --git a/plugins/publiclink/db_structure.xml b/plugins/publiclink/db_structure.xml new file mode 100644 index 00000000000..de63b03f445 --- /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 00000000000..c579dc9246c --- /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 00000000000..494f84fdb7a --- /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 00000000000..1de65e7ec6f --- /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 00000000000..75abed6cf08 --- /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 + +