Commit 965d5ef9 authored by hockeymikey's avatar hockeymikey

Added Readme

parent 5dc1636d
## The Thousand Year Archiver
Simple archiving website service written in PHP, Python and Bash. Uses HTTPTrack for archiving websites, git for storing and php for displaying.
Currently used for OldKrox.com.
### Future Plans
* Ditch HttpTrack and write own in Python
* Config for easy conversion to other sites
* Multi-site support
* Different storage backend (git is nice for text files but not binary like Video).
* Maybe something fancy like BIP or Borg. Both are powerful.
\ No newline at end of file
<?php
session_start();
//$DataArray = $_SESSION['dataArray'];
include 'functions.php';
require_once __DIR__ . '/vendor/autoload.php';
use TQ\Git\Repository\Repository;
// open an already initialized repository
//$git = Repository::open('/home/hockeymikey/achiver/data', '/usr/bin/git');
//
//if (isset($_GET['date']) && isset($_GET['url'])) {
// $date = $_GET['date'];
// $sDate = explode("_", $date);
// $Requested = $_GET['url'];
// //echo $RequestedImage;
// fetchDatabase();
//
// //if (isset(vars::$DataArray[$sDate[0]][$sDate[1]]) ) {
// // $comm = vars::$DataArray[$sDate[0]][$sDate[1]];
// //}
// //else {
// // $comm = reset(vars::$DataArray[$sDate[0]]);
// //}
// //
// //$contents = $git->showFile($Requested, $comm);
//}
//else {
// //404 image file
// $contents = fopen('./404.png', 'rb');
//
//}
// send the right headers
//header("Content-Type: image/png");
//header("Content-Length: " . filesize($name));
// dump the picture and stop the script
//fpassthru($contents);
$Requested = $_GET['url'];
$name=end(explode("/", $Requested));
$path = './data/'.$name;
header('Content-Type: audio/mpeg');
header('Content-Length: ' . filesize($path));
header('Content-Disposition: inline; filename=\"'.$name.'\"');
//header("Content-Transfer-Encoding: binary");
header('Content-Description: Audio Player');
//header('Content-Type: application/octet-stream');
//header('Expires: 0');
//header('Cache-Control: must-revalidate');
//header('Pragma: public');
header('Accept-Ranges: bytes');
flush();
//header('X-Pad: avoid browser bug');
//header('Cache-Control: no-cache');
//header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
//readfile($file);
set_time_limit(0);
$file = @fopen($path,"rb");
if ($file) {
while(!feof($file)) {
print(@fread($file, 1024*8));
ob_flush();
flush();
}
}
exit;
?>
\ No newline at end of file
......@@ -5,71 +5,100 @@ include 'functions.php';
require_once __DIR__ . '/vendor/autoload.php';
use TQ\Git\Repository\Repository;
// open an already initialized repository
//$git = Repository::open('/home/hockeymikey/achiver/data', '/usr/bin/git');
//
//if (isset($_GET['date']) && isset($_GET['url'])) {
// $date = $_GET['date'];
// $sDate = explode("_", $date);
// $Requested = $_GET['url'];
// //echo $RequestedImage;
// fetchDatabase();
//
// //if (isset(vars::$DataArray[$sDate[0]][$sDate[1]]) ) {
// // $comm = vars::$DataArray[$sDate[0]][$sDate[1]];
// //}
// //else {
// // $comm = reset(vars::$DataArray[$sDate[0]]);
// //}
// //
// //$contents = $git->showFile($Requested, $comm);
//}
//else {
// //404 image file
// $contents = fopen('./404.png', 'rb');
//
//}
// send the right headers
//header("Content-Type: image/png");
//header("Content-Length: " . filesize($name));
// dump the picture and stop the script
//fpassthru($contents);
$Requested = $_GET['url'];
$name=end(explode("/", $Requested));
$path = './data/'.$name;
stream($path, 'audio/mpeg');
header('Content-Type: audio/mpeg');
header('Content-Length: ' . filesize($path));
header('Content-Disposition: inline; filename=\"'.$name.'\"');
header("Content-Transfer-Encoding: binary");
/**
* Stream-able file handler
*
* @param String $file_location
* @param Header|String $content_type
* @return content
*/
function stream($file, $content_type = 'application/octet-stream') {
@error_reporting(0);
header('Content-Description: Audio Player');
//header('Content-Type: application/octet-stream');
// Make sure the files exists, otherwise we are wasting our time
if (!file_exists($file)) {
header("HTTP/1.1 404 Not Found");
exit;
}
//header('Expires: 0');
//header('Cache-Control: must-revalidate');
//header('Pragma: public');
// Get file size
$filesize = sprintf("%u", filesize($file));
header('Accept-Ranges: bytes');
flush();
//header('X-Pad: avoid browser bug');
//header('Cache-Control: no-cache');
//header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
// Handle 'Range' header
if(isset($_SERVER['HTTP_RANGE'])){
$range = $_SERVER['HTTP_RANGE'];
}elseif($apache = apache_request_headers()){
$headers = array();
foreach ($apache as $header => $val){
$headers[strtolower($header)] = $val;
}
if(isset($headers['range'])){
$range = $headers['range'];
}
else $range = FALSE;
} else $range = FALSE;
//readfile($file);
//Is range
if($range){
$partial = true;
list($param, $range) = explode('=',$range);
// Bad request - range unit is not 'bytes'
if(strtolower(trim($param)) != 'bytes'){
header("HTTP/1.1 400 Invalid Request");
exit;
}
// Get range values
$range = explode(',',$range);
$range = explode('-',$range[0]);
// Deal with range values
if ($range[0] === ''){
$end = $filesize - 1;
$start = $end - intval($range[0]);
} else if ($range[1] === '') {
$start = intval($range[0]);
$end = $filesize - 1;
}else{
// Both numbers present, return specific range
$start = intval($range[0]);
$end = intval($range[1]);
if ($end >= $filesize || (!$start && (!$end || $end == ($filesize - 1)))) $partial = false; // Invalid range/whole file specified, return whole file
}
$length = $end - $start + 1;
}
// No range requested
else $partial = false;
set_time_limit(0);
$file = @fopen($path,"rb");
while(!feof($file))
{
print(@fread($file, 1024*8));
ob_flush();
flush();
}
// Send standard headers
header("Content-Type: $content_type");
header("Content-Length: $filesize");
header('Accept-Ranges: bytes');
exit;
// send extra headers for range handling...
if ($partial) {
header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $start-$end/$filesize");
if (!$fp = fopen($file, 'rb')) {
header("HTTP/1.1 500 Internal Server Error");
exit;
}
if ($start) fseek($fp,$start);
while($length){
set_time_limit(0);
$read = ($length > 8192) ? 8192 : $length;
$length -= $read;
print(fread($fp,$read));
}
fclose($fp);
}
//just send the whole file
else readfile($file);
exit;
}
?>
\ No newline at end of file
<?php
session_start();
//$DataArray = $_SESSION['dataArray'];
include 'functions.php';
$Requested = $_GET['url'];
$name=end(explode("/", $Requested));
$path = './data/'.$name;
// send content-type and length headers
header("Content-Type: audio/mpeg");
// open the file and spew it back to the client
$file = fopen($path, 'rb');
header("Content-length: ".filesize($file));
header('Content-Disposition: inline; filename=\"'.$name.'\"');
header('Content-Description: Audio Player');
header('Accept-Ranges: bytes');
fpassthru($file);
exit;
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment