diff --git a/.ruby-version b/.ruby-version index e1b9401f..c506e4ef 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.0.0-p195 +ruby-2.0.0-p353 diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index 352b92d3..00000000 --- a/.rvmrc +++ /dev/null @@ -1,2 +0,0 @@ -rvm use --create 2.0.0-p195@amahi - diff --git a/Gemfile b/Gemfile index b894a6b9..804b67dc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,26 @@ source 'https://rubygems.org' -gem 'rails', '3.2.17' +gem "rails", '~>4.1.1' gem 'mysql2' gem "yettings" -group :assets do - gem 'sass-rails' - gem 'coffee-rails' +gem 'sass-rails' , '~>4.0.3' +gem 'coffee-rails' - gem 'therubyracer' +gem 'therubyracer' - gem 'uglifier' -end +gem 'uglifier' + +gem "activeresource", require: "active_resource" +gem 'protected_attributes' +gem 'actionpack-action_caching' +gem 'rails-observers' gem 'jbuilder' gem 'ya2yaml' -gem 'themes_for_rails' +gem 'themes_for_rails', :git => "https://github.com/amahi/themes_for_rails.git" gem 'jquery-rails' gem 'jquery-ui-rails' @@ -43,7 +46,7 @@ group :development do # FIXME: for Fedora only if ((open('/etc/issue').grep(/fedora/i).length > 0) rescue false) - gem 'minitest' + gem "minitest" end end diff --git a/Gemfile.lock b/Gemfile.lock index fcff153c..bbb5785a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,42 +1,54 @@ +GIT + remote: https://github.com/amahi/themes_for_rails.git + revision: e0f2e834ce27f19b287e964f18f027a9b4f172bb + specs: + themes_for_rails (0.5.1) + rails (>= 3.0.0) + GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.17) - actionpack (= 3.2.17) + actionmailer (4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) mail (~> 2.5.4) - actionpack (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) + actionpack (4.1.1) + actionview (= 4.1.1) + activesupport (= 4.1.1) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionpack-action_caching (1.1.1) + actionpack (>= 4.0.0, < 5.0) + actionview (4.1.1) + activesupport (= 4.1.1) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.17) - activesupport (= 3.2.17) - builder (~> 3.0.0) - activerecord (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.17) - activemodel (= 3.2.17) - activesupport (= 3.2.17) - activesupport (3.2.17) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) + activemodel (4.1.1) + activesupport (= 4.1.1) + builder (~> 3.1) + activerecord (4.1.1) + activemodel (= 4.1.1) + activesupport (= 4.1.1) + arel (~> 5.0.0) + activeresource (4.0.0) + activemodel (~> 4.0) + activesupport (~> 4.0) + rails-observers (~> 0.1.1) + activesupport (4.1.1) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) addressable (2.3.6) - arel (3.0.3) - authlogic (3.4.1) + arel (5.0.1.20140414130214) + authlogic (3.4.2) activerecord (>= 3.2) activesupport (>= 3.2) - request_store (~> 1.0.5) + request_store (~> 1.0) bcrypt (3.1.7) - builder (3.0.4) - capybara (2.2.1) + builder (3.2.2) + capybara (2.3.0) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) @@ -46,19 +58,19 @@ GEM capybara (>= 1.0, < 3) launchy cliver (0.3.2) - coffee-rails (3.2.2) + coffee-rails (4.0.1) coffee-script (>= 2.2.0) - railties (~> 3.2.0) + railties (>= 4.0.0, < 5.0) coffee-script (2.2.0) coffee-script-source execjs coffee-script-source (1.7.0) daemons (1.1.9) diff-lcs (1.2.5) - docile (1.1.3) + docile (1.1.5) erubis (2.7.0) eventmachine (1.0.3) - execjs (2.0.2) + execjs (2.2.0) factory_girl (4.4.0) activesupport (>= 3.0.0) factory_girl_rails (4.4.1) @@ -70,11 +82,10 @@ GEM rake hike (1.2.3) i18n (0.6.9) - jbuilder (2.0.6) + jbuilder (2.1.1) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) - journey (1.0.4) - jquery-rails (3.1.0) + jquery-rails (3.1.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) jquery-ui-rails (4.2.1) @@ -88,67 +99,70 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) - mini_portile (0.5.3) - minitest (5.3.3) - multi_json (1.9.2) - mysql2 (0.3.15) - nokogiri (1.6.1) - mini_portile (~> 0.5.0) - poltergeist (1.5.0) + mini_portile (0.6.0) + minitest (5.3.5) + multi_json (1.10.1) + mysql2 (0.3.16) + nokogiri (1.6.2.1) + mini_portile (= 0.6.0) + poltergeist (1.5.1) capybara (~> 2.1) cliver (~> 0.3.1) multi_json (~> 1.0) websocket-driver (>= 0.2.0) - polyglot (0.3.4) + polyglot (0.3.5) + protected_attributes (1.0.8) + activemodel (>= 4.0.1, < 5.0) psych (2.0.5) - quiet_assets (1.0.2) + quiet_assets (1.0.3) railties (>= 3.1, < 5.0) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.4) - rack + rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (3.2.17) - actionmailer (= 3.2.17) - actionpack (= 3.2.17) - activerecord (= 3.2.17) - activeresource (= 3.2.17) - activesupport (= 3.2.17) - bundler (~> 1.0) - railties (= 3.2.17) - railties (3.2.17) - actionpack (= 3.2.17) - activesupport (= 3.2.17) - rack-ssl (~> 1.3.2) + rails (4.1.1) + actionmailer (= 4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) + activemodel (= 4.1.1) + activerecord (= 4.1.1) + activesupport (= 4.1.1) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.1) + sprockets-rails (~> 2.0) + rails-observers (0.1.2) + activemodel (~> 4.0) + railties (4.1.1) + actionpack (= 4.1.1) + activesupport (= 4.1.1) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) + thor (>= 0.18.1, < 2.0) raindrops (0.13.0) - rake (10.3.1) + rake (10.3.2) rb-readline (0.5.1) - rdoc (3.12.2) - json (~> 1.4) ref (1.0.5) - request_store (1.0.5) - rspec-core (2.14.8) - rspec-expectations (2.14.5) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.6) - rspec-rails (2.14.2) + request_store (1.0.6) + rspec-core (3.0.2) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.2) + rspec-support (~> 3.0.0) + rspec-rails (3.0.1) actionpack (>= 3.0) - activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - sass (3.3.6) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.2) + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) scrypt (1.2.1) ffi-compiler (>= 0.0.2) rake @@ -160,15 +174,17 @@ GEM slim (2.0.2) temple (~> 0.6.6) tilt (>= 1.3.3, < 2.1) - sprockets (2.2.2) + sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.1.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) sqlite3 (1.3.9) temple (0.6.7) - themes_for_rails (0.5.1) - rails (>= 3.0.0) therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref @@ -177,15 +193,17 @@ GEM eventmachine (>= 1.0.0) rack (>= 1.0.0) thor (0.19.1) + thread_safe (0.3.4) tilt (1.4.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.39) - uglifier (2.5.0) + tzinfo (1.2.1) + thread_safe (~> 0.1) + uglifier (2.5.1) execjs (>= 0.3.0) json (>= 1.8.0) - unicorn (4.8.2) + unicorn (4.8.3) kgio (~> 2.6) rack raindrops (~> 0.7) @@ -199,6 +217,8 @@ PLATFORMS ruby DEPENDENCIES + actionpack-action_caching + activeresource authlogic bcrypt capybara @@ -211,17 +231,19 @@ DEPENDENCIES minitest mysql2 poltergeist + protected_attributes psych quiet_assets - rails (= 3.2.17) + rails (~> 4.1.1) + rails-observers rb-readline rspec-rails - sass-rails + sass-rails (~> 4.0.3) scrypt simplecov slim sqlite3 - themes_for_rails + themes_for_rails! therubyracer thin thor diff --git a/Makefile b/Makefile index 1f7c2f8d..fec15e37 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,12 @@ bundle: - bundle install --without test --path vendor/bundle --binstubs bin/ --deployment - (cd vendor/bundle/ruby/gems/; find . -type f -exec grep -l '/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby' {} \; | xargs sed -i -e 's|/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby|/usr/bin/ruby|') || true + /usr/bin/bundle install --without test --path vendor/bundle --binstubs bin/ --deployment + (cd vendor/bundle/ruby/ && find . -type f -exec grep -l '/usr/bin/ruby' {} \; | xargs sed -i -e 's|/usr/bin/ruby|/usr/bin/ruby|') || true + # clean up things that are not needed at run time + (cd vendor/bundle/ruby/ && rm -rf cache) || true + (cd vendor/bundle/ruby/gems && rm -rf rails-*/guides */spec */doc */doc-api) || true + (cd vendor/bundle/ruby/gems && rm -rf */test */tests) || true + (cd vendor/bundle/ruby/ && find . \( -name '*.[coa]' -or -name '*.cc' -or -name '*.md' -or -name '.git' \) -exec rm -rf {} \;) || true distclean: clean rm -rf vendor/bundle diff --git a/app/assets/images/logo16x16.png b/app/assets/images/logo16x16.png index a81c1b0b..a46636a6 100644 Binary files a/app/assets/images/logo16x16.png and b/app/assets/images/logo16x16.png differ diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png deleted file mode 100644 index d5edc04e..00000000 Binary files a/app/assets/images/rails.png and /dev/null differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 82d50edc..0ba021c5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,5 +13,5 @@ //= require lib/application //= require lib/templates //= require lib/smart-links - +//= require lib/debug //= require spinner diff --git a/app/assets/javascripts/lib/debug.js.coffee b/app/assets/javascripts/lib/debug.js.coffee new file mode 100644 index 00000000..bf13fa42 --- /dev/null +++ b/app/assets/javascripts/lib/debug.js.coffee @@ -0,0 +1,24 @@ +# Amahi Home Server +# Copyright (C) 2007-2013 Amahi +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License v3 +# (29 June 2007), as published in the COPYING file. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# file COPYING for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Amahi +# team at http://www.amahi.org/ under "Contact Us." + +# Debug JS functionality + + +$(document).on "ajax:success", ".debug-form", (event, results) -> + if results.status is "ok" + $('#debug-submit-form').html("

Error Log Succesfully Submitted

") + else + $('#debug-submit-form').html("

Debug report failed. Please do try again later.

