Dirty mail.log parser

Simple dirty script about parsing mail.log for bad emails,
I didn’t parse multi line because i don’t need to get who send the email, only to whom it is failed, performance is not so bad, 8.4 GB mail.log file, in virtual machine it take 2m 23sec.

<?php
error_reporting(E_ALL);
$filename = '/var/log/mail.log';
$pattern = '/to=<((?:"[^"]+"@|[^<]+@)[^>]+)>/S';

$bademails = array();
$file_handle = fopen($filename, "r");
while (! feof($file_handle)) {
	$line = fgets($file_handle);
	if (strpos($line, 'dsn=5') !== False) {
		$matches = null;
		if (preg_match($pattern, $line, $matches) != 0) {
			if (!in_array($matches[1], $bademails)) {
				array_push($bademails, $matches[1]);
			//	echo $matches[1] . "\n";
			}
		}
	}
}
fclose($file_handle);
echo count($bademails);

Karma

April 29th, 2012 No comments

I was not believe on karma, or somethings like that. But now i started to believe. I don’t like to think bad about persons and that is all. Everything is happening for a reason. If you try to not do mistakes to others and not think bad about things, when something bad happen, it protects you from more bad, or give you more good. Just you see this in time.

Categories: General Tags: ,

Bind dns_rdata_fromtext ran out of space

April 8th, 2012 No comments

Probably you made domainkey bits bigger then 1024 bit.
Bind not allow more than 255 character in one string constant.
You need to split TXT define with ”

For example

selector1._domainkey IN TXT "k=rsa; p=MIIBIjANBgkq" "hkiG9w0BAQEFAAOCAQ8A.."

you can split bind TXT record like that.

PS: Gmail also use their dkim key in that way.

MacosX Snow Leopard some tweak

April 3rd, 2012 No comments

Opening Safari Webkit Developer Extras

defaults write com.apple.Safari WebKitDeveloperExtras -bool true

Showing Hidden Applications at Dock

defaults write com.apple.Dock showhidden -bool YES

And my two favorite:
Making Finder closeable

defaults write com.apple.finder QuitMenuItem -bool YES

Close spotlight indexing

sudo mdutil -a -i off

Macosx Terminal key bindings

April 3rd, 2012 No comments

Recently I was use iTerm as terminal, until today. I reinstalled Macosx snow leopard today. (if you ask why not lion, at everywhere it written as shorter battery time). I wanted to give snow leopard terminal a try. It went good until now with only minor problems.

One of the problem is keybindings.

Standart terminal “home” “pageup” “pagedown” and “end” is act differently at Macosx Terminal. That keys work like shift pageup and shift pagedown.
and the quite opposite, shift home and shift pageup works like home and pageup at iTerm.

If you want standart behaviour;

just add key codes to Terminal

