Skip to content

Commit

Permalink
Merge pull request #35 from takkii/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
takkii authored Jan 2, 2025
2 parents ec433de + 99e905b commit fbeafff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
10 changes: 8 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
DATABASE_USER = "postgres"
DATABASE_PASSWORD = "password"
IPADDRESS_WIN = ""
IPADDRESS_WSL = ""
WIN_IP_ONE = ""
WIN_IP_TWO = ""
WIN_IP_THREE = ""
WIN_IP_FOUR = ""
WSL_IP_ONE = ""
WSL_IP_TWO = ""
WSL_IP_THREE = ""
WSL_IP_FOUR = ""
36 changes: 22 additions & 14 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require 'open3'

class ApplicationController < ActionController::Base
before_action ->{
:set_locale
:validate_ipaddress
}
before_action :set_locale
before_action :validate_ipaddress

def after_sign_in_path_for(resource)
#root_path # Set the path to transition to after logging in
Expand All @@ -30,17 +28,27 @@ def validate_ipaddress
nodejs_path = "node" + " " + "#{File.dirname(__FILE__) + '/myipad.js'}"
stdout_js, stderr_js, status_js = Open3.capture3(nodejs_path)
# When the server is running, only a few permissions are granted.
ip_win = ENV['IPADDRESS_WIN']
ip_wsl = ENV['IPADDRESS_WSL']

# IP address(IPv4), enter one digit at a time in ascending order.
win_ip_one = ENV['WIN_IP_ONE']
win_ip_two = ENV['WIN_IP_TWO']
win_ip_three = ENV['WIN_IP_THREE']
win_ip_four = ENV['WIN_IP_FOUR']
wsl_ip_one = ENV['WSL_IP_ONE']
wsl_ip_two = ENV['WSL_IP_TWO']
wsl_ip_three = ENV['WSL_IP_THREE']
wsl_ip_four = ENV['WSL_IP_FOUR']

# Development is assumed to be in a local environment.
if "#{stdout_js}".match( /#{ip_win}/o) || {}[:match]
# windows, ip address specification, nothing displayed.
elsif "#{stdout_js}".match( /#{ip_wsl}/o) || {}[:match]
# wsl2, ip address specification, nothing displayed.
else
raise MyError, "An exception was raised on its own. Something other than an IP address was matched. Please review."
end
# Development is assumed to be in a local environment.
if "#{stdout_js}".match( /#{win_ip_one}.#{win_ip_two}.#{win_ip_three}.#{win_ip_four}/o) || {}[:match]
# windows, ip address specification, nothing displayed.
elsif "#{stdout_js}".match( /#{wsl_ip_one}.#{wsl_ip_two}.#{wsl_ip_three}.#{wsl_ip_four}/o) || {}[:match]
# wsl2, ip address specification, nothing displayed.
else
puts "An exception was raised on its own. Something other than an IP address was matched. Please review."
raise MyError => e
puts e.backtrace
end
end

def render_404(e)
Expand Down

0 comments on commit fbeafff

Please sign in to comment.