parent
ce2c7bad44
commit
a54ea3246c
@ -1,46 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ownCloud - ajax frontend |
||||
* |
||||
* @author Robin Appelman |
||||
* @copyright 2010 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/>. |
||||
* |
||||
*/ |
||||
|
||||
|
||||
// Init owncloud |
||||
require_once('../../lib/base.php'); |
||||
require_once( 'lib_public.php' ); |
||||
|
||||
|
||||
// Check if we are a user |
||||
OC_Util::checkLoggedIn(); |
||||
|
||||
OC_App::setActiveNavigationEntry( "files_publiclink_administration" ); |
||||
|
||||
OC_Util::addScript( 'files_publiclink', 'admin' ); |
||||
|
||||
$baseUrl = OC_Helper::linkTo('files_publiclink','get.php', null, true); |
||||
|
||||
|
||||
// return template |
||||
$tmpl = new OC_Template( "files_publiclink", "admin", "user" ); |
||||
$tmpl->assign( 'links', OC_PublicLink::getLinks()); |
||||
$tmpl->assign('baseUrl',$baseUrl); |
||||
$tmpl->printPage(); |
||||
|
||||
?> |
@ -1,11 +0,0 @@ |
||||
<?php |
||||
$RUNTIME_NOAPPS=true; //no need to load the apps |
||||
|
||||
require_once '../../../lib/base.php'; |
||||
|
||||
require_once '../lib_public.php'; |
||||
|
||||
$token=$_GET['token']; |
||||
|
||||
OC_PublicLink::delete($token); |
||||
?> |
@ -1,8 +0,0 @@ |
||||
<?php |
||||
$RUNTIME_NOAPPS = true; |
||||
|
||||
require_once('../../../lib/base.php'); |
||||
require_once('../lib_public.php'); |
||||
|
||||
$path = $_GET['path']; |
||||
echo json_encode(OC_PublicLink::getLink($path)); |
@ -1,13 +0,0 @@ |
||||
<?php |
||||
$RUNTIME_NOAPPS=true; //no need to load the apps |
||||
|
||||
require_once '../../../lib/base.php'; |
||||
|
||||
require_once '../lib_public.php'; |
||||
|
||||
$path=$_GET['path']; |
||||
$expire=0; |
||||
|
||||
$link=new OC_PublicLink($path,$expire); |
||||
echo $link->getToken(); |
||||
?> |
@ -1,6 +0,0 @@ |
||||
<?php |
||||
|
||||
// OC_App::addNavigationEntry(array( "id" => "files_publiclink_administration", "order" => 2, "href" => OC_Helper::linkTo( "files_publiclink", "admin.php" ), "name" => "Public Links")); |
||||
|
||||
|
||||
?> |
@ -1,47 +0,0 @@ |
||||
<?xml version="1.0" encoding="ISO-8859-1" ?> |
||||
<database> |
||||
<name>*dbname*</name> |
||||
<create>true</create> |
||||
<overwrite>false</overwrite> |
||||
<charset>latin1</charset> |
||||
<table> |
||||
<name>*dbprefix*publiclink</name> |
||||
<declaration> |
||||
<field> |
||||
<name>token</name> |
||||
<type>text</type> |
||||
<default></default> |
||||
<notnull>true</notnull> |
||||
<length>40</length> |
||||
</field> |
||||
<field> |
||||
<name>path</name> |
||||
<type>text</type> |
||||
<default></default> |
||||
<notnull>true</notnull> |
||||
<length>128</length> |
||||
</field> |
||||
<field> |
||||
<name>user</name> |
||||
<type>text</type> |
||||
<default> |
||||
</default> |
||||
<notnull>true</notnull> |
||||
<length>64</length> |
||||
</field> |
||||
<field> |
||||
<name>expire_time</name> |
||||
<type>timestamp</type> |
||||
<notnull>true</notnull> |
||||
</field> |
||||
<index> |
||||
<name>a_files_publiclink_token</name> |
||||
<unique>true</unique> |
||||
<field> |
||||
<name>token</name> |
||||
<sorting>ascending</sorting> |
||||
</field> |
||||
</index> |
||||
</declaration> |
||||
</table> |
||||
</database> |
@ -1,10 +0,0 @@ |
||||
<?xml version="1.0"?> |
||||
<info> |
||||
<id>files_publiclink</id> |
||||
<name>Share by Publiclink</name> |
||||
<description>Simple file sharing by creating a public link to a file</description> |
||||
<version>0.2</version> |
||||
<licence>AGPL</licence> |
||||
<author>Robin Appelman</author> |
||||
<require>2</require> |
||||
</info> |
@ -1,83 +0,0 @@ |
||||
<?php |
||||
$RUNTIME_NOAPPS=true; //no need to load the apps |
||||
$RUNTIME_NOSETUPFS=true; //don't setup the fs yet |
||||
|
||||
require_once '../../lib/base.php'; |
||||
|
||||
require_once 'lib_public.php'; |
||||
|
||||
//get the path of the shared file |
||||
$token=$_GET['token']; |
||||
$path=OC_PublicLink::getPath($token); |
||||
$root=$path; |
||||
|
||||
if($path!==false){ |
||||
if(isset($_GET['path']) and !strstr($_GET['path'],'..')){ |
||||
$subPath=$_GET['path']; |
||||
}else{ |
||||
$subPath=''; |
||||
} |
||||
$path.=$subPath; |
||||
if(!OC_Filesystem::file_exists($path)){ |
||||
header("HTTP/1.0 404 Not Found"); |
||||
$tmpl = new OC_Template( '', '404', 'guest' ); |
||||
$tmpl->assign('file',$subPath); |
||||
$tmpl->printPage(); |
||||
exit; |
||||
} |
||||
if(OC_Filesystem::is_dir($path)){ |
||||
$files = array(); |
||||
$rootLength=strlen($root); |
||||
foreach( OC_Files::getdirectorycontent( $path ) as $i ){ |
||||
$i['date'] = OC_Util::formatDate($i['mtime'] ); |
||||
$i['directory']=substr($i['directory'],$rootLength); |
||||
if($i['directory']=='/'){ |
||||
$i['directory']=''; |
||||
} |
||||
$files[] = $i; |
||||
} |
||||
|
||||
// Make breadcrumb |
||||
$breadcrumb = array(); |
||||
$pathtohere = "/"; |
||||
foreach( explode( "/", $subPath ) as $i ){ |
||||
if( $i != "" ){ |
||||
$pathtohere .= "$i/"; |
||||
$breadcrumb[] = array( "dir" => $pathtohere, "name" => $i ); |
||||
} |
||||
} |
||||
|
||||
$breadcrumbNav = new OC_Template( "files_publiclink", "breadcrumb", "" ); |
||||
$breadcrumbNav->assign( "breadcrumb", $breadcrumb ); |
||||
$breadcrumbNav->assign('token',$token); |
||||
|
||||
$list = new OC_Template( 'files_publiclink', 'files', '' ); |
||||
$list->assign( 'files', $files ); |
||||
$list->assign('token',$token); |
||||
|
||||
$tmpl = new OC_Template( 'files_publiclink', 'index', 'user' ); |
||||
$tmpl->assign('fileList', $list->fetchPage()); |
||||
$tmpl->assign( "breadcrumb", $breadcrumbNav->fetchPage() ); |
||||
$tmpl->printPage(); |
||||
}else{ |
||||
//get time mimetype and set the headers |
||||
$mimetype=OC_Filesystem::getMimeType($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-Disposition: filename="'.basename($path).'"'); |
||||
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"); |
||||
$tmpl = new OC_Template( '', '404', 'guest' ); |
||||
$tmpl->printPage(); |
||||
die(); |
||||
} |
||||
?> |
@ -1,45 +0,0 @@ |
||||
$(document).ready(function() { |
||||
$( "#path" ).autocomplete({ |
||||
source: "../../files/ajax/autocomplete.php", |
||||
minLength: 1 |
||||
}); |
||||
$(".delete").live('click', function( event ) { |
||||
event.preventDefault(); |
||||
var token=$(this).attr('data-token'); |
||||
var data="token="+token; |
||||
$.ajax({ |
||||
type: 'GET', |
||||
url: 'ajax/deletelink.php', |
||||
cache: false, |
||||
data: data, |
||||
success: function(){ |
||||
$('#'+token).remove(); |
||||
} |
||||
}); |
||||
}); |
||||
$('#newlink').submit(function( event ){ |
||||
event.preventDefault(); |
||||
var path=$('#path').val(); |
||||
var expire=0; |
||||
var data='path='+path+'&expire='+expire; |
||||
$.ajax({ |
||||
type: 'GET', |
||||
url: 'ajax/makelink.php', |
||||
cache: false, |
||||
data: data, |
||||
success: function(token){ |
||||
if(token){ |
||||
var html="<tr class='link' id='"+token+"'>"; |
||||
html+="<td class='path'>"+path+"</td>"; |
||||
html+="<td class='link'><input type='text' value='"+$('#baseUrl').val()+"?token="+token+"' /></td>" |
||||
html+="<td><input type='submit' class='delete' data-token='"+token+" value='Delete' /></td>" |
||||
html+="</tr>" |
||||
$(html).insertAfter($('#newlink_row')); |
||||
$('#path').val(''); |
||||
$('#'+token+' input').focus(); |
||||
$('#'+token+' input').select(); |
||||
} |
||||
} |
||||
}); |
||||
}); |
||||
}); |
@ -1,84 +0,0 @@ |
||||
<?php |
||||
class OC_PublicLink{ |
||||
/** |
||||
* create a new public link |
||||
* @param string path |
||||
* @param int (optional) expiretime time the link expires, as timestamp |
||||
*/ |
||||
public function __construct($path,$expiretime=0){ |
||||
if($path and OC_Filesystem::file_exists($path) and OC_Filesystem::is_readable($path)){ |
||||
$user=OC_User::getUser(); |
||||
$token=sha1("$user-$path-$expiretime"); |
||||
$query=OC_DB::prepare("INSERT INTO *PREFIX*publiclink VALUES(?,?,?,?)"); |
||||
$result=$query->execute(array($token,$path,$user,$expiretime)); |
||||
if( PEAR::isError($result)) { |
||||
$entry = 'DB Error: "'.$result->getMessage().'"<br />'; |
||||
$entry .= 'Offending command was: '.$result->getDebugInfo().'<br />'; |
||||
if(defined("DEBUG") && DEBUG) {error_log( $entry );} |
||||
die( $entry ); |
||||
} |
||||
$this->token=$token; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* get the path of that shared file |
||||
*/ |
||||
public static function getPath($token) { |
||||
//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']; |
||||
|
||||
//prepare the filesystem |
||||
OC_Util::setupFS($user); |
||||
|
||||
return $path; |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* get the token for the public link |
||||
* @return string |
||||
*/ |
||||
public function getToken(){ |
||||
return $this->token; |
||||
} |
||||
|
||||
public static function getLink($path) { |
||||
$query=OC_DB::prepare("SELECT token FROM *PREFIX*publiclink WHERE user=? AND path=? LIMIT 1"); |
||||
$result=$query->execute(array(OC_User::getUser(),$path))->fetchAll(); |
||||
if(count($result)>0){ |
||||
return $result[0]['token']; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* gets all public links |
||||
* @return array |
||||
*/ |
||||
static public function getLinks(){ |
||||
$query=OC_DB::prepare("SELECT * FROM *PREFIX*publiclink WHERE user=?"); |
||||
return $query->execute(array(OC_User::getUser()))->fetchAll(); |
||||
} |
||||
|
||||
/** |
||||
* delete a public link |
||||
*/ |
||||
static public function delete($token){ |
||||
$query=OC_DB::prepare("SELECT user,path FROM *PREFIX*publiclink WHERE token=?"); |
||||
$result=$query->execute(array($token))->fetchAll(); |
||||
if(count($result)>0 and $result[0]['user']==OC_User::getUser()){ |
||||
$query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE token=?"); |
||||
$query->execute(array($token)); |
||||
} |
||||
} |
||||
|
||||
private $token; |
||||
} |
||||
?> |
@ -1,18 +0,0 @@ |
||||
<input type="hidden" id="baseUrl" value="<?php echo $_['baseUrl'];?>"/>
|
||||
<table id="linklist"> |
||||
<thead id="controls"> |
||||
<tr id="newlink_row"><form action="#" id="newlink"> |
||||
<td class="path"><input placeholder="Path" id="path"/></td> |
||||
<td><input type="submit" value="Share" /></td> |
||||
</form></tr> |
||||
</thead> |
||||
<tbody> |
||||
<?php foreach($_['links'] as $link):?> |
||||
<tr class="link" id="<?php echo $link['token'];?>">
|
||||
<td class="path"><?php echo $link['path'];?></td>
|
||||
<td class="link"><input type="text" value="<?php echo $_['baseUrl'];?>?token=<?php echo $link['token'];?>" /></td>
|
||||
<td><input type="submit" class="delete" data-token="<?php echo $link['token'];?>" value="<?php echo $l->t( 'Delete' ); ?>" /></td>
|
||||
</tr> |
||||
<?php endforeach;?> |
||||
</tbody> |
||||
</table> |
Loading…
Reference in new issue