Skip to content

Commit

Permalink
Sanitize the key file name in order to avoid errors with openvpn.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Clark committed Sep 1, 2015
1 parent f168635 commit 4614fc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def show


def download
if File.exists? "/opt/keys/#{current_user.email}.zip"
send_file "/opt/keys/#{current_user.email}.zip", type: "application/zip"
if File.exists? "/opt/keys/#{current_user.key_file_name}.zip"
send_file "/opt/keys/#{current_user.key_file_name}.zip", type: "application/zip"
else
player = Player.find(params[:id])
redirect_to player, flash: {error: "Your VPN cert hasn't been generated yet. Check back in 2 minutes." }
Expand Down
9 changes: 8 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def display_name
end
end

# Grab the first 10 characters from the email and append the users ID.
# Since we have 2 different scoreboards the ID is not sufficient, therefore
# if we seed it with some additional data it should solve the issue.
def key_file_name
self.email.tr('^A-Za-z', '')[0..10] + self.id.to_s
end

def set_password; nil; end

def set_password=(value)
Expand All @@ -37,7 +44,7 @@ def set_password=(value)
private

def touch_file
`touch /opt/keys/#{self.email}`
`touch /opt/keys/#{self.key_file_name}`
end

end

0 comments on commit 4614fc4

Please sign in to comment.