Implement option to manage virtual networks using VMC
authorMichal Novotny <minovotn@redhat.com>
Fri, 22 Jul 2011 12:10:55 +0000 (14:10 +0200)
committerMichal Novotny <minovotn@redhat.com>
Fri, 22 Jul 2011 12:10:55 +0000 (14:10 +0200)
Signed-off-by: Michal Novotny <minovotn@redhat.com>

classes/language.php
classes/libvirt.php
error.php
lang/cs.php
lang/en.php
main-menu.php
pages/network-list.php [new file with mode: 0644]
pages/new-net.php [new file with mode: 0644]

index cdb4e18..2f064fc 100644 (file)
@@ -33,6 +33,9 @@
                                        'password' => 'Password',
                                        'Yes' => 'Yes',
                                        'No' => 'No',
+                                       'error_page_title' => 'Error',
+                                       'error_page_label' => 'Page not found:',
+                                       'error_page_text' => 'The page you were looking for was not found. Please report to the administrator and try again later.',
                                        'host_details' => 'Host details',
                                        'model' => 'Model',
                                        'pcpus' => 'CPUs/cores',
                                        'conn_failed' => 'Connection has failed',
                                        'domain_list' => 'Domain list',
                                        'dom_screenshot' => 'Screenshot',
+                                       'network_list' => 'Network list',
                                        'dom_none' => 'No valid domain defined',
                                        'main_menu' => 'Main menu',
                                        'cannot_connect' => 'Cannot connect to hypervisor. Please change connection information.',
                                        'new-vm-existing' => 'Use existing disk image',
                                        'new-vm-create' => 'Create new disk image',
                                        'vm-disk-size' => 'New disk size',
+                                       'net_ip' => 'IP Address',
+                                       'net_mask' => 'Subnet mask',
+                                       'net_range' => 'IP Range',
+                                       'net_forward' => 'Forwarding',
+                                       'net_dev' => 'Forwarding to device',
+                                       'net_dhcp_range' => 'DHCP Range',
+                                       'net_active' => 'Active',
+                                       'create-new-network' => 'Create a new network',
+                                       'net_start' => 'Start network',
+                                       'net_dumpxml' => 'Dump network XML',
+                                       'net_editxml' => 'Edit network XML',
+                                       'net_undefine' => 'Undefine network',
+                                       'net_stop' => 'Stop network',                                   
+                                       'net_xmldesc' => 'Network XML description',
+                                       'net_editxml' => 'Edit network XML description',
+                                       'net_define_changed' => 'Network definition changed',
+                                       'net_define_change_err' => 'Error occurred while changing network definition',
+                                       'net_start_ok' => 'Network has been started successfully',
+                                       'net_start_err' => 'An error occurred while starting the network',
+                                       'net_stop_ok' => 'Network has been stopped successfully',
+                                       'net_stop_err' => 'An error occurred while stopping the network',
+                                       'net_undefine_question' => 'Do you really want to undefine this network?',
+                                       'net_undefine_ok' => 'Network has been successfully undefined',
+                                       'net_undefine_err' => 'An error occurred while undefining the network',
+                                       'net_ip_range_def' => 'IP Range definition',
+                                       'net_ip_cidr' => 'CIDR (192.168.111.0/24)',
+                                       'net_ip_direct' => 'Direct (2 values)',
+                                       'net_ipdef_cidr' => 'CIDR Definition',
+                                       'dhcp' => 'DHCP',
+                                       'net_dhcp_start' => 'DHCP Range start',
+                                       'net_dhcp_end' => 'DHCP Range end',
+                                       'net_forward_none' => 'none',
+                                       'net_forward_nat' => 'NAT',
+                                       'net_forward_route' => 'Route',
+                                       'net_created' => 'Network has been created successfully',
                                        );
 
                        $this->trans = $trans;
index 3bb9168..32c1058 100644 (file)
@@ -39,7 +39,7 @@
                }
 
                function domain_new($name, $img, $vcpus, $features, $mem, $maxmem, $clock, $nic, $disk, $persistent=true) {
-                       $uuid = $this->domain_generate_uuid_unique();
+                       $uuid = $this->domain_generate_uuid();
                        $emulator = $this->get_default_emulator();
 
                        $mem *= 1024;
                        return true;
                }
 
