Projekt

Obecné

Profil

4 batix
<?
session_start();

include "../server_exists.php";
include "konstanty.php";
include "../language/".$_GET['lng'].".php";
//include "zkontroluj.php";


if ($_GET['zobraz']=="vyber") {
header ("Location: ../index.php?lng=".$_GET['lng']."&zobraz=vyber&".SID."");
exit;
}
//if ($_POST['ulozeno'] || $_POST['zobrazit_nahled']) {
//if ($_SESSION['ulozeno']) $_SESSION['po_odeslani_formu']="";

if ($_POST['smazano']) {
//echo $_POST['smazat_co'];
if (strstr($_POST['smazat_co'],"subnet")) $nahrad="subnet";
if (strstr($_POST['smazat_co'],"host")) $nahrad="host";
if (strstr($_POST['smazat_co'],"popis_g")) $nahrad="popis_g";

$jaky=str_replace($nahrad,"",$_POST['smazat_co']);

if ($nahrad=="subnet") {
for ($i=0;$i<sizeof($subnet_parametry);$i++)
unset($_SESSION[$subnet_zadane_hodnoty[$i].$jaky]);
unset($_SESSION["popis_s".$jaky]);
//$_SESSION['pocet_subnet']--;
}
if ($nahrad=="host") {
for ($i=0;$i<sizeof($host_parametry);$i++)
unset($_SESSION[$host_zadane_hodnoty[$i].$jaky]);
unset($_SESSION["popis_h".$jaky]);
unset($_SESSION["pridelit_hosta".$jaky]);
//$_SESSION['pocet_host']--;
}
if ($nahrad=="popis_g") {
for ($i=0;$i<sizeof($group_parametry);$i++)
unset($_SESSION[$group_zadane_hodnoty[$i].$jaky]);
unset($_SESSION["popis_g".$jaky]);
unset($_SESSION["pridelit_group".$jaky]);
//$_SESSION['pocet_group']--;
}
}
foreach($_SESSION as $ind => $val) //pridani uvozovek
if (strstr($ind,"_UVSTR_") && $val!="") $_SESSION[$ind]="\"".$val."\"";

//************************************** ULOZENI GLOBALNICH PARAMETRU DO PROMENNE: $global_z_formu *****************************
$global_z_formu="";

for ($i=0;$i<sizeof($globalni_zadane_hodnoty);$i++)
if ($_SESSION[$globalni_zadane_hodnoty[$i]]!="")
if (strstr($globalni_zadane_hodnoty[$i],"_CHECK_")) $global_z_formu .= $globalni_parametry[$i].";\n";
else $global_z_formu .= $globalni_parametry[$i]." ".$_SESSION[$globalni_zadane_hodnoty[$i]].";\n";

$global_z_formu .= "\n";

//************************************** ULOZENI HOSTU DO PROMENNE: array $host_z_formu **********************************************
$host_z_formu="";
$host_z_formu_kSubnet="";
$host_z_formu_kGroup="";

for ($i=0;$i<$_SESSION['pocet_host'];$i++) {
if ($_SESSION["host".$i]=="") continue;
if (strstr($_SESSION["pridelit_hosta".$i],"subnet")) {
$kde="kSubnetu";
$cislo=str_replace("subnet","",$_SESSION["pridelit_hosta".$i]);
}
if (strstr($_SESSION["pridelit_hosta".$i],"group")) {
$kde="kGroupu";
$cislo=str_replace("group","",$_SESSION["pridelit_hosta".$i]);
}
if (strstr($_SESSION["pridelit_hosta".$i],"toplevel")) {
$kde="toplevel";
$cislo=0;
}

if ($_SESSION["popis_h".$i]!="") $popis="# ".$_SESSION["popis_h".$i]."\n";
else $popis="";
$host_z_formu[$kde][$cislo] .= $popis."host ".$_SESSION["host".$i]." {\n";
for ($u=1;$u<sizeof($host_parametry);$u++) {
if ($_SESSION[$host_zadane_hodnoty[$u].$i]!="")
if (strstr($host_zadane_hodnoty[$u].$i,"_CHECK_")) $host_z_formu[$kde][$cislo] .= $host_parametry[$u].";\n";
else $host_z_formu[$kde][$cislo] .= $host_parametry[$u]." ".$_SESSION[$host_zadane_hodnoty[$u].$i].";\n";
}
$host_z_formu[$kde][$cislo] .= "}\n";

}
//************************************** ULOZENI JEDNOTLIVYCH GROUPS DO PROMENNE $group_z_formu ********************************
$group_z_formu="";
for ($i=0;$i<$_SESSION['pocet_group'];$i++) {
if ($_SESSION["popis_g".$i]=="") continue;
if (strstr($_SESSION["pridelit_group".$i],"subnet")) {
$kde="kSubnetu";
$cislo=str_replace("subnet","",$_SESSION["pridelit_group".$i]);
}
if (strstr($_SESSION["pridelit_group".$i],"toplevel")) {
$kde="toplevel";
$cislo=0;
}

if ($_SESSION["popis_g".$i]!="") $popis="# ".$_SESSION["popis_g".$i]."\n";
else $popis="# group ".($i+1)."\n";
$group_z_formu[$kde][$cislo] .= $popis."group {\n";
for ($u=0;$u<sizeof($group_parametry);$u++) {
if ($_SESSION[$group_zadane_hodnoty[$u].$i]!="")
if (strstr($group_zadane_hodnoty[$u].$i,"_CHECK_")) $group_z_formu[$kde][$cislo] .= $group_parametry[$u].";\n";
else $group_z_formu[$kde][$cislo] .= $group_parametry[$u]." ".$_SESSION[$group_zadane_hodnoty[$u].$i].";\n";
}
$group_z_formu[$kde][$cislo] .= $host_z_formu["kGroupu"][$i]."}\n\n";
}

