Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //exit();
- $email = "your@email.tld";
- $fromEmail = "from@email.tld";
- $filename = "/tmp/login.".time().".temp";
- exec("cat /var/log/auth.log | grep 'Accepted password for ' > ".$filename);
- $file = file_get_contents($filename);
- $last = trim(file_get_contents('/tmp/lastlog.log'));
- $file = explode("\n",$file);
- $i = 0;
- $proccess = 0;
- foreach ($file as $k => $v) {
- if ($proccess == 1) {
- $v2 = explode($findme, $v);
- $ex = explode(" ",$v2[1]);
- $login[$i]['ip'] = $ex[2];
- $login[$i]['user'] = $ex[0];
- $login[$i]['line'] = $v;
- $i++;
- }
- if (trim($v) == $last) {
- $proccess = 1;
- }
- }
- //var_dump($blline);
- $line = $login[($i-1)]['line'];
- if ($line) {
- file_put_contents("/tmp/lastlog.log", $line);
- }
- foreach ($login as $k => $v) {
- /*foreach ($v['ip'] as $k2 => $v2) {
- $emailtext .= "Login from $v2 <br />\n";
- }*/
- $emailtext .= "Login:
- User: ".$login[$k]['user']."
- IP: ".$login[$k]['ip']."
- Hostname: ".gethostbyaddr($login[$k]['ip'])."
- Line: ".$login[$k]['line']."
- -----------------------------
- ";
- }
- //echo $emailtext;
- if ($i != 0) {
- mail($email, "SHH Login - ".date('G:i:s j/m/Y'), str_replace("\n", "<br />\n", $emailtext), "From: ".$fromEmail."\r\nContent-type: text/html; charset=iso-8859-1\r\n");
- }
- unlink($filename);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement