-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Telegram connector (#1) * Initial telegram interface implementation * bump go version to 1.21.3 * update doc; remove debug logging * actions/[email protected] * goreleaser: add goarch, goarm params * sync fork (#2) * sync fork * SSL certs (#3) * SSL certs required to connect telegram API --------- Co-authored-by: Vlad <[email protected]> Co-authored-by: Vlad <[email protected]>
- Loading branch information
1 parent
831c76c
commit e58ef15
Showing
14 changed files
with
665 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ jobs: | |
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-22.04 | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE | ||
|
@@ -29,7 +29,7 @@ jobs: | |
- name: Setup go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.19 | ||
go-version: 1.21.3 | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ jobs: | |
steps: | ||
- | ||
name: Checkout | ||
uses: actions/[email protected].1.1 | ||
uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
builds: | ||
- ldflags: | ||
- env: | ||
- CGO_ENABLED=0 | ||
- GO111MODULE=on | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm | ||
- arm64 | ||
goarm: | ||
- "6" | ||
- "7" | ||
ldflags: | ||
- -s -w -X main.BuildVersion={{.Version}} -X main.Commit={{.Commit}} -X main.BuildDate={{.Date}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# FTPServer Telegram connector | ||
|
||
[](https://stand-with-ukraine.pp.ua) | ||
|
||
## Register bot | ||
|
||
Read about telegram bots at https://core.telegram.org/bots/tutorial. | ||
|
||
Bots are not allowed to contact users. You need to make the first contact from the user for which you want to set up the bot. | ||
|
||
### Quick start | ||
|
||
- Create a bot with [@BotFather](https://t.me/BotFather), let's say with username `my_ftp_bot` | ||
- Get bot token from BotFather's response, use it as `Token` in config | ||
- Get bot id by run `curl https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getMe` | ||
- Find `@my_ftp_bot` in telegram and start chat with it | ||
- Send `/start` to bot | ||
- Run `curl https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates` and find your chat id in response, use it as `ChatID` in config | ||
|
||
|
||
## Config example | ||
|
||
Please note about `shared` flag. If it's `true` then bot instance will be shared between all connections. | ||
If it's `false` then each user (or even each ftp connection) will have own bot instance and it can lead to telegram bot flood protection. | ||
|
||
```json | ||
{ | ||
"version": 1, | ||
"accesses": [ | ||
{ | ||
"fs": "telegram", | ||
"shared": true, | ||
"user": "my_ftp_bot", | ||
"pass": "my_secure_password", | ||
"params": { | ||
"Token": "<YOUR_BOT_TOKEN>", | ||
"ChatID": "<YOUR_CHAT_ID>" | ||
} | ||
|
||
} | ||
], | ||
"passive_transfer_port_range": { | ||
"start": 2122, | ||
"end": 2130 | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": 1, | ||
"accesses": [ | ||
{ | ||
"fs": "telegram", | ||
"shared": true, | ||
"user": "test", | ||
"pass": "test", | ||
"params": { | ||
"Token": "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", | ||
"ChatID": "123456789" | ||
} | ||
|
||
} | ||
], | ||
"passive_transfer_port_range": { | ||
"start": 2122, | ||
"end": 2130 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package telegram | ||
|
||
import ( | ||
"os" | ||
"sync" | ||
) | ||
|
||
// fakeFilesystem is a really simple and limited fake filesystem intended for store temporary info about files | ||
// since some ftp clients expect to perform mkdir() + stat() on files and directories before upload | ||
type fakeFilesystem struct { | ||
sync.Mutex | ||
dict map[string]*FileInfo | ||
// dir fakeDir | ||
} | ||
|
||
type fakeDir struct { | ||
name string | ||
content []os.FileInfo | ||
} | ||
|
||
// newFakeFilesystem creates a new fake filesystem | ||
func newFakeFilesystem() *fakeFilesystem { | ||
return &fakeFilesystem{ | ||
dict: map[string]*FileInfo{}, | ||
// dir: fakeDir{content: []os.FileInfo{}}, | ||
} | ||
} | ||
|
||
// mkdir creates a directory | ||
func (f *fakeFilesystem) mkdir(name string, mode os.FileMode) { | ||
f.Lock() | ||
defer f.Unlock() | ||
f.dict[name] = &FileInfo{&FileData{ | ||
name: name, | ||
dir: true, | ||
mode: mode, | ||
}} | ||
} | ||
|
||
// create creates a file | ||
func (f *fakeFilesystem) create(name string) { | ||
f.Lock() | ||
defer f.Unlock() | ||
f.dict[name] = &FileInfo{&FileData{ | ||
name: name, | ||
dir: false, | ||
}} | ||
} | ||
|
||
// setSize sets the size of a file | ||
func (f *fakeFilesystem) setSize(name string, size int64) { | ||
f.Lock() | ||
defer f.Unlock() | ||
if fileInfo, found := f.dict[name]; found { | ||
fileInfo.size = size | ||
} | ||
} | ||
|
||
// stat returns a file info | ||
func (f *fakeFilesystem) stat(name string) *FileInfo { | ||
f.Lock() | ||
defer f.Unlock() | ||
return f.dict[name] | ||
} | ||
|
||
// remove removes a file | ||
func (f *fakeFilesystem) remove(name string) { | ||
f.Lock() | ||
defer f.Unlock() | ||
delete(f.dict, name) | ||
} | ||
|
||
// exists checks if a file exists | ||
func (f *fakeFilesystem) exists(name string) bool { | ||
f.Lock() | ||
defer f.Unlock() | ||
_, ok := f.dict[name] | ||
return ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package telegram | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
// FileData is a simple structure to store file information and implement os.FileInfo interface | ||
type FileData struct { | ||
name string | ||
dir bool | ||
mode os.FileMode | ||
modtime time.Time | ||
size int64 | ||
} | ||
|
||
type FileInfo struct { | ||
*FileData | ||
} | ||
|
||
// Implements os.FileInfo | ||
func (s *FileInfo) Name() string { | ||
_, name := filepath.Split(s.name) | ||
return name | ||
} | ||
|
||
func (s *FileInfo) Mode() os.FileMode { return s.mode } | ||
func (s *FileInfo) ModTime() time.Time { return s.modtime } | ||
func (s *FileInfo) IsDir() bool { return s.dir } | ||
func (s *FileInfo) Sys() interface{} { return nil } | ||
func (s *FileInfo) Size() int64 { | ||
if s.IsDir() { | ||
return int64(42) | ||
} | ||
return s.size | ||
} |
Oops, something went wrong.