Class: SafeDb::Vpn

Inherits:
Controller show all
Defined in:
lib/controller/api/vpn/vpn.rb

Overview

This vpn use case sets up vpn connection paraphernelia and can bring up a VPN connection and then tear it down.

safe vpn up
safe vpn down

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Controller

#check_post_conditions, #check_pre_conditions, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse

Constructor Details

This class inherits a constructor from SafeDb::Controller

Instance Attribute Details

#command=(value) ⇒ Object (writeonly)

Sets the attribute command

Parameters:

  • value

    the value to set the attribute command to.



12
13
14
# File 'lib/controller/api/vpn/vpn.rb', line 12

def command=(value)
  @command = value
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/controller/api/vpn/vpn.rb', line 14

def execute

  if( @command && @command.eql?( "down" ) )

    puts ""
    system @dictionary[ :nm_conn_off ]; sleep 2;
    system @dictionary[ :nm_conn_del ]
    puts ""
    return

  end

  puts ""
  system @dictionary[ :safe_write_cmd ]
  puts "[#{@dictionary[ :vpn_filename ]}] temporarily exported to [#{@dictionary[ :vpn_filepath ]}]."
  system @dictionary[ :nm_import_cmd  ]
  File.delete( @dictionary[ :vpn_filepath ] )
  puts "Exported file [#{@dictionary[ :vpn_filepath ]}] has now been deleted."

  system @dictionary[ :nm_default_cmd ]
  system @dictionary[ :nm_user_cmd    ]
  system @dictionary[ :nm_reload_cmd  ]
  system @dictionary[ :nm_flags_cmd   ]
  system @dictionary[ :chown_cmd_1    ]

  vpn_data = IniFile.load( @dictionary[:nm_filepath] )
  vpn_data['vpn-secrets'] = { 'password' => @dictionary[:vpn_password] }
  vpn_data.write()

  system @dictionary[ :chown_cmd_2 ]
  system @dictionary[ :nm_restart  ]; sleep 2;
  system @dictionary[ :nm_conn_up  ]
  puts ""

end