piektdiena, 2009. gada 10. jūlijs

Aerofoto no balticmaps.eu - skripts 1

Skripts, kas novelk ortofoto bildi vienai konkrētai vietai no balticmaps.eu piedāvātajām aerofotokartēm.

Lai darbotos, nepieciešams bash, wget un imagemagick.
Skriptam kā parametri ir jānorāda X un Y koordinātes pēc balticmaps.eu, vēlamais kartes nosaukums un kartes vienas malas izmērs kilometros.
X un Y koordinātes var iegūt arī no garuma un platuma grādiem, izmantojot proj4 utilītas. piem.
 echo 57.151101N  24.285018E  | cs2cs ??? 


Jāatceras gan, ka komanda "montage" spēj noēst ļoti daudz atmiņas, un jau kartes ģenerēšana ar izmēriem 12x12km ir ļoti resursietilpīga.

Un pats skripts:

#!/bin/bash
# Ortofoto vilkshanas skripts

# Pārbaudam argumentu skaitu - jābūt 3
if [ $# -lt 3 ]
then
echo -e "Jāievada 3 vai 4 argumenti - centra X un Y koordinātes, vēlamais kartes nosaukums un kartes garums(platums)km (jaadalaas ar 4) \\n, piemēram:\\n
bash karte2.sh 353300 6363319 Ventspils 8 \\n
uztaisīs Ventspils aerofoto karti ar 8x8km izmēriem "
exit
fi

# Solis ir 2km
SOLIS=2000

# Mazās bildes nosaukumam sākumā piekabināsim kārtas numuru, lai pēc tam vieglāk varētu kombinēt bildi.
# Vienkāršākais - sākas ar 101
NOS=101
centrsX=$1
centrsY=$2
nosaukums=$3
GaPl=$(($4/2)) 2>/dev/null
if [[ $GaPl == "" ]]
then
# minimālais kartes izmērs - 2x2 km
GaPl=1
fi

#Pārbaudam vai šāds fails jau ir uztaisīts, ja ir - pārsaucam, pieliekot datumu un laiku
if [ -f $nosaukums-map.jpg ]
then
echo Kartes fails ar šādu nosaukumu jau eksistē - pārvietojam to
mv $nosaukums-map.jpg $nosaukums-map-`date +%y%m%d-%H%M`.jpg
fi

tmpkartes=`mktemp -d ./tmp-$nosaukums.XXXXXXXX`

# Apalojam XY līdz veseliem 100 - tā labāk lasās no servera ?
centrsX=$((($centrsX+50)/100))00
centrsY=$((($centrsY+50)/100))00

## Funkcija, kas veic bildes vilkshanu un pārbauda, vai tā ir novilkta
function ortofoto {
echo velkam $X $Y $SOLIS $NOS
bilde=$tmpkartes/$NOS-$X-$Y
wget -q "http://maps.kartes.lv/kijs/server_scripts/orto/get_orto_foto.php?BBOX=$X,$Y,$(($X+$SOLIS)),$(($Y+$SOLIS))&WIDTH=$SOLIS&HEIGHT=$SOLIS&KIJS=BM45" -O $bilde.jpg || wget -q "http://maps.kartes.lv/kijs/server_scripts/orto/get_orto_foto.php?BBOX=$X,$Y,$(($X+$SOLIS)),$(($Y+$SOLIS))&WIDTH=$SOLIS&HEIGHT=$SOLIS&KIJS=BM45" -O $bilde.jpg
# Ja joprojaam bilde nav novilkta, tad meeginam no
if [[ `identify -format '%W%H' $bilde.jpg` != "$SOLIS$SOLIS" ]] 2>/dev/null ; then
# Uztaisam mazu nobiidi par 1 pikseli
rm $bilde.jpg 2>/dev/null
X=$(($X-1)) && Y=$(($Y-1))
wget -nv "http://maps.kartes.lv/kijs/server_scripts/orto/get_orto_foto.php?BBOX=$X,$Y,$(($X+$SOLIS)),$(($Y+$SOLIS))&WIDTH=$SOLIS&HEIGHT=$SOLIS&KIJS=BM45" -O $bilde-a.jpg
if [[ `identify -format '%W%H' $bilde-a.jpg` != "$SOLIS$SOLIS" ]] ; then
rm $bilde-a.jpg 2>/dev/null
wget -nv "http://maps.kartes.lv/kijs/server_scripts/orto/get_orto_foto.php?BBOX=$X,$Y,$(($X+$SOLIS)),$(($Y+$SOLIS))&WIDTH=$SOLIS&HEIGHT=$SOLIS&KIJS=BM45" -O $bilde-b.jpg
if [[ `identify -format '%W%H' $bilde-b.jpg` != "$SOLIS$SOLIS" ]] ; then
rm $bilde-b.jpg 2>/dev/null
# Izveidojam mazu bildes failu, kas nepieciešams tālākai bildes kopā komponēšanai
convert -size 10x10 xc:gray $bilde-c.jpg
fi
fi
fi
}

# Aprēķinam kreiso X koordināti
startX=$(($centrsX-$GaPl/2*$SOLIS))
# Aprēķinam augšējo Y koordināti
startY=$(($centrsY+$GaPl/2*$SOLIS))

# echo $startX $startY

# Velkam kartes - saakot no augšējā kreisā stūra
# visas mazo karshu apakseejaas Y koordinaates
for Y in `seq $(($startY-$SOLIS)) -$SOLIS $(($startY - $SOLIS*$GaPl))`
do

# visas mazo karshu kreisās X koordinātes
for X in `seq $startX $SOLIS $(($startX + $SOLIS*($GaPl-1)))` ; do
# nosuutam mazaas bildes datus kartes vilksanas f-jai
ortofoto $X $Y $SOLIS $NOS
NOS=$(($NOS+1))
done
done

# Montējam kopā failu
if which montage >/dev/null 2>/dev/null; then
montage -verbose -tile $GaPlx$GaPl -geometry $SOLISx$SOLIS $tmpkartes/*jpg ./$nosaukums-map.jpg
rm -r $tmpkartes
fi

ceturtdiena, 2009. gada 9. jūlijs

DNAT routing over second link

The problem:
  • You have 2 connnections to the Internet - A is the default link, B - secondary link.
  • You have hosts inside LAN which are DNAT'ed from B space IP addresses.
  • Provider A blocks IP addresses from B address space
  • on router you have DNAT'ed some hosts to LAN and SNAT'ed all outgoing IP addresses on A and B interfaces.
Although you have already build some ip routes un rules to answer to packets on exactly the same interfaces, where incoming connections occurs, the DNAT'ed LAN hosts routes all outgoing packets over default - A link with SNAT'ed addresses from B space.

To correct this, you should:
  • add corresponding iproute2 table (if not already exist)
  • mark all outgoing packets from specified LAN host(s) with iptables PREROUTING chain
  • add ip rule to route marked packets through specified table and gateway


## script - all other routes and configurations skipped
## you should add this only one time
# echo 200 bprovider >> /etc/iproute2/rt_tables
...
## add routes to B space and gateway - all in bprovider table
ip route add $B-NET dev $B-DEV src $B-IP table bprovider
ip route add default via $B-GW table bprovider

## add rule to answer all incoming connections to B space over B gateway
ip rule add from $B-IP table bprovider

## iptables part - DNAT incoming packets, SNAT outgoing packets, and mark LAN packets - only for B addresses.
## Only some http ports (80,443) are redirected to LAN host
...
iptables -t nat -A PREROUTING -d $B-IP -m multiport -p tcp --dports 80,443 -j DNAT --to $LAN_IP
iptables -t nat -A POSTROUTING -o $B-DEV -j SNAT --to-source $B-IP
iptables -t mangle -A PREROUTING -s $LAN_IP -j MARK --set-mark 99
...
## and finally - order marked packets to routed over B gateway
ip rule add fwmark 99 table bprovider

Some other approach with CONNMARK (don't tested yet): http://home.regit.org/?page_id=7

svētdiena, 2009. gada 5. jūlijs

Attēlu apstrāde ar imagemagick

Pāris skriptu, kā apstrādāt attēlu failus lielās direktorijās

Skripts, kas visiem attēliem faila nosaukumiem pieliek klāt datumu:

#!/bin/bash
for i in *jpg *JPG
do
# Izvelkam datumu no bildes
DATUMS=`identify -format '%[EXIF:DateTime]' $i | tr : _ | awk '{print $1}' `
# Ja datuma vērtība eksistē un bildes nosaukumā jau nau datums, tad pārsaucam bildi
if [[ -n $DATUMS && $i != $DATUMS* ]]
then
mv -v $i $DATUMS-$i
fi
done


Uzmanību Ubuntu lietotājiem: Dažās versijās ir bugs, kas neattēlo EXIF informāciju!
https://bugs.launchpad.net/ubuntu/+source/imagemagick/+bug/227631

ceturtdiena, 2009. gada 2. jūlijs

To enable routing on Ubuntu host

edit /etc/sysctl.conf or with sysctl -w

To allow forward packets
sysctl -w net.ipv4.ip_forward=1

To forward packets comming to "wrong" interfaces:
sysctl -w net.ipv4.conf.default.rp_filter=0
(filter is enabled by default)

pirmdiena, 2009. gada 26. janvāris

How to query Active Directory users from Linux to get password expire information

BASH script:



#!/bin/bash
#
DEXP=`date -d '+1week' +%s`
DNOW=`date +%s`
DVEC=`date -d '-1week' +%s`
SERV=winADserv
AUTHF=cred.txt

# Ielasama visus lietotajvardus
wbinfo -u | while read User
do

# Katram lietotaajam skatamies paroles expireeshanaas laiku
rpcclient -A $AUTHF -c "queryuser $User" $SERV | grep "Password must change Time" | cut -f 2- -d, | while read Datums
do
if [[ `date -d "$Datums" +%s` -le $DEXP ]] && [[ `date -d "$Datums" +%s` -ge $DVEC ]]
then
echo $User `date -d "$Datums" +%F`
fi
# echo -e $Datums\\t$User

done
done


ldapsearch script




LDAPDC="dc=skola,dc=example,dc=com"
LDAPCN="cn=Administrator,ou=Users,$LDAPDC"
LDAPPW=VerySecretAdminPassword
SERV=winADserv
WARNPWAGE=80days

ldapsearch -x -D "$CN" -w $LDAPPW -h $SERV -b $LDAPDC "(&(sAMAccountName=*)(objectClass=user)(pwdLastSet<=$((`date -d -$WARNPWAGE +%s`+11644473600))0000000)(pwdLastSet>=$((`date -d -100days +%s`+11644473600))0000000)(sAMAccountType=805306368))"| grep sAMAccountName

pirmdiena, 2008. gada 15. decembris

Iozone - Stende -> Server8 iscsi

Tests no STENDE uz BFSA - ar iscsi
 iozone -i0 -i1 -c -e -a -n 1g -g 16g -y 2048 -s 2048 -q 8192 


KB reclen write rewrite read reread
1048576 4096 27476 27449 91704 70380
2097152 4096 26775 26010 69460 68300
4194304 4096 26823 26338 60614 57342


Tests no Srv7 Ub810Jeos uz BFSA - ar iscsi

KB reclen write rewrite read reread
1048576 4096 26507 27016 68971 66816
2097152 4096 26448 27360 68377 67586
4194304 4096 26557 27959 60378 58767
8388608 4096 26098 26025 54164 54467
16777216 4096 26244 27713 54396 54254

ceturtdiena, 2008. gada 31. jūlijs

ISCSI testi

initiator: Win2003 VMWare serveris (4GB RAM)
target: Ubuntu 8.04 ar HW RAID5
tīkls: HP 2824 Gigabit switch


iozone.exe -a -c -n 1g -g 8g -y 2048 -i0 -i1 -i2 -f h:\iotest
random random
KB reclen write rewrite read reread read write
8388608 16384 9385 9639 47135 48333 41887 8881