[READ-ONLY] Mirror of https://github.com/thoda-dev/du-simple-access-control. a script to control access with doors of force fields. Work with user name or ID or Organisation name or id
0

Configure Feed

Select the types of activity you want to include in your feed.

version 1.0.0

Thomas (May 14, 2023, 8:11 PM +0200) ebb1a77a 7a57b473

+217 -2
+28 -2
README.md
··· 1 - # du simple access control 2 - a script to control access with doors of force fields 1 + # Du-Simple-Access-Control 2 + 3 + A script to control access with doors of force fields. 4 + 5 + - It can control several doors and force fields at the same time. 6 + - You can manage access with user name, user id, organisation name or organisation id. 7 + 8 + ## How to install 9 + 10 + 1. copy the script on the board 11 + 2. link the doors you want to control to the board 12 + 3. link the force fields you want to control to the board 13 + 4. link the screens where you want to diplay the access is granted or not to the board 14 + 5. link the zone detection to the board (with a relay if you want to use several). The link must be done from the detector to the board (blue link, not green). 15 + 16 + ## Mounting Scheme 17 + 18 + ![Mounting Scheme]() 19 + 20 + ## How to configure 21 + 22 + In the Lua Parameters of the board (right click on the board > advanced > Lua parameters), you can change the following parameters: 23 + - AllowedUsersId: the list of the users id allowed to access, comma separated. 24 + - AllowedUsersName: the list of the users name allowed to access, comma separated, case sensitive. 25 + - AllowedUserOrgsId: the list of the organisations id allowed to access, comma separated. 26 + - AllowedUserOrgsName: the list of the organisations name allowed to access, comma separated, case sensitive. 27 + 28 + ![Lua Parameters]()
+1
config.json
··· 1 + {"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"--version 1.0.0\n\n--LUA PARAMETERS\nlocal AllowedUsersId = \"\" --export: the list of all IDs, comma separated\nlocal AllowedUsersName = \"Jericho\" --export: the list of all names, comma separated (Case sensitive)\nlocal AllowedUserOrgsId = \"18261\" --export: the list of all organisation IDs, comma separated\nlocal AllowedUserOrgsName = \"Federatis\" --export: the list of all organisation Names, comma separated (Case sensitive)\n\n--Libraries\n--split is a function to split a string in a table with a delimiter written by Jericho\nfunction split(s,d)local t={}s:gsub(\"[^\"..d..\"]+\",function(w)table.insert(t,w)end)return t end\n\n--hide unit widget\nunit.hideWidget()\n\n--auto detecting the door, force fields and the screens\nDoors = {}\nFields = {}\nScreens = {}\nfor slotName,slot in pairs(unit) do\n if\n type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getClass\n then\n local ElementClass = slot.getClass():lower()\n if ElementClass:find(\"doorunit\") then\n table.insert(Doors, slot)\n elseif ElementClass:find(\"forcefieldunit\") then\n table.insert(Fields, slot)\n slot.activate()\n elseif ElementClass:find(\"screenunit\") then\n table.insert(Screens, slot)\n slot.activate()\n else\n system.print(ElementClass)\n end\n end\nend\n\nfunction getRenderScript(access)\n local color = \"red\"\n local message = \"Access Denied\"\n if access then\n color = \"green\"\n message = \"Access Granted\"\n end\n return [[\n setBackgroundColor(15/255,24/255,29/255)\n local rx,ry = getResolution()\n local cx, cy = getCursor()\n if vmode then\n ry,rx = getResolution()\n cy, cx = getCursor()\n cx = rx - cx\n if vmode_side == \"right\" then\n cy = ry - cy\n cx = rx - cx\nend\nend\n\n local smallBold=loadFont('Play-Bold',40)\n local bigBold=loadFont('Play-Bold',64)\n\n local front=createLayer()\n local back=createLayer()\n setDefaultStrokeColor( back,Shape_Line,0,0,0,0.5)\n setDefaultShadow( back,Shape_Line,6,0,0,0,0.5)\n setDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1)\n setDefaultFillColor( front,Shape_Text,0,0,0,1)\n setDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1)\n setDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1)\n\n local red = {177/255,42/255,42/255}\n local green = {34/255,177/255,76/255}\n\n function renderHeader(title)\n local h = 55\n addLine(back,0,h+12,rx,h+12)\n addBox(front,0,12,rx,h)\n addText(front,smallBold,title,44,h-12)\nend\n\n setNextFillColor(front, ]] .. color .. [[[1], ]] .. color .. [[[2], ]] .. color .. [[[3], 1)\n setNextTextAlign(front,AlignH_Center,AlignV_Middle)\n addText(front,smallBold,\"]] .. message .. [[\", rx/2, ry/4)\n\n\n setNextFillColor(front, ]] .. color .. [[[1], ]] .. color .. [[[2], ]] .. color .. [[[3], 1)\n setNextTextAlign(front,AlignH_Center,AlignV_Middle)\n addText(front,bigBold,\"]] .. player.getName() .. [[\", rx/2, ry/2)\n\n renderHeader(\"Access Control System\")\n requestAnimationFrame(10)\n ]]\nend\n\nlocal AccessPermitted = false\n\nfunction setRenderScriptOnScreens(access)\n for _,screen in pairs(Screens) do\n screen.setRenderScript(getRenderScript(access))\n end\nend\n\nfunction grantAccess()\n AccessPermitted = true\n for _,Door in pairs(Doors) do\n Door.open() --open the door\n end\n for _,Field in pairs(Fields) do\n Field.deactivate() --open the field\n end\n setRenderScriptOnScreens(true)\nend\n\nfunction closeAll()\n AccessPermitted = false\n for _,Door in pairs(Doors) do\n Door.close() --close the door\n end\n for _,Field in pairs(Fields) do\n Field.activate() --close the field\n end\nend\n\nfunction rejectAccess()\n closeAll()\n setRenderScriptOnScreens(false)\n unit.exit()\nend\n\n--converting to tables\nlocal tPermittedUsersId = split(AllowedUsersId,',') or {}\nlocal tPermittedUsersName = split(AllowedUsersName,',') or {}\nlocal tPermittedOrgsId = split(AllowedUserOrgsId,',') or {}\nlocal tPermittedOrgsName = split(AllowedUserOrgsName,',') or {}\n\nlocal player_id = player.getId()\n\nfor _,id in pairs(tPermittedUsersId) do\n if id == player_id then\n grantAccess()\n AccessPermitted = true\n break\n end\nend\n\nif not AccessPermitted then\n local player_name = player.getName()\n for _,name in pairs(tPermittedUsersName) do\n if name == player_name then\n grantAccess()\n break\n end\n end\nend\n\nif not AccessPermitted then\n local player_orgs_id = player.getOrgIds()\n for _,oid in pairs(player_orgs_id) do\n for _,id in pairs(tPermittedOrgsId) do\n if tonumber(id) == oid then\n grantAccess()\n break\n end\n end\n --if access is granted, end the loop\n if AccessPermitted then break end\n --if not a valid ID, veifying the org name\n local o = system.getOrganization(oid)\n if o.name then\n for _,name in pairs(tPermittedOrgsName) do\n if name == o.name then\n grantAccess()\n break\n end\n end\n end\n --if access is granted, end the loop\n if AccessPermitted then break end\n end\nend\n\nif not AccessPermitted then\n rejectAccess()\nend","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"0"},{"code":"closeAll()\n","filter":{"args":[],"signature":"onStop()","slotKey":"-1"},"key":"1"}],"methods":[],"events":[]}
images/lua_parameters.png

This is a binary file and will not be displayed.

images/mounting_scheme.png

This is a binary file and will not be displayed.

images/screen_access_deniedpng.png

This is a binary file and will not be displayed.

images/screen_access_granted.png

This is a binary file and will not be displayed.

+187
source/unit/onStart.lua
··· 1 + --version 1.0.0 2 + 3 + --LUA PARAMETERS 4 + local AllowedUsersId = "" --export: the list of all IDs, comma separated 5 + local AllowedUsersName = "Jericho" --export: the list of all names, comma separated (Case sensitive) 6 + local AllowedUserOrgsId = "18261" --export: the list of all organisation IDs, comma separated 7 + local AllowedUserOrgsName = "Federatis" --export: the list of all organisation Names, comma separated (Case sensitive) 8 + 9 + --Libraries 10 + --split is a function to split a string in a table with a delimiter written by Jericho 11 + function split(s,d)local t={}s:gsub("[^"..d.."]+",function(w)table.insert(t,w)end)return t end 12 + 13 + --hide unit widget 14 + unit.hideWidget() 15 + 16 + --auto detecting the door, force fields and the screens 17 + Doors = {} 18 + Fields = {} 19 + Screens = {} 20 + for slotName,slot in pairs(unit) do 21 + if 22 + type(slot) == "table" 23 + and type(slot.export) == "table" 24 + and slot.getClass 25 + then 26 + local ElementClass = slot.getClass():lower() 27 + if ElementClass:find("doorunit") then 28 + table.insert(Doors, slot) 29 + elseif ElementClass:find("forcefieldunit") then 30 + table.insert(Fields, slot) 31 + slot.activate() 32 + elseif ElementClass:find("screenunit") then 33 + table.insert(Screens, slot) 34 + slot.activate() 35 + else 36 + system.print(ElementClass) 37 + end 38 + end 39 + end 40 + 41 + function getRenderScript(access) 42 + local color = "red" 43 + local message = "Access Denied" 44 + if access then 45 + color = "green" 46 + message = "Access Granted" 47 + end 48 + return [[ 49 + setBackgroundColor(15/255,24/255,29/255) 50 + local rx,ry = getResolution() 51 + local cx, cy = getCursor() 52 + if vmode then 53 + ry,rx = getResolution() 54 + cy, cx = getCursor() 55 + cx = rx - cx 56 + if vmode_side == "right" then 57 + cy = ry - cy 58 + cx = rx - cx 59 + end 60 + end 61 + 62 + local smallBold=loadFont('Play-Bold',40) 63 + local bigBold=loadFont('Play-Bold',64) 64 + 65 + local front=createLayer() 66 + local back=createLayer() 67 + setDefaultStrokeColor( back,Shape_Line,0,0,0,0.5) 68 + setDefaultShadow( back,Shape_Line,6,0,0,0,0.5) 69 + setDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1) 70 + setDefaultFillColor( front,Shape_Text,0,0,0,1) 71 + setDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1) 72 + setDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1) 73 + 74 + local red = {177/255,42/255,42/255} 75 + local green = {34/255,177/255,76/255} 76 + 77 + function renderHeader(title) 78 + local h = 55 79 + addLine(back,0,h+12,rx,h+12) 80 + addBox(front,0,12,rx,h) 81 + addText(front,smallBold,title,44,h-12) 82 + end 83 + 84 + setNextFillColor(front, ]] .. color .. [[[1], ]] .. color .. [[[2], ]] .. color .. [[[3], 1) 85 + setNextTextAlign(front,AlignH_Center,AlignV_Middle) 86 + addText(front,smallBold,"]] .. message .. [[", rx/2, ry/4) 87 + 88 + 89 + setNextFillColor(front, ]] .. color .. [[[1], ]] .. color .. [[[2], ]] .. color .. [[[3], 1) 90 + setNextTextAlign(front,AlignH_Center,AlignV_Middle) 91 + addText(front,bigBold,"]] .. player.getName() .. [[", rx/2, ry/2) 92 + 93 + renderHeader("Access Control System") 94 + requestAnimationFrame(10) 95 + ]] 96 + end 97 + 98 + local AccessPermitted = false 99 + 100 + function setRenderScriptOnScreens(access) 101 + for _,screen in pairs(Screens) do 102 + screen.setRenderScript(getRenderScript(access)) 103 + end 104 + end 105 + 106 + function grantAccess() 107 + AccessPermitted = true 108 + for _,Door in pairs(Doors) do 109 + Door.open() --open the door 110 + end 111 + for _,Field in pairs(Fields) do 112 + Field.deactivate() --open the field 113 + end 114 + setRenderScriptOnScreens(true) 115 + end 116 + 117 + function closeAll() 118 + AccessPermitted = false 119 + for _,Door in pairs(Doors) do 120 + Door.close() --close the door 121 + end 122 + for _,Field in pairs(Fields) do 123 + Field.activate() --close the field 124 + end 125 + end 126 + 127 + function rejectAccess() 128 + closeAll() 129 + setRenderScriptOnScreens(false) 130 + unit.exit() 131 + end 132 + 133 + --converting to tables 134 + local tPermittedUsersId = split(AllowedUsersId,',') or {} 135 + local tPermittedUsersName = split(AllowedUsersName,',') or {} 136 + local tPermittedOrgsId = split(AllowedUserOrgsId,',') or {} 137 + local tPermittedOrgsName = split(AllowedUserOrgsName,',') or {} 138 + 139 + local player_id = player.getId() 140 + 141 + for _,id in pairs(tPermittedUsersId) do 142 + if id == player_id then 143 + grantAccess() 144 + AccessPermitted = true 145 + break 146 + end 147 + end 148 + 149 + if not AccessPermitted then 150 + local player_name = player.getName() 151 + for _,name in pairs(tPermittedUsersName) do 152 + if name == player_name then 153 + grantAccess() 154 + break 155 + end 156 + end 157 + end 158 + 159 + if not AccessPermitted then 160 + local player_orgs_id = player.getOrgIds() 161 + for _,oid in pairs(player_orgs_id) do 162 + for _,id in pairs(tPermittedOrgsId) do 163 + if tonumber(id) == oid then 164 + grantAccess() 165 + break 166 + end 167 + end 168 + --if access is granted, end the loop 169 + if AccessPermitted then break end 170 + --if not a valid ID, veifying the org name 171 + local o = system.getOrganization(oid) 172 + if o.name then 173 + for _,name in pairs(tPermittedOrgsName) do 174 + if name == o.name then 175 + grantAccess() 176 + break 177 + end 178 + end 179 + end 180 + --if access is granted, end the loop 181 + if AccessPermitted then break end 182 + end 183 + end 184 + 185 + if not AccessPermitted then 186 + rejectAccess() 187 + end
+1
source/unit/onStop.lua
··· 1 + closeAll()