Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 5 commits
  • 18 files changed
  • 0 commit comments
  • 1 contributor
View
10 bin/concerto_configserver
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+begin
+ require 'concerto_client/application/app.rb'
+rescue LoadError => e
+ require 'rubygems'
+ path = File.expand_path '../../lib', __FILE__
+ $:.unshift(path) if File.directory?(path) && !$:.include?(:path)
+ require 'concerto_client/application/app.rb'
+end
View
6 bin/concerto_netsetup
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+require 'concerto_client/netconfig'
+
+ConcertoConfig::configure_system
+
View
16 concerto_client.gemspec
@@ -0,0 +1,16 @@
+require 'rake'
+
+Gem::Specification.new do |s|
+ s.name = 'concerto_client'
+ s.version = '0.0.2'
+ s.date = '2012-06-12'
+ s.summary = 'Concerto Client Tools'
+ s.description = 'Client-side tools for Concerto digital signage'
+ s.authors = ['Andrew Armenia']
+ s.email = 'andrew@asquaredlabs.com'
+ s.files = FileList[
+ 'lib/**/*.rb', 'lib/concerto_client/application/public/*',
+ 'lib/concerto_client/application/views/*.haml', 'bin/*'
+ ].to_a
+ s.executables = ['concerto_netsetup', 'concerto_configserver']
+end
View
308 concerto_config_server.rb
@@ -1,308 +0,0 @@
-require 'rubygems'
-require 'sinatra'
-require 'haml'
-require 'json'
-require './netconfig'
-require 'net/http'
-require 'ipaddress'
-
-# Some files we will use. None of these need to exist right away.
-PASSWORD_FILE='/tmp/concerto_password'
-URL_FILE='/tmp/concerto_url'
-
-# push these over to netconfig.rb?
-# Our list of available physical-layer connection methods...
-CONNECTION_METHODS = [
- ConcertoConfig::WiredConnection,
- ConcertoConfig::WirelessConnection
-]
-# ... and available layer-3 addressing methods.
-ADDRESSING_METHODS = [
- ConcertoConfig::DHCPAddressing,
- ConcertoConfig::StaticAddressing
-]
-
-# Hosts we allow to access configuration without authenticating.
-LOCALHOSTS = [
- IPAddress.parse("127.0.0.1"),
- IPAddress.parse("::1")
-]
-
-# Load our (constant) password from file.
-begin
- PASSWORD = File.open(PASSWORD_FILE) do |f|
- f.readline.chomp
- end
-rescue Errno::ENOENT
- PASSWORD = 'default'
-end
-
-helpers do
- # Get the return value of the method on obj if obj supports the method.
- # Otherwise return the empty string.
- # This is useful in views where arguments may be of diverse types.
- def value_from(obj, method)
- if obj.respond_to? method
- obj.send method
- else
- ""
- end
- end
-
- # Enforce authentication on actions.
- # Calling from within an action will check authentication and return 401
- # if unauthorized.
- def protected!
- unless authorized?
- response['WWW-Authenticate'] = %(Basic realm="Concerto Configuration")
- throw(:halt, [401, "Not authorized\n"])
- end
- end
-
- # Check authorization credentials.
- # Currently configured to check if the REMOTE_ADDR is localhost and allow
- # everything if so. This permits someone at local console to configure
- # without the need for a password. Others must have the correct password
- # to be considered authorized.
- def authorized?
- ip = IPAddress.parse(request.env['REMOTE_ADDR'])
- if LOCALHOSTS.include? ip
- # allow all requests from localhost no questions asked
- true
- else
- @auth ||= Rack::Auth::Basic::Request.new(request.env)
- @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['root', PASSWORD]
- end
- end
-
- # Get our base URL from wherever it may be stored.
- def concerto_url
- begin
- File.open(URL_FILE) do |f|
- f.readline.chomp
- end
- rescue
- ""
- end
- end
-
- # Try to figure out what our current IPv4 address is
- # and return it as a string.
- def my_ip
- iface = ConcertoConfig.configured_interface
- if iface
- iface.ip
- else
- "Network setup failed or bad configuration"
- end
- end
-
- # Check if we have something resembling a network connection.
- # This means we found a usable interface and it has an IPv4 address.
- def network_ok
- iface = ConcertoConfig.configured_interface
- if iface
- if iface.ip != "0.0.0.0"
- true
- else
- false
- end
- else
- false
- end
- end
-
- # Check if we can retrieve a URL and get a 200 status code.
- def validate_url(url)
- begin
- # this will fail with Errno::something if server can't be reached
- response = Net::HTTP.get_response(URI(url))
- if response.code != "200"
- # also bomb out if we don't get an OK response
- # maybe demanding 200 is too strict here?
- fail
- end
-
- # if we get here we have a somewhat valid URL to go to
- true
- rescue
- # our request bombed out for some reason
- false
- end
- end
-end
-
-# The local fullscreen browser will go to /screen.
-# We should redirect to the screen URL if possible.
-# Otherwise, we need to go to the setup page to show useful information
-# and allow for local configuration if needed/wanted.
-get '/screen' do
- # if we don't have a URL go to setup
- # if we do, check it out
- if concerto_url == ''
- redirect '/setup'
- else
- # check if the concerto server is reachable, if so redirect there
- # if not redirect to a local error message screen
- if validate_url(concerto_url)
- redirect concerto_url
- else
- redirect '/problem'
- end
- end
-end
-
-# Present a form for entering the base URL.
-get '/setup' do
- protected!
- if network_ok
- # Everything's up and running, we just don't know what
- # our URL should be.
- haml :setup, :layout => :main
- else
- # The network settings are not sane, we don't have an IP.
- # Redirect the user to the network configuration page to
- # take care of this.
- redirect '/netconfig'
- end
-end
-
-# Save the Concerto base URL.
-post '/setup' do
- protected!
- url = params[:url]
- if validate_url(url)
- File.open(URL_FILE, 'w') do |f|
- f.write url
- end
-
- # root will now redirect to the proper concerto_url
- redirect '/screen'
- else
- # the URL was no good, back to setup!
- # error handling flash something something something
- redirect '/setup'
- end
-end
-
-# render a page indicating that the concerto_url is no good.
-# this page redirects to / every 5 seconds
-get '/problem' do
- haml :problem, :layout => :main
-end
-
-get '/netconfig' do
- protected!
-
- # parse existing config file (if any)
- # if there isn't one, nil will suffice because our
- # value_from(...) helper will return the empty string if a method
- # is not implemented. This is also how we get away with just having
- # one instance each of the config classes that are currently selected.
- begin
- cm, am = ConcertoConfig.read_config
- rescue Errno::ENOENT
- cm = nil
- am = nil
- end
-
- # view will grab what it can from our existing
- # connection/addressing methods using value_from().
- haml :netsettings, :locals => {
- :connection_method => cm,
- :addressing_method => am
- },
- :format => :html5, :layout => :main
-end
-
-# Given the name of a class, pick a class out of a list of allowed classes.
-# This is used for parsing the form input for network configuration.
-def pick_class(name, list)
- list.find { |klass| klass.basename == name }
-end
-
-# Extract arguments from a set of form data that are intended to go to a
-# specific network configuration class. These fields have names of the form
-# 'ClassName/field_name'; this function returns a hash in the form
-# { 'field_name' => 'value } containing the configuration arguments.
-def extract_class_args(params, target_class)
- result = { }
- params.each do |key, value|
- klass, arg = key.split('/', 2)
- if klass == target_class
- result[arg] = value
- end
- end
-
- result
-end
-
-# Set the arguments on an instance of a given configuration class.
-# This uses the safe_assign method that should be present in all
-# configuration classes to determine which values are allowed to be passed
-# via form fields (i.e. which ones are subject to validation)
-def do_assign(params, instance)
- safe = instance.safe_assign
-
- params.each do |param, value|
- if safe.include? param.intern
- instance.send((param + '=').intern, value)
- end
- end
-end
-
-# Process the form fields and generate a JSON network configuration file.
-post '/netconfig' do
- protected!
-
- # First we find the connection-method and addressing-method classes.
- cmclass = pick_class(params[:connection_type], CONNECTION_METHODS)
- fail "Connection method not supported" if cmclass.nil?
-
- amclass = pick_class(params[:addressing_type], ADDRESSING_METHODS)
- fail "Addressing method not supported" if amclass.nil?
-
- # ... and create some instances of them.
- cm = cmclass.new
- am = amclass.new
-
- # Now given the names of the specific classes the user has chosen,
- # extract the corresponding form fields.
- cmargs = extract_class_args(params, cmclass.basename)
- amargs = extract_class_args(params, amclass.basename)
-
- # Set properties on each instance given the form values passed in.
- do_assign(cmargs, cm)
- do_assign(amargs, am)
-
- # Check that everything is consistent. If not, we currently throw
- # an exception, which probably is not the best long term solution.
- cm.validate
- am.validate
-
- # Serialize our instances as JSON data to be written to the config file.
- json_data = {
- 'connection_method' => cmclass.basename,
- 'connection_method_args' => cm.args,
- 'addressing_method' => amclass.basename,
- 'addressing_method_args' => am.args
- }
-
- # Write the config file to disk.
- File.open(ConcertoConfig::CONFIG_FILE, 'w') do |f|
- f.write json_data.to_json
- end
-
- # Reload network configuration.
- STDERR.puts "Trying to bring down the interface"
- if ConcertoConfig.configured_interface
- ConcertoConfig.configured_interface.ifdown
- end
- STDERR.puts "Rewriting configuration files"
- ConcertoConfig::configure_system
- STDERR.puts "Bringing interface back up"
- ConcertoConfig.configured_interface.ifup
-
- # Back to the network form.
- redirect '/netconfig' # as a get request
-end
View
301 lib/concerto_client/application/app.rb
@@ -0,0 +1,301 @@
+require 'rubygems'
+require 'sinatra/base'
+require 'haml'
+require 'json'
+require 'net/http'
+require 'ipaddress'
+require 'concerto_client/netconfig'
+
+class ConcertoConfigServer < Sinatra::Base
+ # push these over to netconfig.rb?
+ # Our list of available physical-layer connection methods...
+ CONNECTION_METHODS = [
+ ConcertoConfig::WiredConnection,
+ ConcertoConfig::WirelessConnection
+ ]
+ # ... and available layer-3 addressing methods.
+ ADDRESSING_METHODS = [
+ ConcertoConfig::DHCPAddressing,
+ ConcertoConfig::StaticAddressing
+ ]
+
+ # Hosts we allow to access configuration without authenticating.
+ LOCALHOSTS = [
+ IPAddress.parse("127.0.0.1"),
+ IPAddress.parse("::1")
+ ]
+
+ set :haml, { :format => :html5, :layout => :main }
+
+ helpers do
+ # Get the return value of the method on obj if obj supports the method.
+ # Otherwise return the empty string.
+ # This is useful in views where arguments may be of diverse types.
+ def value_from(obj, method)
+ if obj.respond_to? method
+ obj.send method
+ else
+ ""
+ end
+ end
+
+ # Enforce authentication on actions.
+ # Calling from within an action will check authentication and return
+ # 401 if unauthorized.
+ def protected!
+ unless authorized?
+ response['WWW-Authenticate'] = \
+ %(Basic realm="Concerto Configuration")
+ throw(:halt, [401, "Not authorized\n"])
+ end
+ end
+
+ # Check authorization credentials.
+ # Currently configured to check if the REMOTE_ADDR is local and allow
+ # everything if so. This permits someone at local console to configure
+ # without the need for a password. Others must have the correct
+ # password to be considered authorized.
+ def authorized?
+ ip = IPAddress.parse(request.env['REMOTE_ADDR'])
+ password = ConcertoConfig::ConfigStore.read_config(
+ 'password', 'default'
+ )
+ if LOCALHOSTS.include? ip
+ # allow all requests from localhost no questions asked
+ true
+ else
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
+ @auth.provided? && @auth.basic? && @auth.credentials && \
+ @auth.credentials == ['root', password]
+ end
+ end
+
+ # Get our base URL from wherever it may be stored.
+ def concerto_url
+ ConcertoConfig::ConfigStore.read_config('concerto_url', '')
+ end
+
+ # Try to figure out what our current IPv4 address is
+ # and return it as a string.
+ def my_ip
+ iface = ConcertoConfig.configured_interface
+ if iface
+ iface.ip
+ else
+ "Network setup failed or bad configuration"
+ end
+ end
+
+ # Check if we have something resembling a network connection.
+ # This means we found a usable interface and it has an IPv4 address.
+ def network_ok
+ iface = ConcertoConfig.configured_interface
+ if iface
+ if iface.ip != "0.0.0.0"
+ true
+ else
+ false
+ end
+ else
+ false
+ end
+ end
+
+ # Check if we can retrieve a URL and get a 200 status code.
+ def validate_url(url)
+ begin
+ # this will fail with Errno::something if server
+ # can't be reached
+ response = Net::HTTP.get_response(URI(url))
+ if response.code != "200"
+ # also bomb out if we don't get an OK response
+ # maybe demanding 200 is too strict here?
+ fail
+ end
+
+ # if we get here we have a somewhat valid URL to go to
+ true
+ rescue
+ # our request bombed out for some reason
+ false
+ end
+ end
+ end
+
+ # The local fullscreen browser will go to /screen.
+ # We should redirect to the screen URL if possible.
+ # Otherwise, we need to go to the setup page to show useful information
+ # and allow for local configuration if needed/wanted.
+ get '/screen' do
+ # if we don't have a URL go to setup
+ # if we do, check it out
+ if concerto_url == ''
+ redirect '/setup'
+ else
+ # check if the concerto server is reachable, if so redirect there
+ # if not redirect to a local error message screen
+ if validate_url(concerto_url)
+ redirect concerto_url
+ else
+ redirect '/problem'
+ end
+ end
+ end
+
+ # Present a form for entering the base URL.
+ get '/setup' do
+ protected!
+ if network_ok
+ # Everything's up and running, we just don't know what
+ # our URL should be.
+ haml :setup
+ else
+ # The network settings are not sane, we don't have an IP.
+ # Redirect the user to the network configuration page to
+ # take care of this.
+ redirect '/netconfig'
+ end
+ end
+
+ # Save the Concerto base URL.
+ post '/setup' do
+ protected!
+ url = params[:url]
+ if validate_url(url)
+ # save to the configuration store
+ ConcertoConfig::ConfigStore.write_config('concerto_url', url)
+
+ # root will now redirect to the proper concerto_url
+ redirect '/screen'
+ else
+ # the URL was no good, back to setup!
+ # error handling flash something something something
+ redirect '/setup'
+ end
+ end
+
+ # render a page indicating that the concerto_url is no good.
+ # this page redirects to / every 5 seconds
+ get '/problem' do
+ haml :problem
+ end
+
+ get '/netconfig' do
+ protected!
+
+ # parse existing config file (if any)
+ # if there isn't one, nil will suffice because our
+ # value_from(...) helper will return the empty string if a method
+ # is not implemented. This is also how we get away with just having
+ # one instance each of the config classes that are currently selected.
+ begin
+ cm, am = ConcertoConfig.read_network_config
+ rescue Errno::ENOENT
+ cm = nil
+ am = nil
+ end
+
+ # view will grab what it can from our existing
+ # connection/addressing methods using value_from().
+ haml :netsettings, :locals => {
+ :connection_method => cm,
+ :addressing_method => am
+ }
+ end
+
+ # Given the name of a class, pick a class out of a list of allowed classes.
+ # This is used for parsing the form input for network configuration.
+ def pick_class(name, list)
+ list.find { |klass| klass.basename == name }
+ end
+
+ # Extract arguments from a set of form data that are intended to go to a
+ # specific network configuration class. These fields have names of the form
+ # 'ClassName/field_name'; this function returns a hash in the form
+ # { 'field_name' => 'value } containing the configuration arguments.
+ def extract_class_args(params, target_class)
+ result = { }
+ params.each do |key, value|
+ klass, arg = key.split('/', 2)
+ if klass == target_class
+ result[arg] = value
+ end
+ end
+
+ result
+ end
+
+ # Set the arguments on an instance of a given configuration class.
+ # This uses the safe_assign method that should be present in all
+ # configuration classes to determine which values are allowed to be passed
+ # via form fields (i.e. which ones are subject to validation)
+ def do_assign(params, instance)
+ safe = instance.safe_assign
+
+ params.each do |param, value|
+ if safe.include? param.intern
+ instance.send((param + '=').intern, value)
+ end
+ end
+ end
+
+ # Process the form fields and generate a JSON network configuration file.
+ post '/netconfig' do
+ protected!
+
+ # First we find the connection-method and addressing-method classes.
+ cmclass = pick_class(params[:connection_type], CONNECTION_METHODS)
+ fail "Connection method not supported" if cmclass.nil?
+
+ amclass = pick_class(params[:addressing_type], ADDRESSING_METHODS)
+ fail "Addressing method not supported" if amclass.nil?
+
+ # ... and create some instances of them.
+ cm = cmclass.new
+ am = amclass.new
+
+ # Now given the names of the specific classes the user has chosen,
+ # extract the corresponding form fields.
+ cmargs = extract_class_args(params, cmclass.basename)
+ amargs = extract_class_args(params, amclass.basename)
+
+ # Set properties on each instance given the form values passed in.
+ do_assign(cmargs, cm)
+ do_assign(amargs, am)
+
+ # Save the configuration file.
+ ConcertoConfig.write_network_config(cm, am)
+
+ # Reload network configuration.
+ STDERR.puts "Trying to bring down the interface"
+ if ConcertoConfig.configured_interface
+ ConcertoConfig.configured_interface.ifdown
+ end
+ STDERR.puts "Rewriting configuration files"
+ ConcertoConfig::configure_system_network
+ STDERR.puts "Bringing interface back up"
+ ConcertoConfig.configured_interface.ifup
+
+ # Back to the network form.
+ redirect '/netconfig' # as a get request
+ end
+
+ get '/password' do
+ protected!
+ haml :password
+ end
+
+ post '/password' do
+ protected!
+
+ if params[:newpass] != params[:newpass_confirm]
+ # something something error handling something
+ redirect '/password'
+ end
+
+ ConcertoConfig::ConfigStore.write_config('password', params[:newpass])
+ redirect '/setup'
+ end
+end
+
+ConcertoConfigServer.run!
View
0 public/network.js → ...erto_client/application/public/network.js
File renamed without changes.
View
0 public/problem.js → ...erto_client/application/public/problem.js
File renamed without changes.
View
0 public/stylesheet.css → ..._client/application/public/stylesheet.css
File renamed without changes.
View
0 public/trollface.png → ...o_client/application/public/trollface.png
File renamed without changes
View
0 views/main.haml → ...ncerto_client/application/views/main.haml
File renamed without changes.
View
0 views/netsettings.haml → ...client/application/views/netsettings.haml
File renamed without changes.
View
9 lib/concerto_client/application/views/password.haml
@@ -0,0 +1,9 @@
+%form{:method=>'post'}
+ %p
+ %label{:for=>'newpass'} New Password
+ %input{:type=>'password', :name=>'newpass'}
+ %p
+ %label{:for=>'newpass_confirm'} Confirm Password
+ %input{:type=>'password', :name=>'newpass_confirm'}
+ %p
+ %input{:type=>'submit', :value=>'Change Password'}
View
0 views/problem.haml → ...rto_client/application/views/problem.haml
File renamed without changes.
View
25 lib/concerto_client/application/views/setup.haml
@@ -0,0 +1,25 @@
+%h1 Welcome to Concerto Player
+%p
+ You're seeing this because your Concerto player has not yet been configured.
+ We need the URL of your Concerto instance before we can get up and running.
+
+%form{:method=>'post'}
+ %p
+ %label{:for=>'url'} URL
+ %input{:type=>'text', :name=>'url'}
+ %input{:type=>'submit', :value=>'Here it is!'}
+
+%p
+ The IPv4 address of this screen appears to be:
+ =my_ip
+%p
+ ==This page can be accessed remotely via http://#{my_ip}/setup
+%p
+ Username is root, default password is 'default'.
+%p
+ Also, you may want to
+ %a{:href=>'/netconfig'} change network settings
+ or
+ %a{:href=>'/password'} change the configuration password.
+
+
View
48 lib/concerto_client/config_store.rb
@@ -0,0 +1,48 @@
+require 'concerto_client/live_image'
+require 'fileutils'
+
+# A key/value store for strings.
+# Right now implemented as disk files.
+module ConcertoConfig
+ module ConfigStore
+ @@path = nil
+
+ def self.read_config(name, default='')
+ initialize_path if not @@path
+ file = File.join(@@path, name)
+ rofile = File.join(@@ropath, name)
+
+ # Check the read/write config location first. If nothing there,
+ # check the read-only location. If nothing is there, return default.
+ # This way writes can be made at runtime on read-only media while
+ # still allowing some settings to be "baked into" the media.
+ if File.exist?(file)
+ IO.read(file)
+ elsif File.exist?(rofile)
+ IO.read(rofile)
+ else
+ default
+ end
+ end
+
+ # Write a config to the read/write configuration location.
+ def self.write_config(name, value)
+ initialize_path if not @@path
+ file = File.join(@@path, name)
+
+ File.open(file, 'w') do |f|
+ f.write value
+ end
+ end
+
+ def self.initialize_path
+ @@ropath = File.join(LiveImage.mountpoint, 'concerto', 'config')
+ if LiveImage.readonly?
+ @@path = '/tmp/concerto/config'
+ else
+ @@path = @@ropath
+ end
+ FileUtils.mkdir_p @@path
+ end
+ end
+end
View
24 lib/concerto_client/live_image.rb
@@ -0,0 +1,24 @@
+# Functions for dealing with the live image
+# (where it's mounted, if it's read-only, etc)
+module ConcertoConfig
+ module LiveImage
+ def self.mountpoint
+ '/live/image'
+ end
+
+ def self.readonly?
+ # on a readonly file system this will fail
+ if not File.exist? self.mountpoint
+ true
+ else
+ begin
+ f = Tempfile.new('test', self.mountpoint)
+ f.close!
+ false
+ rescue Errno::EROFS
+ true
+ end
+ end
+ end
+ end
+end
View
79 netconfig.rb → lib/concerto_client/netconfig.rb
@@ -3,6 +3,7 @@
require 'rubygems'
require 'json'
require 'ipaddress'
+require 'concerto_client/config_store'
# The big idea here is that we have connection methods (layer 2)
# and addressing methods (layer 3) and by combining that configuration
@@ -19,21 +20,17 @@
# files such as wpa_supplicant.conf, resolv.conf etc.
class Module
+ # Get the name of a class/module and strip off any leading modules.
+ # This is useful in determining arguments for Module#const_get.
def basename
name.gsub(/^.*::/, '')
end
end
module ConcertoConfig
- # Where we store the name of the interface we are going to configure.
- INTERFACE_FILE='/tmp/concerto_configured_interface'
-
# The Debian interfaces configuration file we are going to write out.
INTERFACES_FILE='/etc/network/interfaces'
- # The configuration file we will read from.
- CONFIG_FILE='/tmp/netconfig.json'
-
# Some useful interface operations.
class Interface
# Wrap an interface name (eth0, wlan0 etc) with some useful operations.
@@ -440,14 +437,27 @@ def self.description
end
end
- # Read a JSON formatted network configuration from an input stream.
+ # Read a JSON formatted network configuration from the config store.
# This instantiates the connection and addressing method classes
- # and returns the instances
- # i.e.
- # cm, am = read_config(STDIN)
- def self.read_config
- input = IO.read(CONFIG_FILE)
- args = JSON.parse(input)
+ # and returns the instances i.e. cm, am = read_network_config
+ #
+ # If no configuration is saved or it is corrupt this returns
+ # a default configuration that is somewhat likely to work.
+ def self.read_network_config
+ input = ConfigStore.read_config('network_config', '')
+
+ begin
+ args = JSON.parse(input)
+ rescue
+ # set up some sane defaults if we have no configuration
+ # or it can't be parsed
+ args = {
+ 'connection_method' => 'WiredConnection',
+ 'addressing_method' => 'DHCPAddressing',
+ 'connection_method_args' => { },
+ 'addressing_method_args' => { }
+ }
+ end
connection_method_class = ConcertoConfig.const_get(args['connection_method'])
addressing_method_class = ConcertoConfig.const_get(args['addressing_method'])
@@ -463,19 +473,38 @@ def self.read_config
return [connection_method, addressing_method]
end
+ # Save the network configuration to the configuration store.
+ # Arguments are instances of connection method and addressing
+ # method classes. Throws exception if either one is not valid.
+ def self.write_network_config(cm, am)
+ # Check that everything is consistent. If not, we currently throw
+ # an exception, which probably is not the best long term solution.
+ cm.validate
+ am.validate
+
+ # Serialize our instances as JSON data to be written to the config file.
+ json_data = {
+ 'connection_method' => cm.class.basename,
+ 'connection_method_args' => cm.args,
+ 'addressing_method' => am.class.basename,
+ 'addressing_method_args' => am.args
+ }.to_json
+
+ # Save the serialized configuration.
+ ConfigStore.write_config('network_config', json_data)
+ end
+
# This reads a JSON configuration file on STDIN and writes the interfaces
# file. Also the classes instantiated will have a chance to write
# out any auxiliary files needed.
- def self.configure_system
- connection_method, addressing_method = read_config
+ def self.configure_system_network
+ connection_method, addressing_method = read_network_config
ifname = connection_method.config_interface_name
# squirrel away the name of the interface we are configuring
# This will be useful later for getting network status information.
- File.open(INTERFACE_FILE, 'w') do |f|
- f.write ifname
- end
+ ConfigStore.write_config('network_interface', ifname)
# Write the /etc/network/interfaces file.
File.open(INTERFACES_FILE, 'w') do |f|
@@ -500,13 +529,11 @@ def self.configure_system
# Get the name of the interface we configured
def self.configured_interface
- begin
- ifname = File.open(INTERFACE_FILE) do |f|
- f.readline.chomp
- end
- Interface.new(ifname)
- rescue
- nil
- end
+ ifname = ConfigStore.read_config('network_interface', '')
+ if ifname != ''
+ Interface.new(ifname)
+ else
+ nil
+ end
end
end
View
18 views/setup.haml
@@ -1,18 +0,0 @@
-%h1 Welcome to Concerto Player
-%p
- You're seeing this because your Concerto player has not yet been configured.
- We need the URL of your Concerto instance before we can get up and running.
-
-%form{:method=>'post'}
- %p
- %label{:for=>'url'} URL
- %input{:type=>'text', :name=>'url'}
- %input{:type=>'submit', :value=>'Here it is!'}
-
-%p
- The IPv4 address of this screen appears to be:
- =my_ip
-%p
- ==This page can be accessed remotely via http://#{my_ip}/setup
-%p
- Username is root, default password is 'default'.

No commit comments for this range

Something went wrong with that request. Please try again.