") \ No newline at end of file diff --git a/app/assets/stylesheets/login.css.scss b/app/assets/stylesheets/login.css.scss index 71475bde..1039576a 100644 --- a/app/assets/stylesheets/login.css.scss +++ b/app/assets/stylesheets/login.css.scss @@ -57,7 +57,7 @@ a {text-decoration: none;} margin: 20px auto 7em auto; } -.message-error { +.alert-danger{ margin: 0 0 16px 8px; padding: 12px; border: 1px solid #C00000; @@ -71,7 +71,7 @@ a {text-decoration: none;} background-color: #e0ffda; } -.message-notice { +.alert-info { margin: 0 0 16px 8px; padding: 12px; border: 1px solid #FAB762; diff --git a/app/assets/themes/default/stylesheets/style.css.scss b/app/assets/themes/default/stylesheets/style.css.scss index 5e5590e8..b9123747 100644 --- a/app/assets/themes/default/stylesheets/style.css.scss +++ b/app/assets/themes/default/stylesheets/style.css.scss @@ -1558,3 +1558,31 @@ textarea {border: 1px solid #ccc;} .hide { display: none; } + +//Markup for alert boxes +.alert { +padding: 15px; +margin-bottom: 20px; +border: 1px solid transparent; +border-radius: 4px; +} +.alert-success { + color: #3c763d; + background-color: #dff0d8; + border-color: #d6e9c6; +} +.alert-info { + color: #31708f; + background-color: #d9edf7; + border-color: #bce8f1; +} +.alert-danger { + color: #a94442; + background-color: #f2dede; + border-color: #ebccd1; +} +//Debug Tab Design +.debug-form{ + margin-top:10px !important; + margin-left: 20px !important; +} \ No newline at end of file diff --git a/app/controllers/aliases_controller.rb b/app/controllers/aliases_controller.rb index 74867e81..e7955d84 100644 --- a/app/controllers/aliases_controller.rb +++ b/app/controllers/aliases_controller.rb @@ -18,8 +18,8 @@ class AliasesController < ApplicationController before_filter :admin_required - VALID_NAME = Regexp.new "^[A-Za-z0-9\-]+$" - VALID_ADDRESS = Regexp.new '^(|\d(\d?\d?)|\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?))$' + VALID_NAME = Regexp.new "\A[A-Za-z0-9\-]+\z" + VALID_ADDRESS = Regexp.new '\A(|\d(\d?\d?)|\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?))\z' def initialize @page_title = 'DNS Aliases' @@ -160,7 +160,7 @@ def new_alias_check render :partial => 'aliases/name_bad' return end - a = DnsAlias.find_by_alias(n) + a = DnsAlias.where(:alias=>n).first if a.nil? # no such alias, ok to create it @name = n @@ -195,7 +195,7 @@ def valid_address?(addr) # NOTE: do not allow aliases to the hda as a blank address return false if addr.blank? return false unless (addr =~ VALID_ADDRESS) - if addr =~ Regexp.new('^(\d+)\.(\d+)\.(\d+)\.(\d+)$') + if addr =~ Regexp.new('\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z') [$1, $2, $3, $4].each { |ip| return false if ip.to_i > 254 } return true end @@ -203,11 +203,11 @@ def valid_address?(addr) end def is_address_full?(addr) - (addr =~ Regexp.new('^(\d+)\.(\d+)\.(\d+)\.(\d+)$')) ? true : false + (addr =~ Regexp.new('\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z')) ? true : false end def valid_short_address?(addr) - if addr =~ Regexp.new('^(\d+)$') + if addr =~ Regexp.new('\A(\d+)\z') v = addr.to_i return true unless v < 0 or v > 254 end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e4429191..9a329c6f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,17 +37,17 @@ def before_filter_hook set_direction check_for_amahi_app prepare_theme - adv = Setting.find_by_name('advanced') + adv = Setting.where(:name=>'advanced').first @advanced = adv && adv.value == '1' end def check_for_amahi_app server = request.env['SERVER_NAME'] dom = Setting.get_by_name('domain') - if server && server != 'hda' && server =~ /^(.*)\.#{dom}$/ + if server && server != 'hda' && server =~ /\A(.*)\.#{dom}\z/ server = $1 end - if server && server != 'hda' && DnsAlias.find_by_name(server) + if server && server != 'hda' && DnsAlias.where(:name=>server).first redirect_to "http://hda/hda_app_#{server}" end end @@ -75,8 +75,8 @@ def setup_router rd = RouterDriver.current_router = (r ? r.value : "") # return the class proper if valid @router = Kernel.const_get(rd) unless rd.blank? - u = Setting.network.find_by_name('router_username') - p = Setting.network.find_by_name('router_password') + u = Setting.network.where(:name=>'router_username').first + p = Setting.network.where(:name=>'router_password').first RouterDriver.set_auth(unobfuscate(u.value), unobfuscate(p.value)) if p and u and p.value and u.value rescue # shhh. comment out the rescue for debugging @@ -165,7 +165,7 @@ def current_user def login_required unless current_user store_location - flash[:notice] = I18n.t('must_be_logged_in') + flash[:info] = I18n.t('must_be_logged_in') redirect_to new_user_session_path return false end @@ -181,7 +181,7 @@ def admin_required return false if login_required == false unless current_user.admin? store_location - flash[:notice] = t('must_be_admin') + flash[:info] = t('must_be_admin') redirect_to new_user_session_url return false end diff --git a/app/controllers/calendar_controller.rb b/app/controllers/calendar_controller.rb index b7163282..c1cf6b44 100644 --- a/app/controllers/calendar_controller.rb +++ b/app/controllers/calendar_controller.rb @@ -36,7 +36,7 @@ def remove FileUtils.rm_rf(".DAV/" + calname + ".dir") @calendars = Dir["*.ics"] end - @has_ical = App.find_by_name 'iCalendar' != nil + @has_ical = App.where(:name => 'iCalendar').first != nil render :partial => 'calendar/calendar', :collection => @calendars, :locals => { :has_ical => @has_ical } end @@ -52,7 +52,7 @@ def new end @calendars = Dir["*.ics"] end - @has_ical = App.find_by_name 'iCalendar' != nil + @has_ical = App.where(:name=>'iCalendar').first != nil render :partial => 'calendar/calendar', :collection => @calendars, :locals => { :has_ical => @has_ical } end diff --git a/app/controllers/debug_controller.rb b/app/controllers/debug_controller.rb new file mode 100644 index 00000000..8b68821f --- /dev/null +++ b/app/controllers/debug_controller.rb @@ -0,0 +1,51 @@ +# Amahi Home Server +# Copyright (C) 2007-2013 Amahi +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License v3 +# (29 June 2007), as published in the COPYING file. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# file COPYING for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Amahi +# team at http://www.amahi.org/ under "Contact Us." + +class DebugController < ApplicationController + + before_filter :admin_required + layout 'debug' + + def index + @page_title = t('debug') + end + + def logs + @page_title = t('debug') + end + + def system + @page_title = t('debug') + end + + + def submit + AmahiApi.api_key = Setting.get "api-key" + report = SystemUtils.run 'tail -200 /var/hda/platform/html/log/production.log' + er = AmahiApi::ErrorReport.new(:report => report, :comments => params[:comments], :subject => params[:subject]) + begin + if er.save + render :json =>{:status=>'ok'} + else + render :json =>{:status=>'failed',:errors=> er.errors} + end + rescue + render :json =>{:status=>'failed',:errors=> er.errors} + end + end + + +end diff --git a/app/controllers/front_controller.rb b/app/controllers/front_controller.rb index 5f1264cd..8113495b 100644 --- a/app/controllers/front_controller.rb +++ b/app/controllers/front_controller.rb @@ -4,12 +4,12 @@ # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License v3 # (29 June 2007), as published in the COPYING file. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # file COPYING for more details. -# +# # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Amahi # team at http://www.amahi.org/ under "Contact Us." @@ -24,5 +24,4 @@ def index @apps = App.in_dashboard @news = AmahiNews.top() end - end diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb index 01d56dc1..84ed22e1 100644 --- a/app/controllers/hosts_controller.rb +++ b/app/controllers/hosts_controller.rb @@ -17,8 +17,8 @@ class HostsController < ApplicationController before_filter :admin_required - VALID_NAME = Regexp.new "^[A-Za-z][A-Za-z0-9\-]+$" - VALID_ADDRESS = Regexp.new '^(|\d(\d?\d?)|\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?))$' + VALID_NAME = Regexp.new "\A[A-Za-z][A-Za-z0-9\-]+\z" + VALID_ADDRESS = Regexp.new '\A(|\d(\d?\d?)|\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?)\.\d(\d?\d?))\z' MAC_P = '(\d|[A-Fa-f])(\d|[A-Fa-f])' # This is the range at which DHCP starts. Strictly below is valid @@ -122,7 +122,7 @@ def update_address render :text => a.address return end - h = Host.find_by_address addr + h = Host.where(:address=>addr).first if h.nil? # no such address, ok to use it a.address = addr @@ -140,7 +140,7 @@ def update_mac render :text => a.mac return end - h = Host.find_by_mac mac + h = Host.where(:mac=>mac).first if h.nil? # no such address, ok to use it a.mac = mac @@ -172,7 +172,7 @@ def new_host_check render :partial => 'hosts/name_bad' return end - a = Host.find_by_host(n) + a = Host.where(:host=>n).first if a.nil? # no such alias, ok to create it @name = n @@ -190,7 +190,7 @@ def new_address_check render :partial => 'hosts/address_bad' return end - a = Host.find_by_address(n) + a = Host.where(:address=>n).first if a.nil? # no such address, ok to create it @name = n @@ -208,7 +208,7 @@ def new_mac_check render :partial => 'hosts/mac_bad' return end - a = Host.find_by_mac(n) + a = Host.where(:mac=>n).first if a.nil? # no such mac, ok to create it @name = n @@ -242,7 +242,7 @@ def valid_name?(nm) end def valid_short_address?(addr) - if addr =~ Regexp.new('^(\d+)$') + if addr =~ Regexp.new('\A(\d+)\z') v = addr.to_i return true if v > 0 and v < VALID_DHCP_ADDRESS_RANGE end diff --git a/app/controllers/share_controller.rb b/app/controllers/share_controller.rb index 0f792821..45e1bd78 100644 --- a/app/controllers/share_controller.rb +++ b/app/controllers/share_controller.rb @@ -17,7 +17,7 @@ class ShareController < ApplicationController before_filter :admin_required - VALID_NAME = Regexp.new "^\\w[\\w ]+$" + VALID_NAME = Regexp.new "\A\\w[\\w ]+\z" # Disk Pool minimum free: default og 10GB, but for root, # 20GB. so that when all drives are full, / should still have 10GB free. DP_MIN_FREE_DEFAULT = 10 @@ -97,7 +97,7 @@ def new_share_name_check render :partial => 'share/name_invalid' return false end - share = Share.find_by_name(sn) + share = Share.where(:name=>sn).first if share render :partial => 'share/name_not_available' return false @@ -118,7 +118,7 @@ def new_share_path_check render :partial => 'share/path_invalid' return false end - share = Share.find_by_path(sp) + share = Share.where(:path=>sp).first if share render :partial => 'share/path_not_available' return false @@ -296,7 +296,7 @@ def update_disk_pool_copies def toggle_disk_pool_partition path = params[:path] - part = DiskPoolPartition.find_by_path(path) + part = DiskPoolPartition.where(:path=>path).first if part # was enabled - disable it by deleting it # FIXME - see http://bugs.amahi.org/issues/show/510 @@ -318,7 +318,7 @@ def toggle_disk_pool_partition def is_valid_domain_name(domain) return false if domain.size > 15 || domain.size < 1 - return false unless domain =~ /^[A-z][A-z_0-9]*$/ + return false unless domain =~ /\A[A-z][A-z_0-9]*\z/ true end diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index 921be70b..c475a09c 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -4,12 +4,12 @@ # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License v3 # (29 June 2007), as published in the COPYING file. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # file COPYING for more details. -# +# # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Amahi # team at http://www.amahi.org/ under "Contact Us." @@ -34,7 +34,7 @@ def start else # initial system initialization @user = User.new - flash[:notice] = t("amahi_initialization") + flash[:info] = t("amahi_initialization") @title = t("amahi_initialization") end end @@ -45,9 +45,10 @@ def create remember_me = params[:remember_me] @user_session = UserSession.new(:login => username, :password => password, :remember_me => remember_me) if @user_session.save + flash[:success] = t 'logged_in_successfully' redirect_to root_url else - flash[:error] = t 'not_a_valid_user_or_password' + flash[:danger] = t 'not_a_valid_user_or_password' render :action => 'new' end end @@ -57,7 +58,7 @@ def destroy @user_session = UserSession.find @user_session.destroy # FIXME-translate - flash[:notice] = t('you_have_been_logged_out') + flash[:info] = t('you_have_been_logged_out') redirect_to root_path end @@ -67,7 +68,7 @@ def initialize_system pwd = params[:password] conf = params[:password_confirmation] unless valid_admin_password?(pwd, conf) - flash[:error] = t 'not_a_valid_user_or_password' + flash[:danger] = t 'not_a_valid_user_or_password' @user = User.new sleep 1 render :action => 'start' @@ -80,13 +81,13 @@ def initialize_system # FIXME-cpg: very hackish constant for regular uid (1000) unless name and uid and uid >= 1000 # not a system user. should we create one? - flash[:error] = t 'not_a_valid_user_or_password' + flash[:danger] = t 'not_a_valid_user_or_password' @user = User.new render :action => 'start' return end # the user exists in the system .. does it exist in the database? - u = User.find_by_login(systemusername) + u = User.where(:login=>systemusername).first if u @user = u else @@ -102,7 +103,7 @@ def initialize_system initialize_default_settings redirect_to root_url else - flash[:error] = t 'not_a_valid_user_or_password' + flash[:danger] = t 'not_a_valid_user_or_password' render :action => 'start' end end diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index c52eb534..9b3f1887 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -17,13 +17,22 @@ module TabsHelper def tab_class(tab) - klass = params[:controller] == tab.id ? 'active' : '' + if params[:controller] == tab.id + klass = 'active' + else + subtab = Tab.find(params[:controller]) + if subtab==nil + if Tab.ischild(params[:controller],tab) + klass = 'active' + end + end + end klass += " empty" unless tab.subtabs? klass end - def subtab_class(action = nil) - params[:action] == action ? 'active' : '' + def subtab_class(action = nil, tab_id) + ((action == params[:action] && params[:controller] == tab_id) or (action == params[:controller] && Tab.find(params[:controller])==nil) ) ? 'active' : '' end def nav_class(tabs) @@ -38,7 +47,7 @@ def debug_tab? end def advanced? - (s = Setting.find_by_name 'advanced') && s.set? + (s = Setting.where(:name=>'advanced').first) && s.set? end def debug? diff --git a/app/models/app.rb b/app/models/app.rb index 2c754e47..059adb3c 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -41,9 +41,9 @@ class App < ActiveRecord::Base has_many :children, :class_name => "AppDependency", :foreign_key => 'dependency_id' has_many :dependencies, :through => :app_dependencies - scope :installed, where(:installed => true) - scope :in_dashboard, where(:show_in_dashboard => true).installed - scope :latest_first, :order => 'updated_at desc' + scope :installed, ->{where(:installed => true)} + scope :in_dashboard,-> {where(:show_in_dashboard => true).installed} + scope :latest_first, ->{order('updated_at desc')} before_destroy :before_destroy_hook @@ -111,7 +111,7 @@ def self.available AmahiApi::api_key = Setting.value_by_name("api-key") begin AmahiApi::App.find(:all).map do |online_app| - App.find_by_identifier(online_app.id) ? nil : App.new(online_app.id, online_app) + App.where(:identifier=>online_app.id).first ? nil : App.new(online_app.id, online_app) end.compact rescue [] @@ -157,14 +157,14 @@ def install_status end def self.installation_status(identifier) - status = Setting.find_by_kind_and_name(identifier, 'install_status') + status = Setting.where(:kind=>identifier,:name=> 'install_status').first return 0 unless status status.value.to_i end def install_status=(value) # create it dynamically if it does not exist - status = Setting.find_or_create_by(self.identifier, 'install_status', value) + status = Setting.where(:kind=>self.identifier, :name=> 'install_status').first_or_create if value.nil? status && status.destroy return nil @@ -213,7 +213,7 @@ def install_bg self.create_db(:name => installer.database) if installer.database && !installer.database.blank? # if it has a share, create it and install it if installer.share - sh = Share.find_by_name installer.share + sh = Share.where(:name=>installer.share).first if sh # FIXME: autohook to it. this is for legacy shares. not needed in new installs self.share = sh @@ -376,7 +376,7 @@ def install_app_deps(installer) return [] if deps.nil? or deps.blank? deps.strip! deps.split(/[, ]+/).map do |identifier| - a = App.find_by_identifier identifier + a = App.where(:identifier=>identifier).first unless a a = App.new identifier a.install_bg @@ -469,7 +469,7 @@ def webapp_name(name) i = 0 add = "" begin - wa = Webapp.find_by_name(name + add) + wa = Webapp.where(:name=>(name + add)).first return (name+add) if wa.nil? raise "cannot find a suitable webapp name. giving up at #{name+add}." if i > 29 i += 1 diff --git a/app/models/db.rb b/app/models/db.rb index f25afec5..2623cd34 100644 --- a/app/models/db.rb +++ b/app/models/db.rb @@ -4,12 +4,12 @@ # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License v3 # (29 June 2007), as published in the COPYING file. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # file COPYING for more details. -# +# # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Amahi # team at http://www.amahi.org/ under "Contact Us." @@ -40,7 +40,7 @@ def hostname private def after_create_hook - c = connection + c = self.class.connection password = name user = name host = 'localhost' @@ -58,7 +58,7 @@ def after_destroy_hook Dir.chdir(DB_BACKUPS_DIR) do system("ln -sf #{filename} latest-#{name}.bz2") end - c = connection + c = self.class.connection host = 'localhost' c.execute "drop user '#{user}'@'#{host}';" c.execute "drop database if exists `#{name}`;" diff --git a/app/models/dns_alias.rb b/app/models/dns_alias.rb index 222af9b2..d30955af 100644 --- a/app/models/dns_alias.rb +++ b/app/models/dns_alias.rb @@ -20,7 +20,7 @@ class DnsAlias < ActiveRecord::Base after_destroy :restart after_save :restart - scope :user_visible, where(["address != ?", '']) + scope :user_visible,->{where(["address != ?", ''])} attr_accessible :name, :address diff --git a/app/models/plugin.rb b/app/models/plugin.rb index 42d448d1..dc1b5c5f 100644 --- a/app/models/plugin.rb +++ b/app/models/plugin.rb @@ -52,7 +52,12 @@ def install(installer, source) # uninstall when the object is destroyed def before_destroy - location = File.join(Rails.root, "plugins", "#{1000+id}-#{path}") + base = File.basename path + location = File.join(Rails.root, "plugins", "#{1000+id}-#{base}") + array = [] + array <<"#{location}/db/migrate" + puts "Reverting the changes to the database made by the plugin" + ActiveRecord::Migrator.down(array,nil) FileUtils.rm_rf location # restart the rails stack -- FIXME: this is too much a restart would be best c = Command.new "touch /var/hda/platform/html/tmp/restart.txt" @@ -75,6 +80,10 @@ def dir2plugin(source, config) FileUtils.rm_rf destination FileUtils.mv source, destination # FIXME: eventually we need to do migrations, probably here + array = [] + array <<"#{destination}/db/migrate" + puts "Migrating database of the plugin, if applicable" + ActiveRecord::Migrator.up(array, nil) # restart the rails stack -- FIXME: this is too much a restart would be best c = Command.new "touch /var/hda/platform/html/tmp/restart.txt" c.execute diff --git a/app/models/setting.rb b/app/models/setting.rb index 3df8ac82..dc68cbe0 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -20,16 +20,16 @@ class Setting < ActiveRecord::Base attr_accessible :name, :value, :kind - scope :by_name, lambda{|name| where(:name => name)} - scope :by_kind, lambda{|kind| where(:kind => kind)} + scope :by_name, lambda{|name| where(:name => name)} + scope :by_kind, lambda{|kind| where(:kind => kind)} - scope :general, by_kind(GENERAL) - scope :network, by_kind(NETWORK) - scope :shares, by_kind(SHARES) + scope :general, ->{by_kind(GENERAL)} + scope :network, ->{by_kind(NETWORK)} + scope :shares, ->{by_kind(SHARES)} validates :value, :length => { :maximum => 15 }, - :format => { :with => /^[a-zA-Z][a-zA-Z0-9]{0,14}$/ }, + :format => { :with => /\A[a-zA-Z][a-zA-Z0-9]{0,14}\z/ }, :if => Proc.new { |x| x.kind.eql?(Setting::GENERAL) && x.name.eql?('workgroup') }, :on => :update @@ -49,7 +49,7 @@ def get(name) end def set(name, value, kind=GENERAL) - self.find_or_create_by_name(:name => name).update_attributes(value: value, kind: kind) + self.where(:name => name).first_or_create.update_attributes(value: value, kind: kind) end def get_kind(kind, name) diff --git a/app/models/share.rb b/app/models/share.rb index a0e562d6..94c2647f 100644 --- a/app/models/share.rb +++ b/app/models/share.rb @@ -26,7 +26,7 @@ class Share < ActiveRecord::Base DEFAULT_SHARES = [ "Books", "Pictures", "Movies", "Videos", "Music", "Docs", "Public" ].each {|s| I18n.t s } PDC_SETTINGS = "/var/hda/domain-settings" - default_scope order("name") + default_scope {order("name")} # scope :in_disk_pool, where([ "disk_pool_copies > ?", 0]) has_many :cap_accesses, :dependent => :destroy @@ -43,7 +43,7 @@ class Share < ActiveRecord::Base attr_accessible :name, :path, :rdonly, :visible, :tags, :extras validates :name, :presence => true, - :format => { :with => /^\w[\w ]+$/ }, + :format => { :with => /\A\w[\w ]+\z/ }, :length => { :maximum => 32 }, :uniqueness => { :case_sensitive => false } diff --git a/app/models/theme.rb b/app/models/theme.rb index cc139c03..6ee100f3 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -24,7 +24,7 @@ def self.available tl = all Dir.chdir(File.join(Rails.root, THEME_ROOT)) do Dir.glob("*").sort.each do |theme_dir| - next if find_by_css theme_dir + next if where(:css=>theme_dir).first theme_init_file = File.join(theme_dir, "init.rb") if File.exist? theme_init_file load theme_init_file diff --git a/app/models/user.rb b/app/models/user.rb index 06dc68da..e752d623 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -19,7 +19,7 @@ class User < ActiveRecord::Base - scope :admins, where(:admin => true) + scope :admins, ->{ where(:admin => true)} begin acts_as_authentic do |c| @@ -37,7 +37,7 @@ class User < ActiveRecord::Base attr_accessible :login, :name, :password, :password_confirmation, :admin validates :login, :presence => true, - :format => { :with => /^[A-Za-z][A-Za-z0-9]+$/ }, + :format => { :with => /\A[A-Za-z][A-Za-z0-9]+\z/ }, :length => { :in => 3..32 }, :uniqueness => { :case_sensitive => false }, :user_not_exist_in_system => {:message => 'already exists in system', :on => :create} @@ -71,7 +71,7 @@ def system_all_new_users res = [] Dir.chdir("/home") do Dir.glob("*").sort.reverse.each do |login| - unless User.find_by_login login + unless User.where(:login=> login).first name, uid = system_find_name_by_username login # FIXME-cpg: Fedora specific constant 500 here res << { :login => login, :name => name } unless name.nil? or name.blank? or uid < 500 diff --git a/app/models/webapp.rb b/app/models/webapp.rb index 958c8923..d8683193 100644 --- a/app/models/webapp.rb +++ b/app/models/webapp.rb @@ -97,13 +97,14 @@ def conf_file else # generic f = File.open(BASE % "generic") end - server_aliases = self.aliases.split(/[, ]+/).select{ |s| ! (s.empty? || DnsAlias.find_by_alias(s)) } + server_aliases = self.aliases.split(/[, ]+/).select{ |s| ! (s.empty? || DnsAlias.where(:alias=>s).first) } server_aliases += self.webapp_aliases.map{|wa| wa.name} aliases = server_aliases.count > 0 ? ("ServerAlias " + server_aliases.join(" ")) : "" conf = f.readlines.join conf = conf.gsub(/HDA_APP_NAME/, name) conf = conf.gsub(/APP_ROOT_DIR/, path) conf = conf.gsub(/HDA_DOMAIN/, domain) unless domain.empty? + conf = conf.gsub(/HDA_AUTHFILE/, "#{path}/htpasswd") conf = conf.gsub(/HDA_ACCESS/, login_required ? access_conf : '') conf = conf.gsub(/APP_ALIASES/, aliases || '') begin diff --git a/app/models/webapp_alias.rb b/app/models/webapp_alias.rb index e3a11feb..a149ee4c 100644 --- a/app/models/webapp_alias.rb +++ b/app/models/webapp_alias.rb @@ -20,12 +20,12 @@ class WebappAlias < ActiveRecord::Base after_save :save_webapp after_destroy :save_webapp - + attr_accessible :name, :webapp_id validates :name, :presence => true, :uniqueness => true, :length => { :within => 1..254 }, - :format => { :with => /^[a-z0-9][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*){0,5}$/i } + :format => { :with => /\A[a-z0-9][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*){0,5}\z/i } def to_s name diff --git a/app/views/aliases/_new.html.erb b/app/views/aliases/_new.html.erb index fd3838ea..409fc575 100644 --- a/app/views/aliases/_new.html.erb +++ b/app/views/aliases/_new.html.erb @@ -1,6 +1,6 @@
-<%= button_to_function " #{t('new_alias')} » ", update_page { |page| +<%= button_to " #{t('new_alias')} » ", update_page { |page| page.hide 'new-alias-to-step1' page[:alias_alias].value = "" page[:alias_address].value = "" diff --git a/app/views/aliases/_one.html.erb b/app/views/aliases/_one.html.erb index 27d71bf6..4ed4ff8d 100644 --- a/app/views/aliases/_one.html.erb +++ b/app/views/aliases/_one.html.erb @@ -1,10 +1,10 @@ <% name = [h(one.alias), @domain].join '.' - name = h($1) if one.alias =~ /(.*)\.$/ + name = h($1) if one.alias =~ /(.*)\.\z/ (base, addr) = case one.address when '' [@net, @self] - when /^\d+$/ + when /\A\d+\z/ [@net, [@net, h(one.address)].join('.')] else ['', h(one.address)] @@ -22,7 +22,7 @@
- <%= link_to_function(h(name), '') %> + <%= link_to(h(name), '') %> <%= h(addr) %> diff --git a/app/views/aliases/_step1.html.erb b/app/views/aliases/_step1.html.erb index 29a605c5..4156dc52 100644 --- a/app/views/aliases/_step1.html.erb +++ b/app/views/aliases/_step1.html.erb @@ -29,7 +29,7 @@
 
   - <%= link_to_function t('cancel'), update_page { |page| + <%= link_to t('cancel'), update_page { |page| page.hide 'new-alias-step1' page.show 'new-alias-to-step1' page[:alias_alias].value = "" diff --git a/app/views/debug/_app_logs.rhtml b/app/views/debug/_app_logs.rhtml deleted file mode 100644 index 6b2a3411..00000000 --- a/app/views/debug/_app_logs.rhtml +++ /dev/null @@ -1,51 +0,0 @@ -<% message_string = "\n\nExplain the sequence of events leading to the error\nin as much detail as you can.\n\nThe more *concrete detail* you can add,\nthe higher chances we fix the problem quickly!\n\nClick here to continue ..." %> - - -
-
-
-
-	<% text = SystemUtils.run "tail -100 #{Rails.root}/log/production.log" %>
-	<%= h text %> 
-	
-
diff --git a/app/views/debug/_debug_submit_failed.rjs b/app/views/debug/_debug_submit_failed.rjs deleted file mode 100644 index 351cb7b7..00000000 --- a/app/views/debug/_debug_submit_failed.rjs +++ /dev/null @@ -1,2 +0,0 @@ -page[:thanks].replace_html "Debug report failed. Please do try again later." -page.visual_effect :highlight, :thanks, { :duration => 8 } diff --git a/app/views/debug/_debug_submit_worked.rjs b/app/views/debug/_debug_submit_worked.rjs deleted file mode 100644 index be97213d..00000000 --- a/app/views/debug/_debug_submit_worked.rjs +++ /dev/null @@ -1,5 +0,0 @@ -page.visual_effect :fade, :debug_submit_form -page[:thanks].replace_html "Debug report submitted. Your report ID is #{error_id}. Thanks for helping improve Amahi!" -page.visual_effect :highlight, :thanks, { :duration => 14 } -page[:subject].value = "Describe what failed here ..." -page[:comments].value = "Click here to explain how the error occurred ..." diff --git a/app/views/debug/_form.html.slim b/app/views/debug/_form.html.slim new file mode 100644 index 00000000..145aef62 --- /dev/null +++ b/app/views/debug/_form.html.slim @@ -0,0 +1,18 @@ +- message_string = "\n\nExplain the sequence of events leading to the error\nin as much detail as you can.\n\nThe more *concrete detail* you can add,\nthe higher chances we fix the problem quickly!" + += form_for :debug, :remote => true, :html => {\ + :class => 'debug-form',\ + :id => 'submit-debug-form'\ + } do |f| + .control-group + h3.debug-form Help improve Amahi by sending crash reports and anonymous usage data. + .control-group + .controls= f.text_field :subject, :size => 32, :maxlength => 40, :placeholder => "Describe what failed here ...",:class=> "form-control debug-form" + .control-group + .controls + = text_area_tag :comments, '', :rows => 10, :cols => 80, :placeholder => message_string, :class=> "form-control debug-form" + .control-group.create-btn + .controls + = spinner + = button_tag 'Submit', :type => 'submit', :id => 'debug_button', :class => 'btn btn-submit btn-info btn-sm debug-form', :data=>{:confirm=>"Machine logs will be submitted to Amahi for debug.\nThis will help improve Amahi!\nWould you like to submit?"} + = link_to t('cancel'), '#', :class => 'close-area cancel-link debug-form', :data => {:related=> '#debug-button'}, :onclick=>"$('#debug-submit-form').hide('slow');" \ No newline at end of file diff --git a/app/views/debug/_logs.rhtml b/app/views/debug/_logs.rhtml deleted file mode 100644 index 21c997ff..00000000 --- a/app/views/debug/_logs.rhtml +++ /dev/null @@ -1,4 +0,0 @@ -
-<%= SystemUtils.run "grep -v \"hda dhcpd:\" #{Platform.file_name(:syslog)} | tail -100 | tac" %>
-
- diff --git a/app/views/debug/_system.rhtml b/app/views/debug/_system.rhtml deleted file mode 100644 index beb7fab7..00000000 --- a/app/views/debug/_system.rhtml +++ /dev/null @@ -1,6 +0,0 @@ -
-<%= SystemUtils.uptime %> 
-<%= SystemUtils.run 'cat /proc/cpuinfo' %> 
-<%= SystemUtils.run 'cat /proc/meminfo' %> 
-
- diff --git a/app/views/debug/index.html.slim b/app/views/debug/index.html.slim new file mode 100644 index 00000000..16eaea70 --- /dev/null +++ b/app/views/debug/index.html.slim @@ -0,0 +1,9 @@ + += button_tag 'Submit for Debug', :type => 'button', :class => 'open-area btn btn-create', :id => "debug-button", :data => { :related => "#debug-submit-form" } + +#debug-submit-form[style="display:none;"] + fieldset + legend   Debug Report   + = render 'form' +pre + = SystemUtils.run "tail -100 #{Rails.root}/log/production.log" diff --git a/app/views/debug/logs.html.slim b/app/views/debug/logs.html.slim new file mode 100644 index 00000000..86afa632 --- /dev/null +++ b/app/views/debug/logs.html.slim @@ -0,0 +1,3 @@ +pre + = SystemUtils.run "grep -v \"hda dhcpd:\" #{Platform.file_name(:syslog)} | tail -100 | tac" + diff --git a/app/views/debug/system.html.slim b/app/views/debug/system.html.slim new file mode 100644 index 00000000..2a852bfd --- /dev/null +++ b/app/views/debug/system.html.slim @@ -0,0 +1,4 @@ +pre + = SystemUtils.uptime + = SystemUtils.run 'cat /proc/cpuinfo' + = SystemUtils.run 'cat /proc/meminfo' \ No newline at end of file diff --git a/app/views/firewall/_new.html.erb b/app/views/firewall/_new.html.erb index 5e05c4d6..a9b3a279 100644 --- a/app/views/firewall/_new.html.erb +++ b/app/views/firewall/_new.html.erb @@ -1,6 +1,6 @@
-<%= button_to_function " #{t 'new_firewall_rule'} » ", update_page { |page| +<%= button_to " #{t 'new_firewall_rule'} » ", update_page { |page| page.hide 'new-firewall-to-step1' page.show 'new-firewall-step1' }, :id => "new-firewall-to-step1" %> diff --git a/app/views/firewall/_rule.html.erb b/app/views/firewall/_rule.html.erb index 99b040c6..e3e32694 100644 --- a/app/views/firewall/_rule.html.erb +++ b/app/views/firewall/_rule.html.erb @@ -15,7 +15,7 @@
- <%= link_to_function(name, '') %> + <%= link_to(name, '') %> <%= active ? "Active" : "Inactive" %> diff --git a/app/views/hosts/_new.html.erb b/app/views/hosts/_new.html.erb index 2f9608cf..95c8ec1c 100644 --- a/app/views/hosts/_new.html.erb +++ b/app/views/hosts/_new.html.erb @@ -1,6 +1,6 @@
-<%= button_to_function " #{t('new_static_ip')} » ", update_page { |page| +<%= button_to " #{t('new_static_ip')} » ", update_page { |page| page.hide 'new-host-to-step1' page[:host_host].value = "" page[:host_address].value = "" diff --git a/app/views/hosts/_one.html.erb b/app/views/hosts/_one.html.erb index fa582480..3d50077b 100644 --- a/app/views/hosts/_one.html.erb +++ b/app/views/hosts/_one.html.erb @@ -22,7 +22,7 @@
- <%= link_to_function(h(name), '') %> + <%= link_to(h(name), '') %> <%= h(addr) %> diff --git a/app/views/hosts/_step1.html.erb b/app/views/hosts/_step1.html.erb index c87c1561..62fda755 100644 --- a/app/views/hosts/_step1.html.erb +++ b/app/views/hosts/_step1.html.erb @@ -35,7 +35,7 @@
 
   - <%= link_to_function t('cancel'), update_page { |page| + <%= link_to t('cancel'), update_page { |page| page.hide 'new-host-step1' page.show 'new-host-to-step1' page[:host_host].value = "" diff --git a/app/views/layouts/debug.html.slim b/app/views/layouts/debug.html.slim new file mode 100644 index 00000000..b1253a24 --- /dev/null +++ b/app/views/layouts/debug.html.slim @@ -0,0 +1,63 @@ +doctype 5 +html[dir="#{@locale_direction}" lang="#{I18n.locale}" xml:lang="#{I18n.locale}"] + head + meta charset="utf-8" + title = full_page_title + + = stylesheet_link_tag 'application' + + - if theme.name != "default" and theme.disable_inheritance == false + = stylesheet_link_tag(theme_stylesheet_path('style', theme.default)) + = stylesheet_link_tag(theme_stylesheet_path('rtl', theme.default)) if rtl? + + = theme_stylesheet_link_tag 'style' + = theme_stylesheet_link_tag('rtl') if rtl? + - amahi_plugins.each do |p| + = stylesheet_link_tag p[:class].underscore + + /[ if lt IE 9 ] + = javascript_include_tag 'http://html5shim.googlecode.com/svn/trunk/html5.js' + + = javascript_tag {render 'shared/js_vars'} + = javascript_include_tag 'application' + - amahi_plugins.each do |p| + = javascript_include_tag p[:class].underscore + + = javascript_tag {'$.fx.off = true;' if Rails.env.test?} + - for header in theme.headers do + = header =~ /\.js$/ ? javascript_include_tag(header) : header + + link rel="search" type="application/opensearchdescription+xml" title="HDA Search" href="/search.xml" + link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" + + = csrf_meta_tags + + body + + = render 'layouts/header' + + #content + = render 'layouts/subheader' + = render 'shared/flash_messages' + #app.inner + #tabs + nav.preftab + ul + li.active + a href='/tab/debug' + = t 'debug' + ul + li[class="#{request.fullpath == '/tab/debug' ? 'active' : ''}"] + = link_to "App Logs", '/tab/debug' + li[class="#{request.fullpath == '/tab/debug/logs' ? 'active' : ''}"] + = link_to "Logs", '/tab/debug/logs' + li[class="#{request.fullpath == '/tab/debug/system' ? 'active' : ''}"] + = link_to "System Info", '/tab/debug/system' + #preferences + .preftab + = yield + + = render 'layouts/footer' + + #js-templates[style="display:none"] + = yield :js_templates diff --git a/app/views/server/_one.html.erb b/app/views/server/_one.html.erb index 9f3435db..b0c9e352 100644 --- a/app/views/server/_one.html.erb +++ b/app/views/server/_one.html.erb @@ -16,7 +16,7 @@
- <%= link_to_function(server.comment, '') %> + <%= link_to(server.comment, '') %> <%= status %> diff --git a/app/views/shared/_flash_messages.html.slim b/app/views/shared/_flash_messages.html.slim index dc3229bf..e1bc8347 100644 --- a/app/views/shared/_flash_messages.html.slim +++ b/app/views/shared/_flash_messages.html.slim @@ -1,3 +1,4 @@ #errors - flash.each do |name, msg| - div[id="flash_#{name}"]= msg \ No newline at end of file + div[class=" alert alert-#{name}"] + strong = msg \ No newline at end of file diff --git a/app/views/shared/_tabs.html.slim b/app/views/shared/_tabs.html.slim index f7ac8da9..55e7a76a 100644 --- a/app/views/shared/_tabs.html.slim +++ b/app/views/shared/_tabs.html.slim @@ -9,9 +9,9 @@ ul - if @advanced - tab.advanced_subtabs.each do |subtab| - li[class=subtab_class(subtab.id)] + li[class=subtab_class(subtab.id,tab.id)] = link_to t(subtab.label), subtab.url - else - tab.basic_subtabs.each do |subtab| - li[class=subtab_class(subtab.id)] + li[class=subtab_class(subtab.id,tab.id)] = link_to t(subtab.label), subtab.url diff --git a/app/views/user_sessions/new.html.slim b/app/views/user_sessions/new.html.slim index b9bbd66c..69cf3cc5 100644 --- a/app/views/user_sessions/new.html.slim +++ b/app/views/user_sessions/new.html.slim @@ -4,7 +4,7 @@ a[href="http://www.amahi.org/" title="Powered by Amahi"] Amahi Server Login - flash.each do |name, msg| - div[class="message-#{name}"]= msg + div[class="alert alert-#{name}"]= msg = form_for @user_session do |f| p diff --git a/app/views/user_sessions/start.html.slim b/app/views/user_sessions/start.html.slim index ce030330..ed5b0378 100644 --- a/app/views/user_sessions/start.html.slim +++ b/app/views/user_sessions/start.html.slim @@ -4,7 +4,7 @@ a[href="http://www.amahi.org/" title="Powered by Amahi"] Amahi Server Login - flash.each do |name, msg| - div[class="message-#{name}"]= msg + div[class="alert alert-#{name}"]= msg = form_for @user, :url => initialize_system_path(@user.login) do |f| p diff --git a/config/application.rb b/config/application.rb index 2e9904c2..61909104 100644 --- a/config/application.rb +++ b/config/application.rb @@ -2,12 +2,7 @@ require 'rails/all' -if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) -end +Bundler.require(:default, Rails.env) module AmahiHDA class Application < Rails::Application @@ -55,7 +50,7 @@ class Application < Rails::Application config.active_record.whitelist_attributes = true # Enable the asset pipeline - config.assets.enabled = true + # config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.1' diff --git a/config/environments/development.rb b/config/environments/development.rb index b1be76e2..8315845e 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,8 +6,9 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false + config.eager_load = false # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true + #config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true @@ -19,18 +20,18 @@ # Print deprecation notices to the Rails logger config.active_support.deprecation = :log - # Only use best-standards-support built into browsers - config.action_dispatch.best_standards_support = :builtin + # # Only use best-standards-support built into browsers + # config.action_dispatch.best_standards_support = :builtin - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + # # Raise exception on mass assignment protection for Active Record models + # config.active_record.mass_assignment_sanitizer = :strict - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - config.active_record.auto_explain_threshold_in_seconds = 0.5 + # # Log the query plan for queries taking more than this (works + # # with SQLite, MySQL, and PostgreSQL) + # config.active_record.auto_explain_threshold_in_seconds = 0.5 - # Do not compress assets - config.assets.compress = false + # # Do not compress assets + # config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true diff --git a/config/environments/production.rb b/config/environments/production.rb index ff64c307..bb659de6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -4,6 +4,7 @@ # Code is not reloaded between requests config.cache_classes = true + config.eager_load = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true @@ -12,7 +13,7 @@ config.serve_static_assets = true # Compress JavaScripts and CSS - config.assets.compress = false + config.assets.js_compressor = :uglifier # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 4599370d..94f14b6f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -7,12 +7,13 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true + config.eager_load = false # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" # Log error messages when you accidentally call methods on nil - config.whiny_nils = true + # config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true @@ -30,7 +31,7 @@ config.action_mailer.delivery_method = :test # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + # config.active_record.mass_assignment_sanitizer = :strict # Print deprecation notices to the stderr config.active_support.deprecation = :stderr diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 29fd0621..344913c2 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -5,3 +5,4 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. AmahiHDA::Application.config.secret_token = '8e134f84fdc7df1d23c1c8c4bad7d807589cfb2f1099e838c0f4c7fb5c2d9d8edfae608899239afb41762528cd46aea3dd1d7afccbead5f844151eac2b72f21c' +AmahiHDA::Application.config.secret_key_base = '8e134f84fdc7df1d23c1c8c4bad7d807589cfb2f1099e838c0f4c7fb5c2d9d8edfae608899239afb41762528cd46aea3dd1d7afccbead5f844151eac2b72f21c' diff --git a/config/locales/en.yml b/config/locales/en.yml index 54433fd5..c66fe9c2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -39,6 +39,7 @@ # login log_in: Log In + logged_in_successfully: "Logged in successfully" not_a_valid_user_or_password: "Error: Incorrect username or password" first_time_admin_setup: "First admin setup. Please re-create your user password." remember_me: Remember me diff --git a/config/routes.rb b/config/routes.rb index 2cd5b16f..81993755 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,16 @@ - AmahiHDA::Application.routes.draw do themes_for_rails amahi_plugin_routes - match 'login' => 'user_sessions#new', :as => :login - match 'logout' => 'user_sessions#destroy', :as => :logout - match 'start' => 'user_sessions#start', :as => :start - match 'user_sessions/initialize_system' => 'user_sessions#initialize_system', :as => :initialize_system - + match 'login' => 'user_sessions#new', :as => :login, via: [:get] + match 'logout' => 'user_sessions#destroy', :as => :logout, via: [:get] + match 'start' => 'user_sessions#start', :as => :start, via: [:get] + match 'user_sessions/initialize_system' => 'user_sessions#initialize_system', :as => :initialize_system, via: [:get,:post] + get '/tab/debug'=>'debug#index' + post '/tab/debug'=>'debug#submit' + get '/tab/debug/system'=>'debug#system' + get '/tab/debug/logs'=>'debug#logs' resources :shares do collection do get 'disk_pooling' @@ -35,10 +37,10 @@ resources :user_sessions, :hosts, :aliases - match 'search/:action' => 'search', :as => :search + match 'search/:action' => 'search', :as => :search, via: [:get,:post] root :to => 'front#index' - match ':controller(/:action(/:id))(.:format)' + match ':controller(/:action(/:id))(.:format)', via: [:get] end diff --git a/doc/plugins.md b/doc/plugins.md index 5a2eb2ae..80032e6a 100644 --- a/doc/plugins.md +++ b/doc/plugins.md @@ -22,13 +22,23 @@ Each plugin has to have a file called `config/amahi_plugin.yml` with details of name: Foo Bar Tab # class to be mounted class: FooBar - # kind of plugin (so far we only support 'tab' plugins) kind: tab # url where it will be mounted in the platform url: /tab/foobar No two apps have may use the same class or url to be mounted. +In case you are adding plugin as a subtab under a tab(Fuzzbar) : + + # human readable name (no localization supported yet) + # for example, it may be used as the text of the tab or the page title, etc. + name: Foo Bar Sub Tab + # class to be mounted + class: FooBar + kind: subtab + # url where it will be mounted in the platform + url: /tab/fuzzbar/foobar + ## Adding Tabs and Subtabs To add visible tabs in a plugin, one has to do it programmatically at plugin initialization time with what in RoR is known as an initializer. @@ -37,10 +47,13 @@ Example for initialization for a plugin (e.g. plugin/foo_bar/config/initializers ```ruby # plugin initialization -- set up a tab by calling Tab.new: +#Checks for Existing tab with the same controller. +unless t = Tab.find("foobar") # - first argument to Tab.new is the controller that it will hooked up to # - second argument is a string, the label for the tab. This will support internationalization in the future # - third argument is the route it should be mounted on, example /tab/foobar -t = Tab.new("foobar", "FooBar", "/tab/apps") + t = Tab.new("foobar", "FooBar", "/tab/apps") +end # add any subtabs to this tab with what you need. # The params are # - controller @@ -53,6 +66,17 @@ t.add("expert", "Expert Settings", true) t.add("other", "Other Settings") ``` +To add a plugin as a subtab of an existing tab(Fuzzbar) : +```ruby +# plugin initialization -- set up a tab by calling Tab.new: +#Checks for Existing tab with the same controller. +unless t = Tab.find("fuzzbar") + t = Tab.new("fuzzbar", "FuzzBar", "/tab/Fuzzbar") +end +t.add("foobar", "Foobar") +``` + + ## Principles * One folder = One plugin. This is a must. To install an Amahi plugin manually, all there needs to be done is copy a single folder into the plugins/ directory and done. It's good for manual installation, it's good for automatic installation. diff --git a/lib/generators/plugin/plugin_generator.rb b/lib/generators/plugin/plugin_generator.rb index 99e820f6..76951aeb 100644 --- a/lib/generators/plugin/plugin_generator.rb +++ b/lib/generators/plugin/plugin_generator.rb @@ -110,8 +110,8 @@ class Engine < ::Rails::Engine # root of the plugin root :to => '#{plural_name}#index' # examples of controllers built in this generator. delete at will - match 'settings' => '#{plural_name}#settings' - match 'advanced' => '#{plural_name}#advanced' + match 'settings' => '#{plural_name}#settings',:via=> :all + match 'advanced' => '#{plural_name}#advanced',:via => :all end FILE end diff --git a/lib/partition_utils.rb b/lib/partition_utils.rb index 8739155e..219efc19 100644 --- a/lib/partition_utils.rb +++ b/lib/partition_utils.rb @@ -77,7 +77,7 @@ def disk_stats(path) # return total bytes, free bytes [blocks * bsize, bfree * bsize] rescue => e - RAILS_DEFAULT_LOGGER.error("******** disk stats error for #{path}: #{e.inspect}") + Rails.logger.error("******** disk stats error for #{path}: #{e.inspect}") [0, 0] end end diff --git a/lib/set_theme.rb b/lib/set_theme.rb index b55d4215..d44b4222 100644 --- a/lib/set_theme.rb +++ b/lib/set_theme.rb @@ -22,7 +22,7 @@ class << self def find begin - theme_setting = Setting.find_or_create_by_name(:name => 'theme', :value => self.default) + theme_setting = Setting.where(:name => 'theme').first_or_create path = theme_setting.value theme_path = init_file_exists?(path) ? path : self.default theme = init(theme_path) diff --git a/lib/tab.rb b/lib/tab.rb index eb8a2b3d..12da6c50 100644 --- a/lib/tab.rb +++ b/lib/tab.rb @@ -45,6 +45,41 @@ def advanced_subtabs subtabs end + # Return the Tab(if exists) with id:contoller. Otherwise creates a new Tab + def self.find_or_create(controller, label, url) + tabs = self.find(controller) + if tabs==nil + tabs = Tab.new(controller, label, url) + end + tabs + end + + #Returns Tab with id:controller + def self.find(controller) + tabs = [] + AmahiHDA::Application.config.tabs.each do |tab| + if tab.id==controller + tabs << tab + break + end + end + tabs.first + end + + #checks if tab has a subtab with id:controller + def self.ischild(controller,tab) + child = false + if tab.subtabs? + tab.subtabs.each do |subtab| + if(subtab.id == controller) + child = true + break + end + end + end + child + end + private # keep top-level tabs in an app variable, due to complex initialzation issues diff --git a/plugins/010-users/app/views/users/_auth.html.slim b/plugins/010-users/app/views/users/_auth.html.slim index e6e9470e..0eab136a 100644 --- a/plugins/010-users/app/views/users/_auth.html.slim +++ b/plugins/010-users/app/views/users/_auth.html.slim @@ -1,7 +1,7 @@ td.top label #{t('authentication')} td.top - = link_to_function content_tag('i', '', class: 'auth'), "$(this).parent().children('.pubkey-area').toggle('slow')", + = link_to content_tag('i', '', class: 'auth'), '#', :onclick=>"$(this).parent().children('.pubkey-area').toggle('slow')", :title => t('manage_your_public_key'), :class => 'control-action',:id=>"user-auth-control-action-#{user.id}" = theme_image_tag("ok.png", :class => 'ok', :style => 'display:none') @@ -15,4 +15,4 @@ td.top .control-group .controls = submit_tag t('update_key'), :class => 'btn' - = link_to_function t('cancel'), "$(this).parents('.pubkey-area').hide('slow')", :class => 'cancel-link' + = link_to t('cancel'), '#', :onclick=>"$(this).parents('.pubkey-area').hide('slow')", :class => 'cancel-link' diff --git a/plugins/010-users/app/views/users/_password.html.slim b/plugins/010-users/app/views/users/_password.html.slim index 90bd7b39..70230538 100644 --- a/plugins/010-users/app/views/users/_password.html.slim +++ b/plugins/010-users/app/views/users/_password.html.slim @@ -1,7 +1,7 @@ td.top label #{t('password')} td.top - = link_to_function content_tag('i', '', class: 'password'), "$(this).parent().find('.password-edit').toggle('slow')", + = link_to content_tag('i', '', class: 'password'),'#', :onclick=> "$(this).parent().find('.password-edit').toggle('slow')", :class => 'control-action',:id=>"user-password-control-action-#{user.id}" = form_for user, url: users_engine.update_password_user_path(user), remote: true, method: :put, html: { class: 'update-password update-form form-horizontal' } do |f| .password-edit[style="display:none"] @@ -15,5 +15,5 @@ td.top .controls = spinner = f.submit t('change'), :class => 'btn',:id=>"submit_password_#{user.id}" - = link_to_function t('cancel'), "$(this).parents('.password-edit').hide('slow').find('input[type=password]').val('')", :class => 'cancel-link' + = link_to t('cancel'), '#', :onclick=>"$(this).parents('.password-edit').hide('slow').find('input[type=password]').val('')", :class => 'cancel-link' .messages diff --git a/plugins/010-users/config/initializers/plugin_init.rb b/plugins/010-users/config/initializers/plugin_init.rb index c6fb72a1..adae4e22 100644 --- a/plugins/010-users/config/initializers/plugin_init.rb +++ b/plugins/010-users/config/initializers/plugin_init.rb @@ -1,4 +1,6 @@ +# plugin initialization t = Tab.new("users", "users", "/tab/users") +# add any subtabs with what you need. params are controller and the label t.add('index', "details") # disable settings for now # t.add('settings', "settings") diff --git a/plugins/010-users/config/routes.rb b/plugins/010-users/config/routes.rb index 61803152..ddc5179f 100644 --- a/plugins/010-users/config/routes.rb +++ b/plugins/010-users/config/routes.rb @@ -9,5 +9,5 @@ put 'update_pubkey' end end - match 'settings' => 'users#settings' + match 'settings' => 'users#settings' ,via: [:get,:post] end diff --git a/plugins/020-shares/app/views/shares/_permissions.html.slim b/plugins/020-shares/app/views/shares/_permissions.html.slim index cdb12b2d..1e581cce 100644 --- a/plugins/020-shares/app/views/shares/_permissions.html.slim +++ b/plugins/020-shares/app/views/shares/_permissions.html.slim @@ -3,7 +3,7 @@ .permissions = spinner = link_to content_tag('span', '', :class => 'tools'), clear_permissions_share_path(share), :remote => true, :method => 'put', - :confirm => t('this_will_clear_permissions_wide', :share => share.name), :class => 'clear-permissions remote-btn', + :class => 'clear-permissions remote-btn', :title => t('this_will_clear_permissions_wide', :share => share.name), - :data => { :success => t('permissions_cleared'), :error => t('permissions_clearning_error') } + :data => { :confirm => t('this_will_clear_permissions_wide', :share => share.name), :success => t('permissions_cleared'), :error => t('permissions_clearning_error') } span.messages diff --git a/plugins/020-shares/config/routes.rb b/plugins/020-shares/config/routes.rb index 719cbf46..5c15c5e8 100644 --- a/plugins/020-shares/config/routes.rb +++ b/plugins/020-shares/config/routes.rb @@ -2,6 +2,6 @@ # root of the plugin root :to => 'shares#index' # examples of controllers built in this generator. delete at will - match 'settings' => 'shares#settings' - match 'advanced' => 'shares#advanced' + match 'settings' => 'shares#settings', via: [:get,:post] + match 'advanced' => 'shares#advanced', via: [:get,:post] end diff --git a/plugins/030-disks/app/views/disks/index.html.slim b/plugins/030-disks/app/views/disks/index.html.slim index 4140f55d..2cda7b80 100644 --- a/plugins/030-disks/app/views/disks/index.html.slim +++ b/plugins/030-disks/app/views/disks/index.html.slim @@ -7,8 +7,8 @@ th = t 'temperature' |  ( - = link_to_function "F", '$("#disks-table .temperature").toggle()', class: 'temperature', style: 'display:none' - = link_to_function "C", '$("#disks-table .temperature").toggle()', class: 'temperature' + = link_to "F", '#', :onclick=> '$("#disks-table .temperature").toggle()', class: 'temperature', style: 'display:none' + = link_to "C", '#', :onclick=> '$("#disks-table .temperature").toggle()', class: 'temperature' | ) tbody - @disks.each do | disk | diff --git a/plugins/030-disks/config/routes.rb b/plugins/030-disks/config/routes.rb index bd6274a6..d439d6b8 100644 --- a/plugins/030-disks/config/routes.rb +++ b/plugins/030-disks/config/routes.rb @@ -2,5 +2,5 @@ # root of the plugin root :to => 'disks#index' # examples of controllers built in this generator. delete at will - match 'mounts' => 'disks#mounts' + match 'mounts' => 'disks#mounts', via: [:get,:post] end diff --git a/plugins/040-apps/app/controllers/apps_controller.rb b/plugins/040-apps/app/controllers/apps_controller.rb index 185f4eeb..3ad372c9 100644 --- a/plugins/040-apps/app/controllers/apps_controller.rb +++ b/plugins/040-apps/app/controllers/apps_controller.rb @@ -34,13 +34,13 @@ def installed def install identifier = params[:id] - @app = App.find_by_identifier identifier + @app = App.where(:identifier=>identifier).first App.install identifier unless @app end def install_progress identifier = params[:id] - @app = App.find_by_identifier identifier + @app = App.where(:identifier=>identifier).first if @app @app.reload @@ -56,13 +56,13 @@ def install_progress def uninstall identifier = params[:id] - @app = App.find_by_identifier identifier + @app = App.where(:identifier=>identifier).first @app.uninstall if @app end def uninstall_progress identifier = params[:id] - @app = App.find_by_identifier identifier + @app = App.where(:identifier=>identifier).first if @app @app.reload @progress = @app.install_status @@ -76,7 +76,7 @@ def uninstall_progress def toggle_in_dashboard identifier = params[:id] - app = App.find_by_identifier identifier + app = App.where(:identifier=>identifier).first if app.installed app.show_in_dashboard = ! app.show_in_dashboard app.save diff --git a/plugins/040-apps/app/controllers/webapp_alias_controller.rb b/plugins/040-apps/app/controllers/webapp_alias_controller.rb deleted file mode 100644 index 8f56be63..00000000 --- a/plugins/040-apps/app/controllers/webapp_alias_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -# Amahi Home Server -# Copyright (C) 2007-2013 Amahi -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License v3 -# (29 June 2007), as published in the COPYING file. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# file COPYING for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Amahi -# team at http://www.amahi.org/ under "Contact Us." - -class WebappAliasController < ApplicationController - before_filter :admin_required - - def new - @id = params[:id] - end - - def index - @wa = Webapp.find(params[:id]) - raise "Webapp with id=#{params[:id]} cannot be found" unless @wa - render :partial => "webapp/webapp_aliases", :locals => { :webapp => @wa } - end - - def create - @wa = Webapp.find(params[:id]) - raise "Webapp with id=#{params[:id]} cannot be found" unless @wa - @waa = WebappAlias.find_by_name(params[:name]) - if @waa - prev = @waa.webapp_id - @waa.webapp_id = @wa.id - @waa.save! - Webapp.find(prev).save - else - @waa = WebappAlias.create(:name => params[:name], :webapp_id => @wa.id) - end - render :partial => "webapp/webapp_aliases", :locals => { :webapp => @wa } - end - - def destroy - @waa = WebappAlias.find(params[:id]) rescue nil - @waa.destroy if @waa - @wa = Webapp.find(params[:webapp]) rescue nil - return unless @wa - render :partial => "webapp/webapp_aliases", :locals => { :webapp => @wa } - end -end diff --git a/plugins/040-apps/app/controllers/webapp_controller.rb b/plugins/040-apps/app/controllers/webapp_controller.rb deleted file mode 100644 index 75e74128..00000000 --- a/plugins/040-apps/app/controllers/webapp_controller.rb +++ /dev/null @@ -1,146 +0,0 @@ -# Amahi Home Server -# Copyright (C) 2007-2013 Amahi -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License v3 -# (29 June 2007), as published in the COPYING file. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# file COPYING for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Amahi -# team at http://www.amahi.org/ under "Contact Us." - -class WebappController < ApplicationController - before_filter :admin_required - - VALID_NAME = Regexp.new "^[A-Za-z][A-Za-z0-9\-]+$" - - def create - # FIXME - check check check! - name = params[:name].strip - path = params[:path].sub(/\/+$/, '') - path.gsub!(/\/+/, '/') - wa = Webapp.create(:name => name, :path => path) - @webapps = Webapp.find :all - render :partial => "index" - end - - def delete - # FIXME - check check check! - wa = Webapp.find params[:id] - wa.destroy - webapps = Webapp.find(:all) - render :partial => 'list', :locals => { :webapps => webapps } - end - - def new_name_check - n = params[:name] - if n.nil? or n.blank? - render :partial => 'name_bad' - return - end - if (not (valid_name?(n))) or (n.size > 32) - render :partial => 'name_bad' - return - end - n = n.strip - a = DnsAlias.find_by_alias(n) - if a.nil? - # no such alias, ok to create it - @name = n - render :partial => 'name_available' - else - render :partial => 'name_unavailable' - end - end - - def new_path_check - n = params[:path] - if n.nil? or n.blank? - render :partial => 'path_bad' - return - end - unless valid_path?(n) - render :partial => 'path_bad' - return - end - if File.exist? n - render :partial => 'path_exists' - else - render :partial => 'path_available' - end - end - - def update_name - id = params[:id] - wa = Webapp.find(id) - unless params[:value].blank? - name = params[:value] - wa.name = name - wa.save - wa.reload - end - name = wa.name - render :text => name - end - - def update_path - id = params[:id] - wa = Webapp.find(id) - unless params[:value].blank? - path = params[:value] - # check it exists! - if files_exist?(path) - wa.path = path - wa.save - wa.reload - else - # FIXME - report (somehow) why we did not - # make it! user must be confused!?! - # alternatively, create it! - raise PathDoesNotExist(path) - end - end - path = wa.path - render :text => path - end - - def toggle_login_required - begin - webapp = Webapp.find params[:id] - webapp.login_required = ! webapp.login_required - webapp.save - rescue - end - render :partial => 'login_required', :locals => { :webapp => webapp } - end - - -private - - def valid_name?(nm) - return false unless (nm =~ VALID_NAME) - true - end - - def valid_path?(path) - return false if path.size > 250 - return false unless path =~ /^\// - return false unless path =~ /^[A-Za-z0-9_\/-]+$/ - return false if path =~ /\/$/ - return false if path =~ /\/\/+/ - true - end - - def files_exist?(path) - return false unless File.exist?(path) - return false unless File.exist?(File.join(path, "html")) - return false unless File.exist?(File.join(path, "logs")) - true - end - -end diff --git a/plugins/040-apps/app/helpers/apps_helper.rb b/plugins/040-apps/app/helpers/apps_helper.rb index 99923bbb..c24a1b00 100644 --- a/plugins/040-apps/app/helpers/apps_helper.rb +++ b/plugins/040-apps/app/helpers/apps_helper.rb @@ -17,9 +17,9 @@ module AppsHelper def short_desc(app) - desc = app.description ? app.description.gsub(/<[^>]+>/, '') : t('no_description_supplied') - desc = truncate(strip_tags(desc), :length => 70, :omission => ' ...') if desc.length > 70 - desc.html_safe + return t('no_description_supplied') unless app.description + # truncate if too long + truncate(strip_tags(app.description), length: 90) end def name_with_warning(app) diff --git a/plugins/040-apps/app/views/apps/_is_installed.html.slim b/plugins/040-apps/app/views/apps/_is_installed.html.slim index 3c18a7bf..d5077c43 100644 --- a/plugins/040-apps/app/views/apps/_is_installed.html.slim +++ b/plugins/040-apps/app/views/apps/_is_installed.html.slim @@ -20,21 +20,20 @@ - if app.webapp div.app-url= link_to(app.full_url, app.full_url, :target => '_blank') + = render 'in_dashboard', :app => app - if app.plugin div.app-url= link_to(app.plugin.name, app.plugin.path, :target => '_blank') + = spinner - if app.theme div.app-url= link_to(t('manage_themes'), settings_engine.themes_path) - -- if app.webapp - = render 'in_dashboard', :app => app + = spinner br br br -= spinner span.progress - unless app.has_dependents? span.install-button diff --git a/plugins/040-apps/app/views/webapp/_body.html.erb b/plugins/040-apps/app/views/webapp/_body.html.erb deleted file mode 100644 index 26f897da..00000000 --- a/plugins/040-apps/app/views/webapp/_body.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%= render :partial => 'webapp/list', :locals => { :webapps => webapps } %> -
-
-<%= render :partial => 'webapp/new' %> diff --git a/plugins/040-apps/app/views/webapp/_index.html.erb b/plugins/040-apps/app/views/webapp/_index.html.erb deleted file mode 100644 index 1fee0cfe..00000000 --- a/plugins/040-apps/app/views/webapp/_index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -
- <%= render :partial => 'webapp/body', :locals => { :webapps => @webapps } %> -
diff --git a/plugins/040-apps/app/views/webapp/_list.html.erb b/plugins/040-apps/app/views/webapp/_list.html.erb deleted file mode 100644 index 35f59936..00000000 --- a/plugins/040-apps/app/views/webapp/_list.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -
-
- <% if webapps.size > 0 %> - - - - - - - - -
<%=t 'name' %><%=t 'url' %>
- <%= render :partial => 'webapp/webapp', :collection => webapps %> - <% else %> -
-
-

<%=t 'there_are_no_webapps' %>

-

Web apps are web-based applications hosted in your Amahi HDA.

-

Example of web apps are Wordpress, - MediaWiki, - Gallery, - Webmin and - PHPSysinfo.

-

There are a myriad of other apps that run under Linux.

-

You can install web apps in this panel by:

-

-

    -
  • Deciding what name you want to access the web app within your network (e.g. http://blog), and
  • -
  • Selecting where is the root directory of the app you want to run
  • -
-

-

The application code is expected to be present (before or after configuring the app) in the root directory.

-

You can install it there as an archive from source (tar/zip), or as a package from existing applications in the base OS.

-

Currently supported are applications based on LAMP (PHP), Python, static pages and others.

-

We have a small gallery of apps that other Amahi - developers and users have tried and tested.

-
-
- <% end %> -
-
diff --git a/plugins/040-apps/app/views/webapp/_login_required.html.erb b/plugins/040-apps/app/views/webapp/_login_required.html.erb deleted file mode 100644 index fda3856c..00000000 --- a/plugins/040-apps/app/views/webapp/_login_required.html.erb +++ /dev/null @@ -1,12 +0,0 @@ -<% id = "login_required_#{webapp.id}" %> - -<%= checkbox_to_remote webapp.login_required, - :url => { :controller => 'webapp', :action => 'toggle_login_required', :id => webapp }, - :submit => id, - :before => "Element.show('spinner-access-#{webapp.id}')", - :success => "Element.hide('spinner-access-#{webapp.id}')", - :update => id -%> -  <%=t 'require_login' %>     » <%= theme_image_tag "more" %> -<%= spinner "access-#{webapp.id}" %> - - diff --git a/plugins/040-apps/app/views/webapp/_name_available.rjs b/plugins/040-apps/app/views/webapp/_name_available.rjs deleted file mode 100644 index f280ce64..00000000 --- a/plugins/040-apps/app/views/webapp/_name_available.rjs +++ /dev/null @@ -1,5 +0,0 @@ -page[:name_messages].replace_html theme_image_tag("ok") + " " + t('name_looks_good') -page.show 'name_messages' -page[:path].disabled = false -# FIXME - this path needs parametrization -page[:path].value = "/var/hda/web-apps/" + @name diff --git a/plugins/040-apps/app/views/webapp/_name_bad.rjs b/plugins/040-apps/app/views/webapp/_name_bad.rjs deleted file mode 100644 index 61bebc60..00000000 --- a/plugins/040-apps/app/views/webapp/_name_bad.rjs +++ /dev/null @@ -1,4 +0,0 @@ -page[:name_messages].replace_html theme_image_tag("stop") + " " + t('name_is_not_valid') -page.show 'name_messages' -page[:path].disabled = true -page[:webapp_create_button].disabled = true diff --git a/plugins/040-apps/app/views/webapp/_name_unavailable.rjs b/plugins/040-apps/app/views/webapp/_name_unavailable.rjs deleted file mode 100644 index 6735e220..00000000 --- a/plugins/040-apps/app/views/webapp/_name_unavailable.rjs +++ /dev/null @@ -1,4 +0,0 @@ -page[:name_messages].replace_html theme_image_tag("stop") + " " + t('name_is_taken_already') -page.show 'name_messages' -page[:path].disabled = true -page[:webapp_create_button].disabled = true diff --git a/plugins/040-apps/app/views/webapp/_new.html.erb b/plugins/040-apps/app/views/webapp/_new.html.erb deleted file mode 100644 index 750ab918..00000000 --- a/plugins/040-apps/app/views/webapp/_new.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -<%= button_to_function " #{t('new_web_app')} » ", update_page { |page| - page.hide 'new-webapp-to-step1' - page[:name].value = "" - page[:path].value = "" - page[:webapp_create_button].disabled = true - page.select(".messages").each do |item| - page.send 'replace_html', item, "" - end - page.show 'new-webapp-step1' - page[:name].focus - }, :id => "new-webapp-to-step1" %> - -
-
-
- -
- <%= error_messages_for :setup %> -
- - <% form_for :webapp, :id => "webapp-new", :url => { :controller => 'webapp', :action => 'create' } do |f| -%> - - - - <% end %> -
-
-
diff --git a/plugins/040-apps/app/views/webapp/_path_available.rjs b/plugins/040-apps/app/views/webapp/_path_available.rjs deleted file mode 100644 index 2207150f..00000000 --- a/plugins/040-apps/app/views/webapp/_path_available.rjs +++ /dev/null @@ -1,3 +0,0 @@ -page[:path_messages].replace_html theme_image_tag("ok") + " " + t('path_looks_good') -page.show 'path_messages' -page[:webapp_create_button].disabled = false diff --git a/plugins/040-apps/app/views/webapp/_path_bad.rjs b/plugins/040-apps/app/views/webapp/_path_bad.rjs deleted file mode 100644 index 7dbc8c4c..00000000 --- a/plugins/040-apps/app/views/webapp/_path_bad.rjs +++ /dev/null @@ -1,3 +0,0 @@ -page[:path_messages].replace_html theme_image_tag("stop") + " " + t('this_path_is_not_valid') -page.show 'path_messages' -page[:webapp_create_button].disabled = true diff --git a/plugins/040-apps/app/views/webapp/_path_exists.rjs b/plugins/040-apps/app/views/webapp/_path_exists.rjs deleted file mode 100644 index 9602a90a..00000000 --- a/plugins/040-apps/app/views/webapp/_path_exists.rjs +++ /dev/null @@ -1,3 +0,0 @@ -page[:path_messages].replace_html theme_image_tag("warning") + " " + t('this_path_exists_already') -page.show 'path_messages' -page[:webapp_create_button].disabled = false diff --git a/plugins/040-apps/app/views/webapp/_step1.rhtml b/plugins/040-apps/app/views/webapp/_step1.rhtml deleted file mode 100644 index df728575..00000000 --- a/plugins/040-apps/app/views/webapp/_step1.rhtml +++ /dev/null @@ -1,59 +0,0 @@ - - - -
-
-  <%=t 'create_a_new_webapp' %>   -
- - - - - - - - - - - - - - - - - - - -
<%= text_field_tag :name, "", :size => 16, :maxlength => 20 %>» <%= theme_image_tag "more" %>
<%= text_field_tag :path, "", :size => 38, :maxlength => 128, :disabled => true %>/html
  
  - <%= link_to_function t('cancel'), update_page { |page| - page.hide 'new-webapp-step1' - page.show 'new-webapp-to-step1' - page[:name].value = "" - page[:path].value = "" - page.select(".messages").each do |item| - page.send 'replace_html', item, "" - end - page[:path].disabled = true - page[:webapp_create_button].disabled = true - } %> -    - <%= submit_to_remote "create_webapp", " #{t('create')} » ", - :url => { :controller => 'webapp', :action => 'create' }, - :html => { :id => "webapp_create_button", :disabled => true }, - :failure => "alert('HTTP Error ' + request.status + '!')", - :update => { :success => "webapps", :failure => "create_webapp_error_msgs" } %> -
-
-
-
- - - -<%= observe_field 'name', :frequency => 0.5, - :url => { :controller => 'webapp', :action => 'new_name_check' }, - :with => "'name=' + encodeURIComponent(value)" %> -<%= observe_field 'path', :frequency => 0.5, - :url => { :controller => 'webapp', :action => 'new_path_check' }, - :with => "'path=' + encodeURIComponent(value)" %> - -
diff --git a/plugins/040-apps/app/views/webapp/_webapp.html.erb b/plugins/040-apps/app/views/webapp/_webapp.html.erb deleted file mode 100644 index 3632d44b..00000000 --- a/plugins/040-apps/app/views/webapp/_webapp.html.erb +++ /dev/null @@ -1,120 +0,0 @@ -<% - delete_icon = theme_image_tag("delete", :title => t('delete_web_app')) - webapp = webapp - uid = webapp.id.to_s - return if webapp.nil? - toggler = update_page { |page| - row = "webapp_row_" + uid.to_s - info = "webapp_info_" + uid.to_s - page.toggle info - page[row].toggle_class_name "settings-row-open" - } -%> - - - - - -
- <%= link_to_function(h(webapp.name), '') %> - - http://<%= h webapp.name %> -
- - diff --git a/plugins/040-apps/app/views/webapp/_webapp_aliases.html.erb b/plugins/040-apps/app/views/webapp/_webapp_aliases.html.erb deleted file mode 100644 index 8d434f88..00000000 --- a/plugins/040-apps/app/views/webapp/_webapp_aliases.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<% uid = webapp.id.to_s %> - - -<%= link_to_remote t('new_alias'), - :update => "webapp_aliases_new_#{uid}", - :before => spinner_show(uid), - :success => spinner_hide(uid), - :url => { :controller => 'webapp_alias', :action => 'new', :id => uid } %> -    » <%= theme_image_tag "more" %> - -<%= webapp.webapp_aliases.count > 0 ? "

" : "" %> - <%= webapp.webapp_aliases.map do |a| - del = link_to_remote("x", :update => "webapp_aliases_#{uid}", :before => spinner_show(uid), :success => spinner_hide(uid), :url => { :controller => 'webapp_alias', :action => 'destroy', :id => a.id, :webapp => uid }); - link = link_to("http://#{a}", "http://#{a}", { :target => '_blank'}) - "[#{del}] #{link}" - end.join("
") -%> -
diff --git a/plugins/040-apps/app/views/webapp_alias/new.js.erb b/plugins/040-apps/app/views/webapp_alias/new.js.erb deleted file mode 100644 index a6db9125..00000000 --- a/plugins/040-apps/app/views/webapp_alias/new.js.erb +++ /dev/null @@ -1,16 +0,0 @@ -
-<%= text_field_tag :wa_alias, "", :size => 16, :maxlenth => 80 %> -<%= submit_to_remote "add_alias", " #{t 'create'} ", - :url => { :controller => 'webapp_alias', :action => 'create', :id => @id }, - :with => "'name=' + escape($('wa_alias').value)", - :before => spinner_show(@id), - :success => spinner_hide(@id), - :update => { :success => "webapp_aliases_#{@id}"} %> -  <%= link_to_remote t('cancel'), - :url => { :controller => 'webapp_alias', :action => 'index', :id => @id }, - :before => spinner_show(@id), - :success => spinner_hide(@id), - :update => { :success => "webapp_aliases_#{@id}"} - %> -
-
diff --git a/plugins/040-apps/config/routes.rb b/plugins/040-apps/config/routes.rb index a1e27dcd..1692b562 100644 --- a/plugins/040-apps/config/routes.rb +++ b/plugins/040-apps/config/routes.rb @@ -2,14 +2,13 @@ # root of the plugin root :to => 'apps#index' # examples of controllers built in this generator. delete at will - match 'installed' => 'apps#installed' - match 'webapps' => 'apps#advanced' + match 'installed' => 'apps#installed', via: [:get,:post] post 'install/:id' => 'apps#install', as: 'install' - get 'install_progress/:id' => 'apps#install_progress', as: 'install_progress' + match 'install_progress/:id' => 'apps#install_progress', as: 'install_progress', via: [:get,:post] post 'uninstall/:id' => 'apps#uninstall', as: 'uninstall' - get 'uninstall_progress/:id' => 'apps#uninstall_progress', as: 'uninstall_progress' + match 'uninstall_progress/:id' => 'apps#uninstall_progress', as: 'uninstall_progress', via: [:get,:post] put 'toggle_in_dashboard/:id' => 'apps#toggle_in_dashboard', as: 'toggle_in_dashboard' end diff --git a/plugins/080-settings/app/assets/javascripts/settings.js.coffee b/plugins/080-settings/app/assets/javascripts/settings.js.coffee index 7ab72470..c3aa01e3 100644 --- a/plugins/080-settings/app/assets/javascripts/settings.js.coffee +++ b/plugins/080-settings/app/assets/javascripts/settings.js.coffee @@ -20,3 +20,11 @@ $ -> $ -> $(".preftab").on "ajax:success", "#locale", -> window.location.reload(true) + +$(document).on "click", ".remote-check", (event)-> + checkbox = $(this) + checkbox.prop("checked",!checkbox.prop("checked")) + true + +$(document).on "ajax:complete",".remote-check", -> + $(this).prop("checked",!$(this).prop("checked")) diff --git a/plugins/080-settings/app/controllers/settings_controller.rb b/plugins/080-settings/app/controllers/settings_controller.rb index 1965d75e..588e50fc 100644 --- a/plugins/080-settings/app/controllers/settings_controller.rb +++ b/plugins/080-settings/app/controllers/settings_controller.rb @@ -21,8 +21,8 @@ class SettingsController < ApplicationController def index @page_title = t 'settings' @available_locales = locales_implemented - @advanced_settings = Setting.find_by_name('advanced') - @guest = Setting.find_by_name("guest-dashboard") + @advanced_settings = Setting.where(:name=>'advanced').first + @guest = Setting.where(:name=>"guest-dashboard").first @version = Platform.platform_versions end @@ -120,7 +120,7 @@ def themes end def activate_theme - s = Setting.find_by_name "theme" + s = Setting.where(:name=> "theme").first s.value = params[:id] s.save! # redirect rather than render, so that it re-displays with the new theme diff --git a/plugins/080-settings/app/views/settings/index.html.slim b/plugins/080-settings/app/views/settings/index.html.slim index d580df20..4d997410 100644 --- a/plugins/080-settings/app/views/settings/index.html.slim +++ b/plugins/080-settings/app/views/settings/index.html.slim @@ -42,14 +42,14 @@ div.settings-fields.settings-wrap method: :post, class: 'btn-system', id: 'btn-poweroff', - confirm: t('this_will_power_off') + data: {confirm: t('this_will_power_off')} = link_to t('reboot'), settings_engine.reboot_path, remote: true, method: :post, class: 'btn-system', id: 'btn-reboot', - confirm: t('this_will_reboot') + data: {confirm: t('this_will_reboot')} div.settings-fields#info-table table tr diff --git a/plugins/080-settings/config/routes.rb b/plugins/080-settings/config/routes.rb index d11bf823..99149137 100644 --- a/plugins/080-settings/config/routes.rb +++ b/plugins/080-settings/config/routes.rb @@ -1,18 +1,20 @@ Settings::Engine.routes.draw do # root of the plugin root :to => 'settings#index' - match 'change_language' => 'settings#change_language' - match 'toggle_setting' => 'settings#toggle_setting' - match 'reboot' => 'settings#reboot' - match 'poweroff' => 'settings#poweroff' - match 'servers' => 'settings#servers' - match 'servers/:id/refresh' => 'settings#refresh', as: 'refresh' - match 'servers/:id/start' => 'settings#start', as: 'start' - match 'servers/:id/stop' => 'settings#stop', as: 'stop' - match 'servers/:id/restart' => 'settings#restart', as: 'restart' - match 'servers/:id/toggle_monitored' => 'settings#toggle_monitored', as: 'toggle_monitored' - match 'servers/:id/toggle_start_at_boot' => 'settings#toggle_start_at_boot', as: 'toggle_start_at_boot' - match 'refresh' => 'settings#refresh' - match 'themes' => 'settings#themes' - match 'activate_theme' => 'settings#activate_theme' + match 'change_language' => 'settings#change_language', via: [:get,:post] + match 'toggle_setting' => 'settings#toggle_setting', via: [:get,:post] + match 'reboot' => 'settings#reboot', via: [:get,:post] + match 'poweroff' => 'settings#poweroff', via: [:get,:post] + match 'servers' => 'settings#servers', via: [:get,:post] + match 'servers/:id/refresh' => 'settings#refresh', as: 'refresh', via: [:get,:post] + match 'servers/:id/start' => 'settings#start', as: 'start', via: [:get,:post] + match 'servers/:id/stop' => 'settings#stop', as: 'stop', via: [:get,:post] + match 'servers/:id/restart' => 'settings#restart', as: 'restart', via: [:get,:post] + match 'servers/:id/toggle_monitored' => 'settings#toggle_monitored', as: 'toggle_monitored', via: [:get,:post] + match 'servers/:id/toggle_start_at_boot' => 'settings#toggle_start_at_boot', as: 'toggle_start_at_boot', via: [:get,:post] + match 'refresh' => 'settings#refresh', via: [:get,:post] + match 'themes' => 'settings#themes', via: [:get,:post] + match 'activate_theme' => 'settings#activate_theme', via: [:get,:post] + + put 'revoke_app' => 'settings#revoke_app', as: 'revoke_app' end diff --git a/script/install-app b/script/install-app index 5a12afff..603166f4 100755 --- a/script/install-app +++ b/script/install-app @@ -102,7 +102,7 @@ def main(app_id, install) exit 1 end begin - app = install ? App.new(app_id) : App.find_by_identifier(app_id) + app = install ? App.new(app_id) : App.where(:identifier=>app_id).first raise "Error: cannot find #{app_id} to #{install ? "install" : "uninstall"}!" unless app install_or_uninstall install, app_id, app rescue => e diff --git a/spec/features/admin_creation_spec.rb b/spec/features/admin_creation_spec.rb index f23f5800..9a31c050 100644 --- a/spec/features/admin_creation_spec.rb +++ b/spec/features/admin_creation_spec.rb @@ -8,7 +8,7 @@ end scenario "first login for admin should see the setup page and setup first admin" do - (s = Setting.find_by_name('initialized')) && s.destroy + (s = Setting.where(:name=>'initialized').first) && s.destroy username = "newuser" User.stub(:system_find_name_by_username) { ["New User", 1000, username] } visit start_path @@ -17,8 +17,8 @@ fill_in "password", :with => "secret" fill_in "password_confirmation", :with => "secret" click_button "Create" - user = User.find_by_login username - user.admin.should be_true + user = User.where(:login => username).first + user.admin.should be_truthy end end diff --git a/spec/features/front_page_spec.rb b/spec/features/front_page_spec.rb index 59dc45a2..935d5268 100644 --- a/spec/features/front_page_spec.rb +++ b/spec/features/front_page_spec.rb @@ -7,7 +7,7 @@ end scenario "should be the dashboard if \"guest dashboard\" is enabled" do - setting = Setting.find_by_name("guest-dashboard") + setting = Setting.where(:name=>"guest-dashboard").first setting.value = "1" setting.save visit root_path diff --git a/spec/features/network_spec.rb b/spec/features/network_spec.rb index 4c1eaf25..80b810cd 100644 --- a/spec/features/network_spec.rb +++ b/spec/features/network_spec.rb @@ -31,6 +31,5 @@ wait_for_ajax page.should have_content("testdns") page.should have_content("192.168.1.10") - page.save_screenshot("checking.png") end end diff --git a/spec/features/user_create_spec.rb b/spec/features/user_create_spec.rb index 84e12b5c..9f9622b8 100644 --- a/spec/features/user_create_spec.rb +++ b/spec/features/user_create_spec.rb @@ -65,7 +65,7 @@ fill_in "user_password", :with => "secret" click_button "user_create_button" wait_for_ajax - page.should have_content 'is too short (minimum is 4 characters)' + page.should have_content "doesn't match Password" end scenario 'when password doesnt match' do visit users_engine.users_path @@ -76,7 +76,8 @@ fill_in "user_password_confirmation", :with => "notsecret" click_button "user_create_button" wait_for_ajax - page.should have_content "doesn't match confirmation" + page.save_screenshot('image1.jpg') + page.should have_content "doesn't match Password" end end end