Skip to content

Instantly share code, notes, and snippets.

View Ephigenia's full-sized avatar
🕊️
I may be slow to respond.

Marcel Eichner Ephigenia

🕊️
I may be slow to respond.
View GitHub Profile
@Ephigenia
Ephigenia / gist:1295160
Created October 18, 2011 10:57
nginx-fb-hotlinking-hb
# apply this rule on any location that’s an image using Regexp
location ~* \.(png|gif|jpg|jpeg|swf|ico)(\?[0-9]+)?$ {
# block empty blocked or whiteliste referers
valid_referers none blocked horrorblog.org www.horrorblog.org;
if ($invalid_referer) {
return 403;
}
}
#!/usr/bin/env php
<?php
function testForExploit($url = NULL) {
$oCurl = curl_init($url);
curl_setopt_array($oCurl, array (CURLOPT_HTTPHEADER => array('Range: bytes=0-4')
,CURLOPT_RETURNTRANSFER => 1
,CURLOPT_TIMEOUT => 15
,CURLOPT_CONNECTTIMEOUT => 0
,CURLOPT_SSL_VERIFYHOST => 0
@Ephigenia
Ephigenia / .htaccess
Created July 4, 2011 17:39
nginx-blogpost-2011-07-04-03
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ thumbnailer.php?image=$1
@Ephigenia
Ephigenia / thumbnailer.php
Created July 4, 2011 17:37
nginx-blogpost-2011-07-04-02
<?php
$imageRoot = 'img/';
$requestedFilename = $_GET['image'];
$formatRegexp = '@^'.$imageRoot.
'(?P<hash>[a-z0-9]{8})\/'.
'(?P<width>\d+|auto)x(?P<height>\d+|auto)\/'.
'(?P<filename>[a-z0-9_.]+\.(jpg|gif|png))@i';
if (!preg_match($formatRegexp, $requestedFilename, $found)) {
die('IMAGE NOT FOUND');
@Ephigenia
Ephigenia / server.conf
Created July 4, 2011 17:37
nginx-blogpost-2011-07-04-01
# somewhere in the server section of any nginx config
location ~* \.(png|gif|jpg|jpeg)(\?[0-9]+)?$ {
# try existing files, or put request to index.php
try_files $uri /thumbnailer.php?image=$uri;
# old method when try_files did not exist
# if (!-f $request_filename) {
# rewrite ^/(.*)$ /thumbnailer.php?image=$1 last;
# break;
# }
}
@Ephigenia
Ephigenia / gist:966251
Created May 11, 2011 10:28
Youtube Video Event Tracking
// assume you embed your youtube videos in a container with the class ".youtube-video"
// like this
// <div class="youtube-video" id="youtube-VIDEOID">
// <img src="thumbnailurl" />
// </div>
// and don’t forget the youtube jsapi js embed in your page and the google "pageTracker"
// must also be available
//
window.onYouTubePlayerAPIReady = function() {
$('.youtube-video').each(function(index, elm) {
@Ephigenia
Ephigenia / gist:946725
Created April 28, 2011 16:45
apach requests per seconds shoutbox notify
#!/bin/sh
CTL_CMD="apachectl";
REQUESTS_MAX="2";
SHOUT_GROUP="wesc";
SLEEP=1
echo "Press CTRL+C to stop";
while [ "$end" != "end" ]
do
@Ephigenia
Ephigenia / gist:894785
Created March 30, 2011 16:49
google_mail_filter_example_2_2
{
{to: from: cc:}
horrorblog.org
}
@Ephigenia
Ephigenia / gist:894780
Created March 30, 2011 16:47
google_mail_filter_example_3
{
from:
@getsatisfaction.com
@facebookmail
@postmaster.twitter.com
[email protected]
[email protected]
@foursquare
[email protected]
@imdb
@Ephigenia
Ephigenia / gist:894773
Created March 30, 2011 16:45
google_mail_filter_example_2
{
to: horrorblog.org
from: horrorblog.org
cc: horrorblog.org
}