I know little about PHP so decided that the creation of a web-based tool for generating Red Hat kickstart files will be a good project to learn with. Among other things, the tool will parse a CSV file and generate a table containing the data taken from it. The input file is in the following format:
host1,10.153.196.248,255.255.255.0,10.153.196.1,00:50:56:ac:69:cb ,10.153.157.113,255.255.255.128,10.153.157.1, ,10.153.157.241,255.255.255.128,10.153.157.129, ,/home,10,,, ,swap,10,,, ,/opt,60,,, ,/data,30,,, ,,,,, host2,10.153.155.124,255.255.255.128,10.153.155.1,00:50:56:ac:69:ce ,10.153.157.114,255.255.255.128,10.153.157.1, ,10.153.157.242,255.255.255.128,10.153.157.129, ,/home,10,,, ,swap,10,,, ,/opt,60,,, ,/data,30,,, ,,,,,
Each section of text represents the information for one server. The fields are as follows:
hostname,eth0 IP, eth0 netmask, eth0 gateway, eth4 MAC null,eth1 IP, eth1 netmask, eth1 gateway, null blank,eth2 IP, eth2 netmask, eth2 gateway, null null,partition name, partition size in GB, null, null null,partition name, partition size in GB, null, null null,partition name, partition size in GB, null, null null,partition name, partition size in GB, null, null null,null,null,null,null
At the moment, I can parse it and generate a table with each row in the input file being a row in the table. The function that handles this:
function processFile($workFile) {
    if (file_exists($workFile)) {
        print '<table>';
        $fh = fopen("$workFile", 'rb');
        if ($fh) {
            for ($line = fgets($fh); !feof($fh); $line = fgets($fh)) {
                $line = trim($line);
                $info = explode(',', $line);
                print '<tr><td>' . $info[0] . '</td><td>' . $info[1] . '</td><td>' . $info[2] . '</td><td>' . $info[3] . '</td></tr>';
            }
        } else {
            print "Failed to open $workFile";
        }
        print '</table>';
    } else {
        print "File $workFile does not exist";
    }
}
Which generates:
host1     eth0 IP      eth0 netmask      eth0 gateway
          eth1 IP      eth1 netmask      eth1 gateway
          eth2 IP      eth2 netmask      eth2 gateway
          partition 1  partition 1 size
          partition 2  partition 2 size
          partition 3  partition 3 size
          partition 4  partition 4 size
host2     eth0 IP      eth0 netmask      eth0 gateway
          eth1 IP      eth1 netmask      eth1 gateway
          eth2 IP      eth2 netmask      eth2 gateway
          partition 1  partition 1 size
          partition 2  partition 2 size
          partition 3  partition 3 size
          partition 4  partition 4 size
This is a start. However, not every server is going to have four partitions. Some will have many more, some will have one or two fewer. And not knowing that information ahead of time puts a hindrance on what I want to do which is to add a row below the partition information for each server as well as probably break each server up into its own table. Something along the lines of this:
host1     eth0 IP          eth0 netmask      eth0 gateway
          eth1 IP          eth1 netmask      eth1 gateway
          eth2 IP          eth2 netmask      eth2 gateway
          partition 1      partition 1 size
          partition 2      partition 2 size
          partition 3      partition 3 size
          partition 4      partition 4 size
          partition 5      partition 5 size
          partition 6      partition 6 size
          How many disks?  [Text Field}    
host2     eth0 IP          eth0 netmask      eth0 gateway
          eth1 IP          eth1 netmask      eth1 gateway
          eth2 IP          eth2 netmask      eth2 gateway
          partition 1      partition 1 size
          partition 2      partition 2 size
          partition 3      partition 3 size
          partition 4      partition 4 size
          How many disks?  [Text Field}
My prevailing thought is that I'm going to have to have a field in the CSV file indicate that the row contains partition information. It seems the easiest approach. I'm wondering if there is another means I could use, though, that doesn't require altering the format of the input file.
I'll also have to figure out how to use the line containing all null fields as the section delimiter.
Any thoughts on how I can approach this will be appreciated.
 
     
     
    