Warning: Undefined array key 1 in /var/www/dokuwiki/lib/plugins/note/syntax.php on line 103
Table of Contents
Scripts
PHP
bookmark-checker.php
This script checks your exported bookmarks in html format for broken links and report them.
Try it live Bookmark Checker
- bookmark-checker.php
<html> <head> <title>Online Bookmark Checker</title> <style type="text/css"> body { color: black; background-color: #EEEEEE; font-size: 14px; font-family: Verdana,sans-serif; margin: 0; padding: 1em 0; text-align: center; } h1 { font-size: 12px; } h1.error { color: red; } h1.ok { color: green; } tr { font-size: 12px; border: 1px solid #CCCCCC; } tr.row0 { background-color:#DDD; } tr.row1 { background-color:#FFF } tr.row0:hover ,tr.row1:hover { background-color:#AABBCC; } </style> </head> <body> This script checks your bookmarks if the links are broken or not.<br> Please upload your exported bookmarks as .html file <p> <? if (isset($_REQUEST[submit])) { if ($_FILES["bookmarks"]["type"] != "text/html") { echo "<h1 class=error>Only HTML plaintext bookmarks allowed<br>You tried to upload a file with meta " . $_FILES["bookmarks"]["type"] . "</h1>"; exit; } $target_path = "/tmp/" . basename( $_FILES['bookmarks']['name']); if(move_uploaded_file($_FILES['bookmarks']['tmp_name'], $target_path)) {?> <h1 class=ok>Verified <i>"<? echo basename( $_FILES['bookmarks']['name']) ?>"</i></h1> <table width=100%> <?$handler = fopen($target_path,"r"); $file = fread($handler,filesize($target_path)); preg_match_all('/(<A HREF=\")(.*)(\" ADD_DATE)/Ui',$file,$urls); $urls = $urls[2]; $rowclass = 0; error_reporting(0); # Turn off PHP error set_time_limit(3); # Set timeout limit for get_headers 3 secs ob_implicit_flush(true); # Turn implicit flush on foreach ($urls as $url) {?> <tr class=row<?echo $rowclass ?>><td> <?$rowclass = 1 - $rowclass;?> <a href="<?print($url)?>"><?print($url)?></a> </td><td> <?$urlcheck = get_headers($url); if (preg_match("/200 OK/",$urlcheck[0])) { echo "<font color=green>OK</font>"; } else { echo "<font color=red>" . $urlcheck[0] . "</font>"; }?> </td></tr> <?}?> </table><p>Finished <?} else { echo "There was an error uploading the file!"; } } else {?> <form enctype="multipart/form-data" method="post" action="<? $PHP_SELF;?>"> <input type="file" name="bookmarks" accept="text/html"> <input type="submit" name=submit value="Check"> </form> <?}?> </body> </html>
ldap-connector.php
This script checks an LDAP server over the internet.
Try it live: LDAP Connector
- ldap-connector.php
<html> <head> <!-- for iPhones --> <meta name="viewport" content="width=320" /> <style type="text/css"> body { color: black; background-color: #EEEEEE; font-size: 14px; font-family: Verdana,sans-serif; margin: 0; padding: 1em 0; text-align: center; } h1 { font-size: 12px; } h1.error { color: red; } h1.ok { color: green; } tr { font-size: 12px; border: 1px solid #CCCCCC; } tr.row0 { background-color:#DDD; } tr.row1 { background-color:#FFF } </style> <title>LDAP Connection Checker</title> </head> <body> <b>This script checks your LDAP server from the Internet.</b><br> <font size=1>Caveats: If you check TLS/SSL, the port will be forced to 636</font><hr> <p> <? if (isset($_REQUEST[submit])) { if ($_REQUEST[server] == "" || $_REQUEST[port] == "") { echo "<h1 class=error>Please insert a server and its port</h1>"; } else if ($_REQUEST[protocol] == "") { echo "<h1 class=error>Please select a protocol</h1>"; } else if ($_REQUEST[bind] == "") { echo "<h1 class=error>Please select an authentication</h1>"; } else if ($_REQUEST[bind] == "auth" && $_REQUEST[binddn] == "") { echo "<h1 class=error>Please insert a Bind-DN</h1>"; } else if ($_REQUEST[bind] == "auth" && $_REQUEST[bindpw] == "") { echo "<h1 class=error>Please insert a Bind-PW</h1>"; } else if ($_REQUEST[basedn] == "") { echo "<h1 class=error>Please insert a base DN </h1>"; } else { echo "Checking connection to " . $_REQUEST[server] . ":"; error_reporting(0); if ($_REQUEST[tls]) { # with ldaps:// the port's obsolete 'cos it's forced to 636 echo "636: "; $_REQUEST[port] = 636; $ldapconn = ldap_connect("ldaps://$_REQUEST[server]"); } else { echo $_REQUEST[port] . ": "; $ldapconn = ldap_connect("$_REQUEST[server]", $_REQUEST[port]); } ldap_set_option($ldapconn,LDAP_OPT_PROTOCOL_VERSION, $_REQUEST[protocol]); ldap_set_option($ldapconn,LDAP_OPT_TIMELIMIT, 20); if (!$ldapconn) { echo "<font color=red>Connection failed: "; echo ldap_err2str(ldap_errno($ldapconn)); echo "</font>"; } else { echo "<font color=green>Connection successful</font><br>"; echo "<p>Binding "; if ($_REQUEST[bind] == "anon") { echo "anonymously: "; $ldapbind = ldap_bind($ldapconn); } else { echo "with DN " . $_REQUEST[binddn] . ": "; $ldapbind = ldap_bind($ldapconn, $_REQUEST[binddn], $_REQUEST[bindpw]); } if ($ldapbind) { echo "<font color=green>Binding successful</font><p>"; echo "Showing first entry in " . $_REQUEST[basedn] . ": "; $ldapsearch = ldap_search($ldapconn, $_REQUEST[basedn], "objectclass=*"); $getentries = ldap_get_entries($ldapconn, $ldapsearch); echo "<font color=green>" . $getentries[1]["dn"] . "</font>"; } else { echo "<font color=red>Bind failed -> "; echo ldap_err2str(ldap_errno($ldapconn)); echo "</font>"; } ldap_unbind($ldapconn); } ldap_close($ldapconn); } } ?> <form method=post action="<? $PHP_SELF;?>"> <table align=center> <tr class=row0><td>Server:</td><td><input type=text name=server value="<? echo $_REQUEST[server]?>"></td></tr> <tr class=row1><td>Port:</td><td><input type=text name=port value=<? echo $_REQUEST[port]?>></td></tr> <tr class=row0><td>Protocol:</td><td><input type=radio <? if ($_REQUEST[protocol] == "2") { echo "checked"; }?> name=protocol value=2>v2<br> <input type=radio <? if ($_REQUEST[protocol] == "3") { echo "checked"; }?> name=protocol value=3>v3</td></tr> <tr class=row1><td>TLS/SSL:</td><td><input type=checkbox <? if ($_REQUEST[tls]) { echo "checked"; }?> name=tls></td></tr> <tr class=row0><td>Bind:</td><td><input type=radio <? if ($_REQUEST[bind] == "anon") { echo "checked"; }?> name=bind value=anon>Anonymous<br> <input type=radio <? if ($_REQUEST[bind] == "auth") { echo "checked"; }?> name=bind value=auth>Authenticated</td></tr> <tr class=row1><td>Bind-DN:</td><td><input type=text name=binddn value="<? echo $_REQUEST[binddn]?>"></td></tr> <tr class=row0><td>Bind-PW:</td><td><input type=password name=bindpw value="<? echo $_REQUEST[bindpw]?>"></td></tr> <tr class=row1><td>Base-DN:</td><td><input type=text name=basedn value="<? echo $_REQUEST[basedn]?>"></td></tr> </table> <input type="submit" name=submit value="Check"> </form> </body> </html>
BaSH
update_dokuwiki.sh
This script updates dokuwiki from tgz file on your document root. The updating file must be named dokuwiki*.tgz
- update_dokuwiki.sh
#!/bin/bash set -e # Set your install dir INSTALLDIR=/var/www [[ `whoami` != "root" ]] && { echo "Must be root"; exit 2; } [[ `pwd` != "$INSTALLDIR" ]] && { echo "You must be in $INSTALLDIR instead in `pwd`"; exit 2; } DOKUFILE=`ls $INSTALLDIR/dokuwiki*.tgz |awk -F/ '{print $NF}'` [[ -z $DOKUFILE ]] && { echo "No TAR file found matching dokuwiki*.tgz"; exit 2; } cd $INSTALLDIR echo "Removing old backup dokuwiki.old" rm -rf dokuwiki.old echo "Backup current Dokuwiki to dokuwiki.old" mv dokuwiki dokuwiki.old echo "Extracting new TAR" tar -xzf $DOKUFILE echo "Rename extracted directory to dokuwiki if not yet" mv `find . -type d -name "dokuwiki-*"` dokuwiki echo "Remove .dist files in the new installation" find dokuwiki -name *.dist -exec rm -rf {} \; echo "Get local configs and acl.auth.php from previous installation" find dokuwiki.old/conf -name "*local*" -exec cp -p {} dokuwiki/conf \; cp -p dokuwiki.old/conf/acl.auth.php dokuwiki/conf echo "Get custom smileys from previous installation" for i in `awk '{print $NF}' dokuwiki.old/conf/smileys.local.conf`; do printf " $i" cp dokuwiki.old/lib/images/smileys/$i dokuwiki/lib/images/smileys done echo "" echo "Rsync data from previous installation" rsync -a --delete dokuwiki.old/data dokuwiki echo "Clear update messages" echo "" > dokuwiki/data/cache/messages.txt echo "Copy active template from previous installation" TPL=`grep template dokuwiki.old/conf/local.php |cut -f4 -d\'` cp -pr dokuwiki.old/lib/tpl/$TPL dokuwiki/lib/tpl echo "Copy custom installed plugins" for i in `ls dokuwiki.old/lib/plugins/`; do if [[ ! `ls dokuwiki/lib/plugins/$i 2>/dev/null` ]]; then printf " $i" cp -pr dokuwiki.old/lib/plugins/$i dokuwiki/lib/plugins fi done echo "" echo "Fixing permissions" chown -R www-data dokuwiki/data dokuwiki/lib/plugins chown www-data dokuwiki/conf dokuwiki/conf/local.php dokuwiki/conf/acl.auth.php /etc/init.d/apache2 reload
ipcheck.sh
This script is executed every 30 minutes by cron from root. It checks if the public IP has changed and sends an email with the notification to dislist the new IP from Spamhaus Blacklist.
- ipcheck.sh
#!/bin/bash # # Check if IP has changed and send mail # # Mon Feb 2 13:57:44 CET 2009 hanr # Thu Jul 2 08:33:55 CET 2009 hanr - Send email only if ip is listed on spamhaus # Mon Jan 4 11:17:07 CET 2010 hanr - Some fixes # # Variables EMAIL="hanr" # Separate with semicolon FROM="IP Check <root@runlevel.ch>" CACHEDADDRESS="/var/tmp/ipcheck.address" IPADDRESS=`w3m checkip.dyndns.org |awk '{print $4}'` SPAMHAUSTEXT= # Script if [ "$IPADDRESS" = "" ]; then logger "$0 could not get dyndns.org" exit 1 elif [ "$IPADDRESS" != "`cat $CACHEDADDRESS`" ]; then SPAMHAUSIP=`w3m http://www.spamhaus.org/query/bl?ip=$IPADDRESS |grep records |awk '{print $3}'` if [ "$SPAMHAUSIP" ]; then printf "Dislist $SPAMHAUSIP on spamhaus \nhttp://www.spamhaus.org/pbl/removal/form" | mailx -a from:"$ FROM" -s "Public IP has changed from `cat $CACHEDADDRESS` to $IPADDRESS" $EMAIL fi logger "Public IP has changed from `cat $CACHEDADDRESS` to $IPADDRESS" echo $IPADDRESS > $CACHEDADDRESS exit 1 fi exit 0
nsupdate.sh
This scripts adds or removes A and PTR records over nsupdate with rndc key
- nsupdate.sh
#!/bin/bash # # This scripts adds or removes A and PTR records # over nsupdate with rndc key # # Fri Apr 8 12:41:47 CEST 2011 - hanr # # Variables TTL=3600 DNSSERVER="127.0.0.1" KEYFILE=/etc/bind/rndc.key DNSFILE=`mktemp` HOSTNAME="$2" IPADDR="$3" # Functions f_usage(){ echo "Usage: $0 {add | del} fqdn ip.addr.ess" exit 1 } f_extract_key(){ KEYNAME=`grep ^key $KEYFILE |cut -f2 -d\"` SECRET=`grep secret $KEYFILE |cut -f2 -d\"` } f_check_host(){ host $1 $DNSSERVER >/dev/null if [ $? -eq 0 ]; then return 0 else return 1 fi } f_add_dns(){ f_check_host $HOSTNAME && { echo "A record already exists"; exit 1; } f_check_host $IPADDR && { echo "PTR record already exists"; exit 1; } cat << EOD >$DNSFILE server $DNSSERVER update add $HOSTNAME $TTL A $IPADDR send EOD f_do_nsupdate && echo "Added A record for $HOSTNAME" cat << EOD >$DNSFILE server $DNSSERVER update add $REVIPADDR.in-addr.arpa $TTL PTR ${HOSTNAME}. send EOD f_do_nsupdate && echo "Added reverse PTR entry for $IPADDR" } f_del_dns(){ f_check_host $HOSTNAME || { echo "A record does not exist"; exit 1; } f_check_host $IPADDR || { echo "PTR record does not exist"; exit 1; } cat << EOD >$DNSFILE server $DNSSERVER update delete $HOSTNAME A send EOD f_do_nsupdate && echo "Deleted A record for $HOSTNAME" cat << EOD >$DNSFILE server $DNSSERVER update delete $REVIPADDR.in-addr.arpa IN PTR ${HOSTNAME}. send EOD f_do_nsupdate && echo "Deleted reverse PTR record for $IPADDR" } f_do_nsupdate(){ f_extract_key nsupdate -y $KEYNAME:$SECRET $DNSFILE } # Main [[ `whoami` == "root" ]] || { echo "Only root can execute this script"; exit 1; } [[ $# -eq 3 ]] || f_usage # Revert IP address for PTR record REVIPADDR=`echo $IPADDR |awk -F. '{print $4,$3,$2,$1}' |tr ' ' '.'` case $1 in add) f_add_dns ;; del) f_del_dns ;; *) f_usage ;; esac rm -f $DNSFILE
dnscheck.sh
Obsoleted by ipcheck.sh
- dnscheck.sh
#!/bin/bash # # Compare DynDNS Hostname with A Record Entry asked on /etc/resolv.conf servers # # Thu Feb 7 01:41:14 CET 2008 # Wed May 21 10:59:33 CEST 2008 / Added abort (exit 1) if no internet connection # Mon Aug 11 16:49:21 CEST 2008 / Added flag to reduce mail notifications # # Variables EMAIL="hanr" # separate with semicolons FROM="ipcheck" SYSLOG=/var/log/messages FLAG=/tmp/dnscheck.flag DYNDNS=`ping -c 1 runlevel.dyndns.org |head -1 |awk '{print $3}' |tr "(|)" " "` FIXDNS=`ping -c 1 runlevel.ch |head -1 |awk '{print $3}' |tr "(|)" " "` # Script if [ "$DYNDNS" = "" ]; then echo `date "+%b %e %H:%M:%S"` `hostname -f` "Warn: dnscheck.sh could not resolve hostnames" >>$SYSLOG exit 1 fi if [ $DYNDNS != $FIXDNS ]; then if [ -t $FLAG ]; then echo `date "+%b %e %H:%M:%S"` `hostname -f` "Warn: Public IP has changed from $FIXDNS to $DYNDNS" >>$SYSLOG exit 1 else touch $FLAG fi echo "Change DNS entries at www.mydomain.com and dislist $DYNDNS on spamhaus" | mailx -a from:$FROM -s "Public IP has changed from $FIXDNS to $DYNDNS" $EMAIL echo `date "+%b %e %H:%M:%S"` `hostname -f` "Warn: Public IP has changed from $FIXDNS to $DYNDNS" >>$SYSLOG exit 1 else echo `date "+%b %e %H:%M:%S"` `hostname -f` "Public IP is still $FIXDNS" >>$SYSLOG if [ -f $FLAG ]; then rm -f $FLAG fi exit 0 fi # EOF
gather_songs.sh
This script collects all mp3 files from a specified album in the MyBook repository and compresses it.
- gather_songs.sh
#!/bin/bash # # Collect MP3 from an album on mybook and get a zip file # # Die Feb 24 15:12:35 CET 2009 hanr # Do 2. Jul 08:45:58 CEST 2009 placed $ALBUM in doublequotes to search more than 1 word in album name # ### Variables MYORIGIN=`pwd` MYBOOK=/mybook/Music ALBUM=$1 # Script function usage { echo "Usage: $0 \"album name\" tar|zip" exit 1 } if [ "$ALBUM" = "" ]; then usage fi cd $MYBOOK case "$2" in tar) find */*"$ALBUM"* -name "*.mp3" |sed 's/ /\\ /g' |xargs tar -cvzf "$ALBUM".tar.gz mv "$ALBUM".tar.gz $MYORIGIN ;; zip) find */*"$ALBUM"* -name "*.mp3" -exec zip "$ALBUM".zip {} \;|sed 's/ /\\ /g' mv "$ALBUM".zip $MYORIGIN ;; *) usage ;; esac cd $MYORIGIN exit 0 ### EOF
diskusage.sh
- diskusage.sh
#!/bin/bash # # Script zum Anzeigen der Groesse von gehosteten Verzeichnissen. # Ein html Dokument wird ebenso erstellt # # Son Mai 5 15:06:30 GMT 2002 / rha # Tue Dec 11 21:57:35 CET 2007 / Script mit for-Schleife optimiert und Table # Do 2. Jul 08:55:52 CEST 2009 / Optimized # # Variables host="/var/httpd" output=/var/httpd/www.runlevel.ch/www/hosts.php # Script echo "<table>" > $output for i in `ls -d $host/*`; do echo "<tr align=right><td> `echo $i | cut -f4 -d'/'`" >> $output echo ":</td>" >> $output result=`du -shP $i | cut -f 1` # Human readable resultdet=`du -sP $i | cut -f 1` # in KB echo "<td>$result ($resultdet KB)</td></tr>" >> $output done echo "</table>" >> $output echo "<br><br><font size=1>(crontab wrote diskusage.sh at "`date '+%e. %B %Y'`\) >> $output
Backup
My backup framework
backup.lib.sh
- backup.lib.sh
# This is the sourced library for the backup scripts # # Fri Dec 3 10:42:04 CET 2010 / hanr # Sat Jul 2 14:13:58 CET 2011 / added keychain support for ssh-agents # ### Variables RDIFFBIN="/usr/bin/rdiff-backup" RDIFFPARAMS="--print-statistics --create-full-path" RETENTION="3M" # keep last 3 months TMPFILE="/tmp/backup_$HOSTNAME.sh.tmp" # Complete path with filename for mail content EMAIL="hanr" # Address where content or alert shoult be sent, semicolon sep. FROM="backup" DRYRUN= TXT01="####################################################################################" ### Functions function f_keychain() { if [ -f ~/.keychain/$HOSTNAME-sh ]; then . ~/.keychain/$HOSTNAME-sh else f_error "No keychain found on this system" fi } function f_mysqld() { case $1 in start) /etc/init.d/mysql $1 >>$TMPFILE pidno=`ps ax |grep mysqld_safe |grep -v grep` if [ -z "$pidno" ]; then printf "\n!!!!!!! MYSQL SERVER NOT RUNNING OR FAILED TO START !!!!!!!" >>$TMPFILE else echo $pidno >>$TMPFILE fi ;; stop) /etc/init.d/mysql $1 >>$TMPFILE ;; esac } function f_sendmail() { if [ $DRYRUN ]; then cat $TMPFILE else cat $TMPFILE |mailx -a from:$FROM -s "$HOSTNAME Backup" $EMAIL fi } function f_error() { printf "!!! Skipped !! $1 (`date +"%H:%M:%S"`)\n$TXT01\n" >$TMPFILE f_sendmail exit 1 }
backup_server.sh
- backup_server.sh
#!/bin/bash # # BACKUP SCRIPT # # Usage: backup_server.sh [-n] # # Fri Jul 7 16:55:21 CEST 2006 / Added MySQL Stop-Start-Check # Mon Oct 15 18:20:48 CEST 2007 / Added exit code if HD couldn't be mounted # Tue Dec 11 23:02:18 CET 2007 / Added /usr/local/sbin to backup and -p para to cp command # Tue May 6 10:02:57 CEST 2008 / Added new procedure: mount backup-disk before backup and umount after # Wed May 21 09:59:15 CEST 2008 / Personalized for Server # Tue Jul 8 10:54:20 CEST 2008 / Changed cp command to rsync. Added for loop for folders to be backed # Added combo backup for nas and server with uname check # Not umount anymore # Mon Nov 24 13:22:06 CET 2008 / Added mybook mirroring # Thu Feb 5 22:20:49 CET 2009 / Modifed for only 1 server # Tue Feb 24 14:13:59 CET 2009 / Removed mybook mirroring. Is now on mybook_sync.sh # Fri Sep 4 16:46:37 CET 2009 / Added /var/lib/ldap to FOLDERS # Wed Feb 24 09:51:17 CET 2010 / Optimized complete code with funcs and printf # Wed Aug 18 14:01:22 CET 2010 / Changed rsync to rdiff-backup for incremental backup # Fri Dec 3 10:16:07 CET 2010 / Added retention for increments # Include library for common variables and functions # Fri Aug 19 18:20:56 CET 2011 / Added package list file into /root ### Config FOLDERS="/var/log /var/www /var/httpd /var/lib/mysql /var/lib/ldap /var/lib/postgresql /home /etc /root" # Separate with spaces BACKUPDISK="/mybook" BACKUPDIR="$BACKUPDISK/backup/server" TIMESTART=`date +%s` # Source library . backup.lib.sh || { echo "backup.lib.sh not found"; exit 1; } ### Checks if [ "$1" == "-n" ]; then DRYRUN=1 RDIFFPARAMS="--compare" echo "RUNNING IN DRY MODE" fi # Check if rdiff-backup exists [[ `which $RDIFFBIN` ]] || { echo "$RDIFFBIN not found"; exit 1; } # Check if Backup Disk is mounted if [ `mount |grep "$BACKUPDISK " >/dev/null` ]; then f_error "$BACKUPDISK not mounted" fi printf "++++++++++++++++++++++ Backup Start at `date +"%H:%M:%S"` +++++++++++++++++++++++\n" >$TMPFILE PKGLIST=/root/packages.installed DISTRO=`lsb_release -i |awk '{print $3}'` printf "Creating installed packages list $PKGLIST" >>$TMPFILE case $DISTRO in Debian) dpkg --get-selections |grep install |awk '{print $1}' >$PKGLIST ;; RedHatEnterpriseServer) rpm -qa >$PKGLIST ;; *) echo "Could not determine Linux distribution. Skipping package list..." >>$TMPFILE ;; esac f_mysqld stop # Building include list for FOLDER in $FOLDERS; do INCLUDEFOLDERS="$INCLUDEFOLDERS --include $FOLDER " done # Show what will be changed printf "\n$TXT01\n # $FOLDERS backuped (`date +"%H:%M:%S"`):\n$TXT01\n" >>$TMPFILE echo "--------------[ Change statistics ]--------------" >>$TMPFILE for FOLDER in $FOLDERS; do $RDIFFBIN --compare $FOLDER $BACKUPDIR$FOLDER >>$TMPFILE done # Do the backup $RDIFFBIN $RDIFFPARAMS $INCLUDEFOLDERS --exclude '**' / $BACKUPDIR >>$TMPFILE # Retention $RDIFFBIN --remove-older-than $RETENTION --force $BACKUPDIR >>$TMPFILE echo "--------------[ Incremental statistics ]--------------" >>$TMPFILE $RDIFFBIN -l $BACKUPDIR >>$TMPFILE f_mysqld start printf "\n++++++++++++++++++++++ Backup End at `date +"%H:%M:%S"` +++++++++++++++++++++++" >>$TMPFILE TIMESTOP=`date +%s` printf "\n++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++" >>$TMPFILE f_sendmail exit 0
backup_osiris.sh
- backup_osiris.sh
#!/bin/bash # # BACKUP SCRIPT # # Usage: backup_osiris.sh [-n] # # Fri Aug 20 16:19:26 CEST 2010 - adapted from backup_server.sh and reduced # Fri Dec 3 10:16:07 CET 2010 / Added retention for increments # Include library for common variables and functions # Sat Jul 2 14:17:11 CET 2011 - Added keychain requirement # Fri Aug 19 18:20:56 CET 2011 / Added package list file into /root ### Config FOLDERS="/var/log /etc /root" # Separate with spaces BACKUPSERVER="server.runlevel.ch" BACKUPDIR="/mybook/backup/osiris" TIMESTART=`date +%s` # Source library . backup.lib.sh || { echo "backup.lib.sh not found"; exit 1; } ### Checks if [ "$1" == "-n" ]; then DRYRUN=1 RDIFFPARAMS="--compare" echo "RUNNING IN DRY MODE" fi # Check if rdiff-backup exists [[ `which $RDIFFBIN` ]] || { echo "$RDIFFBIN not found"; exit 1; } # Check if a keychain with an adequate ssh agent exist and load it f_keychain # Check if remote server is reachable and backup dir is available [[ `$RDIFFBIN --test-server $BACKUPSERVER::$BACKUPDIR >$TMPFILE 2>&1` ]] && { f_error "$BACKUPSERVER not reachable" ; } [[ `ssh -q $BACKUPSERVER "cd $BACKUPDIR" >$TMPFILE 2>&1` ]] && { f_error "$BACKUPDIR on $BACKUPSERVER not reachable "; } ### Main printf "++++++++++++++++++++++ Backup Start at `date +"%H:%M:%S"` +++++++++++++++++++++++\n" >>$TMPFILE PKGLIST=/root/packages.installed DISTRO=`lsb_release -i |awk '{print $3}'` printf "Creating installed packages list $PKGLIST" >>$TMPFILE case $DISTRO in Debian) dpkg --get-selections |grep install |awk '{print $1}' >$PKGLIST ;; RedHatEnterpriseServer) rpm -qa >$PKGLIST ;; *) echo "Could not determine Linux distribution. Skipping package list..." >>$TMPFILE ;; esac # Building include list for FOLDER in $FOLDERS; do INCLUDEFOLDERS="$INCLUDEFOLDERS --include $FOLDER " done # Show what will be changed printf "\n$TXT01\n # Backup of $FOLDERS (`date +"%H:%M:%S"`):\n$TXT01\n" >>$TMPFILE echo "--------------[ Change statistics ]--------------" >>$TMPFILE for FOLDER in $FOLDERS; do $RDIFFBIN --compare $FOLDER $BACKUPSERVER::$BACKUPDIR$FOLDER >>$TMPFILE done # Do the backup $RDIFFBIN $RDIFFPARAMS $INCLUDEFOLDERS --exclude '**' / $BACKUPSERVER::$BACKUPDIR >>$TMPFILE # Retention $RDIFFBIN --remove-older-than $RETENTION --force $BACKUPSERVER::$BACKUPDIR >>$TMPFILE # Show statistics echo "--------------[ Incremental statistics ]--------------" >>$TMPFILE $RDIFFBIN -l $BACKUPSERVER::$BACKUPDIR >>$TMPFILE printf "\n++++++++++++++++++++++ Backup End at `date +"%H:%M:%S"` +++++++++++++++++++++++" >>$TMPFILE TIMESTOP=`date +%s` printf "\n++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++" >>$TMPFILE f_sendmail exit 0
mybook_sync.sh
- mybook_sync.sh
#!/bin/bash # # SYNCRONISATION SCRIPT FOR MYBOOKS # # Usage: mybook_sync.sh [-n] # # Tue Feb 24 14:12:14 CET 2009 # Tue Mar 16 10:05:49 CET 2010 Optimized and fixed ### Config RSYNCPARAMS="-aHvh --delete" TMPFILE="/tmp/mybook_sync.sh.tmp" # Complete path with filename for mail content EMAIL="hanr" # Address where content or alert shoult be sent, semicolon sep. FROM="mybook-sync" MYBOOK="/mybook" MIRROR="/mybook_mirror" TIMESTART=`date +%s` DRYRUN= ### Functions f_sendmail() { if [ "$DRYRUN" ]; then cat $TMPFILE else cat $TMPFILE |mailx -a from:$FROM -s "MyBook Syncronization" $EMAIL # Send mail with content of file fi exit 0 } f_checkbook() { if [[ -z `mount |grep "$1 "` ]]; then echo "!!! Skipped MyBook Syncronization!! $1 not mounted" >>$TMPFILE f_sendmail fi } ### SCRIPT echo "++++++++++++++++++++++ MyBook sync start at `date +"%H:%M:%S"` +++++++++++++++++++++++" >$TMPFILE if [ "$1" == "-n" ]; then RSYNCPARAMS="$RSYNCPARAMS -n"; DRYRUN=1 echo "RUNNING IN DRY MODE" fi # Check if MyBooks are mounted f_checkbook $MYBOOK f_checkbook $MIRROR # Do the sync rsync $RSYNCPARAMS $MYBOOK/ $MIRROR >> $TMPFILE printf "\n\n++++++++++++++++++++++ MyBook sync end at `date +"%H:%M:%S"` +++++++++++++++++++++++" >>$TMPFILE TIMESTOP=`date +%s` printf "\n++++++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++++++" >>$TMPFILE f_sendmail
gdrive_sync.sh
- gdrive_sync.sh
#!/bin/bash # # SYNCRONISATION SCRIPT TO GOOGLE DRIVE # # Usage: gdrive_sync.sh [-n] # # Fri Aug 22 14:21:56 CEST 2014 ### Config RSYNCPARAMS="-aHvh --delete" TMPFILE="/tmp/gdrive_sync.sh.tmp" # Complete path with filename for mail content EMAIL="hanr" # Address where content or alert shoult be sent, semicolon sep. FROM="gdrive-sync" GDFSTOOL=/usr/local/bin/gdfstool CREDFILE=/var/cache/gdfs/credcache SRCFS="/mybook" SOURCE="$SRCFS/backup" MNTPT="/mnt" DEST="$MNTPT/backup/`hostname`" TIMESTART=`date +%s` DRYRUN= ### Functions f_sendmail() { if [ "$DRYRUN" ]; then cat $TMPFILE else cat $TMPFILE |mailx -a "From:$FROM" -s "GDrive Syncronization" $EMAIL # Send mail with content of file fi exit 0 } f_checkfs() { if [[ -z `mount |grep "$1 "` ]]; then echo "!!! Skipped GDrive Syncronization!! $1 not mounted" >>$TMPFILE f_sendmail fi } ### SCRIPT [ "`whoami`" != "root" ] && { echo "Must run as root"; exit 2; } echo "++++++++++++++++++++++ GDrive sync start at `date +"%H:%M:%S"` +++++++++++++++++++++++" >$TMPFILE if [ "$1" == "-n" ]; then RSYNCPARAMS="$RSYNCPARAMS -n"; DRYRUN=1 echo "RUNNING IN DRY MODE" fi # Check if relevent FS are mounted and dirs exist [ -x $GDFSTOOL ] || { echo "$GDFSTOOL not found or executable"; exit 2; } [ -r $CREDFILE ] || { echo "$CREDFILE not found or readable"; exit 2; } $GDFSTOOL mount $CREDFILE $MNTPT f_checkfs $MNTPT f_checkfs $SRCFS [ -d $DEST ] || mkdir -p $DEST # Do the sync rsync $RSYNCPARAMS $SOURCE $DEST >> $TMPFILE printf "\n\n++++++++++++++++++++++ GDrive sync end at `date +"%H:%M:%S"` +++++++++++++++++++++++" >>$TMPFILE TIMESTOP=`date +%s` printf "\n++++++++++++++++++++++++++ Duration `expr $TIMESTOP - $TIMESTART`sec +++++++++++++++++++++++++++" >>$TMPFILE umount $MNTPT f_sendmail
ssid
- ssid
#!/bin/bash # # Command line WiFi connector. Only WPA and non-encryption supported # # Okt 31 09:06:31 CET 2007 # Fri May 23 16:02:39 CEST 2008 / added WPA option # Thu May 29 19:56:10 CEST 2008 / WPA key input is now invisible # added rescanning if SSID input is blank # Thu Sep 18 10:30:15 CEST 2008 / added function to scan available interface # and wpa_supplicant binary check # Wed Aug 19 11:37:54 CEST 2009 / more optimized # Mon Oct 3 14:53:59 CEST 2016 / dialog'ed # # IFACE=$1 umask 0002 # secure tmp files pkill wpa_supplicant # kill existing wpa processes DIALOGBIN=`which dialog` if [[ -z $DIALOGBIN ]] ; then DIALOG= else #DIALOGBIN="$DIALOGBIN --backtitle \"Wireless connection wizard\"" DIALOG=1 TMP=/tmp/tmp.$$ trap "rm -rf $TMP" INT TERM EXIT fi # Check if Parameter is a valid Interface to use. If not, the Script proposes # the Interface he found with iwconfig ifconfig $IFACE > /dev/null if [ "$?" -eq "1" ] ; then FINDIFACE=`iwconfig |grep IEEE |awk '{print $1}'` if [[ $DIALOG ]]; then $DIALOGBIN --title "Interface $1 not found" --msgbox "But found $FINDIFACE. \nContinuing with this interface" 8 50 else clear echo "Interface $1 not found..." echo "...but found $FINDIFACE. Press [ENTER] to continue with this Interface." read fi IFACE=$FINDIFACE fi # Output a Usage if no Parameter is given if [ "$1" == "" ] ; then echo "Usage: $0 interface" exit 1 fi clear ifconfig $IFACE up if [[ $DIALOG ]]; then $DIALOGBIN --infobox "Scanning for Access Points on $IFACE ..." 3 50 SSIDLIST=`iwlist $IFACE scanning |grep ESSID |cut -f2 -d\" |grep -v "\\x00"` SSIDLISTSIZE=`echo $SSIDLIST |wc -w` $DIALOGBIN --title "Enter ESSID you want to connect or leave blank to rescan" --inputbox "$SSIDLIST" `expr 10 + $SSIDLISTSIZE` 80 2>$TMP SSID=`cat $TMP` else echo "Scanning for Access Points in $IFACE ..." echo "" iwlist $IFACE scanning |grep ESSID echo "" echo "Enter ESSID you want to connect or leave blank to rescan and press [ENTER]:" read SSID fi # If the Input is empty, the Script loops over the scan and asks each time to enter # a SSID to continue with the connection while [[ -z $SSID ]]; do clear if [[ $DIALOG ]]; then $DIALOGBIN --infobox "Rescanning for Access Points on $IFACE ..." 3 50 SSIDLIST=`iwlist $IFACE scanning |grep ESSID |cut -f2 -d\" |grep -v "\\x00"` SSIDLISTSIZE=`echo $SSIDLIST |wc -w` $DIALOGBIN --title "Enter ESSID you want to connect or leave blank to rescan" --inputbox "$SSIDLIST" `expr 10 + $SSIDLISTSIZE` 80 2>$TMP SSID=`cat $TMP` else echo "Rescanning for Access Points..." iwlist $IFACE scanning |grep ESSID echo "Enter ESSID you want to connect or leave blank to rescan and press [ENTER]:" echo "" read SSID fi done # Set the entered SSID and wait 1 Second iwconfig $IFACE ESSID "$SSID" sleep 1 # Encryption select if [[ $DIALOG ]]; then $DIALOGBIN --title "Encryption" --radiolist "Please select Security for $SSID:" 10 60 2 1 None off 2 WPA on 2>$TMP ENCRYPT=`cat $TMP` else clear echo "You are connecting to $SSID" echo "Please select Security: " echo "1: None" echo "2: WPA" read ENCRYPT fi case "$ENCRYPT" in 1) ;; 2) # Check if wpa_supplicant is installed and quit if not if [[ ! `which wpa_supplicant` ]]; then if [[ $DIALOG ]]; then $DIALOGBIN --infobox "wpa_supplicant was not found on this system. Aborted" 3 60 else echo "wpa_supplicant was not found on this system. Aborted" fi exit 1 fi if [[ $DIALOG ]]; then $DIALOGBIN --passwordbox "Enter Passphrase" 10 60 2>$TMP PASS=`cat $TMP` else echo "Enter Passpharse: " read -s PASS fi # Store the entered Passphrase as WPA Key and start wpa_supplicant # process in the background wpa_passphrase $SSID $PASS > /etc/wpa_supplicant/wpa_supplicant.conf chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf wpa_supplicant -B -Dwext -i$IFACE -c/etc/wpa_supplicant/wpa_supplicant.conf & ;; *) if [[ $DIALOG ]]; then $DIALOGBIN --infobox "Wrong selection. Aborted!" 3 60 else echo "Wrong selection. Aborted!" fi exit 1 ;; esac # Renew the IP and quit smoothly if [[ $DIALOG ]]; then $DIALOGBIN --infobox "Obtaining IP Address\n\n If this process takes longer than 15s,\n you may enter a wrong key or no DHCP server present" 6 60 dhclient -q -1 $IFACE else dhclient -v -1 $IFACE fi
rsa_encrypter.sh
Skilled work at HFU. Slideshow in german rsa_encryption.ppt
- rsa_encrypter.sh
#!/bin/bash # # Mon Dec 29 13:20:30 CET 2008 # Tue Mar 16 15:00:24 CET 2010 / EEA korr.: Phi Zahl addiert wenn mult. Inv. kleiner 0 ist # anstatt groessere Primzahl # # RSA encryption simulator # # Usage: rsa_encrypter.sh [ 1.primenumber 2.primenumber [-d] ] # ################################################################################# # Variablen und Funktionen ################################################################################# if [ ! `which bc` ]; then echo "bc not found" exit 2 fi clear # Terminal loeschen START=$(date +%s.%N) # Zeit stoppen if [ "$3" -eq "-d" ]; then # Setze Variable DEBUG wenn der 3. Parameter -d ist DEBUG=1 else DEBUG= fi function_primzahl() # Waehlt zufaellig eine Primzahl aus dem Bereich { PRIM_ARRAY=( 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 ) ANZ_PRIMS=${#PRIM_ARRAY[*]} # Die Anzahl Elemente im Array INDEX=$(($RANDOM%$ANZ_PRIMS)) # Zufallszahl modulo Anzahl Elemente PRIMZAHL=${PRIM_ARRAY[$INDEX]} # Inhalt der Indexes zuweisen echo $PRIMZAHL # Inhalt ausgeben } function_ggt() # Rechne den groessten gemeinsamen Teiler { NUM1=$1 # Erster Parameter (Zahl) NUM2=$2 # Zweiter Parameter (Zahl) MOD=1 # Pseudo Platzhalter, da Variable nicht leer sein darf # Einfacher eukldischer Algorithmus: while [ $MOD != 0 ]; do MOD=`expr $NUM2 % $NUM1` # NUM2 Modulo NUM1 if [ $MOD == 0 ]; then echo $NUM1 else NUM2=$NUM1 NUM1=$MOD fi done } function_teilerfremd() # Gibt eine Zahl zurueck, die teilerfremd zur uebergebenen Zahl ist (parameter $1) { TEILER=0 while [ $TEILER != 1 ]; do # Wiederhole den Vorgang bis der ggT 1 zutrifft ZUFALLSZAHL=$(($RANDOM%$1)) # Zufallszahl generieren die kleiner als uebergebene Zahl ist if [ $ZUFALLSZAHL = 0 ]; then ZUFALLSZAHL=$(($RANDOM%$1)) # Falls Zahl 0 ist, generiere eine Neue fi TEILER=$(function_ggt $ZUFALLSZAHL $1) # Rufe den groessten gem. Teiler auf done echo $ZUFALLSZAHL # Gefundene Zahl ausgeben } function_erweuklalgo() # Erweiterter Euklidischer Algorithmus um das multiplikative Inverse zu ermitteln # Funktion kann mittels zwei Zahlen und -d als 3. Parameter einzel aufgerufen werden { if [ "$1" -le "$2" ]; then # Werte kehren, falls erster Wert kleiner ist als Zweiter g1=$2; g2=$1 else g1=$1; g2=$2 fi y1=1; y2=0 x1=0; x2=1 q=0 if [ $DEBUG ]; then printf "q\tg\ty\tx\n" echo "-------------------------" printf "$q\t$g1\t$y1\t$x1\n" printf "$q\t$g2\t$y2\t$x2\n" fi while [ $g2 != 1 ]; do # Wiederhole die Zerlegung bis g2 den Wert 1 erreicht hat q=`expr $g1 / $g2` if [ $DEBUG ]; then printf "$q\t" fi temp=$g2 g2=`expr $g1 % $g2` g1=$temp if [ $DEBUG ]; then printf "$g2\t" fi temp=$y2 let y2=$q*$y2 let y2=$y1-$y2 y1=$temp if [ $DEBUG ]; then printf "($y2)\t" fi temp=$x2 let x2=$q*$x2 let x2=$x1-$x2 x1=$temp if [ $DEBUG ]; then if [ $g2 == 1 ]; then echo -e "\033[1m$x2\033[0m" else echo -e "$x2\t" fi fi done if [ $DEBUG ]; then echo -e "\n g hat die Zahl 1 erreicht. Das multiplikative Inverse ist x" fi if [ "$x2" -le 0 ]; then # Wenn die Inverse kleiner 0 ist, addiere die Phi-Zahl, damit positiv if [ $DEBUG ]; then echo "x war eine negative Zahl, also Phi-Zahl generiert und addiert" let phiN=(`expr $1 - 1`*`expr $2 - 1`) let x2=$x2+$phiN else let phiN=(`expr $q - 1`*`expr $p - 1`) fi fi if [ $DEBUG ]; then printf "Endgueltiges, multiplikatives Inverse von $2 und $1 ist: " fi echo $x2 } ################################################################################ # Implementation ################################################################################ function_alice1() # Alice's erster Schritt { echo -e "\033[1m Alice: \033[0m" p=;q= if [ -e $1 -o -e $2 ]; then echo "Generiere Primzahlen..." elif [ $1 -eq -$2 ]; then echo "Zahlen duerfen nicht gleich sein" exit 2 fi while [ $p == $q ]; do # Wiederhole falls generierte Zahlen gleich if [ -e $1 ]; then p=$(function_primzahl) else let p=$1 fi if [ -e $2 ]; then q=$(function_primzahl) else let q=$2 fi done let N=$q*$p; echo -e "RSA Modul: $q x $p = \033[1m $N \033[0m" let phiN=(`expr $q - 1`*`expr $p - 1`); echo -e "Eulersche Phi-Funktion: ($q - 1) x ($p - 1) = \033[1m $phiN \033[0m" echo "Suche mittels euklidischem Algorhitmus eine Nummer, die teilerfremd zu $phiN ist:" e=$(function_teilerfremd $phiN); echo -e "\033[1m $e \033[0m ist teilerfremd zu $phiN (beide haben 1 als ggT)" echo -e "Alice's oeffentlicher Schluessel ist das RSA Modul \033[1m $N \033[0m und die gefundene, teilerfremde Zahl \033[1m $e \033[0m" echo "An Bob senden ---> ..." } function_bob1() # Bob's erster Schritt { echo -e "\033[1m Bob: \033[0m" x=$(($RANDOM%$N)); echo -e "Moechte die Zahl \033[1m $x \033[0m sicher an Alice uebermitteln (Zahl muss kleiner als RSA Modul sein)" echo -ne "Verschluessle die Zahl mit der Formel: $x ^ $e mod $N = "; y=$(echo $x^$e%$N |bc); echo -e "\033[1m $y \033[0m" echo "Sende zurueck ---> ..." } function_alice2() # Alice's zweiter Schritt { echo -e "\033[1m Alice: \033[0m" echo -ne "Benutze den erw. euklidischen Algorithmus um das multiplikative Inverse von $phiN und $e zu ermitteln:" b=$(function_erweuklalgo $phiN $e); echo -e "\033[1m $b \033[0m" echo -ne "Entschluessle $y mittels Formel: $y ^ $b mod $N = "; xy=$(echo $y^$b%$N |bc); echo -e "\033[1m $xy \033[0m" echo "" if [ $xy -eq $x ]; then echo "Hat geklappt!" else echo "Leider nicht geklappt" fi } # MAIN ################################################################################# echo "Dieses Script simuliert eine RSA Verschluesselung" echo "______________________________________" if [ $DEBUG ]; then echo "Fuehre nur den erw. euklidischen Algorithmus aus" function_erweuklalgo $1 $2 # Debug Euklidischer Algorithmus else function_alice1 $1 $2 printf "\n" function_bob1 printf "\n" function_alice2 fi END=$(date +%s.%N) DIFF=$(echo "$END - $START" |bc) echo "Die Kalkulationen dauerten $DIFF Sek"
accounts.sh
Decrypt, edit and reencrypt a gpg crypted file
- accounts.sh
#!/bin/bash # # Fri Feb 5 10:43:29 CET 2010 / hanr # Wed Feb 24 10:22:03 CET 2010 / added umask and clear screen # Mon May 10 21:32:44 CET 2010 / exit if passphrase wrong # vi and gpg binary check # LASTUMASK=`umask` ACCOUNTFILE=$HOME/.accounts VIBIN=`which vi` GPGBIN=`which gpg` # checks ([ -z $GPGBIN ] || [ -z $VIBIN ]) && { echo "gpg and/or vi not found on this system"; exit 1; } [ -f $ACCOUNTFILE.swp ] && { echo "File already in use by vi"; exit 1; } # set secure umask umask 077 # decrypt file and exit immediately if passphrase is wrong $GPGBIN -d $ACCOUNTFILE.gpg > $ACCOUNTFILE || exit 2 # edit $VIBIN $ACCOUNTFILE # encrypt new file and overwrite existing one echo "Encrypting ..." $GPGBIN --yes -e -r $USER $ACCOUNTFILE # remove unencrypted file rm -f $ACCOUNTFILE # restore umask umask $LASTUMASK # clear the screen clear
sa_passgen
- sa_passgen
#!/bin/bash # # A password generator. # # Thu Nov 20 08:23:44 CET 2008 hanr # Fri Feb 26 15:32:41 CET 2010 hanr - extended with special char at the end # SIZE=7 # Length of password without special char CHARARR=( q w e r t z u i o p a s d f g h j k l y x c v b n m Q W E R T Z U I O P A S D F G H J K L Y X C V B N M 1 2 3 4 5 6 7 8 9 0 ) # Array filling with chars SPCHARARR=( ! . = + - ) # Array filling with special chars TOTELEMCHAR=${#CHARARR[*]} # Number of elements in char array TOTELEMSPCHAR=${#SPCHARARR[*]} # Number of elements in special char array COUNTER=0 # Counter for loop while [ $COUNTER -lt $SIZE ] do COUNTER=`expr $COUNTER + 1` # Increment CHARINDEX=$(($RANDOM%$TOTELEMCHAR)) # Random indexnumber inside the array length with modulo PASS=$PASS"${CHARARR[$CHARINDEX]}" # Attach the char in the element to the password until its length done if [ ! `echo $PASS |egrep [0-9] >/dev/null` ]; then # If the passwd hasn't at least one numeric digit, PASS=`echo $PASS |cut -b1-6` # delete the last element PASS=$PASS"$(($RANDOM%9))" # and attach a random number from 0-9 at the end fi SPCHARINDEX=$(($RANDOM%$TOTELEMSPCHAR)) # Random indexnumber inside the array length with modulo PASS=$PASS"${SPCHARARR[$SPCHARINDEX]}" # Attach the special char in the element to the password echo $PASS # print the password exit 0
samhain_reinit.sh
- samhain_reinit.sh
# # This script reinitializes the Samhain database remotely # Execute this script immediatly after intentional changes in the system # # Thu Feb 3 09:31:56 CET 2011 - hanr # Sat Jul 2 14:19:09 CET 2011 - added keychain support # TARGETHOST=host.domain SAMNAME=samhain SSHOPTS="-q" printf "Check SSH keychain: " if [ -f ~/.keychain/$HOSTNAME-sh ]; then . ~/.keychain/$HOSTNAME-sh echo "Loaded" else echo "No keychain found. You will be prompted for passphrase" fi echo "Stopping $SAMNAME process" ssh $SSHOPTS $TARGETHOST "/etc/init.d/$SAMNAME stop" echo "Reinitialize database" # Delete existing DB and reinitialize a new one ssh $SSHOPTS $TARGETHOST "rm /var/lib/${SAMNAME}/${SAMNAME}_file; $SAMNAME -t init -p none" # Sign it ssh $SSHOPTS -t $TARGETHOST "gpg -a --clearsign --not-dash-escaped /var/lib/${SAMNAME}/${SAMNAME}_file" # Exit if signing fails [[ $? != 0 ]] && exit 2 # Rename and set right permissions ssh $SSHOPTS $TARGETHOST "mv /var/lib/${SAMNAME}/${SAMNAME}_file.asc /var/lib/${SAMNAME}/${SAMNAME}_file;\ chmod 640 /var/lib/${SAMNAME}/${SAMNAME}_file" echo "Starting $SAMNAME process" ssh $SSHOPTS $TARGETHOST "/etc/init.d/$SAMNAME start"
mrtg_mails.sh
- mrtg_mails.sh
#!/bin/sh # # This script collects the total amount of recevied mails (incl. spam) # and the total of spam only marked mails per hour. # The script is performed for MRTG and must be scheduled at :59 min # # Caveats: Last minute before full hour is missing # # Mon Mar 8 15:59:32 CET 2010 hanr # # Where is your maillog MAILLOG=/var/log/mail.log # Spamassassin messages SPAMMSG="identified spam" CLEANMSG="clean message" # Timestamp in maillog DATE=`date '+%b %e %H:'` # Get spam mails SPAM=`grep "$SPAMMSG" $MAILLOG |grep -e "^$DATE" |wc -l` # Get clean mails CLEAN=`grep "$CLEANMSG" $MAILLOG |grep -e "^$DATE" |wc -l` TOTAL=`expr $SPAM + $CLEAN` echo $TOTAL echo $SPAM
compare-format-metadb.sh
- compare-format-metadb.sh
#!/bin/bash # # Tue May 5 12:25:41 CEST 2009 / hanr # Thu Jul 16 10:38:10 CEST 2009 / hanr - added verbose info # Tue Oct 6 09:45:01 CEST 2009 / hanr - added devfsadm and cfgadm # Wed Jan 27 14:46:35 CEST 2010 / hanr - checks also local filesystems # and looks in vfstab if not in metadb # Wed Jun 9 12:54:20 CEST 2010 / hanr - added metadb check and warning if in vfstab # fixed some stuff and made it functional # Fri Jun 10 09:17:06 CEST 2011 / hanr - added version, minor bugfix # # This script compares disks from format in metadb and vice versa # Must run under root and SunOS # VERSION=0906610 f_checks() { if [ `id |cut -f2 -d'=' |cut -f1 -d'('` -ne "0" ]; then echo "This script must run under UID 0 (root)" exit 2 fi if [[ `uname -s` -ne "SunOS" ]]; then echo "This script runs only on Solaris" exit 2 fi if [[ ! `metadb` ]]; then echo "No metadb found on this machine. Seems you don't use the Solaris LVM" exit 2 fi } f_parameters() { case $1 in -v) VERBOSE=1 ;; -h|--help) echo "Usage: $0 [-v]" exit 1 ;; *) VERBOSE=0 esac } f_device_discovery() { printf "Device discovery..." printf "devfsadm...." devfsadm -C printf "cfgadm..." cfgadm -al > /dev/null echo "done" printf "\n\n" } f_compare_format2metadb() { METADB=`metastat -c` echo " COMPARE IF DISK FROM FORMAT IS IN METADB " echo "------------------------------------------------------" for DISK in `format </dev/null |grep alt |grep -v configured |awk '{print $2}'`; do printf "Searching Disk $DISK in metadb: " if [[ `echo $METADB |grep $DISK` ]]; then echo -e "\033[1mok\033[0m" else if [[ `grep $DISK /etc/vfstab` ]]; then echo -e "not found, but in vfstab. \033[1mwarning\033[0m" else echo "NOT IN METADB FOUND!!!" fi fi if [ "$VERBOSE" -eq "1" ]; then format $DISK <<EOF |tail -12 ver q EOF echo "> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >" echo "" fi done #echo "Press ENTER key to continue..."; read printf \\n\\n } f_compare_metadb2format() { FORMATLIST=`format </dev/null` echo " COMPARE IF DISK FROM METADB IS IN FORMAT " echo "------------------------------------------------------" for DISK in `metastat -c |grep dsk |awk '{print $4}' |cut -f4 -d'/' |cut -f1 -d's'`; do printf "Searching Disk $DISK in format: " if [[ `echo $FORMATLIST |grep $DISK` ]]; then echo -e "\033[1mok\033[0m" else echo "NOT IN FORMAT FOUND !!!" fi done } # MAIN printf "\n*** `basename $0` - Version $VERSION *** \n\n" f_checks f_parameters $1 f_device_discovery f_compare_format2metadb f_compare_metadb2format
transcode-ffmpeg.sh
This file is used by Media Tomb to transcode any format supported by ffmpeg to a mpeg2 stream
The command in /etc/mediatomb/config.xml looks like this:
<agent command="/var/lib/mediatomb/transcode-ffmpeg" arguments="%in %out"/>
- transcode-ffmpeg.sh
#!/bin/bash FFMPEG_PATH="/usr/bin/ffmpeg" ASPECT="-aspect 16:9" INPUT="$1" OUTPUT="$2" VIDEO_CODEC="mpeg2video" VIDEO_BITRATE="8192k" #AUDIO_CODEC="mp2" AUDIO_CODEC="mp2" #AUDIO_CODEC="ac3" AUDIO_BITRATE="128k" AUDIO_SAMPLERATE="44100" AUDIO_CHANNELS="1" #FORMAT="dvd" #FORMAT="mpegts" FORMAT="mpeg" exec "${FFMPEG_PATH}" -y -i "${INPUT}" "${ASPECT}" -vcodec ${VIDEO_CODEC} -b ${VIDEO_BITRATE} \ -acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} -ar ${AUDIO_SAMPLERATE} \ -ac ${AUDIO_CHANNELS} -f ${FORMAT} - > "${OUTPUT}"
aircrack
This script creates a monitoring interface using airmon-ng and then starts aircrack-ng
- aircrack
#!/bin/bash # # Thu Sep 2 13:01:36 CEST 2010 hanr airmon-ng check echo "Press any key to continue..." read MON=`ifconfig |grep mon |tail -1 |awk '{print $1}'` [[ -z $MON ]] && { MON=`airmon-ng start wlan0 |grep enabled |awk '{print $5}' |sed -e 's/)$//g'`; } || { echo "Existing interface $MON found"; } echo "Will start monitoring with interface ${MON}. Press any key to begin..." read airodump-ng -u 1 -a -w dump $MON # aircrack-ng -a 1 dump.ivs echo "Stopping airmon-ng on wlan0" airmon-ng stop wlan0 echo "Bringing interface $MON down" ifconfig $MON down
spacewalk-package-installed
This script shows which servers have installed a specific package
- spacewalk-package-installed
#!/bin/bash PACKAGE=$1 VERSION=$2 RELEASE=$3 [[ $@ -ne 3 ]] && { echo "Usage: $0 packagename version release"; exit 2; } for id in `/usr/bin/spacewalk-report system-packages-installed \ --where-package_name=$PACKAGE \ --where-package_version=$VERSION \ --where-package_release=$RELEASE \ |cut -f1 -d, |grep -v ^system_id` do /usr/bin/spacewalk-report inventory \ --where-server_id=$id \ |cut -f3 -d, |tail -1 done
C
zombie.c
- zombie.c
#include <stdlib.h> #include <sys/types.h> #include <unistd.h> // This script creates a zombie process which will be // declared as defunct in a UNIX system // Compile: gcc -o zombie zombie.c int main () { pid_t child_pid; child_pid = fork (); if (child_pid > 0) { sleep (60); } else { exit (0); } return 0; }
Patches
Roundcube
ext_addrbook_inetorgperson.patch
This patch was taken from Ticket 1486377 of trac.roundcube.net and adopted to match the RFC 2798
- ext_addbook_inetorgperson.patch
# This patch was taken from Ticket 1486377 of trac.roundcube.net and adopted to match the RFC 2798 # # Only usable for v0.5 and higher # # Caveats: # It only applies the php files, no database patch!!! (I'm using LDAP) # It patches only the language files en_US and de_CH. Edit other language files by hand # # Wed Jul 28 10:31:14 CET 2010 hanr - Modified for v.0.4 compatibility # Mon Mar 7 11:13:19 CET 2011 hanr - Modified for v.0.5 compatibility # Changed location label to location_place because newly used by RC # diff -ruw roundcubemail_svn/config/main.inc.php roundcubemail/config/main.inc.php --- roundcubemail_svn/config/main.inc.php 2010-05-04 16:39:10.000000000 -0600 +++ roundcubemail/config/main.inc.php 2010-05-04 16:46:25.000000000 -0600 @@ -425,6 +425,14 @@ 'email_field' => 'mail', // this field represents the contact's e-mail 'surname_field' => 'sn', // this field represents the contact's last name 'firstname_field' => 'gn', // this field represents the contact's first name + 'work_number_field' => 'Phone', // contact work phone number + 'home_number_field' => 'homePhone', // contact home phone number + 'fax_number_field' => 'Fax', // contact fax number + 'mobile_number_field' => 'mobile', // contact cell number + 'title_field' => 'title', // contact title + 'street_field' => 'street', // contact street name + 'postal_code_field' => 'postalCode', // contact postal code + 'location_place_field' => 'l', // contact location 'sort' => 'cn', // The field to sort the listing by. 'scope' => 'sub', // search mode: sub|base|list 'filter' => '', // used for basic listing (if not empty) and will be &'d with search queries. example: status=act Only in roundcubemail/config: main.inc.php.orig diff -ruw roundcubemail_svn/program/include/rcube_contacts.php roundcubemail/program/include/rcube_contacts.php --- roundcubemail_svn/program/include/rcube_contacts.php 2010-05-04 16:38:34.000000000 -0600 +++ roundcubemail/program/include/rcube_contacts.php 2010-05-04 16:46:25.000000000 -0600 @@ -42 +42 @@ - private $table_cols = array('name', 'email', 'firstname', 'surname', 'vcard'); + private $table_cols = array('name', 'email', 'firstname', 'surname', 'work_number', 'home_number', 'fax_number', 'mobile_number', 'title', 'street', 'postal_code', 'location_place', 'vcard'); Only in roundcubemail/program/include: rcube_contacts.php.orig diff -ruw roundcubemail_svn/program/include/rcube_vcard.php roundcubemail/program/include/rcube_vcard.php --- roundcubemail_svn/program/include/rcube_vcard.php 2010-05-04 16:38:34.000000000 -0600 +++ roundcubemail/program/include/rcube_vcard.php 2010-05-04 16:46:25.000000000 -0600 @@ -75,6 +75,29 @@ $this->nickname = $this->raw['NICKNAME'][0][0]; $this->organization = $this->raw['ORG'][0][0]; $this->business = ($this->raw['X-ABSHOWAS'][0][0] == 'COMPANY') || (join('', (array)$this->raw['N'][0]) == '' && !empty($this->organization)); + $this->title = $this->raw['TITLE'][0]; + foreach ($this->raw['LABEL'] as $entry) { + if ($entry['type'][0] == "HOME"){ + $this->location_place = $entry[0]; + } + elseif ($entry['type'][0] == "WORK") { + $this->postal_code = $entry[0]; + } + } + foreach ($this->raw['TEL'] as $entry) { + if ($entry['type'][0] == "HOME"){ + $this->home_number = $entry[0]; + } + elseif ($entry['type'][0] == "WORK") { + $this->work_number = $entry[0]; + } + elseif ($entry['type'][0] == "CELL") { + $this->mobile_number = $entry[0]; + } + elseif ($entry['type'][0] == "FAX") { + $this->fax_number = $entry[0]; + } + } foreach ((array)$this->raw['EMAIL'] as $i => $raw_email) $this->email[$i] = is_array($raw_email) ? $raw_email[0] : $raw_email; @@ -145,6 +162,47 @@ $this->raw['EMAIL'][$index][0] = $value; } break; + + case 'home_number': + $index=$this->get_type_index('TEL','HOME'); + if (!is_array($this->raw['TEL'][$index])) { + $this->raw['TEL'][$index] = array(0 => $value, 'type' => 'HOME'); + } + else { + $this->raw['TEL'][0][0] = $value; + } + break; + + case 'work_number': + $index=$this->get_type_index('TEL','WORK'); + if (!is_array($this->raw['TEL'][$index])) { + $this->raw['TEL'][$index] = array(0 => $value, 'type' => 'WORK'); + } + else { + $this->raw['TEL'][0][0] = $value; + } + break; + + case 'mobile_number': + $index=$this->get_type_index('TEL','CELL'); + if (!is_array($this->raw['TEL'][$index])) { + $this->raw['TEL'][$index] = array(0 => $value, 'type' => 'CELL'); + } + else { + $this->raw['TEL'][0][0] = $value; + } + break; + + case 'fax_number': + $index=$this->get_type_index('TEL','FAX'); + if (!is_array($this->raw['TEL'][$index])) { + $this->raw['TEL'][$index] = array(0 => $value, 'type' => 'FAX'); + } + else { + $this->raw['TEL'][0][0] = $value; + } + break; + } } diff -ruw roundcubemail_svn/program/localization/de_CH/labels.inc roundcubemail/program/localization/de_CH/labels.inc --- roundcubemail_svn/program/localization/de_CH/labels.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/localization/de_CH/labels.inc 2010-05-04 16:46:25.000000000 -0600 @@ -200,0 +200,09 @@ +$labels['phone'] = 'Telefon'; +$labels['work_number'] = 'Arbeit'; +$labels['home_number'] = 'Privat'; +$labels['fax_number'] = 'Fax'; +$labels['mobile_number'] = 'Mobile'; +$labels['title'] = 'Titel'; +$labels['street'] = 'Strasse'; +$labels['postal_code'] = 'Postleitzahl'; +$labels['location_place'] = 'Ort'; diff -ruw roundcubemail_svn/program/localization/en_US/labels.inc roundcubemail/program/localization/en_US/labels.inc --- roundcubemail_svn/program/localization/en_US/labels.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/localization/en_US/labels.inc 2010-05-04 16:46:25.000000000 -0600 @@ -242,6 +242,15 @@ $labels['firstname'] = 'First name'; $labels['surname'] = 'Last name'; $labels['email'] = 'E-Mail'; +$labels['phone'] = 'Phone'; +$labels['work_number'] = 'Work Number'; +$labels['home_number'] = 'Home Number'; +$labels['fax_number'] = 'Fax Number'; +$labels['mobile_number'] = 'Mobile Number'; +$labels['title'] = 'Title'; +$labels['street'] = 'Street'; +$labels['postal_code'] = 'Postal Code'; +$labels['location_place'] = 'Location'; $labels['addcontact'] = 'Add new contact'; $labels['editcontact'] = 'Edit contact'; diff -ruw roundcubemail_svn/program/steps/addressbook/edit.inc roundcubemail/program/steps/addressbook/edit.inc --- roundcubemail_svn/program/steps/addressbook/edit.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/steps/addressbook/edit.inc 2010-05-04 16:46:25.000000000 -0600 @@ -58,6 +58,14 @@ 'firstname' => array('type' => 'text', 'size' => $i_size), 'surname' => array('type' => 'text', 'size' => $i_size), 'email' => array('type' => 'text', 'size' => $i_size), + 'work_number' => array('type' => 'text', 'size' => $i_size), + 'home_number' => array('type' => 'text', 'size' => $i_size), + 'fax_number' => array('type' => 'text', 'size' => $i_size), + 'mobile_number' => array('type' => 'text', 'size' => $i_size), + 'title' => array('type' => 'text', 'size' => $i_size), + 'street' => array('type' => 'text', 'size' => $i_size), + 'postal_code' => array('type' => 'text', 'size' => $i_size), + 'location_place' => array('type' => 'text', 'size' => $i_size), ), ), ); diff -ruw roundcubemail_svn/program/steps/addressbook/export.inc roundcubemail/program/steps/addressbook/export.inc --- roundcubemail_svn/program/steps/addressbook/export.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/steps/addressbook/export.inc 2010-05-04 16:46:25.000000000 -0600 @@ -35,6 +35,14 @@ $vcard->set('firstname', $row['firstname']); $vcard->set('surname', $row['surname']); $vcard->set('email', $row['email']); + $vcard->set('title', $row['title']); + $vcard->set('street', $row['street']); + $vcard->set('work_number', $row['work_number']); + $vcard->set('home_number', $row['home_number']); + $vcard->set('mobile_number', $row['mobile_number']); + $vcard->set('fax_number', $row['fax_number']); + $vcard->set('postal_code', $row['postal_code']); + $vcard->set('location_place', $row['location_place']); echo $vcard->export(); } diff -ruw roundcubemail_svn/program/steps/addressbook/import.inc roundcubemail/program/steps/addressbook/import.inc --- roundcubemail_svn/program/steps/addressbook/import.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/steps/addressbook/import.inc 2010-05-04 16:46:25.000000000 -0600 @@ -152,6 +152,14 @@ 'firstname' => $vcard->firstname, 'surname' => $vcard->surname, 'email' => $email, + 'work_number' => $vcard->work_number, + 'home_number' => $vcard->home_number, + 'mobile_number' => $vcard->mobile_number, + 'fax_number' => $vcard->fax_number, + 'title' => $vcard->title, + 'street' => $vcard->street, + 'postal_code' => $vcard->postal_code, + 'location_place' => $vcard->location_place, 'vcard' => $vcard->export(), ); diff -ruw roundcubemail_svn/program/steps/addressbook/save.inc roundcubemail/program/steps/addressbook/save.inc --- roundcubemail_svn/program/steps/addressbook/save.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/steps/addressbook/save.inc 2010-05-04 16:46:25.000000000 -0600 @@ -40,7 +40,7 @@ // setup some vars we need -$a_save_cols = array('name', 'firstname', 'surname', 'email'); +$a_save_cols = array('name', 'firstname', 'surname', 'email', 'work_number', 'home_number', 'fax_number', 'mobile_number', 'title', 'street', 'postal_code', 'location_place'); $a_record = array(); // read POST values into hash array diff -ruw roundcubemail_svn/program/steps/addressbook/show.inc roundcubemail/program/steps/addressbook/show.inc --- roundcubemail_svn/program/steps/addressbook/show.inc 2010-05-04 16:38:26.000000000 -0600 +++ roundcubemail/program/steps/addressbook/show.inc 2010-05-04 16:46:25.000000000 -0600 @@ -49,7 +49,15 @@ 'name' => array('type' => 'text', 'size' => $i_size), 'firstname' => array('type' => 'text', 'size' => $i_size), 'surname' => array('type' => 'text', 'size' => $i_size), 'email' => array('type' => 'text', 'size' => $i_size), + 'work_number' => array('type' => 'text', 'size' => $i_size), + 'home_number' => array('type' => 'text', 'size' => $i_size), + 'fax_number' => array('type' => 'text', 'size' => $i_size), + 'mobile_number' => array('type' => 'text', 'size' => $i_size), + 'title' => array('type' => 'text', 'size' => $i_size), + 'street' => array('type' => 'text', 'size' => $i_size), + 'postal_code' => array('type' => 'text', 'size' => $i_size), + 'location_place' => array('type' => 'text', 'size' => $i_size), ), ), 'groups' => array( @@ -74,7 +82,7 @@ 'class' => $microformats['email'], ), Q($record['email'])); } - foreach (array('name', 'firstname', 'surname') as $col) { + foreach (array('name', 'firstname', 'surname', 'work_number', 'home_number', 'fax_number', 'mobile_number', 'title', 'street', 'postal_code', 'location_place') as $col) { if ($record[$col]) { $form['info']['content'][$col]['value'] = html::span($microformats[$col], Q($record[$col])); }
DOS
For loop
Convert xwm files in a loop with VLC to mp3 format
c:\Program Files (x86)\VideoLAN\VLC>for %i in ("c:\users\ReDiculum\Desktop\music\explore\*.xwm") do vlc -I dummy -vvv %i --sout=#transcode{acodec=mp3}:standard{access=file,mux=raw,dst=%i.mp3 vlc://quit