Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
6bde5f98
Commit
6bde5f98
authored
Aug 12, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store password in client structure.
No need to carry password around.
parent
6a37033c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
47 deletions
+53
-47
client.go
client.go
+6
-1
disk.go
disk.go
+2
-2
group.go
group.go
+30
-32
webclient.go
webclient.go
+14
-11
webserver.go
webserver.go
+1
-1
No files found.
client.go
View file @
6bde5f98
package
main
package
main
type
clientCredentials
struct
{
Username
string
`json:"username,omitempty"`
Password
string
`json:"password,omitempty"`
}
type
client
interface
{
type
client
interface
{
Group
()
*
group
Group
()
*
group
Id
()
string
Id
()
string
Username
()
string
Credentials
()
clientCredentials
pushConn
(
id
string
,
conn
upConnection
,
tracks
[]
upTrack
,
label
string
)
error
pushConn
(
id
string
,
conn
upConnection
,
tracks
[]
upTrack
,
label
string
)
error
pushClient
(
id
,
username
string
,
add
bool
)
error
pushClient
(
id
,
username
string
,
add
bool
)
error
}
}
disk.go
View file @
6bde5f98
...
@@ -32,8 +32,8 @@ func (client *diskClient) Id() string {
...
@@ -32,8 +32,8 @@ func (client *diskClient) Id() string {
return
client
.
id
return
client
.
id
}
}
func
(
client
*
diskClient
)
Username
()
string
{
func
(
client
*
diskClient
)
Credentials
()
clientCredentials
{
return
"RECORDING"
return
clientCredentials
{
"RECORDING"
,
""
}
}
}
func
(
client
*
diskClient
)
pushClient
(
id
,
username
string
,
add
bool
)
error
{
func
(
client
*
diskClient
)
pushClient
(
id
,
username
string
,
add
bool
)
error
{
...
...
group.go
View file @
6bde5f98
...
@@ -180,13 +180,13 @@ func delGroupUnlocked(name string) bool {
...
@@ -180,13 +180,13 @@ func delGroupUnlocked(name string) bool {
return
true
return
true
}
}
func
addClient
(
name
string
,
c
client
,
pass
string
)
(
*
group
,
error
)
{
func
addClient
(
name
string
,
c
client
)
(
*
group
,
error
)
{
g
,
err
:=
addGroup
(
name
,
nil
)
g
,
err
:=
addGroup
(
name
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
perms
,
err
:=
getPermission
(
g
.
description
,
c
.
Username
(),
pass
)
perms
,
err
:=
getPermission
(
g
.
description
,
c
.
Credentials
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -214,13 +214,15 @@ func addClient(name string, c client, pass string) (*group, error) {
...
@@ -214,13 +214,15 @@ func addClient(name string, c client, pass string) (*group, error) {
g
.
clients
[
c
.
Id
()]
=
c
g
.
clients
[
c
.
Id
()]
=
c
go
func
(
clients
[]
client
)
{
go
func
(
clients
[]
client
)
{
c
.
pushClient
(
c
.
Id
(),
c
.
Username
(),
true
)
u
:=
c
.
Credentials
()
.
Username
c
.
pushClient
(
c
.
Id
(),
u
,
true
)
for
_
,
cc
:=
range
clients
{
for
_
,
cc
:=
range
clients
{
err
:=
c
.
pushClient
(
cc
.
Id
(),
cc
.
Username
(),
true
)
uu
:=
cc
.
Credentials
()
.
Username
err
:=
c
.
pushClient
(
cc
.
Id
(),
uu
,
true
)
if
err
==
ErrClientDead
{
if
err
==
ErrClientDead
{
return
return
}
}
cc
.
pushClient
(
c
.
Id
(),
c
.
Username
()
,
true
)
cc
.
pushClient
(
c
.
Id
(),
u
,
true
)
}
}
}(
g
.
getClientsUnlocked
(
c
))
}(
g
.
getClientsUnlocked
(
c
))
...
@@ -240,7 +242,7 @@ func delClient(c client) {
...
@@ -240,7 +242,7 @@ func delClient(c client) {
go
func
(
clients
[]
client
)
{
go
func
(
clients
[]
client
)
{
for
_
,
cc
:=
range
clients
{
for
_
,
cc
:=
range
clients
{
cc
.
pushClient
(
c
.
Id
(),
c
.
Username
()
,
false
)
cc
.
pushClient
(
c
.
Id
(),
c
.
Credentials
()
.
Username
,
false
)
}
}
}(
g
.
getClientsUnlocked
(
nil
))
}(
g
.
getClientsUnlocked
(
nil
))
}
}
...
@@ -311,19 +313,15 @@ func (g *group) getChatHistory() []chatHistoryEntry {
...
@@ -311,19 +313,15 @@ func (g *group) getChatHistory() []chatHistoryEntry {
return
h
return
h
}
}
type
groupUser
struct
{
func
matchUser
(
user
clientCredentials
,
users
[]
clientCredentials
)
(
bool
,
bool
)
{
Username
string
`json:"username,omitempty"`
Password
string
`json:"password,omitempty"`
}
func
matchUser
(
user
,
pass
string
,
users
[]
groupUser
)
(
bool
,
bool
)
{
for
_
,
u
:=
range
users
{
for
_
,
u
:=
range
users
{
if
u
.
Username
==
""
{
if
u
.
Username
==
""
{
if
u
.
Password
==
""
||
u
.
Password
==
pass
{
if
u
.
Password
==
""
||
u
.
Password
==
user
.
Password
{
return
true
,
true
return
true
,
true
}
}
}
else
if
u
.
Username
==
user
{
}
else
if
u
.
Username
==
user
.
Username
{
return
true
,
(
u
.
Password
==
""
||
u
.
Password
==
pass
)
return
true
,
(
u
.
Password
==
""
||
u
.
Password
==
user
.
Password
)
}
}
}
}
return
false
,
false
return
false
,
false
...
@@ -337,9 +335,9 @@ type groupDescription struct {
...
@@ -337,9 +335,9 @@ type groupDescription struct {
MaxClients
int
`json:"max-clients,omitempty"`
MaxClients
int
`json:"max-clients,omitempty"`
AllowAnonymous
bool
`json:"allow-anonymous,omitempty"`
AllowAnonymous
bool
`json:"allow-anonymous,omitempty"`
AllowRecording
bool
`json:"allow-recording,omitempty"`
AllowRecording
bool
`json:"allow-recording,omitempty"`
Op
[]
groupUser
`json:"op,omitempty"`
Op
[]
clientCredentials
`json:"op,omitempty"`
Presenter
[]
groupUser
`json:"presenter,omitempty"`
Presenter
[]
clientCredentials
`json:"presenter,omitempty"`
Other
[]
groupUser
`json:"other,omitempty"`
Other
[]
clientCredentials
`json:"other,omitempty"`
}
}
func
descriptionChanged
(
name
string
,
old
*
groupDescription
)
(
bool
,
error
)
{
func
descriptionChanged
(
name
string
,
old
*
groupDescription
)
(
bool
,
error
)
{
...
@@ -384,18 +382,18 @@ func getDescription(name string) (*groupDescription, error) {
...
@@ -384,18 +382,18 @@ func getDescription(name string) (*groupDescription, error) {
return
&
desc
,
nil
return
&
desc
,
nil
}
}
type
user
Permission
struct
{
type
client
Permission
struct
{
Op
bool
`json:"op,omitempty"`
Op
bool
`json:"op,omitempty"`
Present
bool
`json:"present,omitempty"`
Present
bool
`json:"present,omitempty"`
Record
bool
`json:"record,omitempty"`
Record
bool
`json:"record,omitempty"`
}
}
func
getPermission
(
desc
*
groupDescription
,
user
,
pass
string
)
(
user
Permission
,
error
)
{
func
getPermission
(
desc
*
groupDescription
,
creds
clientCredentials
)
(
client
Permission
,
error
)
{
var
p
user
Permission
var
p
client
Permission
if
!
desc
.
AllowAnonymous
&&
user
==
""
{
if
!
desc
.
AllowAnonymous
&&
creds
.
Username
==
""
{
return
p
,
userError
(
"anonymous users not allowed in this group, please choose a username"
)
return
p
,
userError
(
"anonymous users not allowed in this group, please choose a username"
)
}
}
if
found
,
good
:=
matchUser
(
user
,
pas
s
,
desc
.
Op
);
found
{
if
found
,
good
:=
matchUser
(
cred
s
,
desc
.
Op
);
found
{
if
good
{
if
good
{
p
.
Op
=
true
p
.
Op
=
true
p
.
Present
=
true
p
.
Present
=
true
...
@@ -406,14 +404,14 @@ func getPermission(desc *groupDescription, user, pass string) (userPermission, e
...
@@ -406,14 +404,14 @@ func getPermission(desc *groupDescription, user, pass string) (userPermission, e
}
}
return
p
,
userError
(
"not authorised"
)
return
p
,
userError
(
"not authorised"
)
}
}
if
found
,
good
:=
matchUser
(
user
,
pas
s
,
desc
.
Presenter
);
found
{
if
found
,
good
:=
matchUser
(
cred
s
,
desc
.
Presenter
);
found
{
if
good
{
if
good
{
p
.
Present
=
true
p
.
Present
=
true
return
p
,
nil
return
p
,
nil
}
}
return
p
,
userError
(
"not authorised"
)
return
p
,
userError
(
"not authorised"
)
}
}
if
found
,
good
:=
matchUser
(
user
,
pas
s
,
desc
.
Other
);
found
{
if
found
,
good
:=
matchUser
(
cred
s
,
desc
.
Other
);
found
{
if
good
{
if
good
{
return
p
,
nil
return
p
,
nil
}
}
...
...
webclient.go
View file @
6bde5f98
...
@@ -86,8 +86,8 @@ func isWSNormalError(err error) bool {
...
@@ -86,8 +86,8 @@ func isWSNormalError(err error) bool {
type
webClient
struct
{
type
webClient
struct
{
group
*
group
group
*
group
id
string
id
string
username
string
credentials
clientCredentials
permissions
user
Permission
permissions
client
Permission
requested
map
[
string
]
uint32
requested
map
[
string
]
uint32
done
chan
struct
{}
done
chan
struct
{}
writeCh
chan
interface
{}
writeCh
chan
interface
{}
...
@@ -107,8 +107,8 @@ func (c *webClient) Id() string {
...
@@ -107,8 +107,8 @@ func (c *webClient) Id() string {
return
c
.
id
return
c
.
id
}
}
func
(
c
*
webClient
)
Username
()
string
{
func
(
c
*
webClient
)
Credentials
()
clientCredentials
{
return
c
.
username
return
c
.
credentials
}
}
func
(
c
*
webClient
)
pushClient
(
id
,
username
string
,
add
bool
)
error
{
func
(
c
*
webClient
)
pushClient
(
id
,
username
string
,
add
bool
)
error
{
...
@@ -172,7 +172,7 @@ type clientMessage struct {
...
@@ -172,7 +172,7 @@ type clientMessage struct {
Id
string
`json:"id,omitempty"`
Id
string
`json:"id,omitempty"`
Username
string
`json:"username,omitempty"`
Username
string
`json:"username,omitempty"`
Password
string
`json:"password,omitempty"`
Password
string
`json:"password,omitempty"`
Permissions
userPermission
`json:"permissions,omitempty"`
Permissions
clientPermission
`json:"permissions,omitempty"`
Group
string
`json:"group,omitempty"`
Group
string
`json:"group,omitempty"`
Value
string
`json:"value,omitempty"`
Value
string
`json:"value,omitempty"`
Me
bool
`json:"me,omitempty"`
Me
bool
`json:"me,omitempty"`
...
@@ -461,8 +461,8 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti
...
@@ -461,8 +461,8 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti
return
err
return
err
}
}
if
c
.
username
!=
""
{
if
u
:=
c
.
Credentials
()
.
Username
;
u
!=
""
{
up
.
label
=
c
.
username
up
.
label
=
u
}
}
err
=
up
.
pc
.
SetRemoteDescription
(
offer
)
err
=
up
.
pc
.
SetRemoteDescription
(
offer
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -631,7 +631,10 @@ func startClient(conn *websocket.Conn) (err error) {
...
@@ -631,7 +631,10 @@ func startClient(conn *websocket.Conn) (err error) {
c
:=
&
webClient
{
c
:=
&
webClient
{
id
:
m
.
Id
,
id
:
m
.
Id
,
username
:
m
.
Username
,
credentials
:
clientCredentials
{
m
.
Username
,
m
.
Password
,
},
actionCh
:
make
(
chan
interface
{},
10
),
actionCh
:
make
(
chan
interface
{},
10
),
done
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
}
}
...
@@ -662,7 +665,7 @@ func startClient(conn *websocket.Conn) (err error) {
...
@@ -662,7 +665,7 @@ func startClient(conn *websocket.Conn) (err error) {
c
.
writerDone
=
make
(
chan
struct
{})
c
.
writerDone
=
make
(
chan
struct
{})
go
clientWriter
(
conn
,
c
.
writeCh
,
c
.
writerDone
)
go
clientWriter
(
conn
,
c
.
writeCh
,
c
.
writerDone
)
g
,
err
:=
addClient
(
m
.
Group
,
c
,
m
.
Password
)
g
,
err
:=
addClient
(
m
.
Group
,
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -1015,7 +1018,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
...
@@ -1015,7 +1018,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
group
:
c
.
group
,
group
:
c
.
group
,
id
:
"recording"
,
id
:
"recording"
,
}
}
_
,
err
:=
addClient
(
c
.
group
.
name
,
disk
,
""
)
_
,
err
:=
addClient
(
c
.
group
.
name
,
disk
)
if
err
!=
nil
{
if
err
!=
nil
{
disk
.
Close
()
disk
.
Close
()
return
c
.
error
(
err
)
return
c
.
error
(
err
)
...
...
webserver.go
View file @
6bde5f98
...
@@ -334,7 +334,7 @@ func checkGroupPermissions(w http.ResponseWriter, r *http.Request, group string)
...
@@ -334,7 +334,7 @@ func checkGroupPermissions(w http.ResponseWriter, r *http.Request, group string)
return
false
return
false
}
}
p
,
err
:=
getPermission
(
desc
,
user
,
pass
)
p
,
err
:=
getPermission
(
desc
,
clientCredentials
{
user
,
pass
}
)
if
err
!=
nil
||
!
p
.
Record
{
if
err
!=
nil
||
!
p
.
Record
{
return
false
return
false
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment