Skip to content

Instantly share code, notes, and snippets.

@gdugas
gdugas / securejoin.py
Last active December 9, 2015 23:38
return a absolute path jailed in a rootpath
import os
"""
return a absolute path jailed in a rootpath
example:
securejoin('/home/john/', 'path1/../../path2')
> /home/john/path2
"""
def securejoin(rootpath, path):
path = os.path.join(path).split('/')
@gdugas
gdugas / php53-ubuntu1204-installer.sh
Last active December 13, 2015 23:59
php-5.3 installation script for ubuntu 12.04
#! /bin/sh
#
# php-5.3 installation script (ubuntu 12.04)
#
install_dir=/opt/php-5.3
sudo apt-get install -y \
build-essential \
libxml2-dev \
@gdugas
gdugas / jelix_completion
Created March 22, 2013 19:44
basic jelix bash_completion
_jelix_completion()
{
local cur prev opts actions
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Standalone options
opts=""
@gdugas
gdugas / webminapi.py
Last active November 4, 2017 20:28
webmin / virtualmin remote api module webmin api: http://doxfer.webmin.com/Webmin/TheWebminAPI virtualmin api: http://www.virtualmin.com/documentation/developer/cli Examples: webmin = WebminApi('localhost', 'mylogin', 'mypassword') print webmin('user', 'list_users') virtualmin = VirtualminApi('localhost', 'mylogin', 'mypassword') print virtualmi…
import base64, httplib, json, xmlrpclib
class ApiBase(object):
def __init__(self, host, login, password, port=10000, https=True):
self.host = host
self.login = login
self.password = password
self.port = port
self.https = https
@gdugas
gdugas / include_once.py
Created May 3, 2013 07:18
Django template tag: include_once
from django import template
register = template.Library()
def render_include_once(self, context):
ctname = '_include_once_node_registry'
if not ctname in context:
context[ctname] = {}
@gdugas
gdugas / gethostip.py
Created June 4, 2013 09:42
Return ip in hex format: 192.168.1.1 => C0A80101
def gethostip(ip):
return "".join([("%0.2x" % int(i)).upper() for i in ip.split('.')])
from django.core.management import BaseCommand, LaxOptionParser, CommandError, ManagementUtility
from django.core.management.base import handle_default_options
from optparse import make_option, OptionParser
import sys
class SubManagementUtil(ManagementUtility):
def __init__(self, argv=None, commands={}):
self.commands = commands
super(SubManagementUtil, self).__init__(argv)
@gdugas
gdugas / tail.php
Created June 27, 2013 09:59
basic tail method
function tail($fh, $max_length=10) {
$tailed = array();
fseek($fh, -2, SEEK_END);
$stop = ftell($fh) + 2;
while (ftell($fh) >= 0 && count($tailed) < $max_length) {
@gdugas
gdugas / xboxdrv.sh
Created September 4, 2013 16:59
linux xboxdrv service
#! /bin/sh -e
DAEMON="/usr/bin/xboxdrv"
DEAMON_OPT="--quiet --silent"
DAEMONUSER="root"
DEAMON_NAME="xboxdrv"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
test -x $DAEMON || exit 0
@gdugas
gdugas / postfix_log_parser.py
Created September 6, 2013 15:04
Postfix log parser: parse postfix mail.log, store only send and reception results in 'messages' attributes.
class Parser(object):
PATTERN = r"^" \
+ r"(?P<month>\w{3})\s+" \
+ r'(?P<day>\d{1,2})\s+' \
+ r'(?P<time>\d{2}:\d{2}:\d{2})\s+' \
+ r'(?P<hostname>[^\s]+)\s+' \
+ r'(?P<exec>\w+/\w+)' \
+ r'\[(?P<port>\d+)\]:\s+' \
+ r'(?P<message_id>\w+):\s+' \