MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. Spinster
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    S
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 32
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: Show calendar based on IP Address accessed

      @MMRIZE
      Here is my config

      	{
      		module: "alert",
      	},
      
      	/*
      	{
      		module: "updatenotification",
      		position: "top_bar"
      	},*/
      	{
      		module: "clock",
      		position: "top_left"
      	},
      	{
      		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://10.5.11.1:8080/modules/getip')
      							const ip = JSON.parse(await r.text())?.[ 'address' ] ?? null
      							console.log(ip)
      							if (!this.config.clientMap?.[ ip ]?.includes(calendarName)) {
      								return original(notification, { ...payload, events: [] })
      							}
      						}
      						return original(notification, payload)
      					}
      				}
      			]
      		}
      	},
      	{
      		module: "getip",
      	},
      	{
      		module: "calendar",
      		header: "Home Cal",
      		position: "top_left",
      		config: {
      			clientMap: {
      				"10.5.11.5": [ "cal1" ],
      				"10.5.11.6": ["cal2"]
      			},
      			calendars: [
      				{
      					fetchInterval: 10 * 60 * 1000,
      					symbol: "calendar-check",
      					url: "https://homecals/xEzboFt7Kr3Yfiys?export",
      					name: "cal1",
      
      				}
      			]
      		}
      	}
      

      This is showing both 10.5.11.5 and 10.5.11.6 the same calendar. Though 10.5.11.6 should not have any calendar since it is not defined. Even I tried without an entry of 10.5.11.6 in calendar map but it still showing the calendar. What am I doing wrong. Please advice

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @sdetweil Is this working? Should I try it, please advice

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @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

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

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

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @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

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @sdetweil

      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

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @sdetweil @MMRIZE

      Wow, you are quick, you have given me some homework. Will use your code and get back with the result.

      Thank you so much for your patience and understanding.

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @MMRIZE Great, You have given me an idea, will wait for your code. Please share when possible.

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @MMRIZE I understand, Ideally I would like to avoid opening multiple ports and use a common config to serve clients based on their IP. In fact, though DHCP is used by my home server, I have only assigned the IP address to reservations, hence static IP within my home network is not a problem.

      Please suggest a simple code to use a specific calendar based on IP address of the client.

      posted in Development
      S
      Spinster
    • RE: Show calendar based on IP Address accessed

      @sdetweil I understand about the log. Thank you.

      Regarding the IP address, I am very new to javascript hence trying to get my head around it. Being a C programmer, certain things in JavaScript is still a distant for me. Hope to understand soon.

      Just in case if you have some time, a simple code from you would help me. Please.

      posted in Development
      S
      Spinster
    • 1
    • 2
    • 3
    • 4
    • 3 / 4