Author: titmuss
Date: Thu Jan 17 08:28:59 2008
New Revision: 1485

URL: http://svn.slimdevices.com?rev=1485&root=Jive&view=rev
Log:
Bug: N/A
Description:
Parse mac address on desktop jive.


Modified:
    
trunk/jive/src/pkg/jive_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua

Modified: 
trunk/jive/src/pkg/jive_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua?rev=1485&root=Jive&r1=1484&r2=1485&view=diff
==============================================================================
--- 
trunk/jive/src/pkg/jive_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua 
(original)
+++ 
trunk/jive/src/pkg/jive_desktop/share/applets/DesktopJive/DesktopJiveMeta.lua 
Thu Jan 17 08:28:59 2008
@@ -1,5 +1,6 @@
 
 local oo            = require("loop.simple")
+local io            = require("io")
 local math          = require("math")
 local string        = require("string")
 local table         = require("jive.utils.table")
@@ -9,6 +10,8 @@
 local appletManager = appletManager
 local jiveMain      = jiveMain
 local jnt           = jnt
+
+local log         = require("jive.utils.log").logger("applets.setup")
 
 
 module(...)
@@ -30,18 +33,66 @@
 function registerApplet(meta)
        local settings = meta:getSettings()
 
+       local store = false
+
        if not settings.uuid then
+               store = true
+
                local uuid = {}
                for i = 1,16 do
                        uuid[#uuid + 1] = string.format('%02x', 
math.random(255))
                end
 
                settings.uuid = table.concat(uuid)
+       end
+
+       if not settings.mac then
+               local f = io.popen("ifconfig")
+               if f then
+                       local ifconfig = f:read("*a")
+                       f:close()
+
+                       store = true
+                       settings.mac = string.match(ifconfig, 
"HWaddr%s([%x:]+)")
+               end
+       end
+
+       if not settings.mac then
+               -- FIXME this needs testing
+               local f = io.popen("ipconfig /all")
+               if f then
+                       local ipconfig = f:read("*a")
+                       f:close()
+
+                       log:debug("ipconfig: ", ipconfig)
+
+                       store = true
+                       local mac = string.match(ipconfig, "Physical 
Address.-:([%x%-]+)")
+                       log:debug("mac: ", mac)
+
+                       if mac then
+                               settings.mac = string.gsub(mac, "%-", ":")
+                       end
+               end
+       end
+
+       if not settings.mac then
+               -- random fallback
+               mac = {}
+               for i = 1,6 do
+                       mac[#mac + 1] = string.format('%02x', math.random(255))
+               end
+
+               store = true
+               settings.mac = table.concat(mac, ":")
+       end
+
+       if store then
                meta:storeSettings()
        end
 
        -- set uuid
-       jnt:setUUID(settings.uuid)
+       jnt:setUUID(settings.uuid, settings.mac)
 end
 
 

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to