Changeset 185
- Timestamp:
- 07/30/08 15:53:46 (4 months ago)
- Files:
-
- nethorus/app/controllers/ipvpn_admin_controller.rb (moved) (moved from nethorus/app/controllers/ipvpns_controller.rb) (1 diff, 1 prop)
- nethorus/app/views/device_admin/edit.html.erb (modified) (1 diff)
- nethorus/app/views/device_admin/index.html.erb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nethorus/app/controllers/ipvpn_admin_controller.rb
- Property svn:mergeinfo set
r163 r185 22 22 =begin rdoc 23 23 24 Controller for IPVPNs.24 IPVPN Administration Controller. 25 25 26 26 =end 27 27 28 class IpvpnsController < ApplicationController 28 class IpvpnAdminController < ApplicationController 29 30 31 # Return a list of all IP VPNs. 32 33 def index 34 35 @subtitle = "IP VPN Administration" 36 37 @all_ipvpns = Ipvpn.all 38 39 end 40 41 42 # Create a new IP VPN 43 44 def new 45 46 @subtitle = "IP VPN Administration: New IP VPN" 47 48 49 # If we've been given data, create a new IP VPN object with this data. 50 # Otherwise, just create a new IP VPN object. 51 52 if params[:ipvpn] 53 @ipvpn = Ipvpn.new(params[:ipvpn]) 54 else 55 @ipvpn = Ipvpn.new 56 end 57 58 if @ipvpn.valid? && params[:ipvpn] 59 60 # Save the record and redirect to the calling page 61 62 logger.info "New IP VPN valid - saving" 63 64 if @ipvpn.save 65 66 flash[:info] = "Created a new IP VPN record for <strong>#{@ipvpn.ipvpn_name}</strong>" 67 redirect_to :action => 'index' 68 69 else 70 71 # Trap the case where the IP VPN did not save properly 72 73 flash[:info] = "There was a problem saving the new IP VPN <strong>#{@ipvpn.ipvpn_name}</strong>" 74 render :action => 'edit' 75 76 end 77 78 else 79 80 render :action => 'edit' 81 82 end 83 84 end 85 86 87 # Edit a specific IP VPN. 88 89 def edit 90 91 @subtitle = "IP VPN Administration: Edit IP VPN" 92 93 94 # Load the object we're editing 95 96 @ipvpn = Ipvpn.find(params[:ipvpn_id]) 97 98 99 # Process the data within the form if it has been submitted 100 101 if params[:ipvpn] 102 103 104 # Compare the submitted data to the recorded data and log any changes 105 106 params[:ipvpn].each do |param| 107 108 if @ipvpn.send(param[0]) != param[1] 109 110 @ipvpn.send("#{param[0]}=", "#{param[1]}") 111 logger.debug "Column #{param[0]} changed from value='#{@ipvpn.send(param[0])}' to value='#{param[1]}'" 112 113 else 114 115 logger.debug "Column #{param[0]} unchanged from value='#{@ipvpn.send(param[0])}'" 116 117 end 118 119 end 120 121 122 # Always check if the ipvpn is valid, in case we have a now-invalid 123 # record in the database. 124 125 if @ipvpn.valid? 126 127 if @ipvpn.changed? 128 129 # If the object has changed, save it and respond with a suitable flash message. 130 131 logger.debug "IP VPN id=#{@ipvpn.id} changed - saving record" 132 @ipvpn.save 133 flash[:info] = "Updated <strong>#{@ipvpn.ipvpn_name}</strong>" 134 135 else 136 137 # If the object hasn't changed, log it for debugging purposes but 138 # don't show any feedback. 139 140 logger.debug "IP VPN id=#{@ipvpn.id} not changed" 141 142 end 143 144 145 # Since the object is valid, we can return to the index. 146 147 redirect_to :action => 'index' 148 149 else 150 151 # The object isn't valid - log it, and go back to the edit page 152 # which will then show the errors 153 154 logger.debug "IP VPN id=#{@ipvpn.id} is invalid" 155 156 end 157 158 end 159 160 end 161 162 163 # Delete a record after first after confirming that this is really the 164 # intended action. 165 166 def delete 167 168 begin 169 @ipvpn = Ipvpn.find(params[:ipvpn_id]) 170 rescue 171 flash[:notice] = "Cannot find IP VPN <strong>#{params[:ipvpn_id]}</strong> - you may not have access to delete this ipvpn, or it may not exist." 172 end 173 174 if @ipvpn 175 @ipvpn.destroy 176 flash[:notice] = "Deleted ipvpn <strong>#{@ipvpn.ipvpn_name}</strong>" 177 end 178 179 redirect_to :action => 'index' 180 181 end 29 182 30 183 end nethorus/app/views/device_admin/edit.html.erb
r170 r185 1 1 <h1> 2 <% if @ device.id.nil? %>3 New Device2 <% if @ipvpn.id.nil? %> 3 New IP VPN 4 4 <% else %> 5 Editing <%=h @ device.hostname.blank? ? "an unnamed device" : @device.hostname %><% if !@device.ipv4_address.blank? %> (<%=h @device.ipv4_address%>)<% end %>5 Editing <%=h @ipvpn.ipvpn_name.blank? ? "a new IP VPN" : @ipvpn.ipvpn_name %><% if !@ipvpn.ipvpn_rd.blank? %> (RD <%=h @ipvpn.ipvpn_rd %>)<% end %> 6 6 <% end %> 7 7 </h1> 8 8 9 <% form_for : device, @device, :url => { :action => @device.id ? 'edit' : 'new' , :device_id => @device.id } do |form| %>9 <% form_for :ipvpn, @ipvpn, :url => { :action => @ipvpn.id ? 'edit' : 'new' , :ipvpn_id => @ipvpn.id } do |form| %> 10 10 11 <% if @ device.id %><%= form.hidden_field :id %><% end %>11 <% if @ipvpn.id %><%= form.hidden_field :id %><% end %> 12 12 13 <% if params[: device] && !@device.valid? %>14 <%= form.error_messages :header_message => "", :message => "This devicecouldn't be saved for the following reasons:" %>13 <% if params[:ipvpn] && !@ipvpn.valid? %> 14 <%= form.error_messages :header_message => "", :message => "This ipvpn couldn't be saved for the following reasons:" %> 15 15 <% end %> 16 16 17 18 17 <fieldset> 19 <legend>Essentials</legend> 20 <label for="hostname" accesskey="h">Hostname</label><%= form.text_field :hostname %><br /> 21 <label for="description" accesskey="d">Description</label><%= form.text_field :description %><br /> 22 <label for="site" accesskey="s">Site</label><%= collection_select(:device, :site_id, Site.find(:all), :id, :description) %><br /> 18 <legend>VPN Details</legend> 19 <label for="ipvpn_rd" accesskey="h">Route Distinguisher</label><%= form.text_field :ipvpn_rd %><br /> 20 <label for="ipvpn_name" accesskey="d">Name</label><%= form.text_field :ipvpn_name %><br /> 23 21 </fieldset> 24 22 25 <fieldset> 26 <legend>Management</legend> 27 <label for="ipv4_address" accesskey="a">IP Address</label><%= form.text_field :ipv4_address %><br /> 28 <%= form.radio_button("snmp_version", "1", { :onchange => "Element.show('snmpv1_data'); Element.hide('snmpv2_data'); Element.hide('snmpv3_data');" } ) %>SNMPv1<br /> 29 <%= form.radio_button("snmp_version", "2", { :onchange => "Element.hide('snmpv1_data'); Element.show('snmpv2_data'); Element.hide('snmpv3_data');" } ) %>SNMPv2<br /> 30 <%= form.radio_button("snmp_version", "3", { :onchange => "Element.hide('snmpv1_data'); Element.hide('snmpv2_data'); Element.show('snmpv3_data');" } ) %>SNMPv3<br /> 31 </fieldset> 23 <%= submit_tag @ipvpn.id ? 'Save' : 'Create' %> 32 24 33 <fieldset id="snmpv1_data"> 34 <legend>SNMPv1 Settings</legend> 35 <p><strong>Select SNMPv1 only when you are certain this device does not support SNMPv2. Although SNMPv1 is backward compatible, it will not use GETBULK, which may delay gathering data.</strong></p> 36 <label for="snmp_community" accesskey="c">Community string</label><%= form.text_field :snmp_community %><br /> 37 </fieldset> 38 39 <fieldset id="snmpv2_data"> 40 <legend>SNMPv2 Settings</legend> 41 <label for="snmp_community" accesskey="c">Community string</label><%= form.text_field :snmp_community %><br /> 42 </fieldset> 43 44 <fieldset id="snmpv3_data"> 45 <legend>SNMPv3 Settings</legend> 46 <label for="snmpv3_security_level">Security Level</label><%= select('snmpv3_security_level', '', [ ['None', 'noAuthNoPriv'], ['Authentication', 'authNoPriv'], ['Privacy', 'authPriv'] ]) %><br /> 47 <label for="snmpv3_auth_protocol">Authentication</label><%= select('snmpv3_auth_protocol', '', [ ['SHA', 'sha'], ['MD5', 'md5'] ]) %><%= form.text_field :snmpv3_auth_passphrase %><br /> 48 <label for="snmpv3_priv_protocol">Privacy</label><%= select('snmpv3_priv_protocol', '', [ ['AES', 'aes'], ['DES', 'des'] ]) %><%= form.text_field :snmpv3_priv_passphrase %><br /> 49 <label for="snmpv3_security_name">Security Name</label><%= form.text_field :snmpv3_security_name %><br /> 50 </fieldset> 51 52 <% if @device.snmp_version == 1 %> 53 <%= javascript_tag "Element.hide('snmpv2_data'); Element.hide('snmpv3_data');" %> 54 <% elsif @device.snmp_version == 3 %> 55 <%= javascript_tag "Element.hide('snmpv1_data'); Element.hide('snmpv2_data');" %> 56 <% else %> 57 <%= javascript_tag "Element.hide('snmpv1_data'); Element.hide('snmpv3_data');" %> 58 <% end %> 59 60 <%= submit_tag @device.id ? 'Save' : 'Create' %> 61 62 <% if @device.id %> 63 <%= link_to 'Delete', :action => 'delete', :device_id => @device.id %> 25 <% if @ipvpn.id %> 26 <%= button_to 'Delete', :action => 'delete', :ipvpn_id => @ipvpn.id %> 64 27 <% end %> 65 28 nethorus/app/views/device_admin/index.html.erb
r168 r185 1 <h1> Devices</h1>1 <h1>IP VPNs</h1> 2 2 3 <p><%= link_to "New device", { :controller => 'device_admin', :action => 'new' } %></p>3 <p><%= link_to "New IP VPN", { :controller => 'ipvpn_admin', :action => 'new' } %></p> 4 4 5 5 <table class="vert"> 6 6 <tr> 7 <th> Hostname</th>8 <th> Site</th>7 <th>Route Distinguisher</th> 8 <th>Description</th> 9 9 </tr> 10 <% @all_ devices.each do |device| %>10 <% @all_ipvpns.each do |ipvpn| %> 11 11 <tr> 12 <td><%= link_to device.hostname, { :controller => 'device_admin', :action => 'edit', :device_id => device.id } %><br /><small><%=h device.description %></small></td>13 <td><%= device.site.nil? ? "" : device.site.description%></td>12 <td><%= link_to ipvpn.ipvpn_rd, { :controller => 'ipvpn_admin', :action => 'edit', :ipvpn_id => ipvpn.id } %></td> 13 <td><%= ipvpn.ipvpn_name %></td> 14 14 </tr> 15 15 <% end %>
