Guest User

Untitled

a guest
Jun 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Read in a CSV file as taken from the command line arg
  5. * CSV file needs to be in the same directory as this
  6. * script for the time being
  7. *
  8. * Output is expected to be text representing an ACL
  9. * declaration that can be copypasta'd into a VCL file.
  10. *
  11. * ACL function name will be the header from CSV and
  12. * IPs will be formatted accordingly.
  13. */
  14.  
  15.  
  16. /**
  17. * Grab the filename from the command line args
  18. */
  19. $filename = $argv[1];
  20.  
  21. $handle = fopen($filename, "r");
  22.  
  23. $output = "";
  24. $i = 0;
  25.  
  26. if ($handle !== FALSE) {
  27.  
  28. while (($data = fgetcsv($handle)) !== FALSE) {
  29. //on the first iteration, we'll create the acl function name using the csv header
  30. if ($i == 0) {
  31. $output = "acl " . strtolower(str_replace(" ", "_", $data[0])) . " {\n";
  32. } else {
  33. $ipstr = explode('/', $data[0]);
  34. $output .= " \"$ipstr[0]\"/$ipstr[1];\n";
  35. }
  36. $i++;
  37. }
  38. }
  39.  
  40. $output .= "}";
  41.  
  42. if (file_put_contents("acl-convert.txt", $output)) {
  43. echo "all done!\n";
  44. }
  45.  
  46. fclose($handle);
Add Comment
Please, Sign In to add comment