Skip to content

Commit 48c6315

Browse files
authored
Merge pull request #20 from alces-software/develop
Overware 1.1
2 parents 47f442d + 57d8e25 commit 48c6315

26 files changed

+351
-22
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export APPLICATION_NAME=ABC # Optionally set for development
55
# Set the following regardless of environment
66
export SSH_KEYS_FILE_PATH=ABC
77
export APPLIANCE_INFORMATION_FILE_PATH=ABC
8+
export NETWORK_VARIABLES_FILE_PATH=ABC
9+
export NETWORK_SETUP_SCRIPT_FILE_PATH=ABC
810

911
# Set the following in production
1012
#SECRET_KEY_BASE=ABC

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ gem 'turbolinks', '~> 5'
4545
gem 'commonmarker'
4646
gem 'dotenv-rails'
4747

48-
gem 'bootstrap', '~> 4.1.2'
48+
gem 'bootstrap', '~> 4.3.1'
4949
gem 'jquery-rails' # Required for Bootstrap.
5050

5151
group :development, :test do

Gemfile.lock

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ GEM
5252
io-like (~> 0.3.0)
5353
arel (9.0.0)
5454
ast (2.4.0)
55-
autoprefixer-rails (9.4.2)
55+
autoprefixer-rails (9.4.9)
5656
execjs
5757
bcrypt (3.1.12)
5858
bindex (0.5.0)
5959
bootsnap (1.3.2)
6060
msgpack (~> 1.0)
61-
bootstrap (4.1.3)
62-
autoprefixer-rails (>= 6.0.3)
63-
popper_js (>= 1.12.9, < 2)
64-
sass (>= 3.5.2)
61+
bootstrap (4.3.1)
62+
autoprefixer-rails (>= 9.1.0)
63+
popper_js (>= 1.14.3, < 2)
64+
sassc-rails (>= 2.0.0)
6565
builder (3.2.3)
6666
byebug (10.0.2)
6767
capybara (3.12.0)
@@ -270,6 +270,15 @@ GEM
270270
sprockets (>= 2.8, < 4.0)
271271
sprockets-rails (>= 2.0, < 4.0)
272272
tilt (>= 1.1, < 3)
273+
sassc (2.0.0)
274+
ffi (~> 1.9.6)
275+
rake
276+
sassc-rails (2.1.0)
277+
railties (>= 4.0.0)
278+
sassc (>= 2.0)
279+
sprockets (> 3.0)
280+
sprockets-rails
281+
tilt
273282
selenium-webdriver (3.141.0)
274283
childprocess (~> 0.5)
275284
rubyzip (~> 1.2, >= 1.2.2)
@@ -313,7 +322,7 @@ PLATFORMS
313322

314323
DEPENDENCIES
315324
bootsnap (>= 1.1.0)
316-
bootstrap (~> 4.1.2)
325+
bootstrap (~> 4.3.1)
317326
byebug
318327
capybara (>= 2.15)
319328
chromedriver-helper

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737

3838
8.2. Load schema `RAILS_ENV=production bin/rails db:schema:load`
3939

40+
8.3. Run database migrations `RAILS_ENV=production bin/rails db:migrate`
41+
42+
8.4. Run data migrations `RAILS_ENV=production bin/rails data:migrate`
43+
4044
9. Create an initial user
4145

4246
9.1. Enter the rails console using `RAILS_ENV=production rails c`
@@ -50,3 +54,33 @@
5054

5155
12. Access the application at its public IP and use the details for the user
5256
you created in step 7 to log in
57+
58+
## Bolt-Ons
59+
60+
A Bolt-On is an optional part of the web interface configuration. These can be enabled on an individual basis in one of two ways:
61+
62+
1. Within the `rails-admin` interface
63+
64+
1.1. Navigate to the `Bolt ons` section
65+
66+
For each Bolt-On you wish to enable:
67+
68+
1.2. Click the edit icon next to the database entry
69+
70+
1.3. Click the `Enabled` checkbox
71+
72+
1.4. Save the entry
73+
74+
2. Via the rails console
75+
76+
2.1. Enter the rails console using `RAILS_ENV=production rails c`
77+
78+
For each Bolt-On you wish to enable:
79+
80+
2.2. Enable using:
81+
82+
```
83+
bolt_on = BoltOn.find_by(name: '<NAME_OF_BOLT_ON>')
84+
bolt_on.enabled = true
85+
bolt_on.save!
86+
```

app/assets/stylesheets/application.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@import 'bootstrap';
1818
@import 'font-awesome';
1919

