This repository was archived by the owner on Aug 9, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,37 @@ public function authenticate($input) {
5757 }
5858
5959 public function authorize ($ input ) {
60+ $ mqttUser = new PluginFlyvemdmMqttUser ();
61+ if (!$ mqttUser ->getByUser ($ input ['username ' ])) {
62+ return 403 ;
63+ }
64+ if ($ mqttUser ->getField ('enabled ' ) == '0 ' ) {
65+ return 403 ;
66+ }
6067
68+ $ mqttUserId = $ mqttUser ->getID ();
69+ $ acc = (int ) $ input ['acc ' ];
70+ $ requestedTopic = explode ('/ ' , $ input ['topic ' ]);
71+ $ mqttAcl = new PluginFlyvemdmMqttAcl ();
72+ $ rows = $ mqttAcl ->find ("`plugin_flyvemdm_mqttusers_id`=' $ mqttUserId'
73+ AND `access_level` & $ acc " );
74+ foreach ($ rows as $ row ) {
75+ $ topic = explode ('/ ' , $ row ['topic ' ]);
76+ foreach ($ topic as $ index => $ pathItem ) {
77+ if ($ pathItem === '# ' && $ index === count ($ topic ) - 1 ) {
78+ return 200 ;
79+ }
80+ if ($ pathItem === '+ ' ) {
81+ // This path item matches a joker
82+ continue ;
83+ }
84+ if ($ pathItem !== $ requestedTopic [$ index ]) {
85+ // This topic does not match, try the next one
86+ break ;
87+ }
88+ }
89+ }
6190
62- return 404 ;
91+ return 403 ;
6392 }
6493}
You can’t perform that action at this time.
0 commit comments