+               function network_new($name, $ipinfo, $dhcpinfo=false, $forward=false, $forward_dev=false, $bridge=false) {
+                       $uuid = $this->network_generate_uuid();
+                       if (!$bridge) {
+                               $maxid = -1;
+                               $nets = $this->get_networks();
+                               for ($i = 0; $i < sizeof($nets); $i++) {
+                                       $bridge = $this->get_network_bridge($nets[$i]);
+                                       if ($bridge) {
+                                               $tmp = explode('br', $bridge);
+                                               $id = (int)$tmp[1];
+
+                                               if ($id > $maxid)
+                                                       $maxid = $id;
+                                       }
+                               }
+
+                               $newid = $maxid + 1;
+                               $bridge = 'virbr'.$newid;
+                       }
+
+                       $forwards = '';
+                       if ($forward) {
+                               if (!$forward_dev)
+                                       $forwards = "<forward mode='$forward' />";
+                               else
+                                       $forwards = "<forward mode='$forward' dev='$forward_dev' />";
+                       }
+
+                       /* array('ip' => $ip, 'netmask' => $mask) has been passed */
+                       if (is_array($ipinfo)) {
+                               $ip = $ipinfo['ip'];
+                               $mask = $ipinfo['netmask'];
+                       }
+                       else {
+                               /* CIDR definition otherwise, like 192.168.122.0/24 */
+                               $tmp = explode('/', $ipinfo);
+                               $ipc = explode('.', $tmp[0]);
+                               $ipc[3] = (int)$ipc[3] + 1;
+                               $ip = implode('.', $ipc);
+
+                               $bin = '';
+                               for ($i = 0; $i < $tmp[1]; $i++)
+                                       $bin .= '1';
+
+                               $tmp = bindec($bin);
+                               $ipc[0] = $tmp         % 256;
+                               $ipc[1] = ($tmp >> 8 ) % 256;
+                               $ipc[2] = ($tmp >> 16) % 256;
+                               $ipc[3] = ($tmp >> 24) % 256;
+
+                               $mask = implode('.', $ipc);
+                       }
+
+                       $dhcps = '';
+                       if ($dhcpinfo) {
+                               /* For definition like array('start' => $dhcp_start, 'end' => $dhcp_end) */
+                               if (is_array($dhcpinfo)) {
+                                       $dhcp_start = $dhcpinfo['start'];
+                                       $dhcp_end = $dhcpinfo['end'];
+                               }
+                               else {
+                                       /* Definition like '$dhcp_start - $dhcp_end' */
+                                       $tmp = explode('-', $dhcpinfo);
+                                       $dhcp_start = Trim($tmp[0]);
+                                       $dhcp_end = Trim($tmp[1]);
+                               }
+
+                               $dhcps = "<dhcp>
+                                                <range start='$dhcp_start' end='$dhcp_end' />
+                                        </dhcp>";
+                       }
+
+                       $xml = "<network>
+                               <name>$name</name>
+                               <uuid>$uuid</uuid>
+                               $forwards
+                               <bridge name='$bridge' stp='on' delay='0' />
+                               <ip address='$ip' netmask='$mask'>
+                                       $dhcps
+                               </ip>
+                               </network>";
+
+                       return $this->network_define($xml);
+               }
+
+               function network_define($xml) {
+                       $tmp = libvirt_network_define_xml($this->conn, $xml);
+                       return ($tmp) ? $tmp : $this->_set_last_error();
+               }
+
+               function network_undefine($network) {
+                       $net = $this->get_network_res($network);
+                       $tmp = libvirt_network_undefine($net);
+                       return ($tmp) ? $tmp : $this->_set_last_error();
+               }
+
                function translate_storagepool_state($state) {
                        $lang = new Language($this->lang_str);
                        $ret = $lang->get('unknown');
                        return ($tmp) ? $tmp : $this->_set_last_error();
                }
 
