<p>I see! Upon looking, <em>dnsmasq</em> stores infinite leases as "0" in the <em>/tmp/dhcp.leases</em> file. This corresponds to the <em>01/01/1970 00:00:00 GMT</em>, in Unix EPOCH time. Since today's date is "1484889355". But the expires property is (EXPIRY DATE - TODAYS DATE). So it's 0-1484889355. So any value below -1484889355 works.</p>
<p>So if someone wanted to do a dnsmasq infinite check properly you could:</p>
<ol>
<li>
<p>Check the <em>/tmp/dhcp.leases</em> file and see if it has a 0 as the time.</p>
</li>
<li>
<p>Since the DHCP Lease Table is pulling its information from:</p>
</li>
<li>
<p><code>XHR.poll(5, '<%=url('admin/network/dhcplease_status')%>'</code></p>
</li>
<li>
<p>Going to the URL: <em><a href="http://192.168.0.1/cgi-bin/luci/admin/network/dhcplease_status">http://192.168.0.1/cgi-bin/luci/admin/network/dhcplease_status</a></em> shows that it only gives the expiry conversion, and not the original expiry date. So someone would have to alter the structs and put the expiry time, and original EXPIRY DATE. Then you can use that and check to see if it's 0 for an infinite lease --- More work.</p>
</li>
<li>
<p>The leases[i].expires property is just EXPIRY DATE - CURRENT DATE. So you could reverse this calculation and check to see if it's 0. Of course, playing with time can be smudgy with rounding.</p>
</li>
</ol>
<p>Option 2 is probably the cleanest, Option 3 is the easiest. So if we were doing 3, we can just do the check in these two files as:</p>
<p><em>luci/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm<br>
luci/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm</em></p>
<pre><code>                                 if (info.leases[i].expires === false || Math.trunc((new Date().getTime()/1000 + info.leases[i].expires)/10) == 0)
                                                timestr = '<em><%:unlimited%></em>';
                                        else if (info.leases[i].expires <= 0)
                                                timestr = '<em><%:expired%></em>';
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you were mentioned.<br />Reply to this email directly, <a href="https://github.com/openwrt/luci/issues/963#issuecomment-273989416">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ATxnSnKCO1SO851caS885RSfi1gBzLKrks5rUFZqgaJpZM4Lo023">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ATxnSkraNTZJ8-uSoP6jv_uAmIzgbAbsks5rUFZqgaJpZM4Lo023.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/openwrt/luci/issues/963#issuecomment-273989416"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/openwrt/luci","title":"openwrt/luci","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/openwrt/luci"}},"updates":{"snippets":[{"icon":"PERSON","message":"@NvrBst in #963: I see! Upon looking, _dnsmasq_ stores infinite leases as \"0\" in the _/tmp/dhcp.leases_ file. This corresponds to the _01/01/1970 00:00:00 GMT_, in Unix EPOCH time. Since today's date is \"1484889355\". But the expires property is (EXPIRY DATE - TODAYS DATE). So it's 0-1484889355. So any value below -1484889355 works.\r\n\r\nSo if someone wanted to do a dnsmasq infinite check properly you could:\r\n\r\n1. Check the _/tmp/dhcp.leases_ file and see if it has a 0 as the time.\r\n2. Since the DHCP Lease Table is pulling its information from:\r\n\r\n3. `XHR.poll(5, '\u003c%=url('admin/network/dhcplease_status')%\u003e'`\r\n4. Going to the URL: _http://192.168.0.1/cgi-bin/luci/admin/network/dhcplease_status_ shows that it only gives the expiry conversion, and not the original expiry date. So someone would have to alter the structs and put the expiry time, and original EXPIRY DATE. Then you can use that and check to see if it's 0 for an infinite lease --- More work.\r\n5. The leases[i].expires property is just EXPIRY DATE - CURRENT DATE. So you could reverse this calculation and check to see if it's 0. Of course, playing with time can be smudgy with rounding.\r\n\r\nOption 2 is probably the cleanest, Option 3 is the easiest. So if we were doing 3, we can just do the check in these two files as:\r\n\r\n_luci/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm\r\nluci/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm_\r\n```\r\n\t\t\t\t\tif (info.leases[i].expires === false || Math.trunc((new Date().getTime()/1000 + info.leases[i].expires)/10) == 0)\r\n\t\t\t\t\t\ttimestr = '\u003cem\u003e\u003c%:unlimited%\u003e\u003c/em\u003e';\r\n\t\t\t\t\telse if (info.leases[i].expires \u003c= 0)\r\n\t\t\t\t\t\ttimestr = '\u003cem\u003e\u003c%:expired%\u003e\u003c/em\u003e';\r\n```\r\n\r\n"}],"action":{"name":"View Issue","url":"https://github.com/openwrt/luci/issues/963#issuecomment-273989416"}}}</script>