Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cf-online-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KS Pardubický kraj
cf-online-api
Commits
bc532022
Verified
Commit
bc532022
authored
4 years ago
by
Andrej Ramašeuski
Browse files
Options
Downloads
Patches
Plain Diff
Lepsi pocitani, prepnuti na Mojo::Pg
parent
65f42b64
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/CF/Controller/Websockets.pm
+45
-23
45 additions, 23 deletions
lib/CF/Controller/Websockets.pm
with
45 additions
and
23 deletions
lib/CF/Controller/Websockets.pm
+
45
−
23
View file @
bc532022
...
@@ -8,13 +8,12 @@ use POSIX qw(ceil);
...
@@ -8,13 +8,12 @@ use POSIX qw(ceil);
use
feature
'
signatures
';
use
feature
'
signatures
';
no
warnings
qw{ experimental::signatures }
;
no
warnings
qw{ experimental::signatures }
;
use
constant
SOCKET_INACTIVITY_TIMEOUT
=>
30
0
;
use
constant
SOCKET_INACTIVITY_TIMEOUT
=>
18
0
;
sub
main
{
sub
main
{
my
$c
=
shift
;
my
$c
=
shift
;
my
$ip
=
$c
->
tx
->
remote_address
;
my
$ip
=
$c
->
tx
->
remote_address
;
my
$key
=
$c
->
req
->
headers
->
header
('
Sec-WebSocket-Key
');
my
$user
;
$c
->
inactivity_timeout
(
SOCKET_INACTIVITY_TIMEOUT
);
$c
->
inactivity_timeout
(
SOCKET_INACTIVITY_TIMEOUT
);
...
@@ -25,29 +24,53 @@ sub main {
...
@@ -25,29 +24,53 @@ sub main {
});
});
$c
->
on
(
json
=>
sub
(
$c
,
$message
)
{
$c
->
on
(
json
=>
sub
(
$c
,
$message
)
{
if
(
$message
->
{
event
}
eq
'
KEEPALIVE
'
)
{
if
(
$message
->
{
event
}
eq
'
KEEPALIVE
'
)
{
if
(
$message
->
{
payload
}
=~
/^(\d+)$/
)
{
my
$user
;
# TODO: check signtaure
if
(
$message
->
{
payload
}
=~
/^\d+$/
)
{
$user
=
$c
->
pg
->
db
->
select
('
users
',
[
qw(id username secret jitsi_allowed roles banned_until)
],
{
id
=>
$message
->
{
payload
}}
)
->
hash
;
}
$user
//
=
$c
->
schema
->
resultset
('
User
')
->
find
(
if
(
$user
)
{
{
id
=>
$
1
}
my
$sig
=
hmac_sha1_hex
(
$message
->
{
payload
},
$user
->
{
secret
}
);
if
(
$sig
ne
$message
->
{
sig
}
)
{
$c
->
app
->
log
->
warn
(
"
Invalid signature for
"
.
$user
->
{
username
}
);
);
$user
=
undef
;
}
}
}
eval
{
my
$tx
=
$c
->
pg
->
db
->
begin
;
$c
->
schema
->
resultset
('
Socket
')
->
update_or_create
({
$c
->
pg
->
db
->
delete
('
sockets
',
[
id
=>
$c
->
req
->
headers
->
header
('
Sec-WebSocket-Key
'),
{
id
=>
$key
},
{
user_id
=>
$message
->
{
payload
}},
]);
$c
->
pg
->
db
->
insert
('
sockets
',
{
id
=>
$key
,
ip
=>
$ip
,
ip
=>
$ip
,
keepalive
=>
\
'
now()
',
keepalive
=>
\
'
now()
',
user_id
=>
$user
?
$user
->
id
:
undef
,
user_id
=>
$user
?
$user
->
{
id
}
:
undef
,
},
{
key
=>
$user
?
'
user
':'
primary
'}
);
}
);
my
$all
=
$c
->
schema
->
resultset
('
Socket_view
')
->
count
();
$tx
->
commit
;
};
my
$members
=
$c
->
schema
->
resultset
('
Socket_view
')
->
count
(
my
$all
=
$c
->
pg
->
db
->
query
(
{
is_member
=>
'
t
'
}
'
select count(*) from sockets_view
'
);
)
->
hash
->
{
count
};
my
$members
=
$c
->
pg
->
db
->
query
(
'
select count(*) from sockets_view where is_member
'
)
->
hash
->
{
count
};
my
$group_size
=
$c
->
_member_group_size
(
$members
);
my
$group_size
=
$c
->
_member_group_size
(
$members
);
...
@@ -59,15 +82,14 @@ sub main {
...
@@ -59,15 +82,14 @@ sub main {
}}});
}}});
if
(
$user
)
{
if
(
$user
)
{
my
$jitsi
=
$user
->
jitsi_allowed
||
$user
->
roles
=~
/chairman/
;
my
$jitsi
=
$user
->
{
jitsi_allowed
}
||
$user
->
{
roles
}
=~
/chairman
|jitsi
/
;
$c
->
send
({
json
=>
{
event
=>
'
user_status
',
payload
=>
{
$c
->
send
({
json
=>
{
event
=>
'
user_status
',
payload
=>
{
jitsi_allowed
=>
$jitsi
?
\
1
:
\
0
,
jitsi_allowed
=>
$jitsi
?
\
1
:
\
0
,
is_banned
=>
$user
->
banned_until
?
\
1
:
\
0
,
is_banned
=>
$user
->
{
banned_until
}
?
\
1
:
\
0
,
}}});
}}});
}
}
}
}
});
});
$c
->
on
(
finish
=>
sub
($c, $code, $reason = undef) {
$c
->
on
(
finish
=>
sub
($c, $code, $reason = undef) {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment