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) {
57
57
}
58
58
59
59
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
+ }
60
67
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
+ }
61
90
62
- return 404 ;
91
+ return 403 ;
63
92
}
64
93
}
You can’t perform that action at this time.
0 commit comments