Initial commit

develop
Sven Slootweg 13 years ago
parent cf36da409d
commit 869c990ed9

@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

@ -0,0 +1,136 @@
<!doctype html>
<html>
<head>
<title>Cryto Tahoe-LAFS Storage Grid repair utility</title>
<style>
pre
{
max-height: 300px;
overflow: auto;
background-color: #E7E7E7;
padding: 12px;
}
</style>
</head>
<body>
<?php
function curl_post($url, $variables)
{
if(is_array($variables))
{
foreach($variables as $key => $value)
{
$variables[$key] = urlencode($value);
$variable_strings[] = "{$key}={$value}";
}
$post_string = implode("&", $variable_strings);
}
else
{
$post_string = "";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, count($variables));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($ch);
$error = curl_error($ch);
if(empty($error))
{
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$return_object->result = $result;
$return_object->code = $code;
return $return_object;
}
else
{
return false;
}
curl_close($ch);
}
if(isset($_POST['submit']))
{
$uri = $_POST['uri'];
$process = true;
// process repair request
if(preg_match("/http:\/\/[^\/]+\/download\/([^\/]+)(\/.*)?/i", $uri, $matches))
{
// gateway url
$uri = $matches[1];
}
if(!preg_match("/^[a-zA-Z0-9=_:]+$/i", $uri))
{
$process = false;
echo("ERROR: Your input was in an invalid format.<br><br>");
}
if(strpos($uri, ":") === false)
{
// probably base64
$uri = base64_decode($uri);
if($uri === false)
{
$process = false;
echo("ERROR: Your input was invalid. Check if it's really a valid Tahoe-LAFS gateway URL, base64-encoded URI, or plaintext URI.<br><br>");
}
}
if($process === true)
{
$result = curl_post("http://localhost:3456/uri/{$uri}?t=check&repair=true&output=json", false);
if($result->code == 200)
{
$result_object = json_decode($result->result);
$attempted = $result_object->{'repair-attempted'};
if($attempted)
{
$succeeded = $result_object->{'repair-successful'};
}
else
{
$succeeded = false;
}
if($attempted === false)
{
echo("<strong>The file is still healthy, and does not need to be repaired.</strong>");
}
elseif($attempted === true && $succeeded === false)
{
echo("<strong>Repair of the file was attempted, but FAILED.</strong>");
}
else
{
echo("<strong>Repair of the file was SUCCESSFULLY completed.</strong>");
}
echo("<pre>{$result->result}</pre>");
}
else
{
echo("ERROR: Repair failed. Your input may be in the wrong format or the server may be down.<br><br>");
}
}
}
?>
<form method="post" action="repair.php">
URI/base64/URL: <input type="text" name="uri">
<button type="submit" name="submit" value="submit">Repair!</button>
</form>
</body>
</html>

@ -0,0 +1,85 @@
#!/bin/bash
## Changelog
# 16-AUG-2011 | Xeross | Don't read into temp file but straight into variable
# 16-AUG-2011 | Xeross | If non-zero exit status don't run url.py
# 16-AUG-2011 | Xeross | Make remote filename for file upload optional
##### Configuration starts here #####
# The URL of the Tahoe-LAFS web interface that you are trying to upload to.
tahoe="http://localhost:3456/uri/";
# The (write cap) URI of the directory you want to upload to by default.
URI="";
##### Configuration ends here #####
URI=${URI//:/%3A};
fullURI=$tahoe$URI/;
function upload_file {
local TYPE=$1
local DATA=$2
local DEST=$3
if [ "$TYPE" == "INPUT" ]; then
CAP=$(echo "$DATA" | curl --progress-bar -T - "$fullURI$DEST")
RETVAL=$?
elif [ "$TYPE" == "FILE" ]; then
CAP=$(curl --progress-bar -T "$DATA" "$fullURI$DEST")
RETVAL=$?
else
echo "Error: Unknown type passed"
exit 2
fi
if [ $RETVAL -ne 0 ]; then
echo "Upload failed (Exit code: $RETVAL)"
else
python url.py $CAP $DEST
fi
}
function usage {
echo "Usage:"
echo "Upload input from stdin"
echo "# cat file.txt | ./tahoe.sh -i subfolder/filename.txt"
echo
echo "Upload specified file"
echo "# ./tahoe.sh -f file.jpg [subfolders/filename.jpg]"
echo
echo "Create new subdirectory"
echo "# ./tahoe.sh -d new_subdirectory"
}
case $1 in
-i)
if [ $# -ne 2 ]; then
echo "Invalid syntax"
usage
exit 1
fi
read INPUT
upload_file "INPUT" "$INPUT" "$2"
;;
-f)
if [ $# -eq 2 ]; then
FILENAME=$(basename $2)
elif [ $# -eq 3 ]; then
FILENAME=$3
else
echo "Invalid syntax"
usage
exit 1
fi
upload_file "FILE" "$2" "$FILENAME"
;;
-d)
curl -d "" $fullURI$2?t=mkdir
;;
*)
usage
;;
esac

@ -0,0 +1,10 @@
import sys,base64
if len(sys.argv) < 3:
print ("""\
Usage: url.py cap filename
cap = Tahoe-LAFS readcap
filename = Actual filename of the file
""")
else:
print "http://tahoe-gateway.cryto.net:3719/download/" + base64.urlsafe_b64encode(sys.argv[1]) + "/" + sys.argv[2]
Loading…
Cancel
Save