• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Show calendar based on IP Address accessed

Scheduled Pinned Locked Moved Development
68 Posts 3 Posters 21.0k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    Spinster @MMRIZE
    last edited by May 7, 2024, 1:09 PM

    @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

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdetweil @Spinster
      last edited by sdetweil May 7, 2024, 5:34 PM May 7, 2024, 1:09 PM

      @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

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • M Offline
        MMRIZE @Spinster
        last edited by MMRIZE May 7, 2024, 1:20 PM May 7, 2024, 1:12 PM

        @Spinster
        With getip of @sdetweil and MMM-ModuleMonkeyPatch, I did it. (You don’t have to modify the original source code for future-proof.)

        Example.
        Server is running on 192.168.178.63 and I run 2 clients on 192.168.178.22 and 192.168.178.63.
        Both 2 clients can show different set of calendars.

        da786ea9-d7f4-4ad4-89ac-88c5621c03c6-image.png

        windows.192.168.178.22.png

        {
        	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 notification CALENDAR_EVENTS coming, getip is called. After first execution, to store IP on the localStorage or cookie would be better.

        S S 2 Replies Last reply May 7, 2024, 1:22 PM Reply Quote 0
        • S Offline
          Spinster @sdetweil
          last edited by May 7, 2024, 1:14 PM

          @sdetweil will express ipfilter be useful? Similar to whitelist, can we try something

          S 1 Reply Last reply May 7, 2024, 1:19 PM Reply Quote 0
          • S Offline
            sdetweil @Spinster
            last edited by May 7, 2024, 1:19 PM

            @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

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • S Offline
              sdetweil @MMRIZE
              last edited by sdetweil May 7, 2024, 1:28 PM May 7, 2024, 1:22 PM

              @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…

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              M 2 Replies Last reply May 7, 2024, 1:28 PM Reply Quote 0
              • M Offline
                MMRIZE @sdetweil
                last edited by May 7, 2024, 1:28 PM

                @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.

                S 1 Reply Last reply May 7, 2024, 1:41 PM Reply Quote 0
                • M Offline
                  MMRIZE @sdetweil
                  last edited by MMRIZE May 7, 2024, 1:39 PM May 7, 2024, 1:36 PM

                  @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.

                  S 1 Reply Last reply May 7, 2024, 1:38 PM Reply Quote 0
                  • S Offline
                    sdetweil @MMRIZE
                    last edited by sdetweil May 7, 2024, 5:34 PM May 7, 2024, 1:38 PM

                    @MMRIZE yes

                    @Spinster

                    see later post

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    S 1 Reply Last reply May 7, 2024, 1:57 PM Reply Quote 0
                    • S Offline
                      sdetweil @MMRIZE
                      last edited by May 7, 2024, 1:41 PM

                      @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…

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      M 1 Reply Last reply May 7, 2024, 1:57 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 6
                      • 7
                      • 3 / 7
                      3 / 7
                      • First post
                        30/68
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy