Need assistance modifying php script

I have the following php script, from a wiki, on a Linux box that needs modification in order to work:


exec('cat /var/log/suricata/fast.log | grep "`date -d "-1 minute" "+%b %e %H:%M"`"',$lastMin); foreach($lastMin as $line) {

       if (strpos($line,"Priority: 1")!==FALSE || strpos($line,"Misc Attack")!==FALSE)
                       preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $line, $matches);
                       if (!in_array($filter, $blocked))
                               if (strpos($filter,"10.10.")!==FALSE) continue; //Protected space
			       if (strpos($filter,"64.8.")!==FALSE) continue; //Protected space
                               sendMikrotik('', 'raymond', 'password',$filter);   // Mikrotik 1

} function sendMikrotik($mt,$user,$pass,$filter) { $connection = ssh2_connect($mt); ssh2_auth_password($connection,$user,$pass); sleep(1); $stream = ssh2_exec($connection, ':global ip '.$filter); $stream = ssh2_exec($connection, '/system script run filter'); $stream = ssh2_exec($connection, 'quit'); } 

Open in new window

The script is to make a connection to my firewall and provide a list of IPs that should be blocked, based on strings it finds in a log file.

When I connect to the firewall manually, via ssh, I connect with the following command:

ssh -i /home/raymond/.ssh/id_dsa raymond@ (supply password manually)

I need to duplicate this process via the script.

I am not sure that ssh2_exec or ssh_auth_password are available; at least I could not locate them.

I am not skilled in scripting or php, so simple instructions would be appreciated.
Who is Participating?
That's based on a PECL package.

Once you add the package, you'll have access to those ssh2_ commands.
tamray_techAuthor Commented:
OK... Got that installed:
https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip,, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp

How do I modify the ssh2 commands to connect via:
ssh -i /home/raymond/.ssh/id_dsa raymond@
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.