From 882f60e952c36b4ee5ef452df5cb4bae074a1198 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> Date: Mon, 30 Aug 2010 10:01:17 +0000 Subject: [PATCH] newly created node can be declared 'reservable' + various cosmetic --- Makefile | 48 +++++++++++++++++++++++ application/controllers/register.php | 18 ++++++--- application/views/header.php | 4 +- application/views/stage3_node_choose.php | 40 ++++++++++++++----- application/views/stage4_node_confirm.php | 42 ++++++++++++++------ wizard.css | 3 ++ 6 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 Makefile create mode 100644 wizard.css diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a94e47a --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +# refresh tags +tags: + find . '(' -name '*.php' -o -name '*.js' -o -name '*.css' -o -name Makefile ')' | xargs etags + +.PHONY: tags + +########## sync +# 2 forms are supported +# (*) if your plc root context has direct ssh access: +# make sync PLC=boot.planet-lab.eu +# (*) otherwise, entering through the root context +# make sync PLCHOST=testplc.onelab.eu GUEST=vplc03.inria.fr + +PLCHOST ?= testplc.onelab.eu + +ifdef GUEST +SSHURL:=root@$(PLCHOST):/vservers/$(GUEST) +SSHCOMMAND:=ssh root@$(PLCHOST) vserver $(GUEST) +endif +ifdef PLC +SSHURL:=root@$(PLC):/ +SSHCOMMAND:=ssh root@$(PLC) +endif + +LOCAL_RSYNC_EXCLUDES := --exclude '*.pyc' +RSYNC_EXCLUDES := --exclude .svn --exclude .git --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES) +RSYNC_COND_DRY_RUN := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,) +RSYNC := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES) + +sync: +ifeq (,$(SSHURL)) + @echo "sync: You must define, either PLC, or PLCHOST & GUEST, on the command line" + @echo " e.g. make sync PLC=boot.planet-lab.eu" + @echo " or make sync PLCHOST=testplc.onelab.eu GUEST=vplc03.inria.fr" + @exit 1 +else + +$(RSYNC) ./ $(SSHURL)/var/www/html/registerwizard/ +endif + +#################### convenience, for debugging only +# make +foo : prints the value of $(foo) +# make ++foo : idem but verbose, i.e. foo=$(foo) +++%: varname=$(subst +,,$@) +++%: + @echo "$(varname)=$($(varname))" ++%: varname=$(subst +,,$@) ++%: + @echo "$($(varname))" diff --git a/application/controllers/register.php b/application/controllers/register.php index f3b4075..4e15529 100644 --- a/application/controllers/register.php +++ b/application/controllers/register.php @@ -245,8 +245,9 @@ class Register extends Controller { if ( isset($_REQUEST['pcu_proceed']) ) { $rules['hostname'] = ""; + $rules['node_type'] = 'regular'; $rules['model'] = ""; - $rules['method'] = ""; + $rules['method'] = "dhcp"; $rules['ip'] = ""; $rules['netmask'] = ""; $rules['network'] = ""; @@ -256,6 +257,7 @@ class Register extends Controller { $rules['dns2'] = ""; $this->validation->set_rules($rules); $fields['hostname'] = "Hostname"; + $fields['node_type'] = "Node Type"; $fields['model'] = "Model"; $fields['method'] = "Method"; $fields['ip'] = "IP Address"; @@ -325,6 +327,7 @@ class Register extends Controller { { global $api, $plc; $hostname = trim($_REQUEST['hostname']); + $node_type = trim($_REQUEST['node_type']); $model= trim($_REQUEST['model']); $method = trim($_REQUEST['method']); $ip = trim($_REQUEST['ip']); @@ -357,7 +360,7 @@ class Register extends Controller { if( !isset($errors) || count($errors) == 0 ) { // add new node and its network - $optional_vals= array( "hostname"=>$hostname, "model"=>$model ); + $optional_vals= array( 'hostname'=>$hostname, 'node_type'=>$node_type, 'model'=>$model ); $site_id= $data['site_id']; // Try to get node in case this is from an error: @@ -533,6 +536,7 @@ class Register extends Controller { $person = new Person($plc->person); $fields['hostname'] = "Hostname"; + $fields['node_type'] = "Node Type"; $fields['model'] = "Model"; $fields['method'] = "Method"; $fields['ip'] = "IP Address"; @@ -552,8 +556,9 @@ class Register extends Controller { if ( isset($_REQUEST['node_choose']) ) { $rules['node_id'] = "required|intval"; $rules['hostname'] = ""; + $rules['node_type'] = "regular"; $rules['model'] = ""; - $rules['method'] = ""; + $rules['method'] = "dhcp"; $rules['ip'] = ""; $rules['netmask'] = ""; $rules['network'] = ""; @@ -618,10 +623,11 @@ class Register extends Controller { # TODO: RECODE To update values instead of adding them... global $api, $plc; $hostname = trim($_REQUEST['hostname']); - $model= trim($_REQUEST['model']); + $model = trim($_REQUEST['model']); + $node_type = trim($_REQUEST['node_type']); $node_id = intval($this->validation->node_id); - $ret = $api->UpdateNode( $node_id, array('hostname' => $hostname, - 'model' => $model)); + $optional_vals = array('hostname' => $hostname, 'model' => $model, 'node_type' => $node_type ); + $ret = $api->UpdateNode( $node_id, $optional_vals); if( $ret <= 0 ) { $data['error'] = $api->error(); print $data['error']; diff --git a/application/views/header.php b/application/views/header.php index 45ead67..13887dd 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -4,9 +4,9 @@ <style type="text/css" media="all">@import "https://www.planet-lab.org/misc/drupal.css";</style> <style type="text/css" media="all">@import "https://www.planet-lab.org/sites/default/themes/chameleon/common.css";</style> <style type="text/css" media="all">@import "https://www.planet-lab.org/sites/default/themes/chameleon/planetlab/style.css";</style> - <link rel="shortcut icon" - href="https://www.planet-lab.org/sites/default/themes/chameleon/planetlab/favicon.ico" type="image/x-icon" /> + <link rel="shortcut icon" href="/misc/favicon.ico" type="image/x-icon" /> <style type="text/css" media="all">@import "/registerwizard/rounded.css";</style> + <style type="text/css" media="all">@import "/registerwizard/wizard.css";</style> <script src="/registerwizard/rounded.js"></script> </head> <body> diff --git a/application/views/stage3_node_choose.php b/application/views/stage3_node_choose.php index ae443f3..abe54c7 100644 --- a/application/views/stage3_node_choose.php +++ b/application/views/stage3_node_choose.php @@ -4,9 +4,18 @@ if( isset($errors) && count($errors) > 0 ) } ?> <script language="javascript"> -function updateStaticFields() -{ - var is_dhcp= document.fm.method[0].checked; +function initNodeTypeFields() { + var regular=document.getElementById("regular_checked"); + var reservable=document.getElementById("reservable_checked"); + if ( regular.checked || reservable.checked) return; + regular.checked=true; +} +function updateMethodFields() { + var dhcp=document.getElementById("dhcp_checked"); + var static=document.getElementById("static_checked"); + // set dhcp as default + if ( ! dhcp.checked && ! static.checked) dhcp.checked=true; + var is_dhcp=dhcp.checked; document.fm.netmask.disabled= is_dhcp; document.fm.network.disabled= is_dhcp; @@ -62,30 +71,42 @@ function updateStaticFields() <tr><th>Site: </th><td><?= $site['name'] ?></td> </tr> <tr> - <th width=200>Hostname:</td> + <th width=200>Hostname</td> <td><input type="text" name="hostname" value="<?= $this->validation->hostname ?>" size="40" maxlength="256"> <?= ( $this->disp_errors ? $this->validation->hostname_error : "") ?> </td> </tr> <tr> - <th>Model:</td> + <th valign='top' width="200">Node Type</th> + <td> + <input type="radio" name="node_type" value="regular" id="regular_checked" + <?= ( $this->validation->node_type == 'regular' ? "checked" : "" ) ?>>regular + <input type="radio" name="node_type" value="reservable" id="reservable_checked" + <?= ( $this->validation->node_type == 'reservable' ? "checked" : "" ) ?>>reservable + </td> + </tr> + <tr> + <th>Model</td> <td> <input type="text" name="model" value="<?= $this->validation->model ?>" size="40" maxlength="256"> <?= ( $this->disp_errors ? $this->validation->model_error : "") ?> </td> </tr> + + + <tr> - <td> <b>Network Settings</b> </td> + <td colspan=2> <h3>Network Settings</h3> </td> </tr> <tr> <th valign='top' width="200">Addressing Method</th> <td> - <input type="radio" name="method" value="dhcp" onChange='updateStaticFields()' + <input type="radio" name="method" value="dhcp" id="dhcp_checked" onChange='updateMethodFields()' <?= ( $this->validation->method == 'dhcp' ? "checked" : "" ) ?>>DHCP - <input type="radio" name="method" value="static" onChange='updateStaticFields()' + <input type="radio" name="method" value="static" id='static_checked' onChange='updateMethodFields()' <?= ( $this->validation->method == 'static' ? "checked" : "" ) ?>>Static </td> </tr> @@ -166,5 +187,6 @@ function updateStaticFields() </form> <script language="javascript"> -updateStaticFields(); +initNodeTypeFields(); +updateMethodFields(); </script> diff --git a/application/views/stage4_node_confirm.php b/application/views/stage4_node_confirm.php index b7fd6a4..35c7dd3 100644 --- a/application/views/stage4_node_confirm.php +++ b/application/views/stage4_node_confirm.php @@ -11,9 +11,18 @@ if( isset($errors) && count($errors) > 0 ) } ?> <script language="javascript"> -function updateStaticFields() -{ - var is_dhcp= document.fm.method[0].checked; +function initNodeTypeFields() { + var regular=document.getElementById("regular_checked"); + var reservable=document.getElementById("reservable_checked"); + if ( regular.checked || reservable.checked) return; + regular.checked=true; +} +function updateMethodFields() { + var dhcp=document.getElementById("dhcp_checked"); + var static=document.getElementById("static_checked"); + // set dhcp as default + if ( ! dhcp.checked && ! static.checked) dhcp.checked=true; + var is_dhcp=dhcp.checked; document.fm.netmask.disabled= is_dhcp; document.fm.network.disabled= is_dhcp; @@ -60,12 +69,21 @@ next stage. Otherwise, please Update the information as appropriate. </tr> <?php } ?> <tr> - </tr> <th width=200>Hostname:</td> <td><input type="text" name="hostname" value="<?= $node->hostname ?>" size="40" maxlength="256"> <?= ( $this->disp_errors ? $this->validation->hostname_error : "") ?> </td> + </tr> + <tr> + <th valign='top' width="200">Node Type</th> + <td> + <input type="radio" name="node_type" value="regular" id="regular_checked" + <?= ( $this->validation->node_type == 'regular' ? "checked" : "" ) ?>>regular + <input type="radio" name="node_type" value="reservable" id="reservable_checked" + <?= ( $this->validation->node_type == 'reservable' ? "checked" : "" ) ?>>reservable + </td> + </tr> <tr> <th>Model:</th> <td> @@ -74,17 +92,18 @@ next stage. Otherwise, please Update the information as appropriate. <?= ( $this->disp_errors ? $this->validation->model_error : "") ?> </td> </tr> + <tr> <th valign='top' width="200">Addressing Method</th> <td> - <input type="radio" name="method" value="dhcp" onChange='updateStaticFields()' - <?= ( $node->method == 'dhcp' ? "checked" : "" ) ?>>DHCP - <input type="radio" name="method" value="static" onChange='updateStaticFields()' - <?= ( $node->method == 'static' ? "checked" : "" ) ?>>Static + <input type="radio" name="method" value="dhcp" id="dhcp_checked" onChange='updateMethodFields()' + <?= ( $this->validation->method == 'dhcp' ? "checked" : "" ) ?>>DHCP + <input type="radio" name="method" value="static" id='static_checked' onChange='updateMethodFields()' + <?= ( $this->validation->method == 'static' ? "checked" : "" ) ?>>Static </td> </tr> - - <tr><th valign='top'>IP Address</th> + <tr> + <th valign='top'>IP Address</th> <td><input type="text" name="ip" value="<?= $node->ip ?>"> <?= ( $this->disp_errors ? $this->validation->ip_error : "") ?> </td> @@ -149,5 +168,6 @@ next stage. Otherwise, please Update the information as appropriate. </form> <script language="javascript"> -updateStaticFields(); +initNodeTypeFields(); +updateMethodFields(); </script> diff --git a/wizard.css b/wizard.css new file mode 100644 index 0000000..dcdd6b9 --- /dev/null +++ b/wizard.css @@ -0,0 +1,3 @@ +tr>td>h3 { + padding: 20; +} -- 2.47.0