Ticket #250 (reopened Bug report)

Opened 14 years ago

Last modified 12 years ago

Problem with mail translation in cron/page.php

Reported by: Kim Tae Doo Owned by:
Priority: low Milestone:
Component: Auth server, Other Version:
Keywords: Cc:

Description

I executing cron/page.php method.

But it doesn't sending E-mail.

I checking this program, this php program running timezone in 'Canada/Eastern?'.(My servers local.config.php's DATE_TIMEZONE is 'Asia/Tokyo?'.)

It moved normally when this was added to this command in the 52nd line.

date_default_timezone_set('Asia/Tokyo?');

I don't know, why this program can't get DATE_TIMEZONE, and how was generaly if it write. But I think, any server using in another timezone, it doesn't move normaly.

(My Servers timezone is JST +09:00. So this program sending down time reporting at 13th hours later ;-)

Please continue your favors toward correspondence.

Change History

Changed 14 years ago by Kim Tae Doo

Incidently, the Node Status Report's [Last heartbeat] item output too Strange value.(It printing about -46777)

Is not the DATE_TIMEZONE taken by all programs?

Changed 14 years ago by benoitg

DATE_TIMEZONE is only used for PHP >= 5.1. The function date_default_timezone_set didn't exist before PHP 5.1, so I guess you are running that. But the page.php script should take it into account (it includes common.php).

You are saying that mail was sent normally when you added the date_default_timezone_set('Asia/Tokyo?') to page.php?

Changed 14 years ago by Kim Tae Doo

I knew date_default_timezone_set function calling in common.php.
And my server's page.php is requiring common.php.
But DATE_TIMEZONE was different setting.

I testing default page.php in [echo date("O",time())."\n";]
It's result output display at [-0400].
'Asia/Tokyo?' is +0900.
-0400 is 'Canada/Eastern?', isn's it?

I past on my changed page.php and local.config.php's Timezone setting.

I'm changing only 2 point.

1st. Adding [date_default_timezone_set('Asia/Tokyo?');]

2nd. Changing message.
It was I puting Japanese string message in smarty's message.po.
But page.php sending message was only English.
I think it can't using smarty, that's page.php is calling on cron, no calling by apache.
So I'm hard cording in Japanese message.

<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

// +-------------------------------------------------------------------+
// | WiFiDog Authentication Server                                     |
// | =============================                                     |
// |                                                                   |
// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
// | portal suite.                                                     |
// +-------------------------------------------------------------------+
// | PHP version 5 required.                                           |
// +-------------------------------------------------------------------+
// | Homepage:     http://www.wifidog.org/                             |
// | Source Forge: http://sourceforge.net/projects/wifidog/            |
// +-------------------------------------------------------------------+
// | This program 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 2 of    |
// | the License, or (at your option) any later version.               |
// |                                                                   |
// | This program 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 this program; if not, contact:                         |
// |                                                                   |
// | Free Software Foundation           Voice:  +1-617-542-5942        |
// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
// |                                                                   |
// +-------------------------------------------------------------------+

/**
 * @package    WiFiDogAuthServer
 * @author     Philippe April
 * @copyright  2005-2006 Philippe April
 * @version    Subversion $Id: page.php 1042 2006-05-20 20:28:27Z benoitg $
 * @link       http://www.wifidog.org/
 */

/**
 * Load required files
 */

require_once(dirname(__FILE__) . '/../include/common.php');

require_once('classes/Network.php');
require_once('classes/Node.php');
date_default_timezone_set('Asia/Tokyo');

function page_if_down_since($nodeObject, $minutes) {
    $last_heartbeat = strtotime($nodeObject->getLastHeartbeatTimestamp());

    if (time() - $last_heartbeat > 60*$minutes ) {
        $lastPaged = strtotime($nodeObject->getLastPaged());
        if (!$nodeObject->getLastPaged() || !$lastPaged) {
            $nodeObject->setLastPaged(time());
        } else if ($lastPaged - $last_heartbeat < 60*$minutes) {
            $network = $nodeObject->getNetwork();

            $nodeObject->setLastPaged(time());

            foreach ($nodeObject->getTechnicalOfficers() as $officer) {
                # Doesn't work if called from cron
                #Locale :: setCurrentLocale(Locale::getObject($officer->getPreferedLocale()));
                $mail = new Mail();
                //$mail->setSenderName(_("Monitoring system"));
                $mail->setSenderName("WiFiDog モニタリングシステム");
                $mail->setSenderEmail($network->getTechSupportEmail());
                $mail->setRecipientEmail($officer->getEmail());
                //$mail->setMessageSubject($minutes . " - " . $network->getName()." "._("node")." ".$nodeObject->getName());
                $mail->setMessageSubject($minutes . " - " . $network->getName()." ".$nodeObject->getName());
                //$mail->setMessageBody(sprintf(_("Node %s (%s) has been down for %d minutes (since %s)"), $nodeObject->getName(), $nodeObject->getId(), $minutes, date("r", $last_heartbeat)));
                $mail->setMessageBody(sprintf("%s (%s) のノードが%d分前にダウンしました。\n最終通信時間は(%s)です。\n", $nodeObject->getName(), $nodeObject->getId(), $minutes, date("Y年 n月 j日 H:i:s", $last_heartbeat)));
                $mail->send();
            }

            throw new exception("Node has been DOWN for $minutes, we paged");
        }
        throw new exception("DOWN since $minutes");
    }
}

try {
        $sql = "SELECT node_id FROM nodes WHERE node_deployment_status = 'DEPLOYED'";
    $nodes_results = null;
    //$nodes_results = array();
    $db->execSql($sql, $nodes_results, false);

    if ($nodes_results == null)
        throw new Exception(_("No nodes could not be found in the database"));

    foreach ($nodes_results as $node_row)
    {
        $nodeObject = Node :: getObject($node_row['node_id']);
        #echo $nodeObject->getName();
        #echo " - ";
        #echo $nodeObject->getLastHeartbeatTimestamp();
        #echo " - ";
        try {
            page_if_down_since($nodeObject, 120);
            page_if_down_since($nodeObject, 60);
            page_if_down_since($nodeObject, 30);
            page_if_down_since($nodeObject, 20);
            page_if_down_since($nodeObject, 15);
            page_if_down_since($nodeObject, 10);
            page_if_down_since($nodeObject, 5);
        } catch (Exception $e) {
            # Do nothing, we cronned this
            #echo $e->getMessage() . "<br>";
        }
        #echo "<br>";
        #echo "<hr>";
        #echo "\n";
    }
} catch (Exception $e) {
    #echo $e;
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * End:
 */

?>
/**
 * Timezone
 * ========
 *
 * Since PHP 5.1.0 date functions have been rewritten and require to set
 * a valid timezone.
 *
 * You'll find a list of valid identifiers at:
 * http://www.php.net/manual/en/timezones.php
 */
define('DATE_TIMEZONE', 'Asia/Tokyo');

Changed 14 years ago by benoitg

  • status changed from new to closed
  • resolution set to fixed
  • summary changed from Don't sending Mail from cron/page.php to Problem with mail translation in cron/page.php

Changed 14 years ago by benoitg

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 14 years ago by benoitg

  • priority changed from high to low

Changed 13 years ago by benoitg

  • component changed from Auth server: Authentication to Auth server, Other
Note: See TracTickets for help on using tickets.