telegram

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const BUTTONS_TIP = `- Click 'Del' to delete
- It works in active executor
- To add from history, send /history`
View Source
const EXECUTORS_TIP = `- Click 'Del' to delete
- To refresh, send /executors
- To add new, use /addexecutor`
View Source
const FILES_TIP = `- Click '↓' to get
- To narrow, use /files <prefix>`
View Source
const HELP_TEXT = `` /* 1562-byte string literal not displayed */
View Source
const HISTORY_TIP = `- Click 'Run' to execute
- Click 'Add' to save to buttons
- It works in active executor
- To del buttons, send /buttons`
View Source
const MSG_EXECUTOR_NOT_FOUND_TPL = "Executor '%s' not found"
View Source
const MSG_IGNORE_BELATED = "ignore message that arrived too late"
View Source
const MSG_INVALID = "Invalid"
View Source
const MSG_RESETSECRET = "Services secret resetted. To gain access again, send /services"
View Source
const MSG_RESET_EXECUTOR = "Active executor changed to default"
View Source
const MSG_START = "Welcome & Congratulations! You have configured tgshell sucessfully.\nFor help, send /help\n"
View Source
const MSG_SUCCESS = "Success"
View Source
const MSG_UNSUPPORTED_TYPE = "Unsupported msg type. Send a cmdline text to run it in active executor; " +
	"Send a file (not gallery or music) to save it to the current working directory of server"
View Source
const SERVICES_TIP = `` /* 155-byte string literal not displayed */
View Source
const TYPE_CLOSE = "close"
View Source
const TYPE_GLOBAL = "global"
View Source
const TYPE_REPLY = "reply"
View Source
const USAGE_ADDBTN = "Usage: /addbtn <cmdline>"
View Source
const USAGE_ADDCMD = `Usage: /addcmd <name> <cmdline>
E.g.: /addcmd ping ping -c 5 8.8.8.8`
View Source
const USAGE_ADDEXECUTOR = `Usage: /addexecutor <name> <type> [config]
E.g.: /addexecutor myssh ssh 1.2.3.4`
View Source
const USAGE_CD = `Usage: /cd [dir]
[dir] default to user home dir`
View Source
const USAGE_CLEARBTN = "Usage: /clearbtn <executor>"
View Source
const USAGE_DELBTN = "Usage: /delbtn <cmdline_prefix>"
View Source
const USAGE_DELCMD = `Usage: /delcmd <name>
E.g.: /delcmd ping`
View Source
const USAGE_DELEXECUTOR = `Usage: /delexecutor <name>
E.g.: /delexecutor myssh`
View Source
const USAGE_GETFILE = "Usage: /getfile /path/to/file.txt"
View Source
const USAGE_RAW = `Usage: /raw <sequence>
<sequence> is a C-style escape string. E.g.:
\x03pwd\n : Send 0x03 (Ctrl-C) + "pwd" + "\n"`
View Source
const USAGE_RUN = `Usage: /run <cmdline>
E.g.: /run /usr/bin/ls -lh`
View Source
const USAGE_SETSECRET = `Usage: /setsecret <executor> [secret]
If [secret] is empty, clear it`

Variables

View Source
var CTRL_SEQUENCE_REGEXP = regexp.MustCompile(`^(?i)(Ctrl[-\+]|\^)(?P<char>\S)$`)

Functions

func Start

func Start(ctx context.Context)

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

type ServicesProxy

type ServicesProxy struct {
	// contains filtered or unexported fields
}

func NewServicesProxy

func NewServicesProxy(serviceConfigs []*config.ConfigServiceStruct, addr string,
	port int, publicport int, https bool, secret string) (
	*ServicesProxy, error)

Service flow: 1. user send /services in tg. 2. bot generate token and send http://<public_url>/__auth__/<token> to user. 3. User click the link which has tokens, reverse proxy set "Set-Cookie" header, then redirecting to /. 4. Reverse proxy check every incoming request for valid cookie before forwarding to backend. <token> : one-time use token for generating cookie, will expire soon. <cookie> : long-time valid token.

func (*ServicesProxy) GetUrl

func (sp *ServicesProxy) GetUrl(service string) (string, error)

get service url (with auth token), click the url will set the token and then redirect to service root

func (*ServicesProxy) UpdateSecret

func (sp *ServicesProxy) UpdateSecret(secret string)

type TgActiveSessions

type TgActiveSessions map[int64](string)

chatid => sessionName

func (TgActiveSessions) GetActiveSessionName

func (as TgActiveSessions) GetActiveSessionName(chatid int64) string

func (TgActiveSessions) IsActiveSession

func (as TgActiveSessions) IsActiveSession(chatid int64, sessionName string) bool

func (TgActiveSessions) IsDefaultExecutorActive

func (as TgActiveSessions) IsDefaultExecutorActive(chatid int64) bool

type TgCommad

type TgCommad struct {
	Name    string
	Payload string
	Chatid  int64
	C       tele.Context // telebot ctx
	Output  chan<- string
	// contains filtered or unexported fields
}

type TgExecutorSession

type TgExecutorSession struct {
	Executor executor.Executor
	Chatid   int64
	Ready    bool
}

type TgGlobalMsg

type TgGlobalMsg struct {
	// "global": global message which does NOT belong to a session.
	// "close": a open executor session closed.
	// "reply": reply to a user sent message, C is set
	//  Others: send data to user directly, Chatid is set
	Type     string
	Executor string // executor name
	Data     string
	Chatid   int64        // owning chatid
	C        tele.Context // telebot ctx
}

func (*TgGlobalMsg) GetSessionName

func (tgm *TgGlobalMsg) GetSessionName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL