#!/tvbin/tivosh ############################################################################## # Network Config 1.0 by l.g. kahn to get around the problem # that dtivo v. 6.2 has no network menus. # # This file will configure the netowrk parameters ie # ip, default gateway etc. in the correct mfs registry locations # as if the menus were executed. # # In this way you can configure your ip information and use MRV # on the boxes. Putting an ifconfig in the normal rc.sysinit.author # is too late in the boot process and thus MRV doesn't work. # # v2.0 Modified by Flash_ to function as a TiVoWebPlus module and # include Wireless parms # v2.1 Modified by SteveT to add missing subobject to mfs if needed # # (C) 2005. No publication or sale without permission. ############################################################################## if {$::version < 4} { continue } proc load_ip_parms { chan } { global dhcp global nettype global hostaddr global netmask global gw global dns global ssid set db [dbopen] set goodfsid "" ForeachMfsFile fsid name type "/State/Network/" "" { RetryTransaction { set nconfig [db $db openidconstruction $fsid] try { set default [dbobj $nconfig get Default] } catch errCode { set default "" } if {$default == "1"} { set goodfsid $fsid } } } if { $goodfsid == "" } { puts $chan "Didn't find network with Default = 1 exiting...

" dbclose $db return 1 } RetryTransaction { set nconfig [db $db openidconstruction $goodfsid] #only create if not already existing try { set ipparms [dbobj $nconfig get IpParams] } catch errCode { set ipparms "" } if { $ipparms != "" } { set nettype [dbobj $nconfig get NetworkMedium] set dhcp [dbobj $ipparms get AutoConfigEnabled] set hostaddr [dbobj $ipparms get HostAddress] set netmask [dbobj $ipparms get SubnetMask] set gw [dbobj $ipparms get GatewayAddress] set dns [dbobj $ipparms get DnsServers] try { set w_fsid [dbobj $nconfig get WirelessParams] } catch errCode { set w_fsid "" } if { $w_fsid != "" } { set deny [dbobj $w_fsid get DenyUnencrypted] #puts $chan "DenyUnencrypted $deny

" set ssid [dbobj $w_fsid get SsId] } } } dbclose $db return 0 } proc set_ip_parms { chan } { global dhcp global nettype global hostaddr global netmask global gw global dns global ssid set db [dbopen] set goodfsid "" ForeachMfsFile fsid name type "/State/Network/" "" { RetryTransaction { set nconfig [db $db openidconstruction $fsid] try { set default [dbobj $nconfig get Default] } catch errCode { set default "" } if {$default == "1"} { set goodfsid $fsid } } } if { $goodfsid == "" } { puts $chan "Didn't find network with Default = 1 exiting...

" dbclose $db return 1 } RetryTransaction { set nconfig [db $db openidconstruction $goodfsid] # Find the IP parms fsid set ipparms [dbobj $nconfig get IpParams] # not found, create the subobject and store value of subobject if { $ipparms == "" } { set ipparms [db $db createsub NetConfigIpParams $nconfig] dbobj $nconfig set IpParams $ipparms } # Find the Wireless fsid try { set wparms [dbobj $nconfig get WirelessParams] } catch errCode { if {$nettype == 5} { set wparms [db $db createsub NetConfigWirelessParams $nconfig] dbobj $nconfig set WirelessParams $wparms } else { set wparms "" } } # Set the IP parms if { $ipparms != "" } { dbobj $nconfig set NetworkMedium $nettype dbobj $ipparms set AutoConfigEnabled $dhcp if {$hostaddr != ""} { dbobj $ipparms set HostAddress $hostaddr } if {$netmask != ""} { dbobj $ipparms set SubnetMask $netmask } if {$gw != ""} { dbobj $ipparms set GatewayAddress $gw } if {$dns != ""} { dbobj $ipparms set DnsServers $dns } } #Wireless Parameters if { $wparms != "" } { dbobj $wparms set DenyUnencrypted 1 #puts $chan "DenyUnencrypted $deny

" if {$ssid != ""} { dbobj $wparms set SsId $ssid } } } dbclose $db return 0 } proc config_table {chan mode} { global nettype global dhcp global hostaddr global netmask global gw global dns global ssid set checked "" if {$dhcp == "1"} {set checked "1"} puts $chan [html_form_start "GET" "/netconfig"] puts $chan [html_table_start "" "Network Parameters" "COLSPAN=2"] puts $chan [tr "" [td "DHCP"] [td [html_form_checkbox "ndhcp" $checked]]] puts $chan [tr "" [td "IP Address"] [td [html_form_text 1 16 "nhostaddr" $hostaddr]]] puts $chan [tr "" [td "Netmask"] [td [html_form_text 1 16 "nnetmask" $netmask]]] puts $chan [tr "" [td "Default Gateway"] [td [html_form_text 1 16 "ngw" $gw]]] puts $chan [tr "" [td "DNS Server"] [td [html_form_text 1 16 "ndns" $dns]]] puts $chan [tr "" [td "Network Type"] [td [html_form_select "nnettype" "4 5" "Wired Wireless" $nettype]]] puts $chan [tr "" [td "Wireless SSID"] [td [html_form_text 1 35 "nssid" $ssid]]] puts $chan [tr "" [td "WEP Key"] [td "Not Supported Yet :("]] set htmlline "" set htmlline "

" if {$mode == 0 } { append htmlline [html_form_input "submit" "submit" "Submit"] } elseif {$mode == 1} { append htmlline [html_form_input "submit" "submit" "Reboot Now!"] } append htmlline "
" puts $chan [tr "" [td "COLSPAN=2" $htmlline]] puts $chan [html_form_end] } proc action_netconfig {chan path env} { set name "" eval $env set version "2.1" global nettype global dhcp global hostaddr global netmask global gw global dns global ssid set dhcp "" set hostaddr "" set netmask "" set gw "" set dns "" set nettype 4 set ssid "" puts $chan [html_start] puts $chan "
" puts $chan "

Net Config

" puts $chan "

Network config by L.G. Kahn

" puts $chan "

TiVoWebPlus module and Wireless support by Flash_

" puts $chan [html_link "/mfs/State/Network" "Show MFS /State/Network data"] if {$env == ""} { set rc [load_ip_parms $chan] config_table $chan 0 } elseif {$submit=="view"} { set rc [load_ip_parms $chan] puts $chan "NetworkMedium is $nettype

" puts $chan "AutoConfigEnabled is $dhcp

" puts $chan "HostAddress is $hostaddr

" puts $chan "SubnetMask is $netmask

" puts $chan "GatewayAddress is $gw

" puts $chan "DnsServers is $dns

" puts $chan "SsId is $ssid

" } elseif {$submit=="Submit"} { set nettype $nnettype set hostaddr $nhostaddr set netmask $nnetmask set gw $ngw set dns "$ndns" set ssid "$nssid" try { if {$ndhcp == "on"} { set dhcp 1 } else { set dhcp 0 } } catch errCode { set dhcp 0 } set rc [set_ip_parms $chan] puts $chan "

Settings have been saved!

Reboot for changes to take effect.

" config_table $chan 1 } elseif {$submit=="Reboot Now!"} { puts $chan "

Rebooting Now!!!

" set rc [exec reboot] } } register_module "netconfig" "Net Config" "Setup IP and Wireless parameters"