Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #35

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading