Basic IMAP Updater

Signed-off-by: Samuel Denis-D'Ortun <sam@sddproductions.com>
This commit is contained in:
Samuel Denis-D'Ortun 2014-06-18 22:48:27 -04:00
parent abfc38178a
commit b1c96cabcd
2 changed files with 95 additions and 0 deletions

View File

@ -154,6 +154,7 @@ $sm_lang = array(
'error_server_ip_bad_length' => 'The domain / IP must be between 1 and 255 characters.',
'error_server_ip_bad_service' => 'The IP address is not valid.',
'error_server_ip_bad_website' => 'The website URL is not valid.',
'error_server_ip_bad_imap' => 'The IMAP URL need to be in format imap://username:password@hostname/options ',
'error_server_type_invalid' => 'The selected server type is invalid.',
'error_server_warning_threshold_invalid' => 'The warning threshold must be a valid integer greater than 0.',
),

View File

@ -0,0 +1,94 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Samuel Denis-D'Ortun <sam@sddproductions.com>
* @copyright Copyright (c) 2014 Samuel Denis-D'Ortun <sam@sddproductions.com>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
**/
namespace psm\Util\Updater\Types;
require_once 'AbstractUpdater.php';
use psm\Service\Database;
use psm\Util\Updater;
class ImapUpdater extends AbstractUpdater
{
public function GetIcon(){
return 'icon-globe';
}
public function ValidateIP($ip)
{
// make sure websites start with http://
if(substr($ip, 0, 7) != 'imap://') {
throw new \InvalidArgumentException('server_ip_bad_imap');
}
if(!filter_var($ip, FILTER_VALIDATE_URL)) {
throw new \InvalidArgumentException('server_ip_bad_imap');
}
}
/**
* Check the current server as a IMAP Server
*
* Allow to open connections to IMAP server.
*
* IP must be provided in a URL encoded string (See PHP imap_open())
* - imap://user:pass@domain.com/OPTIONS
*
* When host require full email address, replace the @ with %40 in the user field.
* - imap://mailbox%40domain.com:mypassword@domain.com/novalidate-cert
*
* @param array $server
* @return boolean
*/
public function Update($server) {
$this->StartRun();
$url = parse_url($server['ip']);
imap_errors(); // clean error list
$stream = @imap_open( '{' . $url['host'] . $url['path'] . '}' ,urldecode( $url['user'] ) ,urldecode($url['pass']) , OP_HALFOPEN );
if($stream === false)
{
$errors = @imap_errors() ;
$this->SetError( implode(" ; " , $errors));
}
else
imap_close($stream);
$result = ($stream !== false) ? true: false;
$this->StopRun();
return $result;
}
}