-               function domain_generate_uuid($seed=false) {
+               function generate_uuid($seed=false) {
                        if (!$seed)
                                $seed = time();
                        srand($seed);
                        return $a.'-'.$b.'-'.$c.'-'.$d.'-'.$e;
                }
 
-               function domain_generate_uuid_unique() {
-                       $uuid = $this->domain_generate_uuid();
+               function domain_generate_uuid() {
+                       $uuid = $this->generate_uuid();
 
                        while ($this->domain_get_name_by_uuid($uuid))
-                               $uuid = $this->domain_generate_uuid();
+                               $uuid = $this->generate_uuid();
 
                        return $uuid;
                }
 
+               function network_generate_uuid() {
+                       /* TODO: Fix after virNetworkLookupByUUIDString is exposed
+                                to libvirt-php to ensure UUID uniqueness */
+                       return $this->generate_uuid();
+               }
+
                function domain_shutdown($domain) {
                        $dom = $this->get_domain_object($domain);
                        if (!$dom)
index 63cc459..8da825d 100644 (file)
--- a/error.php
+++ b/error.php
@@ -1,10 +1,10 @@
   <!-- CONTENTS -->
   <div id="content">
 
-    <div class="section">Error</div>
+    <div class="section"><?= $lang->get('error_page_title') ?></div>
     <div class="item">
-      <div class="label">Page not found:</div>
-      <div class="value">The page you were looking for was not found. Please report to the administrator and try again later.</div>
+      <div class="label"><?= $lang->get('error_page_label') ?></div>
+      <div class="value"><?= $lang->get('error_page_text') ?></div>
       <div class="nl" />
     </div>
 
index 6363cd2..595be3f 100644 (file)
@@ -15,6 +15,9 @@
                                        'password' => 'Heslo',
                                        'Yes' => 'Ano',
                                        'No' => 'Ne',
+                                       'error_page_title' => 'Chyba',
+                                       'error_page_label' => 'Stránka nenalezena:',
+                                       'error_page_text' => 'Stránka, kterou hledáte, nebyla nalezena. Prosím reportujte tuto chybu správci a zkuste znovu později.',
                                        'host_details' => 'Detaily hostitele',
                                        'model' => 'Model',
                                        'pcpus' => 'Procesory/jádra',
                                        'conn_saved' => 'Připojení bylo uloženo',
                                        'conn_failed' => 'Připojení selhalo',
                                        'domain_list' => 'Seznam domén',
+                                       'network_list' => 'Seznam sítí',
                                        'dom_screenshot' => 'Snímek obrazovky',
                                        'settings' => 'Nastavení',
                                        'interval_sec' => 'Interval (sekund)',
                                        'new-vm-existing' => 'Použít existující disk',
                                        'new-vm-create' => 'Vytvořit nový disk',
                                        'vm-disk-size' => 'Nová velikost disku',
+                                       'net_ip' => 'IP adresa',
+                                       'net_mask' => 'Maska podsítě',
+                                       'net_range' => 'Rozsah IP adres',
+                                       'net_forward' => 'Směrování',
+                                       'net_dev' => 'Zařízení pro směrování',
+                                       'net_dhcp_range' => 'Rozsah DHCP',
+                                       'net_active' => 'Aktivní',
+                                       'create-new-network' => 'Vytvořit novou síť',
+                                       'net_start' => 'Povolit síť',
+                                       'net_dumpxml' => 'Zobrazit XML konfiguraci',
+                                       'net_editxml' => 'Editovat XML konfiguraci',
+                                       'net_undefine' => 'Smazat síť',
+                                       'net_stop' => 'Zakázat síť',
+                                       'net_xmldesc' => 'XML konfigurace sítě',
+                                       'net_editxml' => 'Upravit XML konfiguraci sítě',
+                                       'net_define_changed' => 'Konfigurace sítě byla změněna',
+                                       'net_define_change_err' => 'Nastala chyba při změně konfigurace sítě',
+                                       'net_start_ok' => 'Síť byla úspěšně povolena (zapnuta)',
+                                       'net_start_err' => 'Nastala chyba při startování sítě',
+                                       'net_stop_ok' => 'Síť byla úspěšně zakázána (vypnuta)',
+                                       'net_stop_err' => 'Nastala chyba při zakazování sítě',
+                                       'net_undefine_question' => 'Skutečně si přejete danou síť smazat?',
+                                       'net_undefine_ok' => 'Síť byla úspěšně smazána',
+                                       'net_undefine_err' => 'Nastala chyba při mazání sítě',
+                                       'net_ip_range_def' => 'Definice rozsahu',
+                                       'net_ip_cidr' => 'CIDR (192.168.111.0/24)',
+                                       'net_ip_direct' => 'Přímá definice (2 hodnoty)',
+                                       'net_ipdef_cidr' => 'CIDR Definice',
+                                       'dhcp' => 'DHCP',
+                                       'net_dhcp_start' => 'Počátek DHCP rozsahu',
+                                       'net_dhcp_end' => 'Konec DHCP rozsahu',
+                                       'net_forward_none' => 'žádné',
+                                       'net_forward_nat' => 'NAT',
+                                       'net_forward_route' => 'Route',
+                                       'net_created' => 'Síť byla vytvořena úspěšně',
                                        );
 ?>
index fad8ac3..d92802e 100644 (file)
@@ -14,6 +14,9 @@
                                        'password' => 'Password',
                                        'Yes' => 'Yes',
                                        'No' => 'No',
+                                       'error_page_title' => 'Error',
+                                       'error_page_label' => 'Page not found:',
+                                       'error_page_text' => 'The page you were looking for was not found. Please report to the administrator and try again later.',
                                        'host_details' => 'Host details',
                                        'model' => 'Model',
                                        'pcpus' => 'CPUs/cores',
                                        'conn_failed' => 'Connection has failed',
                                        'domain_list' => 'Domain list',
                                        'dom_screenshot' => 'Screenshot',
+                                       'network_list' => 'Network list',
                                        'dom_none' => 'No valid domain defined',
                                        'main_menu' => 'Main menu',
                                        'cannot_connect' => 'Cannot connect to hypervisor. Please change connection information.',
                                        'new-vm-existing' => 'Use existing disk image',
                                        'new-vm-create' => 'Create new disk image',
                                        'vm-disk-size' => 'New disk size',
+                                       'net_ip' => 'IP Address',
+                                       'net_mask' => 'Subnet mask',
+                                       'net_range' => 'IP Range',
+                                       'net_forward' => 'Forwarding',
+                                       'net_dev' => 'Forwarding to device',
+                                       'net_dhcp_range' => 'DHCP Range',
+                                       'net_active' => 'Active',
+                                       'create-new-network' => 'Create a new network',
+                                       'net_start' => 'Start network',
+                                       'net_dumpxml' => 'Dump network XML',
+                                       'net_editxml' => 'Edit network XML',
+                                       'net_undefine' => 'Undefine network',
+                                       'net_stop' => 'Stop network',
+                                       'net_xmldesc' => 'Network XML description',
+                                       'net_editxml' => 'Edit network XML description',
+                                       'net_define_changed' => 'Network definition changed',
+                                       'net_define_change_err' => 'Error occurred while changing network definition',
+                                       'net_start_ok' => 'Network has been started successfully',
+                                       'net_start_err' => 'An error occurred while starting the network',
+                                       'net_stop_ok' => 'Network has been stopped successfully',
+                                       'net_stop_err' => 'An error occurred while stopping the network',
+                                       'net_undefine_question' => 'Do you really want to undefine this network?',
+                                       'net_undefine_ok' => 'Network has been successfully undefined',
+                                       'net_undefine_err' => 'An error occurred while undefining the network',
+                                       'net_ip_range_def' => 'Range definition',
+                                       'net_ip_cidr' => 'CIDR (192.168.111.0/24)',
+                                       'net_ip_direct' => 'Direct (2 values)',
+                                       'net_ipdef_cidr' => 'CIDR Definition',
+                                       'dhcp' => 'DHCP',
+                                       'net_dhcp_start' => 'DHCP Range start',
+                                       'net_dhcp_end' => 'DHCP Range end',
+                                       'net_forward_none' => 'none',
+                                       'net_forward_nat' => 'NAT',
+                                       'net_forward_route' => 'Route',
+                                       'net_created' => 'Network has been created successfully',
                                        );
 ?>
index 7446083..61a681f 100644 (file)
@@ -2,6 +2,7 @@
   <div id="main-menu">
     <a href="?"><?= $lang->get('main_menu') ?></a>
     | <a href="?page=domain-list"><?= $lang->get('domain_list') ?></a>
+    | <a href="?page=network-list"><?= $lang->get('network_list') ?></a>
     | <a href="?page=info"><?= $lang->get('info') ?></a>
     | <a href="?page=settings"><?= $lang->get('settings') ?></a>
   </div>
diff --git a/pages/network-list.php b/pages/network-list.php
new file mode 100644 (file)
index 0000000..fd072ba
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+  $action = array_key_exists('action', $_GET) ? $_GET['action'] : false;
+
+  $frm = '';
+  $msg = '';
+
+  if ($action == 'net-start') {
+    $name = $_GET['net'];
+
+    $msg = $lv->set_network_active($name, true) ? $lang->get('net_start_ok') :
+          $lang->get('net_start_err').': '.$lv->get_last_error();
+  }
+
+  if ($action == 'net-stop') {
+    $name = $_GET['net'];
+
+    $msg = $lv->set_network_active($name, false) ? $lang->get('net_stop_ok') :
+           $lang->get('net_stop_err').': '.$lv->get_last_error();
+  }
+
+  if ($action == 'net-undefine') {
+    $name = $_GET['net'];
+    if ((!array_key_exists('confirmed', $_GET)) || ($_GET['confirmed'] != 1)) {
+        $frm = '<div class="section">'.$lang->get('net_undefine').'</div>
+                <table id="form-table">
+                <tr>
+                  <td colspan="3">'.$lang->get('net_undefine_question').' '.$lang->get('name').': <u>'.$name.'</u></td>
+                </tr>
+                <tr align="center">
+                  <td><a href="'.$_SERVER['REQUEST_URI'].'&amp;confirmed=1">'.$lang->get('Yes').'</a></td>
+                  <td><a href="?page='.$page.'">'.$lang->get('No').'</a></td>
+                </td>
+                </table>';
+    }
+    else {
+        $msg = $lv->network_undefine($name) ? $lang->get('net_undefine_ok') :
+               $lang->get('net_undefine_err').': '.$lv->get_last_error();
+    }
+  }
+
+  if ($action == 'net-dumpxml') {
+    $name = $_GET['net'];
+
+    $xml = $lv->network_get_xml($name);
+    $frm = '<div class="section">'.$lang->get('net_xmldesc').' - <i>'.$name.'</i></div><form method="POST">
+            <table id="form-table"><tr><td>'.$lang->get('net_xmldesc').': </td>
+            <td><textarea readonly="readonly" name="xmldesc" rows="25" cols="90%">'.$xml.'</textarea></td></tr><tr align="center"><td colspan="2">
+            </tr></form></table>';
+  }
+
+  if ($action == 'net-editxml') {
+    $name = $_GET['net'];
+
+    if (array_key_exists('xmldesc', $_POST)) {
+        $msg = $lv->network_change_xml($name, $_POST['xmldesc']) ? $lang->get('net_define_changed') :
+               $lang->get('net_define_change_err').': '.$lv->get_last_error();
+
+    }
+    else {
+        $xml = $lv->network_get_xml($name);
+        $frm = '<div class="section">'.$lang->get('net_editxml').' - <i>'.$name.'</i></div><form method="POST"><table id="form-table"><tr><td>'.$lang->get('net_xmldesc').': </td>
+             <td><textarea name="xmldesc" rows="25" cols="90%">'.$xml.'</textarea></td></tr><tr align="center"><td colspan="2">
+             <input type="submit" value=" '.$lang->get('net_editxml').' "></tr></form></table>';
+    }
+  }
+?>
+<div id="content">
+
+<?php
+    if ($msg):
+?>
+    <div id="msg"><b><?= $lang->get('msg') ?>: </b><?= $msg ?></div>
+<?php
+    endif;
+?>
+
+<?php
+    if ($frm)
+       echo $frm;
+?>
+
+<div class="section"><?= $lang->get('network_list') ?></div>
+
+<table id="domain-list">
+  <tr>
+    <td colspan="2" align="left">
+      <a href="?page=new-net"><?= $lang->get('create-new-network') ?></a>
+    </td>
+  </tr>
+  <tr>
+    <th><?= $lang->get('name') ?></th>
+    <th><?= $lang->get('net_ip') ?></th>
+    <th><?= $lang->get('net_mask') ?></th>
+    <th><?= $lang->get('net_range') ?></th>
+    <th><?= $lang->get('net_forward') ?></th>
+    <th><?= $lang->get('net_dev') ?></th>
+    <th><?= $lang->get('net_dhcp_range') ?></th>
+    <th><?= $lang->get('net_active') ?></th>
+    <th><?= $lang->get('actions') ?></th>
+  </tr>
+<?php
+               $nets = $lv->get_networks();
+               $num = 0;
+               if ($nets) {
+                       sort($nets);
+                       for ($i = 0; $i < sizeof($nets); $i++) {
+                               $name = $nets[$i];
+                               $netinfo = $lv->get_network_information($name);
+                               $ip = $netinfo['ip'];
+                               $mask = $netinfo['netmask'];
+                               $range = $netinfo['ip_range'];
+                               $forward = $netinfo['forwarding'];
+                               $dev = $netinfo['forward_dev'];
+                               $dhcpinfo = (array_key_exists('dhcp_start', $netinfo)) ? $netinfo['dhcp_start'].' - '.$netinfo['dhcp_end'] : '-';
+                               $active = $netinfo['active'];
+                               $active_str = $lang->get( $active ? 'Yes' : 'No' );
+
+                               $actions = '';
+                               if (!$active) {
+                                       $actions .= '<a href="?page='.$page.'&amp;action=net-start&amp;net='.$name.'">'.$lang->get('net_start').'</a> | ';
+                                       $actions .= '<a href="?page='.$page.'&amp;action=net-dumpxml&amp;net='.$name.'">'.$lang->get('net_dumpxml').'</a> | ';
+                                       $actions .= '<a href="?page='.$page.'&amp;action=net-editxml&amp;net='.$name.'">'.$lang->get('net_editxml').'</a> | ';
+                                       $actions .= '<a href="?page='.$page.'&amp;action=net-undefine&amp;net='.$name.'">'.$lang->get('net_undefine').'</a> | ';
+
+                                       $actions[ strlen($actions) - 2 ] = ' ';
+                                       $actions = Trim($actions);
+                               }
+                               else {
+                                       $actions  = '<a href="?page='.$page.'&amp;action=net-stop&amp;net='.$name.'">'.$lang->get('net_stop').'</a> | ';
+                                       $actions .= '<a href="?page='.$page.'&amp;action=net-dumpxml&amp;net='.$name.'">'.$lang->get('net_dumpxml').'</a> | ';
+
+                                       $actions[ strlen($actions) - 2 ] = ' ';
+                                       $actions = Trim($actions);
+                               }
+
+                               echo "<tr>
+                                       <td class=\"name\">
+                                           $name
+                                       </td>
+                                               <td>$ip</td>
+                                        <td>$mask</td>
+                                        <td>$range</td>
+                                        <td>$forward</td>
+                                        <td>$dev</td>
+                                        <td>$dhcpinfo</td>
+                                        <td align=\"center\">$active_str</td>
+                                        <td>
+                                           $actions
+                                        </td>
+                                  </tr>";
+                               $num++;
+                       }
+               }
+
+               if ($num == 0)
+                       echo "<tr><td colspan=\"9\">".$lang->get('dom_none')."</td></tr>";
+       ?>
+</table>
+
+</div>
diff --git a/pages/new-net.php b/pages/new-net.php
new file mode 100644 (file)
index 0000000..dec1aeb
--- /dev/null
@@ -0,0 +1,159 @@
+<?php
+  $skip = false;
+  $msg = false;
+
+  if (array_key_exists('sent', $_POST)) {
+       if ($_POST['ip_range_cidr'])
+               $ipinfo = $_POST['net_cidr'];
+       else
+               $ipinfo = array('ip' => $_POST['net_ip'], 'netmask' => $_POST['net_mask']);
+
+       $dhcpinfo = ($_POST['setup_dhcp']) ? $_POST['net_dhcp_start'].'-'.$_POST['net_dhcp_end'] : false;
+
+       $tmp = $lv->network_new($_POST['name'], $ipinfo, $dhcpinfo, $_POST['forward'], $_POST['net_forward_dev']);
+       if (!$tmp)
+               $msg = $lv->get_last_error();
+       else {
+               $skip = true;
+               $msg = $lang->get('net_created');
+       }
+  }
+?>
+
+<?php
+    if ($msg):
+?>
+    <div id="msg"><b><?= $lang->get('msg') ?>: </b><?= $msg ?></div>
+<?php
+    endif;
+?>
+
+<?php
+    if (!$skip):
+?>
+<script>
+<!--
+       function change_divs(what, val) {
+               if (val == 1)
+                       style = 'table-row';
+               else
+                       style = 'none';
+
+               for (i = 1; i < 10; i++) {
+                       name = 'setup_'+what+i;
+                       d = document.getElementById(name);
+                       if (d == null)
+                               break;
+                       d.style.display = style;
+               }
+       }
+
+       function net_ip_change(val) {
+               if (val == 1) {
+                       document.getElementById('net_ip_cidr').style.display = 'table-row';
+                       document.getElementById('net_ip_direct1').style.display = 'none';
+                       document.getElementById('net_ip_direct2').style.display = 'none';
+               } else {
+                       document.getElementById('net_ip_cidr').style.display = 'none';
+                       document.getElementById('net_ip_direct1').style.display = 'table-row';
+                       document.getElementById('net_ip_direct2').style.display = 'table-row';
+               }
+       }
+-->
+</script>
+
+<div id="content">
+
+<div class="section"><?= $lang->get('create-new-network') ?></div>
+
+<form method="POST">
+
+<table id="form-table">
+<tr>
+    <td align="right"><?= $lang->get('name') ?>: </td>
+    <td><input type="text" name="name" /></td>
+</tr>
+
+<tr>
+    <td align="right"><?= $lang->get('net_ip_range_def') ?>:</td>
+    <td>
+      <select name="ip_range_cidr" onchange="net_ip_change(this.value)">
+       <option value="1"><?= $lang->get('net_ip_cidr') ?></option>
+       <option value="0"><?= $lang->get('net_ip_direct') ?></option>
+      </select>
+    </td>
+</tr>
+
+<tr id="net_ip_cidr">
+    <td align="right"><?= $lang->get('net_ipdef_cidr') ?>:</td>
+    <td><input type="text" name="net_cidr" /></td>
+</tr>
+
+<tr id="net_ip_direct1" style="display: none">
+    <td align="right"><?= $lang->get('net_ip') ?>:</td>
+    <td><input type="text" name="net_ip" /></td>
+</tr>
+
+<tr id="net_ip_direct2" style="display: none">
+    <td align="right"><?= $lang->get('net_mask') ?>:</td>
+    <td><input type="text" name="net_mask" /></td>
+</tr>
+
+<tr>
+    <td align="right"><?= $lang->get('setup').' '.$lang->get('dhcp') ?>:</td>
+    <td>
+      <select name="setup_dhcp" onchange="change_divs('dhcp', this.value)">
+        <option value="0"><?= $lang->get('No') ?></option>
+        <option value="1"><?= $lang->get('Yes') ?></option>
+      </select>
+    </td>
+</tr>
+
+<tr id="setup_dhcp1" style="display: none">
+    <td align="right"><?= $lang->get('net_dhcp_start') ?>:</td>
+    <td>
+      <input type="text" name="net_dhcp_start" />
+    </td>
+</tr>
+
+<tr id="setup_dhcp2" style="display: none">
+    <td align="right"><?= $lang->get('net_dhcp_end') ?>:</td>
+    <td>
+      <input type="text" name="net_dhcp_end" />
+    </td>
+</tr>
+
+<tr>
+    <td align="right"><?= $lang->get('net_forward') ?>:</td>
+    <td>
+      <select name="forward">
+        <option value="none"><?= $lang->get('net_forward_none') ?></option>
+        <option value="nat"><?= $lang->get('net_forward_nat') ?></option>
+       <option value="route"><?= $lang->get('net_forward_route') ?></option>
+      </select>
+    </td>
+</tr>
+
+<tr>
+    <td align="right"><?= $lang->get('net_dev') ?>:</td>
+    <td>
+      <input type="text" name="net_forward_dev" />
+    </td>
+</tr>
+
+</div>
+
+<tr align="center">
+    <td colspan="2">
+    <input type="submit" value=" <?= $lang->get('create-vm') ?> " />
+    </td>
+</tr>
+
+<input type="hidden" name="sent" value="1" />
+</form>
+
+<?php
+  endif;
+?>
+
+</div>