Module: EnfCli

Defined in:
lib/enfcli/version.rb,
lib/enfcli.rb,
lib/enfthor.rb,
lib/enfcli/commands/xcr.rb,
lib/enfcli/commands/xfw.rb,
lib/enfcli/commands/user.rb,
lib/enfcli/commands/xdns.rb,
lib/enfcli/commands/xiam.rb,
lib/enfcli/commands/captive.rb

Overview

Copyright 2018-2020 Xaptum,Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: Cmd, Shell Classes: CLI, CTX, ERROR, EnfThor, IPV6, IPV6Cidr

Constant Summary collapse

CONFIG_FILE =
"#{Dir.home() + "/.xaptum_config.json"}"
FIREWALL_CMD =
"firewall"
IAM_CMD =
"iam"
NETWORK_CMD =
"network"
USER_CMD =
"user"
CAPTIVE_CMD =
"captive"
DNS_CMD =
"dns"
VERSION =
"5.0.1"

Class Method Summary collapse

Class Method Details

.ask_password(prompt = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/enfcli.rb', line 113

def self.ask_password(prompt = nil)
  begin
    prompt ||= "Enter Password:"
    print prompt
    # We hide the entered characters before to ask for the password
    system "stty -echo"
    password = $stdin.gets.chomp
    system "stty echo"
    puts ""
    return password
  rescue NoMethodError, Interrupt
    # When the process is exited, we display the characters again
    # And we exit
    system "stty echo"
    exit
  end
end

.expand_env(str) ⇒ Object



152
153
154
# File 'lib/enfcli.rb', line 152

def self.expand_env(str)
  str.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) { ENV[$1] }
end

.expand_path(file) ⇒ Object



148
149
150
# File 'lib/enfcli.rb', line 148

def self.expand_path(file)
  new_file = File.expand_path(EnfCli::expand_env(file))
end

.generate_ec_cert(key, ipv6) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/enfcli.rb', line 131

def self.generate_ec_cert(key, ipv6)
  # monkey patch
  OpenSSL::PKey::EC.send(:alias_method, :private?, :private_key?)

  # Generate cert
  cert = OpenSSL::X509::Certificate.new
  cert.subject = cert.issuer = OpenSSL::X509::Name.new([["CN", ipv6.to_s]])
  cert.not_before = Time.now
  cert.not_after = Time.now + 365 * 24 * 60 * 60
  cert.public_key = key
  cert.serial = SecureRandom.random_number(2 ** 159 - 2) + 1
  cert.version = 2

  cert.sign key, OpenSSL::Digest::SHA256.new
  cert
end

.to_canonical_ipv6(ipv6) ⇒ Object



156
157
158
159
# File 'lib/enfcli.rb', line 156

def self.to_canonical_ipv6(ipv6)
  ip = EnfCli::IPV6.new ipv6
  ip.to_s
end