ISPConfig 3, SquirrelMail Account checker...

Discussion in 'Tips/Tricks/Mods' started by BorderAmigos, Jul 12, 2010.

  1. BorderAmigos

    BorderAmigos New Member

    If you use a lot of different email addresses in your business it can be a pain to check them all. I wrote this little script that will check all of the accounts listed in the $userIDs array. I have it on a Drupal page so if you want to run it standalone you may want to add the head, body, et cetera, to the html output.

    Note that the passwords are visible in the generated source code so access to this page should be authenticated somehow. For me it is an admin only page in Drupal. With it I can tell at a glance if any of 80 email accounts has mail. Clicking on the account opens and logs in automatically. Remember to log out though.

    Code:
    <?php
    
    // array of "usernames:passwords", should be on same server.
    $userIDs=array(
    "[email protected]:Password123",
    "[email protected]:Password456",
    //  As many as you want...
    "[email protected]:Password789"
    );
    
    $refresh='900';  // in seconds
    $server='http://mail.'.$_SERVER["SERVER_NAME"];  // or IP address
    $pageURL='http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];  
    
    // The php headers function gives some errors in Drupal, meta doesn't
    $output='<meta http-equiv="refresh" content="'.$refresh.';url='.$pageURL.'">';
    
    $output .= '<script language="JavaScript" type="text/javascript">';
    $output .= '<!--';
    $output .= 'function squirrelmail_loginpage_onload() {';
    $output .= 'document.forms[0].js_autodetect_results.value = \'1\';';
    $output .= 'for (i = 0; i < document.forms[0].elements.length; i++) {';
    $output .= 'if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "password") {';
    $output .= 'document.forms[0].elements[i].focus();';
    $output .= 'break;';
    $output .= '}}}';
    $output .= '// -->';
    $output .= '</script>';
    
    $output .= '<span style="font-size:2em;font-weight:bold;">'.date("D F d Y H:i:s",time()).'</span><br><br>';
    $output .= '<form><input type="button" value="Back" onClick="history.go(-1);return true;"><input type="button" value="Refresh" onClick="location.reload(true);"></form><br>';
    $output .= '<div onload="squirrelmail_loginpage_onload()" class="mailboxes" style"float:none;clear:both;">';
    $output .= '<span display="inline">';
    foreach ($userIDs as $userID) 
    {
    	$temp=explode(':',$userID);
    	$address=$temp[0];
    	$password=$temp[1];
    	$imap = imap_open("{127.0.0.1:110/pop3/notls}INBOX", $address, $password);
    	$info = imap_check($imap);
    	$msgColor=($info->Nmsgs)?'color:#cc0000;':'color:#0000cc;';
    	$msgColor.='background-color:#ffffff;';
    	$output .=  '
    	<form method="post" action="'.$server.'/webmail/src/redirect.php" target="_blank" style="margin:5px;float:left;">
    		<input type="hidden" name="js_autodetect_results" value="0"><input type="hidden" name="just_logged_in" value="1">
    		<input type="hidden" name="secretkey" size="10" value="'.$password.'">
    		<input type="hidden" name="login_username" value="'.$address.'">
    		<input type="submit" name="username" style="'.$msgColor.'height:20px;width:250px;text-align:right;font-size:0.85em;" value="'.$address.'&nbsp;&nbsp;('.$info->Nmsgs.')"> 
    	</form>';
    	imap_close($imap);
    }
    $output .= '</span></div>';
    $output .= '<p style="float:none;clear:both;">&nbsp;</p>';
    $output .= '<form><input type="button" value="Back" onClick="history.go(-1);return true;"><input type="button" value="Refresh" onClick="location.reload(true);"></form>';
    print $output;
    ?>
    
     
    Last edited: Jul 12, 2010

Share This Page