2021-12-06 05:08:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gitea.benny.dog/torjus/ezshare/actions"
|
2021-12-08 04:42:25 +00:00
|
|
|
"gitea.benny.dog/torjus/ezshare/ezshare"
|
2021-12-06 05:08:17 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
cli.VersionFlag = &cli.BoolFlag{Name: "version"}
|
|
|
|
app := cli.App{
|
|
|
|
Name: "ezshare",
|
2021-12-08 04:42:25 +00:00
|
|
|
Version: ezshare.Version,
|
2021-12-06 05:08:17 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Usage: "Path to config-file.",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "verbose",
|
|
|
|
Aliases: []string{"v"},
|
|
|
|
Usage: "Be more verbose",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "serve",
|
|
|
|
Usage: "Start ezshare server",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-grpc",
|
|
|
|
Usage: "Do not enable grpc.",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-http",
|
|
|
|
Usage: "Do not enable http.",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "grpc-addr",
|
|
|
|
Usage: "Address to listen for grpc.",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "http-addr",
|
|
|
|
Usage: "Address to listen for http.",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "hostname",
|
|
|
|
Usage: "Hostname used in links",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: actions.ActionServe,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "client",
|
|
|
|
Usage: "Client commands",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "addr",
|
|
|
|
Usage: "Address of server.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "get",
|
|
|
|
Usage: "Get file with id",
|
|
|
|
ArgsUsage: "ID [ID]..",
|
|
|
|
Action: actions.ActionClientGet,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "upload",
|
|
|
|
Usage: "Upload file(s)",
|
|
|
|
ArgsUsage: "PATH [PATH]..",
|
2021-12-06 19:13:04 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "with-passcode",
|
|
|
|
Usage: "Require passcode to view",
|
|
|
|
},
|
|
|
|
&cli.DurationFlag{
|
|
|
|
Name: "ttl",
|
|
|
|
Usage: "Expire file when duration has passed",
|
|
|
|
},
|
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "max-views",
|
|
|
|
Usage: "Limit the amount of times the file can be viewed.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: actions.ActionClientUpload,
|
2021-12-06 05:08:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "delete",
|
|
|
|
Usage: "Delete file with id",
|
|
|
|
ArgsUsage: "ID [ID]..",
|
|
|
|
Action: actions.ActionClientDelete,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "List files",
|
|
|
|
Action: actions.ActionClientList,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "login",
|
|
|
|
Usage: "Login and retrieve client cert",
|
|
|
|
ArgsUsage: "[PROTO://]HOSTNAME[:PORT]",
|
|
|
|
Action: actions.ActionClientLogin,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "username",
|
|
|
|
Usage: "Username used for login.",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "overwrite",
|
|
|
|
Usage: "Overwrite existing config",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-12-08 05:54:51 +00:00
|
|
|
Name: "password",
|
2021-12-06 05:53:49 +00:00
|
|
|
Usage: "Change password",
|
2021-12-08 05:54:51 +00:00
|
|
|
Action: actions.ActionClientPassword,
|
2021-12-06 05:08:17 +00:00
|
|
|
},
|
2021-12-08 04:42:25 +00:00
|
|
|
{
|
|
|
|
Name: "update",
|
|
|
|
Usage: "Download the latest ezshare",
|
|
|
|
Action: actions.ActionClientUpdate,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "out-dir",
|
|
|
|
Usage: "Directory where binary is saved",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-08 05:54:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "admin",
|
|
|
|
Usage: "Admin commands",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "upload",
|
|
|
|
Usage: "Upload binaries to be served",
|
|
|
|
ArgsUsage: "FILENAME [FILENAME...]",
|
|
|
|
Action: actions.ActionAdminUploadBinary,
|
|
|
|
},
|
2021-12-06 18:14:39 +00:00
|
|
|
{
|
|
|
|
Name: "cert",
|
|
|
|
Usage: "Certificate-related commands",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "List certificates",
|
2021-12-08 05:54:51 +00:00
|
|
|
Action: actions.ActionAdminCertList,
|
2021-12-06 18:14:39 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "revoke",
|
|
|
|
Usage: "Revoke certificate(s)",
|
|
|
|
ArgsUsage: "SERIAL [SERIAL...]",
|
2021-12-08 05:54:51 +00:00
|
|
|
Action: actions.ActionAdminCertRevoke,
|
2021-12-06 18:14:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-06 05:08:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "cert",
|
|
|
|
Usage: "Certificate commands",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "gen-all",
|
|
|
|
Usage: "Generate CA, Server and Client certificates",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "out-dir",
|
|
|
|
Usage: "Directory where certificates will be stored.",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "hostname",
|
|
|
|
Usage: "Hostname used for server certificate.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: actions.ActionGencerts,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error: %s\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|