Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('memory_limit','8192M');
- ini_set('max_execution_time', 900);
- function get_list_tables($url){
- $tables=file_get_contents($url);
- $arr_tables=json_decode($tables,true);
- $list_table=array();
- foreach($arr_tables as $d){
- $temp='RAW_'.$d['vh_alias'].'_'.$d['vh_name'];
- $temp=str_replace(array('.','-'),'_',$temp);
- $list_table[]=array(strtoupper($temp),$d['links']['2']['href']);
- }
- return $list_table;
- }
- function insert_data($table, $con){
- $return=false;
- if(substr($table[0],0,7)!='RAW_JUP'){
- $nodes=file_get_contents($table[1]);
- $arr_nodes=json_decode($nodes,true);
- $list_nodes=array();
- echo '<pre>';
- //-- get table structure
- $temp=reset($arr_nodes);
- $list_fields=array();
- foreach($temp as $key=>$value){
- if(!is_array($value)){
- $list_fields[]=strtoupper($key);
- }else{
- $id=$ix=0;
- foreach($value as $k=>$val){
- if($ix!=$k){$ix=$k;++$id;};
- if(!is_numeric($k)){
- if(!is_array($val)){
- $list_fields[]=strtoupper($key.'_'.$k);
- }else{
- $jd=$jx=0;
- foreach($val as $idx=>$va){
- if($jx!=$idx){$jx=$idx;++$jd;};
- if(!is_numeric($idx)){
- $list_fields[]=strtoupper($key.'_'.$k.'_'.$idx);
- }else{
- foreach($va as $kx=>$kv){
- $list_fields[]=strtoupper($key.'_'.$k.'_'.$kx.'_'.$jd);
- }
- }
- }
- }
- }else{
- foreach($val as $i=>$v){
- $list_fields[]=strtoupper($key.'_'.$i.'_'.$id);
- }
- }
- }
- }
- }
- echo "[START] processing table {$table[0]}\n";
- $sql_check="SELECT COUNT(1) AS jml FROM user_tables WHERE TABLE_NAME='{$table[0]}'";
- $stmt = oci_parse($con,$sql_check)or die('statement error' . $sql_check);;
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_check);
- $row=oci_fetch_assoc($stmt);
- oci_free_statement($stmt);
- if($row['JML']==0){
- //-- create a table based on given structure
- $sql_create="CREATE TABLE \"IF_INTRANET_JAH\".\"{$table[0]}\"( ";
- foreach($list_fields as $field){
- $sql_create.="\"{$field}\" VARCHAR2(".(strtoupper($field)=='DESCRIPTION'?'10':'2')."00 BYTE), ";
- }
- $sql_create.="\"DATE_IN\" TIMESTAMP (6) DEFAULT SYSDATE NOT NULL ENABLE ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE \"IF_INTRANET_JAH_DATA\" ";
- $stmt = oci_parse($con,$sql_create)or die('statement error' . $sql_create);;
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_create);
- oci_free_statement($stmt);
- }
- //-- insert data to db table
- $find=array("'","&");
- $replace=array("","n");
- $fields=implode('","',$list_fields);
- reset($arr_nodes);
- $count=0;
- $sql_insert="INSERT ALL ";
- foreach($arr_nodes as $temp){
- if(++$count==10){
- $sql_insert.="SELECT * FROM dual";
- $stmt = oci_parse($con,$sql_insert)or die('statement error' . $sql_insert);;
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_insert);
- oci_free_statement($stmt);
- $count=0;
- $sql_insert="INSERT ALL ";
- }
- $list_values=array();
- $sql_insert.="INTO \"IF_INTRANET_JAH\".\"{$table[0]}\"(\"{$fields}\") VALUES (";
- foreach($temp as $key=>$value){
- if(!is_array($value)){
- if($key=='description'){
- $value=str_replace($find,$replace,$value);
- }
- $list_values[]=$value;
- }else{
- $id=$ix=0;
- foreach($value as $k=>$val){
- if($ix!=$k){$ix=$k;++$id;};
- if(!is_numeric($k)){
- if(!is_array($val)){
- $list_values[]=$val;
- }else{
- $jd=$jx=0;
- foreach($val as $idx=>$va){
- if($jx!=$idx){$jx=$idx;++$jd;};
- if(!is_numeric($idx)){
- $list_values[]=$va;
- }else{
- foreach($va as $kx=>$kv){
- $list_values[]=$kv;
- }
- }
- }
- }
- }else{
- foreach($val as $i=>$v){
- $list_values[]=$v;
- }
- }
- }
- }
- }
- $temp="'".implode("','",$list_values)."'";
- $temp=str_replace('#','',$temp);
- $sql_insert.=$temp.") ";
- }
- $sql_insert.="SELECT * FROM dual ";
- $stmt = oci_parse($con,$sql_insert)or die('statement error' . $sql_insert);;
- $return=oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_insert);
- oci_free_statement($stmt);
- }
- return $return;
- }
- //-- for insert idirect
- function insert_idirect($table,$con){
- $return=false;
- $list_fields=array
- (
- 'ID',
- 'NAME',
- 'DESCRIPTION',
- 'SERIALNUMBER',
- 'TYPE',
- 'SOFTWAREVERSION',
- 'PP_ID',
- 'PP_NAME',
- 'INROUTEGROUP_ID',
- 'INROUTEGROUP_NAME',
- 'OUTROUTE_ID',
- 'OUTROUTE_NAME',
- 'INTERFACE_ETH0_VLANID_1',
- 'INTERFACE_ETH0_IP_1',
- 'INTERFACE_ETH0_SUBNET_1',
- 'INTERFACE_ETH0_GW_1',
- 'INTERFACE_ETH0_VLANID_2',
- 'INTERFACE_ETH0_IP_2',
- 'INTERFACE_ETH0_SUBNET_2',
- 'INTERFACE_ETH0_GW_2',
- 'INTERFACE_SAT0_VLANID_1',
- 'INTERFACE_SAT0_IP_1',
- 'INTERFACE_SAT0_SUBNET_1',
- 'INTERFACE_SAT0_GW_1',
- 'INTERFACE_SAT0_VLANID_2',
- 'INTERFACE_SAT0_IP_2',
- 'INTERFACE_SAT0_SUBNET_2',
- 'INTERFACE_SAT0_GW_2',
- 'DATE_IN'
- );
- echo "[START] processing table {$table[0]}\n";
- $nodes=file_get_contents($table[1]);
- $arr_nodes=json_decode($nodes,true);
- $list_nodes=array();
- $find=array("'","&");
- $replace=array("","n");
- $sql_insert="INSERT ALL ";
- $fields=implode('","',$list_fields);
- $count=0;
- foreach($arr_nodes as $d){
- $sql_insert.="INTO \"IF_INTRANET_JAH\".\"{$table[0]}\"(\"{$fields}\") VALUES ";
- $desc=$d['description'];
- $desc=str_replace($find,$replace,$desc);
- $sql_insert.="(
- '{$d['id']}',
- '{$d['name']}',
- '{$desc}',
- '{$d['serialnumber']}',
- '{$d['type']}',
- '{$d['softwareversion']}',
- '{$d['pp']['id']}',
- '{$d['pp']['name']}',
- '{$d['inroutegroup']['id']}',
- '{$d['inroutegroup']['name']}',
- '{$d['outroute']['id']}',
- '{$d['outroute']['name']}',";
- foreach($d['interface']['eth0'] as $eth){
- $sql_insert.="
- '".$eth['vlanid']."',
- '".$eth['ip']."',
- '".$eth['subnet']."',
- '".$eth['gw'].",";
- }
- if(count($d['interface']['eth0'])<2){
- $sql_insert.="'','','','',";
- }
- foreach($d['interface']['sat0'] as $sat){
- $sql_insert.="
- '".$sat['vlanid']."',
- '".$sat['ip']."',
- '".$sat['subnet']."',
- '".$sat['gw']."',";
- }
- if(count($d['interface']['sat0'])<2){
- $sql_insert.="'','','','',";
- }
- $sql_insert.="
- NOW()
- )";
- if(++$count==10){
- $sql_insert.="SELECT * FROM dual";
- $stmt = oci_parse($con,$sql_insert)or die('statement error' . $sql_insert);;
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_insert);
- oci_free_statement($stmt);
- $count=0;
- $sql_insert="INSERT ALL ";
- }
- }
- $sql_insert.="SELECT * FROM dual ";
- $stmt = oci_parse($con,$sql_insert)or die('statement error' . $sql_insert);;
- $return=oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_insert);
- oci_free_statement($stmt);
- return $return;
- }
- //-- for insert jupiter
- function insert_jupiter($table,$con=''){
- $return=false;
- $list_fields=array
- (
- 'GWID',
- 'USERFILEMODE',
- 'BEAMID',
- 'NETWORKID',
- 'TRACELOGGINGMODE',
- 'VLNADRES0_INTFCFIPV4SUBNETMASK',
- 'VLNADRES0_VLANCFNATENABLED',
- 'VLNADRES0_INTFCFMAPPEDIPV4SBNT',
- 'VLNADRES0_INTFCFTMPLTEIPV4SBNT',
- 'VLNADRES0_INTFCFNATLCLSBNTPRFX',
- 'VLNADRES0_INTFCFNATLCLIPADRES',
- 'VLNADRES0_VLANCFVLANID',
- 'VLNADRES0_TERMINAL_REF',
- 'VLNADRES0_VLANCFNATMODE',
- 'VLNADRES0_INTFCFMAPPEDIPV6PRFX',
- 'VLNADRES0_VLANCFNAME',
- 'VLNADRES0_INTFCFTMPLTEIPV6PRFX',
- 'VLNADRES0_AUTOASSIGNED',
- 'VLNADRES0_INTFCFMAPPEDIPV4PRFX',
- 'TMPRPLCMNT0_INTFCFTMPADRTBLNDX',
- 'TMPRPLCMNT0_INTFCFSUBNETMASK',
- 'TMPRPLCMNT0_TERMINAL_CLASS',
- 'TMPRPLCMNT0_ADDRESSTYPE',
- 'TMPRPLCMNT0_INTFCFMAPEDADRSBNT',
- 'TMPRPLCMNT1_INTFCFTMPADRTBLNDX',
- 'TMPRPLCMNT1_INTFCFSUBNETMASK',
- 'TMPRPLCMNT1_TERMINAL_CLASS',
- 'TMPRPLCMNT1_ADDRESSTYPE',
- 'TMPRPLCMNT1_INTFCFMAPEDADRSBNT',
- 'TMPRPLCMNT2_INTFCFTMPADRTBLNDX',
- 'TMPRPLCMNT2_INTFCFSUBNETMASK',
- 'TMPRPLCMNT2_TERMINAL_CLASS',
- 'TMPRPLCMNT2_ADDRESSTYPE',
- 'TMPRPLCMNT2_INTFCFMAPEDADRSBNT',
- 'TMPRPLCMNT3_INTFCFTMPADRTBLNDX',
- 'TMPRPLCMNT3_INTFCFSUBNETMASK',
- 'TMPRPLCMNT3_TERMINAL_CLASS',
- 'TMPRPLCMNT3_ADDRESSTYPE',
- 'TMPRPLCMNT3_INTFCFMAPEDADRSBNT',
- 'TMPRPLCMNT4_INTFCFTMPADRTBLNDX',
- 'TMPRPLCMNT4_INTFCFSUBNETMASK',
- 'TMPRPLCMNT4_TERMINAL_CLASS',
- 'TMPRPLCMNT4_ADDRESSTYPE',
- 'TMPRPLCMNT4_INTFCFMAPEDADRSBNT',
- 'TMPRPLCMNT5_INTFCFTMPADRTBLNDX',
- 'TMPRPLCMNT5_INTFCFSUBNETMASK',
- 'TMPRPLCMNT5_TERMINAL_CLASS',
- 'TMPRPLCMNT5_ADDRESSTYPE',
- 'TMPRPLCMNT5_INTFCFMAPEDADRSBNT',
- 'SAI',
- 'SWPROFILEID',
- 'STATICIPSUBNETSIZE',
- 'MODE',
- 'TIMESTAMP',
- 'ID',
- 'AUTOLOGGINGMODE',
- 'ESN',
- 'INTFCFLANIPV4ADDR',
- 'LONGITUDE',
- 'SPID',
- 'TEMPLATEMACPARAMETERS',
- 'STATICIPWITHRTR',
- 'VSATUPLINKSPISIGNATURE',
- 'USERFILEINPUTSTRING',
- 'SWAPALLOWED',
- 'HEALTHMONITOTERMINAL',
- 'VSATUPLINKSPIPARAMS',
- 'SERVICEPLANID',
- 'TRACELEVEL',
- 'VLANGROUPID',
- 'ODUPOWER',
- 'SUSPENSIONSTATE',
- 'AUDITMEMORYCAPCITY',
- 'TRACEMEMORYCPACITY',
- 'VSATSPISIGNATURE',
- 'MOVEALLOWED',
- 'HARDWARETYPE',
- 'ACTIVATIONTYPE',
- 'SCIDI',
- 'VSATSPIPARAMS',
- 'VNID',
- 'LATITUDE',
- 'TIMEZONEID',
- 'DATE_IN'
- );
- echo "[START] processing table {$table[0]}\n";
- $nodes=file_get_contents($table[1]);
- $arr_nodes=json_decode($nodes,true);
- $list_nodes=array();
- $sql_insert="INSERT ALL ";
- $fields=implode('","',$list_fields);
- $count=0;
- foreach($arr_nodes as $d){
- $sql_insert.="INTO \"IF_INTRANET_JAH\".\"{$table[0]}\"(\"{$fields}\") VALUES ";
- $sql_insert.="(
- '{$d['gwId']}',
- '{$d['userFileMode']}',
- '{$d['beamId']}',
- '{$d['networkId']}',
- '{$d['traceLoggingMode']}',";
- foreach($d['vlanAddressing']as $eth){
- $sql_insert.="
- '".$eth['intfCfIPv4SubnetMask']."',
- '".$eth['vlanCfNatEnabled']."',
- '".$eth['intfCfMappedIPv4Subnet']."',
- '".$eth['intfCfTemplateIPv4Subnet']."',
- '".$eth['intfCfDMZAddress']."',
- '".$eth['intfCfNatLocalSubnetPrefix']."',
- '".$eth['intfCfNatLocalIpAddress']."',
- '".$eth['terminal']['_ref']."',
- '".$eth['terminal']['class']."',
- '".$eth['vlanCfNatMode']."',
- '".$eth['intfCfIPv6PrefixLen']."',
- '".$eth['intfCfMappedIPv6Prefix']."',
- '".$eth['vlanCfName']."',
- '".$eth['intfCfTemplateIPv6Prefix']."',
- '".$eth['autoAssigned']."',
- '".$eth['intfCfMappedIPv4Prefix']."',";
- }
- $k=0;
- if(!empty($d['templateReplacementAddressing'])){
- ++$k;
- foreach($d['templateReplacementAddressing'] as $sat){
- $sql_insert.="
- '".$sat['intfCfTemplateAdrTableIndex']."',
- '".$sat['intfCfAdrSubnetMask']."',
- '".$sat['terminal']['_ref']."',
- '".$sat['terminal']['class']."',
- '".$sat['intfCfTemplateAdrSubnet']."',
- '".$sat['addressType']."',
- '".$sat['intfCfMappedAdrSubnet']."',";
- }
- }
- for($l=($k-1);$l<5;$l++){
- $sql_insert.="'','','','','','','',";
- }
- $sql_insert.="(
- '{$d['sai']}',
- '{$d['swProfileId']}',
- '{$d['staticIpSubnetSize']}',
- '{$d['timestamp']}',
- '{$d['id']}',
- '{$d['auditLoggingMode']}',
- '{$d['esn']}',
- '{$d['intfCfLan1Ipv4Addr']}',
- '{$d['longitude']}',
- '{$d['spId']}',
- '".(!empty($d['templateMacParameters'])?$d['templateMacParameters']:'')."',
- '{$d['staticIPWithRtr']}',
- '{$d['vsatUplinkSpiSignature']}',
- '{$d['userFileInputString']}',
- '{$d['swapAllowed']}',
- '{$d['healthMonitorTerminal']}',
- '{$d['vsatUplinkSpiParams']}',
- '{$d['servicePlanId']}',
- '{$d['traceLevel']}',
- '{$d['vlanGroupId']}',
- '{$d['oduPower']}',
- '{$d['suspensionState']}',
- '{$d['auditMemoryCapacity']}',
- '{$d['traceMemoryCapacity']}',
- '{$d['vsatSpiSignature']}',
- '{$d['moveAllowed']}',
- '{$d['hardwareType']}',
- '{$d['activationState']}',
- '{$d['scidi']}',
- '{$d['vsatSpiParams']}',
- '{$d['vnId']}',
- '{$d['latitude']}',
- '{$d['timeZoneId']}',
- NOW()
- )";
- if(++$count==10){
- $sql_insert.="SELECT * FROM dual";
- $stmt = oci_parse($con,$sql_insert)or die('statement error' . $sql_insert);;
- oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_insert);
- oci_free_statement($stmt);
- $count=0;
- $sql_insert="INSERT ALL ";
- }
- }
- $sql_insert.="SELECT * FROM dual ";
- $stmt = oci_parse($con,$sql_insert)or die('statement error' . $sql_insert);;
- $return=oci_execute($stmt, OCI_COMMIT_ON_SUCCESS )or die('execute error ' . $sql_insert);
- oci_free_statement($stmt);
- return $return;
- }
- //-- create and insert table
- $con = oci_connect('IF_INTRANET_JAH','E9JWZz66TkkK','10.24.19.123:6725/IMSDEV') or die('connection failed !');
- $url="http://132.13.33.112/webapi/vsat/v2/vsathubs/";
- $list_table=get_list_tables($url);
- foreach($list_table as $table){
- if(substr($table[0],0,7)=='RAW_IDI'){
- $result=insert_idirect($table,$con);
- }elseif(substr($table[0],0,7)=='RAW_JUP'){
- $result=insert_jupiter($table,$con);
- }else{
- $result=insert_data($table,$con);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement