mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-05 16:49:47 +03:00
Logical theme system example: IP based access permissions #2819
Closed
opened 2026-02-05 05:18:42 +03:00 by OVERLORD
·
29 comments
No Branch/Tag Specified
development
l10n_development
further_theme_development
release
llm_only
vectors
v25-11
docker_env
drawio_rendering
user_permissions
ldap_host_failover
svg_image
prosemirror
captcha_example
fix/video-export
v25.12.3
v25.12.2
v25.12.1
v25.12
v25.11.6
v25.11.5
v25.11.4
v24.11.4
v25.11.3
v25.11.2
v25.11.1
v25.11
v25.07.3
v25.07.2
v25.07.1
v25.07
v25.05.2
v25.05.1
v25.05
v25.02.5
v25.02.4
v25.02.3
v25.02.2
v25.02.1
v25.02
v24.12.1
v24.12
v24.10.3
v24.10.2
v24.10.1
v24.10
v24.05.4
v24.05.3
v24.05.2
v24.05.1
v24.05
v24.02.3
v24.02.2
v24.02.1
v24.02
v23.12.3
v23.12.2
v23.12.1
v23.12
v23.10.4
v23.10.3
v23.10.2
v23.10.1
v23.10
v23.08.3
v23.08.2
v23.08.1
v23.08
v23.06.2
v23.06.1
v23.06
v23.05.2
v23.05.1
v23.05
v23.02.3
v23.02.2
v23.02.1
v23.02
v23.01.1
v23.01
v22.11.1
v22.11
v22.10.2
v22.10.1
v22.10
v22.09.1
v22.09
v22.07.3
v22.07.2
v22.07.1
v22.07
v22.06.2
v22.06.1
v22.06
v22.04.2
v22.04.1
v22.04
v22.03.1
v22.03
v22.02.3
v22.02.2
v22.02.1
v22.02
v21.12.5
v21.12.4
v21.12.3
v21.12.2
v21.12.1
v21.12
v21.11.3
v21.11.2
v21.11.1
v21.11
v21.10.3
v21.10.2
v21.10.1
v21.10
v21.08.6
v21.08.5
v21.08.4
v21.08.3
v21.08.2
v21.08.1
v21.08
v21.05.4
v21.05.3
v21.05.2
v21.05.1
v21.05
v21.04.6
v21.04.5
v21.04.4
v21.04.3
v21.04.2
v21.04.1
v21.04
v0.31.8
v0.31.7
v0.31.6
v0.31.5
v0.31.4
v0.31.3
v0.31.2
v0.31.1
v0.31.0
v0.30.7
v0.30.6
v0.30.5
v0.30.4
v0.30.3
v0.30.2
v0.30.1
v0.30.0
v0.29.3
v0.29.2
v0.29.1
v0.29.0
v0.28.3
v0.28.2
v0.28.1
v0.28.0
v0.27.5
v0.27.4
v0.27.3
v0.27.2
v0.27.1
v0.27
v0.26.4
v0.26.3
v0.26.2
v0.26.1
v0.26.0
v0.25.5
v0.25.4
v0.25.3
v0.25.2
v0.25.1
v0.25.0
v0.24.3
v0.24.2
v0.24.1
v0.24.0
v0.23.2
v0.23.1
v0.23.0
v0.22.0
v0.21.0
v0.20.3
v0.20.2
v0.20.1
v0.20.0
v0.19.0
v0.18.5
v0.18.4
v0.18.3
v0.18.2
v0.18.1
v0.18.0
v0.17.4
v0.17.3
v0.17.2
v0.17.1
v0.17.0
v0.16.3
v0.16.2
v0.16.1
v0.16.0
v0.15.3
v0.15.2
v0.15.1
v0.15.0
v0.14.3
v0.14.2
v0.14.1
v0.14.0
v0.13.1
v0.13.0
v0.12.2
v0.12.1
v0.12.0
v0.11.2
v0.11.1
v0.11.0
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
v0.8.2
v0.8.1
v0.8.0
v0.7.6
v0.7.5
v0.7.4
v0.7.3
0.7.2
v.0.7.1
v0.7.0
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
Labels
Clear labels
🎨 Design
📖 Docs Update
🐛 Bug
🐛 Bug
:cat2:🐈 Possible duplicate
💿 Database
☕ Open to discussion
💻 Front-End
🐕 Support
🚪 Authentication
🌍 Translations
🔌 API Task
🏭 Back-End
⛲ Upstream
🔨 Feature Request
🛠️ Enhancement
🛠️ Enhancement
🛠️ Enhancement
❤️ Happy feedback
🔒 Security
🔍 Pending Validation
💆 UX
📝 WYSIWYG Editor
🌔 Out of scope
🔩 API Request
:octocat: Admin/Meta
🖌️ View Customization
❓ Question
🚀 Priority
🛡️ Blocked
🚚 Export System
♿ A11y
🔧 Maintenance
> Markdown Editor
pull-request
Mirrored from GitHub Pull Request
No Label
🔨 Feature Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/BookStack#2819
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AuthorShin on GitHub (May 29, 2022).
As per https://github.com/BookStackApp/BookStack/issues/3374#issuecomment-1140344900, re-purposing this to provide a logical theme system example.
Describe the feature you'd like
Hello
Thanks for building BookStack
I would like to see an option to limit the access for some /pages/books/shelves based on (public) viewer public IP address so it will check with a list of IPs in the settings that you already provided the works as whitelist.
Describe the benefits this would bring to existing BookStack users
For instance you have a public BookStack on your server and it's publicly available to everyone but there are pages and books and you don't want people to see/access so you set custom permissions for it but each time for accessing it you have to login, which is no problem for one or two device but for like 10 or more in the office it's nightmarish and imagine you have multi-factor authentication enabled as well.
So, how it will help? well in those cases all those devices are on the same network so will have the same public IP address and BookStack will override the custom permissions and let them access/see the pages/books/shelves that are not publicly available for the IP addresses that are not in the whitelist even though the user did not logged in.
Can the goal of this request already be achieved via other means?
Not sure.
Have you searched for an existing open/closed issue?
How long have you been using BookStack?
0 to 6 months
Additional context
No response
@AuthorShin commented on GitHub (May 29, 2022):
Duplicate :/
@ssddanbrown commented on GitHub (May 29, 2022):
Updated the issue details and re-opening as a task for myself to provide an example.
@ssddanbrown commented on GitHub (Jun 8, 2022):
Hi @AuthorShin,
As promised, here's an example of using the Logical theme system to enable this functionality in some form.
The below enables auto-login to specific user accounts based upon certain IP addresses.
Setup
You should already have a
themes/folder within your BookStack directory.Within this create a
customdirectory, then within that create afunctions.phpfile with the code from the belowthemes/custom/functions.phpsection.Within your BookStack
.envfile, add the below line to set your theme folder:Within your
themes/custom/functions.phpfile, You can edit the IP-address mapping on around lines 17-19 (Within the$userIdsByIparray). This functions.php file is fully commented to describe what each section does.The way this is done means that you can still login via another user by going directly to the
/loginpath on your instance if required.Note: This is essentially an unsupported functionality addition. There may be logical holes in usage and this could break upon future updates.
themes/custom/functions.phpfile@ssddanbrown commented on GitHub (Jun 8, 2022):
Since the above has been provided I'll therefore close this off but feel free to still comment here if you have questions or need additional guidance.
@AuthorShin commented on GitHub (Jun 24, 2022):
@ssddanbrown
Thanks a lot man for the time and effort.
Is this supposed to work if the BookStack is installed as a Docker container?
@ssddanbrown commented on GitHub (Jun 24, 2022):
@AuthorShin Being a docker container should not make too much of a difference, as long as you can access the relevant
themesfolder. If you're not sure let me know what container image you're using and I'll double check their setup.@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown I'm using
lscr.io/linuxserver/bookstack:latestimage.I setup the
themesfolder and also added thefunctions.phpfile also addedAPP_THEME=customto Environment Variables of the container but if I setup a custom permission on a shelve and the BookStack will deny the access to it if I'm not logged in but even by adding my public IP address to thefunctions.phpfile, I couldn't still access it when I open the BookStack with that public IP address when I'm not logged in.@ssddanbrown commented on GitHub (Jun 27, 2022):
@AuthorShin It sounds like the
functions.phptheme file is just not being used.How/where did you set this up?
For the versions of the linuxserver/bookstack image that support the themes folder, the
themesfolder should already exist atwww/themeswithin your mounted volume targeting/configin the container.What version of BookStack are you using? It may be you're currently still using an older container image.
It's since a mid-march image using BookStack v22.02.3 that themes have been supported with linuxserver.io.
@AuthorShin commented on GitHub (Jun 27, 2022):
I had
v22.04.2now I updated it to the latest versionv22.06.1.And about
functions.phpfile it's in the exact path that you mentioned (www/themes/custom/functions.php).@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown
www/themes/custom/functions.phporwww/themes/functions.php?I used
www/themes/custom/functions.php.@AuthorShin commented on GitHub (Jun 27, 2022):
Should I change ID=
3in the following?@ssddanbrown commented on GitHub (Jun 27, 2022):
www/themes/custom/functions.phpis correct.Yeah, the number should be the ID of the user you want to be logged in for that IP address.
The user ID can be found in the URL when editing a user as an admin.
@AuthorShin commented on GitHub (Jun 27, 2022):
And there is another question which is unrelated.
Isn't custom permissions suppose to limit access to that shelve/book that we apply them to and the books/pages that they contain?
For example I add custom permissions on a shelve named Debra and within that we have 2 books named Work and Home which each containing a lot of chapters and pages. the shelve (Debra) access is limited and I cannot be accessed without logging in but on 'My Recently Viewed' and 'Recently Updated Pages' those pages and books with show up and if I click on them they will be open.
Actually just the shelve page itself is limited not anything inside it.
@ssddanbrown commented on GitHub (Jun 27, 2022):
This is detailed in our docs here:
https://www.bookstackapp.com/docs/user/roles-and-permissions/#content-level-permissions
Specifically:
This is also mentioned as a warning message when applying shelf custom permissions.
@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown
I even created a new user with ID 3 and set custom permission on that shelve for that user but still not working.
@ssddanbrown commented on GitHub (Jun 27, 2022):
@AuthorShin Are you testing while still logged in?
@AuthorShin commented on GitHub (Jun 27, 2022):
Why logged in? The whole idea is to access it with specific IP without the need to login.
@ssddanbrown commented on GitHub (Jun 27, 2022):
@AuthorShin I was just making sure, in case you were expecting to re-log-you-in as another user.
Maybe the logic is not running at all, Could you made the below change temporarily (Adding the
dd(line)? This should break BookStack display and show a message instead. If not then the theme system is not running.@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown
So to clarify the situation and the steps:
www/themes/custom/functions.phpAPP_THEME=customand restart the container@AuthorShin commented on GitHub (Jun 27, 2022):
This is my
functions.phpfile right now:@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown
After adding
ddthings are still working. (php file is above)@AuthorShin commented on GitHub (Jun 27, 2022):
Even with having the
functions.phpfile like this things are still working:@ssddanbrown commented on GitHub (Jun 27, 2022):
Then the theme folder is likely not being read.
Just to confirm, Is
www/themes/custom/functions.phppart of the folder that's passed to your BookStack contained as a mounted volume to/config? Does the samewwwfolder contain a.envfile anduploadsdirectory?@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown
Yes it is.
And there are
.envfile anduploadsdirectory inside thatwwwfolder but I didn't addAPP_THEME=customto that.envfile, I add it to the container Environment Variables as that's how in casaOS works.As shown here:
https://github.com/BookStackApp/BookStack/issues/3464#issuecomment-1167472105
@ssddanbrown commented on GitHub (Jun 27, 2022):
Gotta admit, I'm running out of ideas, there's something preventing the themes folder from being used. Possible extra steps:
APP_THEMEoption to thewww/.envfile (And removing any options of the same name if they exist).@AuthorShin commented on GitHub (Jun 27, 2022):
I added that to the
www/.envfile but no change.In settings of BookStack the version is shown like this:
Is it correct?
@ssddanbrown commented on GitHub (Jun 27, 2022):
Yeah, that appears correct.
I just started up a fresh docker-compose setup, using the docker-compose config shown in their readme, just to double check this can be done using their image. Everything seemed to work as expected, themes folder was exposed as expected.
To replicate things any further I feel I'd need to create a CasaOS setup.
@AuthorShin commented on GitHub (Jun 27, 2022):
@ssddanbrown
Thanks for all the time and energy that you're putting in.
For casaOS you have to have BookStack container and MariaDB separated.
You can use this .json files to import via casaOS and install the easily.
BookStack:
MariaDB:
@ssddanbrown commented on GitHub (Jun 29, 2022):
Okay, have now done a run-though testing this with a fresh CasaOS setup on a fresh Ubuntu 22.04 install.
I used the configs you provide (thanks!) and only tweaked the password fields, APP_URL option and DB_HOST options.
I left all volume paths as-is.
After getting a running BookStack setup on CasaOS, I uploaded a
functions.phpin the location shown below:This worked as expected, with first the simplified debug version of
functions.phpcausing the displayed output, then with the full IP address to user mapping. Within the paths shown, thethemesfolder already existed, I did create thecustomfolder myself. I also restarted my BookStack container after mapping and this continued to work.I did experience a bug within CasaOS, where using the file upload tool in the file browser, to upload a smaller file over a larger existing file, would only overwrite the larger file for the length of the new smaller file, effectively producing a bad merge of the two files. This caused invalid PHP in my case which could lead to a white blank screen upon BookStack access.
ls -alh /home/docker/bookstack/data/www/themes/custom/on the host system? Mine is as follows:I was suprised to see CasaOS use my own system user (
dan) for permissions here.I'm just wondering if file/folder permissions could be getting in the way here if the bookstack container processes don't have the ability to access the themes folder or functions file.