diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-12-14 10:47:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-14 10:47:50 +0100 |
commit | 10ae35e46bd3deeb5a4d974b31ca606108bc2f50 (patch) | |
tree | 42752db13e54edc71bbf89b6a47e19580c71faa3 /server/sonar-web/src/main/webapp | |
parent | 90a1e2480844aa318112e22d66aaef1bb445b088 (diff) | |
download | sonarqube-10ae35e46bd3deeb5a4d974b31ca606108bc2f50.tar.gz sonarqube-10ae35e46bd3deeb5a4d974b31ca606108bc2f50.zip |
SONAR-8535 SONAR-7304 sanitize WS api/server/*
- SONAR-8535 drop api/server/index
- SONAR-8535 drop api/server/setup
- SONAR-7304 refactor api/server/version in Java
Signed-off-by: Simon Brandhof <simon.brandhof@sonarsource.com>
Diffstat (limited to 'server/sonar-web/src/main/webapp')
3 files changed, 0 insertions, 242 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb deleted file mode 100644 index d1b89828235..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb +++ /dev/null @@ -1,119 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2016 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# SonarQube 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 GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -class Api::ServerController < Api::ApiController - - skip_before_filter :check_authentication - - # prevent HTTP proxies from caching server status - before_filter :set_cache_buster, :only => 'index' - - # execute database setup - skip_before_filter :check_database_version, :setup - - def version - render :text => Java::OrgSonarServerPlatform::Platform.getServer().getVersion() - end - - def index - hash={:id => Java::OrgSonarServerPlatform::Platform.getServer().getId(), :version => Java::OrgSonarServerPlatform::Platform.getServer().getVersion()} - complete_with_status(hash) - respond_to do |format| - format.json{ render :json => jsonp(hash) } - format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'server') } - format.text { render :text => text_not_supported} - end - end - - def setup - verify_post_request - manager=DatabaseMigrationManager.instance - begin - # Ask the DB migration manager to start the migration - # => No need to check for authorizations (actually everybody can run the upgrade) - # nor concurrent calls (this is handled directly by DatabaseMigrationManager) - manager.start_migration - - operational=manager.is_sonar_access_allowed? - current_status = operational ? "ok" : "ko" - hash={ - # deprecated fields - :status => current_status, - :migration_status => manager.status, - - # correct fields - :operational => operational, - :state => manager.status - } - hash[:message]=manager.message if manager.message - hash[:startedAt]=manager.migration_start_time if manager.migration_start_time - - respond_to do |format| - format.json{ render :json => jsonp(hash) } - format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'setup') } - format.text { render :text => hash[:status] } - end - rescue => e - hash={ - # deprecated fields - :status => 'ko', - :msg => e.message, - - # correct fields - :message => e.message, - :state => manager.status - } - respond_to do |format| - format.json{ render :json => jsonp(hash) } - format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'setup') } - format.text { render :text => hash[:status] } - end - end - end - - private - - def server_properties_to_json(properties) - hash={} - properties.each do |prop| - hash[prop[0].to_s]=prop[1].to_s - end - hash - end - - def complete_with_status(hash) - if DatabaseMigrationManager.instance.is_sonar_access_allowed? - hash[:status]='UP' - elsif DatabaseMigrationManager.instance.migration_running? - hash[:status]='MIGRATION_RUNNING' - elsif DatabaseMigrationManager.instance.requires_migration? - hash[:status]='SETUP' - else - # migration failed or not connected to the database - hash[:status]='DOWN' - hash[:status_msg]=DatabaseMigrationManager.instance.message - end - end - - def set_cache_buster - response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" - response.headers["Pragma"] = "no-cache" - response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" - end -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb deleted file mode 100644 index 139da4a8ca2..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/database_migration_manager.rb +++ /dev/null @@ -1,122 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2016 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# SonarQube 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 GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -# -# Class that centralizes the management the DB migration -# - -require 'singleton' -require 'thread' - -class DatabaseMigrationManager - - # mixin the singleton module to ensure we have only one instance of the class - # it will be accessible with "DatabaseMigrationManager.instance" - include Singleton - - # the status of the migration - @status - MIGRATION_NEEDED = "MIGRATION_NEEDED" - MIGRATION_RUNNING = "MIGRATION_RUNNING" - MIGRATION_FAILED = "MIGRATION_FAILED" - MIGRATION_SUCCEEDED = "MIGRATION_SUCCEEDED" - NO_MIGRATION = "NO_MIGRATION" - - # the corresponding message that can be given to the user - @message - - # the time when the migration was started - @start_time - - def initialize - if !ActiveRecord::Base.connected? - @status = MIGRATION_FAILED - @message = "Not connected to database." - elsif DatabaseVersion.uptodate? - @status = NO_MIGRATION - @message = "Database is up-to-date, no migration needed." - else - if DatabaseVersion.production? - @status = MIGRATION_NEEDED - @message = "Migration required." - else - @status = MIGRATION_FAILED - @message = "Upgrade is not supported. Please use a <a href=\"http://redirect.sonarsource.com/doc/requirements.html\">production-ready database</a>." - end - end - end - - def message - @message - end - - def status - @status - end - - def requires_migration? - @status==MIGRATION_NEEDED - end - - def migration_running? - @status==MIGRATION_RUNNING - end - - def migration_failed? - @status==MIGRATION_FAILED - end - - def is_sonar_access_allowed? - @status==NO_MIGRATION || @status==MIGRATION_SUCCEEDED - end - - def migration_start_time - @start_time - end - - def start_migration - # Use an exclusive block of code to ensure that only 1 thread will be able to proceed with the migration - requires_migration = false - Thread.exclusive do - requires_migration = requires_migration? - end - - if requires_migration - Thread.new do - begin - @status = MIGRATION_RUNNING - @message = "Database migration is running" - Thread.current[:name] = "Database Upgrade" - @start_time = Time.now - - DatabaseVersion.upgrade_and_start - - @status = MIGRATION_SUCCEEDED - @message = "Migration succeeded." - rescue Exception => e - @status = MIGRATION_FAILED - @message = "Migration failed: " + Api::Utils.exception_message(e) + ".<br/> Please check logs." - Api::Utils.java_facade.logError("Fail to upgrade database\n#{Api::Utils.exception_message(e, :backtrace => true)}") - end - end - end - end - -end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb b/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb index 2931db12590..e51f89c25d8 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/config/routes.rb @@ -8,7 +8,6 @@ ActionController::Routing::Routes.draw do |map| map.connect 'api', :controller => 'api/java_ws', :action => 'redirect_to_ws_listing' - map.connect 'api/server/:action', :controller => 'api/server' map.connect 'api/resoures', :controller => 'api/resources', :action => 'index' map.resources 'properties', :path_prefix => 'api', :controller => 'api/properties', :requirements => { :id => /.*/ } |