Files
2024-11-11 17:56:00 +08:00

394 lines
11 KiB
PHP
Executable File

<?php
/*********************************************************
文件说明:
功能说明:上载文件
调用关系:调用:header.inc
被调用:
变量说明:
作者:
修改注释:
NO.1
姓名:
时间:
修改说明:
*********************************************************/
require("../../inc/header.inc");
$helpId="6.6.1";
//****************************************************************
//
// 函数名 send_shm_tftp($file_name,$ip,$length)
//
// 功能说明:该函数用于在对数据库进行操作后,通过设置共享内存通知后台程序.
//
// 调用关系:
//
// 变量说明: $file_name文件名
// $ip IP地址
// $length message长度
// 返回值:
//
// 作者:
//
//修改注释:
//NO.1
//姓名:
//时间:
//修改说明:
//
//----------------------------------------------------------
function send_shm_tftp($file_name,$ip,$length)
{
global $strCommandBeExecute,$strDaemonOperationTimeout,$strDaemonOperationFailure,$strDaemonOperationSuccess,$strSetMemoryFailure,$strDaemonRecordNoChange,$strMemoryWaitStatus,$strDownloadSuccessToSwitch,$strDownloadFailureToSwitch;
$DEBUG=0;
$command_status_1=tftp_get_shm(0,1);//第一次扫描命令状态
if($DEBUG) echo "<br>command_status_1=$command_status_1";
if($command_status_1=='1' || $command_status_1=='2')//1--待执行状态 2--在执行状态
{
echo "<br><font color=\"#FF0000\">$strCommandBeExecute!</font>";
return(-1);
}
else//共享内存可写
{
if($DEBUG) echo "<br>file_name=$file_name";
if($DEBUG) echo "<br>ip=$ip";
if($DEBUG) echo "<br>length=$length";
$set_result_1=tftp_set_shm(1,0);
$set_result_2=tftp_set_shm($length,1);
$set_result_3=tftp_set_shm($ip,5);
$set_result_4=tftp_set_shm($file_name,20);
if($DEBUG) echo "<br>set_result_1=$set_result_1";
if($DEBUG) echo "<br>set_result_2=$set_result_2";
if($DEBUG) echo "<br>set_result_3=$set_result_3";
if($DEBUG) echo "<br>set_result_4=$set_result_4";
$scan_1=0;//待执行状态标识
$scan_2=0;//已处理记录标识
$pre_records=0;//上次处理记录数
if($set_result_1>0 && $set_result_2>0 && $set_result_3>0 && $set_result_4>0)//设置共享内存成功
{
do{
sleep(2);
$command_status_2=tftp_get_shm(0,1);
if($DEBUG) echo "<br>command_status_2=$command_status_2";
if($command_status_2=='1')
{
$scan_1++;
if($DEBUG) echo "<br>scan_1=$scan_1";
if($scan_1>1)//如果连续4秒处于该状态,异常退出
{
$prompt_name=$strMemoryWaitStatus;
echo "<br><font color=\"#FF0000\">$prompt_name</font>";
break;
}
}
elseif($command_status_2=='2')
{
$the_records=tftp_get_shm(60,4);
if($DEBUG) echo "<br>the_records=$the_records";
if($DEBUG) echo "<br>pre_records=$pre_records";
if($pre_records==$the_records)
{
$scan_2++;
//echo "<br>scan_2=$scan_2";
}
else
{
$pre_records=$the_records;//把本次已处理记录数赋给上次记录数
}
if($scan_2>1)
{
$prompt_name=$strDaemonRecordNoChange;
echo "<br><font color=\"#FF0000\">$prompt_name</font>";
break;//如果连续4秒已处理记录数不变,异常退出
}
}
else
{
$describe=tftp_get_shm(64,36);
echo "<br><font color=\"#0000FF\">$describe</font>";
if($command_status_2=='4')
{
$prompt_name="$strDownloadFailureToSwitch";
echo "<br><font color=\"#FF0000\">$prompt_name</font>";
}
elseif($command_status_2=='3')
{
$prompt_name="$strDownloadSuccessToSwitch";
echo "<br><font color=\"#0000FF\">$prompt_name</font>";
$suc_sign=1;
}
}
}while($command_status_2=='1' || $command_status_2=='2');
$set_result=tftp_set_shm(0,0);
if($suc_sign>0){
return(1);
}else{
return(-1);
}
}
else
{
echo "<br><font color=\"#FF0000\">$strSetMemoryFailure</font>";
$set_result=tftp_set_shm(0,0);
return(-1);
}
}//end else共享内存可写
}
//****************************************************************
// 函数2 tftp_set_shm($str,$offset)
//
// 功能说明:该函数用于tftp通知后台程序的共享内存设定.
//
// 调用关系:
//
// 变量说明:$str 写入共享内存中的字串
// $offset 从开辟的共享内存块中的第几位开始写
// (0:发送一般命令,1:发送uninstall命令)
//
// 返回值:操作类型的值(正:成功,负:失败)
//
//
//
//修改注释:
//NO.1
//姓名:
//时间:
//修改说明:
//
//----------------------------------------------------------
function tftp_set_shm($str,$offset)
{
//PHP_C_SHM_KEY 0x6AE00000
//PHP_C_SHM_PERM 0666
//PHP_C_SEM_KEY 440
//PHP_C_SEM_PERM 0666
//size 10*100 bytes
define("Semaphore_Key",440,1);
define("SharedMem_Key",0x6AE00000,1);
define("SharedMem_Size",1000,1); //共享内存大小
$SharedMemID = @shmop_open(SharedMem_Key,"c",0666,SharedMem_Size);
$sharemen_sign = 0;
//将指定变量存入共享内存
if(shmop_write($SharedMemID,$str,$offset))
$sharemen_sign++;
if($sharemen_sign == 1){
return(1);
}else{
return(-1);
}
}
//****************************************************************
// 函数3 tftp_get_shm($offset,$count)
//
// 功能说明:该函数用于tftp通知后台程序的共享内存设定.
//
// 调用关系:
//
// 变量说明: $offset 从开辟的共享内存块中的第几位开始读
// $count 读多少位
//
// 返回值:操作类型的值(正:读出的值,负:失败)
//
// 作者:
//
//修改注释:
//NO.1
//姓名:
//时间:
//修改说明:
//
//----------------------------------------------------------
function tftp_get_shm($offset,$count)
{
//PHP_C_SHM_KEY 0x6AE00000
//PHP_C_SHM_PERM 0666
//PHP_C_SEM_KEY 440
//PHP_C_SEM_PERM 0666
//size 10*100 bytes
define("Semaphore_Key",440,1);
define("SharedMem_Key",0x6AE00000,1);
define("SharedMem_Size",1000,1); //共享内存大小
$SharedMemID = @shmop_open(SharedMem_Key,"c",0666,SharedMem_Size);
//将指定共享内存存入变量
$Read_str= shmop_read($SharedMemID,$offset,$count);
return($Read_str);
}
if($action1){ //if files have been uploaded, process them
$DEBUG=0;
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<?php
adjust_head();
adjust_title_head();
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\" align=\"left\">";
echo "Advanced > Software Upgrade >Tftp";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">&nbsp";
echo "</td>";
echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();
echo "<br>";
?>
<p><font face="Arial, Helvetica, sans-serif"><font size="+1"><?php echo $strMapUploadResults; ?></font><br><br>
<?
set_time_limit(60); //make reasonably sure the script does not time out on large files
$path1 = dirname($PATH_TRANSLATED); // assign our path in a form PHP for Windows understands
if($DEBUG) echo "<br>path1=$path1";
$source = $file1;
if($DEBUG) echo "<br>source=$source";
$source_name = $file1_name;
if($DEBUG) echo "<br>source_name=$source_name";
echo "<br><font color=\"#0000FF\">FileName:$source_name</font>";
echo "<br><font color=\"#0000FF\">IPAddress:$ip</font>";
echo "<br><font color=\"#0000FF\">MessageLength:$length BYTES</font><br>";
$log_name="TFTP ".$strFileUpload;
if(($source <> "none")&&($source <> "")){ // see if the file exists; non-existing file has name of "none"
if($error1 <> 1){ // no need to copy a file if directory not write-enabled
$dest = $path1."/".$source_name; // append file name to our path
if($DEBUG) echo "<br>dest=$dest";
if(copy($source,$dest)){ // copy the file from the temp directory to the upload directory, and test for success
$newname = "../../../tftp/";
$newname .=$source_name;
if(copy($dest,$newname))
{
insertLog("$log_name");
echo "<br><font color=\"#0000FF\">$strFileUploadSuccessToServer</font><br>\n";
$set_result=send_shm_tftp($source_name,$ip,$length);
}
else
{
echo "<br><font color=\"#FF0000\">$strUploadFailure</font><br>\n";
insertLog("$log_name");
}
unlink ($dest);
}//end if(copy($source,$dest))
else
{
echo "$strUploadDirectoryNotWriteEnabled\n"; // you need to write-enable the upload directory
$error1 = 1; // set flag
insertLog("$log_name");
}
}//if($error1 <> 1)
unlink($source); // delete the file from the temp directory
}else{//if(($source <> "none")&&($source <> ""))
echo "<br><font color=\"#FF0000\">source=none!</font></br>";
}
?>
<br><br><a href="./tftp.php"><?php echo " <<< Return"; ?></a>
</font></p>
<?php
adjust_content_tail();
?>
</body>
</html>
<?
}//end if($action1)
else {
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<?php
adjust_head();
adjust_title_head();
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Advanced > Software Upgrade >Tftp";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
//showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();
echo "<br>";
?>
<p><font face="Arial, Helvetica, sans-serif"><font size="3"><b><?php echo $strTFTPFileTransfer; ?></b></font>
<p></p>
<form method="post" enctype="multipart/form-data" action="<?php echo "$PHP_SELF"; ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="800000">
<input type="hidden" name="action1" value="1">
<table border="0" width="500">
<tr>
<td width="20%"><?php echo "File:"; ?></td>
<td width="80%"><input type="file" name="file1" size="20" class="button"></td>
</tr>
<tr>
<td width="20%"><?php echo "IP:"; ?></td>
<td width="80%"><input type="text" name="ip" size="20" class="button"></td>
</tr>
<tr>
<td width="20%"><?php echo "$strMessageLength:"; ?></td>
<td width="80%">
<select name="length">
<option value="64">64</option>
<option value="128" selected>128</option>
<option value="256">256</option>
<option value="512">512</option>
<option value="1024">1024</option>
</select>
Bytes
</td>
</tr>
<tr>
<td width="15%">
<?php echo "<input type=\"submit\" value=$strUpload class=\"button\">"; ?>
</td>
<td width="85%">&nbsp;</td>
</tr>
</table>
</form>
</font></p>
</body>
<b>Remarks:</b><br><br>
Browse to 8K E1 Card software in the File field.<br>
Input IP address of LAN module of 8K E1 Card in the IP field.<br>
Set 128 bytes for the Message length option.<br>
<?php
adjust_content_tail();
?>
</html>
<?
}
?>