How to view user login information

Hi,

I set up password protection by adding code chips directly to the lib/sequenceserver/routes.rb file.

Can I view the user’s login information (such as login time, ip)?

Thanks.

Shenglong bai

Hi,

There is no built-in way as such. But you can edit the same file to log the necessary information.

Change the following code block:

before do
logger.debug params
end

to:

before do
username = env[‘REMOTE_USER’]}
logger.info “#{username}@#{request.ip} requested #{request.path_info}"
logger.debug params
end

logger automatically adds timestamp.

This will only print successful attempts. Failed login attempts won’t make it to this point.

Priyam

Hi,

Thanks for your reply, I added the code block as you suggested, but I don’t know in which file to view the login information.

In addition, I have another question, how to add multiple users? I added multiple users with the following command, but it seems that only the last account works.

`

use Rack::Auth::Basic, “Restricted Area” do |username, password|
username == ‘admin’ and password == ‘admin’
username == ‘group1’ and password == ‘group11’
username == ‘group2’ and password == ‘group22’
end

`

在 2019年12月3日星期二 UTC+8上午3:15:56,Anurag Priyam写道:

Hi,

The logs are displayed in the terminal window where you launched sequenceserver. You can redirect it to a file for convenience:

sequenceserver 2> sequenceserver.log

For multiple users, you can do something like:

use Rack::Auth::Basic, “Restricted Area” do |username, password|
credentials = {
admin: ‘admin’,
group1: ‘group11’
group2: ‘group22’
}
credendtials.include?(username) && credentials[username] == password
end

Priyam

Hi,

About logs information, I start server through sudo systemctl restart sequenceserver.service command, I have checked the relevant files and don’t know where to add the redirected log files.

About multiple users, I added the following code (fixed some spelling errors in the code you provided).

`

add password

use Rack::Auth::Basic, “Restricted Area” do |username, password|
credentials = {
admin: ‘admin’,
group1: ‘group11’,
group2: ‘group22’
}
credentials.include?(username) && credentials[username] == password
end

`

I can start the service successfully, but I can’t access the service by entering my account password.
Do you have any syntax errors? I only know some Python syntax. I don’t know how to modify this file.

Thanks for your help.

Shenglong

在 2019年12月4日星期三 UTC+8上午12:52:39,Anurag Priyam写道:

Hi,

This link might help for viewing the logs: https://unix.stackexchange.com/questions/20399/view-stdout-stderr-of-systemd-service

Sorry, I now realise the error in the code snippet. Changing syntax of the credentials Hash (similar to Python dictionary) as follows should work:

credentials = {
‘admin’ => ‘admin’,
‘group1’ => ‘group11’,
}

In the previous syntax the keys are converted internally to what are called symbols in Ruby, where as username is a string. Due to this, the hash lookups in the last line would always fail and you would remain unauthenticated. In the new syntax the keys will remain as string and the rule in the last line should work as expected (is the username present in the hash, and if so, does the password saved in the hash match with what the user entered).

Priyam

Thank you very much for your patience. My question has been perfectly answered.

在 2019年12月5日星期四 UTC+8上午12:45:17,Anurag Priyam写道: