/** * strip crap from posts (i.e. sessionhash * * @param string post * * @return string post */ function stripcrap($post) { if ($post) { $post = preg_replace("/(\\?|\\&){1}sid=[a-z0-9]{32}/", "\\1sid=", $post); $post = preg_replace("/(&#)(\\d+)(;)/e", "chr(intval('\\2'))", $post); $post = dos2unix($post); } return $post; }
public static function getTriplets($cell) { if (isset($cell['ip_bin']) and isset($cell['vslist'])) { // cell is IPAddress return self::getTripletsByIP($cell['ip_bin']); } $ret = array(); switch ($cell['realm']) { case 'object': $db_field = 'object_id'; $order_fields = 'vs_id'; $display_cells = array('vs', 'rs'); break; case 'ipv4vs': $db_field = 'vs_id'; $order_fields = 'rspool_id'; $display_cells = array('rs', 'lb'); break; case 'ipv4rspool': $db_field = 'rspool_id'; $order_fields = 'vs_id'; $display_cells = array('vs', 'lb'); break; default: throw new InvalidArgException('realm', $cell['realm']); } $result = usePreparedSelectBlade("SELECT * FROM IPv4LB WHERE `{$db_field}` = ? ORDER BY {$order_fields}", array($cell['id'])); $rows = $result->fetchAll(PDO::FETCH_ASSOC); unset($result); global $triplet_class; foreach ($rows as $row) { $row['vsconfig'] = dos2unix($row['vsconfig']); $row['rsconfig'] = dos2unix($row['rsconfig']); $triplet = new $triplet_class($row['object_id'], $row['vs_id'], $row['rspool_id'], $row); $triplet->display_cells = $display_cells; $ret[] = $triplet; } return $ret; }
function verifyCodeAJAX() { global $pageno, $tabno; $pageno = 'perms'; $tabno = 'edit'; fixContext(); assertPermission(); genericAssertion('code', 'string'); $result = getRackCode(dos2unix($_REQUEST['code'])); if ($result['result'] == 'ACK') { echo "ACK\n"; } else { echo "NAK\n" . $result['load']; } }
function generateSLBConfig2($triplet_list) { $ret = ''; global $parser_class; $gl_parser = new $parser_class(); $defaults = getSLBDefaults(TRUE); $gl_parser->addMacro('GLOBAL_VS_CONF', dos2unix($defaults['vsconfig'])); $gl_parser->addMacro('GLOBAL_RS_CONF', dos2unix($defaults['rsconfig'])); $gl_parser->addMacro('RSPORT', '%VPORT%'); $gl_parser->addMacro('VS_PREPEND', "# LB (id == %LB_ID%): %LB_NAME%\n# VSG (id == %VSG_ID%): %VS_NAME%\n# RS (id == %RSP_ID%): %RSP_NAME%"); // group triplets by object_id, vs_id $grouped = array(); foreach ($triplet_list as $triplet) { $grouped[$triplet['object_id']][$triplet['vs_id']][] = $triplet; } foreach ($grouped as $object_id => $subarr) { $seen_vs_groups = array(); $lb_parser = clone $gl_parser; $lb_cell = spotEntity('object', $object_id); $lb_parser->addMacro('LB_ID', $lb_cell['id']); $lb_parser->addMacro('LB_NAME', $lb_cell['name']); foreach ($subarr as $vs_id => $triplets) { $vs_parser = clone $lb_parser; $vs_cell = spotEntity('ipvs', $vs_id); if (!isset($vs_cell['ports']) || !isset($vs_cell['vips'])) { amplifyCell($vs_cell); } $vs_parser->addMacro('VS_ID', $vs_cell['id']); $vs_parser->addMacro('VSG_ID', $vs_cell['id']); $vs_parser->addMacro('VS_NAME', $vs_cell['name']); $vs_parser->addMacro('VS_RS_CONF', dos2unix($vs_cell['rsconfig'])); foreach ($triplets as $triplet) { $virtual_services = array(); $tr_parser = clone $vs_parser; $rs_cell = spotEntity('ipv4rspool', $triplet['rspool_id']); $tr_parser->addMacro('RSP_ID', $rs_cell['id']); $tr_parser->addMacro('RSP_NAME', $rs_cell['name']); $tr_parser->addMacro('RSP_VS_CONF', dos2unix($rs_cell['vsconfig'])); $tr_parser->addMacro('RSP_RS_CONF', dos2unix($rs_cell['rsconfig'])); $tr_parser->addMacro('VS_VS_CONF', dos2unix($vs_cell['vsconfig'])); // VS-driven vsconfig has higher priority than RSP-driven foreach ($triplet['ports'] as $port_row) { $is_mark = $port_row['proto'] == 'MARK'; $p_parser = clone $tr_parser; $p_parser->addMacro('VS_HEADER', $is_mark ? 'fwmark %MARK%' : '%VIP% %VPORT%'); $p_parser->addMacro('PROTO', $is_mark ? 'TCP' : $port_row['proto']); $p_parser->addMacro($is_mark ? 'MARK' : 'VPORT', $port_row['vport']); foreach ($vs_cell['ports'] as $vport) { if ($vport['vport'] == $port_row['vport'] && $vport['proto'] == $port_row['proto']) { $p_parser->addMacro('PORT_VS_CONF', dos2unix($vport['vsconfig'])); $p_parser->addMacro('PORT_RS_CONF', dos2unix($vport['rsconfig'])); break; } } $p_parser->addMacro('SLB_PORT_VS_CONF', dos2unix($port_row['vsconfig'])); $p_parser->addMacro('SLB_PORT_RS_CONF', dos2unix($port_row['rsconfig'])); if ($is_mark) { $p_parser->addMacro('RS_HEADER', '%RSIP%'); // find enabled IP families to fill IP_VER $seen_families = array(); foreach ($triplet['vips'] as $ip_row) { $family_length = strlen($ip_row['vip']); $seen_families[$family_length] = $family_length == 16 ? 6 : 4; } if (!$seen_families) { $seen_families['unknown'] = ''; } foreach ($seen_families as $ip_ver) { $fam_parser = clone $p_parser; if ($ip_ver) { $fam_parser->addMacro('IP_VER', $ip_ver); } if ('' != ($vs_config = generateVSSection($fam_parser))) { $virtual_services["IPv{$ip_ver} " . $fam_parser->expandMacro('VS_HEADER')] = $vs_config; } } } else { $p_parser->addMacro('RS_HEADER', '%RSIP% %RSPORT%'); foreach ($triplet['vips'] as $ip_row) { $ip_parser = clone $p_parser; $ip_parser->addMacro('VIP', ip_format($ip_row['vip'])); $ip_parser->addMacro('IP_VER', strlen($ip_row['vip']) == 16 ? 6 : 4); $ip_parser->addMacro('PRIO', $ip_row['prio']); foreach ($vs_cell['vips'] as $vip) { if ($vip['vip'] === $ip_row['vip']) { $ip_parser->addMacro('VIP_VS_CONF', dos2unix($vip['vsconfig'])); $ip_parser->addMacro('VIP_RS_CONF', dos2unix($vip['rsconfig'])); break; } } $ip_parser->addMacro('SLB_VIP_VS_CONF', dos2unix($ip_row['vsconfig'])); $ip_parser->addMacro('SLB_VIP_RS_CONF', dos2unix($ip_row['rsconfig'])); if ('' != ($vs_config = generateVSSection($ip_parser))) { $virtual_services[$port_row['proto'] . " " . $ip_parser->expandMacro('VS_HEADER')] = $vs_config; } } // vips } } //ports // group multiple virtual_services into vs_groups $groups = array(); foreach ($virtual_services as $key => $content) { $groups[$content][] = preg_replace('/^(TCP|UDP|IPv[46]?)\\s+/', '', $key); } foreach ($groups as $content => $keys) { if (NULL !== ($new_content = callHook('generateSLBConfig_stage2', $content, $keys))) { $content = $new_content; } $ret .= $tr_parser->expand("\n%VS_PREPEND%\n"); if (count($keys) == 1) { $ret .= "virtual_server " . array_first($keys) . " {\n" . $content . "}\n"; } else { // come up with the name for new VS group $vsg_name = makeUniqueVSGName($seen_vs_groups, $keys, $vs_cell); $seen_vs_groups[$vsg_name] = 1; $tr_parser->addMacro('VSG_NAME', $vsg_name); $ret .= $tr_parser->expand("virtual_server_group %VSG_NAME% {\n"); foreach ($keys as $vs_header) { $ret .= "\t{$vs_header}\n"; } $ret .= "}\n"; $ret .= $tr_parser->expand("virtual_server group %VSG_NAME% {\n"); $ret .= $content . "}\n"; } } } // triplets } // vs } // balancers return $ret; }
function transformRequestData() { global $sic; // Magic quotes feature is deprecated, but just in case the local system // still has it activated, reverse its effect. $do_magic_quotes = (function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()); $seen_keys = array(); // Escape any globals before we ever try to use them, but keep a copy of originals. $sic = array(); // walk through merged GET and POST instead of REQUEST array because it // can contain cookies with data that could not be decoded from UTF-8 foreach ($_POST + $_GET as $key => $value) { if (is_array($value)) { $_REQUEST[$key] = $value; } else { $value = dos2unix($value); if ($do_magic_quotes) { $value = stripslashes($value); } $_REQUEST[$key] = escapeString($value); } $sic[$key] = $value; $seen_keys[$key] = 1; } // delete cookie information from the $_REQUEST array foreach (array_keys($_REQUEST) as $key) { if (!isset($seen_keys[$key])) { unset($_REQUEST[$key]); } } if (isset($_SERVER['PHP_AUTH_USER'])) { $_SERVER['PHP_AUTH_USER'] = escapeString($_SERVER['PHP_AUTH_USER']); } if (isset($_SERVER['REMOTE_USER'])) { $_SERVER['REMOTE_USER'] = escapeString($_SERVER['REMOTE_USER']); } }
function saveRackCode() { assertStringArg('rackcode'); // For the test to succeed, unescape LFs, strip CRs. $newcode = dos2unix($_REQUEST['rackcode']); $parseTree = getRackCode($newcode); if ($parseTree['result'] != 'ACK') { showFuncMessage(__FUNCTION__, 'ERR1', array($parseTree['load'])); return; } saveScript('RackCode', $newcode); saveScript('RackCodeCache', base64_encode(serialize($parseTree))); showFuncMessage(__FUNCTION__, 'OK'); }
public function prepareParserForRS(&$parser, $rs_row) { $parser->addMacro('RS_HEADER', $this->vs['proto'] == 'MARK' ? '%RSIP%' : '%RSIP% %RSPORT%'); $parser->addMacro('RSIP', $rs_row['rsip']); $parser->addMacro('RSPORT', isset($rs_row['rsport']) ? $rs_row['rsport'] : $this->vs['vport']); // VS port is a default value for RS port $parser->addMacro('RS_COMMENT', $rs_row['comment']); $defaults = getSLBDefaults(TRUE); $parser->addMacro('GLOBAL_RS_CONF', dos2unix($defaults['rs'])); $parser->addMacro('VS_RS_CONF', dos2unix($this->vs['rsconfig'])); $parser->addMacro('RSP_RS_CONF', dos2unix($this->rs['rsconfig'])); $parser->addMacro('SLB_RS_CONF', dos2unix($this->slb['rsconfig'])); $parser->addMacro('RS_RS_CONF', $rs_row['rsconfig']); }
function generateConfig() { // fill the predefined macros $parser = $this->createParser(); $parser->addMacro('LB_ID', $this->lb['id']); $parser->addMacro('LB_NAME', $this->lb['name']); $parser->addMacro('VS_ID', $this->vs['id']); $parser->addMacro('VS_NAME', $this->vs['name']); $parser->addMacro('RSP_ID', $this->rs['id']); $parser->addMacro('RSP_NAME', $this->rs['name']); $parser->addMacro('VIP', $this->vs['vip']); $parser->addMacro('VPORT', $this->vs['vport']); $parser->addMacro('PRIO', $this->slb['prio']); $parser->addMacro('IP_VER', strlen($this->vs['vip_bin']) == 16 ? 6 : 4); if ($this->vs['proto'] == 'MARK') { $parser->addMacro('PROTO', 'TCP'); $mark = implode('', unpack('N', substr($this->vs['vip_bin'], 0, 4))); $parser->addMacro('MARK', $mark); $parser->addMacro('VS_HEADER', "fwmark {$mark}"); } else { $parser->addMacro('VS_HEADER', $this->vs['vip'] . ' ' . $this->vs['vport']); $parser->addMacro('PROTO', $this->vs['proto']); } $defaults = getSLBDefaults(TRUE); $parser->addMacro('GLOBAL_VS_CONF', dos2unix($defaults['vs'])); $parser->addMacro('RSP_VS_CONF', dos2unix($this->rs['vsconfig'])); $parser->addMacro('VS_VS_CONF', dos2unix($this->vs['vsconfig'])); $parser->addMacro('SLB_VS_CONF', dos2unix($this->slb['vsconfig'])); // return the expanded VS template using prepared $macros array $ret = $parser->expand("\n# LB (id == %LB_ID%): %LB_NAME%\n# VS (id == %VS_ID%): %VS_NAME%\n# RS (id == %RSP_ID%): %RSP_NAME%\nvirtual_server %VS_HEADER% {\n\tprotocol %PROTO%\n\t%GLOBAL_VS_CONF%\n\t%RSP_VS_CONF%\n\t%VS_VS_CONF%\n\t%SLB_VS_CONF%\n"); foreach (getRSListInPool($this->rs['id']) as $rs) { // do not add v6 reals into v4 service and vice versa if (strlen($rs['rsip_bin']) != strlen($this->vs['vip_bin'])) { continue; } if ($rs['inservice'] != 'yes') { continue; } $parser->pushdefs(); // backup macros $parser->addMacro('RS_HEADER', $this->vs['proto'] == 'MARK' ? '%RSIP%' : '%RSIP% %RSPORT%'); $parser->addMacro('RSIP', $rs['rsip']); $parser->addMacro('RSPORT', isset($rs['rsport']) ? $rs['rsport'] : $this->vs['vport']); // VS port is a default value for RS port $parser->addMacro('RS_COMMENT', $rs['comment']); $parser->addMacro('GLOBAL_RS_CONF', dos2unix($defaults['rs'])); $parser->addMacro('VS_RS_CONF', dos2unix($this->vs['rsconfig'])); $parser->addMacro('RSP_RS_CONF', dos2unix($this->rs['rsconfig'])); $parser->addMacro('SLB_RS_CONF', dos2unix($this->slb['rsconfig'])); $parser->addMacro('RS_RS_CONF', $rs['rsconfig']); $ret .= $parser->expand("\n\t%RS_PREPEND%\n\treal_server %RS_HEADER% {\n\t\t%GLOBAL_RS_CONF%\n\t\t%VS_RS_CONF%\n\t\t%RSP_RS_CONF%\n\t\t%SLB_RS_CONF%\n\t\t%RS_RS_CONF%\n\t}\n"); $parser->popdefs(); // restore original (VS-driven) macros } $ret .= "}\n"; return $ret; }
function gwRetrieveDeviceConfig($object_id, $command) { require_once 'deviceconfig.php'; global $breedfunc; $breed = detectDeviceBreed($object_id); assertBreedFunction($breed, $command); $objectInfo = spotEntity('object', $object_id); $endpoints = findAllEndpoints($object_id, $objectInfo['name']); if (count($endpoints) == 0) { throw new RTGatewayError('no management address set'); } if (count($endpoints) > 1) { throw new RTGatewayError('cannot pick management address'); } $endpoint = str_replace(' ', '\\ ', str_replace(' ', '+', $endpoints[0])); $tmpfilename = tempnam('', 'RackTables-deviceconfig-'); try { queryGateway('deviceconfig', array("{$command} {$endpoint} {$breed} {$tmpfilename}")); $configtext = file_get_contents($tmpfilename); unlink($tmpfilename); } catch (RTGatewayError $e) { unlink($tmpfilename); throw $e; } if ($configtext === FALSE) { throw new RTGatewayError('failed to read temporary file'); } // Being here means it was alright. return $breedfunc["{$breed}-{$command}-main"](dos2unix($configtext)); }
$smarty->assign("linkid", $_GET['id']); $smarty->display("a_download_edit.tpl.php"); exit; } /** * * Links erzeugen * **/ if ($action == "new") { $smarty->assign("action", $action); if ($_POST['send']) { if ($_FILES['uploadfile']['size'] <= $shopconfig['shopconfig_max_upload_size']) { $attachment_file_extension = strtolower(substr(strrchr($_FILES['uploadfile']['name'], '.'), 1)); $attachment_file_name2 = substr($_FILES['uploadfile']['name'], 0, (intval(strlen($attachment_file_extension)) + 1) * -1); $allowextensions = str_replace("\n", "|", str_replace('*', '[a-z0-9]*', dos2unix($shopconfig['shopconfig_allowed_upload_extension']))); $upload_file_size = $_FILES['uploadfile']['size']; // Wenn die Datei hochgeladen werden darf if (preg_match("/^({$allowextensions})\$/i", $attachment_file_extension)) { $result = $db->query("INSERT INTO rhs_download_data SET\n\t\t\t\t\tdlname='{$_POST['dlname']}',\n\t\t\t\t\tdldescription='{$_POST['dldescription']}',\n\t\t\t\t\tdlfile='{$attachment_file_name2}.{$attachment_file_extension}',\n\t\t\t\t\tcatid='{$_POST['p_cat']}',\n\t\t\t\t\tfilesize='{$upload_file_size}',\n\t\t\t\t\tfiletype='{$attachment_file_extension}',\n\t\t\t\t\tmandant=" . $adminsession->session_mandant_data['mandant_id'] . ",\n\t\t\t\t\tcreate_userid=" . $adminsession->session_user_data['customer_id'] . ",\n\t\t\t\t\tcreate_date=" . time()); if ($result) { if (!is_dir($shopconfig['shopconfig_upload_folder'] . $adminsession->session_mandant_data['mandant_id'])) { mkdir($shopconfig['shopconfig_upload_folder'] . $adminsession->session_mandant_data['mandant_id']); } // Bild auf den Server speichern if (@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $shopconfig['shopconfig_upload_folder'] . $adminsession->session_mandant_data['mandant_id'] . "/" . $db->insert_id() . '.' . $attachment_file_extension)) { @chmod($shopconfig['shopconfig_upload_folder'] . $adminsession->session_mandant_data['mandant_id'] . "/" . $db->insert_id() . '.' . $attachment_file_extension, 0777); $smarty->assign("fehler", 1); $smarty->assign("action", "editlink"); $smarty->assign("page_redirect", "download_cat.php?sid=" . $adminsession->session_data['hash']); } else {