From f5eb5fdd5e6d8bcf3ad52749e99a378e411ff8ad Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 12 Feb 2015 20:30:50 -0800 Subject: Add simple_encrypt gem --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 462c932584d..897ad547c34 100644 --- a/Gemfile +++ b/Gemfile @@ -200,6 +200,7 @@ gem 'nprogress-rails' gem 'request_store' gem "virtus" gem 'addressable' +gem 'simple_encrypt' group :development do gem 'brakeman', require: false diff --git a/Gemfile.lock b/Gemfile.lock index cca8f59ac28..eb8d607c5fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -551,6 +551,7 @@ GEM json redis (>= 3.0.6) redis-namespace (>= 1.3.1) + simple_encrypt (0.0.1) simple_oauth (0.1.9) simplecov (0.9.0) docile (~> 1.1.0) @@ -774,6 +775,7 @@ DEPENDENCIES settingslogic shoulda-matchers (~> 2.7.0) sidekiq (~> 3.3) + simple_encrypt simplecov sinatra six -- cgit v1.2.1 From 345fd545bf6d5f161686a09c4583a1e7488fd9c6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 12 Feb 2015 20:31:55 -0800 Subject: Add version check badge to admin area --- app/helpers/version_check_helper.rb | 5 +++++ app/views/admin/dashboard/index.html.haml | 6 +++++- lib/version_check.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/helpers/version_check_helper.rb create mode 100644 lib/version_check.rb diff --git a/app/helpers/version_check_helper.rb b/app/helpers/version_check_helper.rb new file mode 100644 index 00000000000..63d8eaeb2bd --- /dev/null +++ b/app/helpers/version_check_helper.rb @@ -0,0 +1,5 @@ +module VersionCheckHelper + def version_status_badge + image_tag VersionCheck.new.url + end +end diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index d1c586328a2..6b4ff4b330d 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -56,7 +56,11 @@ %span.light.pull-right = boolean_to_icon Gitlab.config.omniauth.enabled .col-md-4 - %h4 Components + %h4 + Components + .pull-right + = version_status_badge + %hr %p GitLab diff --git a/lib/version_check.rb b/lib/version_check.rb new file mode 100644 index 00000000000..ada5e0db7a9 --- /dev/null +++ b/lib/version_check.rb @@ -0,0 +1,30 @@ +# This class is used to encrypt GitLab version and URL +# with public key when we send it to version.gitlab.com to +# check if it is a new version for update +class VersionCheck + include SimpleEncrypt + + def public_key + public_key_file = Rails.root.join('safe', 'public.pem').to_s + File.read(public_key_file) + end + + def data + { + version: Gitlab::VERSION, + url: Gitlab.config.gitlab.url + } + end + + def encrypt(string) + encrypt_with_public_key(string, public_key) + end + + def url + "#{host}?gitlab_info=#{encrypt(data.to_json)}" + end + + def host + 'http://localhost:9090/check.png' + end +end -- cgit v1.2.1 From deb384a73bf92444ba5e64d3147409faca8b8d7a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 21:48:02 -0800 Subject: Prevent crash if file does not exists --- app/helpers/version_check_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/helpers/version_check_helper.rb b/app/helpers/version_check_helper.rb index 63d8eaeb2bd..df0e25b9f6e 100644 --- a/app/helpers/version_check_helper.rb +++ b/app/helpers/version_check_helper.rb @@ -1,5 +1,7 @@ module VersionCheckHelper def version_status_badge - image_tag VersionCheck.new.url + if File.exists?(Rails.root.join('safe', 'public.pem')) + image_tag VersionCheck.new.url + end end end -- cgit v1.2.1 From 73179685b0517dcdebe696b5987b47822b9bf6ed Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 9 Mar 2015 21:03:24 -0700 Subject: Add version check to help page too --- app/views/help/index.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/help/index.html.haml b/app/views/help/index.html.haml index af39dfeac5b..e2276260189 100644 --- a/app/views/help/index.html.haml +++ b/app/views/help/index.html.haml @@ -3,6 +3,7 @@ GitLab %span= Gitlab::VERSION %small= Gitlab::REVISION + = version_status_badge %p.slead GitLab is open source software to collaborate on code. %br -- cgit v1.2.1 From 100d750bc5ec4c6c5be11eb6f4100fe38b4ddee7 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 10 Mar 2015 12:51:46 -0700 Subject: Add feature to disable version check --- app/controllers/admin/application_settings_controller.rb | 3 ++- app/views/admin/application_settings/_form.html.haml | 6 ++++++ app/views/admin/dashboard/index.html.haml | 5 +++-- app/views/help/index.html.haml | 3 ++- .../20150310194358_add_version_check_to_application_settings.rb | 5 +++++ db/schema.rb | 3 ++- 6 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20150310194358_add_version_check_to_application_settings.rb diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 2b0c500e97a..5973af71267 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -28,7 +28,8 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController :gravatar_enabled, :twitter_sharing_enabled, :sign_in_text, - :home_page_url + :home_page_url, + :version_check_enabled ) end end diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index ac64d26f9aa..cab5688a499 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -24,6 +24,12 @@ .col-sm-10 = f.check_box :twitter_sharing_enabled, class: 'checkbox form-control', :'aria-describedby' => 'twitter_help_block' %span.help-block#twitter_help_block Show users a button to share their newly created public or internal projects on twitter + .form-group + .col-sm-offset-2.col-sm-10 + .checkbox + = f.label :version_check_enabled do + = f.check_box :version_check_enabled + Version check enabled %fieldset %legend Misc .form-group diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index 6b4ff4b330d..3732ff847b9 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -58,8 +58,9 @@ .col-md-4 %h4 Components - .pull-right - = version_status_badge + - if current_application_settings.version_check_enabled + .pull-right + = version_status_badge %hr %p diff --git a/app/views/help/index.html.haml b/app/views/help/index.html.haml index e2276260189..bf4b7234b21 100644 --- a/app/views/help/index.html.haml +++ b/app/views/help/index.html.haml @@ -3,7 +3,8 @@ GitLab %span= Gitlab::VERSION %small= Gitlab::REVISION - = version_status_badge + - if current_application_settings.version_check_enabled + = version_status_badge %p.slead GitLab is open source software to collaborate on code. %br diff --git a/db/migrate/20150310194358_add_version_check_to_application_settings.rb b/db/migrate/20150310194358_add_version_check_to_application_settings.rb new file mode 100644 index 00000000000..e9d42c1e749 --- /dev/null +++ b/db/migrate/20150310194358_add_version_check_to_application_settings.rb @@ -0,0 +1,5 @@ +class AddVersionCheckToApplicationSettings < ActiveRecord::Migration + def change + add_column :application_settings, :version_check_enabled, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index a686bb4b3cd..d63e1bc17a9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150225065047) do +ActiveRecord::Schema.define(version: 20150310194358) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -27,6 +27,7 @@ ActiveRecord::Schema.define(version: 20150225065047) do t.string "home_page_url" t.integer "default_branch_protection", default: 2 t.boolean "twitter_sharing_enabled", default: true + t.boolean "version_check_enabled", default: true end create_table "broadcast_messages", force: true do |t| -- cgit v1.2.1 From f38ce01bc3b5a894d527550ca6a782567dfd19f9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 8 May 2015 15:14:56 +0300 Subject: Remove encryption Signed-off-by: Dmitriy Zaporozhets --- Gemfile | 1 - Gemfile.lock | 2 -- app/helpers/version_check_helper.rb | 4 +--- lib/version_check.rb | 24 ++++++------------------ 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index 897ad547c34..462c932584d 100644 --- a/Gemfile +++ b/Gemfile @@ -200,7 +200,6 @@ gem 'nprogress-rails' gem 'request_store' gem "virtus" gem 'addressable' -gem 'simple_encrypt' group :development do gem 'brakeman', require: false diff --git a/Gemfile.lock b/Gemfile.lock index eb8d607c5fc..cca8f59ac28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -551,7 +551,6 @@ GEM json redis (>= 3.0.6) redis-namespace (>= 1.3.1) - simple_encrypt (0.0.1) simple_oauth (0.1.9) simplecov (0.9.0) docile (~> 1.1.0) @@ -775,7 +774,6 @@ DEPENDENCIES settingslogic shoulda-matchers (~> 2.7.0) sidekiq (~> 3.3) - simple_encrypt simplecov sinatra six diff --git a/app/helpers/version_check_helper.rb b/app/helpers/version_check_helper.rb index df0e25b9f6e..63d8eaeb2bd 100644 --- a/app/helpers/version_check_helper.rb +++ b/app/helpers/version_check_helper.rb @@ -1,7 +1,5 @@ module VersionCheckHelper def version_status_badge - if File.exists?(Rails.root.join('safe', 'public.pem')) - image_tag VersionCheck.new.url - end + image_tag VersionCheck.new.url end end diff --git a/lib/version_check.rb b/lib/version_check.rb index ada5e0db7a9..018bd9dac97 100644 --- a/lib/version_check.rb +++ b/lib/version_check.rb @@ -1,27 +1,15 @@ -# This class is used to encrypt GitLab version and URL -# with public key when we send it to version.gitlab.com to +require "base64" + +# This class is used to build image URL to # check if it is a new version for update class VersionCheck - include SimpleEncrypt - - def public_key - public_key_file = Rails.root.join('safe', 'public.pem').to_s - File.read(public_key_file) - end - def data - { - version: Gitlab::VERSION, - url: Gitlab.config.gitlab.url - } - end - - def encrypt(string) - encrypt_with_public_key(string, public_key) + { version: Gitlab::VERSION } end def url - "#{host}?gitlab_info=#{encrypt(data.to_json)}" + encoded_data = Base64.urlsafe_encode64(data.to_json) + "#{host}?gitlab_info=#{encoded_data}" end def host -- cgit v1.2.1 From edf0a0715b56a50fd1ac8ac505333f7e6fa4384c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 8 May 2015 15:59:34 +0300 Subject: Remove unnecessary public key Signed-off-by: Dmitriy Zaporozhets --- lib/version_check.rb | 1 + safe/public.pem | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 safe/public.pem diff --git a/lib/version_check.rb b/lib/version_check.rb index 018bd9dac97..460dc166c41 100644 --- a/lib/version_check.rb +++ b/lib/version_check.rb @@ -12,6 +12,7 @@ class VersionCheck "#{host}?gitlab_info=#{encoded_data}" end + # FIXME: Replace with version.gitlab.com def host 'http://localhost:9090/check.png' end diff --git a/safe/public.pem b/safe/public.pem deleted file mode 100644 index c5ffe20a5c7..00000000000 --- a/safe/public.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnp2mUaLBoHFX127ysonX -OihiGpI4098eFfH1iAxpKHIof0vs0jFF05IUScNXJZ1U3w8G1U/unY/wGGa3NzAb -ZfDd22eOF6X2Gfiey6U4w9dFf0/UT5x1bphlpX357yh4O9oWWuNaWD062DTbOOsJ -U6UW2U/sZAu/QScys0Nw+gJ58t93hb4jFq+nO5IAQc6g4S8ek5YvIXOshFEpF2in -ZLbSYowx92+9GzfjvdQ7fk0Q2ssg0zfScVa6FY8n019osz0SC3wcSd/qicdfecpu -7oycpd9YDqk4lufE1qVMOsgE8OO4KXMrByz2f+T0p/bH9zdBa5HYylf1T7i60hIL -kQIDAQAB ------END PUBLIC KEY----- -- cgit v1.2.1 From 09b3e354c87df17e3ea42825246cca2057bda901 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 8 May 2015 16:47:00 +0300 Subject: Fix syntax error Signed-off-by: Dmitriy Zaporozhets --- app/controllers/admin/application_settings_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb index 03fd12e9ecd..4c35622fff1 100644 --- a/app/controllers/admin/application_settings_controller.rb +++ b/app/controllers/admin/application_settings_controller.rb @@ -42,8 +42,8 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController :default_project_visibility, :default_snippet_visibility, :restricted_signup_domains_raw, + :version_check_enabled, restricted_visibility_levels: [], - :version_check_enabled ) end end -- cgit v1.2.1 From b3f5c679b6ae493c7bbc0ba75707c0f9c72685a8 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 11 May 2015 18:21:45 +0300 Subject: Replace host with real one Signed-off-by: Dmitriy Zaporozhets --- lib/version_check.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/version_check.rb b/lib/version_check.rb index 460dc166c41..ea23344948c 100644 --- a/lib/version_check.rb +++ b/lib/version_check.rb @@ -12,8 +12,7 @@ class VersionCheck "#{host}?gitlab_info=#{encoded_data}" end - # FIXME: Replace with version.gitlab.com def host - 'http://localhost:9090/check.png' + 'https://version.gitlab.com/check.png' end end -- cgit v1.2.1 From 0928c3ae04c8e708753705746e9eb74c62001dad Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 11 May 2015 18:23:40 +0300 Subject: Enable version check only for production environment Signed-off-by: Dmitriy Zaporozhets --- app/helpers/version_check_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/helpers/version_check_helper.rb b/app/helpers/version_check_helper.rb index 63d8eaeb2bd..f64d730b448 100644 --- a/app/helpers/version_check_helper.rb +++ b/app/helpers/version_check_helper.rb @@ -1,5 +1,7 @@ module VersionCheckHelper def version_status_badge - image_tag VersionCheck.new.url + if Rails.env.production? + image_tag VersionCheck.new.url + end end end -- cgit v1.2.1