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

Question: How to restrict access to a specific IP per folder #781

Open
merlinuwe opened this issue Oct 17, 2024 · 13 comments
Open

Question: How to restrict access to a specific IP per folder #781

merlinuwe opened this issue Oct 17, 2024 · 13 comments
Labels
question Further information is requested

Comments

@merlinuwe
Copy link

merlinuwe commented Oct 17, 2024

I remember - many years ago - when I was using HFS there was an option to allow to access a folder only from a given IP-address. I searched in the latest release candidate of today, but did not find this anymore. Is there a solution?

Background: I'd like to use this software (again) in a classroom, where are 25 computers for pupils and 1 for me, the teacher.

Example:

Place 1 with IP 10.10.304.1 should have only access to the folder "Platz_01" and the folder "Platz_99", where the teacher gives (only) download-access to some files/folders to everyone without any permission. (The pupils should not need an account. No pupil should be able to access the account of an other pupil. ;-))

Place 2 with IP 10.10.304.2 should have only access to the folder "Platz_02" and the folder "Platz_99" and so on.

(The teacher can zip the whole folders after the pupils work is done.)

@rejetto
Copy link
Owner

rejetto commented Oct 17, 2024

i'm quite sure there's no such feature in hfs2, but you could get the effect with some basic scripting.
hfs3 has scripting too, while in a much different fashion.
I'm not sure i understand your instructions, anyway.
For a start, 1) are you ok with all the folders being visible by anybody, but accessible only by the right ip?
And 2) do you know some programming?

@rejetto
Copy link
Owner

rejetto commented Oct 17, 2024

  1. is it true that IP 10.10.304.X will have access to Platz_X ?

@merlinuwe
Copy link
Author

For 1) yes, no problem.
For 2) not really ...
For 3) Yes, that's correct.

@rejetto
Copy link
Owner

rejetto commented Oct 17, 2024

how will hfs know that you are the teacher?

@merlinuwe
Copy link
Author

I work at the pc with IP 10.10.304.99.

@rejetto
Copy link
Owner

rejetto commented Oct 17, 2024

ok, exception made for you, every X has to access folder X and folder 99, right?
i didn't test it, but this should be close to what you need

exports.middleware = ctx => {
   if (ctx.ip === '10.10.304.99') return // skip 
   const n = ctx.path.match(/Platz_(\d+)/)?.[1]
   if (n && n !== '99' && ctx.ip !== '10.10.304.' + Number(n))
       ctx.status = 403
}

put in admin-panel > options > server-code

@rejetto rejetto added the question Further information is requested label Oct 17, 2024
@merlinuwe
Copy link
Author

merlinuwe commented Oct 17, 2024

Oh, thank you very much!
To test it at home, I changed the ip-addresses in your code to 192.168.178.x

exports.middleware = ctx => {
   if (ctx.ip === '192.168.178.21') return // skip 
   const n = ctx.path.match(/Platz_(\d+)/)?.[1]
   if (n && n !== '21' && ctx.ip !== '192.168.178.' + Number(n))
       ctx.status = 403
}

image

Now I can access from my smartphone to my PC. But it is allowed to log in as user 1, 2 21 and 27. The smartphone has ip 192.168.178.27. It should only be allowed to have access to folder Platz_27 (which I added).

Here are my other settings:

image

image

@rejetto
Copy link
Owner

rejetto commented Oct 17, 2024

I'm not sure i'm following.
You asked about folders and IPs, and to not require accounts, but now you are introducing accounts.
Of course accounts are not going to work with my script.

@merlinuwe
Copy link
Author

merlinuwe commented Oct 17, 2024

Ah - my fault. Thanks for the clarification.

@rejetto
Copy link
Owner

rejetto commented Oct 17, 2024

np, but so, what is the plan, accounts or ips?
you don't want to do both...
btw, you are not the first teacher using hfs. I'm glad it can be useful in schools.

@merlinuwe
Copy link
Author

IPs are the correct way.

Good to hear that other colleagues like it, too. ;-)

@levent0119
Copy link

What I need is to allow my members access based on their static external IP address, blocking them from logging in from different IPs. It would be great if there were plugins that could do this.

@rejetto
Copy link
Owner

rejetto commented Oct 20, 2024

What I need is to allow my members access based on their static external IP address, blocking them from logging in from different IPs. It would be great if there were plugins that could do this.

hey, in this issue/topic, accounts are NOT involved, but you say "logging in".
If you want something related to accounts then you should open a different discussion/issue, as this will be closed when the original problem is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants