$swiftdata['smtp'] = array(); $swiftdata['smtp']['host'] = 'mail.example.com'; $swiftdata['smtp']['port'] = '25'; $swiftdata['smtp']['username'] = '******'; $swiftdata['smtp']['password'] = '******'; $swiftdata['from'] = array('name' => 'Absender', 'email' => '*****@*****.**'); $swiftdata['to'] = array('name' => 'Empfänger', 'email' => '*****@*****.**'); ## end Configuration swiftmailer ## require_once dirname(__FILE__) . '/../src/Robo47/DirectoryHasher/Autoloader.php'; Robo47_DirectoryHasher_Autoloader::register(); require_once dirname(__FILE__) . '/swiftmailer/lib/swift_required.php'; if (!file_exists($outputdirectory)) { mkdir($outputdirectory); } create_new_resultfile($directory, $outputdirectory); $differences = check_differences($outputdirectory . '/old.xml', $outputdirectory . '/new.xml'); if (count($differences) > 0) { dh_send_info_mail($swiftdata, $differences); } /** * @param string $directory * @param string $outputfile */ function create_new_resultfile($directory, $outputdirectory) { $writer = new Robo47_DirectoryHasher_Writer_File_Xml(); if (file_exists($outputdirectory . '/new.xml')) { if (file_exists($outputdirectory . '/old.xml')) { rename($outputdirectory . '/old.xml', $outputdirectory . '/old-' . date('m.d.Y-h-i') . '.xml'); } rename($outputdirectory . '/new.xml', $outputdirectory . '/old.xml');
// --------------- Testing presence of file if (authorized_key_exist($identity_name, $account_name, $hostname, "{$homedir}/.ssh/authorized_keys") == 0) { archive_authorized_key_file($identity_name, $account_name, $hostname, "{$homedir}/.ssh/authorized_keys"); get_local_copy_authorized_key_file($identity_name, $account_name, $hostname, "{$homedir}/.ssh/authorized_keys"); } else { // We create an empty file so check_differences will have 2 files to compare. $command = "touch /tmp/authorized_keys-{$hostname}-{$account_name}"; exec($command, $output, $exit_status); } // ------------------- Construction authorized_keys_file ------------------ echo "<fieldset class=cmdok><legend class=cmdok>Constructing securities for {$account_name} on host {$hostname}</legend>\n"; $output = prepare_authorizedkey_file($id, $id_account); echo "{$output}\n"; echo "</fieldset>"; push_authorized_key_file($identity_name, $account_name, $hostname, "{$homedir}/.ssh/authorized_keys"); $diff_result = check_differences($account_name, $hostname); } } echo "</fieldset>"; echo "<a href='host-view.php?id_hostgroup={$id_group}#{$id}'><img src='images/arrowbright.gif> Return to {$hostname}</a>\n"; // We send an email to all users who have an account $mailheader = "From: SKM <" . $admin_email . ">\nX-Mailer: Reminder\nContent-Type: text/html"; $emailuser = $admin_email; $message = "Deploying {$account_name} to {$hostname}"; $message = "User " . $_SESSION['SESS_FIRST_NAME'] . " " . $_SESSION['SESS_LAST_NAME'] . " has deployed account {$account_name} to host {$hostname}\nHere is what was changed :\n{$diff_result}"; #mail("$emailuser","SKM: Deploying SSH-Key from $account_name to $hostname.","$message","$mailheader") or die("Could not send mail..."); // ------------------- Removing private key from filesystems ------------------ unlink("/tmp/{$identity_name}-id") or die("ATTENTION : Private key file /tmp/" . $identity_name . "-id could not be deleted"); unlink("/tmp/authorized_keys-{$hostname}-{$account_name}") or die("ATTENTION : file /tmp/" . $identity_name . "-" . $hostname . "-" . $account_name . " could not be deleted"); unlink("/tmp/authorized_keys") or die("ATTENTION : Private key file /tmp/authorized_keys could not be deleted"); ?>