Skip to content

Commit

Permalink
Merge pull request #1 from antonraharja/reseller-mods
Browse files Browse the repository at this point in the history
Reseller mods
  • Loading branch information
antonraharja committed May 14, 2014
2 parents 974a91e + 267b99c commit 175cb88
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions web/plugin/feature/email2sms/fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
function email2sms_hook_playsmsd() {
global $core_config;

$now = mktime();

// fetch every 60 seconds
$last_loop = core_playsmsd_last_loop();
$next = floor(($last_loop / 60)) * 60 + 60;
$now = mktime();
$next = floor(($now / 60)) * 60 + 60;

if ($now < $next) {
return;
Expand All @@ -29,17 +27,17 @@ function email2sms_hook_playsmsd() {
$username = $items['features']['email2sms']['username'];
$password = $items['features']['email2sms']['password'];

if ($protocol && $port && $server && $username && $password) {
_log('fetch uid:' . $uid, 3, 'email2sms_hook_playsmsd');
} else {
if (! ($protocol && $port && $server && $username && $password)) {
continue;
}

//_log('fetch uid:' . $uid, 3, 'email2sms_hook_playsmsd');

$param = 'email2sms_uid_' . $uid;
$is_fetching = (playsmsd_pid_get($param) ? TRUE : FALSE);
if (!$is_fetching) {
$RUN_THIS = "nohup " . $core_config['daemon']['PLAYSMS_BIN'] . "/playsmsd playsmsd once " . $param . " >/dev/null 2>&1 &";
_log('execute:' . $RUN_THIS, 3, 'email2sms_hook_playsmsd');
//_log('execute:' . $RUN_THIS, 3, 'email2sms_hook_playsmsd');
shell_exec($RUN_THIS);
}
}
Expand All @@ -54,7 +52,7 @@ function email2sms_hook_playsmsd_once($param) {
}
}

_log('fetch uid:' . $uid, 3, 'email2sms_hook_playsmsd_once');
//_log('fetch uid:' . $uid, 3, 'email2sms_hook_playsmsd_once');

if ($uid) {

Expand All @@ -66,14 +64,14 @@ function email2sms_hook_playsmsd_once($param) {
$hostname = '{' . $items['features']['email2sms']['server'] . ':' . $items['features']['email2sms']['port'] . '/' . $items['features']['email2sms']['protocol'] . $ssl . $novalidate_cert . '}INBOX';
$username = $items['features']['email2sms']['username'];
$password = $items['features']['email2sms']['password'];
_log('fetch ' . $username . ' at ' . $hostname, 3, 'email2sms_hook_playsmsd_once');
//_log('fetch ' . $username . ' at ' . $hostname, 3, 'email2sms_hook_playsmsd_once');

$inbox = imap_open($hostname, $username, $password);

if (!$inbox) {
$errors = imap_errors();
foreach ($errors as $error) {
_log('error:' . $error, 3, 'email2sms_hook_playsmsd_once');
//_log('error:' . $error, 3, 'email2sms_hook_playsmsd_once');
}
return;
}
Expand All @@ -86,13 +84,14 @@ function email2sms_hook_playsmsd_once($param) {
$email_subject = trim($overview[0]->subject);
$email_sender = trim($overview[0]->from);
$email_body = trim(imap_fetchbody($inbox, $email_number, 1));
_log('email from:[' . $email_sender . '] subject:[' . $email_subject . '] body:[' . $email_body . ']', 3, 'email2sms_hook_playsmsd');
//_log('email from:[' . $email_sender . '] subject:[' . $email_subject . '] body:[' . $email_body . ']', 3, 'email2sms_hook_playsmsd');

$sms_to = explode(',', $email_subject);
$message = preg_replace('/--[\r\n]+.*/s', '', $email_body);

$username = user_uid2username($uid);
if ($username && count($sms_to) && $message) {
_log('email2sms username:'.$username, 3, 'email2sms_hook_playsmsd_once');
sendsms($username, $sms_to, $message);
}
}
Expand Down

0 comments on commit 175cb88

Please sign in to comment.