Initial Commit

This commit is contained in:
Clortox 2021-01-04 15:22:48 -05:00
commit 1e9762ff50
9 changed files with 339 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
############
# Git Ignore
#Linux trash folder which can appear anywhere
.Trash-*
# .nfs files are created when file is removed but still being accessed
.nfs*
#dont add anyof the symlinks in dir to tracking
dir/*
#but still keep the folder
!dir/.gitkeep

13
README.md Normal file
View File

@ -0,0 +1,13 @@
Simple Repository
=================
My simple php file repository/link tree that I wrote for my personal NAS.
How to use
----------
I designed this with the intent that it could be used on something like a raspberry pi with little to now programming knowledge.
The config file is supposed to be very easy to read and understand what each option means. The config file is in php.
The config file is [var/config.php](var/config.php)

0
dir/.gitkeep Normal file
View File

15
helpers/files.php Normal file
View File

@ -0,0 +1,15 @@
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
function foldersize($path){
$sizestr = shell_exec('du -sh ' . "$path" . '/ | awk \'{print $1} \'');
return $sizestr;
}
function listingsize($path){
$sizestr = shell_exec('du -h ' . "$path" . ' | awk \'{print $1}\'');
return $sizestr;
}
?>

57
index.php Normal file
View File

@ -0,0 +1,57 @@
<html>
<head>
<?php
session_start();
//if this is a session inside the local connection
if(strpos($_SERVER['REMOTE_ADDR'],"192.168.1.")){
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
}
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
//css, js, and other includes
include 'www/include.php';
include 'helpers/files.php';
?>
<title><?php echo $site_name ?></title>
</head>
<body class="bg-dark">
<?php
include 'www/header.php';
?>
<div class="card ml-4 mr-4">
<div class="card-header">
<h2>Folders</h2>
</div>
<div class="card-body">
<p>Select a catagory to start browsing</p>
<table id="catTable" class="display table">
<thead>
<tr>
<th>Name</th>
<th>Link</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<?php
foreach($dir_names as $i=>$currentdir){
echo '<tr>';
echo '<td>' . $currentdir . '</td>';
echo '<td><a href="listing.php?folder=' . $dir_names[$i] .'">View Listing</a></td>';
echo '<td>' . foldersize($dir_dirs[$i]) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</body>
</html>

110
listing.php Normal file
View File

@ -0,0 +1,110 @@
<html>
<head>
<?php
session_start();
//if this is a session inside the local connection
if(strpos($_SERVER['REMOTE_ADDR'],"192.168.1.")){
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
}
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
//css, js, and other includes
include 'www/include.php';
include 'helpers/files.php';
?>
<title><?php echo $site_name ?></title>
</head>
<body class="bg-dark">
<?php
include 'www/header.php';
?>
<?php
$dir = $_GET['folder'];
$exists = false;
foreach($dir_names as $dir_index=>$dir_){
if($dir_ == $dir){
$exists = true;
break;
}
}
if(!$exists){
echo <<< errorblock
<div class="card-header">
<h2><b>LISTING NOT FOUND</b></h2>
</div>
errorblock;
exit();
}
if(!array_key_exists('path', $_GET)){
$path = '/';
} else {
$path = $_GET['path'];
}
if($handle = opendir($dir_dirs[$dir_index] . $path)){
while(false !== ($entry = readdir($handle))){
//exclude . and ..
if($entry != '.' && $entry != '..'){
$elements[] = $entry;
}
}
} else {
echo <<< erroropendir
<div class="card-header">
<h2><b>ERROR OPENING DIRECTORY, PLEASE RELOAD THE PAGE</b></h2>
<h2><b>IF THE ISSUE PERSISTS, PLEASE CONTACT YOUR SYSTEM ADMINISTRATOR</b></h2>
</div>
erroropendir;
exit();
}
?>
<div class="card ml-4 mr-4">
<div class="card-header">
<h2><?php echo $dir ?></h2>
</div>
<div class="card-body">
<p>Select a file to download, or a folder to view its contents</p>
<table id="catTable" class="display table">
<thead>
<tr>
<th>File Name</th>
<th>Link</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<?php
foreach($elements as $i=>$currentfile){
echo "<tr>";
echo "<td>" . $currentfile . "</td>";
$fulldir = $dir_dirs[$dir_index] . $path . "/" . $currentfile;
if(is_dir($fulldir)){
echo "<td><a href=\"listing.php?folder="
. $dir . "&path=%2F" . $currentfile
. "\">View Directory</a></td>";
echo "<td>" . foldersize($fulldir) . "</td>";
} else {
echo "<td><a href=\"" . $fulldir . "\">Download</a></td>";
echo "<td>" . listingsize($fulldir) . "</td>";
}
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</body>
</html>

88
var/config.php Normal file
View File

@ -0,0 +1,88 @@
<?php
//general config globals
//This is what will appear in the tab, as well as on the header
$site_name = 'Tyler\'s File Repository';
/* Navbar
*
* Each variable in $nav_names is what will appear on the top bar
* These can be set to anything and could be Places on the page, internal pages
* on the site, or external sites
*
* Each varaible in $nav_links is a link that the user will be directed to
* These can start with "#" to direct to a tag on the page, could be an internal
* link by using "/listing.php?folder=SomeFolder", or could be an external site
*
* These associate in order ie the Tag $nav_names[3] will direct the user to
* the link in $nav_links[3]
*
*/
$nav_names = array(
'Home',
'Github',
);
$nav_links = array(
'index.php',
'https://github.com/Clortox',
);
/* Directory Variables
*
* Each variable in $dir_dirs will be a listing
* on the main page under "folders"
* I recomend making a folder of symlinks to where the downloadable files are
*
* Each variable in $dir_names will be the title of the listing
* These will appear on the left hand side and will be the name of the
* name of the folder as it appears to the user
*
* These assiocate in order ie the folder $dir_dirs[3] will have
* the title $dir_names[3]
*/
$dir_names = array(
'Printable Guns',
'GNU Software',
'Linux Kernel',
'OS Images',
'Books and Documents',
);
$dir_dirs = array(
'dir/guns',
'dir/gnu',
'dir/linux',
'dir/iso',
'dir/books',
);
/* Convo
*
* These are little tag lines that will appear on the header.
* A header is randomly chosen each time the page is loaded
* If you would like to disable this, set isConvo to false
* If you would like only one line, just comment out/delete all of them except
* the one you would like to keep.
*
* The format is
* CLIENTIP + [CONVO] + SERVERIP
*
* Example:
* 192.168.1.100 is exchanging goverment secrets with 192.168.1.1
*
*/
$isConvo = true;
$convo = array(
' is exchanging goverment secrets with ',
' is talking about life with ',
' is asking for data via the information superhighway from ',
' is baking cookies with ',
' is asking for help with their homework from ',
);
?>

28
www/header.php Normal file
View File

@ -0,0 +1,28 @@
<?php
$clientip = $_SERVER['REMOTE_ADDR'];
$serverip = $_SERVER['SERVER_ADDR'];
?>
<header>
<div class="jumbotron">
<h1><?php echo $site_name ?></h1>
<?php
if($isConvo){
$saying = $convo[rand(0,count($convo)-1)];
echo '<p>' . $clientip . $saying . $serverip . '</p>';
}
?>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<?php
foreach($nav_names as $index=>$name){
echo '<a class="navbar-brand" href="' . $nav_links[$index] . '">'
. $name . '</a>';
}
?>
</nav>
</div>
</header>

14
www/include.php Normal file
View File

@ -0,0 +1,14 @@
<?php
$p = $_SERVER['DOCUMENT_ROOT'];
$p .= "/var/config.php";
include_once($p);
?>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="../www/js/progressbar.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.js"></script>