Merge branch 'master' of git.cryto.net:projects/joepie91/main

master
Sven Slootweg 11 years ago
commit 90ea5263f5

@ -0,0 +1,135 @@
import os, stat, argparse
template_fcgi = '''#!/usr/bin/env python
from flup.server.fcgi import WSGIServer
from app import app
from werkzeug.contrib.fixers import LighttpdCGIRootFix
if __name__ == '__main__':
WSGIServer(LighttpdCGIRootFix(app)).run()
'''
template_config = '''$HTTP["host"] =~ "%s" {
server.document-root = "%s"
fastcgi.server = ("/" =>
((
"socket" => "%s",
"bin-path" => "%s",
"check-local" => "disable",
"max-procs" => 1
))
)
alias.url = (
"/static" => "%s"
)
url.rewrite-once = (
"^(/static($|/.*))$" => "$1"
)
}
'''
template_app = '''#!/usr/bin/env python
from flask import Flask
app = Flask(__name__)
'''
template_run = '''from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from app import app
app.debug = True
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(1234)
IOLoop.instance().start()
'''
parser = argparse.ArgumentParser(description='Creates and configures a new Flask project for a server running lighttpd.')
parser.add_argument('--name', dest='name', action='store', required=True,
help='(required) lowercase alphanumeric name of the project')
parser.add_argument('--hostname', dest='hostname', action='store', required=True,
help='(required) the hostname on which the project should be available')
parser.add_argument('--config', dest='config', action='store', default="/etc/lighttpd/lighttpd.conf",
help='path to the lighttpd configuration file')
parser.add_argument('--path', dest='path', action='store', default="/var/apps",
help='path to the apps directory')
args = parser.parse_args()
options = vars(args)
# Figure out the docroot
docroot = "%s/%s" % (options['path'], options['name'])
# The lighttpd configuration file can only include relative paths, so we'll have to figure out how deep we are.
config_depth = len([x for x in options['config'].split("/") if x != ""]) - 1
basepath = "../" * config_depth
# Generate included configuration paths
relative_include = "%s/%s/lighttpd.conf" % (basepath[:-1], docroot[1:])
absolute_include = "%s/lighttpd.conf" % docroot
# Generate path to socket
socket_path = "/tmp/%s-fcgi.sock" % options['name']
# Generate path to main .fcgi file
fcgi_path = "%s/app.fcgi" % docroot
# Generate path to static directory
static_path = "%s/static" % docroot
print "Document root: %s" % docroot
print "Relative include path: %s" % relative_include
print "Absolute include path: %s" % absolute_include
print "Socket path: %s" % socket_path
print "FCGI path: %s" % fcgi_path
print "Static file path: %s" % static_path
print "Hostname: %s" % options['hostname']
raw_input("Press enter to continue...")
print "Creating document root..."
# Create document root
os.makedirs(docroot)
print "Creating static file directory..."
# Create static file directory
os.makedirs(static_path)
print "Creating main .fcgi file..."
# Create main .fcgi file
f = open(fcgi_path, "w")
f.write(template_fcgi)
f.close()
print "Creating configuration include..."
# Create configuration include
f = open(absolute_include, "w")
f.write(template_config % (options['hostname'], docroot, socket_path, fcgi_path, static_path))
f.close()
print "Creating application template..."
f = open("%s/app.py" % docroot, "w")
f.write(template_app)
f.close()
print "Creating run script..."
f = open("%s/run.py" % docroot, "w")
f.write(template_run)
f.close()
print "Setting main .fcgi file as executable..."
os.chmod(fcgi_path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH)
print "Appending include path to main lighttpd configuration file..."
# Append include to the main lighttpd configuration file
f = open(options['config'], "a")
f.write("\ninclude \"%s\"\n" % relative_include)
f.close()
print "Done!"

@ -0,0 +1 @@
wget http://cryto.net/projects/webshots/webshots_debian.sh && chmod +x webshots_debian.sh && ./webshots_debian.sh

@ -0,0 +1,16 @@
#!/bin/bash
cd ~
git clone git://github.com/ArchiveTeam/webshots-grab.git
if [ $? -ne 0 ]; then echo "[X] Retrieving the grabber code failed. Exiting..."; exit 1; fi
cd webshots-grab
./get-wget-lua.sh
if [ $? -ne 0 ]; then echo "[X] Compiling wget-lua failed. Exiting..."; exit 1; fi
echo "What username would you like to use? "
read USERNAME
echo "How many threads? (start out with 2 or so) "
read THREADCOUNT
echo "run-pipeline --concurrent $THREADCOUNT ~/webshots-grab/pipeline.py $USERNAME" > ./start.sh
chmod +x ./start.sh
echo "Done! Run ~/webshots-grab/start.sh as the 'archiveteam' user to start grabbing."

@ -0,0 +1,24 @@
#!/bin/bash
apt-get update
apt-get install -y lua50 liblua5.1-0-dev python python-setuptools git-core openssl libssl-dev bzip2 build-essential curl
if [ $? -ne 0 ]; then echo "[X] Installing dependencies failed. Exiting..."; exit 1; fi
easy_install pip
if [ $? -ne 0 ]; then echo "[X] Installing pip failed. Exiting..."; exit 1; fi
pip install seesaw
if [ $? -ne 0 ]; then echo "[X] Installing seesaw failed. Exiting..."; exit 1; fi
useradd -m archiveteam
if [ $? -ne 0 ]; then echo "[X] Creating archiveteam user failed. Exiting..."; exit 1; fi
wget -O /home/archiveteam/setup.sh http://cryto.net/projects/webshots/setup.sh
if [ $? -ne 0 ]; then echo "[X] Retrieving the user setup script failed. Exiting..."; exit 1; fi
chown archiveteam:archiveteam /home/archiveteam/setup.sh
if [ $? -ne 0 ]; then echo "[X] Chowning the setup script failed. Exiting..."; exit 1; fi
chmod +x /home/archiveteam/setup.sh
if [ $? -ne 0 ]; then echo "[X] Chmodding the setup script failed. Exiting..."; exit 1; fi
su -c "/home/archiveteam/setup.sh" archiveteam

@ -0,0 +1,149 @@
<?php
class PathValidator
{
public function __construct($path)
{
$parsed_path = $this->ParsePath($path);
if($parsed_path != null)
{
$this->path = $parsed_path;
}
else
{
throw new Exception("Invalid path specified");
}
}
public function ValidatePath($root)
{
$root_path = $this->ParsePath($root);
if($root_path != null)
{
if($this->RelativeDepth($root) >= 0)
{
$root_stack = explode("/", $root_path);
$path_stack = explode("/", $this->path);
for($i = 0; $i < count($root_stack); $i++)
{
if($root_stack[$i] != $path_stack[$i])
{
return false;
}
}
return true;
}
else
{
return false;
}
}
else
{
throw new Exception("Specified root path is invalid.");
}
}
public function RelativeDepth($root)
{
$root_length = substr_count($this->ParsePath($root), "/");
$path_length = substr_count($this->path, "/");
return $path_length - $root_length;
}
private function RemoveTrailingSlash($path)
{
if(substr($path, strlen($path) - 1) == "/")
{
return substr($path, 0, strlen($path) - 1);
}
else
{
return $path;
}
}
private function ParsePath($path)
{
/* We use a custom function for this since we just want to resolve the path no matter what,
* and the realpath() function will return false if the path either doesn't exist or is not
* accessible. */
$path = $this->RemoveTrailingSlash($path);
if(substr($path, 0, 1) == "/")
{
/* Absolute path */
return $path;
}
else
{
$path_elements = explode("/", $path);
if(substr($path, 0, 1) == "~")
{
/* Home directory path */
if(!empty($_SERVER['home']))
{
$homedir = $_SERVER['home'];
}
elseif(getenv("HOME") != null)
{
$homedir = getenv("HOME");
}
elseif(function_exists("posix_getuid") && function_exists("posix_getpwuid"))
{
$userinfo = posix_getpwuid(posix_getuid());
$homedir = $userinfo['dir'];
}
else
{
throw new Exception("Could not find a way to get the home directory of the current user.");
}
$homedir = $this->RemoveTrailingSlash($homedir);
$stack = explode("/", $homedir);
array_shift($path_elements);
}
else
{
/* Relative path */
$basepath = $this->RemoveTrailingSlash(getcwd());
$stack = explode("/", $basepath);
}
foreach($path_elements as $element)
{
if($element == ".")
{
/* Ignore */
}
elseif($element == "..")
{
/* Go up one directory */
if(count($stack) > 1)
{
array_pop($stack);
}
else
{
/* There are no elements left to pop, this is an invalid path. */
return null;
}
}
else
{
/* Append to path */
$stack[] = $element;
}
}
return implode("/", $stack);
}
}
}

