Read the statement by Michael Teeuw here.
Show calendar based on IP Address accessed
-
so the little module is
https://github.com/sdetweil/getip
and it does correctly return the ip address of the client… tested from 4 different systems to the same MM…
see later post for final solution
-
-
I tried your code, but find that once I include getip module in config.js, I am not seeing any output for calendar. Is this the expected output. Without getip module, I find that client_ip = document.getElementById("getip is returning null.Please advice
-
@Spinstersee later post
-
@Spinster
By the way, which client are you using? Electron? Or Browser? -
@MMRIZE Browser as of now.
I also tried using express ipfilter, but the problem is I don’t know how to use it in module.js, it is throwing error saying ipfilter not known etc
-
@Spinster well, here is a working example, in addition to the other code already
watch out if using address AND MM host system not included. as it won’t show either…
one could make the ipaddress in cal a list (of ip addresses) similar to what @MMRIZE does…
I don’t like adding the extra block,
just add the var to the thing that matters…see later post
-
@Spinster
Withgetipof @sdetweil andMMM-ModuleMonkeyPatch, I did it. (You don’t have to modify the original source code for future-proof.)Example.
Server is running on192.168.178.63and I run 2 clients on192.168.178.22and192.168.178.63.
Both 2 clients can show different set of calendars.

{ module: "MMM-ModuleMonkeyPatch", config: { patches: [ { module: "calendar", method: "socketNotificationReceived", patch: async function (original, args) { const [ notification, payload ] = args if (notification === "CALENDAR_EVENTS") { const calendarName = this.config.calendars.find((cal) => cal.url === payload?.url)?.name const r = await fetch('http://192.168.178.63:8080/modules/getip') const ip = JSON.parse(await r.text())?.[ 'address' ] ?? null if (!this.config.clientMap?.[ ip ]?.includes(calendarName)) { return original(notification, { ...payload, events: [] }) } } return original(notification, payload) } } ] } }, { module: "getip", }, { module: "calendar", header: "US Holidays", position: "top_left", config: { clientMap: { "192.168.178.63": [ "cal1", "cal2", "cal3" ], "192.168.178.22": ["cal3", "cal4", "cal5"] }, calendars: [ { url: "...", name: "cal1", }, { url: "...", name: "cal2", }, { url: "...", name: "cal3", }, { url: "...", name: "cal4", }, { url: "...", name: "cal5", } ] } },TO Improve
Whenever notificationCALENDAR_EVENTScoming,getipis called. After first execution, to store IP on thelocalStorageorcookiewould be better. -
@sdetweil will express ipfilter be useful? Similar to whitelist, can we try something
-
@Spinster no… as its in the wrong place… (inside node_helper…) we NEED the ip address to compare with
just get it and return . one time
-
@MMRIZE said in Show calendar based on IP Address accessed:
(You don’t have to modify the original source code for future-proof.)
BUT you are fetching cal for system not going to use it… SOME cals are 1000’s of entries especially old
that have to be processed… this is a bad waste of resources…and this exposes a cal problem, as if u fetch http://xyz on client 1 and client 2 and client 3, we fetch it 3 times. also bad
this could also lead to different clients showing different data between fetchIntervals… -
@sdetweil said in Show calendar based on IP Address accessed:
BUT you are fetching cal for system not going to use it… SOME cals are 1000’s of entries especially old
that have to be processed… this is a bad waste of resources…I Can’t understand your point.
My code is just small injection that does filtering out calendars by condition on socketNotificationReceived. No additional fetching is needed. -
@sdetweil said in Show calendar based on IP Address accessed:
@MMRIZE said in Show calendar based on IP Address accessed:
(You don’t have to modify the original source code for future-proof.)
BUT you are fetching cal for system not going to use it… SOME cals are 1000’s of entries especially old
that have to be processed… this is a bad waste of resources…and this exposes a cal problem, as if u fetch http://xyz on client 1 and client 2 and client 3, we fetch it 3 times. also bad
this could also lead to different clients showing different data between fetchIntervals…Well, if that is the issue, we need a new “calendar” module that can ignore duplicated feed on addCalendar.
Regardless of my code, the original calendar module will fetch a same feed multiply on multi clients. It’s MM’s limitation. -
-
@MMRIZE said in Show calendar based on IP Address accessed:
My code is just small injection that does filtering out calendars by condition on socketNotificationReceived. No additional fetching is needed.
AFTER fetching… so throw away data, which we fetched , knowing we wouldn’t use it…
-
@MMRIZE I tried it, but it is still showing the calendar even if there is no calendar defined for the ip. I edited only the config.js file and added your code. Modified the calendars to suite mine. I could see even if there is no calendar defined for a particular ip. Please advice
-
@sdetweil Is this working? Should I try it, please advice
-
@sdetweil
Still I can’t catch you.[2024-05-07 15:03:33.741] [LOG] Use existing calendarfetcher for url: https://ics.calendarlabs.com/76/mm3137/US_Holidays.icsThe log shows, duplicated URL would be integrated into existing fetcher, So unlike your words, 3 clients doesn’t make 3 duplicated wasted fetcher.
If clientA needs cal1, cal2, cal3 and clientB needs cal1, cal4, cal5. In this case server should fetch 5 calendars anyway. User may need cal1 ~ cal5 even on 1 screen or 2 screens, ther server’s burden would be the same.
The only aspect that could be considered a waste is the transmission of unusing event data for cal4 and cal5 to clientA, but unless it’s a performance issue with the data parsing algorithm, simply having large data size being transmitted isn’t particularly problematic. Moreover, since the data is dropped in my code as soon as the notification is received, it can’t be deemed a significant memory issue. If the data size itself becomes problematic, it implies there’s already a problem with the original calendar module using cal1, cal2, cal3, cal4, and cal5.
Too skeptic.
-
@Spinster said in Show calendar based on IP Address accessed:
Modified the calendars to suite mine. I could see even if there is no calendar defined for a particular ip. Please advice
in the calendar config, I added
clientMap.{ module: "calendar", header: "US Holidays", position: "top_left", config: { clientMap: { "192.168.178.63": [ "cal1", "cal2", "cal3" ], "192.168.178.22": [ "cal3", "cal4", "cal5" ] }, calendars: [ { url: "...", name: "cal1", }, ... -
@Spinster yes, the two pieces together
ipaddress:“…”
at each cal url block… only does one ipaddress per url
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login