shell_exec($down_command); shell_exec($del_command); } else { // for insert action $update_qry = "UPDATE `tbl_interface` \n\t\t\t\t\t\tSET `bridge`='yes' \n\t\t\t\t\t\tWHERE `is_active`='active' \n\t\t\t\t\t\t\t\tAND (\t`interface_name` = '{$interface['0']}' OR \n\t\t\t\t\t\t\t\t\t\t`interface_name` = '{$interface['1']}' OR \n\t\t\t\t\t\t\t\t\t\t`interface_name` = '{$interface['2']}' OR \n\t\t\t\t\t\t\t\t\t\t`interface_name` = '{$interface['3']}' \n\t\t\t\t\t\t\t\t\t)"; Sql_exec($cn, $update_qry); // interface query: update bridge field = 'yes' for each of the new interface $bridgeTag = "\n" . "BRIDGE=" . $bridge_name; $interface_names = array('', '', '', ''); $i = 0; foreach ($interface as $name) { if ($name != "") { if (strpos($name, ":") == true) { $name = str_replace(":", ".", $name); } file_modify($dir . $name, $bridgeTag); //Add BRIDGE tag to newly interface config file $interface_name_parts = split("-", $name); $interface_names[$i++] = $interface_name_parts[1]; } } bridge_file_write($dir, $bridge_name, $ip, $net_mask); $cmd2 = "sudo brctl addif " . $bridge_name; if ($interface_names[0] != "") { $cmd2 .= " " . $interface_names[0]; } if ($interface_names[1] != "") { $cmd2 .= " " . $interface_names[1]; } if ($interface_names[2] != "") { $cmd2 .= " " . $interface_names[2];
function post() { global $TITLE; global $xoopsConfig; global $mod_old, $pre_old, $sec_old, $name_old; xoops_cp_header(); echo "<h4>$TITLE</h4>\n"; $mod_new = $_POST['mod']; $pre_new = $_POST['pre']; $sec_new = $_POST['sec']; $name_new = $_POST['name']; $lang = $xoopsConfig['language']; $dir_old = XOOPS_ROOT_PATH.'/modules/'.$mod_old; $dir_new = XOOPS_ROOT_PATH.'/modules/'.$mod_new; $pre_old = strtolower($pre_old); $pre_new = strtolower($pre_new); $word_array_old = array($pre_old, strtoupper($pre_old), $mod_old, $sec_old, $name_old); $word_array_new = array($pre_new, strtoupper($pre_new), $mod_new, $sec_new, $name_new); // not change XFS_xx in blocks $word_array_2_old = array($pre_old, $mod_old, $sec_old, $name_old); $word_array_2_new = array($pre_new, $mod_new, $sec_new, $name_new); // --- cpoy module --- if (!file_exists($dir_new)) { echo "mkdir $mod_new <br>\n"; $ret = mkdir($dir_new,0707); if (!$ret) { echo "cannot make new module: $mod_new <br>\n"; echo "please copy module manaualy <br>\n"; exit(); } } echo "copy $mod_old to $mod_new <br>\n"; system("cp -p -R $dir_old/* $dir_new"); // --- modify --- file_modify("$dir_new","xoops_version.php",$word_array_old,$word_array_new); file_modify("$dir_new","conf.php",$word_array_old,$word_array_new); file_modify("$dir_new/include","search.inc.php",$word_array_old,$word_array_new); // data.inc.php file_modify("$dir_new/include","data.inc.php",$word_array_old,$word_array_new); file_modify("$dir_new/language/$lang","admin.php",$word_array_old,$word_array_new); file_modify("$dir_new/language/$lang","modinfo.php",$word_array_old,$word_array_new); file_modify("$dir_new/language/english","admin.php",$word_array_old,$word_array_new); file_modify("$dir_new/language/english","modinfo.php",$word_array_old,$word_array_new); // --- modify and rename --- file_modify_rename("$dir_new/sql","xfsection.sql",$mod_old,$mod_new,$word_array_old,$word_array_new); dir_modify_rename("$dir_new/templates",$mod_old,$mod_new); dir_modify_rename("$dir_new/templates/blocks",$pre_old,$pre_new,$mod_old,$mod_new); // not change XFS_xx in blocks dir_block_modify_rename("$dir_new/blocks",$pre_old,$pre_new,$word_array_2_old,$word_array_2_new,$mod_new); // --- rename --- file_rename("$dir_new/images","xfs_slogo.gif",$pre_old,$pre_new); // --- chmod --- system("chmod 777 -R $dir_new"); ?> <br><b>finished</b><br> <hr> <div align="center"> <a href="../../system/admin.php?fct=modulesadmin">[admin module]</a> </div> <?php xoops_cp_footer(); exit(); }
/** * Network Settings Bridge */ function file_writer_ns_bridge($cn) { global $dir; $is_error = 0; $file_dir = $dir; log_generator("Network Settings Bridge File Writing Start", __FILE__, __FUNCTION__, __LINE__, NULL); function file_modify($file, $bridgeTag) { $data = file_get_contents($file); $data = trim($data); $file_data = $data . $bridgeTag; file_put_contents($file, $file_data); } $select_qry = "select id,bridge_name,interface1,interface2,interface3,interface4, ip, net_mask, gateway from tbl_bridge where is_active='active'"; $rs = Sql_exec($cn, $select_qry); while ($dt = Sql_fetch_array($rs)) { $bridge = $dt['bridge_name']; $ip_addr = $dt['ip']; $net_mask = $dt['net_mask']; $gateway = $dt['gateway']; $interface1 = $dt['interface1']; $interface2 = $dt['interface2']; $interface3 = $dt['interface3']; $interface4 = $dt['interface4']; $file = $file_dir . "ifcfg-br" . $bridge; if ($handle = fopen($file, 'w')) { //or die('Cannot create file: ' . $file); $writingString = "# Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet\n"; $writingString .= "DEVICE=br" . $bridge . "\n"; $writingString .= "BOOTPROTO=static\n"; $writingString .= "ONBOOT=yes\n"; $writingString .= "TYPE=Bridge\n"; if (trim($ip_addr) != "") { $writingString .= "IPADDR=" . $ip_addr . "\n"; } if (trim($net_mask) != "") { $writingString .= "NETMASK=" . $net_mask . "\n"; } if (trim($gateway) != "") { $writingString .= "GATEWAY=" . $gateway . "\n"; } $writingString .= "STP=yes\n"; $writingString .= "DELAY=15\n"; fwrite($handle, $writingString); fclose($handle); } $bridgeTag = "\n" . "BRIDGE=br" . $bridge; //bridge 1 $b1 = $interface1; if ($b1 != "") { $b1_u = $b1; if (strpos($b1, ":")) { $b1_u = str_replace(":", ".", $b1); } $file = $dir . $b1_u; file_modify($file, $bridgeTag); } // bridge 2 $b2 = $interface2; if ($b2 != "") { $b2_u = $b2; if (strpos($b2, ":")) { $b2_u = str_replace(":", ".", $b2); } $file = $dir . $b2_u; file_modify($file, $bridgeTag); } // bridge 3 $b3 = $interface3; if ($b3 != "") { $b3_u = $b3; if (strpos($b3, ":")) { $b3_u = str_replace(":", ".", $b3); } $file = $dir . $b3_u; file_modify($file, $bridgeTag); } // bridge 4 $b4 = $interface4; if ($b4 != "") { $b4_u = $b4; if (strpos($b4, ":")) { $b4_u = str_replace(":", ".", $b4); } $file = $dir . $b4_u; file_modify($file, $bridgeTag); } } log_generator("Bridge Successfully Written", __FILE__, __FUNCTION__, __LINE__, NULL); return $is_error; }