@@ -48,6 +48,9 @@ public function authenticate($input) {
48
48
if (!$ mqttUser ->getByUser ($ input ['username ' ])) {
49
49
return 404 ;
50
50
}
51
+ if ($ mqttUser ->getField ('enabled ' ) == '0 ' ) {
52
+ return 404 ;
53
+ }
51
54
$ input ['password ' ] = Toolbox::stripslashes_deep ($ input ['password ' ]);
52
55
if ($ mqttUser ->comparePasswords ($ input ['password ' ])) {
53
56
return 200 ;
@@ -57,8 +60,50 @@ public function authenticate($input) {
57
60
}
58
61
59
62
public function authorize ($ input ) {
63
+ $ mqttUser = new PluginFlyvemdmMqttUser ();
64
+ if (!$ mqttUser ->getByUser ($ input ['username ' ])) {
65
+ return 403 ;
66
+ }
67
+ if ($ mqttUser ->getField ('enabled ' ) == '0 ' ) {
68
+ return 403 ;
69
+ }
70
+
71
+ $ mqttUserId = $ mqttUser ->getID ();
72
+ $ acc = (int ) $ input ['acc ' ];
73
+ $ requestedTopic = explode ('/ ' , $ input ['topic ' ]);
74
+ $ mqttAcl = new PluginFlyvemdmMqttAcl ();
75
+ $ rows = $ mqttAcl ->find ("`plugin_flyvemdm_mqttusers_id`=' $ mqttUserId'
76
+ AND `access_level` & $ acc " );
77
+ foreach ($ rows as $ row ) {
78
+ $ topic = explode ('/ ' , $ row ['topic ' ]);
79
+ $ match = true ;
80
+ foreach ($ topic as $ index => $ pathItem ) {
81
+ if ($ pathItem === '+ ' ) {
82
+ // This path item matches a joker
83
+ continue ;
84
+ }
85
+ if ($ pathItem === '# ' && $ index === count ($ topic ) - 1 ) {
86
+ continue ;
87
+ }
88
+ if (!isset ($ requestedTopic [$ index ])) {
89
+ $ match = false ;
90
+ break ;
91
+ }
92
+ if ($ pathItem !== $ requestedTopic [$ index ]) {
93
+ // This topic does not match, try the next one
94
+ $ match = false ;
95
+ break ;
96
+ }
97
+ }
98
+ if ($ match ) {
99
+ return 200 ;
100
+ }
101
+ }
60
102
103
+ return 403 ;
104
+ }
61
105
62
- return 404 ;
106
+ public function isSuperuser ($ input ) {
107
+ return 403 ;
63
108
}
64
109
}
0 commit comments