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

session_start();
require("./ninsyou.inc");
if(0 > ninsyou_check(3)){
   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>";

$BNAME_1 = enco($_GET["BNAME_1"]);
$BNAME_2 = enco($_GET["BNAME_2"]);
$CNAME_X = enco($_GET["CNAME_X"]);
$GEN = enco($_GET["GEN"]);

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

// DB接続
$conn = db_connect();
if(!$conn){
   echo "not connection!<br>";
   exit;
   }

// コピー元ブロックBNAME_1があるか
if(0 == strlen($BNAME_1)){
   print("NG NOT block1 name");
   exit;
   }

// コピー先ブロックBNAME_2があるか
if(0 == strlen($BNAME_2)){
   print("NG NOT block2 name");
   exit;
   }

// CNAME_X があるか
if(0 == strlen($CNAME_X)){
   print("NG NOT cname_x name");
   exit;
   }


// BNAME_1 があるかを調べる
$num = 0;
$result=db_query($conn, "select * from userblock where bname='$BNAME_1'");
if(!$result){
   print("NG bud query set\n");
   exit;
   }
$num = db_num_rows($result);
if($num > 0){
   $CNAME = enco_rtrim(db_fetch_Result($result, $s, cname));
   print("OK コピー元ブロックが現在登録されているクライアントは $CNAME です\n");
   }
else{
   print("NG $BNAME_1 コピー元ブロックから監視クライアントが判断出来ません？");
   exit;
   }
db_free_result($result);


// CNAME_X が存在するか？
$num = 0;
$result=db_query($conn, "select * from connection where cname='$CNAME_X'");
if(!$result){
   print("bud query set\n");
   exit;
   }
$num = db_num_rows($result);
if($num <= 0){
   print("NG $BNAME_1 のコピー先クライアント $CNAME_X が存在しません。\n");
   exit;
   }
db_free_result($result);

print("OK $BNAME_1 のコピー先クライアント $CNAME_X が存在しました \n");




$num = 0;
$result=db_query($conn, "select * from userblock where bname='$BNAME_1'");
if($result){
   $num = db_num_rows($result);
   if($num > 0){
      while($s < $num){
         print("$BNAME_1 ブロックが存在したので $BNAME_2 の複製を作っています \n");

         $YOUNAME = enco_rtrim(db_fetch_Result($result, $s, youname));
         $CNAME = enco_rtrim(db_fetch_Result($result, $s, cname));
         $BNAME = enco_rtrim(db_fetch_Result($result, $s, bname));
         $MAILSEND = enco_rtrim(db_fetch_Result($result, $s, mailsend));
         $STAT = enco_rtrim(db_fetch_Result($result, $s, stat));
         $PLUSTIME = enco_rtrim(db_fetch_Result($result, $s, plustime));
         $STARTTIME = enco_rtrim(db_fetch_Result($result, $s, starttime));
         $STOPSETTIME = enco_rtrim(db_fetch_Result($result, $s, stopsettime));
         $MAILTO = enco_rtrim(db_fetch_Result($result, $s, mailto));
         $MAILCC = enco_rtrim(db_fetch_Result($result, $s, mailcc));
         $FREE1 = enco_rtrim(db_fetch_Result($result, $s, free1));
         $FREE2 = enco_rtrim(db_fetch_Result($result, $s, free2));
         $UNO = enco_rtrim(db_fetch_Result($result, $s, uno));

         $num_2 = 0;
         $result_2 = db_query($conn, "insert into userblock values (
          '$YOUNAME',
          '$BNAME_2', 
          '$CNAME_X',
          'OFF',
          '$STAT',
          $PLUSTIME,
          '$STARTTIME',
          '$STOPSETTIME',
          '$MAILTO',
          '$MAILCC',
          '$FREE1',
          '$FREE2',
          'NOT'
           )");

         if($result_2){
            print("$BNAME_2 ブロックは作成されました、$BNAME_1に含まれる監視項目を追加していきます \n");
            $s_3 = 0;
            $num_3 = 0;
            $result_3 = db_query($conn, "select * from monitor where free4='$BNAME_1'");

            if($result_3){
               printf("コピーする監視項目がありました \n");
               $num_3 = db_num_rows($result_3);
               if($num_3 > 0){
                  while($s_3 < $num_3){

                     $COME_M = enco_rtrim(db_fetch_Result($result_3, $s_3, come));
                     $CNAME_M = enco_rtrim(db_fetch_Result($result_3, $s_3, cname));
                     $MONITOR_M = enco_rtrim(db_fetch_Result($result_3, $s_3, monitor));
                     $SIGN_M = enco_rtrim(db_fetch_Result($result_3, $s_3, sign));
                     $PROTO_M = enco_rtrim(db_fetch_Result($result_3, $s_3, proto));
                     $COM_M = enco_rtrim(db_fetch_Result($result_3, $s_3, com));
                     $CIP_M = enco_rtrim(db_fetch_Result($result_3, $s_3, cip));
                     $PORT_M = enco_rtrim(db_fetch_Result($result_3, $s_3, port));
                     $WTIME_M = enco_rtrim(db_fetch_Result($result_3, $s_3, wtime));
                     $PINFO_M = enco_rtrim(db_fetch_Result($result_3, $s_3, pinfo));
                     $PRINO_M = enco_rtrim(db_fetch_Result($result_3, $s_3, prino));
                     $FREE1_M = enco_rtrim(db_fetch_Result($result_3, $s_3, free1));
                     $FREE2_M = enco_rtrim(db_fetch_Result($result_3, $s_3, free2));
                     $FREE3_M = enco_rtrim(db_fetch_Result($result_3, $s_3, free3));
                     $FREE4_M = enco_rtrim(db_fetch_Result($result_3, $s_3, free4));
                     print("監視項目の内容抜粋 $CIP_M \n");

                     $result_4 = db_query($conn, "insert into monitor
                       (come, cname, monitor, sign, proto, com, cip, port, wtime, pinfo, prino, free1, free2, free3, free4)
                        values (
                       'OFF',
                       '$CNAME_X',
                       '$MONITOR_M',
                        $SIGN_M,
                       '$PROTO_M',
                       '$COM_M',
                       '$CIP_M',
                       '$PORT_M',
                        $WTIME_M,
                       '$PINFO_M',
                        $PRINO_M,
                       '$FREE1_M',
                       '$FREE2_M',
                       '$FREE3_M',
                       '$BNAME_2') ");
                     if(!$result_4){
                        print("監視項目が正常にコピー出来ませんでした $CIP_M \n");
                        }
                     else{
                        print("正常に監視項目のコピーが出来ました  $CIP_M \n");
                        }

                     $s_3++;
                     }
                  db_free_result($result_4);
                  }
               }
            db_free_result($result_3);



            }
         else{
            print("監視ブロック $BNAME_2 の作成が出来ませんでした \n");
            }
         db_free_result($result_3);
         $s++;
         }
      db_free_result($result_2);
      }
   }

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



print("OK DBの変更は完了しました\n");
printf("ファイルへ反映しています\n");


// --- list file upload --- // 

list_file_upload($CNAME, $GEN);
list_file_upload($CNAME_X, $GEN);




?>

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


