mirror of
https://github.com/nokonoko/Uguu.git
synced 2024-01-06 13:35:15 +00:00
Merge pull request #26 from pierre-alain-b/master
Adding a config file and other changes
This commit is contained in:
commit
660b976c3e
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
includes/config.php
|
||||
rain/cache/*.php
|
||||
rain/template/footer.html
|
||||
public/files
|
1
LICENSE
1
LICENSE
@ -1,5 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
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
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
|
66
README.md
66
README.md
@ -1,48 +1,54 @@
|
||||
# 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:
|
||||
* Nginx+PHP5-FPM (PHP 5.4) on Debian 7 Wheezy
|
||||
# Tested with:
|
||||
* Nginx+PHP5-FPM (PHP 5.4) on Debian 7 Wheezy
|
||||
* 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
|
||||
|
||||
Modify
|
||||
* 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.
|
||||
# Install:
|
||||
|
||||
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.
|
||||
* Make global config file.
|
||||
* Probably a lot of things but I'm a lazy fuck, come with suggestions.
|
||||
Alias "/files" "/var/www/Uguu/public/files/"
|
||||
<Directory /var/www/Uguu/public/files/>
|
||||
<Files *>
|
||||
SetHandler default-handler
|
||||
</Files>
|
||||
AllowOverride None
|
||||
Options -Indexes
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
</VirtualHost>
|
||||
```
|
||||
|
||||
# Using the API
|
||||
|
||||
* 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.
|
||||
|
||||
|
||||
* 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).
|
||||
|
||||
|
||||
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://uguu.se/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).
|
||||
* 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://path.to.uguu/api.php?d=upload-tool (Plain text Response)
|
||||
|
9
api.php
9
api.php
@ -1,14 +1,17 @@
|
||||
<?php
|
||||
//Loading configuration file
|
||||
require_once "includes/config.php";
|
||||
|
||||
//If the value d doesn't exist, redirect back to front page *1
|
||||
if(isset($_GET['d'])) {
|
||||
//Include the core file with the functions
|
||||
include_once('includes/core.php');
|
||||
include_once(CONFIG_ROOT_PATH.'includes/core.php');
|
||||
switch ($_GET['d']) {
|
||||
//Uploading with HTML response and errors
|
||||
case 'upload':
|
||||
//If no file is being posted, show the error page and exit.
|
||||
if(empty($_FILES['file']['name'])){
|
||||
include_once('error.php');
|
||||
include_once(CONFIG_ROOT_PATH.'error.php');
|
||||
exit(0);
|
||||
}
|
||||
//Set the name value to the original filename
|
||||
@ -47,7 +50,7 @@ if(isset($_GET['d'])) {
|
||||
break;
|
||||
default:
|
||||
//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;
|
||||
}
|
||||
}else{
|
||||
|
@ -13,6 +13,5 @@ $tpl->assign("title", $title);
|
||||
$tpl->draw("header");
|
||||
$tpl->draw("error");
|
||||
|
||||
|
||||
$tpl->draw("footer");
|
||||
?>
|
||||
?>
|
||||
|
@ -1,2 +1,2 @@
|
||||
#! /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 {} \;
|
||||
|
9
includes/config.template.php
Normal file
9
includes/config.template.php
Normal 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")));
|
@ -1,24 +1,25 @@
|
||||
<?php
|
||||
//Loading configuration file
|
||||
require_once "config.php";
|
||||
|
||||
//Saving the file on the server
|
||||
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
|
||||
switch($arg){
|
||||
case 'random':
|
||||
$ext = pathinfo($file.$name, PATHINFO_EXTENSION);
|
||||
$ext = strtolower($ext);
|
||||
if(in_array($ext, $block)){
|
||||
if($type==='normal'){
|
||||
include_once('error_meow.php');
|
||||
if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){
|
||||
if($type==='normal'){
|
||||
include_once(CONFIG_ROOT_PATH.'error_meow.php');
|
||||
exit(0);
|
||||
}else{
|
||||
exit('File type not allowed.');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
exit('File type not allowed.');
|
||||
}
|
||||
}
|
||||
$file_name = gen_name('random', $ext);
|
||||
while(file_exists($path.$file_name)){
|
||||
$file_name = gen_name('random', $ext);
|
||||
while(file_exists(CONFIG_FILES_PATH.$file_name)){
|
||||
$file_name = gen_name('random', $ext);
|
||||
}
|
||||
break;
|
||||
case 'custom_original':
|
||||
@ -27,38 +28,40 @@ function save_file ($file, $name, $arg, $type){
|
||||
$file_name = gen_name('custom_original', $name);
|
||||
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
$ext = strtolower($ext);
|
||||
if(in_array($ext, $block)){
|
||||
if($type==='normal'){
|
||||
include_once('error_meow.php');
|
||||
exit(0);
|
||||
}else{
|
||||
exit('File type not allowed.');
|
||||
if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){
|
||||
if($type==='normal'){
|
||||
include_once(CONFIG_ROOT_PATH.'error_meow.php');
|
||||
exit(0);
|
||||
}else{
|
||||
exit('File type not allowed.');
|
||||
}
|
||||
}
|
||||
}
|
||||
while(file_exists($path.$file_name)){
|
||||
while(file_exists(CONFIG_FILES_PATH.$file_name)){
|
||||
$file_name = gen_name('custom_original', $name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//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
|
||||
if($type==='tool'){
|
||||
//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);
|
||||
}elseif($type==='normal'){
|
||||
//Return url+filename to the user (HTML)
|
||||
$n=urlencode($file_name);
|
||||
include_once('/home/neku/www/page/public/upload-done.php');
|
||||
include_once(CONFIG_ROOT_PATH.'upload-done.php');
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
#Generate a random name for the uploaded file
|
||||
function gen_name($arg, $in){
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyz';
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
$name = '';
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$name .= $chars[mt_rand(0, 25)];
|
||||
for ($i = 0; $i < CONFIG_RANDOM_LENGTH; $i++) {
|
||||
$name .= $chars[mt_rand(0, 60)];
|
||||
}
|
||||
switch($arg){
|
||||
case 'random':
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
//Loading configuration file
|
||||
require_once "includes/config.php";
|
||||
|
||||
require_once "rain/rain.tpl.class.php";
|
||||
|
||||
raintpl::configure( 'path_replace', false);
|
||||
@ -15,10 +18,12 @@ $tpl->assign("title", $title);
|
||||
$tpl->draw("header");
|
||||
|
||||
if(isset($_GET['info'])) {
|
||||
$tpl->assign("url_filename", CONFIG_ROOT_URL);
|
||||
$tpl->assign("retention_time", CONFIG_MAX_RETENTION_TEXT);
|
||||
$tpl->draw("info");
|
||||
} else {
|
||||
$tpl->draw("upload");
|
||||
}
|
||||
|
||||
$tpl->draw("footer");
|
||||
?>
|
||||
?>
|
||||
|
0
public/files/.keep
Normal file
0
public/files/.keep
Normal file
0
rain/cache/.keep
vendored
Normal file
0
rain/cache/.keep
vendored
Normal file
@ -17,4 +17,4 @@
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
@ -4,8 +4,8 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Temp file hosting, Up to 150MB for 1 hour.">
|
||||
<title>Uguu.se · {$title}</title>
|
||||
<meta name="description" content="Temp file hosting, up to 150MB.">
|
||||
<title>Uguu · {$title}</title>
|
||||
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
|
||||
<!-- materialize -->
|
||||
<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="container">
|
||||
<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>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
<li><a href="/?info">Info</a></li>
|
||||
<li><a href="https://github.com/nokonoko/uguu">Github</a></li>
|
||||
</ul>
|
||||
<ul class="side-nav" id="mobile-demo">
|
||||
<li><a href="/?info">Info</a></li>
|
||||
<li><a href="https://github.com/nokonoko/uguu">Github</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -3,16 +3,14 @@
|
||||
<div class="col s12">
|
||||
<div class="card-panel blue-grey darken-1">
|
||||
<div class="card-content white-text">
|
||||
<span class="card-title">Info</span>
|
||||
<p>Store any filetype with a size up to 150MB for up to 1 hour.
|
||||
<span class="card-title"><b>Info</b></span>
|
||||
<p>Store any filetype with a size up to 150MB for up to {$retention_time}.
|
||||
Uguu cares about your privacy and stores NO logs.
|
||||
</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 />
|
||||
<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 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</code> (HTML Response)<br />
|
||||
<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>
|
||||
|
@ -3,9 +3,9 @@
|
||||
<div class="col s12">
|
||||
<div class="card-panel blue-grey darken-1">
|
||||
<div class="card-content white-text">
|
||||
<span class="card-title" style="color: #FF9999"><h3>File uploaded!</h3></span>
|
||||
<p><a href="http://a.uguu.se/{$filename}">http://a.uguu.se/{$filename}</a></p>
|
||||
<p>Your file will be available for download during 24 hours.</p>
|
||||
<span class="card-title" style="color: #00FF99"><h3>File uploaded!</h3></span>
|
||||
<p><a href="{$url_filename}">{$url_filename}</a></p>
|
||||
<p>Your file will be available for download during {$retention_time}.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,13 +1,14 @@
|
||||
<?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( 'tpl_dir', '/home/neku/www/page/public/rain/template/');
|
||||
raintpl::configure( 'cache_dir', '/home/neku/www/page/public/rain/cache/' );
|
||||
raintpl::configure( 'tpl_dir', 'rain/template/');
|
||||
raintpl::configure( 'cache_dir', 'rain/cache/' );
|
||||
$tpl = new RainTPL;
|
||||
$title = "Temp File Hosting";
|
||||
$tpl->assign("title", $title);
|
||||
$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("footer");
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user