Guest User

Untitled

a guest
Dec 7th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. form.cfm
  2. <form action="handler.cfm" method="post">
  3.     StartIP <input type="text" name="startIP" value="10.1.5.0" />
  4.     <br><br>
  5.    
  6.     EndIP <input type="text" name="endIP" value="10.1.5.255" />
  7.     <br><br>
  8.    
  9.     Status  <select name="ipStatus">
  10.                 <option>1</option>
  11.                 <option>2</option>
  12.                 <option>3</option>
  13.                 <option>4</option>
  14.             </select>
  15.     <br><br>
  16.    
  17.     Group <input type="text" name="groupName" value="workgroup" />
  18.     <br><br>
  19.    
  20.     <input type="submit" value=" GO " />
  21. </form>
  22.  
  23.  
  24. handler.cfm
  25. <cfscript>
  26. // NOTE : just assuming all data is correct from the form
  27. startIP     = form["startIP"];
  28. endIP       = form["endIP"];
  29. ipStatus    = form["ipStatus"];
  30. groupName   = form["groupName"];
  31.  
  32. // setup vars for loop processing
  33. xx          = listToArray( startIp, ".")[4];    // first IP in range
  34. _endBit     = listToArray( endIp, ".")[4];      // last IP in range
  35. _ipPrefix   = Replace( startIp, ".#xx#", "" );  // trim off the final .999 to get ipPrefix
  36. insertArray = ArrayNew(1);  // temp array to hold insert values
  37.  
  38.  
  39. // loop through ip range and create VALUES list for SQL INSERT
  40. while( xx <= _endBit )
  41. {
  42.     // append each row's value to array
  43.     ArrayAppend( insertArray, "( '#groupName#', '#_ipPrefix#.#xx#', #ipStatus# )" );
  44.     xx++;
  45. }
  46. // convert array to comma delimited list
  47. insert_values = ArrayToList( insertArray, "," );
  48.  
  49. // cleanup
  50. ArrayClear( insertArray );
  51. </cfscript>
  52.  
  53.  
  54. <cfoutput>
  55. <cfquery name="insert_data" result="insert_result" DATASOURCE="#request.dsn#" USERNAME="#request.dbuser#" PASSWORD="#request.dbpswd#">
  56. INSERT INTO GROUP_IPS ( group_id, ip_address, status )
  57. VALUES
  58. #PreserveSingleQuotes( insert_values )#
  59. </cfquery>
  60. </cfoutput>
Add Comment
Please, Sign In to add comment