Merge pull request #26 from pierre-alain-b/master

Adding a config file and other changes
This commit is contained in:
Eric Johansson (neku) 2016-05-14 21:51:54 +02:00
commit 660b976c3e
16 changed files with 109 additions and 82 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
includes/config.php
rain/cache/*.php
rain/template/footer.html
public/files

View File

@ -1,5 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2015 nokonoko Copyright (c) 2015 nokonoko
Copyright (c) 2016 PA BANDINELLI, HéliApps SAS
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to the Software without restriction, including without limitation the rights to

View File

@ -1,48 +1,54 @@
# About # About
[Uguu.se](http://uguu.se) source code, stores files and deletes after X amount of time. Temp file sharing application source code, stores files and deletes after X amount of time. Forked from Uguu.se available [here](https://github.com/nokonoko/uguu).
# Install # Tested with:
Tested with: * Nginx+PHP5-FPM (PHP 5.4) on Debian 7 Wheezy
* Nginx+PHP5-FPM (PHP 5.4) on Debian 7 Wheezy
* Apache (PHP 5.4) on Ubuntu 14.04 LTS * Apache (PHP 5.4) on Ubuntu 14.04 LTS
* Apache (PHP 5.6) on Debian 8 Jessie
* Nginx+PHP5-FPM (PHP 5.6) on Debian 8 Jessie * Nginx+PHP5-FPM (PHP 5.6) on Debian 8 Jessie
Modify # Install:
* Modify includes/core.php where to save files and other paths.
* Set correct paths in several other files. (Will add fix for this via config file instead).
* Change uguu.se to your own name in several files.
* Cron with check.sh: `crontab -e`
* After running `crontab -e`, add `0,15,30,45 * * * * bash /path/to/check.sh`, or read up on how cron works.
* Some extensions are blocked by default, this can be changed via includes/core.php's $block array.
* Everything else to your likings.
Change php.ini and nginx.conf settings to allow bigger uploads. * Deploy base code, for example with `git clone https://github.com/pierre-alain-b/Uguu.git`
* Modify includes/config.php (copy config.template.php as a starting point) to set up the main options for Uguu.
* Some file extensions are blocked by default, this can be changed via includes/config.php's CONFIG_BLOCKED_EXTENSIONS value.
* Copy `rain/template/footer.template.html` as `rain/template/footer.html` and personalize the footer as you wish
* Execute check.sh regularly with cron to delete old files: `crontab -e` and add `0,15,30,45 * * * * bash /path/to/check.sh` (or adapt if you know how cron works).
* Make the Uguu/public/files and Uguu/rain/cache directory modifiable by the web server user:
`chown -R www-data:www-data /path/to/Uguu/public/files` and `chown -R www-data:www-data /path/to/Uguu/rain/cache`
* Make sure the Uguu/public/files folder is not indexable, you may use a virtual host config similar to this one:
Make the uguu/ directory modifiable to the nginx user: ```
`setfacl -m u:www-data:rwx /path/to/uguu/directory/` <VirtualHost *:80>
ServerName path.to.uguu
# Todo DocumentRoot /var/www/Uguu/
<Directory /var/www/Uguu/>
AllowOverride All
Require all granted
</Directory>
* Restructure files. Alias "/files" "/var/www/Uguu/public/files/"
* Make global config file. <Directory /var/www/Uguu/public/files/>
* Probably a lot of things but I'm a lazy fuck, come with suggestions. <Files *>
SetHandler default-handler
</Files>
AllowOverride None
Options -Indexes
Require all granted
</Directory>
</VirtualHost>
```
# Using the API # Using the API
* Leaving POST value 'name' empty will cause it to save using the original filename. * Leaving POST value 'name' empty will cause it to save using the original filename.
* Leaving POST value 'randomname' empty will cause it to use original filename or custom name if 'name' is set to file.ext. * Leaving POST value 'randomname' empty will cause it to use original filename or custom name if 'name' is set to file.ext.
* Putting anything into POST value 'randomname' will cause it to return a random filename + ext (xxxxxx.ext). * Putting anything into POST value 'randomname' will cause it to return a random filename + ext (xxxxxx.ext).
* Putting a custom name into POST value 'name' will cause it to return a custom filename (yourpick.ext). * Putting a custom name into POST value 'name' will cause it to return a custom filename (yourpick.ext).
E.g: E.g:
* curl -i -F name=test.jpg -F file=@localfile.jpg http://uguu.se/api.php?d=upload (HTML Response) * curl -i -F name=test.jpg -F file=@localfile.jpg http://path.to.uguu/api.php?d=upload (HTML Response)
* curl -i -F name=test.jpg -F file=@localfile.jpg http://uguu.se/api.php?d=upload-tool (Plain text Response) * curl -i -F name=test.jpg -F file=@localfile.jpg http://path.to.uguu/api.php?d=upload-tool (Plain text Response)
This will probably get changed later since it's messy and unpractical.
# Contact
[neku@pomf.se](mailto:neku@pomf.se) or [@Nekunekus](https://twitter.com/nekunekus).

View File

@ -1,14 +1,17 @@
<?php <?php
//Loading configuration file
require_once "includes/config.php";
//If the value d doesn't exist, redirect back to front page *1 //If the value d doesn't exist, redirect back to front page *1
if(isset($_GET['d'])) { if(isset($_GET['d'])) {
//Include the core file with the functions //Include the core file with the functions
include_once('includes/core.php'); include_once(CONFIG_ROOT_PATH.'includes/core.php');
switch ($_GET['d']) { switch ($_GET['d']) {
//Uploading with HTML response and errors //Uploading with HTML response and errors
case 'upload': case 'upload':
//If no file is being posted, show the error page and exit. //If no file is being posted, show the error page and exit.
if(empty($_FILES['file']['name'])){ if(empty($_FILES['file']['name'])){
include_once('error.php'); include_once(CONFIG_ROOT_PATH.'error.php');
exit(0); exit(0);
} }
//Set the name value to the original filename //Set the name value to the original filename
@ -47,7 +50,7 @@ if(isset($_GET['d'])) {
break; break;
default: default:
//If no correct valid argument for the api to perform on, tell them to enter a valid one //If no correct valid argument for the api to perform on, tell them to enter a valid one
exit('Please provide a valid argument. Example: curl -i -F name=test.jpg -F file=@localfile.jpg http://uguu.se/api.php?d=upload-tool'); exit('Please provide a valid argument. Example: curl -i -F name=test.jpg -F file=@localfile.jpg '.CONFIG_ROOT_URL.'/api.php?d=upload-tool');
break; break;
} }
}else{ }else{

View File

@ -13,6 +13,5 @@ $tpl->assign("title", $title);
$tpl->draw("header"); $tpl->draw("header");
$tpl->draw("error"); $tpl->draw("error");
$tpl->draw("footer"); $tpl->draw("footer");
?> ?>

View File

@ -1,2 +1,2 @@
#! /bin/sh #! /bin/sh
find /home/neku/www/files/ -mmin +1440 -exec rm -f {} \; find $(grep -oP '"CONFIG_FILES_PATH", "\K(.*)(?=")' config.php) -mtime +$(grep -oP '"CONFIG_MAX_RETENTION_TIME", "\K(.*)(?=")' config.php) -exec rm -f {} \;

View File

@ -0,0 +1,9 @@
<?php
//This is the configuration file for Uguu Temp File Sharing system
define("CONFIG_ROOT_URL", "http://path.to.uguu");
define("CONFIG_FILES_PATH", "/path/to/uguu/public/files/");
define("CONFIG_ROOT_PATH", "/path/to/uguu/");
define("CONFIG_MAX_RETENTION_TIME", "60"); //Max retention time in minutes
define("CONFIG_MAX_RETENTION_TEXT", "1 hour"); //Max retention time as a text to be displayed
define("CONFIG_RANDOM_LENGTH", "12"); //Length of the random chain appended to the filename
define ("CONFIG_BLOCKED_EXTENSIONS", serialize(array("exe", "scr", "rar", "zip", "com", "vbs", "bat", "cmd", "html", "htm", "msi")));

View File

@ -1,24 +1,25 @@
<?php <?php
//Loading configuration file
require_once "config.php";
//Saving the file on the server
function save_file ($file, $name, $arg, $type){ function save_file ($file, $name, $arg, $type){
//Where to save
$path='/home/neku/www/files/';
$block = array('exe', 'scr', 'rar', 'zip', 'com', 'vbs', 'bat', 'cmd', 'html', 'htm', 'msi');
//Generate name depending on arg //Generate name depending on arg
switch($arg){ switch($arg){
case 'random': case 'random':
$ext = pathinfo($file.$name, PATHINFO_EXTENSION); $ext = pathinfo($file.$name, PATHINFO_EXTENSION);
$ext = strtolower($ext); $ext = strtolower($ext);
if(in_array($ext, $block)){ if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){
if($type==='normal'){ if($type==='normal'){
include_once('error_meow.php'); include_once(CONFIG_ROOT_PATH.'error_meow.php');
exit(0); exit(0);
}else{ }else{
exit('File type not allowed.'); exit('File type not allowed.');
} }
} }
$file_name = gen_name('random', $ext); $file_name = gen_name('random', $ext);
while(file_exists($path.$file_name)){ while(file_exists(CONFIG_FILES_PATH.$file_name)){
$file_name = gen_name('random', $ext); $file_name = gen_name('random', $ext);
} }
break; break;
case 'custom_original': case 'custom_original':
@ -27,38 +28,40 @@ function save_file ($file, $name, $arg, $type){
$file_name = gen_name('custom_original', $name); $file_name = gen_name('custom_original', $name);
$ext = pathinfo($file_name, PATHINFO_EXTENSION); $ext = pathinfo($file_name, PATHINFO_EXTENSION);
$ext = strtolower($ext); $ext = strtolower($ext);
if(in_array($ext, $block)){ if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){
if($type==='normal'){ if($type==='normal'){
include_once('error_meow.php'); include_once(CONFIG_ROOT_PATH.'error_meow.php');
exit(0); exit(0);
}else{ }else{
exit('File type not allowed.'); exit('File type not allowed.');
}
} }
} while(file_exists(CONFIG_FILES_PATH.$file_name)){
while(file_exists($path.$file_name)){
$file_name = gen_name('custom_original', $name); $file_name = gen_name('custom_original', $name);
} }
break; break;
} }
//Move the file to the above location with said filename //Move the file to the above location with said filename
move_uploaded_file($file,$path.$file_name); move_uploaded_file($file,CONFIG_FILES_PATH.$file_name);
//Check if html or plain text should be returned //Check if html or plain text should be returned
if($type==='tool'){ if($type==='tool'){
//Return url+filename to the user (plain text) //Return url+filename to the user (plain text)
echo 'http://a.uguu.se/'.urlencode($file_name); echo CONFIG_ROOT_URL.'/files/'.urlencode($file_name);
exit(0); exit(0);
}elseif($type==='normal'){ }elseif($type==='normal'){
//Return url+filename to the user (HTML) //Return url+filename to the user (HTML)
$n=urlencode($file_name); $n=urlencode($file_name);
include_once('/home/neku/www/page/public/upload-done.php'); include_once(CONFIG_ROOT_PATH.'upload-done.php');
exit(0); exit(0);
} }
} }
#Generate a random name for the uploaded file
function gen_name($arg, $in){ function gen_name($arg, $in){
$chars = 'abcdefghijklmnopqrstuvwxyz'; $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$name = ''; $name = '';
for ($i = 0; $i < 6; $i++) { for ($i = 0; $i < CONFIG_RANDOM_LENGTH; $i++) {
$name .= $chars[mt_rand(0, 25)]; $name .= $chars[mt_rand(0, 60)];
} }
switch($arg){ switch($arg){
case 'random': case 'random':

View File

@ -1,4 +1,7 @@
<?php <?php
//Loading configuration file
require_once "includes/config.php";
require_once "rain/rain.tpl.class.php"; require_once "rain/rain.tpl.class.php";
raintpl::configure( 'path_replace', false); raintpl::configure( 'path_replace', false);
@ -15,10 +18,12 @@ $tpl->assign("title", $title);
$tpl->draw("header"); $tpl->draw("header");
if(isset($_GET['info'])) { if(isset($_GET['info'])) {
$tpl->assign("url_filename", CONFIG_ROOT_URL);
$tpl->assign("retention_time", CONFIG_MAX_RETENTION_TEXT);
$tpl->draw("info"); $tpl->draw("info");
} else { } else {
$tpl->draw("upload"); $tpl->draw("upload");
} }
$tpl->draw("footer"); $tpl->draw("footer");
?> ?>

0
public/files/.keep Normal file
View File

0
rain/cache/.keep vendored Normal file
View File

View File

@ -17,4 +17,4 @@
</footer> </footer>
</body> </body>
</html> </html>

View File

@ -4,8 +4,8 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Temp file hosting, Up to 150MB for 1 hour."> <meta name="description" content="Temp file hosting, up to 150MB.">
<title>Uguu.se &middot; {$title}</title> <title>Uguu &middot; {$title}</title>
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon"> <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<!-- materialize --> <!-- materialize -->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/> <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
@ -25,15 +25,13 @@
<div class="nav-wrapper blue-grey darken-1"> <div class="nav-wrapper blue-grey darken-1">
<div class="container"> <div class="container">
<div class="col s12"> <div class="col s12">
<a href="/" class="brand-logo">Uguu.se</a> <a href="/" class="brand-logo">Uguu</a>
<a href="#" data-activates="mobile-demo" class="button-collapse"><i class="mdi-navigation-menu"></i></a> <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="mdi-navigation-menu"></i></a>
<ul class="right hide-on-med-and-down"> <ul class="right hide-on-med-and-down">
<li><a href="/?info">Info</a></li> <li><a href="/?info">Info</a></li>
<li><a href="https://github.com/nokonoko/uguu">Github</a></li>
</ul> </ul>
<ul class="side-nav" id="mobile-demo"> <ul class="side-nav" id="mobile-demo">
<li><a href="/?info">Info</a></li> <li><a href="/?info">Info</a></li>
<li><a href="https://github.com/nokonoko/uguu">Github</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -3,16 +3,14 @@
<div class="col s12"> <div class="col s12">
<div class="card-panel blue-grey darken-1"> <div class="card-panel blue-grey darken-1">
<div class="card-content white-text"> <div class="card-content white-text">
<span class="card-title">Info</span> <span class="card-title"><b>Info</b></span>
<p>Store any filetype with a size up to 150MB for up to 1 hour. <p>Store any filetype with a size up to 150MB for up to {$retention_time}.
Uguu cares about your privacy and stores NO logs. Uguu cares about your privacy and stores NO logs.
</p> </p>
<p> <p>
If you would like to upload using ShareX read <a style="color: #bbdefb" href="https://github.com/ShareX/ShareX/wiki/Custom-Uploader-examples#uguuse">this</a>.<br />
To upload using curl or make a tool you can post using:<br /> To upload using curl or make a tool you can post using:<br />
<code>curl -i -F name=test.jpg -F file=@localfile.jpg http://uguu.se/api.php?d=upload</code> (HTML Response)<br /> <code>curl -i -F name=test.jpg -F file=@localfile.jpg {$url_filename}/api.php?d=upload</code> (HTML Response)<br />
<code>curl -i -F name=test.jpg -F file=@localfile.jpg http://uguu.se/api.php?d=upload-tool</code> (Plain text Response)</p> <code>curl -i -F name=test.jpg -F file=@localfile.jpg {$url_filename}/api.php?d=upload-tool</code> (Plain text Response)</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -3,9 +3,9 @@
<div class="col s12"> <div class="col s12">
<div class="card-panel blue-grey darken-1"> <div class="card-panel blue-grey darken-1">
<div class="card-content white-text"> <div class="card-content white-text">
<span class="card-title" style="color: #FF9999"><h3>File uploaded!</h3></span> <span class="card-title" style="color: #00FF99"><h3>File uploaded!</h3></span>
<p><a href="http://a.uguu.se/{$filename}">http://a.uguu.se/{$filename}</a></p> <p><a href="{$url_filename}">{$url_filename}</a></p>
<p>Your file will be available for download during 24 hours.</p> <p>Your file will be available for download during {$retention_time}.</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,13 +1,14 @@
<?php <?php
require_once "/home/neku/www/page/public/rain/rain.tpl.class.php"; require_once "rain/rain.tpl.class.php";
raintpl::configure( 'path_replace', false); raintpl::configure( 'path_replace', false);
raintpl::configure( 'tpl_dir', '/home/neku/www/page/public/rain/template/'); raintpl::configure( 'tpl_dir', 'rain/template/');
raintpl::configure( 'cache_dir', '/home/neku/www/page/public/rain/cache/' ); raintpl::configure( 'cache_dir', 'rain/cache/' );
$tpl = new RainTPL; $tpl = new RainTPL;
$title = "Temp File Hosting"; $title = "Temp File Hosting";
$tpl->assign("title", $title); $tpl->assign("title", $title);
$tpl->draw("header"); $tpl->draw("header");
$tpl->assign("filename", $n); $tpl->assign("url_filename", CONFIG_ROOT_URL.'/files/'.$n);
$tpl->assign("retention_time", CONFIG_MAX_RETENTION_TEXT);
$tpl->draw("upload-done"); $tpl->draw("upload-done");
$tpl->draw("footer"); $tpl->draw("footer");
?> ?>