Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
statsbot
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
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Janne Mareike Koschinski
statsbot
Commits
2e76436e
Verified
Commit
2e76436e
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Added references, significantly improved security
parent
b491c9f3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
glide.lock
+3
-2
3 additions, 2 deletions
glide.lock
glide.yaml
+1
-1
1 addition, 1 deletion
glide.yaml
main.go
+50
-12
50 additions, 12 deletions
main.go
with
54 additions
and
15 deletions
glide.lock
+
3
−
2
View file @
2e76436e
hash:
71071f00798b1f4ce22ab71a61bbaccc0a10c7cb9e0a9acd0ac8c868c843d46d
hash:
9aa87de7030f5b57ee15949488773eed43794051d931d592b57d01ba08baa1b3
updated: 2018-05-24T0
1:08:01.558664212
+02:00
updated: 2018-05-24T0
2:24:44.532048957
+02:00
imports:
imports:
- name: github.com/lib/pq
- name: github.com/lib/pq
version: 90697d60dd844d5ef6ff15135d0203f65d2f53b8
version: 90697d60dd844d5ef6ff15135d0203f65d2f53b8
...
@@ -10,5 +10,6 @@ imports:
...
@@ -10,5 +10,6 @@ imports:
- name: golang.org/x/crypto
- name: golang.org/x/crypto
version: 75e913eb8a8e3d31a97b216de09de106a7b07681
version: 75e913eb8a8e3d31a97b216de09de106a7b07681
subpackages:
subpackages:
- scrypt
- sha3
- sha3
testImports: []
testImports: []
This diff is collapsed.
Click to expand it.
glide.yaml
+
1
−
1
View file @
2e76436e
...
@@ -4,4 +4,4 @@ import:
...
@@ -4,4 +4,4 @@ import:
-
package
:
github.com/lib/pq
-
package
:
github.com/lib/pq
-
package
:
golang.org/x/crypto
-
package
:
golang.org/x/crypto
subpackages
:
subpackages
:
-
sha3
-
scrypt
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.go
+
50
−
12
View file @
2e76436e
...
@@ -7,11 +7,11 @@ import (
...
@@ -7,11 +7,11 @@ import (
"strings"
"strings"
"log"
"log"
"time"
"time"
"golang.org/x/crypto/sha3"
_
"github.com/lib/pq"
_
"github.com/lib/pq"
"encoding/hex"
"encoding/hex"
"database/sql"
"database/sql"
"strconv"
"strconv"
"golang.org/x/crypto/scrypt"
)
)
type
Config
struct
{
type
Config
struct
{
...
@@ -59,6 +59,12 @@ func NewConfigFromEnv() Config {
...
@@ -59,6 +59,12 @@ func NewConfigFromEnv() Config {
return
config
return
config
}
}
type
IrcChannel
struct
{
Id
int
Name
string
Salt
string
}
type
IrcMessage
struct
{
type
IrcMessage
struct
{
Time
time
.
Time
Time
time
.
Time
Channel
int
Channel
int
...
@@ -97,6 +103,14 @@ func (m *IrcMessage) ToString() string {
...
@@ -97,6 +103,14 @@ func (m *IrcMessage) ToString() string {
return
fmt
.
Sprintf
(
"IrcMessage{time=%s,channel=%d,sender=%s,words=%d,characters=%d,flags=[%s]}"
,
m
.
Time
.
Format
(
time
.
RFC3339
),
m
.
Channel
,
m
.
Sender
,
m
.
Words
,
m
.
Characters
,
strings
.
Join
(
flags
,
","
))
return
fmt
.
Sprintf
(
"IrcMessage{time=%s,channel=%d,sender=%s,words=%d,characters=%d,flags=[%s]}"
,
m
.
Time
.
Format
(
time
.
RFC3339
),
m
.
Channel
,
m
.
Sender
,
m
.
Words
,
m
.
Characters
,
strings
.
Join
(
flags
,
","
))
}
}
func
hashName
(
salt
string
,
name
string
)
string
{
hash
,
err
:=
scrypt
.
Key
([]
byte
(
name
),
[]
byte
(
salt
),
32768
,
8
,
1
,
32
)
if
err
!=
nil
{
panic
(
err
)
}
return
hex
.
EncodeToString
(
hash
)
}
func
main
()
{
func
main
()
{
config
:=
NewConfigFromEnv
()
config
:=
NewConfigFromEnv
()
...
@@ -122,20 +136,25 @@ func main() {
...
@@ -122,20 +136,25 @@ func main() {
}
}
client
:=
girc
.
New
(
ircConfig
)
client
:=
girc
.
New
(
ircConfig
)
channels
:=
map
[
string
]
int
{}
channels
:=
map
[
string
]
IrcChannel
{}
client
.
Handlers
.
Add
(
girc
.
CONNECTED
,
func
(
c
*
girc
.
Client
,
e
girc
.
Event
)
{
client
.
Handlers
.
Add
(
girc
.
CONNECTED
,
func
(
c
*
girc
.
Client
,
e
girc
.
Event
)
{
result
,
err
:=
db
.
Query
(
"SELECT id, channel FROM channels"
)
result
,
err
:=
db
.
Query
(
"SELECT id, channel
, salt
FROM channels"
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
for
result
.
Next
()
{
for
result
.
Next
()
{
var
id
int
var
id
int
var
name
string
var
name
string
err
:=
result
.
Scan
(
&
id
,
&
name
)
var
salt
string
err
:=
result
.
Scan
(
&
id
,
&
name
,
&
salt
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
channels
[
name
]
=
id
channels
[
name
]
=
IrcChannel
{
Id
:
id
,
Name
:
name
,
Salt
:
salt
,
}
}
}
for
name
:=
range
channels
{
for
name
:=
range
channels
{
c
.
Cmd
.
Join
(
name
)
c
.
Cmd
.
Join
(
name
)
...
@@ -144,15 +163,34 @@ func main() {
...
@@ -144,15 +163,34 @@ func main() {
client
.
Handlers
.
Add
(
girc
.
PRIVMSG
,
func
(
c
*
girc
.
Client
,
e
girc
.
Event
)
{
client
.
Handlers
.
Add
(
girc
.
PRIVMSG
,
func
(
c
*
girc
.
Client
,
e
girc
.
Event
)
{
if
len
(
e
.
Params
)
==
1
{
if
len
(
e
.
Params
)
==
1
{
channel
:=
e
.
Params
[
0
]
channelName
:=
e
.
Params
[
0
]
if
id
,
ok
:=
channels
[
channel
];
ok
{
if
channelData
,
ok
:=
channels
[
channelName
];
ok
{
name
:=
hex
.
EncodeToString
(
sha3
.
New256
()
.
Sum
([]
byte
(
e
.
Source
.
Name
)))
now
:=
time
.
Now
()
.
UTC
()
name
:=
hashName
(
channelData
.
Salt
,
e
.
Source
.
Name
)
content
:=
strings
.
TrimSpace
(
e
.
Trailing
)
content
:=
strings
.
TrimSpace
(
e
.
Trailing
)
// Add referenced nick part here
// c.LookupChannel(channel).UserList
channel
:=
c
.
LookupChannel
(
channelName
)
var
users
[]
string
if
channel
!=
nil
{
for
_
,
user
:=
range
channel
.
UserList
{
if
strings
.
Contains
(
content
,
user
)
{
users
=
append
(
users
,
hashName
(
channelData
.
Salt
,
user
))
}
}
}
for
_
,
user
:=
range
users
{
_
,
err
:=
db
.
Exec
(
"INSERT INTO
\"
references
\"
(time, source, target) VALUES ($1, $2, $3)"
,
now
,
name
,
user
)
if
err
!=
nil
{
println
(
err
.
Error
())
}
}
message
:=
IrcMessage
{
message
:=
IrcMessage
{
Time
:
time
.
Now
()
.
UTC
()
,
Time
:
now
,
Channel
:
i
d
,
Channel
:
channelData
.
I
d
,
Sender
:
name
,
Sender
:
name
,
Words
:
len
(
strings
.
Split
(
content
,
" "
)),
Words
:
len
(
strings
.
Split
(
content
,
" "
)),
Characters
:
len
(
content
),
Characters
:
len
(
content
),
...
...
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