@@ -11,41 +11,45 @@ def index
11
11
def edit
12
12
tmp = Tempfile . new ( "temp_vars" )
13
13
14
- file_data . each do |line |
15
- if line . include? ( "INTERNAL" ) || line . include? ( "EXTERNAL" )
16
- content = line . split ( "=" )
17
- variable = content [ 0 ] . remove ( "export " )
18
- original_value = content [ 1 ] . split ( '"' ) [ 1 ]
19
-
20
- if original_value . empty?
21
- line = line . insert ( line . index ( '"' ) + 1 , network_params [ variable ] )
22
- else
23
- line = line . sub original_value , network_params [ variable ]
14
+ if File . exist? network_variables
15
+ file_data . each do |line |
16
+ if line . include? ( "INTERNAL" ) || line . include? ( "EXTERNAL" )
17
+ content = line . split ( "=" )
18
+ variable = content [ 0 ] . remove ( "export " )
19
+ original_value = content [ 1 ] . split ( '"' ) [ 1 ]
20
+
21
+ if original_value . empty?
22
+ line = line . insert ( line . index ( '"' ) + 1 , network_params [ variable ] )
23
+ else
24
+ line = line . sub original_value , network_params [ variable ]
25
+ end
24
26
end
27
+
28
+ tmp << line
25
29
end
26
30
27
- tmp << line
28
- end
31
+ tmp . close
29
32
30
- tmp . close
31
- if run_shell_command ( "cp --no-preserve=mode,ownership #{ tmp . path } #{ network_variables } " )
32
- out , err , status = run_global_script ( ENV [ 'NETWORK_SET' ] )
33
- if status . success?
34
- flash [ :success ] = 'Network configuration successfully modified'
33
+ if run_shell_command ( "cp --no-preserve=mode,ownership #{ tmp . path } #{ network_variables } " )
34
+ if run_global_script ( ENV [ 'NETWORK_SET' ] ) [ :status ] . success?
35
+ flash [ :success ] = 'Network configuration successfully modified'
36
+ else
37
+ flash [ :danger ] = 'Encountered an error whilst trying to run the setup script'
38
+ end
35
39
else
36
- flash [ :danger ] = 'Encountered an error whilst trying to run the setup script '
40
+ flash [ :danger ] = 'Encountered an error whilst trying to modify the network configuration '
37
41
end
42
+
43
+ tmp . delete
38
44
else
39
- flash [ :danger ] = 'Encountered an error whilst trying to modify the network configuration '
45
+ flash [ :danger ] = 'No network variables file defined '
40
46
end
41
47
42
- tmp . delete
43
-
44
48
redirect_to network_path
45
49
end
46
50
47
51
def add_ssh_service
48
- if run_global_script ( ENV [ 'SSH_ENABLE' ] ) [ 2 ] . success?
52
+ if run_global_script ( ENV [ 'SSH_ENABLE' ] ) [ :status ] . success?
49
53
flash [ :success ] = 'SSH enabled on the external interface'
50
54
else
51
55
flash [ :danger ] = 'Encountered an error whilst trying to enable SSH'
@@ -55,7 +59,7 @@ def add_ssh_service
55
59
end
56
60
57
61
def remove_ssh_service
58
- if run_global_script ( ENV [ 'SSH_DISABLE' ] ) [ 2 ] . success?
62
+ if run_global_script ( ENV [ 'SSH_DISABLE' ] ) [ :status ] . success?
59
63
flash [ :success ] = 'SSH disabled on the external interface'
60
64
else
61
65
flash [ :danger ] = 'Encountered an error whilst trying to disable SSH'
@@ -71,16 +75,15 @@ def network_params
71
75
end
72
76
73
77
def network_get_output
74
- out , err , status = run_global_script ( ENV [ 'NETWORK_GET' ] )
75
- out . lines . map
78
+ run_global_script ( ENV [ 'NETWORK_GET' ] ) [ :output ] . lines . map
76
79
end
77
80
78
81
def network_show_output
79
- out , err , status = run_global_script ( ENV [ 'NETWORK_SHOW' ] )
80
- out . split ( " \n \n " ) . map { |n | n . split ( "\n " ) }
82
+ run_global_script ( ENV [ 'NETWORK_SHOW' ] ) [ :output ] . split ( " \n \n " )
83
+ . map { |n | n . split ( "\n " ) }
81
84
end
82
85
83
86
def file_data
84
- IO . binread ( Rails . application . config . network_variables ) . lines . map
87
+ IO . binread ( network_variables ) . lines . map
85
88
end
86
89
end
0 commit comments