dccmessage: 192.168.0.1 [irc hostname]
dccmessage: PRIVMSG
dccmessage: crawler
dccmessage: :DCC
dccmessage: SEND
dccmessage: .profile [dynamisch aufgrund der spaces]
dccmessage: 3232235521 [long integer ip]
dccmessage: 1482 [vorletzter wert]
dccmessage: 202 [letzter wert]

{{{@dccmessages[0] ==> ip @dccmessages[5] ==> filename @dccmessages[7] ==> port @dccmessages[8] ==> size}}}

sub on_dcc {
#  &on_dcc($dccip,@dccmessages[5],@dccmessages[7],@dccmessages[8]);
    my ($dccserver, $dccfilename, $dccport, $dccsize) = @_;

#       $MySocket=new IO::Socket::INET->new(PeerPort=>$dccport,Proto=>'tcp',PeerAddr=>$dccserver);
#       $MySocket->recv($binary,1024);
#       open (TEST, ">>/tmp/$dccfilename") or do { warn "Can't open test file: $!"; return; };
#       $end=0;
#       while($end!=-1){
#               print TEST $binary;
#               $MySocket->recv($binary,1024); #one week ago I read that it's bad putting system calls into loops well here it is ;)
#               if($binary eq ""){
#                       $end=-1;
#               }
#       }
#       print"transmission finished";


        socket(DCCSH,PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $!;
        my $sin1 = sockaddr_in($dccport,inet_aton($dccserver));
        open (TEST, ">>/tmp/$dccfilename") or do { warn "Can't open test file: $!"; return; };
        connect(DCCSH,$sin1) ;
        do{
                $nread = sysread($sin1
#        while(<DCCSH>){
#               print TEST $_;
#       }
#       $self->new_get($event, \*TEST);
#       print "Saving incoming DCC SEND to /tmp/net-irc.dcctest\n";

sub dcc{
        my ($dccserver, $dccport, $dccfilename, $dccsize)= @_;
        my $long = unpack "L", inet_aton $dccserver;
        my $dccserver = inet_ntoa pack "L", $long;
        print "dcc send from: $dccserver on $dccport\n";
        $dccconnection=new IO::Socket::INET->new(PeerPort=>$dccport,Proto=>'tcp',PeerAddr=>$dccserver);
        open(FILE,">>/tmp/$dccfilename");
        $packetsize=512;

        do{
                if($dccsize>=0){
                        $nread=sysread($dccconnection,$buffer,$packetsize);
                        $dccsize=$dccsize-$packetsize;
#                       print "dccsize: $dccsize\n";
#                       print "packetsize: $packetsize\n";
                        print FILE $buffer;
                }
                if($dccsize-$packetsize<0){
                        $packetsize=$dccsize;
                        print "packetsize: $packetsize\n";
                        print "dccsize - packetsize = ".$dccsize-$packetsize."\n";
                        sleep 1;
                }
        }while($dccsize != 0);
        close(FILE);
        close($dccconnection);
        print"\n\nfile successfully downloaded\n\n";
}

echo "Generating Code: ";
export d=-1;
for((i=0;i<=255;i++)); do
        echo ",$i";
done | rl | while read number; do
        d=`expr $d + 1`;
        echo $d$number;
done | while read lines; do
        printf "$lines,";
done; echo "";

Timing mittels time.h:

#include <time>
...
clock_t clo;
clo=clock();
....
clo=clock()-clo;
printf("%lf s\n",clo/(double)CLOCKS_PER_SEC);
...

Quick n dirty for the lazy ones

photos kopieren:

mount | grep cam
if [ $? == 1 ]; then
        echo cam not mounted ...
        user=`id -un`;
        notmounted=1;
        if [ "$user" = "root" ]; then
                echo user is root mounting cam...
                mount /dev/sda1 /cam;
        else
                echo user not allowed to mount cam..
                exit 1;
        fi
else
        notmounted=0;
fi

printf "Enter destination: "
cd 2003
read directory
test -d directory
if [ $? == 1 ]; then
        echo Creating directory $directory;
        echo copying pictures from digicam;
        mkdir $directory
        cp /cam/dcim/100casio/* $directory/;
        echo done...
else
        echo Sorry directory already exists...
fi

if [ $notmounted  == 1 ]; then
        echo unmounting cam;
        umount /cam
fi

thumbnails und compression for the lazy ones hehe

cd /var/www/photos
rm cat_*
cd /var/www/2003
for FILE in $(ls); do
        ln `pwd`/$FILE /var/www/photos/cat_`echo $FILE | sed 's/_//g'` -s 2>/dev/null 1>/dev/null;
done;
cd /var/www/photos
for FILE in $(ls cat_* -d); do
        cd $FILE
        TAG=$(ls index.html);
        if [ "$TAG" == "index.html" ]; then
                echo $FILE;
                echo "Tag vorhanden";
        else
                for CONV in $(ls *jpg); do
                        echo "Compressing $CONV...";
                        convert $CONV $CONV.1;
                        mv $CONV.1 $CONV;
                done;
                echo "done."
                echo "running galrey to create thumbnails..."
                galrey 1>/dev/null 2>/dev/null
                echo "done."
                echo "renaming thumbnails..."
                for FILE in $(ls t*); do mv $FILE TN_`echo $FILE | sed s/t_//g;`; done
                echo "done."
                echo "deleting galrey html files..."
                rm *html
                echo "done."
                echo "tagging as done.."
                touch index.html;
                echo "done."
        fi;
        cd ..
done;

simplevpn

checkhost:

#!/bin/bash
# (C)opyright 2003 Markus Rechberger <markus@karlsruhe.kicks-ass.net>
#
# etwas drunter und drüber aber es sollte funktioniern :)
# version: 1.6

# setting up some variables

host=myhost
. /etc/vpnhost
lockfile=/var/run/vpncheck.pid
user=`id -un`
verbose=1
hosttimeout=1
vpntimeout=1
debug=0

if [ "$debug" = "1" ]; then
        date > /tmp/checkhostdbg
        echo $PATH >> /tmp/checkhostdbg
fi
if [ "$1" = "-d" ]; then
        hosttimeout=60
        vpntimeout=30
        verbose=0;
fi
if [ "$user" != "root" ]; then
        output "this script may only be run as user root"
        exit 1
fi

output(){
        if [ $verbose == 1 ]; then
                echo $*
        fi
}

test -f $lockfile
if [ $? == 1 ]; then
        echo $$ > $lockfile
else
        vpnpid=`cat $lockfile`
        output "Check is running ($vpnpid) exiting!"
        exit 0
fi

vpncheck(){
        timeout -2 3 ping -c 1 $vpnhost> /dev/null
        if [ $? != 0 ]; then
                output "VPN Host seems to be filtered or down!";
                test -f /var/run/vtundclient.pid
                if [ $? == 0 ]; then
                        output Found vtundclient pid
                        vtunpid=`cat /var/run/vtundclient.pid`;
                        rm /var/run/vtundclient.pid
                        output "validating.."
                        output vtunpid: $vtunpid;
                        test -d /proc/$vtunpid;
                        if [ $? == 0 ]; then
                                output vtunpid valid: $vtunpid .. killing
                                kill $vtunpid
                        else
                                output "vtunpid wasn't valid .. "
                        fi
                fi

                down=1;
        else
                output "VPN Host seems to be nice!";
                down=0;
        fi
}

vpncheck;

if [ $down == 1 ]; then
        output "running renewal process";
        while [ "$down" == "1" ]; do
                timeout -2 3 ping -c 1 $host > /dev/null
                if [ $? == 1 ]; then
                        output "host is still down!.. sleeping $hosttimeout seconds";
                        sleep $hosttimeout
                else
                        output "host seems to be online!";
                        output "trying to reconnect vpn";
                        sh -c "/etc/init.d/subscript $host $$"&
                        output "sleeping $vpntimeout seconds"
                        sleep $vpntimeout
                        vpncheck;
                        if [ $down == 1 ]; then
                                output "restarting check";
                        else
                                output "everything seems to be up again ..";
                        fi
                fi
        done
fi

output check for update
version=`timeout 3 lynx --dump http://$host/vpn/checkhost | head -n 5 - | grep version | awk '{print $3}'`
if [ "$version" = "$installed" ]; then
        output version is up do date
else
        tempdir=$$
        output version differs .. getting and installing new one
        mkdir /tmp/$tempdir.vpn
        wget --directory-prefix=/tmp/$tempdir.vpn http://$host/vpn/checkhost http://$host/vpn/subscript --non-verbose 1>/dev/null 2>/dev/null
        cat /etc/vpnhost | grep -v installed > /tmp/vpnhost.$$
        echo installed=$version >> /tmp/vpnhost.$$
        mv /tmp/vpnhost.$tempdir /etc/vpnhost
        mv /tmp/$tempdir.vpn/checkhost /etc/init.d/checkhost
        mv /tmp/$tempdir.vpn/subscript /etc/init.d/subscript
        rm -rf /tmp/$tempdir.vpn
        chmod 700 /etc/init.d/subscript
        chmod 700 /etc/init.d/checkhost
fi
rm $lockfile

subscript:

#!/bin/bash
PATH=$PATH:/usr/sbin
. /etc/vpnhost
if [ "$2" = "$PPID" ] && [ "$2" != "" ]; then
        echo $$>/var/run/vtundclient.pid;
        exec vtund $client $1 -n $options </dev/null >/dev/null 2>/dev/null;
else
        echo "this script mustn't run as user/root"
fi

democonfig

#sample config file
vpnhost=<myvpnip> # master server
options="-P 5000" # optional vtund settings
client=rvbackup # vtund client
installed=1.6

wddx tagcloser v0.1:

# wddx tag closer - Markus Rechberger <mrechberger |at| web -dot- de>
#

open(HANDLER,"<file.xml");

my $content=<HANDLER>;
my $pos=0;
my $found=0;
$opened=0;
my @tag;
my $nexttag;
my $endtag;
do{
        $pos=index($content,'<',$pos);
        $nextpos=index($content,'/>',$pos);
        $nextendpos=index($content,'>',$pos);
        if($nextendpos-1 == $nextpos){
                # simply ignore this single tag
                $pos=$nextendpos;
        } else {
                if(substr($content,$pos,2) ne "</"){
                        $nexttag=index($content,'<',$pos+1);
                        $endtag=index($content,'>',$pos);
                        if(($endtag>$nexttag&&$nexttag!=-1)||$endtag==-1){
                                if($nexttag!=0){
                                        $content=substr($content,0,$pos);
                                }
                                $pos=-1;
                                $opened--;
                        } else{
                                $nexttag=index($content,' ',$pos+1);
                                if($nexttag!=-1&&$nexttag<$endtag){
                                        $nexttag--;
                                        $endtag=$nexttag;
                                }
                                $tag[$opened++]=substr($content,$pos+1,$endtag-$pos);
                                $found++;
                                if($endtag==$nexttag){
                                        $tag[$opened-1]=$tag[$opened-1].">";
                                }
                        }
                } else {
                        $endtag=index($content,'>',$pos);
                        $opened--;
                        if($endtag==-1){
                                print "cuting\n";
                                $content=substr($content,0,$pos);
                                $pos=-1;
                        }
                }
                if($pos!=-1){
                        $pos++;
                }
        }

} while($pos!=-1);
if($opened>0){
        print"damaged wddx detected\n";
}
for($i=$opened;$i>=0;$i--){
        $recover.="</$tag[$i]";
}
my $recovered=$content.$recover;
open(FINAL,">recovered.xml");
print FINAL $recovered;
close(FINAL);
close(HANDLER);

Nettes script um google/groups im überblick zu behalten :) sed sollte ich mir da noch etwas anschauen..

rm tmp.$$;
touch tmp.$$;
touch stamp.$$;
clear
export UPDATED; 
while :; 
do links 'http://www.google.com/groups?NR=100&hl=en&lr=&ie=UTF-8&group=comp.os.linux.advocacy' -dump -width 200| sed s#\([0123456789][0123456789]\ article.*##g | sed s#\([0123456789]\ article.*##g| grep 2003 |while read a b c d; 
    do if [ "$c" = "`date +%Y`" ]; then 
       MESSAGE="$a-$b-$c $d"; 
    fi; 
    echo $MESSAGE | while read line; 
    do 
      cat tmp.$$ | grep `echo $line | md5sum` -c | while read foo; 
      do 
        if [ "$foo" = "0" ]; then 
           echo "$line"; 
           echo $line | md5sum >> tmp.$$; 
           export UPDATED=1; 
        else 
           export UPDATED=0; 
        fi; 
      done; 
    done; 
  done; 
  sleep 5; 
  if  [ "`cat stamp.$$`" != "`md5sum tmp.$$`"  ]; then 
    md5sum tmp.$$ > stamp.$$; 
    echo ============== UPDATED ==========; 
  fi;  
done

C array beispiel

dynamische allocierung eines multidimensionalen arrays, array pointer mittels realloc damit die alten pointer nicht verloren gehen und die neuen mit malloc

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main ()
{
  char input[50],n;
  int count=0;
  char **strings = NULL;

   do{
         scanf("%s",input);
         strings = (char**) realloc (strings,(count+1)*sizeof(char**));
         strings[count]=(char*) malloc(sizeof(input)); 
         strcpy(strings[count],input);
         count++;
   } while (strcmp(input,"end")!=0);
   printf("\n");
   for (n=0;n<count;n++){
       printf ("entered: %s \n",strings[n]);
       free(strings[n]);
   }
   free(strings);
   return 0;
}

MarkusRechberger/SourceCode (zuletzt geändert am 2007-12-23 22:47:51 durch localhost)