2012年11月8日星期四

Translating a Socks5 Proxy into an HTTP one using delegate


$ delegated -P3000 SERVER=http SOCKS=192.168.1.1:7070

this command line translates a socks proxy on 192.168.1.1:7070 to an HTTP one http://0.0.0.0:3000/

2012年3月30日星期五

对 HTML 网页做 GPG 签名

https://github.com/multiple1902/scripts/blob/master/gpghtml.sh

#!/bin/bash
#
# Written by multiple1902 <multiple1902@gmail.com>
# Released under MIT License
#
# gpghtml.sh:
# Sign a HTML page in cleartext using gnupg
#
# Usage:
# gpghtml.sh happyhour.html
#
# Requirements:
# gnupg
#
if [ -z "$1" ]; then
echo "gpghtml: please specify input file";
    exit 126
fi
TMPFILE=$(mktemp)
DEST=$(dirname "$1")/$(basename "$1" .html).signed.html
cat > "$TMPFILE" << EOF
-->
EOF
cat "$1" >> "$TMPFILE"
cat >> "$TMPFILE" << EOF
<!--
EOF
if gpg --clearsign "$TMPFILE"; then
cat > "$DEST" << EOF
<!--
EOF
    cat >> "$DEST" < "$TMPFILE.asc"
    cat >> "$DEST" << EOF
-->
EOF
    rm "$TMPFILE" "$TMPFILE.asc"
    echo "gpghtml: succ"
else
rm "$TMPFILE"
    echo "gpghtml: gpg failed to sign the file"
    return 125
fi

2012年2月19日星期日

VirtualBox USB Issue Under openSUSE Tumbleweed

Check rules under /etc/udev/rules.d/, uncomment the last 2 lines:

[multiple1902 rules.d]$ pwd
/etc/udev/rules.d

[multiple1902 rules.d]$ cat 60-vboxdrv.rules
KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="root", MODE="0600"
#these two lines give access permission to vboxusers to properly work with usb nodes, this could be security risk (bnc#664520) !!
#
SUBSYSTEM=="usb_device",ATTR{devnum}=="?*",ATTR{busnum}=="?*",SYMLINK+="vboxusb/$attr{busnum}/$attr{devnum}",RUN+="/usr/bin/setfacl -m g:vboxusers:6 /dev/vboxusb/$attr{busnum}/$attr{devnum}"
SUBSYSTEM=="usb",ENV{DEVTYPE}=="usb_device",ATTR{devnum}=="?*",ATTR{busnum}=="?*",SYMLINK+="vboxusb/$attr{busnum}/$attr{devnum}",RUN+="/usr/bin/setfacl -m g:vboxusers:6 /dev/vboxusb/$attr{busnum}/$attr{devnum}"

2012年2月18日星期六

Changing Arch Linux's and openSUSE's boot text

Arch Linux:

Edit /etc/rc.sysinit .

openSUSE:

Compile systemd package, using its source in the source repo. Edit status_welcome() in src/util.c and main() in src/main.c .

2012年1月25日星期三

适用于openSUSE的update-resolv-conf

I didn't find the `resolvconf' package on openSUSE. In fact, openSUSE uses `netconfig'. [1] provides a snippet claimed to be working on openSUSE, but it failed to replace the DNS nameservers on my computer. I edited the `update-resolv-conf' file to suit my needs, and I omitted the `DOMAIN' part.

The following script is available on https://gist.github.com/1675504

#!/bin/bash
#
# Parses DHCP options from openvpn to update resolv.conf
# To use set as 'up' and 'down' script in your openvpn *.conf:
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
#
# Used snippets of resolvconf script by Thomas Hood <jdthood@yahoo.co.uk>
# and Chris Hanson
# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
#
# Adjusted for openSUSE and its 'netconfig' component
# using dirty tricks by multiple1902.
# Omitted the 'DOMAIN' part.
#
# 05/2006 chlauber@bnc.ch
# 01/2012 multiple1902@gmail.com
#
# Example envs set from openvpn:
# foreign_option_1='dhcp-option DNS 193.43.27.132'
# foreign_option_2='dhcp-option DNS 193.43.27.133'
# foreign_option_3='dhcp-option DOMAIN be.bnc.ch'

NETCONFIG="/sbin/netconfig"
CONFIGFILE="/var/run/netconfig/NetworkManager.netconfig"

case $script_type in

up)
    for optionname in ${!foreign_option_*} ; do
        option="${!optionname}"
        echo $option
        part1=$(echo "$option" | cut -d " " -f 1)
        if [ "$part1" == "dhcp-option" ] ; then
            part2=$(echo "$option" | cut -d " " -f 2)
            part3=$(echo "$option" | cut -d " " -f 3)
            if [ "$part2" == "DNS" ] ; then
                IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3"
            fi
        fi
    done
    cp $CONFIGFILE{,.bak}
    grep -v DNSSERVERS $CONFIGFILE.bak > $CONFIGFILE
    echo "DNSSERVERS='$IF_DNS_NAMESERVERS'" >> $CONFIGFILE
    $NETCONFIG update -f
    ;;
down)
    cp $CONFIGFILE{.bak,}
    $NETCONFIG update -f
    ;;
esac









[1] http://www.phocean.net/2006/12/07/openvpn-and-dns-on-a-linux-client.html

2012年1月2日星期一

采用rsync的服务器文件的手工远程备份脚本

#!/bin/bash                                                                                                                            

DATE=`date +%Y-%m-%d_%H`
DEST=./$DATE
RSYNC="rsync -avr root@server:"

mkdir -p $DEST/db $DEST/storage $DEST/cache $DEST/setting $DEST/synclist

$RSYNC/root/rhodecode.db $DEST/db
$RSYNC/sonic/rhodecode --exclude="/rhodecode/*-mirror/*" $DEST/storage
$RSYNC/root/data $DEST/cache
$RSYNC/root/production.ini $DEST/setting
$RSYNC/root/syncrepo.sh $DEST/synclist