Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Read in a CSV file as taken from the command line arg
- * CSV file needs to be in the same directory as this
- * script for the time being
- *
- * Output is expected to be text representing an ACL
- * declaration that can be copypasta'd into a VCL file.
- *
- * ACL function name will be the header from CSV and
- * IPs will be formatted accordingly.
- */
- /**
- * Grab the filename from the command line args
- */
- $filename = $argv[1];
- $handle = fopen($filename, "r");
- $output = "";
- $i = 0;
- if ($handle !== FALSE) {
- while (($data = fgetcsv($handle)) !== FALSE) {
- //on the first iteration, we'll create the acl function name using the csv header
- if ($i == 0) {
- $output = "acl " . strtolower(str_replace(" ", "_", $data[0])) . " {\n";
- } else {
- $ipstr = explode('/', $data[0]);
- $output .= " \"$ipstr[0]\"/$ipstr[1];\n";
- }
- $i++;
- }
- }
- $output .= "}";
- if (file_put_contents("acl-convert.txt", $output)) {
- echo "all done!\n";
- }
- fclose($handle);
Add Comment
Please, Sign In to add comment