/[scire]/webgli/webgliIP.php
Gentoo

Contents of /webgli/webgliIP.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (show annotations) (download)
Sun Apr 23 05:49:53 2006 UTC (11 years, 7 months ago) by codeman
File size: 13047 byte(s)
  webgli: adding initial screens of makedotconf

1 <?
2 require_once('XMLParser.php');
3
4 class InstallProfile extends XMLParser {
5 /*
6 An object representation of a profile.
7 InstallProfile is an object representation of a parsed installation
8 profile file.
9 */
10
11 ##
12 # Initializes all variables to default values and adds handlers.
13 # Configuration information - profile data
14 # All variables must be declared here with a default value to ensure
15 # the XML will correctly serialize.
16
17 function InstallProfile() {
18 $this->_temp_etc_file = array();
19 $this->_temp_partition_table = array();
20 $this->xmldoc = "";
21
22 $this->values = array(
23 'boot_device' => array( 'type' => 'string', value => '' ),
24 'bootloader_kernel_args' => array( 'type' => 'string', 'value' => "" ),
25 'bootloader_mbr' => array( 'type' => 'bool', 'value' => 1 ),
26 'bootloader_pkg' => array( 'type' => 'string', 'value' => 'grub' ),
27 'cron_daemon_pkg' => array( 'type' => 'string', 'value' => 'vixie-cron' ),
28 'default_gateway' => array( 'type' => 'array', 'value' => array(), 'serialize_func' => 'serialize_default_gateway' ),
29 'dns_servers' => array( 'type' => 'array', 'value' => array() ),
30 'domainname' => array( 'type' => 'string', 'value' => "localdomain" ),
31 'dynamic_stage3' => array( 'type' => 'bool', 'value' => 0 ),
32 'etc_files' => array( 'type' => 'array', 'value' => array(), 'serialize_func' => 'serialize_etc_files' ),
33 'ftp_proxy' => array( 'type' => 'string', 'value' => "" ),
34 'grp_install' => array( 'type' => 'bool', 'value' => 0 ),
35 'hostname' => array( 'type' => 'string', 'value' => "localhost" ),
36 'http_proxy' => array( 'type' => 'string', 'value' => "" ),
37 'install_distcc' => array( 'type' => 'bool', 'value' => 0 ),
38 'install_packages' => array( 'type' => 'array', 'value' => array() ),
39 'install_pcmcia_cs' => array( 'type' => 'bool', 'value' => 0 ),
40 'install_rp_pppoe' => array( 'type' => 'bool', 'value' => 0 ),
41 'install_stage' => array( 'type' => 'int', 'value' => 3 ),
42 'logging_daemon_pkg' => array( 'type' => 'string', 'value' => 'syslog-ng' ),
43 'kernel_bootsplash' => array( 'type' => 'bool', 'value' => 0 ),
44 'kernel_build_method' => array( 'type' => 'string', 'value' => 'genkernel' ),
45 'kernel_config_uri' => array( 'type' => 'uri', 'value' => '' ),
46 'kernel_modules' => array( 'type' => 'array', 'value' => array() ),
47 'kernel_initrd' => array( 'type' => 'bool', 'value' => 1 ),
48 'kernel_source_pkg' => array( 'type' => 'string', 'value' => "livecd-kernel" ),
49 'mta_pkg' => array( 'type' => 'string', 'value' => "" ),
50 'network_mounts' => array( 'type' => 'array', 'value' => array(), 'serialize_func' => 'serialize_network_mounts' ),
51 'network_interfaces' => array( 'type' => 'array', 'value' => array(), 'serialize_func' => 'serialize_network_interfaces' ),
52 'nisdomainname' => array( 'type' => 'string', 'value' => "" ),
53 'partition_tables' => array( 'type' => 'array', 'value' => array(), 'serialize_func' => 'serialize_partition_tables' ),
54 'portage_tree_snapshot_uri' => array( 'type' => 'uri', 'value' => "" ),
55 'portage_tree_sync_type' => array( 'type' => 'string', 'value' => "sync" ),
56 'post_install_script_uri' => array( 'type' => 'uri', 'value' => "" ),
57 'root_pass_hash' => array( 'type' => 'string', 'value' => "" ),
58 'rsync_proxy' => array( 'type' => 'string', 'value' => "" ),
59 'services' => array( 'type' => 'array', 'value' => array() ),
60 'stage_tarball_uri' => array( 'type' => 'uri', 'value' => "" ),
61 'time_zone' => array( 'type' => 'string', 'value' => "UTC" ),
62 'users' => array( 'type' => 'array', 'value' => array(), 'serialize_func' => 'serialize_users' ),
63 );
64
65 $this->xmlpaths = array(
66 'gli-profile/bootloader' => 'bootloader_pkg',
67 'gli-profile/boot-device' => 'boot_device',
68 'gli-profile/bootloader-kernel-args' => 'bootloader_kernel_args',
69 'gli-profile/bootloader-mbr' => 'bootloader_mbr',
70 'gli-profile/cron-daemon' => 'cron_daemon_pkg',
71 'gli-profile/default-gateway' => 'parse_default_gateway',
72 'gli-profile/dns-servers' => 'dns_servers',
73 'gli-profile/domainname' => 'domainname',
74 'gli-profile/dynamic-stage3' => 'dynamic_stage3',
75 'gli-profile/etc-files/file' => 'parse_etc_files_file',
76 'gli-profile/etc-files/file/entry' => 'parse_etc_files_file_entry',
77 'gli-profile/ftp-proxy' => 'ftp_proxy',
78 'gli-profile/grp-install' => 'grp_install',
79 'gli-profile/hostname' => 'hostname',
80 'gli-profile/http-proxy' => 'http_proxy',
81 'gli-profile/install-distcc' => 'install_distcc',
82 'gli-profile/install-packages' => 'install_packages',
83 'gli-profile/install-pcmcia-cs' => 'install_pcmcia_cs',
84 'gli-profile/install-rp-pppoe' => 'install_rp_pppoe',
85 'gli-profile/install-stage' => 'install_stage',
86 'gli-profile/kernel-bootsplash' => 'kernel_bootsplash',
87 'gli-profile/kernel-build-method' => 'kernel_build_method',
88 'gli-profile/kernel-config' => 'kernel_config_uri',
89 'gli-profile/kernel-initrd' => 'kernel_initrd',
90 'gli-profile/kernel-modules' => 'kernel_modules',
91 'gli-profile/kernel-source' => 'kernel_source_pkg',
92 'gli-profile/logging-daemon' => 'logging_daemon_pkg',
93 'gli-profile/mta' => 'mta_pkg',
94 'gli-profile/network-interfaces/device' => 'parse_network_interface',
95 'gli-profile/network-mounts/netmount' => 'parse_netmount',
96 'gli-profile/nisdomainname' => 'nisdomainname',
97 'gli-profile/partitions/device' => 'parse_partitions_device',
98 'gli-profile/partitions/device/partition' => 'parse_partitions_device_partition',
99 'gli-profile/portage-snapshot' => 'portage_tree_snapshot_uri',
100 'gli-profile/portage-tree-sync' => 'portage_tree_sync_type',
101 'gli-profile/post-install-script-uri' => 'post_install_script_uri',
102 'gli-profile/root-pass-hash' => 'root_pass_hash',
103 'gli-profile/rsync-proxy' => 'rsync_proxy',
104 'gli-profile/services' => 'services',
105 'gli-profile/stage-tarball' => 'stage_tarball_uri',
106 'gli-profile/time-zone' => 'time_zone',
107 'gli-profile/users/user' => 'parse_user',
108 );
109 }
110
111 function serialize() {
112 return $this->_serialize("gli-profile");
113 }
114
115 function parse_default_gateway($gateway, $attr) {
116 $this->set("default_gateway", array($attr['interface'], $gateway));
117 }
118
119 function serialize_default_gateway() {
120 $gw = $this->get("default_gateway");
121 return sprintf("\t<default-gateway interface=\"%s\">\n\t\t%s\n\t</default-gateway>\n", $gw[0], $gw[1]);
122 }
123
124 function parse_etc_files_file_entry($value, $attr) {
125 if($attr['name']) {
126 if(!$this->_temp_etc_file) $this->_temp_etc_file = array();
127 $this->_temp_etc_file[$attr['name']] = $value;
128 } else {
129 if(!$this->_temp_etc_file) $this->_temp_etc_file = array();
130 $this->_temp_etc_file[] = $value;
131 }
132 }
133
134 function parse_etc_files_file($value, $attr) {
135 $etc_files = $this->get("etc_files");
136 $etc_files[$attr['name']] = $this->_temp_etc_file;
137 $this->_temp_etc_file = array();
138 $this->set("etc_files", $etc_files);
139 }
140
141 function serialize_etc_files() {
142 $etc_files = $this->get("etc_files");
143 if($etc_files) {
144 $this->xmldoc .= "\t<etc-files>\n";
145 foreach($etc_files as $etc_file => $values) {
146 $this->xmldoc .= sprintf("\t\t<file name=\"%s\">\n", $etc_file);
147 $isalist = (array_keys($values) === range(0, count($values) - 1)) ? true : false;
148 foreach($values as $name => $value) {
149 $this->xmldoc .= "\t\t\t<entry";
150 if($isalist) {
151 $this->xmldoc .= sprintf(">\n\t\t\t\t%s\n", $value);
152 } else {
153 $this->xmldoc .= sprintf(" name=\"%s\">\n\t\t\t\t%s\n", $name, $value);
154 }
155 $this->xmldoc .= "\t\t\t</entry>\n";
156 }
157 $this->xmldoc .= "\t\t</file>\n";
158 }
159 $this->xmldoc .= "\t</etc-files>\n";
160 }
161 }
162
163 function parse_network_interface($device, $attr) {
164 $options = null;
165 $ip = $broadcast = $netmask = $dhcp_options = null;
166 $dhcp = true;
167
168 foreach($attr as $name => $value) {
169 switch($name) {
170 case 'ip':
171 $ip = $value;
172 break;
173 case 'broadcast':
174 $broadcast = $value;
175 break;
176 case 'netmask':
177 $netmask = $value;
178 break;
179 case 'options':
180 $dhcp_options = $value;
181 break;
182 }
183 }
184
185 if($ip != 'dhcp') {
186 $dhcp = false;
187 $options = array($ip, $broadcast, $netmask);
188 } else {
189 $options = array('dhcp', $dhcp_options, '');
190 }
191
192 $network_interfaces = $this->get("network_interfaces");
193 $network_interfaces[$device] = $options;
194 $this->set("network_interfaces", $network_interfaces);
195 }
196
197 function serialize_network_interfaces() {
198 $interfaces = $this->get("network_interfaces");
199 if($interfaces) {
200 $this->xmldoc .= "\t<network-interfaces>\n";
201 foreach($interfaces as $iname => $interface) {
202 if($interface[0] == 'dhcp') {
203 $attrs = "ip=\"dhcp\"";
204 if($interface[1]) {
205 $dhcp_options = sprintf("options=\"%s\"", $interface[1]);
206 $attrs .= " " . $dhcp_options;
207 }
208 $this->xmldoc .= sprintf("\t\t<device %s>%s</device>\n", $attrs, $iname);
209 } else {
210 $this->xmldoc .= sprintf("\t\t<device ip=\"%s\" broadcast=\"%s\" netmask=\"%s\">%s</device>\n", $interface[0], $interface[1], $interface[2], $iname);
211 }
212 }
213 $this->xmldoc .= "\t</network-interfaces>\n";
214 }
215 }
216
217 function parse_netmount($unused, $attr) {
218 $netmount_entry = array('export' => '', 'host' => '', 'mountopts' => '', 'mountpoint' => '', 'type' => '');
219 foreach($attr as $name => $value) {
220 $netmount_entry[$name] = $value;
221 }
222 $network_mounts = $this->get("network_mounts");
223 $network_mounts[] = $netmount_entry;
224 $this->set("network_mounts", $network_mounts);
225 }
226
227 function serialize_network_mounts() {
228 $network_mounts = $this->get("network_mounts");
229 if($network_mounts) {
230 $this->xmldoc .= "\t<network-mounts>\n";
231 foreach($network_mounts as $mount) {
232 $this->xmldoc .= sprintf("\t\t<netmount host=\"%s\" export=\"%s\" type=\"%s\" mountpoint=\"%s\" mountopts=\"%s\"/>\n", $mount['host'], $mount['export'], $mount['type'], $mount['mountpoint'], $mount['mountopts']);
233 }
234 $this->xmldoc .= "\t</network-mounts>\n";
235 }
236 }
237
238 function parse_partitions_device($unused, $attr) {
239 $devnode = "";
240 $disklable = "";
241 foreach($attr as $name => $value) {
242 if($name == "devnode") {
243 $devnode = $value;
244 } elseif($name == "disklabel") {
245 $disklabel = $value;
246 }
247 }
248 $partition_tables = $this->get("partition_tables");
249 $partition_tables[$devnode] = $this->_temp_partition_table;
250 $this->_temp_partition_table = array();
251 $this->set("partition_tables", $partition_tables);
252 }
253
254 function parse_partitions_device_partition($unused, $attr) {
255 $part_entry = array();
256 foreach($attr as $name => $value) {
257 $part_entry[$name] = $value;
258 }
259 $part_entry['format'] = $part_entry['format'] == "True" ? true : false;
260 $part_entry['resized'] = $part_entry['resized'] == "True" ? true : false;
261 # if GLIUtility.is_numeric(part_entry['mb']): part_entry['mb'] = long(part_entry['mb'])
262 # if GLIUtility.is_numeric(part_entry['minor']):
263 # part_entry['minor'] = float(part_entry['minor'])
264 # if int(part_entry['minor']) == part_entry['minor']:
265 # part_entry['minor'] = int(part_entry['minor'])
266 # if GLIUtility.is_numeric(part_entry['origminor']): part_entry['origminor'] = int(part_entry['origminor'])
267 $this->_temp_partition_table[] = $part_entry;
268 }
269
270 function serialize_partition_tables() {
271 $partitions = $this->get("partition_tables");
272 if($partitions) {
273 $this->xmldoc .= "\t<partitions>\n";
274 foreach($partitions as $device => $parts) {
275 $this->xmldoc .= sprintf("\t\t<device devnode=\"%s\" disklabel=\"%s\">\n", $device, "msdos"); #partitions[device].get_disklabel())
276 foreach($parts as $part) {
277 $this->xmldoc .= sprintf("\t\t\t<partition minor=\"%s\" origminor=\"%s\" mb=\"%s\" type=\"%s\" mountpoint=\"%s\" mountopts=\"%s\" format=\"%s\" mkfsopts=\"%s\" resized=\"%s\"/>\n", $part['minor'], $part['origminor'], $part['mb'], $part['type'], $part['mountpoint'], $part['mountopts'], $part['format'], $part['mkfsopts'], $part['resized']);
278 }
279 $this->xmldoc .= "\t\t</device>\n";
280 }
281 $this->xmldoc .= "\t</partitions>\n";
282 }
283 }
284
285 function parse_user($username, $attr) {
286 $tmp_user = array();
287 foreach($attr as $name => $value) {
288 $tmp_user[$name] = $value;
289 }
290 $users = $this->get("users");
291 $users[] = array($username, $tmp_user['hash'], $tmp_user['groups'], $tmp_user['shell'], $tmp_user['homedir'], $tmp_user['uid'], $tmp_user['comment']);
292 $this->set("users", $users);
293 }
294
295 function serialize_users() {
296 $users = $this->get("users");
297 if($users) {
298 $this->xmldoc .= "\t<users>\n";
299 foreach($users as $user) {
300 $attrstr = "";
301 if($user[1]) $attrstr .= sprintf("hash=\"%s\" ", $user[1]);
302 if($user[2]) $attrstr .= sprintf("groups=\"%s\" ", implode(",", $user[2]));
303 if($user[3]) $attrstr .= sprintf("shell=\"%s\" ", $user[3]);
304 if($user[4]) $attrstr .= sprintf("homedir=\"%s\" ", $user[4]);
305 if($user[5]) $attrstr .= sprintf("uid=\"%s\" ", $user[5]);
306 if($user[6]) $attrstr .= sprintf("comment=\"%s\" ", $user[6]);
307 $this->xmldoc .= sprintf("\t\t<user %s>\n\t\t\t%s\n\t\t</user>\n", trim($attrstr), $user[0]);
308 }
309 $this->xmldoc .= "\t</users>\n";
310 }
311 }
312 }
313 ?>

  ViewVC Help
Powered by ViewVC 1.1.20