function ghostReconfigure($service_id, $array, $remove = false) { global $config, $bnetParameters; $parameters = ghostGetParameters($service_id); //get the identifier $id = stripAlphaNumeric(getServiceParam($service_id, "id")); if ($id === false) { return false; } //get the existing configuration $ghostConfiguration = ghostGetConfiguration($service_id, false); //modify the configuration based on input $array settings foreach ($array as $k => $v) { if (!$remove) { if (isset($parameters[$k])) { $ghostConfiguration[$k] = ghostEscape($parameters[$k][0], $parameters[$k][1], $parameters[$k][2], $v); } else { if (($bkey_info = ghostConfigurationBnetKey($k)) !== false && isset($bnetParameters[$bkey_info['key']])) { $subkey = $bkey_info['key']; $ghostConfiguration[$k] = ghostEscape($bnetParameters[$subkey][0], $bnetParameters[$subkey][1], $bnetParameters[$subkey][2], $v); } } } else { if (isset($ghostConfiguration[$k])) { unset($ghostConfiguration[$k]); } } } //sort the configuration intelligently uksort($ghostConfiguration, 'ghostConfigurationComparator'); //re-order the configuration so that the bnet id's start from 1 and go up incrementally $curr_bnet_id = 0; //the bnet id counter $seen_bnet_id = -1; //the last seen bnet id from the input $reorderedConfiguration = array(); foreach ($ghostConfiguration as $k => $v) { if (($bkey_info = ghostConfigurationBnetKey($k)) !== false) { $bnet_id = $bkey_info['id']; $subkey = $bkey_info['key']; if ($bnet_id != $seen_bnet_id) { $curr_bnet_id++; $seen_bnet_id = $bnet_id; } if ($bnet_id != $curr_bnet_id) { if ($curr_bnet_id == 1) { $k = "bnet_{$subkey}"; } else { $k = "bnet{$curr_bnet_id}_{$subkey}"; } } } $reorderedConfiguration[$k] = $v; } //sort the configuration intelligently again, just in case? uksort($reorderedConfiguration, 'ghostConfigurationComparator'); //write the configuration out $fout = fopen($config['ghost_path'] . $id . "/ghost.cfg", 'w'); foreach ($reorderedConfiguration as $k => $v) { fwrite($fout, "{$k} = {$v}\n"); } fclose($fout); $jail = jailEnabled($service_id); if ($jail) { jailFileClose($service_id, "ghost", "ghost.cfg", true); } return true; }
<?php include "../include/common.php"; include "../config.php"; include "../include/session.php"; include "../include/dbconnect.php"; include "../include/account.php"; include "../include/ghost.php"; if (isset($_SESSION['account_id']) && isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && isset($_SESSION['is_' . $_REQUEST['id'] . '_ghost'])) { if (isset($_POST['action']) && $_POST['action'] == "update") { //create array of configurations we are updating $array = ghostGetConfigFromRequest(ghostGetParameters($_REQUEST['id']), $_REQUEST); ghostReconfigure($_REQUEST['id'], $array); if (!isset($_SESSION['noredirect'])) { header("Location: config_ghost.php?id=" . $_REQUEST['id']); return; } } $gconfig = ghostGetConfiguration($_REQUEST['id']); get_page("config_ghost", "ghost", array('service_id' => $_REQUEST['id'], 'gconfig' => $gconfig, 'parameters' => $ghostParameters)); } else { header("Location: ../panel/"); }