20-
form {
20+
.styled-form {
2121
border-radius: 5px;
2222
background-color: #f2f2f2;
2323
padding: 20px;

app/controllers/application_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@ def authenticate(params)
77
params[:session][:password]
88
)
99
end
10+
11+
def run_shell_command(command)
12+
system(command, out: File::NULL)
13+
end
14+
15+
def bolt_on_enabled(name)
16+
BoltOn.find_by(name: name).enabled?
17+
end
1018
end

app/controllers/cluster_controller.rb

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,45 @@ class ClusterController < ApplicationController
22
require 'commonmarker'
33

44
def index
5-
file_data = IO.binread(Rails.application.config.appliance_information)
6-
@content = CommonMarker.render_html(file_data, :DEFAULT, [:table])
5+
#BoltOns
6+
@vpn = bolt_on_enabled('VPN')
7+
8+
@content = appliance_information
9+
@active = vpn_status
10+
end
11+
12+
def restart
13+
if run_shell_command("shutdown -r +1 'Reboot requested via web interface'")
14+
flash[:success] = 'Restarting machine'
15+
else
16+
flash[:danger] = 'Encountered an error whilst trying to restart the machine'
17+
end
18+
19+
redirect_to cluster_path
20+
end
21+
22+
def stop
23+
if run_shell_command("shutdown -h +1 'Shutdown requested via web interface'")
24+
flash[:success] = 'Stopping the machine'
25+
else
26+
flash[:danger] = 'Encountered an error whilst trying to stop the machine'
27+
end
28+
29+
redirect_to cluster_path
30+
end
31+
32+
private
33+
34+
def appliance_information
35+
file = Rails.application.config.appliance_information
36+
file_data = IO.binread(file) if File.exist? file
37+
38+
if file_data
39+
CommonMarker.render_html(file_data, :DEFAULT, [:table])
40+
end
41+
end
42+
43+
def vpn_status
44+
run_shell_command("systemctl is-active --quiet openvpn@flightcenter")
745
end
846
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
class NetworkController < ApplicationController
2+
3+
delegate :network_variables,
4+
:network_setup,
5+
to: 'Rails.application.config'
6+
7+
def index
8+
file_lines = file_data
9+
@internal_vars = file_lines.select { |l| l.include? "INTERNAL" }
10+
@external_vars = file_lines.select { |l| l.include? "EXTERNAL" }
11+
end
12+
13+
def edit
14+
tmp = Tempfile.new("temp_vars")
15+
16+
file_data.each do |line|
17+
if line.include?("INTERNAL") || line.include?("EXTERNAL")
18+
content = line.split("export")[1].split("=")
19+
variable = content[0]
20+
tail = content[1].split('"')[2]
21+
22+
line = "export#{variable}=\"#{network_params[variable]}\"#{tail}"
23+
end
24+
25+
tmp << line
26+
end
27+
28+
tmp.close
29+
30+
if run_shell_command("cp --no-preserve=mode,ownership #{tmp.path} #{network_variables}")
31+
if run_shell_command("alces_RERUN=true bash #{network_setup}")
32+
flash[:success] = 'Network configuration successfully modified'
33+
else
34+
flash[:danger] = 'Encountered an error whilst trying to run the setup script'
35+
end
36+
else
37+
flash[:danger] = 'Encountered an error whilst trying to modify the network configuration'
38+
end
39+
40+
tmp.delete
41+
42+
redirect_to network_path
43+
end
44+
45+
private
46+
47+
def network_params
48+
params[:network]
49+
end
50+
51+
def file_data
52+
IO.binread(Rails.application.config.network_variables).lines.map
53+
end
54+
end

app/controllers/sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def create
88
user = User.find_by(username: params[:session][:username])
99
if User.authenticate(params[:session][:username], params[:session][:password])
1010
sign_in(user)
11-
redirect_to cluster_index_path
11+
redirect_to cluster_path
1212
else
1313
flash.now[:danger] = 'Invalid username or password'
1414
render 'new'

app/controllers/vpn_controller.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class VpnController < ApplicationController
2+
def start
3+
return unless bolt_on_enabled('VPN')
4+
if run_shell_command("systemctl start openvpn@flightcenter")
5+
flash[:success] = 'VPN started'
6+
else
7+
flash[:danger] = 'Enountered an error whilst trying to start the VPN'
8+
end
9+
10+
redirect_to cluster_path
11+
end
12+
13+
def stop
14+
return unless bolt_on_enabled('VPN')
15+
if run_shell_command("systemctl stop openvpn@flightcenter")
16+
flash[:success] = 'VPN stopped'
17+
else
18+
flash[:danger] = 'Encountered an error whilst trying to stop the VPN'
19+
end
20+
21+
redirect_to cluster_path
22+
end
23+
24+
def restart
25+
return unless bolt_on_enabled('VPN')
26+
if run_shell_command("systemctl restart openvpn@flightcenter")
27+
flash[:success] = 'VPN restarted'
28+
else
29+
flash[:danger] = 'Encountered an error whilst trying to restart the VPN'
30+
end
31+
32+
redirect_to cluster_path
33+
end
34+
end

0 commit comments

Comments
 (0)