@@ -123,31 +123,32 @@ function detectConfigType(inputConfig) {
123123
124124function generateConfigs ( ) {
125125 const inputType = document . getElementById ( 'inputType' ) . value ;
126- const inputConfig = document . getElementById ( 'inputConfig' ) . value ;
126+ const rawInput = document . getElementById ( 'inputConfig' ) . value . trim ( ) ;
127127
128- if ( ! inputConfig ) {
128+ if ( ! rawInput ) {
129129 showWarning ( 'Please enter the config.' ) ;
130130 return ;
131131 }
132132
133- if ( ! isValidConfigFormat ( inputConfig ) ) {
134- showWarning ( 'The entered config is invalid.' ) ;
133+ const baseConfigs = rawInput . split ( '\n' ) . filter ( c => isValidConfigFormat ( c . trim ( ) ) ) ;
134+
135+ if ( baseConfigs . length === 0 ) {
136+ showWarning ( 'No valid base configs found.' ) ;
135137 return ;
136138 }
137139
138140 if ( inputType === 'cidr' ) {
139- modifyConfigsFromCIDR ( ) ;
141+ modifyConfigsFromCIDR ( baseConfigs ) ;
140142 } else if ( inputType === 'list' ) {
141- modifyConfigsFromList ( ) ;
143+ modifyConfigsFromList ( baseConfigs ) ;
142144 } else if ( inputType === 'configList' ) {
143- modifyConfigsFromConfigsList ( ) ;
145+ modifyConfigsFromConfigsList ( baseConfigs ) ;
144146 }
145147}
146148
147- function modifyConfigsFromCIDR ( ) {
148- const inputConfig = document . getElementById ( 'inputConfig' ) . value ;
149+ function modifyConfigsFromCIDR ( baseConfigs ) {
149150 const ipRanges = document . getElementById ( 'ipRange' ) . value . trim ( ) . split ( '\n' ) . filter ( range => range . trim ( ) !== '' ) ;
150- const outputCount = document . getElementById ( 'outputCount' ) . value ;
151+ const outputCount = parseInt ( document . getElementById ( 'outputCount' ) . value ) ;
151152
152153 if ( ipRanges . length === 0 ) {
153154 showWarning ( 'Please enter at least one IP range.' ) ;
@@ -164,28 +165,27 @@ function modifyConfigsFromCIDR() {
164165 generatedOutput = '' ;
165166 let count = 0 ;
166167
167- for ( const ipRange of ipRanges ) {
168- const [ ip , range ] = ipaddr . parseCIDR ( ipRange . trim ( ) ) ;
169- const ipType = ip . kind ( ) ;
168+ for ( const config of baseConfigs ) {
169+ if ( count >= outputCount ) break ;
170170
171- let currentIp = ip ;
172- while ( currentIp . match ( ipaddr . parseCIDR ( ipRange . trim ( ) ) ) && count < parseInt ( outputCount ) ) {
173- generatedOutput += replaceIPInConfig ( inputConfig , currentIp ) ;
174- count ++ ;
171+ for ( const ipRange of ipRanges ) {
172+ const [ ip , range ] = ipaddr . parseCIDR ( ipRange . trim ( ) ) ;
173+ let currentIp = ip ;
175174
176- if ( count >= parseInt ( outputCount ) ) {
177- break ;
175+ while ( currentIp . match ( ipaddr . parseCIDR ( ipRange . trim ( ) ) ) && count < outputCount ) {
176+ generatedOutput += replaceIPInConfig ( config . trim ( ) , currentIp ) ;
177+ count ++ ;
178+ currentIp = incrementIP ( currentIp ) ;
178179 }
179180
180- currentIp = incrementIP ( currentIp ) ;
181+ if ( count >= outputCount ) break ;
181182 }
182183 }
183184
184185 displayResult ( count ) ;
185186}
186187
187- function modifyConfigsFromList ( ) {
188- const inputConfig = document . getElementById ( 'inputConfig' ) . value ;
188+ function modifyConfigsFromList ( baseConfigs ) {
189189 const ipList = document . getElementById ( 'ipList' ) . value . trim ( ) . split ( '\n' ) . filter ( ip => ip . trim ( ) !== '' ) ;
190190
191191 if ( ipList . length === 0 ) {
@@ -196,22 +196,20 @@ function modifyConfigsFromList() {
196196 generatedOutput = '' ;
197197 let count = 0 ;
198198
199- for ( const ip of ipList ) {
200- let ipStr = ip . trim ( ) ;
201- if ( ipaddr . isValid ( ipStr ) ) {
202- generatedOutput += replaceIPInConfig ( inputConfig , ipaddr . parse ( ipStr ) ) ;
203- count ++ ;
204- } else {
205- showWarning ( `Invalid IP found: ${ ipStr } ` ) ;
206- return ;
199+ for ( const config of baseConfigs ) {
200+ for ( const ip of ipList ) {
201+ let ipStr = ip . trim ( ) ;
202+ if ( ipaddr . isValid ( ipStr ) ) {
203+ generatedOutput += replaceIPInConfig ( config . trim ( ) , ipaddr . parse ( ipStr ) ) ;
204+ count ++ ;
205+ }
207206 }
208207 }
209208
210209 displayResult ( count ) ;
211210}
212211
213- function modifyConfigsFromConfigsList ( ) {
214- const inputConfig = document . getElementById ( 'inputConfig' ) . value ;
212+ function modifyConfigsFromConfigsList ( baseConfigs ) {
215213 const configList = document . getElementById ( 'configList' ) . value . trim ( ) . split ( '\n' ) . filter ( config => config . trim ( ) !== '' ) ;
216214
217215 if ( configList . length === 0 ) {
@@ -222,11 +220,13 @@ function modifyConfigsFromConfigsList() {
222220 generatedOutput = '' ;
223221 let count = 0 ;
224222
225- for ( const config of configList ) {
226- const address = extractAddressFromConfig ( config . trim ( ) ) ;
227- if ( address ) {
228- generatedOutput += replaceIPInConfig ( inputConfig , address ) ;
229- count ++ ;
223+ for ( const baseConfig of baseConfigs ) {
224+ for ( const targetConfig of configList ) {
225+ const address = extractAddressFromConfig ( targetConfig . trim ( ) ) ;
226+ if ( address ) {
227+ generatedOutput += replaceIPInConfig ( baseConfig . trim ( ) , address ) ;
228+ count ++ ;
229+ }
230230 }
231231 }
232232
0 commit comments