main.php – style JQuery AJAX
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="icon" href="cat3.png" />
<link rel="stylesheet" type="text/css" href="./styles.css">
<title>Job Manager</title>
<!-- JQuery -->
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script type="text/javascript"src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<style>
body,ul,li{
margin:0;
padding:0;
}
a{
text-decoration: none;
color:black;
}
.box{
width:100%;
height:100%;
margin:0px auto;
border:0px solid #f90;
border-radius:0px;
}
h3{
text-align:center;
}
ul{
list-style: none;
border-bottom:1px solid #f90;
overflow:hidden;
}
ul li{
float:left;
border:1px solid #f90;
margin-left:-1px;
padding:6px 30px;
border-top-left-radius:3px;
border-top-right-radius:3px;
border-bottom:none;
cursor:pointer;
}
ul li:first-child{
background:#f90;
}
ul li:first-child a{
color:white;
}
iframe{
width:100%;
border:none;
background:none;
}
#footer {
height: 40px;
line-height: 40px;
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
background: #666;
color: #fff;
font-family: Arial;
font-size: 12px;
letter-spacing: 1px;
}
#userinfo {
height: 40px;
line-height: 40px;
bottom: 0;
width: 100%;
text-align: center;
background: #666;
color: #fff;
font-family: Arial;
font-size: 12px;
letter-spacing: 1px;
}
</style>
</head>
<body>
<div id="userinfo">
<?php
session_start();
if (isset($_SESSION["username"]) && isset($_SESSION["password"])){
echo '<font size="2">Welcome '.$_SESSION["username"].'. </font><input style="width:5%;font-size:10px;" type="button" value="Logout" onclick="logout(this)">';
}else
{
echo <<<EOF
Username:<input style="width:10%" type="text" id="username" value="username">
Password:<input style="width:10%" type="password" id="password" value="password">
<input style="width:5%;font-size:14px;" type="button" value="Login" onclick="login(this)">
<input style="width:5%;font-size:14px;" type="button" value="Register" onclick="register(this)">
EOF;
}
?>
</div>
<div class="box" id="box">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" class="biaoti" style="font-size:22px;" height="60">Network QE Driver Team Job Manager</td>
</tr>
</table>
<input type="text" id="hiddenusername" hidden="hidden">
<input type="text" id="hiddenpassword" hidden="hidden">
<ul id="pagelist">
<li><a href="job_scheduler.php" target="content">Scheduler</a></li>
<li><a href="job_statistic/job_statistic.php" target="content">Statistic</a></li>
<li><a href="http://<?php echo $_SERVER['SERVER_ADDR'];?>/job_scheduler/ci/log.txt" target="content">CI LOG</a></li>
<li><a href="system_history_status.php" target="content">System Historical Status</a></li>
<li><a href="how_to_use.txt" target="content">Help</a></li>
</ul>
<iframe src="job_scheduler.php" scrolling="yes" id="mainFrame" name="content" onload="changeFrameHeight()"></iframe>
</div>
<div id="footer">@2020 Redhat Network-QE-Driver </div>
<script>
$(document).ready(function(){
$("#pagelist li").click(function(){
var lis=document.querySelectorAll("#pagelist li");
var len=lis.length;
//切换页签样式:遍历li,给li绑定onclick事件
for(var i=0;i<len;i++){
if(lis[i]==this){//判断是否为当前对象
lis[i].style.background="#f90";
lis[i].querySelector("a").style.color="white";
}else{
lis[i].style.background="white";
lis[i].querySelector("a").style.color="black";
}
}
});
$("#name").change(function(){
if(this.value==""){
this.value="username";
}
document.getElementById("hiddenusername").value=this.value;
});
$("#password").change(function(){
if(this.value==""){
this.value="password";
}
document.getElementById("hiddenpassword").value=this.value;
});
$("#name").click(function(){
this.value="";
});
$("#password").click(function(){
this.value="";
});
});
function valid_username()
{
var did="username";
var content=document.getElementById(did).value;
if(content==null||content=="null")
{
alert("'username' Can Not Be Null");
document.getElementById(did).focus();
return false;
}
return true;
}
function valid_password()
{
var did="password";
var content=document.getElementById(did).value;
if(content==null||content=="null")
{
alert("'password' Can Not Be Null");
document.getElementById(did).focus();
return false;
}
return true;
}
function register(btn)
{
var rtn=valid_username();
if(rtn==false)
{
return false;
}
var rtn=valid_password();
if(rtn==false)
{
return false;
}
btn.disabled=true;
var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("register succeeded!");
//document.getElementById("max_time").value=xmlhttp.responseText;
btn.disabled=false;
}else if(xmlhttp.readyState==4 && xmlhttp.status==501)
{
alert("username exist!!!");
btn.disabled=false;
}else if(xmlhttp.readyState==4 && xmlhttp.status==502)
{
alert("connect to db failed!!!");
btn.disabled=false;
}
}
xmlhttp.open("GET","register.php?username="+username+"&password="+password,true);
xmlhttp.send();
}
function login(btn)
{
var rtn=valid_username();
if(rtn==false)
{
return false;
}
var rtn=valid_password();
if(rtn==false)
{
return false;
}
btn.disabled=true;
var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
btn.disabled=false;
document.getElementById("hiddenusername").value=username;
document.getElementById("hiddenpassword").value=password;
document.getElementById("userinfo").innerHTML='<font size="2">Welcome '+username+'. </font><input style="width:5%;font-size:10px;" type="button" value="Logout" onclick="logout(this)">';
}else if(xmlhttp.readyState==4 && xmlhttp.status==501)
{
alert("login failed!");
btn.disabled=false;
}
}
xmlhttp.open("GET","login.php?username="+username+"&password="+password,true);
xmlhttp.send();
}
function logout(btn)
{
btn.disabled=true;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
btn.disabled=false;
var username=document.getElementById("hiddenusername").value;
var password=document.getElementById("hiddenpassword").value;
document.getElementById("userinfo").innerHTML='Username:<input style="width:10%" type="text" id="username" value="'+username+'"> Password:<input style="width:10%" type="password" id="password" value="'+password+'"> <input style="width:5%;font-size:14px;" type="button" value="Login" onclick="login(this)"> <input style="width:5%;font-size:14px;" type="button" value="Register" onclick="register(this)">';
}else if(xmlhttp.readyState==4 && xmlhttp.status==501)
{
alert("login failed!");
btn.disabled=false;
}
}
xmlhttp.open("GET","logout.php",true);
xmlhttp.send();
}
function changeFrameHeight(){
//var box = document.getElementById("box");
//box.height=document.documentElement.clientHeight;
var ifm= document.getElementById("mainFrame");
ifm.height=document.documentElement.clientHeight-180;
}
window.onresize=function(){
changeFrameHeight();
}
</script>
</body>
</html>
job_scheduler.php – java script
<!DOCTYPE html>
<html>
<head>
<title>Job Scheduler</title>
<link rel="icon" href="cat3.png" />
<link rel="stylesheet" type="text/css" href="./styles.css">
<style>
.error {color: #FF0000;}
.ui-dialog-title {
font-weight: bold;
text-align:center;
}
.ui-dialog-buttonpane {
background:black;
}
#cases {
background:black;
color:green;
font-size:14px;
}
</style>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script type="text/javascript"src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<script type="text/javascript">
/*$(document).ready(function(){
$("#all_speed").click();
});*/
function disable_all_buttons()
{
$("input[type='button']").each(function() {
this.disabled = true;
});
}
function enable_all_buttons()
{
$("input[type='button']").each(function() {
this.disabled = false;
});
}
function ganged(type,nic)
{
if(type==1)
{
check=document.getElementById(nic).checked;
if(check==false)
{
var match=nic+"::";
$(":checkbox[id^='"+match+"']").each(function() {
this.checked = false;
});
}
else
{
var match=nic+"::";
$(":checkbox[id^='"+match+"']").each(function() {
this.checked = true;
});
}
}
else if(type==2)
{
var driver_model=nic.split("::");
var driver=driver_model[0];
var model=driver_model[1];
check=document.getElementById(nic).checked;
if(check==true)
{
document.getElementById(driver).checked=true;
}
else
{
var match=driver+"::"+model+"::";
$(":checkbox[id^='"+match+"']").each(function() {
this.checked = false;
});
}
}else
{
var driver_model=nic.split("::");
var driver=driver_model[0];
var model=driver_model[1];
var speed=driver_model[2];
var driver_model=driver+"::"+model;
check=document.getElementById(nic).checked;
if(check==true)
{
document.getElementById(driver_model).checked=true;
document.getElementById(driver).checked=true;
}
}
}
function click_all_driver()
{
check = document.getElementById("all_driver").checked;
$(".driver").each(function() {
this.checked=check;
});
if(check==false)
{
document.getElementById("all_model").checked = false;
$(".model").each(function() {
this.checked=false;
});
document.getElementById("all_speed").checked = false;
$(".speed").each(function() {
this.checked=false;
});
}
else
{
document.getElementById("all_model").checked = true;
$(".model").each(function() {
this.checked=true;
});
document.getElementById("all_speed").checked = true;
$(".speed").each(function() {
this.checked=true;
});
}
}
function valid_input(did)
{
var content=document.getElementById(did).value;
if(content==null||content=="")
{
alert(did+" can't be null");
document.getElementById(did).focus();
return false;
}
return true;
}
function fetch_nic_info(btn_id)
{
var rtn=valid_match();
if(rtn==false)
{
return false;
}
var rtn=valid_common("unmatch");
if(rtn==false)
{
return false;
}
disable_all_buttons();
var match=document.getElementById("match").value;
var unmatch=document.getElementById("unmatch").value;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("line").innerHTML=xmlhttp.responseText;
document.getElementById("nicinfo").innerHTML=xmlhttp.responseText;
enable_all_buttons();
}
//document.getElementById("distro").innerHTML=xmlhttp1.status;
}
xmlhttp.open("GET","generate_nic_info.php?match="+match+"&unmatch="+unmatch,true);
xmlhttp.send();
}
function valid_testname()
{
var content=document.getElementById("testname").value;
if(content==null||content=="")
{
alert("'Test name' Can Not Be Null");
document.getElementById("testname").focus();
return false;
}
var patt=/[ ,\/\\]/;
if(true==patt.test(content))
{
alert("'Test name' Can not Contain ' ' ',' '/' '\\'");
document.getElementById("testname").focus();
return false;
}
return true;
}
function valid_tier()
{
var did="tiers";
var content=document.getElementById(did).value;
if(content!=null||content!="")
{
var patt=/^[tier0-9,]*$/i;
if(false==patt.test(content))
{
alert("'Tier' Can Only Contain 't' 'i' 'e' 'r' '0-9' ','");
document.getElementById(did).focus();
return false;
}
}
return true;
}
function valid_kernel()
{
return true;
var content=document.getElementById("kernel").value;
if(content!=null&&content!="")
{
var patt1=/^kernel-[0-9]\.[0-9\.\-]*el[0-9]$/;
var patt2=/^kernel-[0-9]\.[0-9\.\-]*el[0-9]_[0-9]*$/;
/*if(false==patt1.test(content))
{
alert("patt1 fail");
}
if(false==patt2.test(content))
{
alert("patt2 fail");
}*/
if(false==patt1.test(content) && false==patt2.test(content))
{
alert("'Kernel' format is wrong.");
document.getElementById("kernel").focus();
return false;
}
}
return true;
}
function valid_distro()
{
var content=document.getElementById("distro").value;
if(content==null||content=="")
{
alert("'Distro' Can Not Be Null.");
document.getElementById("distro").focus();
return false;
}
var patt=/^RHEL-[0-9]\.[0-9][0-9\-\.nd]*$/i;
if(false==patt.test(content))
{
alert("'Distro' format is wrong.");
document.getElementById("distro").focus();
return false;
}
return true;
}
function list_test(show_running_only)
{
if(show_running_only=="yes")
{
btn_id="bt_list_test1";
btn_current_value=document.getElementById(btn_id).value;
if(btn_current_value=="Hide Running Tests")
{
document.getElementById("test_list").innerHTML="";
document.getElementById(btn_id).value="Show Running Tests";
return True;
}
}else
{
btn_id="bt_list_test";
btn_current_value=document.getElementById(btn_id).value;
if(btn_current_value=="Hide All Tests")
{
document.getElementById("test_list").innerHTML="";
document.getElementById(btn_id).value="Show All Tests";
return True;
}
}
/*var rtn=valid_testname();
if(rtn==false)
{
return false;
}*/
disable_all_buttons();
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("test_list").innerHTML=xmlhttp.responseText;
if(show_running_only=="yes")
{
document.getElementById("bt_list_test1").value="Hide Running Tests";
}else
{
document.getElementById("bt_list_test").value="Hide All Tests";
}
enable_all_buttons();
}
}
xmlhttp.open("GET","list_test.php?showrunningonly="+show_running_only,true);
xmlhttp.send();
}
function partial_cancel_test(testname)
{
document.getElementById("partial_cancel_testname").value=testname;
$("#cancel_panel").dialog({ autoOpen: false, height:750, width:1500, modal:true,
buttons:{
"Close":function(){$(this).dialog("close");}
}
});
$("#cancel_panel").dialog( "open" );
}
function partial_cancel_test_step2()
{
testname = document.getElementById("partial_cancel_testname").value;
driver = document.getElementById("c_driver").value;
speed = document.getElementById("c_speed").value;
list = document.getElementById("c_list").value;
testside = document.getElementById("c_testside").value;
var con=confirm("really cancel "+testname+" "+driver+" "+model+" "+speed+" "+list+" "+testside+"?");
if(con==false)
{
return false;
}
document.getElementById("btn_partial_cancel_test").disabled=true;
document.getElementById("btn_partial_reschedule_test").disabled=true;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("test_list").innerHTML=xmlhttp.responseText;
document.getElementById("btn_partial_cancel_test").disabled=false;
document.getElementById("btn_partial_reschedule_test").disabled=false;
alert("succeeded!");
}
else if (xmlhttp.readyState==4 && xmlhttp.status==500)
{
//document.getElementById("test_list").innerHTML=xmlhttp.responseText;
document.getElementById("btn_partial_cancel_test").disabled=false;
document.getElementById("btn_partial_reschedule_test").disabled=false;
alert("failed!");
}else if (xmlhttp.readyState==4 && xmlhttp.status==501)
{
//document.getElementById("test_list").innerHTML=xmlhttp.responseText;
document.getElementById("btn_partial_cancel_test").disabled=false;
document.getElementById("btn_partial_reschedule_test").disabled=false;
alert("failed! unlogin");
}
}
xmlhttp.open("GET","partial_cancel_test.php?testname="+testname+"&driver="+driver+"&model="+model+"&speed="+speed+"&list="+list+"&testside="+testside,true);
xmlhttp.send();
}
function partial_reschedule_test_step2()
{
testname = document.getElementById("partial_cancel_testname").value;
driver = document.getElementById("c_driver").value;
speed = document.getElementById("c_speed").value;
list = document.getElementById("c_list").value;
testside = document.getElementById("c_testside").value;
var con=confirm("really reschedule "+testname+" "+driver+" "+model+" "+speed+" "+list+" "+testside+"?");
if(con==false)
{
return false;
}
document.getElementById("btn_partial_cancel_test").disabled=true;
document.getElementById("btn_partial_reschedule_test").disabled=true;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("test_list").innerHTML=xmlhttp.responseText;
document.getElementById("btn_partial_cancel_test").disabled=false;
document.getElementById("btn_partial_reschedule_test").disabled=false;
alert("succeeded!");
}
else if (xmlhttp.readyState==4 && xmlhttp.status==500)
{
//document.getElementById("test_list").innerHTML=xmlhttp.responseText;
document.getElementById("btn_partial_cancel_test").disabled=false;
document.getElementById("btn_partial_reschedule_test").disabled=false;
alert("failed!");
}else if (xmlhttp.readyState==4 && xmlhttp.status==501)
{
//document.getElementById("test_list").innerHTML=xmlhttp.responseText;
document.getElementById("btn_partial_cancel_test").disabled=false;
document.getElementById("btn_partial_reschedule_test").disabled=false;
alert("failed! unlogin");
}
}
xmlhttp.open("GET","partial_reschedule_test.php?testname="+testname+"&driver="+driver+"&model="+model+"&speed="+speed+"&list="+list+"&testside="+testside,true);
xmlhttp.send();
}
var drivers = [];
var models = [];
var speeds = [];
function get_driver_model_speed()
{
drivers = [];
models = [];
speeds = [];
$(".driver").each(function() {
if(this.checked==true){
drivers.push(this.id);
}
});
$(".model").each(function() {
if(this.checked==true){
var driver_model=this.id.split("::");
var driver=driver_model[0];
var model=driver_model[1];
models.push(model);
}
});
$(".speed").each(function() {
if(this.checked==true){
var driver_model=this.id.split("::");
var driver=driver_model[0];
var model=driver_model[1];
var speed=driver_model[2];
var model_speed=model+"::"+speed;
speeds.push(model_speed);
}
});
if(drivers.length <= 0)
{
$(".driver").each(function() {
drivers.push(this.id);
});
}
if(models.length <= 0)
{
$(".model").each(function() {
var driver_model=this.id.split("::");
var driver=driver_model[0];
var model=driver_model[1];
models.push(model);
});
}
if(speeds.length <= 0)
{
$(".speed").each(function() {
var driver_model=this.id.split("::");
var driver=driver_model[0];
var model=driver_model[1];
var speed=driver_model[2];
var model_speed=model+"::"+speed;
speeds.push(model_speed);
});
}
}
function add_test(btn_id)
{
var rtn=valid_retention();
if(rtn==false)
{
return false;
}
var rtn=valid_testname();
if(rtn==false)
{
return false;
}
var rtn=valid_common("unmatch");
if(rtn==false)
{
return false;
}
var rtn=valid_match();
if(rtn==false)
{
return false;
}
var rtn=valid_distro();
if(rtn==false)
{
return false;
}
var rtn=valid_kernel();
if(rtn==false)
{
return false;
}
/*
var rtn=valid_spreadname();
if(rtn==false)
{
return false;
} */
if(document.getElementById("write2googlesheet").checked==true)
{
var rtn=valid_sheetname();
}
if(rtn==false)
{
return false;
}
var rtn=valid_tier();
if(rtn==false)
{
return false;
}
var rtn=valid_modelblack();
if(rtn==false)
{
return false;
}
var rtn=valid_runtestopt();
if(rtn==false)
{
return false;
}
var con=confirm("really add this test?");
if(con==false)
{
return false;
}
disable_all_buttons();
var d_content=document.getElementById("AnyDriver").value;
if(d_content!=null && d_content!="")
{
drivers=d_content;
var m_content=document.getElementById("AnyModel").value;
if(m_content==null || m_content=="")
{
models="any";
}else
{
models=m_content;
}
var s_content=document.getElementById("AnySpeed").value;
if(s_content==null || s_content=="")
{
speeds=models+"::any";
}else
{
speeds=models+"::"+s_content;
}
}else
{
get_driver_model_speed();
}
var testname=document.getElementById("testname").value;
var match=document.getElementById("match").value;
var unmatch=document.getElementById("unmatch").value;
var distro=document.getElementById("distro").value;
var kernel=document.getElementById("kernel").value;
if(document.getElementById("write2googlesheet").checked==true)
{
var spreadname=document.getElementById("spreadname").value;
var sheetname=document.getElementById("sheetname").value;
}
else
{
var spreadname="";
var sheetname="";
}
var casekeyword=document.getElementById("casekeywords").value;
var unmatchcase=document.getElementById("unmatchcase").value;
var tier=document.getElementById("tiers").value;
var modelblack=document.getElementById("modelblacks").value;
var runtestopt=document.getElementById("runtestopt").value;
var whiteboard=document.getElementById("whiteboard").value;
var retention=document.getElementById("retention-tag").value;
var parameters="testname="+testname+"&match="+match+"&unmatch="+unmatch+"&distro="+distro+"&kernel="+kernel+"&spreadname="+spreadname+"&sheetname="+sheetname+"&casekeyword="+casekeyword+"&tier="+tier+"&modelblack="+modelblack+"&runtestopt="+runtestopt+"&whiteboard="+whiteboard+"&driver="+drivers+"&model="+models+"&speed="+speeds+"&retention="+retention+"&unmatchcase="+unmatchcase;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("line").innerHTML=xmlhttp.responseText;
//document.getElementById("debug").value="";
alert("succeeded!");
enable_all_buttons();
reset_all_checkbox();
}
else if (xmlhttp.readyState==4 && xmlhttp.status==500)
{
//document.getElementById("debug").value=xmlhttp.responseText;
alert("failed! unknown reason.");
enable_all_buttons();
reset_all_checkbox();
}else if (xmlhttp.readyState==4 && xmlhttp.status==501)
{
//document.getElementById("debug").value=xmlhttp.responseText;
alert("failed! unlogin.");
enable_all_buttons();
//reset_all_checkbox();
}
}
xmlhttp.open("GET","add_test.php?"+parameters,true);
xmlhttp.send();
}
function searchJob(id){
var rtn=valid_searchkey("search_key");
if(rtn==false)
{
return false;
}
var key=document.getElementById("search_key").value;
var parameters="key="+key;
disable_all_buttons();
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
result=xmlhttp.responseText;
if(result=="")
{
result="No Matching";
}
alert(result);
enable_all_buttons();
}
else if (xmlhttp.readyState==4 && xmlhttp.status==500)
{
alert(xmlhttp.responseText);
//alert("failed! unknown reason");
enable_all_buttons();
}
else if (xmlhttp.readyState==4 && xmlhttp.status==501)
{
//document.getElementById("debug").value=xmlhttp.responseText;
alert("failed! unlogin.");
enable_all_buttons();
}
}
xmlhttp.open("GET","search_job.php?"+parameters,true);
xmlhttp.send();
}
function removeByValue(arr, val) {
for(var i = 0; i < arr.length; i++) {
if(arr[i] == val) {
arr.splice(i, 1);
break;
}
}
}
function reset_all_checkbox()
{
/*
$("input[type='checkbox']").each(function() {
this.checked = false;
});
$(":checkbox[id^='"+match+"']").each(function() {
this.checked = false;
});*/
document.getElementById("all_driver").checked = false;
document.getElementById("all_model").checked = false;
document.getElementById("all_speed").checked = false;
$(".driver").each(function() {
this.checked=false;
});
$(".model").each(function() {
this.checked=false;
});
$(".speed").each(function() {
this.checked=false;
});
}
function distro_value_change(value)
{
//var index=value.search(/(RHEL)-(\d\.\d)/i);
var ary=/(RHEL)-(\d\.\d)/i.exec(value);
if(ary != null && ary.length >= 3)
{
spread_name=ary[1]+ary[2];
spread_name=spread_name.toUpperCase();
spread_name=spread_name+"_Test_Report";
document.getElementById("spreadname").value=spread_name;
}
else
{
document.getElementById("spreadname").value="";
}
}
$(document).ready(function(){
$("#casekeywords").change(function(){
$.post("./show_cases.php",{
cases:this.value,
tiers:$("#tiers").val(),
unmatchcase:$("#unmatchcase").val()
},
function(data,status){
document.getElementById("cases").value=data;
$("#cases").dialog({ autoOpen: false, height:750, width:1500, modal:true,
buttons:{
"OK":function(){$(this).dialog("close");}
}
});
$("#cases").dialog( "open" );
});
});
$("#tiers").change(function(){
$.post("./show_cases.php",{
cases:$("#casekeywords").val(),
tiers:this.value,
unmatchcase:$("#unmatchcase").val()
},
function(data,status){
document.getElementById("cases").value=data;
$("#cases").dialog({ autoOpen: false, height:750, width:1500, modal:true,
buttons:{
"OK":function(){$(this).dialog("close");}
}
});
$("#cases").dialog( "open" );
});
});
$("#unmatchcase").change(function(){
$.post("./show_cases.php",{
cases:$("#casekeywords").val(),
tiers:$("#tiers").val(),
unmatchcase:this.value
},
function(data,status){
document.getElementById("cases").value=data;
$("#cases").dialog({ autoOpen: false, height:750, width:1500, modal:true,
buttons:{
"OK":function(){$(this).dialog("close");}
}
});
$("#cases").dialog( "open" );
});
});
$("#write2googlesheet").change(function(){
if(this.checked==true)
{
document.getElementById("sheetname_hidden").hidden=false;
}else
{
document.getElementById("sheetname_hidden").hidden=true;
}
});
$("#write2googlesheet").change();
});
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<!--tr>
<td align="right" class="biaoti" height="60"><a href="http://<?php echo $_SERVER['SERVER_ADDR'];?>/job_scheduler/ci/log.txt">CI Log</a></td>
</tr-->
<tr>
<td align="center" class="biaoti" height="60">Setting</td>
</tr>
</table>
<div class="error" style="font-size: 12px;">
Note:
</br>
1. "*" is mandatory.
</br>
2. It will run test on all drivers,models,speeds contained in driver-Prototype pool by default.
</br>
3. If you want to choose driver,model,speed to test, specify system pool using "Match" keyword, and use "Show NICs" to display all driver,model,speed contained in this pool and choose from the list.
</br>
4. You can input multiple values in "Case Keywords, Tiers, Model Blacklist", you must separate each value by comma.
</div>
<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">Test Name</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">Match</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">UnMatch</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">Distro</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">Kernel</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">
<input type="checkbox" id="write2googlesheet" checked>Spread Name
</td>
</tr>
<tr>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="testname">
<span class="error">*</span>
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="match" value="driver-Prototype">
<span class="error">*</span>
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="unmatch">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="distro" onkeyup="distro_value_change(this.value)">
<span class="error">*</span>
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="kernel">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="spreadname" >
<!--input style="width:90%" type="text" id="spreadname" readonly="readonly"-->
<!--span class="error">*</span-->
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Sheet Name</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Case Keywords</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Tiers</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Unmatch Case Keywords</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Model Blacklist</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Runtest Option</td>
</tr>
<tr>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="sheetname">
<span class="error" id="sheetname_hidden">*</span>
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="casekeywords">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="tiers" value="Tier1,Tier2">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="unmatchcase" value="macsec,macvtap,macvlan">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="modelblacks">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="runtestopt" value='--param=SET_DMESG_CHECK_KEY=yes --kdump=netqe-bj.usersys.redhat.com:/home/kdump/vmcore --param=NAY=yes --kernel-options=\"selinux=1 enforcing=0\" --kernel-options-post=\"selinux=1 enforcing=1\"'>
<span class="error">*</span>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Retention Tag</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Whiteboard</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Driver (any = Random Choice A Driver)</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Model (any = Random Choice A Model)</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Speed (any = Random Choice A Speed)</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Reserved</td>
</tr>
<tr>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<select style="width:91%;height:30px" name="retention-tag" id="retention-tag">
<option value="null">select a retention-tag :</option>
<option value="scratch">scratch</option>
<option value="60days">60days</option>
<option value="120days">120days</option>
<option value="active">active</option>
<option value="active+1">active+1</option>
<option value="audit">audit</option>
</select>
<span class="error">*</span>
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="whiteboard">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="AnyDriver">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="AnyModel">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="AnySpeed">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="reserved">
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:91%;height:30px" id="cancel_a_job" type="button" value="Cancel A Job ->" onclick="cancelAJob(this.id)">
</form>
</td>
<td width="15%" height="20px" class="btbg1">
<input style="width:90%;height:20px" type="text" id="job_to_cancel" value="J:xxxxxxx">
</td>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:91%;height:30px" id="reschedule_job" type="button" value="Reschedule A Job ->" onclick="rescheduleJob(this.id)">
</form>
</td>
<td width="15%" height="20px" class="btbg1">
<input style="width:90%;height:20px" type="text" id="job_to_reschedule" value="J:xxxxxxx">
</td>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:91%;height:30px" id="search_job" type="button" value="Search ->" onclick="searchJob(this.id)">
</form>
</td>
<td width="15%" height="20px" class="btbg1">
<input style="width:90%;height:20px" type="text" id="search_key" value="">
</td>
</tr>
<tr>
<td width="15%" height="20px" class="btbg1">
<input style="width:91%;height:30px" id="bt_list_test1" type="button" value="Show Running Tests" onclick="list_test('yes')">
</td>
<td width="15%" height="20px" class="btbg1">
<input style="width:91%;height:30px" id="bt_list_test" type="button" value="Show All Tests" onclick="list_test('no')">
</td>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:91%;height:30px" id="bt_get_all_nic" type="button" value="Show NICs" onclick="fetch_nic_info(this.id)">
</form>
</td>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:91%;height:30px" id="bt_add_test" type="button" value="Add Test" onclick="add_test(this.id)">
</form>
</td>
<td width="15%" height="20px" class="btbg1">
</td>
<td width="15%" height="20px" class="btbg1">
</td>
</tr>
</table>
<textarea id="cases" title="Cases Selected" hidden="hidden" rows="100" cols="260"></textarea>
<!--input type=text" hidden="hidden" id="partial_cancel_testname"/-->
<div id="cancel_panel" title="Partial Cancel or Reschedule" hidden="hidden" rows="100" cols="260">
Test Name : <input type="text" style="width:30%" id="partial_cancel_testname" readonly="readonly">
</p>
Driver : <input type="text" style="width:30%" id="c_driver">
</p>
Model : <input type="text" style="width:30%" id="c_model">
</p>
Speed : <input type="text" style="width:30%" id="c_speed">
</p>
List Name : <input type="text" style="width:30%" id="c_list">
</p>
Test Side :
<select style="width:31%;height:30px" name="testside" id="c_testside">
<option value=""></option>
<option value="multihost_client">multihost_client</option>
<option value="multihost_server">multihost_server</option>
<option value="singlehost">singlehost</option>
</select>
</p>
<input style="width:39%;height:30px;" type="button" value="Cancel" id="btn_partial_cancel_test" onclick="partial_cancel_test_step2()"/>
</p>
<input style="width:39%;height:30px;" type="button" value="Reschedule" id="btn_partial_reschedule_test" onclick="partial_reschedule_test_step2()"/>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" class="biaoti" height="60">Tests</td>
</tr>
</table>
<table id="test_list" width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" class="biaoti" height="60">NICs</td>
</tr>
</table>
<table id="nicinfo" width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
</table>
</body>
</html>
login.php – session mysql
<?php
include 'include.php';
$name = $_GET["username"];
$pwd = md5($_GET["password"]);
/*foreach($_GET as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}*/
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
//file_put_contents('log.text',"abc", FILE_APPEND);
//die("连接失败: " . mysqli_connect_error());
header('HTTP/1.1 501 Internal Server Error');
exit(501);
}
$where_statement="where name='".$name."' and password='".$pwd."'";
$sql = "SELECT name,priority FROM user $where_statement";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$rtn=200;
header('HTTP/1.1 200 Internal Server Error');
session_start();
while($row = mysqli_fetch_assoc($result)) {
$priority=$row["priority"];
$_SESSION["admin"] = $priority;
$_SESSION["username"] = $name;
$_SESSION["password"] = $pwd;
}
}else{
$rtn=501;
header('HTTP/1.1 501 Internal Server Error');
//file_put_contents('log.text',"abc", FILE_APPEND);
}
mysqli_close($conn);
exit($rtn);
?>
logout.php
<?php
/*foreach($_GET as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}*/
$rtn=200;
header('HTTP/1.1 200 Internal Server Error');
session_start();
unset($_SESSION['admin']);
unset($_SESSION["username"]);
unset($_SESSION["password"]);
exit($rtn);
?>
list_test.php – Array
<?php
$show_running_only=$_GET["showrunningonly"];
#$output = passthru('python list_test.py',$res);
$output = exec('python list_test.py',$out,$res);
$all_tests = explode(",",$output);
$len=count($all_tests);
$server_addr=$_SERVER['SERVER_ADDR'];
echo <<<EOF
<tr>
<td width="20%" class="btbg font-center tabtxt2" rowspan="1">Test Name</td>
<td width="20%" class="btbg font-center tabtxt2" rowspan="1">Duration</td>
<td width="10%" class="btbg font-center tabtxt2" rowspan="1">Configuration</td>
<td width="10%" class="btbg font-center tabtxt2" rowspan="1">Status</td>
<td width="40%" class="btbg font-center tabtxt2" rowspan="1">Management</td>
</tr>
EOF;
function get_color()
{
static $index=0;
$all_colors=array("AliceBlue","Azure");
$color=$all_colors[$index];
$index++;
if($index==count($all_colors))
{
$index=0;
}
return $color;
}
for($i=0;$i<$len;$i++)
{
$color=get_color();
$test_status=$all_tests[$i];
$test_status = explode("::",$test_status);
$test = $test_status[0];
$status = $test_status[1];
$time = $test_status[2];
if($show_running_only=="yes" and $status=="completed")
{
continue;
}
if($test=='')
{
continue;
}
if($status=='completed')
{
$status_info="<vi style='color:green;font-size:12px;'>COMPLETED</vi>";
}else if($status=='pause')
{
$status_info="<vi style='color:blue;font-size:12px;'>PAUSING</vi>";
}else
{
$status_info="<vi style='color:red;font-size:12px;'>RUNNING</vi>";
}
echo "<tr>";
echo '<td width="20%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="1">';
echo $test;
echo '</td>';
echo '<td width="20%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="1">';
echo $time;
echo '</td>';
echo '<td width="10%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="1">';
echo '<a href="http://'.$server_addr.'/job_scheduler/tests/'.$test.'/config">configuration</a>';
echo '</td>';
echo '<td width="10%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="1">';
#echo '<a href="http://'.$server_addr.'/job_scheduler/tests/'.$test.'/status">'.$status_info.'</a>';
echo '<a href="http://'.$server_addr.'/job_scheduler/show_test.php?testname='.$test.'">'.$status_info.'</a>';
echo '</td>';
echo '<td width="40%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="1">';
echo '<input type="button" onclick="cancel_test(this.id)" value="Cancel" id="' .$test. '">';
echo '<input type="button" onclick="delete_test(this.id)" value="Delete" id="' .$test. '">';
echo '<input type="button" onclick="partial_cancel_test(this.id)" value="Partial Cancel/Reschedule" id="' .$test. '">';
if($status=='running')
{
echo '<input type="button" onclick="switch_test(this.id,false)" value="Pause" id="' .$test. '">';
}else if($status=='pause')
{
echo '<input type="button" onclick="switch_test(this.id,true)" value="Resume" id="' .$test. '">';
}
echo '</td>';
echo "</tr>";
}
?>
add_test.php – session passthru() exec() vardump() Http-Return-Code
passthru()
function passthru(string $command,int[optional] $return_value)
passthru直接将结果输出到浏览器,不需要使用 echo 或 return 来查看结果
<?php
echo nl2br("passthru\n");
passthru("ls",$rtn);
echo "</br>";
print_r($rtn);
?>
passthru
Cat.png cat.png job_scheduler pChart.tar.gz test.php
0
# 也可以把输出保存到变量
<?php
$output = passthru("ls",$rtn);
echo "</br>";
print_r($output);
?>
exec()
function exec(string $command,array[optional] $output,int[optional] $return_value)
exec 执行系统外部命令时不会输出结果,而是返回结果的最后一行,如果你想得到结果你可以使用第二个参数,
让其输出到指定的数组,此数组一个记录代表输出的一行,即如果输出结果有20行,则这个数组就有20条记录。
第三个参数用来取得命令执行的状态码,通常执行成功都是返回0。
<?php
echo "Hello PHP";
echo "</br>";
echo exec("ls",$file,$rtn);
echo "</br>";
print_r($file);
echo "</br>";
print_r($rtn);
?>
Hello PHP
test.php
Array ( [0] => Cat.png [1] => cat.png [2] => job_scheduler [3] => pChart.tar.gz [4] => test.php )
0
var_dump()
<?php
// 防止全局变量造成安全隐患
$admin = -1;
// 启动会话,这步必不可少
session_start();
// 判断是否登陆
if (!(isset($_SESSION["admin"]) && $_SESSION["admin"] === "0")) {
$_SESSION["admin"] = -1;
header('HTTP/1.1 501 unlogin');
exit(501);
}
$username = $_SESSION["username"];
$testname = $_GET["testname"];
$match = $_GET["match"];
$unmatch = $_GET["unmatch"];
$distro = $_GET["distro"];
$kernel = $_GET["kernel"];
$spreadname = $_GET["spreadname"];
$sheetname = $_GET["sheetname"];
$casekeyword = $_GET["casekeyword"];
$unmatchcase = $_GET["unmatchcase"];
$tier = $_GET["tier"];
$modelblack = $_GET["modelblack"];
$runtestopt = $_GET["runtestopt"];
$whiteboard = $_GET["whiteboard"];
$driver = $_GET["driver"];
$model = $_GET["model"];
$speed = $_GET["speed"];
$retention = urlencode($_GET["retention"]);
#var_dump($_GET);
#file_put_contents('log.text',var_dump($_GET), FILE_APPEND);
$parameters='"'.$testname.'" "'.$match.'" "'.$unmatch.'" "'.$distro.'" "'.$kernel.'" "'.$spreadname.'" "'.$sheetname.'" "'.$casekeyword.'" "'.$tier.'" "'.$runtestopt.'" "'.$modelblack.'" "'.$whiteboard.'" "'.$driver.'" "'.$model.'" "'.$speed.'" "'.$retention.'" "'.$unmatchcase.'" "'.$username.'"';
#$output = exec('python add_test.py '.$parameters,$out,$res);
$output = passthru('python add_test.py '.$parameters,$res);
#var_dump($output);
#echo "$res";
if($res == 0)
{
header('HTTP/1.1 200 OK');
}
else
{
header('HTTP/1.1 500 Internal Server Error');
}
exit($res);
?>
cancel_a_job.php – header()
<?php
// 防止全局变量造成安全隐患
$admin = -1;
// 启动会话,这步必不可少
session_start();
// 判断是否登陆
if (!(isset($_SESSION["admin"]) && $_SESSION["admin"] === "0")) {
$_SESSION["admin"] = -1;
header('HTTP/1.1 501 unlogin');
exit(501);
}
$jobid = $_GET["jobid"];
#$output = passthru('python list_test.py',$res);
$output = exec('bkr job-cancel "'.$jobid.'"',$out,$res);
echo "$output";
if($res == 0)
{
header('HTTP/1.1 200 OK');
}
else
{
header('HTTP/1.1 500 Internal Server Error');
}
?>
generate_nic_info.php – json_decode() dict
<?php
$match = $_GET["match"];
$unmatch = $_GET["unmatch"];
function get_color()
{
static $index=0;
$all_colors=array("AliceBlue","Azure");
$color=$all_colors[$index];
$index++;
if($index==count($all_colors))
{
$index=0;
}
return $color;
}
#echo date("Y-m-d H:i:s");
$output = exec('python generate_nic_info.py "'.$match. '" "' . $unmatch . '"',$out,$res);
#echo $output;
#echo date("Y-m-d H:i:s");
$all_datas=json_decode($output,true);
#var_dump($all_datas);
#$len=count($all_datas);
$row_spans=array();
$need_print=array();
echo <<<EOF
<tr>
<td width="30%" class="btbg font-center tabtxt2" rowspan="1">
<form>
<input type="checkbox" id="all_driver" value="all_driver" onclick="click_all_driver()">Driver
</form>
</td>
<td width="30%" class="btbg font-center tabtxt2" rowspan="1">
<form>
<input type="checkbox" id="all_model" value="all_model" onclick="click_all_model()">Model
</form>
</td>
<td width="30%" class="btbg font-center tabtxt2" rowspan="1">
<form>
<input type="checkbox" id="all_speed" value="all_speed" onclick="click_all_speed()">Speed
</form>
</td>
</tr>
EOF;
foreach($all_datas as $driver=>$model_speed)
{
$driver_row_span=0;
$len_model_speed=count($model_speed);
$need_print[$driver]="yes";
for($j=0;$j<$len_model_speed;$j++)
{
$model_as_key=$model_speed[$j];
foreach($model_as_key as $model=>$speed)
{
$model_row_span=0;
$need_print[$model]="yes";
$len_speed=count($speed);
for($k=0;$k<$len_speed;$k++)
{
$driver_row_span++;
$model_row_span++;
}
$row_spans[$model]=$model_row_span;
}
}
$row_spans[$driver]=$driver_row_span;
}
foreach($all_datas as $driver=>$model_speed)
{
$driver_row_span=$row_spans[$driver];
$len_model_speed=count($model_speed);
$color=get_color();
for($j=0;$j<$len_model_speed;$j++)
{
$model_as_key=$model_speed[$j];
foreach($model_as_key as $model=>$speed)
{
$model_row_span=$row_spans[$model];
$model_need_print=$need_print[$model];
#$len_speed=count($speed);
#for($k=0;$k<$len_speed;$k++)
foreach($speed as $sp=>$rhel_sriov)
{
$other_info=$rhel_sriov[0];
$speed_display=$sp;
if($other_info!="None")
{
$speed_display=$speed_display." "."<vi style='color:red;font-size:10px'>[!".$other_info."]</vi>";
}
$driver_need_print=$need_print[$driver];
$model_need_print=$need_print[$model];
#$sp=$speed[$k];
echo "<tr>";
if($driver_need_print=="yes")
{
echo '<td width="30%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="' . $driver_row_span . '"><form><input class="driver" type="checkbox" id="' . $driver . '" value="' . $driver . '" onchange="ganged(1,this.id)">' . $driver . "</form></td>";
$need_print[$driver]="no";
}
if($model_need_print=="yes")
{
echo '<td width="30%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="' . $model_row_span . '"><form><input class="model" type="checkbox" id="' .$driver."::".$model . '" value="' .$driver."::".$model . '" onchange="ganged(2,this.id)">' . $model . "</from></td>";
$need_print[$model]="no";
}
echo '<td width="30%" style="background:'.$color.'" class="font-center tabtxt2" rowspan="' . '1' . '"><form><input class="speed" type="checkbox" id="'.$driver."::".$model."::".$sp . '" value="'.$driver."::".$model."::".$sp .'" onchange="ganged(3,this.id)">' . $speed_display . "</form></td>";
echo "</tr>";
}
}
}
}
#echo date("Y-m-d H:i:s");
?>
partial_cancel_job.php – file_put_contents()
<?php
// 防止全局变量造成安全隐患
$admin = -1;
// 启动会话,这步必不可少
session_start();
// 判断是否登陆
if (!(isset($_SESSION["admin"]) && $_SESSION["admin"] === "0")) {
$_SESSION["admin"] = -1;
header('HTTP/1.1 501 unlogin');
exit(501);
}
$testname = $_GET["testname"];
$driver = $_GET["driver"];
$model = $_GET["model"];
$speed = $_GET["speed"];
$list = $_GET["list"];
$testside = $_GET["testside"];
if($driver == "")
{
$driver=".*";
}
if($model == "")
{
$model=".*";
}
if($speed == "")
{
$speed=".*";
}
if($list == "")
{
$list=".*";
}
if($testside == "")
{
$testside=".*";
}
#$output = passthru('python list_test.py',$res);
#file_put_contents('log.text',"canceltestp", FILE_APPEND);
#file_put_contents('log.text',$testname, FILE_APPEND);
#file_put_contents('log.text',$driver, FILE_APPEND);
#file_put_contents('log.text',$model, FILE_APPEND);
#file_put_contents('log.text',$speed, FILE_APPEND);
#file_put_contents('log.text',$testside, FILE_APPEND);
#file_put_contents('log.text',$list, FILE_APPEND);
#file_put_contents('log.text',var_dump($_GET), FILE_APPEND);
$output = exec('python cancel_test_by_dmstl.py "'.$testname.'" "'.$driver.'" "'.$model.'" "'.$speed.'" "'.$testside.'" "'.$list.'"',$out,$res);
if($res == 0)
{
header('HTTP/1.1 200 OK');
}
else
{
header('HTTP/1.1 500 Internal Server Error');
}
?>
mysql and pchard
[liliang@MacBook ~/work/kernel/networking/tools/job_scheduler]$ cat query_system_history_status.php
<?php
include 'include.php';
function get_color()
{
static $index=0;
$all_colors=array("AliceBlue","Azure");
$color=$all_colors[$index];
$index++;
if($index==count($all_colors))
{
$index=0;
}
return $color;
}
$sysname = $_GET["sysname"];
$testname = $_GET["testname"];
$starttime = $_GET["starttime"];
$endtime = $_GET["endtime"];
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}
$where_statement="where sysname='".$sysname."'";
if($testname!="")
{
$where_statement="$where_statement" . " and testname='" . $testname."'";
}
if($starttime!="")
{
$where_statement="$where_statement" . " and time>='" . $starttime."'";
}
if($endtime!="")
{
$where_statement="$where_statement" . " and time<='" . $endtime."'";
}
$sql = "SELECT sysname,status,user,testname,time FROM system_status ".$where_statement." order by id desc";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
echo <<<EOF
<tr>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">System Name</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Status</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">User</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Scheduler Test Name</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Time</td>
</tr>
EOF;
while($row = mysqli_fetch_assoc($result))
{
#foreach($row as $x=>$x_value)
#{
# if($x=="duration")
# {
#
# }
#
# }
$color=get_color();
echo "<tr>";
echo '<td width="30%" style="background:'.$color.'" class="font-center tabtxt2">'.$row["sysname"].'</td>';
echo '<td width="10%" style="background:'.$color.'" class="font-center tabtxt2">'.$row["status"].'</td>';
echo '<td width="10%" style="background:'.$color.'" class="font-center tabtxt2">'.$row["user"].'</td>';
echo '<td width="20%" style="background:'.$color.'" class="font-center tabtxt2">'.$row["testname"].'</td>';
echo '<td width="30%" style="background:'.$color.'" class="font-center tabtxt2">'.$row["time"].'</td>';
echo "</tr>";
}
}
mysqli_close($conn);
?>
[liliang@MacBook ~/work/kernel/networking/tools/job_scheduler]$ cat query_system_use_rate.php
<?php
include 'include.php';
include("job_statistic/pChart/pData.class");
include("job_statistic/pChart/pChart.class");
function changeTimeType($seconds){
if ($seconds >3600){
$hours =intval($seconds/3600);
$minutes = $seconds % 3600;
$time = $hours.":".gmstrftime('%M:%S',$minutes);
}else{
$time = gmstrftime('%H:%M:%S',$seconds);
}
return $time;
}
function get_color()
{
static $index=0;
$all_colors=array("AliceBlue","Azure");
$color=$all_colors[$index];
$index++;
if($index==count($all_colors))
{
$index=0;
}
return $color;
}
$sysname = $_GET["sysname"];
$testname = $_GET["testname"];
$starttime = $_GET["starttime"];
$endtime = $_GET["endtime"];
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}
$where_statement="where sysname='".$sysname."'";
if($testname!="")
{
$where_statement="$where_statement" . " and testname='" . $testname."'";
}
if($starttime!="")
{
$where_statement="$where_statement" . " and time>='" . $starttime."'";
}
if($endtime!="")
{
$where_statement="$where_statement" . " and time<='" . $endtime."'";
}
$sql = "SELECT sysname,status,user,testname,time FROM system_status ".$where_statement." order by id desc";
$result = mysqli_query($conn, $sql);
$data=array();
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
array_push($data,$row);
}
}
mysqli_close($conn);
$length=count($data);
if($length<=0)
{
exit;
}
echo <<<EOF
<tr>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">System Name</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Free</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Used By Scheduler</td>
<td width="15%" height="20px" class="btbg1 tabtxt1" rowspan="1">Used By Other People</td>
</tr>
EOF;
$free_time=0.0;
$scheduler_time=0.0;
$other_people_time=0.0;
for($i=$length-1;$i>=0;$i--)
{
$row=$data[$i];
if($i==0)
{
$date=date_create();
$et=date_timestamp_get($date);
$st=date_timestamp_get(date_create($row["time"]));
$du=$et-$st;
}else
{
$next_row=$data[$i-1];
$et=date_timestamp_get(date_create($next_row["time"]));
$st=date_timestamp_get(date_create($row["time"]));
$du=$et-$st;
}
if($row["status"]=="Free")
{
$free_time+=$du;
}else if($row["user"]!="")
{
$other_people_time+=$du;
}else
{
$scheduler_time+=$du;
}
}
$color=get_color();
echo "<tr>";
echo '<td width="30%" style="background:'.$color.'" class="font-center tabtxt2">'.$sysname.'</td>';
echo '<td width="10%" style="background:'.$color.'" class="font-center tabtxt2">'.changeTimeType($free_time).'</td>';
echo '<td width="10%" style="background:'.$color.'" class="font-center tabtxt2">'.changeTimeType($scheduler_time).'</td>';
echo '<td width="20%" style="background:'.$color.'" class="font-center tabtxt2">'.changeTimeType($other_people_time).'</td>';
echo "</tr>";
// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array($free_time,$scheduler_time,$other_people_time),"Serie1");
$DataSet->AddPoint(array("Free","Scheduler","Others"),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test = new pChart(600,400);
$Test->loadColorPalette("/var/www/html/job_scheduler/job_statistic/pChart/rgb.txt");
$Test->drawFilledRoundedRectangle(7,7,593,393,5,240,240,240);
$Test->drawRoundedRectangle(5,5,595,395,5,230,230,230);
// Draw the pie chart
$Test->setFontProperties("/var/www/html/job_scheduler/job_statistic/pChart/tahoma.ttf",8);
$Test->setShadowProperties(2,2,200,200,200);
$Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet->GetDataDescription(),250,200,150,PIE_PERCENTAGE_LABEL,10);
$Test->drawPieLegend(500,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
#$Test->Render("example14.png");
$imageFile = "images/" . $sysname . ".png";
if(file_exists($imageFile)==1)
{
if(!unlink($imageFile))
{
echo "delete failed";
}
}
$Test->Render($imageFile);
echo "<tr>";
echo '<td width="100%" colspan="4" style="background:'.$color.'" class="font-center tabtxt2">';
echo "<img src='".$imageFile."' id='pie'>";
echo '</td>';
echo "</tr>";
?>
register.php
<?php
include 'include.php';
function changeTimeType($seconds){
if ($seconds >3600){
$hours =intval($seconds/3600);
$minutes = $seconds % 3600;
$time = $hours.":".gmstrftime('%M:%S',$minutes);
}else{
$time = gmstrftime('%H:%M:%S',$seconds);
}
return $time;
}
$name = $_GET["username"];
$pwd = md5($_GET["password"]);
/*foreach($_GET as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}*/
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
//file_put_contents('log.text',"abc", FILE_APPEND);
//die("连接失败: " . mysqli_connect_error());
header('HTTP/1.1 502 Internal Server Error');
exit(502);
}
$where_statement="where name='".$name."'";
$sql = "SELECT name FROM user $where_statement";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$rtn=501;
header('HTTP/1.1 501 Internal Server Error');
}else{
file_put_contents('log.text',"abc", FILE_APPEND);
$sql_insert="insert into user(name,password) values('".$name."','".$pwd."')";
if(mysqli_query($conn, $sql_insert)){
$rtn=200;
header('HTTP/1.1 200 Internal Server Error');
}else{
$rtn=500;
header('HTTP/1.1 500 Internal Server Error');
}
}
mysqli_close($conn);
exit($rtn);
?>
system_history_status.php
<!DOCTYPE html>
<html>
<head>
<title>System Historical Status</title>
<link rel="icon" href="cat3.png" />
<link rel="stylesheet" type="text/css" href="./styles.css">
<style>
.error {color: #FF0000;}
.ui-dialog-title {
font-weight: bold;
text-align:center;
}
.ui-dialog-buttonpane {
background:black;
}
#cases {
background:black;
color:green;
font-size:14px;
}
</style>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script type="text/javascript"src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<script type="text/javascript">
function query_system_history_status()
{
var rtn=valid_input("sysname");
if(rtn==false)
{
return false;
}
var rtn=valid_time("starttime");
if(rtn==false)
{
return false;
}
var rtn=valid_time("endtime");
if(rtn==false)
{
return false;
}
disable_all_buttons();
var sysname=document.getElementById("sysname").value;
var testname=document.getElementById("testname").value;
var starttime=document.getElementById("starttime").value;
var endtime=document.getElementById("endtime").value;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("line").innerHTML=xmlhttp.responseText;
document.getElementById("history_item").innerHTML=xmlhttp.responseText;
enable_all_buttons();
}
//document.getElementById("distro").innerHTML=xmlhttp1.status;
}
xmlhttp.open("GET","query_system_history_status.php?sysname="+sysname+"&testname="+testname+"&starttime="+starttime+"&endtime="+endtime,true);
xmlhttp.send();
}
function query_system_use_rate()
{
var rtn=valid_input("sysname");
if(rtn==false)
{
return false;
}
var rtn=valid_time("starttime");
if(rtn==false)
{
return false;
}
var rtn=valid_time("endtime");
if(rtn==false)
{
return false;
}
disable_all_buttons();
var sysname=document.getElementById("sysname").value;
var testname=document.getElementById("testname").value;
var starttime=document.getElementById("starttime").value;
var endtime=document.getElementById("endtime").value;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("history_item").innerHTML=xmlhttp.responseText;
//document.getElementById("pie").src=xmlhttp.responseText;
enable_all_buttons()
}
//document.getElementById("distro").innerHTML=xmlhttp1.status;
}
xmlhttp.open("GET","query_system_use_rate.php?sysname="+sysname+"&testname="+testname+"&starttime="+starttime+"&endtime="+endtime,true);
xmlhttp.send();
}
function disable_all_buttons()
{
$("input[type='button']").each(function() {
this.disabled = true;
});
}
function enable_all_buttons()
{
$("input[type='button']").each(function() {
this.disabled = false;
});
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" class="biaoti" height="60">System Historical Status</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">System Name</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">Test Name</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">Start Time</td>
<td width="15%" height="20px" height="20px" class="btbg1 tabtxt1" rowspan="1">End Time</td>
</tr>
<tr>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="sysname">
<span class="error">*</span>
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="testname">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="starttime">
</td>
<td width="15%" height="20px" class="btbg1 font-center tabtxt2" rowspan="1">
<input style="width:90%;height:20px" type="text" id="endtime">
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:100%;height:30px" id="bt_add_test" type="button" value="Query Historical Status" onclick="query_system_history_status()">
</form>
</td>
<td width="15%" height="20px" class="btbg1">
<form>
<input style="width:100%;height:30px" id="bt_add_test" type="button" value="Percentage" onclick="query_system_use_rate()">
</form>
</td>
</tr>
</table>
<table id="history_item" width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
</table>
<!--table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">
<tr>
<td class="btbg2" id="default_pie">
<img src='' id='pie'>
</td>
</tr>
</table-->
</body>
</html>
AJAX POST
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行的代码
xmlhttp=new XMLHttpRequest();
}
else
{
//IE6, IE5 浏览器执行的代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","add_test_post.php",true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//document.getElementById("line").innerHTML=xmlhttp.responseText;
//document.getElementById("debug").value="";
alert("succeeded!");
enable_all_buttons();
reset_all_checkbox();
}
else if (xmlhttp.readyState==4 && xmlhttp.status==500)
{
//document.getElementById("debug").value=xmlhttp.responseText;
alert("failed! unknown reason.");
enable_all_buttons();
reset_all_checkbox();
}else if (xmlhttp.readyState==4 && xmlhttp.status==501)
{
//document.getElementById("debug").value=xmlhttp.responseText;
alert("failed! unlogin.");
enable_all_buttons();
//reset_all_checkbox();
}
}
xmlhttp.send(parameters);