<?php
require("./total.inc");

session_start();
require("./ninsyou.inc");
if(0 > ninsyou_check(2)){
   exit;
   }


echo "<!DOCTYP:pserver:cvs@dhcvs.ms-n.com:/usr/home/cvsE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
echo "<HTML>";
echo "<HEAD>";
echo "<META name='GENERATOR' content='AmBuilder'>";
echo "<META http-equiv='Content-Type' content='text/html; charset=euc-jp'>";
	echo "<title>zither monitorring save info</title>";

echo "<SCRIPT LANGUAGE='JavaScript'>";
echo "<!--
function WinCls(){
        window.close()
                       }
// window.onload=WinCls();
//-->";
echo "</SCRIPT>";

echo "</head>";
echo "<body alink='#ff0000' bgcolor='#ffffff' link='#0000ff' text='#000000' vlink='#000080'>";

echo "<pre>";



$CNAME = enco($_GET["CNAME"]);
$CNAME2 = enco($_GET["CNAME2"]);
$GEN = enco($_GET["GEN"]);

$C_NAME = $CNAME;

print($version_name);
print("\n");
print(date("Y m d g i s A"));
print("\n");

if(0 == strlen($CNAME)){
   print("NG NOT hostname");
   exit;
   }


$conn = db_connect();
if(!$conn){
   echo "NG not connection!<br>";
   exit;
   }

print("$CNAME --> $CNAME2 \n");


if(0 < strlen($CNAME2)){
   $result = db_query($conn, "select * from connection where cname='$CNAME2'");
   if($result){
      $num = db_num_rows($result);
      if($num > 0){

         print("OK connection 移動を行います\n");

         $result=db_query($conn,
           "update userblock set cname='$CNAME2' where cname='$CNAME'");
         if(!$conn){
            echo "NG userblock を移動出来ませんでした<br>";
            exit;
            }
         $result=db_query($conn,
           "update monitor set cname='$CNAME2' where cname='$CNAME'");
         if(!$conn){
            echo "NG monitor を移動出来ませんでした<br>";
            exit;
            }
         else{
            list_file_upload($CNAME2, $GEN);
            }
         }
      else{
         print("OK $CNAME2 が無いので移動を行いません\n");
         }
      }
   else{
      print("OK $CNAME2 が無いので移動を行いません\n");
      }
   }


$result = db_query($conn, "delete from connection where cname='$CNAME'");
if(!$result){
   print("NG connection から削除できません\n");
   exit;
   }



$result = db_query($conn, "delete from monitor where cname='$CNAME'");
if(!$result){
   print("NG monitor から削除できません\n");
   exit;
   }

$result = db_query($conn, "delete from userblock where cname='$CNAME'");
if(!$result){
   print("NG userblock から削除できません\n");
   exit;
   }

$result = db_query($conn, "delete from config where c_name='$CNAME'");
if(!$result){
   print("NG config から削除できません\n");
   exit;
   }




echo "OK delete data\n";


$conf_file = "/usr/local/zither/conf/" . $CNAME . "." . "conf"; 
echo "Delete $conf_file\n";
unlink($conf_file);

$conf_file = "/usr/local/zither/conf/" . $CNAME . "." . "stat"; 
echo "Delete $conf_file\n";
unlink($conf_file);

$conf_file = "/usr/local/zither/conf/" . $CNAME . "." . "list"; 
echo "Delete $conf_file\n";
unlink($conf_file);

$conf_file = "/usr/local/zither/conf/" . $CNAME . "." . "command"; 
echo "Delete $conf_file\n";
unlink($conf_file);


echo ".conf,.list,.command,.stat file unlink ok\n";
echo "成功 \n";


$conf_file = "/usr/local/zither/conf/neg.conf";
$result = db_query($conn, "select * from connection");
if(!$result){
   print("bud query conection\n");
   exit;
   }
$num = db_num_rows($result);
if($num <= 0){
   print("no data conection\n");
   exit;
   }
if(($fp = fopen($conf_file, "w+"))==NULL){
   print("file not open neg.conf\n");
   exit;
   }
$s = 0;
while($s < $num){
   $CNAME = enco_rtrim(db_fetch_Result($result, $s, cname));
   $CIP = enco_rtrim(db_fetch_Result($result, $s, cip));
   fwrite($fp, "$CNAME:$CIP\n");
   print("$CNAME:$CIP\n");
   $s++;
   }
fclose($fp);
echo "neg.conf file update ok\n";
echo "成功 \n";


if(0 < strlen($GEN)){
   $s = 0;
   $result = db_query($conn, "select distinct(server) from connection;");
   if(!$result){
      print("bud query\n");
      exit;
      }
   $num = db_num_rows($result);
   if($num <= 0){
      print("no data\n");
      exit;
      }
   else{
      while($s < $num){
         $SERVER = enco_rtrim(db_fetch_Result($result, $s, server));
         print("$SERVER $my_web_ip ");
         if(0 != strcmp($SERVER, $my_web_ip)){

            $T_1 = "/negdelete_ok.php" . "?";
            $T_2 = "KEY=" . urlencode($C_NAME);

            $T_ALL = $T_1 . $T_2;

            print("<br>");
            print("$T_ALL");
            http_open($SERVER, $T_ALL, $my_web_ip);

            }

         $s++;
         }
      }
   }



db_free_result($result);
db_Close($conn);



?>

</pre>
</body>
</html>

