Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Dec 4, 2020
1 parent 4cd909b commit e6175f5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

# Ignore Tor embedded process data directory
**/tor-data*
**/data-dir*
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.3] - 2020-12-03

### Fixed
- Small fix.

## [0.5.2] - 2020-11-28

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PACKDIR ?= ./build/package
LDFLAGS := $(shell echo "-X 'wayback/version.Version=`git describe --tags --abbrev=0`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X 'wayback/version.Commit=`git rev-parse --short HEAD`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X 'wayback/version.BuildDate=`date +%FT%T%z`'")
GOBUILD ?= CGO_ENABLED=0 go build --ldflags="-s -w ${LDFLAGS}" -v
GOBUILD ?= CGO_ENABLED=0 go build -trimpath --ldflags "-s -w ${LDFLAGS} -buildid=" -v
VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1` | sed -e 's/v//g')
GOFILES ?= $(wildcard ./cmd/wayback/*.go)
PROJECT := github.com/wabarc/wayback
Expand Down
44 changes: 32 additions & 12 deletions cmd/wayback/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func checkRequiredFlags(cmd *cobra.Command, args []string) error {
for _, d := range daemon {
switch d {
case "telegram":
if strings.TrimSpace(token) == "" {
if flags.Changed("token") && strings.TrimSpace(token) == "" {
return errors.New("Token of the Telegram Bot is required to run as Telegram service.")
}
case "web":
Expand All @@ -90,24 +90,44 @@ func checkRequiredFlags(cmd *cobra.Command, args []string) error {
return nil
}

func setToEnv() {
os.Setenv("WAYBACK_IPFS_HOST", host)
os.Setenv("WAYBACK_IPFS_PORT", fmt.Sprint(port))
os.Setenv("WAYBACK_IPFS_MODE", mode)
os.Setenv("WAYBACK_USE_TOR", fmt.Sprint(tor))
os.Setenv("WAYBACK_ENABLE_IA", fmt.Sprint(ia))
os.Setenv("WAYBACK_ENABLE_IS", fmt.Sprint(is))
os.Setenv("WAYBACK_ENABLE_IP", fmt.Sprint(ip))
os.Setenv("WAYBACK_TELEGRAM_TOKEN", token)
os.Setenv("WAYBACK_TELEGRAM_CHANNEL", chatid)
func setToEnv(cmd *cobra.Command) {
flags := cmd.Flags()

if flags.Changed("ia") {
os.Setenv("WAYBACK_ENABLE_IA", fmt.Sprint(ia))
}
if flags.Changed("is") {
os.Setenv("WAYBACK_ENABLE_IS", fmt.Sprint(is))
}
if flags.Changed("ip") {
os.Setenv("WAYBACK_ENABLE_IP", fmt.Sprint(ip))
}
if flags.Changed("token") {
os.Setenv("WAYBACK_TELEGRAM_TOKEN", token)
}
if flags.Changed("chatid") {
os.Setenv("WAYBACK_TELEGRAM_CHANNEL", chatid)
}
if flags.Changed("host") {
os.Setenv("WAYBACK_IPFS_HOST", host)
}
if flags.Changed("port") {
os.Setenv("WAYBACK_IPFS_PORT", fmt.Sprint(port))
}
if flags.Changed("mode") {
os.Setenv("WAYBACK_IPFS_MODE", mode)
}
if flags.Changed("tor") {
os.Setenv("WAYBACK_USE_TOR", fmt.Sprint(tor))
}
}

func handle(cmd *cobra.Command, args []string) {
if !ia && !is && !ip {
ia, is = true, true
}

setToEnv()
setToEnv(cmd)
parser := config.NewParser()

var err error
Expand Down
19 changes: 11 additions & 8 deletions service/anonymity/tor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (t *tor) Serve(ctx context.Context) error {

verbose := t.opts.HasDebugMode()
// startConf := &embedTor.StartConf{ProcessCreator: libtor.Creator, DataDir: "tor-data"}
startConf := &embedTor.StartConf{DataDir: "tor-data"}
startConf := &embedTor.StartConf{}
if verbose {
startConf.DebugWriter = os.Stdout
} else {
Expand Down Expand Up @@ -158,22 +158,25 @@ func (t *tor) archive(ctx context.Context, text string) (c *template.Collector,

wg := sync.WaitGroup{}
var wbrc wayback.Broker = &wayback.Handle{URLs: urls, Opts: t.opts}
for slot, do := range t.opts.Slots() {
for slot, arc := range t.opts.Slots() {
if !arc {
continue
}
wg.Add(1)
go func(slot string, do bool, c *template.Collector) {
go func(slot string, c *template.Collector) {
defer wg.Done()
switch {
case slot == config.SLOT_IA && do:
switch slot {
case config.SLOT_IA:
logger.Debug("Web: archiving slot: %s", slot)
transform(c, config.SlotName(slot), wbrc.IA())
case slot == config.SLOT_IS && do:
case config.SLOT_IS:
logger.Debug("Web: archiving slot: %s", slot)
transform(c, config.SlotName(slot), wbrc.IS())
case slot == config.SLOT_IP && do:
case config.SLOT_IP:
logger.Debug("Web: archiving slot: %s", slot)
transform(c, config.SlotName(slot), wbrc.IP())
}
}(slot, do, c)
}(slot, c)
}
wg.Wait()

Expand Down
25 changes: 14 additions & 11 deletions service/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,33 @@ type collect struct {
}

func (c *collect) archive(t *telegram, msgid int, urls []string) (int, error) {
logger.Debug("Telegram: archives starg...")
logger.Debug("Telegram: archives start...")
p := *c

wg := sync.WaitGroup{}
var wbrc wayback.Broker = &wayback.Handle{URLs: urls, Opts: t.opts}
for slot, do := range t.opts.Slots() {
for slot, arc := range t.opts.Slots() {
if !arc {
continue
}
wg.Add(1)
go func(slot string, do bool, c *collect) {
go func(slot string) {
defer wg.Done()
switch {
case slot == config.SLOT_IA && do:
switch slot {
case config.SLOT_IA:
logger.Debug("Telegram: archiving slot: %s", slot)
p.Arc = append(p.Arc, fmt.Sprintf("<a href='https://web.archive.org/'>%s</a>", config.SlotName(slot)))
p.Dst = append(p.Dst, wbrc.IA())
case slot == config.SLOT_IS && do:
p.Arc = append(p.Arc, fmt.Sprintf("<a href='https://web.archive.org/'>%s</a>", config.SlotName(slot)))
case config.SLOT_IS:
logger.Debug("Telegram: archiving slot: %s", slot)
p.Arc = append(p.Arc, fmt.Sprintf("<a href='https://archive.today/'>%s</a>", config.SlotName(slot)))
p.Dst = append(p.Dst, wbrc.IS())
case slot == config.SLOT_IP && do:
p.Arc = append(p.Arc, fmt.Sprintf("<a href='https://archive.today/'>%s</a>", config.SlotName(slot)))
case config.SLOT_IP:
logger.Debug("Telegram: archiving slot: %s", slot)
p.Arc = append(p.Arc, fmt.Sprintf("<a href='https://ipfs.github.io/public-gateway-checker/'>%s</a>", config.SlotName(slot)))
p.Dst = append(p.Dst, wbrc.IP())
p.Arc = append(p.Arc, fmt.Sprintf("<a href='https://ipfs.github.io/public-gateway-checker/'>%s</a>", config.SlotName(slot)))
}
}(slot, do, c)
}(slot)
}
wg.Wait()
*c = p
Expand Down

0 comments on commit e6175f5

Please sign in to comment.