<?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                    |
// |                                                                   |
// +-------------------------------------------------------------------+

/**
 * This will respond to the gateway to tell them that the gateway is still up,
 * and also log the gateway checking in for network monitoring
 *
 * @package    WiFiDogAuthServer
 * @author     Alexandre Carmel-Veilleux <acv@acv.ca>
 * @copyright  2004-2006 Alexandre Carmel-Veilleux
 * @version    Subversion $Id: index.php 916 2006-01-23 05:28:15Z max-horvath $
 * @link       http://www.wifidog.org/
 */

/**
 * Load required files
 */
require_once('../include/common.php');

echo "Pong";

$node_id = $db->escapeString($_REQUEST['gw_id']);
$user_agent =  $db->escapeString($_SERVER['HTTP_USER_AGENT']);

$db->execSql("SELECT * FROM nodes WHERE node_id='$node_id'",$result,false);
$numrow = count($result);

if ($numrow == 0){
    $db->execSql("INSERT into nodes(network_id,last_heartbeat_ip,last_heartbeat_timestamp,last_heartbeat_user_agent,node_id) values('default-network','$_SERVER[REMOTE_ADDR]', NOW(), '$user_agent', '$node_id')",$result,false);
} else {
    $db->execSqlUpdate("UPDATE nodes SET last_heartbeat_ip='$_SERVER[REMOTE_ADDR]', last_heartbeat_timestamp=NOW(), last_heartbeat_user_agent='$user_agent' WHERE node_id='$node_id'");
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * End:
 */

?>
