shuri/index.php

67 lines
1.5 KiB
PHP
Raw Normal View History

2013-07-09 19:47:59 +02:00
<?php
if(!empty($_GET['url'])) {
$url = $_GET['url'];
if(strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
$url = 'http://'.$url;
}
$urlhash = sha1($url);
$hashfolder = substr($urlhash, 0, 2);
$hashfile = substr($urlhash, 2);
$hashfolderpath = './db/' . $hashfolder;
$hashfilepath = $hashfolderpath . '/' . $hashfile;
2014-02-15 12:16:06 +01:00
mkdir($hashfolderpath, 0700, true);
2013-07-09 19:47:59 +02:00
file_put_contents($hashfilepath, $url);
2014-02-15 12:16:33 +01:00
$content = '<a href="./?'.$urlhash.'">./?'.$urlhash.'</a><br />
As long as there is not collision, you can shorten it down to 3 characters.';
2013-07-09 19:47:59 +02:00
} else if(!empty($_GET)) {
$urlhash = key($_GET);
$hashfolder = substr($urlhash, 0, 2);
$hashfile = substr($urlhash, 2);
$hashfolderpath = './db/' . $hashfolder;
$hashfilepath = $hashfolderpath . '/' . $hashfile;
$findfiles = glob($hashfilepath . '*');
if(empty($findfiles)) {
2014-02-15 12:40:54 +01:00
$content = 'No files.';
2013-07-09 19:47:59 +02:00
return 1;
} else if (count($findfiles) > 1) {
foreach($findfiles as $file) {
$file = str_replace('/', '', substr($file, 5));
2014-02-15 12:40:54 +01:00
$content = '<a href="./?'.$file.'">./?'.$file.'</a><br />';
2013-07-09 19:47:59 +02:00
}
}
$fullfilepath = current($findfiles);
header('Location:' . file_get_contents($fullfilepath));
return 0;
2014-02-15 12:16:33 +01:00
} else {
$content = '<form method="get">
Enter your URL: <input type="text" name="url"><input type="submit" value="Submit">
</form>';
2013-07-09 19:47:59 +02:00
}
2014-02-15 12:16:33 +01:00
//actual page below
?>
<!DOCTYPE html>
<html>
<head>
<title>Shuri</title>
</head>
<body>
<div id="content">
<?php echo $content ?>
</div>
</body>
</html>