Home \033[1~
End \033[4~
Page Up \033[5~
Page Down \033[6~

and correct shift versions with scrolling buffers.

I always love pointer arithmetic and optimization

December 27th, 2011 No comments
function TDarkStream.ReadStringUntilChars(const chars: TSysCharSet
  ): AnsiString;
var
  P, PE: PChar;
begin
  P := fMemory + fRealPosition;
  PE := fMemory + fRealSize - 1;

  while (P<=PE) and not (P^ in chars) do
    inc(P);

  Result := ReadString(Cardinal(P) - Cardinal(fMemory + fRealPosition));
  if fRealPosition < fRealSize then
    fRealPosition := fRealPosition + 1;
end;

Categories: Programming Tags: ,

Hexdump , what is annoying me.

December 24th, 2011 No comments

When using pointers, i like to see what happen when coding.. I believe a lot of programmer (which working on pointers) also love to work that way. But what really annoying me start at that point. Hexdump.

I don’t have any idea of why the people who make this standard of hex dump, i first saw this at PcTools at DOS at 1992, but one way or another people continue that way of formatting.

00000000  48 54 54 50 2f 31 2e 30  20 32 30 30 20 43 6f 6e HTTP/1.0  200 Con
00000010  6e 65 63 74 69 6f 6e 20  65 73 74 61 62 6c 69 73 nection  establis
00000020  68 65 64 0d 0a 0d 0a                             hed....

annoying part for me is, I really like to see that damned data when debug, yes it also shown at this. but I don’t have any idea of which character is which ASCII. I am NOT smart enough to remember all ASCII character’s hexadecimal values.

and when you start to debug, you are starting to count. (that start at 10, so that hex value must be 14.  then looking it’s hexadecimal value). Doing that for almost 100 times at least really annoys me.

Another problem was in DOS times, our codes was work at real memory. not a protected virtual memory. so showing address in hex can be understandable.

But now ? I use decimal values when doing memory walking not hex! We use flat memory model in codes. mostly can be done is writing pointer memory address. and it can be use only for compare values and it can be done in decimal too. :)

And when my feelings changed to hate from annoy. I changed to hexdump format to this way at my codes.

00000000  48 54 54 50 2f 31 2e 30    20 32 30 30 20 43 6f 6e
           H  T  T  P  /  1  .  0        2  0  0     C  o  n

00000016  6e 65 63 74 69 6f 6e 20    65 73 74 61 62 6c 69 73
           n  e  c  t  i  o  n        e  s  t  a  b  l  i  s

00000032  68 65 64 0d 0a 0d 0a
           h  e  d  .  .  .  .

Yes, I don’t care about row count because I can use less, more, most, shift PageUp. any pager or console help me at it.

And code example:


function csHexDump(const adata: Pointer; datalen: Cardinal;
                 showAddress: Boolean = True; startAt: Cardinal = 0;
                 oldStyle: Boolean = False): AnsiString;
Var
     _Address: ShortString;
     _Dump: ShortString;
     _Ansi: ShortString;
     X, I, J: Integer;
Begin
  Result := '';
  if showAddress then
    _Address := Format( '%.10U:', [ Cardinal( AData ) + startAt ] )
  else
    _Address := Format( '%.6U:', [0] );
  _Dump := '';
  _Ansi := '';

  if not oldStyle then
    for j := 0 to Length(_Address) - 1 do
      _Ansi := _Ansi + ' ';

  For I := 0 To datalen - (startAt) - 1 Do
  Begin
      _Dump := _Dump + Format( '%3.2x', [Byte((pChar( AData ) + I + StartAt)^ )]);

      if oldStyle then
        If Byte( ( pChar( AData ) + I + startAt)^ ) >= 31 Then
        begin
          _Ansi := _Ansi + Char( ( pChar( AData ) + I + startAt)^ );
        end else
             _Ansi := _Ansi + '.';

      if not oldStyle then
        If Byte( ( pChar( AData ) + I  + startAt)^ ) >= 31 Then
          _Ansi := _Ansi + Format( '%3.2S', [Char((pChar( AData )+I+startAt)^)])
        else
          _Ansi := _Ansi + Format( '%3.2S', ['.'] );

      If ( Cardinal( AData ) + I ) Mod 16 = 7 Then _Dump := _Dump + ' |';
      if not oldStyle then
        If ( Cardinal( AData ) + I ) Mod 16 = 7 Then _Ansi := _Ansi + '  ';

      If ( Cardinal( AData ) + I ) Mod 16 = 15 Then
      Begin
           For X := Length( _Dump ) + 1 To 50 Do _Dump := ' ' + _Dump;
           For X := Length( _Ansi ) + 1 To 16 Do _Ansi := ' ' + _Ansi;

           if oldStyle then
             Result := Result + _Address + _Dump + ' | ' + _Ansi + #13#10
           else
             Result := Result + _Address + _Dump + #13#10 + _Ansi + #13#10;

           if showAddress then
             _Address := Format( '%.10U:', [ Cardinal( AData ) + I + startAt + 1 ] )
           else
             _Address := Format( '%.6U:', [ I + 1 ] );
           _Dump := '';
           _Ansi := '';

            if not oldStyle then
              for j := 0 to Length(_Address) - 1 do
                _Ansi := _Ansi + ' ';
      End;
  End;

  if Length(_Dump) > 0 then
    For X := Length( _Dump ) + 1 To 50 Do _Dump := _Dump + ' ';

  if oldStyle then
    if (_Dump <> '') then
      Result := Result + _Address + _Dump + ' | ' + _Ansi + #13#10;

  if not oldStyle then
    if (_Dump <> '') then
      Result := Result + _Address + _Dump + #13#10 + _Ansi + #13#10;

end;

How a Programmer reads your resume?

December 3rd, 2011 1 comment

Categories: Programming Tags: ,

Colon has a great idea

September 17th, 2011 No comments

colon has a great idea

Categories: General Tags: ,

postalias: fatal: open database /etc/aliases.db: Permission denied

September 13th, 2011 No comments

postalias: fatal: open database /etc/aliases.db: Permission denied

Fixation:

if you see that error at newaliases or postfix installs, possibly removing postfix also will not solve the problem.
control your /etc/aliases file is owned by root:root