Jump to content

Cached check box and regex


zangetsu

Recommended Posts

Hi all,

 

  I have two problems one of them I have a form that takes few fields one of them is the Host and i made a regex to take only Ip's and an if statement if on submit everything is ok send else return an error.

 

Next is I have a Dynamic check box. I want when some one clicks on a check box and submits, instead of erasing it after preforming the submit, it should be there.

 

This is my Code

 

<script language='JavaScript'>
function checkAll(chk) {
  chk = document.getElementsByName(chk);
    for (i = 0; i < chk.length; i++)
    chk[i].checked = true ;
  }
function uncheckAll(chk) {
  chk = document.getElementsByName(chk);
    for (i = 0; i < chk.length; i++)
    chk[i].checked = false ;
  }


</script>


<?php
$add = $_POST['server'];

//Database
$server = sqlite_open('server.sqlite');


//Sending Adding the Data to the database

if($_POST['add']) {
sqlite_query($server, "INSERT INTO servers_list VALUES (NULL, '$add')");

}

?>

<html>
<head>
<title></title>
</head>
<body>




<FORM NAME ="Modify_list" METHOD ="POST" ACTION = "serverlist.php">

<select name="mode">
<option value="" name="add">Add</option>
<option value="delete" name="delete">Delete</option>
</select>
<select name="mode2">
<option value="allow" name="allow">Allow</option>
<option value="deny" name="deny">Deny</option>
</select>
Rule Number: <INPUT TYPE ="TEXT" Value ="" Name ="num">
Host: <INPUT TYPE ="TEXT" Value ="" Name ="hosts">
Port: <INPUT TYPE ="TEXT" Value ="" Name ="port">
<BR>
<BR>
<input type="button" name="checkall" value = "Check All" onClick="checkAll('host[]')">
<input type="button" name="checkall" value = "Uncheck All" onClick="uncheckAll('host[]')">
<BR>
<BR>
<?php
$result = sqlite_query($server, "SELECT host FROM servers_list");
if($result){
print "<table width=200 border=1>\n";
print "<tr>\n"; 
print "<th>  </th>\n";
print "<th> Server </th>\n";
print "</tr>\n";




while ( $row = sqlite_fetch_array($result, SQLITE_ASSOC) )
{

print "<tr>\n";

print "<td><input type=\"checkbox\" name=\"host[]\" value=\"$row[host]\" {$checked}></td>\n";

/*$OK = isset($_POST['host']) ? true : false;
        if ($OK && in_array($row[host], $_POST['host'])) {
$checked == 1 ? " CHECKED" : "";

}*/

echo "<td>{$row['host']}</td>\n";

echo "</tr>\n";

}//end while
print "</table>\n";

}//end if
else {
	echo("<P>Error performing query: \"sqlite_error() . \"</P>");
}

?>

<BR>
<INPUT TYPE ="Submit" Name = "submit" Value = "Modify"> <INPUT TYPE ="Submit" Name = "ss" Value = "Status">
</FORM>

<?php
$mode = $_POST['mode'];
$mode2 = $_POST['mode2'];
$hosts = $_POST['hosts'];
$port = $_POST['port'];
$rnum = $_POST['num'];
$serv = $_POST['host'];
$reghost = '^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$';


if($_POST['submit'] && $mode == "" && empty($rnum) && ereg($reghost, $hosts)) {
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
	if($serv != ""){
foreach($serv as $s){
	echo "connected to $s \n";
	if(!($con = ssh2_connect($s, 22, array('hostkey'=>'ssh-dss')))){
    			echo "fail: unable to establish connection\n";
	} else {

    			if(!ssh2_auth_pubkey_file($con, 'root', '.ssh/id_dsa.pub', '.ssh/id_dsa', 'pass')) {
        			echo "fail: unable to authenticate\n";
    			} else {

        			if(!($stream = ssh2_exec($con, "ufw $mode2 from $hosts to any port $port" )) ){
            				echo "fail: unable to execute command\n";
        		} else{
            
            			stream_set_blocking( $stream, true );
           			 $data = "";
            		while( $buf = fread($stream,4096) ){
                		$data .= $buf;
			echo "<pre>$data</pre> \n";
            			}
            		fclose($stream);
        				}
    				}
		}
	}

}else{
	echo "Choose a Server to modify";
}
} else if(!ereg($reghost, $hosts)){
  print ("Host should be ip based.");
}

 

 

Thanks in advanced

Link to comment
https://forums.phpfreaks.com/topic/181833-cached-check-box-and-regex/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.