@ -0,0 +1,128 @@
<style>
body {
background-color: #F5F5F5;
font-family: sans-serif;
margin-right: 40px;
}
.children { padding-left: 40px; }
.definition
{
font-weight: bold;
margin-top: 32px;
}
.example
{
padding: 5px 6px;
font-weight: bold;
font-size: 15px;
background-color: #E6E6E6;
margin-top: 11px;
}
.example > .children
{
padding-top: 11px;
padding-left: 10px;
}
.example > .children > h7
{
font-size: 13px;
}
h7
{
font-size: 14px;
font-weight: bold;
margin-bottom: 2px;
}
pre
{
margin-top: 0px;
padding: 6px 7px;
background-color: #D9D9D9;
font-weight: normal;
font-size: 13px;
}
dl
{
margin: 5px 0px;
}
dt
{
font-weight: bold;
}
dd
{
font-size: 14px;
font-weight: normal;
margin-left: 8px;
}
.exclamation
{
padding: 7px 8px;
margin: 11px 0px;
background-color: #FFE9AA;
border: 1px solid yellow;
font-size: 15px;
font-weight: normal;
}
.text
{
font-size: 15px;
font-weight: normal;
margin: 11px 0px;
}
.toc
{
border: 1px solid gray;
background-color: #E6E6E6;
padding: 8px 9px;
font-size: 15px;
}
.toc h2
{
margin: 0px 0px 3px 0px;
font-size: 19px;
}
.toc ul
{
margin-top: 0px;
margin-bottom: 0px;
padding-left: 25px;
}
.toc li
{
margin-bottom: 2px;
}
.toc .alternatives
{
font-size: 12px;
}
.toc a
{
color: #292722;
}
.toc a:hover
{
color: black;
}
</style><div class="children"><h1>Engine.Random</h1><div class="text">The Random library provides several functions to pick random numbers or items.</div><div class="toc"><h2>Table of contents</h2><ul><li><a href="#def_Engine_Random_Numberminmaxprecision">Engine.Random.Number(min, max, precision)</a> Selects a random number between `min` and `max`, excluding `max` itself. </li><li><a href="#def_Engine_Random_Chooseitemitemitem">Engine.Random.Choose(item [, item [, item ...]])</a> Selects a random item from the supplied items. <span class="alternatives">(also: Engine.Random.Choose(itemarray))</span></li><li><a href="#def_Engine_Random_Pickamountitemitemitem">Engine.Random.Pick(amount, item [, item [, item ...]])</a> Selects <em>amount</em> unique random items from the supplied items. Each item... <span class="alternatives">(also: Engine.Random.Pick(amount, itemarray))</span></li></ul></div><div class="definition"><a name="def_Engine_Random_Numberminmaxprecision">Engine.Random.Number(<em>min</em>, <em>max</em>, <em>precision</em>) <div class="children"><div class="text">Selects a random number between `min` and `max`, excluding `max` itself.</div><dl><dt>min</dt><dd>The minimum number. <em>Defaults to 0.</em></dd></dl><dl><dt>max</dt><dd>The maximum number (itself excluded). <em>Defaults to 1.</em></dd></dl><dl><dt>precision</dt><dd>The precision; this is what the result will be rounded to. <em>Defaults to 0.00000001.</em></dd></dl><div class="example">Example: Get a whole number from 0 to 9 <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Number(0, 10, 1);</pre><h7>Output:</h7><pre class="output">7</pre></div></div><div class="example">Example: Get a one-tenth-precision number from 0 to 9.9 <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Number(0, 10, 0.1);</pre><h7>Output:</h7><pre class="output">3.7</pre></div></div><div class="example">Example: Get a one-fifth-precision number from 5 to 9.8: <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Number(5, 10, 0.2);</pre><h7>Output:</h7><pre class="output">6.4</pre></div></div></div></a></div><div class="definition"><a name="def_Engine_Random_Chooseitemitemitem">Engine.Random.Choose(<em>item</em> [, <em>item</em> [, <em>item</em> ...]])<br> Engine.Random.Choose(<em>itemarray</em>) <div class="children"><div class="text">Selects a random item from the supplied items.</div><dl><dt>item</dt><dd>An item to choose from.</dd></dl><dl><dt>itemarray</dt><dd>An array of items to choose from.</dd></dl><div class="example">Example: Select a random color from a list using multiple arguments <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Choose("blue", "green", "red", "yellow");</pre><h7>Output:</h7><pre class="output">"green"</pre></div></div><div class="example">Example: Select a random day from a list using an array <div class="children"><h7>Code:</h7><pre class="code">var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
Engine.Random.Choose(days);</pre><h7>Output:</h7><pre class="output">"Thursday"</pre></div></div></div></a></div><div class="definition"><a name="def_Engine_Random_Pickamountitemitemitem">Engine.Random.Pick(<em>amount</em>, <em>item</em> [, <em>item</em> [, <em>item</em> ...]])<br> Engine.Random.Pick(<em>amount</em>, <em>itemarray</em>) <div class="children"><div class="text">Selects <em>amount</em> unique random items from the supplied items. Each item can only appear in the result once.</div><div class="exclamation"><strong>Important:</strong> The <em>amount</em> argument must always be equal to or higher than the amount of supplied items!</div><dl><dt>amount</dt><dd>The amount of items to select.</dd></dl><dl><dt>item</dt><dd>An item to choose from.</dd></dl><dl><dt>itemarray</dt><dd>An array of items to choose from.</dd></dl><div class="example">Example: Select three random colors from a list using multiple arguments <div class="children"><h7>Code:</h7><pre class="code">Engine.Random.Pick(3, "red", "green", "blue", "yellow", "purple", "brown", "black", "white", "orange");</pre><h7>Output:</h7><pre class="output">["blue", "orange", "red"]</pre></div></div><div class="example">Example: Select two vegetables from a list using an array <div class="children"><h7>Code:</h7><pre class="code">var vegetables = ["celery", "potato", "tomato", "coleslaw", "onion"];
Engine.Random.Pick(2, vegetables);</pre><h7>Output:</h7><pre class="output">["tomato", "onion"]</pre></div></div></div></a></div></div>

File diff suppressed because one or more lines are too long

