ponedjeljak, 14. ožujka 2011.

PHP: verifying username and password with LDAP

here is a simple example how you can verify username and password with ldap


        $ldaphost = "aai.host.com";
        $ldapport = 389;
        $ldapconfig['basedn'] = 'dc=host,dc=com';

        $ds = ldap_connect($ldaphost, $ldapport)
        or die("Could not connect to $ldaphost");
        if ($ds)
        {
                $username = mysql_real_escape_string($_POST["user"]);
                $upasswd = mysql_real_escape_string($_POST["pass"]);
$dn="uid=".$username.",".$ldapconfig['basedn'];
                $ldapbind = @ldap_bind($ds, $dn, $upasswd);
                if ($ldapbind) {
$ok=true;
echo "Password OK!<br>";
} else {
echo "Password invalid!<br>";
$ok=false;
exit();
}
}


subota, 12. ožujka 2011.

PoE (Power over ethernet) with Mikrotik Routerboards

If you want to connect your RB411, RB433, RB711Hn or any other routerboard that has POE enabled on it ports, and do not want to buy PoE injectors, this is how you can connect it if you have power supply with 12V or any other that is specified for your device.

NOTE! This is only for simple 100 mb PoE, not for IEEE 802.3af devices! They need special electronics that negotiate with 802.3af injectors.

100 MB ethernet uses only 4 wires out of 8 wires that are in standard ethernet cable. There are 4 pairs of wires and they are orange, green, blue and brown. For T-568B Straight-Through Ethernet Cable you use wiring like this:

In 100MB ethernet, blue, blue-white, brown and brown-white are not used, so they can be used to transfer power to device. For routerboards, blue wires are positive and brown wires are negative.

So how do you connect?
You crimp your cable like on picture above (using T-568B standard) and near place you want to connect power adapter you remove the insulation (only the outer white layer that are around all wires) and cut blue and brown wires. Then you remove the insulation from them, but only on ones that are going to your routerboard, and connect blue and blue-white together, and brown and brown-white together. Then you cut connector from your power supply and measure what is positive and what is negative wire. You can do that by using voltmeter(place range to 20V or more DC-direct current, black wire to ground, red wire to voltage measurement) and placing one wire on black and another on red wire. If your voltmeter show +12 or any other voltage, then connect wire that was on black wire to brown and from red wire to blue. On the other hand, if your voltmeter shown -12V then you should do the opposite: wire that was connected to red connect to brown wires, and wire that was connected to black connect to blue wires.

Here is how I connected to my computer. I used +12V from my computer as power supply from molex connector:

Here you see orange and green wires go to connector and other 4 wires go to molex connector connected to my power supply.Other end of UTP is connected to routerboard 411, crimped as shown in first picture.

Connecting optical sensors to microcontroller

My task was to make instrumentation for measuring speed of reaction and speed for crossing two points in space. I used 2 optical sensors that I had laying around and connected them through relays to microcontroller. As microcontroller I used Atmel ATMEGA16 and some development kit i bought on Ebay. As output I used RS232 to send data.

Biggest problem was with sensors that I have no specifications and could not find them on internet. There are 3 wires, one black, one blue and one brown. On sensor is only specification that black and blue are power wires (I connected them to 12V DC) and brown is output. So I decided to use relay.

Fig 1: Atmega16 connected with optical sensor through relay

Note: maybe for your application you will need to use pull-up resistor.I think you can use 10K and connect it to VCC(5V) of Atmega and to that pin.

petak, 11. ožujka 2011.

How to fix “STOP: c000021a (Fatal System Error)” Error!” in windows XP

If you have blue screen and this error:

STOP: c000021a {Fatal System Error}
The Windows Logon Process system process terminated unexpectedly with a status of 0xc06d007e (0×00000000 0×00000000).
The system has been shut down.



when you boot your Windows xp, here is a solution how to resolve the error.

0) Copy c:\windows\system32\winlogon.exe from working Windows XP (use Windows xp with same service pack) to your usb drive
1) Boot your computer with some live cd (I used Windows XP Live!)
2) make copy or rename your winlogon.exe file (I renamed it to winlogon.exeold)
3) copy winlogon.exe from usb drive to your \windows\system32\ directory
4) boot windows

if everything is ok, then that is it, however, in my case computer booted, but explorer was not working so used system restore.

5) when Windows loads, go to task manager (with ctrl+alt+delete or ctrl+shift+esc) and run System restore by going to File, Run, and c:\windows\system32\restore\rstrui.exe

Then restore to some old restore point...and thats it :)
p.s. maybe you will need to run

sfc.exe /scannow
to check your system files.

PHP, mysql, html, css and coloring every other row

I stumbled upon interesting problem, where I wanted to color every second column with specific color.
Problem was that I had css defined, so the php code did not work correctly:

if (($i % 2)==0) { echo '<tr BGCOLOR="#99CCFF" >'; } else { echo '<tr BGCOLOR="#FFFFFF" >'; };


so I changed it to something like this:

if (($i % 2)==0) { echo '<tr style="background-color:blue" >'; } else { echo '<tr style="background-color:white" >'; }; 

And it works :)

I am also posting here whole example:


$query2="SELECT * FROM participant,submitted,section,status_work WHERE submitted.id_section=section.id_section AND submitted.id_status=status_work.id_status AND participant.id_part=submitted.id_participant";
$result2=mysql_query($query2);
$num2=mysql_num_rows($result2);
if ($num2>0){
echo '<table class="X1">';
for ($i=0;$i<$num2;$i++){
if (($i % 2)==0) { echo '<tr style="background-color:blue" >'; } else { echo '<tr style="background-color:white" >'; };
echo "<td>".($i+1)."</td>";
echo "<td>".mysql_result($result2, $i, 'first')." ".mysql_result($result2, $i, 'last')."</td>";
echo "<td>".mysql_result($result2, $i, 'section.value')."</td>";
echo "</tr>"; }
echo "</table>";
}

linux (debian) problem with sending mail

I had some issues with sending mail through my mail server. It is debian distribution, and some users got error mails return to them. This is what they got back:


This is the mail system at host sportikus.kif.hr.
I'm sorry to have to inform you that your message could notbe delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You candelete your own text from the attached returned message.
                   The mail system
<xxxxxx@brugger.at>: host mail.brugger.at[213.229.60.100] said:    550-Inconsistent or no rDNS record for 161.53.51.3 (see RFC1912 2.1)    550-http://www.ietf.org/rfc/rfc1912.txt 550-Reverse DNS record and matching    forward entry must exist. 550 => wrong configuration at sending server    161.53.51.3 (in reply to RCPT TO command)



This was obviously error in dns configuration, specifically in reverse dns. So I edited hosts.rev changed serial number (just +1) and added one line to the end of that file:


3       PTR   sportikus.kif.hr.

 and reloaded the configuration with

rndc reload
Note that number 3 is the ip address of the server.

And that was it! :)

Hello world!

Hi to all...
This is my first blog, and here I will present some things I do, and show you how you can do it. Also, as system administrator I stumble upon some interesting problems, so if I manage to resolve them, I will write the solution here :)