예제 #1
0
파일: nodes.php 프로젝트: BillTheBest/1.6.x
function delete_node_perform()
{
    $f = new mysql_blackbox();
    $f->CheckTables();
    $q = new blackboxes($_POST["delete-node"]);
    $q->delete_node();
}
예제 #2
0
function REGISTER()
{
    $q = new mysql_blackbox();
    if (!isset($_POST["nets"])) {
        die("No network sended");
    }
    $EncodedDatas = $_POST["nets"];
    $array = unserialize(base64_decode($EncodedDatas));
    $nodeid = $_POST["nodeid"];
    $hostid = $_POST["hostid"];
    $ISARTICA = $_POST["ISARTICA"];
    $usessl = $_POST["usessl"];
    if (!is_numeric($ISARTICA)) {
        $ISARTICA = 0;
    }
    if (!is_numeric($nodeid)) {
        $nodeid = 0;
    }
    if (!is_array($array)) {
        echo "<ERROR>No an Array</ERROR>\n";
        writelogs("Not an array... ", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (count($array) == 0) {
        echo "<ERROR>No item sended</ERROR>\n";
        writelogs("No item... ", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $sql = "SELECT nodeid FROM nodes WHERE `hostid`='{$hostid}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    $nodeid = $ligne["nodeid"];
    if (!is_numeric($nodeid)) {
        $nodeid = 0;
    }
    $ME = $_SERVER["SERVER_NAME"];
    $q = new mysql_blackbox();
    $q->CheckTables();
    if ($nodeid > 0) {
        writelogs("item already exists", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        $sql = "UPDATE nodes SET hostname='{$_POST["hostname"]}',\n\t\tipaddress='{$_SERVER["REMOTE_ADDR"]}',\n\t\tport='{$_POST["port"]}',\n\t\thostid='{$hostid}' WHERE nodeid='{$nodeid}'";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$ME}:{$sql}\n";
        }
        $q->QUERY_SQL($sql);
        if (preg_match("#Unknown column 'hostid'#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE nodes");
            $q->CheckTables();
            $sql = "INSERT INTO nodes (`hostname`,`ipaddress`,`port`,`hostid`,`BigArtica`,`ssl`) \n\t\t\tVALUES ('{$_POST["hostname"]}','{$_SERVER["REMOTE_ADDR"]}','{$_POST["port"]}','{$hostid}','{$ISARTICA}','{$usessl}')";
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}:\n{$sql}\n line:" . __LINE__ . "</ERROR>\n";
                return;
            }
            $sql = "SELECT nodeid FROM nodes WHERE `hostid`='{$hostid}'";
            $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
            if (!$q->ok) {
                echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}:\n{$sql}\n line:" . __LINE__ . "</ERROR>\n";
                return;
            }
            $nodeid = $ligne["nodeid"];
        }
        if (!$q->ok) {
            echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}:\n{$sql}\n line:" . __LINE__ . "</ERROR>\n";
            return;
        }
        echo "<SUCCESS>{$nodeid}</SUCCESS>";
    } else {
        echo "Adding new item\n...";
        writelogs("Adding new item", __CLASS__ . "/" . __FUNCTION__, __FILE__, __LINE__);
        $sql = "INSERT INTO nodes (`hostname`,`ipaddress`,`port`,`hostid`,`BigArtica`,`ssl`) \n\t\tVALUES ('{$_POST["hostname"]}','{$_SERVER["REMOTE_ADDR"]}','{$_POST["port"]}','{$hostid}','{$ISARTICA}','{$usessl}')";
        $q->QUERY_SQL($sql);
        if ($GLOBALS["VERBOSE"]) {
            if (!$q->ok) {
                echo "<ERROR>{$ME}: Statisics appliance: {$q->mysql_error}: line:" . __LINE__ . "</ERROR>\n";
            }
        }
        if (preg_match("#Unknown column 'hostid'#", $q->mysql_error)) {
            $q->QUERY_SQL("DROP TABLE nodes");
            $q->CheckTables();
            $q->QUERY_SQL($sql);
        }
        if (!$q->ok) {
            echo "<ERROR>{$ME}:Statisics appliance: {$q->mysql_error}: line:" . __LINE__ . "</ERROR>\n";
            return;
        }
        $sql = "SELECT nodeid FROM nodes WHERE `hostid`='{$hostid}'";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        echo "{$ME}:Success adding new item in the central server\n";
        echo "<SUCCESS>{$ligne["nodeid"]}</SUCCESS>";
    }
}
function AddArticaAgent(){
	$tpl=new templates();
	$sock=new sockets();
	$pattern=$_POST["AddArticaAgent"];
	$ip=$pattern;
	if(preg_match("#(.+?):([0-9]+)#", $pattern,$re)){$ip=$re[1];$port=$re[2];}
	if(!is_numeric($port)){$port=9001;}
	include_once(dirname(__FILE__)."/ressources/class.ccurl.inc");
	
	
	$ArticaHttpsPort=$sock->GET_INFO("ArticaHttpsPort");
	$ArticaHttpUseSSL=$sock->GET_INFO("ArticaHttpUseSSL");
	if(!is_numeric($ArticaHttpUseSSL)){$ArticaHttpUseSSL=1;}
	if(!is_numeric($ArticaHttpsPort)){$ArticaHttpsPort="9000";}	
	
	
	$time=date('Y-m-d H:i:s');
	if(preg_match("#^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+#", $ip)){
		$hostname=gethostbyaddr($ip);
	}else{
		$hostname=$ip;
		$ip=gethostbyname($hostname);
	}

	$q=new mysql_blackbox();
	$q->CheckTables();
	$sql="INSERT IGNORE INTO `nodes` (ipaddress,hostname,port,laststatus) VALUES ('$ip','$hostname','$port','$time')";
	$q->QUERY_SQL($sql);
	if(!$q->ok){echo $q->mysql_error;return;}
	if($q->last_id==0){
		echo "Unable to get Last ID\n";return;
	}
	$curl=new ccurl("http://$ip:$port/listener.php");
	$curl->parms["REGISTER"]="yes";
	$curl->parms["SSL"]=$ArticaHttpUseSSL;
	$curl->parms["PORT"]=$ArticaHttpsPort;
	$curl->parms["NODE_ID"]=$q->last_id;
	if(!$curl->get()){echo $tpl->javascript_parse_text("{$curl->error}")."\nhttp://$ip:$port";return;}
	if(!preg_match("#<SUCCESS>#is", $curl->data)){echo $tpl->javascript_parse_text("{failed} `http://$ip:$port`");return;}	
	
}	
예제 #4
0
<?php 
include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ldap.inc';
include_once dirname(__FILE__) . '/ressources/class.users.menus.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.blackboxes.inc';
include_once dirname(__FILE__) . '/framework/frame.class.inc';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
$GLOBALS["AS_ROOT"] = true;
$GLOBALS["VERBOSE"] = true;
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
ini_set('error_prepend_string', null);
ini_set('error_append_string', null);
echo "Starting initalization....\n";
$q = new mysql_blackbox();
$q->CheckTables();
if ($q->TABLE_EXISTS("nodes")) {
    echo "Starting nodes......: OK\n";
}
if ($q->TABLE_EXISTS("squidconf")) {
    echo "Starting squidconf..: OK\n";
}