//************************************** ULOZENI JEDNOTLIVYCH SUBNETU DO PROMENNE: $subnet_z_formu *****************************
$subnet_z_formu="";

for ($i=0;$i<$_SESSION['pocet_subnet'];$i++) {
if ($_SESSION["subnet".$i]=="" || $_SESSION["netmask".$i]=="") continue;
if ($_SESSION["popis_s".$i]!="") $popis="# ".$_SESSION["popis_s".$i]."\n";
else $popis="";
$subnet_z_formu .= $popis."subnet ".$_SESSION["subnet".$i]." netmask ".$_SESSION["netmask".$i]." {\n";
for ($u=2;$u<sizeof($subnet_parametry);$u++) {
if ($subnet_parametry[$u]=="range") {
for ($a=0;$a<$_SESSION["pocet_range".$i];$a++)
if ($_SESSION["range_od".$i."_".$a]!="" && $_SESSION["range_po".$i."_".$a]!="")
$subnet_z_formu .= "range ".$_SESSION["range_od".$i."_".$a]." ".$_SESSION["range_po".$i."_".$a].";\n";
}
else if ($_SESSION[$subnet_zadane_hodnoty[$u].$i]!="")
if (strstr($subnet_zadane_hodnoty[$u].$i,"_CHECK_")) $subnet_z_formu .= $subnet_parametry[$u].";\n";
else $subnet_z_formu .= $subnet_parametry[$u]." ".$_SESSION[$subnet_zadane_hodnoty[$u].$i].";\n";
}
$subnet_z_formu .= $group_z_formu["kSubnetu"][$i].$host_z_formu["kSubnetu"][$i]."}\n\n";
}




$uloz_do_souboru = $kontrolni_radek.$global_z_formu.$subnet_z_formu.$group_z_formu["toplevel"][0].$host_z_formu["toplevel"][0];

// odsazeni tabulatory v souboru
$tab="";
$nahled=explode("\n",$uloz_do_souboru);
for ($i=0;$i<sizeof($nahled);$i++) {
if (strstr($nahled[$i],"}")) $tab = substr($tab, 1);
$nahled[$i]=$tab.$nahled[$i];
if (strstr($nahled[$i],"{")) $tab .= "\t";
}
$nahled=implode("\n",$nahled);
$uloz_do_souboru=$nahled;

// odsazeni tabulatory v nahledu s tucnm rozlisenim
$tab="";
$nahled=explode("\n",$uloz_do_souboru);
for ($i=0;$i<sizeof($nahled);$i++) {
if (strstr($nahled[$i],"}")) {
$nahled[$i]="<b>".$nahled[$i]."</b>";
$tab = substr($tab, 1);
}
$nahled[$i]=$tab.$nahled[$i];
if (strstr($nahled[$i],"{")) {
$nahled[$i]="<b>".$nahled[$i]."</b>";
$tab .= "\t";
}
}
$nahled=implode("\n",$nahled);




if ($_POST['ulozeno'] || $_POST['smazano']) {
//foreach($_SESSION as $ind => $val) $_SESSION[$ind]="";
$fp=fopen($soubor_dhcp_pro_uloz, "w");
fwrite($fp, $uloz_do_souboru."\n");
fclose($fp);

9 batix
if ($_POST['ulozeno']) {
exec ("scp ../files/".$_SESSION['online_user_serverIP']."/dhcpd.conf.php root@".$_SESSION['online_user_serverIP'].":/etc/dhcpd.conf");
exec ("ssh ".$_SESSION['online_user_serverIP']." ?l root /etc/init.d/dhcpd restart");
}

4 batix
//foreach($_SESSION as $ind => $val) $_SESSION[$ind]="";
if ($_POST['ulozeno']) header ("Location: ../index.php?id=dhcp&lng=".$_GET['lng']."&ulozeno=1&".SID."");
if ($_POST['smazano']) header ("Location: ../index.php?id=dhcp&smazat=".$_GET['smazat']."&lng=".$_GET['lng']."&smazano=1&".SID."");
}
if ($_POST['zobrazit_nahled']) {
foreach($_SESSION as $ind => $val) $_SESSION[$ind]=str_replace("\"","",$val);
echo nl2br(str_replace("\t","&nbsp;&nbsp;&nbsp;",$nahled)); // zobrazeni nahledu
/*
foreach($_SESSION as $ind => $val) {
if (strstr($ind,"popis_h")) echo $val." -> ";
if (strstr($ind,"pridelit_hosta")) echo $ind." = ".$val."<br />";
}
echo "<br />".nl2br($host_z_formu["toplevel"][0]);
*/
}

//}

?>