@ -0,0 +1,325 @@
# ZippyDoc format documentation
{<documentation.zpy}(Download the ZippyDoc source of this page.)
ZippyDoc is a compact, light-weight and code-oriented documentation markup language.
It allows you to easily write documentation for your code or APIs, and batch-convert it to HTML.
{TOC}
## Format overview
ZippyDoc is a paragraph-oriented format, much like Markdown. Each paragraph represents a "block" of something, and no linebreaks are used anywhere - to start on a new line,
you simply start out with a new paragraph. A block is indicated by a specific prefix. Tabs (not spaces!) are used to indent blocks and indicate children of previous blocks.
A new "paragraph" is started by having two or more successive line-endings - this basically comes down to at least one empty line inbetween paragraphs.
There is also some inline markup available, including emphasis, strong text, and hyperlinks to both other ZippyDoc documents and external locations.
## Blocks
Several block types exist. Some of them have "continuation characters" that indicate the continuation of the previous block in a new paragraph, as opposed to
starting a new block.
^ Definition block
A definition block is prefixed with a caret, and contains something along the lines of a function definition or type.
In this particular document, it is used to denote the types of blocks and markup elements. Inline markup (such as the emphasis for arguments in the below example) is applied.
These blocks are used for a table of contents if you choose to use one.
@ Using a definition block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
You can also have an alternative notation for a definition. This can be useful if you have aliased functions, or multiple input forms.
The alternative notation should be put on the same indentation as the original definition, but without a caret in front. The alternative
notations (there is no limit) are shown separately in the table of contents if you choose to use one. You may indent the alternative
notations with spaces to make the definition easier to read.
@ Using a definition block
$ ^ my_function(**argument**, **another_argument**)
alt_func(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
^ Argument block
An argument block shows a particular argument or parameter, and its explanation. The argument name is suffixed with a double colon (::), and the explanation
follows on the next line. If so desired, the explanation can be indented with a tab - the tabs in front of the explanation will be eaten by the parser. The
explanation can also consist of multiple lines - the newlines are preserved in the HTML version. Inline markup is applied only in the explanation.
@ Using an argument block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
^ Example block
An example block shows an example of the function you are documenting, with code and output. The example block itself is prefixed with an @, and only specifies a title;
you will use indented children of the Code and Output block variety to show respectively the code and the output for the example. These blocks will be explained later on.
The title of your example block will be prefixed with "Example:" in the output automatically.
@ Using an example block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
$$ @ Using this function
$$ $ Some code goes here.
$$ > Some output goes here.
^ Code block
The code block is used in an example to show example code. It is prefixed with a dollar sign ($), and all text following it will be show on the HTML page verbatim, without
any further markup processing being done. It even allows you to display ZippyDoc formatting characters without having them interpreted, as is done on this page!
@ Using a code block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
$$ @ Using this function
$$ $ my_function(42, "The answer to everything")
$$ > Some output goes here.
It is also possible to have a code block spanning multiple paragraphs, without each paragraph being broken up into a separate code block (as would normally happen if you
just used the dollar sign). To do this, you can use two dollar signs at the start of the block. Note that after these two dollar signs, whitespace (except for spaces) is
**not** eaten, meaning you can use tabs to indent further blocks of your code!
@ Using a multi-paragraph code block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
$$ @ Using this function
$$ $ if some_variable == True:
$$ $$ my_function(42, "The answer to everything")
$$ > Some output goes here.
^ Output block
The output block is used to display sample output in an example. Just like the code block, it is shown exactly as it originally was, without any further formatting applied.
It is prefixed by a >, and like the code block it has a continuation character - in this case, that is >>.
@ Using an output block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
$$ @ Using this function
$$ $ my_function(42, "The answer to everything")
$$ > The answer to everything is 42!
@ Using a multi-paragraph output block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
$$ @ Using this function
$$ $ my_function(42, "The answer to everything")
$$ > The answer to everything is 42!
$$ >> Did you know The answer to everything is 42?
^ Exclamation block
The exclamation block allows you to mark a block of text as "important". In the standard HTML layout, it will have a yellow-ish background, and will be prefixed
with "__Important!__". It is prefixed with an exclamation mark (!). Inline markup is applied.
@ Using an exclamation block
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ ! Only ever use this function with the number '42'!
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
$$ @ Using this function
$$ $ my_function(42, "The answer to everything")
$$ > The answer to everything is 42!
^ Header block
A header block is a generic header to indicate the start of a new section. It is treated as a separate element, not as a "container". The header blocks in ZippyDoc
work similarly to those in Markdown: they are prefixed by a hash (#), and the amount of hash characters defines what level of header it is.
@ Using header blocks
$ # This is a level 1 (largest) header.
$$ ## This is a level 2 header.
$$ ...
$$ ####### This is a level 7 (smallest) header.
^ Text block
A text block is any block that is not prefixed by a special character. It is shown as defined, with inline markup applied.
## Inline markup
There are also various forms of inline markup that you can use in your documentation.
^ Emphasized text
Emphasized text is typically displayed as italic. You can emphasize text by enclosing it in two asterisks on each side.
@ Emphasizing text
$ This is just some text, and **this part is emphasized**.
^ Strong text
Strong text is typically displayed as bold. You can make text strong by enclosing it in two underscores on each side.
@ Making text strong
$ This is just some text, __and this part is strong__.
^ Internal references (hyperlinks)
Internal references are hyperlinks that point to other documents in the same documentation set. Depending on the export format (currently only HTML is supported),
the appropriate extension is automatically appended. The paths should resemble the directory structure you are storing the ZippyDoc source files in. The target
of the reference is enclosed in curly braces and prefixed with a >. If you wish to give the reference a friendly description, you can do so by appending it,
enclosed in parentheses.
@ Referencing another documentation page
$ You can also view the API documentation at {>api/index}.
@ Referencing another documentation page with a friendly description
$ You can also view the {>api/index}(API documentation).
^ External references (hyperlinks)
External references are hyperlinks just like the internal references, but they refer to an external resources. The syntax is identical to that of internal references,
except for the > disappearing. Note that external references are only picked up when the text enclosed in the braces is an actual URI of some sort.
You can also force an external reference to be created by prefixing the URI with <. This is useful when you want to for example link to a download relative to the current
page.
@ Referencing Google
$ You could also search {http://www.google.com/}.
@ Referencing another documentation page with a friendly description
$ You could also search {http://www.google.com/}(Google).
@ Referencing a relative file that is not a ZippyDoc document
$ You can download it by {<file.zip}(clicking here).
^ Fixed-width text
Fixed-width text can be useful to indicate code elements or other things that would benefit from being displayed in a terminal-like font. You can make text fixed-width
by enclosing it in backticks.
@ Fixed-width text
$ Now enter `./run.sh` into your terminal.
## Special tags
Currently there is only one special tag. Special tags can be inserted anywhere in the document to insert a generated element.
^ Table of contents
To insert a table of contents that is automatically generated from all definition blocks on the page, simply insert {TOC} on the page where you want it to appear (it has
to be in its own paragraph). Typically you will want to place it just below the main page header.
Every item in a table of contents will be followed by a snippet of text, that is grabbed from the first Text block for that definition. Alternative notations are shown
after this description.
@ Including a table of contents
$ # Sample documentation
$$ {TOC}
$$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here.
$$ ...
## Full example
You can {>example}(view a full example here) of a ZippyDoc source file and its result.

@ -0,0 +1,177 @@
<!doctype html>
<html>
<head>
<style>
body {
background-color: #F5F5F5;
font-family: sans-serif;
margin-right: 40px;
}
h2, h3, h4, h5, h6, h7
{
margin-top: 16px;
margin-bottom: 4px;
}
.children { padding-left: 40px; }
.definition
{
font-weight: bold;
margin-bottom: 32px;
}
.example
{
padding: 5px 6px;
font-weight: bold;
font-size: 15px;
background-color: #E6E6E6;
margin-top: 11px;
}
.example > .children
{
padding-top: 11px;
padding-left: 10px;
}
.example > .children > h7
{
font-size: 13px;
}
h7
{
font-size: 14px;
font-weight: bold;
margin-bottom: 2px;
}
pre
{
margin-top: 0px;
padding: 6px 7px;
background-color: #D9D9D9;
font-weight: normal;
font-size: 13px;
}
dl
{
margin: 5px 0px;
}
dt
{
font-weight: bold;
}
dd
{
font-size: 14px;
font-weight: normal;
margin-left: 8px;
}
.exclamation
{
padding: 7px 8px;
margin: 11px 0px;
background-color: #FFE9AA;
border: 1px solid yellow;
font-size: 15px;
font-weight: normal;
}
.text
{
font-size: 15px;
font-weight: normal;
margin-bottom: 14px;
margin-top: 10px;
}
.toc
{
border: 1px solid gray;
background-color: #E6E6E6;
padding: 8px 9px;
font-size: 15px;
}
.toc h2
{
margin: 0px 0px 3px 0px;
font-size: 19px;
}
.toc ul
{
margin-top: 0px;
margin-bottom: 0px;
padding-left: 25px;
}
.toc li
{
margin-bottom: 2px;
}
.toc .alternatives
{
font-size: 12px;
}
.toc a
{
color: #292722;
}
.toc a:hover
{
color: black;
}
.fixed
{
font-family: monospace;
background-color: white;
padding: 1px 4px;
border: 1px solid silver;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="children"><h1>A complete example</h1><h7>Code:</h7><pre class="code">^ my_function(**argument**, **another_argument**)
Some kind of text describing the function goes here. `Also some mono-spaced text.`
! Only ever use this function with the number '42'!
argument::
This is the first argument to this example function.
another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
We can also add an {&gt;documentation}(internal link) and an {http://google.com/}(external link).
@ Using this function
$ if some_variable == True:
$$ my_function(42, "The answer to everything")
&gt; The answer to everything is 42!
&gt;&gt; Did you know The answer to everything is 42?</pre><h2>Result</h2><div class="definition"><a name="def_my_functionargumentanother_argument">my_function(<em>argument</em>, <em>another_argument</em>) <div class="children"><div class="text">Some kind of text describing the function goes here. <span class="fixed">Also some mono-spaced text.</span></div><div class="exclamation"><strong>Important:</strong> Only ever use this function with the number '42'!</div><dl><dt>argument</dt><dd>This is the first argument to this example function.</dd></dl><dl><dt>another_argument</dt><dd>This is the second argument to this example function. As you can see, it's possible to split the explanation over multiple lines as well. We can also add an <a href="documentation.html">internal link</a> and an <a href="http://google.com/">external link</a>.</dd></dl><div class="example">Example: Using this function <div class="children"><h7>Code:</h7><pre class="code">if some_variable == True:
my_function(42, "The answer to everything")</pre><h7>Output:</h7><pre class="output">The answer to everything is 42!
Did you know The answer to everything is 42?</pre></div></div></div></a></div></div>
</body>
</html>

@ -0,0 +1,51 @@
# A complete example
$ ^ my_function(**argument**, **another_argument**)
$$ Some kind of text describing the function goes here. `Also some mono-spaced text.`
$$ ! Only ever use this function with the number '42'!
$$ argument::
This is the first argument to this example function.
$$ another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
We can also add an {>documentation}(internal link) and an {http://google.com/}(external link).
$$ @ Using this function
$$ $ if some_variable == True:
$$ $$ my_function(42, "The answer to everything")
$$ > The answer to everything is 42!
$$ >> Did you know The answer to everything is 42?
## Result
^ my_function(**argument**, **another_argument**)
Some kind of text describing the function goes here. `Also some mono-spaced text.`
! Only ever use this function with the number '42'!
argument::
This is the first argument to this example function.
another_argument::
This is the second argument to this example function.
As you can see, it's possible to split the explanation over multiple lines as well.
We can also add an {>documentation}(internal link) and an {http://google.com/}(external link).
@ Using this function
$ if some_variable == True:
$$ my_function(42, "The answer to everything")
> The answer to everything is 42!
>> Did you know The answer to everything is 42?

@ -0,0 +1,167 @@
<!doctype html>
<html>
<head>
<style>
body {
background-color: #F5F5F5;
font-family: sans-serif;
margin-right: 40px;
}
h2, h3, h4, h5, h6, h7
{
margin-top: 16px;
margin-bottom: 4px;
}
.children { padding-left: 40px; }
.definition
{
font-weight: bold;
margin-bottom: 32px;
}
.example
{
padding: 5px 6px;
font-weight: bold;
font-size: 15px;
background-color: #E6E6E6;
margin-top: 11px;
}
.example > .children
{
padding-top: 11px;
padding-left: 10px;
}
.example > .children > h7
{
font-size: 13px;
}
h7
{
font-size: 14px;
font-weight: bold;
margin-bottom: 2px;
}
pre
{
margin-top: 0px;
padding: 6px 7px;
background-color: #D9D9D9;
font-weight: normal;
font-size: 13px;
}
dl
{
margin: 5px 0px;
}
dt
{
font-weight: bold;
}
dd
{
font-size: 14px;
font-weight: normal;
margin-left: 8px;
}
.exclamation
{
padding: 7px 8px;
margin: 11px 0px;
background-color: #FFE9AA;
border: 1px solid yellow;
font-size: 15px;
font-weight: normal;
}
.text
{
font-size: 15px;
font-weight: normal;
margin-bottom: 14px;
margin-top: 10px;
}
.toc
{
border: 1px solid gray;
background-color: #E6E6E6;
padding: 8px 9px;
font-size: 15px;
}
.toc h2
{
margin: 0px 0px 3px 0px;
font-size: 19px;
}
.toc ul
{
margin-top: 0px;
margin-bottom: 0px;
padding-left: 25px;
}
.toc li
{
margin-bottom: 2px;
}
.toc .alternatives
{
font-size: 12px;
}
.toc a
{
color: #292722;
}
.toc a:hover
{
color: black;
}
.fixed
{
font-family: monospace;
background-color: white;
padding: 1px 4px;
border: 1px solid silver;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="children"><h1>ZippyDoc</h1><div class="text">Hi, this is the website of ZippyDoc, a compact, light-weight and human-readable format for documenting code, APIs, and other things, that can be easily converted to HTML.</div><div class="text">It is designed primarily to be simple to use (unlike complex markup languages like reStructuredText), and very code-oriented (unlike other simple markup languages like Markdown). You will probably learn the entire syntax in about 10 minutes.</div><div class="text">ZippyDoc (both the format and the parser) are licensed under the <a href="http://www.wtfpl.net/">WTFPL</a>, meaning you can basically do with it whatever you want, and reuse it in any fashion you see fit. I hope it will help you write nicer, easier, and more complete documentation!</div><div class="text">While ZippyDoc is technically intended for documentation, I decided to whip up a simple index page in ZippyDoc as well - you're looking at it! :)</div><h2>What does the ZippyDoc format look like?</h2><h7>Code:</h7><pre class="code">^ my_function(argument1, argument2)
! This is just an example!
This is a function.
argument1::
This is the first argument.
argument2::
This is the second argument.
@ How to call my_function
$ my_function("ZippyDoc", "awesome")
&gt; "ZippyDoc is awesome!"</pre><h7>Result:</h7><div class="definition"><a name="def_my_functionargument1argument2">my_function(argument1, argument2) <div class="children"><div class="exclamation"><strong>Important:</strong> This is just an example!</div><div class="text">This is a function.</div><dl><dt>argument1</dt><dd>This is the first argument.</dd></dl><dl><dt>argument2</dt><dd>This is the second argument.</dd></dl><div class="example">Example: How to call my_function <div class="children"><h7>Code:</h7><pre class="code">my_function("ZippyDoc", "awesome")</pre><h7>Output:</h7><pre class="output">"ZippyDoc is awesome!"</pre></div></div></div></a></div><h2>Documentation</h2><div class="text">The documentation for ZippyDoc can be found <a href="documentation.html">here</a>.</div><h2>Downloading ZippyDoc</h2><div class="text">ZippyDoc is still in a pretty messy stage, but it should already work reliably according to the current documentation. GitHub repository is coming soon, until that time you can <a href="zpy2html.py">download the conversion script here</a>. It's a Python script, so you'll need a Python interpreter of some sort. No dependencies are necessary, it only uses standard library functionality. Simply run it with all files you wish to convert as arguments, and it will convert each of them into a file with the same name, but a <em>.html</em> extension instead of the original extension. It's strongly recommended to name your ZippyDoc source files with the <em>.zpy</em> extension.</div></div>
</body>
</html>

@ -0,0 +1,62 @@
# ZippyDoc
Hi, this is the website of ZippyDoc, a compact, light-weight and human-readable format for documenting code, APIs, and other things, that can be easily converted to HTML.
It is designed primarily to be simple to use (unlike complex markup languages like reStructuredText), and very code-oriented (unlike other simple markup languages like Markdown).
You will probably learn the entire syntax in about 10 minutes.
ZippyDoc (both the format and the parser) are licensed under the {http://www.wtfpl.net/}(WTFPL), meaning you can basically do with it whatever you want, and reuse it in any
fashion you see fit. I hope it will help you write nicer, easier, and more complete documentation!
While ZippyDoc is technically intended for documentation, I decided to whip up a simple index page in ZippyDoc as well - you're looking at it! :)
## What does the ZippyDoc format look like?
$ ^ my_function(argument1, argument2)
$$ ! This is just an example!
$$ This is a function.
$$ argument1::
This is the first argument.
$$ argument2::
This is the second argument.
$$ @ How to call my_function
$$ $ my_function("ZippyDoc", "awesome")
$$ > "ZippyDoc is awesome!"
####### Result:
^ my_function(argument1, argument2)
! This is just an example!
This is a function.
argument1::
This is the first argument.
argument2::
This is the second argument.
@ How to call my_function
$ my_function("ZippyDoc", "awesome")
> "ZippyDoc is awesome!"
## Documentation
The documentation for ZippyDoc can be found {>documentation}(here).
## Downloading ZippyDoc
ZippyDoc is still in a pretty messy stage, but it should already work reliably according to the current documentation. GitHub repository is coming soon, until that time you can
{<zpy2html.py}(download the conversion script here). It's a Python script, so you'll need a Python interpreter of some sort. No dependencies are necessary, it only uses standard
library functionality. Simply run it with all files you wish to convert as arguments, and it will convert each of them into a file with the same name, but a **.html** extension
instead of the original extension. It's strongly recommended to name your ZippyDoc source files with the **.zpy** extension.

@ -0,0 +1,391 @@
import os, argparse, sys, re
parser = argparse.ArgumentParser(description='Converts ZippyDoc source files to HTML.')
parser.add_argument('files', metavar='FILE', type=str, nargs='+',
help='files to convert to HTML')
args = parser.parse_args()
options = vars(args)
files = options["files"]
template = """
<!doctype html>
<html>
<head>
<style>
body {
background-color: #F5F5F5;
font-family: sans-serif;
margin-right: 40px;
}
h2, h3, h4, h5, h6, h7
{
margin-top: 16px;
margin-bottom: 4px;
}
.children { padding-left: 40px; }
.definition
{
font-weight: bold;
margin-bottom: 32px;
}
.example
{
padding: 5px 6px;
font-weight: bold;
font-size: 15px;
background-color: #E6E6E6;
margin-top: 11px;
}
.example > .children
{
padding-top: 11px;
padding-left: 10px;
}
.example > .children > h7
{
font-size: 13px;
}
h7
{
font-size: 14px;
font-weight: bold;
margin-bottom: 2px;
}
pre
{
margin-top: 0px;
padding: 6px 7px;
background-color: #D9D9D9;
font-weight: normal;
font-size: 13px;
}
dl
{
margin: 5px 0px;
}
dt
{
font-weight: bold;
}
dd
{
font-size: 14px;
font-weight: normal;
margin-left: 8px;
}
.exclamation
{
padding: 7px 8px;
margin: 11px 0px;
background-color: #FFE9AA;
border: 1px solid yellow;
font-size: 15px;
font-weight: normal;
}
.text
{
font-size: 15px;
font-weight: normal;
margin-bottom: 14px;
margin-top: 10px;
}
.toc
{
border: 1px solid gray;
background-color: #E6E6E6;
padding: 8px 9px;
font-size: 15px;
}
.toc h2
{
margin: 0px 0px 3px 0px;
font-size: 19px;
}
.toc ul
{
margin-top: 0px;
margin-bottom: 0px;
padding-left: 25px;
}
.toc li
{
margin-bottom: 2px;
}
.toc .alternatives
{
font-size: 12px;
}
.toc a
{
color: #292722;
}
.toc a:hover
{
color: black;
}
.fixed
{
font-family: monospace;
background-color: white;
padding: 1px 4px;
border: 1px solid silver;
border-radius: 4px;
}
</style>
</head>
<body>
%s
</body>
</html>
"""
class TreeLevel:
def __init__(self, indentation, data):
self.elements = []
self.indentation = indentation
self.data = data
def add(self, element):
self.elements.append(element)
def output(self):
return self.render()
def render_children(self):
child_output = ""
for child in self.elements:
child_output += child.output()
return '<div class="children">%s</div>' % child_output
def process_inline_markup(self, text):
text = re.sub("`([^`]+)`", '<span class="fixed">\\1</span>', text) # Emphasized
text = re.sub("\*\*([^*]+)\*\*", "<em>\\1</em>", text) # Emphasized
text = re.sub("__([^_]+)__", "<strong>\\1</strong>", text) # Strong
text = re.sub("{>([^}]+)}\(([^)]+)\)", '<a href="\\1.html">\\2</a>', text) # Hyperlink with text
text = re.sub("{>([^}]+)}", '<a href="\\1.html">\\1</a>', text) # Hyperlink
text = re.sub("{([^}]+:[^}]+)}\(([^)]+)\)", '<a href="\\1">\\2</a>', text) # External hyperlink with text
text = re.sub("{([^}]+:[^}]+)}", '<a href="\\1">\\1</a>', text) # External hyperlink
text = re.sub("{<([^}]+)}\(([^)]+)\)", '<a href="\\1">\\2</a>', text) # Forced external hyperlink with text
text = re.sub("{<([^}]+)}", '<a href="\\1">\\1</a>', text) # Forced external hyperlink
return text
def fix_preformatted(self, text):
return text.replace("<", "&lt;").replace(">", "&gt;")
def clear_markup(self, text):
return re.sub("\*\*([^*]+)\*\*", "\\1", text)
def render(self):
return self.render_children()
class Example(TreeLevel):
def render(self):
return '<div class="example">Example: %s %s</div>' % (self.data, self.render_children())
class Code(TreeLevel):
def render(self):
return '<h7>Code:</h7><pre class="code">%s</pre>' % self.fix_preformatted(self.data)
class Output(TreeLevel):
def render(self):
return '<h7>Output:</h7><pre class="output">%s</pre>' % self.fix_preformatted(self.data)
class Definition(TreeLevel):
def get_anchor(self):
first = self.clear_markup(self.data.splitlines()[0])
anchor = first.replace("...", "")
anchor = anchor.replace(".", "_")
anchor = re.sub("[^a-zA-Z0-9_]", "", anchor)
return anchor
def get_description(self):
for element in self.elements:
if element.__class__.__name__ == "Text":
data = self.process_inline_markup(element.data)
if len(data) > 80:
matches = re.match("^(.{0,80})\W", data)
return matches.group(1) + "..."
else:
return data
return ""
def render(self):
return '<div class="definition"><a name="def_%s">%s %s</a></div>' % (self.get_anchor(), self.process_inline_markup(self.data.replace("\n", "<br>")), self.render_children())
class Exclamation(TreeLevel):
def render(self):
return '<div class="exclamation"><strong>Important:</strong> %s</div>' % self.process_inline_markup(self.data)
class Argument(TreeLevel):
def __init__(self, indentation, data, argname):
self.elements = []
self.indentation = indentation
self.argname = argname
self.data = data
def render(self):
return '<dl><dt>%s</dt><dd>%s</dd></dl>' % (self.argname, self.process_inline_markup(self.data))
class Header(TreeLevel):
def __init__(self, indentation, data, depth):
self.elements = []
self.indentation = indentation
self.depth = depth
self.data = data
def render(self):
if self.depth <= 7:
title_type = "h%d" % self.depth
else:
title_type = "h7"
return "<%s>%s</%s>" % (title_type, self.data, title_type)
class Text(TreeLevel):
def render(self):
return '<div class="text">%s</div>' % self.process_inline_markup(self.data)
class Index(TreeLevel):
def render(self):
global toc_items
rendered = ""
for item in toc_items:
forms = item.data.splitlines()
first = self.clear_markup(forms[0])
if len(forms) > 1:
rest = '<span class="alternatives">(also: ' + ', '.join(self.clear_markup(form) for form in forms[1:]) + ")</span>"
else:
rest = ""
anchor = item.get_anchor()
description = item.get_description()
rendered += '<li><a href="#def_%s">%s</a> %s %s</li>' % (anchor, first, description, rest)
return '<div class="toc"><h2>Table of contents</h2><ul>%s</ul></div>' % rendered
for zpy in files:
destination = os.path.splitext(zpy)[0] + ".html"
f = open(zpy, "r")
data = f.read()
f.close()
paragraphs = re.split("\s*\n\s*\n", data)
toc_items = []
current_level = 0
current_paragraph = 0
current_elements = {0: TreeLevel(0, "root")}
for paragraph in paragraphs:
if paragraph.strip() == "":
continue
current_paragraph += 1
indentation = len(paragraph) - len(paragraph.lstrip("\t")) + 1
if indentation > current_level + 1:
raise Exception("Invalid indentation found in paragraph %d" % current_paragraph)
element_type = TreeLevel
start = indentation - 1
lines = [line[start:] for line in paragraph.splitlines()]
if lines[0].startswith("#"):
element_type = Header
depth = len(lines[0]) - len(lines[0].lstrip("#"))
lines[0] = lines[0].lstrip("# ")
data = " ".join(lines)
elif lines[0].startswith("^"):
element_type = Definition
lines[0] = lines[0].lstrip("^ ")
data = "\n".join(lines)
elif lines[0].startswith("@"):
element_type = Example
lines[0] = lines[0].lstrip("@ ")
data = " ".join(lines)
elif lines[0].startswith("$$") and current_elements[current_level].__class__.__name__ == "Code":
current_elements[current_level].data += "\n\n" + "\n".join(lines).lstrip("$ ")
continue
elif lines[0].startswith("$"):
element_type = Code
lines[0] = lines[0].lstrip("$ ")
data = "\n".join(lines)
elif lines[0].startswith(">>") and current_elements[current_level].__class__.__name__ == "Output":
current_elements[current_level].data += "\n\n" + "\n".join(lines).lstrip("> ")
continue
elif lines[0].startswith(">"):
element_type = Output
lines[0] = lines[0].lstrip("> ")
data = "\n".join(lines)
elif lines[0].startswith("!"):
element_type = Exclamation
lines[0] = lines[0].lstrip("! ")
data = " ".join(lines)
elif re.match(".*::\s*$", lines[0]):
element_type = Argument
argname = lines[0][:-2]
data = " ".join(line.lstrip() for line in lines[1:])
elif lines[0].strip() == "{TOC}":
element_type = Index
data = ""
else:
element_type = Text
data = " ".join(lines)
#print "Found element of type %s at indentation %d with data %s" % (element_type.__name__, indentation, data[:80])
if element_type.__name__ == "Header":
element = Header(indentation, data, depth)
elif element_type.__name__ == "Argument":
element = Argument(indentation, data, argname)
else:
element = element_type(indentation, data)
if element_type.__name__ == "Definition":
toc_items.append(element)
current_elements[indentation - 1].add(element)
current_level = indentation
current_elements[current_level] = element
rendered = template % (current_elements[0].output())
f = open(destination, "w")
f.write(rendered)
f.close()
print "Rendered %s" % destination

@ -0,0 +1,89 @@
#!/usr/bin/python
import argparse, os, urllib, json, subprocess, urllib2
parser = argparse.ArgumentParser(description='Searches for music files')
parser.add_argument('-c', dest='limit', action='store', default='10',
help='maximum amount of results to show (don\'t overdo it please)')
parser.add_argument('-v', dest='vlc', action='store_true', default='false',
help='play in VLC media player')
parser.add_argument('query', metavar='QUERY', type=str, nargs='+',
help='destination path for generated class files.')
args = parser.parse_args()
options = vars(args)
query = " ".join(options['query'])
limit = int(options['limit'])
results = urllib.urlopen("http://ex.fm/api/v3/song/search/%s?results=%d" % (urllib.quote_plus(query), limit)).read()
try:
result_object = json.loads(results)
except ValueError:
print "No valid result was returned from the ex.fm API. Exiting..."
exit(1)
if result_object['status_code'] != 200:
print "An error code was returned by the ex.fm API. Exiting..."
exit(1)
print "Searching for '%s'..." % query
if result_object['total'] <= 0:
print "No results."
exit(1)
print ""
for track in result_object['songs']:
if track['artist'] is None:
artist = "Unknown"
else:
artist = track['artist']
if track['album'] is None:
album = "Unknown"
else:
album = track['album']
if track['title'] is None:
title = "Unknown"
else:
title = track['title']
print "Artist: %s\t Album: %s" % (artist, album)
print "Title: %s" % title
print " %s" % track['url']
print ""
if options['vlc'] == True:
print "Playing the first working result in VLC media player..."
working_url = ""
for track in result_object['songs']:
try:
response = urllib2.urlopen(track['url'])
except urllib2.URLError, e:
continue
headers = response.info()
if "text/html" in headers['Content-Type']:
continue
working_url = track['url']
break
if working_url != "":
with open(os.devnull, 'w') as stfu:
subprocess.Popen(["vlc", "--one-instance", working_url], stdin=None, stdout=stfu, stderr=stfu)
exit(0)
else:
print "No working URLs found."
exit(1)

@ -0,0 +1,126 @@
#!/usr/bin/python
# This script will run the appropriate command to print archive contents to stdout
# Written by Sven Slootweg, Licensed under WTFPL - in other words, feel free to reuse for whatever purpose you desire.
import os, argparse, sys, subprocess
parser = argparse.ArgumentParser(description='Prints the uncompressed contents of archives to stdout, based on certain criteria.')
parser.add_argument('pattern', metavar='FILES', type=str, nargs='+',
help='files to parse')
parser.add_argument('-s', dest='size', action='store', default=None,
help='size requirement that has to be satisfied for a file to be printed (use < and >)')
args = parser.parse_args()
options = vars(args)
def exit_script():
sys.stderr.write("Exiting...\n")
exit(1)
def to_bytes(size):
size = size.lower().strip()
if size.endswith("t"):
return int(size[:-1]) * 1024 * 1024 * 1024 * 1024
elif size.endswith("g"):
return int(size[:-1]) * 1024 * 1024 * 1024
elif size.endswith("m"):
return int(size[:-1]) * 1024 * 1024
elif size.endswith("k"):
return int(size[:-1]) * 1024
else:
return int(size)
def from_bytes(size, unit):
size = int(size)
unit = unit.lower()
if unit == 't':
return size * 1.0 / (1024 * 1024 * 1024 * 1024)
elif unit == 'g':
return size * 1.0 / (1024 * 1024 * 1024)
elif unit == 'm':
return size * 1.0 / (1024 * 1024)
elif unit == 'k':
return size * 1.0 / (1024)
else:
return size
specifications = {}
if options['size'] is not None:
# Parse size specification
for specification in options['size'].split(","):
if specification[:1] == "<":
specifications['<'] = specification[1:].strip()
elif specification[:1] == ">":
specifications['>'] = specification[1:].strip()
elif specification[:1] == "=":
specifications['='] = specification[1:].strip()
else:
sys.stderr.write("Incorrect size specification: %s\n" % specification)
exit_script()
# Select all files matching the given pattern
file_list = options['pattern']
for item in file_list:
data = os.stat(item)
filesize = data.st_size
try:
if filesize >= to_bytes(specifications['<']):
continue
except KeyError, e:
pass
try:
if filesize <= to_bytes(specifications['>']):
continue
except KeyError, e:
pass
try:
if int(from_bytes(filesize, specifications['='][-1:])) != specifications['=']:
continue
except KeyError, e:
pass
# Passed all size tests, let's process it
with open(os.devnull, 'w') as stfu:
if item.endswith(".7z"):
processor = "7zip"
returncode = subprocess.call(['7z', 'e', '-so', item], stderr=stfu)
elif item.endswith(".tar"):
processor = "tar"
returncode = subprocess.call(['tar', '-Oxf', item], stderr=stfu)
elif item.endswith(".tar.gz"):
processor = "tar/gzip"
returncode = subprocess.call(['tar', '-Oxzf', item], stderr=stfu)
elif item.endswith(".tar.bz2"):
processor = "tar/bzip2"
returncode = subprocess.call(['tar', '-Oxjf', item], stderr=stfu)
elif item.endswith(".gz"):
processor = "gzip"
returncode = subprocess.call(['gzip', '-cd', item], stderr=stfu)
elif item.endswith(".bz2"):
processor = "bzip2"
returncode = subprocess.call(['bzip2', '-cd', item], stderr=stfu)
elif item.endswith(".zip"):
processor = "unzip"
returncode = subprocess.call(['unzip', '-p', item], stderr=stfu)
else:
sys.stderr.write("WARNING: Skipping item %s, not a recognized archive type\n" % item)
continue
if returncode == 0:
sys.stderr.write("Successfully output %s\n" % item)
elif returncode == 2:
sys.stderr.write("ERROR: Could not run the needed command - are you sure you have %s installed?\n" % processor)
else:
sys.stderr.write("ERROR: Failed to output %s\n" % item)

@ -0,0 +1 @@
find ./ -name "*.xhtml" | xargs sed -i.bak -r -e "s/%([0-9A-Z]{2})/%25\\1/g"

@ -0,0 +1,31 @@
#!/usr/bin/python
import sys
lines = open(sys.argv[1]).readlines()
accounts = {}
password_count = 0
for line in lines:
try:
username, password = line.split("-")
username = username.strip()[1:-1]
password = password.strip()[1:-1]
if username not in accounts:
accounts[username] = [password]
password_count += 1
else:
if password not in accounts[username]:
accounts[username].append(password)
password_count += 1
except ValueError, e:
pass
for username, passwords in accounts.iteritems():
for password in passwords:
print "%s\t\t%s" % (username, password)
print "Done, %d accounts with a total of %d passwords." % (len(accounts), password_count)

@ -0,0 +1,8 @@
dnsbl.dronebl.org
combined.abuse.ch
opm.tornevall.org
torserver.tor.dnsbl.sectoor.de
socks.dnsbl.sorbs.net
http.dnsbl.sorbs.net
b.barracudacentral.org
sbl.spamhaus.org

@ -0,0 +1,141 @@
import socket, argparse, sys, time, re
from collections import deque
from threading import Thread
dnsbls = open("dnsbl.txt").readlines()
socket.setdefaulttimeout(0.5)
total_checking = 0
class CheckThread(Thread):
def __init__(self, username, ip):
Thread.__init__(self)
self.username = username
self.ip = ip
def run(self):
global total_checking
reversed_ip = ".".join(self.ip.split(".")[::-1])
for dnsbl in dnsbls:
dnsbl = dnsbl.strip()
try:
socket.gethostbyname(reversed_ip + "." + dnsbl)
# This is bad.
#sock.send("MODE #bottest +b *@%s\r\n" % self.ip)
#sock.send("KICK #bottest %s :User %s is blacklisted in %s!\r\n" % (self.username, self.username, dnsbl))
#sock.send("PRIVMSG #bottest :User %s is blacklisted in %s!\r\n" % (self.username, dnsbl))
#sock.send("PRIVMSG #bottest :User %s is blacklisted in %s!\r\n" % (self.username, dnsbl))
sock.send("KILL %s :User %s is blacklisted in %s!\r\n" % (self.username, self.username, dnsbl))
print "IP %s is blacklisted in %s!" % (self.ip, dnsbl)
total_checking -= 1
return False
except:
# This is good.
print "No blacklist matches found for %s" % self.ip
pass
sock.send("PRIVMSG #bottest :User %s is clean.\r\n" % self.username)
total_checking -= 1
return True
def run_tocheck():
if total_checking <= 20 and len(to_check) > 0:
nickname = to_check.popleft()
ip = users[nickname]
t = CheckThread(nickname, ip)
t.start()
def split_irc(message):
message = re.sub("(?<=[0-9A-Fa-fI]):(?=[0-9A-Fa-fI])", "[..]", message)
if ":" in message:
first, second = message.split(":", 1)
return first.rstrip().split(" ") + [second]
else:
return message.split(" ")
parser = argparse.ArgumentParser(description='Connects to an IRC network and scans for proxies.')
parser.add_argument('-H', dest='hostname', action='store', required=True,
help='server to connect to')
parser.add_argument('-o', dest='port', action='store', required=True,
help='port* to connect to')
parser.add_argument('-u', dest='username', action='store', required=True,
help='oper username')
parser.add_argument('-p', dest='password', action='store', required=True,
help='oper password')
args = parser.parse_args()
options = vars(args)
to_check = deque([])
users = {}
print "Connecting...",
sock = socket.socket()
sock.settimeout(None)
sock.connect((options['hostname'], int(options['port'])))
readbuffer = ""
print "connected"
sock.send("NICK botkill\r\n")
sock.send("USER botkill %s 0 :ipcheck.py\r\n" % options['hostname'])
print "Registered."
while True:
readbuffer = readbuffer + sock.recv(1024)
lines = readbuffer.split("\n")
readbuffer = lines.pop()
for line in lines:
run_tocheck()
if line.startswith(":"):
origin, line = line.split(" ", 1)
line = line.rstrip()
parts = split_irc(line)
if parts[0] == "PING":
sock.send("PONG %s\r\n" % parts[1])
print "Completed connection challenge."
elif parts[0] == "001":
sock.send("OPER %s %s\r\n" % (options['username'], options['password']))
elif parts[0] == "381":
print "Authenticated as oper."
sock.send("JOIN #bottest\r\n")
elif parts[0] == "JOIN":
if parts[1].lower() == "#bottest":
username = origin[1:].split("!")[0]
print username + " joined"
sock.send("USERIP %s\r\n" % username)
elif parts[0] == "340":
try:
data = parts[2].split("=", 1)
nickname = data[0]
if nickname.endswith("*"):
nickname = nickname[:-1]
ip = data[1].split("@", 1)[1]
users[nickname] = ip
to_check.append(nickname)
run_tocheck()
print "User %s has IP %s" % (nickname, ip)
except:
pass
elif parts[0] == "491":
print "Invalid oper credentials given."
exit(1)
time.sleep(0.005)

@ -41,10 +41,20 @@ parser.add_argument('--gline', dest='action_gline', action='store_true',
parser.add_argument('--kill', dest='action_kill', action='store_true',
help='kill all matching users')
parser.add_argument('--unrealircd', dest='ircd_unreal', action='store_true',
help='assume UnrealIRCd')
parser.add_argument('--inspircd', dest='ircd_insp', action='store_true',
help='assume InspIRCd')
args = parser.parse_args()
options = vars(args)
if options['ircd_unreal'] == False and options['ircd_insp'] == False:
print "You did not specify an IRCd. Try again with --inspircd or --unrealircd switch."
exit(1)
print "Connecting...",
sock = socket.socket()
@ -77,7 +87,12 @@ while True:
sock.send("OPER %s %s\r\n" % (options['username'], options['password']))
elif parts[0] == "381":
print "Authenticated as oper."
sock.send("WHO ** h\r\n")
if options['ircd_insp'] == True:
# InspIRCd
sock.send("WHO ** h\r\n")
elif options['ircd_unreal'] == True:
# UnrealIRCd
sock.send("WHO +hR **\r\n")
print "Requested userlist."
elif parts[0] == "352":
try:

@ -0,0 +1,99 @@
#!/usr/bin/python
start_page = "http://www.devilskitchen.me.uk/"
default_headers = {
'User-Agent': "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13",
'Referer': start_page
}
import re, urllib2, datetime, argparse, os, json, time
from bs4 import BeautifulSoup
parser = argparse.ArgumentParser(description='Archive posts for devilskitchen.me.uk in JSON format')
parser.add_argument('-O', dest='output_dir', action='store', default='.',
help='output directory for archived posts')
args = parser.parse_args()
options = vars(args)
try:
os.mkdir(options['output_dir'])
except:
pass
def fetch_page_headers(url, headers):
request = urllib2.Request(url, headers=headers)
opener = urllib2.build_opener()
response = opener.open(request)
return (response.code, response.headers, response.read())
def fetch_archives():
status_code, headers, response = fetch_page_headers(start_page, default_headers)
if status_code == 200:
archive_pages = re.findall("(http:\/\/www\.devilskitchen\.me\.uk\/([0-9]{4})_([0-9]{2})_[0-9]{2}_archive\.html)", response)
for page in archive_pages:
if os.path.exists("%s/%s-%d" % (options['output_dir'], page[1], int(page[2]))):
print "%s-%s already exists, skipping..." % (page[1], page[2])
else:
print "Scraping %s..." % page[0]
fetch_articles(page[0])
time.sleep(5)
else:
print "ERROR: Failed to retrieve archive index! Exiting..."
exit(1)
def fetch_articles(url):
try:
status_code, headers, response = fetch_page_headers(url, default_headers)
except urllib2.HTTPError, e:
print "ERROR: 403 encountered on %s" % url
return False
if status_code == 200:
soup = BeautifulSoup(response)
posts = soup.find_all("div", class_="post")
for post in posts:
try:
post_title = post.h5.string
except AttributeError, e:
print "WARNING: Article with missing title"
post_title = ""
author_details = post.find_all("p", class_="author-details")[0]
author_name = author_details.find_all("span", class_="author-name")[0].string
post_date = author_details.find_all("a")[0].string
post_body = post.find_all("div", class_="post-body")[0].div.prettify()
actual_date = datetime.datetime.strptime(post_date, "%m/%d/%Y %I:%M:%S %p")
try:
os.mkdir("%s/%d-%d" % (options['output_dir'], actual_date.year, actual_date.month))
except:
pass
try:
json_file = open("%s/%d-%d/%d-%d-%d-%d-%d-%d.json" % (options['output_dir'], actual_date.year, actual_date.month, actual_date.year,
actual_date.month, actual_date.day, actual_date.hour, actual_date.minute, actual_date.second), 'w')
json.dump({
'title': post_title,
'date': actual_date.isoformat(),
'author': author_name,
'body': post_body
}, json_file)
json_file.close()
except:
raise
print "Archived '%s', posted at %s by %s" % (post_title, actual_date.isoformat(), author_name)
else:
print "ERROR: Failed to retrieve %s! Status code was %d" % (url, status_code)
#soup = BeautifulSoup(html_doc)
fetch_archives()

@ -0,0 +1,132 @@
#!/usr/bin/env python
import urllib2, time, urllib
from lxml import etree
def avg(inp):
return (reduce(lambda x, y: x + y, inp) / len(inp))
referer = "http://c.speedtest.net/flash/speedtest.swf?v=316125"
num = 1353968072002
config_url = "http://speedtest.net/speedtest-config.php?x=%d" % num
server_url = "http://speedtest.net/speedtest-servers.php?x=%d" % num
download_path = "/random%dx%d.jpg?x=%d&y=%d"
upload_path = "/upload.php?x=%d" % num
latency_path = "/latency.txt?x=%d" % num
sizes = [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000]
servers = []
server_count = 0
# First, get our own details.
result = urllib2.urlopen(config_url)
for event, element in etree.iterparse(result):
if element.tag == "client":
my_ip = element.get("ip")
my_isp = element.get("isp")
my_latitude = float(element.get("lat"))
my_longitude = float(element.get("lon"))
dl_average = float(element.get("ispdlavg"))
ul_average = float(element.get("ispulavg"))
print "You are %s (%s), with latitude %f and longitude %f. Your ISPs average download speed is %.3f MB/sec, and their average upload speed is %.3f MB/sec." % (my_ip, my_isp, my_latitude, my_longitude, dl_average / 8 / 1024 / 1024, ul_average / 8 / 1024 / 1024)
print "Retrieving server list...",
# Retrieve and parse list of servers.
result = urllib2.urlopen(server_url)
for event, element in etree.iterparse(result):
if element.tag == "server":
hostname = element.get("url").replace("/upload.php", "")
latitude = float(element.get("lat"))
longitude = float(element.get("lon"))
location = element.get("name")
country = element.get("country")
sponsor = element.get("sponsor")
distance = abs(my_latitude - latitude) + abs(my_longitude - longitude)
servers.append((distance, hostname, latitude, longitude, location, country, sponsor))
server_count += 1
print "\rRetrieving server list... %d servers found so far" % server_count,
# Sort the server list by distance.
servers = sorted(servers, key=lambda server: server[0])
print "\nFound 5 closest servers. Determining optimal latency..."
fastest_server = ()
fastest_latency = 0
for server in servers[:5]:
# Take 3 samples of each server.
latencies = []
for i in xrange(0, 3):
request = urllib2.Request(server[1] + latency_path)
start_time = time.time()
urllib2.urlopen(request)
end_time = time.time()
latencies.append((end_time - start_time) * 1000)
latency = avg(latencies)
if fastest_latency == 0 or latency < fastest_latency:
fastest_latency = latency
fastest_server = server
print "\rFastest server so far is '%s' with %dms ping... (%s)" % (fastest_server[6], fastest_latency, latencies),
print "\nTarget server is '%s'. Testing download speed..." % fastest_server[6]
latency = fastest_latency
size = 0
while size < 8:
# Take 3 samples
speeds = []
times = []
for i in xrange(0, 3):
target_file = download_path % (sizes[size], sizes[size], num, i + 1)
request = urllib2.urlopen(fastest_server[1] + target_file)
filesize = int(request.info()['Content-Length'])
block_size = 4096
r = 0
start_time = time.time()
while r < filesize:
request.read(block_size)
r += block_size
speed = r / (time.time() - start_time)
print "\rSize %d, attempt %d... %.3f MB/sec" % (sizes[size], i + 1, speed / 1024 / 1024),
end_time = time.time()
speeds.append(speed)
times.append(end_time - start_time)
print ""
request.close()
if avg(times) < 4:
size += 1
else:
break
# Take result from last speedtest as authorative.
if size >= 8:
size = 7
download_speed = avg(speeds)
#print "Average speed, sample size %d, is %.3f MB/sec" % (sizes[size], download_speed / 1024 / 1024)
print "Latency: %dms\tDownload speed: %.3f MB/sec" % (latency, download_speed / 1024 / 1024)
print "NOTE: Due to function call overhead, the latency is, at best, an estimation."
Loading…
Cancel
Save