<commit_before>//go:generate statik -src=web
//go:generate go fmt statik/statik.go
package main

import (
	"encoding/csv"
	"encoding/json"
	"flag"
	"fmt"
	"net/http"
	"os"
	"sync"
	"time"

	"github.com/dgnorton/norobo"
	"github.com/dgnorton/norobo/filters/exec"
	"github.com/dgnorton/norobo/filters/local"
	"github.com/dgnorton/norobo/filters/twilio"
	"github.com/dgnorton/norobo/hayes"
	"github.com/rakyll/statik/fs"

	_ "github.com/dgnorton/norobo/cmd/norobod/statik"
)

func main() {
	var (
		connstr        string
		blockFile      string
		allowFile      string
		callLogFile    string
		twloAccountSID string
		twloToken      string
		execCommand    string
		execArgs       string
	)

	flag.StringVar(&connstr, "c", "/dev/ttyACM0,19200,n,8,1", "serial port connect string (port,baud,handshake,data-bits,stop-bits)")
	flag.StringVar(&blockFile, "block", "", "path to file containing patterns to block")
	flag.StringVar(&allowFile, "allow", "", "path to file containing patterns to allow")
	flag.StringVar(&callLogFile, "call-log", "", "path to call log file")
	flag.StringVar(&twloAccountSID, "twlo-sid", "", "Twilio account SID")
	flag.StringVar(&twloToken, "twlo-token", "", "Twilio token")
	flag.StringVar(&execCommand, "exec", "", "Command gets executed for every call")
	flag.StringVar(&execArgs, "exec-args", "-n {{.Number}}", "Arguments for exec command; uses text/template; availible vars are (Number, Name, Time)")
	flag.Parse()

	modem, err := hayes.Open(connstr)
	check(err)

	callHandler := newCallHandler(modem, blockFile, allowFile, twloAccountSID, twloToken, callLogFile, execCommand, execArgs)
	modem.SetCallHandler(callHandler)
	modem.EnableSoftwareCache(false)

	check(modem.Reset())

	infos, err := modem.Info()
	check(err)
	println("Modem info:")
	for _, info := range infos {
		println(info)
	}

	fcs, err := modem.FaxClasses()
	check(err)
	println("Fax classes:")
	for _, fc := range fcs {
		println(fc)
	}

	fc, err := modem.FaxClass()
	check(err)
	fmt.Printf("fax class: %s\n", fc)

	check(modem.SetFaxClass(hayes.FaxClass2))

	fc, err = modem.FaxClass()
	check(err)
	fmt.Printf("fax class: %s\n", fc)

	cidModes, err := modem.CallerIDModes()
	check(err)
	println("Caller ID modes:")
	for _, m := range cidModes {
		println(m)
	}

	cidMode, err := modem.CallerIDMode()
	check(err)
	fmt.Printf("caller ID mode: %s\n", cidMode)

	check(modem.SetCallerIDMode(hayes.CallerIDOn))

	cidMode, err = modem.CallerIDMode()
	check(err)
	fmt.Printf("caller ID mode: %s\n", cidMode)

	// Start call log web server.
	s := &http.Server{
		Addr:    ":7080",
		Handler: newWebHandler(callHandler),
	}<commit_msg>make HTTP bind address & port configurable<commit_after>//go:generate statik -src=web
//go:generate go fmt statik/statik.go
package main

import (
	"encoding/csv"
	"encoding/json"
	"flag"
	"fmt"
	"net/http"
	"os"
	"sync"
	"time"

	"github.com/dgnorton/norobo"
	"github.com/dgnorton/norobo/filters/exec"
	"github.com/dgnorton/norobo/filters/local"
	"github.com/dgnorton/norobo/filters/twilio"
	"github.com/dgnorton/norobo/hayes"
	"github.com/rakyll/statik/fs"

	_ "github.com/dgnorton/norobo/cmd/norobod/statik"
)

func main() {
	var (
		connstr        string
		blockFile      string
		allowFile      string
		callLogFile    string
		twloAccountSID string
		twloToken      string
		execCommand    string
		execArgs       string
		httpAddr       string
	)

	flag.StringVar(&connstr, "c", "/dev/ttyACM0,19200,n,8,1", "serial port connect string (port,baud,handshake,data-bits,stop-bits)")
	flag.StringVar(&blockFile, "block", "", "path to file containing patterns to block")
	flag.StringVar(&allowFile, "allow", "", "path to file containing patterns to allow")
	flag.StringVar(&callLogFile, "call-log", "", "path to call log file")
	flag.StringVar(&twloAccountSID, "twlo-sid", "", "Twilio account SID")
	flag.StringVar(&twloToken, "twlo-token", "", "Twilio token")
	flag.StringVar(&execCommand, "exec", "", "Command gets executed for every call")
	flag.StringVar(&execArgs, "exec-args", "-n {{.Number}}", "Arguments for exec command; uses text/template; availible vars are (Number, Name, Time)")
	flag.StringVar(&httpAddr, "bind", "localhost:7080", "HTTP IP and port")
	flag.Parse()

	modem, err := hayes.Open(connstr)
	check(err)

	callHandler := newCallHandler(modem, blockFile, allowFile, twloAccountSID, twloToken, callLogFile, execCommand, execArgs)
	modem.SetCallHandler(callHandler)
	modem.EnableSoftwareCache(false)

	check(modem.Reset())

	infos, err := modem.Info()
	check(err)
	println("Modem info:")
	for _, info := range infos {
		println(info)
	}

	fcs, err := modem.FaxClasses()
	check(err)
	println("Fax classes:")
	for _, fc := range fcs {
		println(fc)
	}

	fc, err := modem.FaxClass()
	check(err)
	fmt.Printf("fax class: %s\n", fc)

	check(modem.SetFaxClass(hayes.FaxClass2))

	fc, err = modem.FaxClass()
	check(err)
	fmt.Printf("fax class: %s\n", fc)

	cidModes, err := modem.CallerIDModes()
	check(err)
	println("Caller ID modes:")
	for _, m := range cidModes {
		println(m)
	}

	cidMode, err := modem.CallerIDMode()
	check(err)
	fmt.Printf("caller ID mode: %s\n", cidMode)

	check(modem.SetCallerIDMode(hayes.CallerIDOn))

	cidMode, err = modem.CallerIDMode()
	check(err)
	fmt.Printf("caller ID mode: %s\n", cidMode)

	// Start call log web server.
	s := &http.Server{
		Addr:    httpAddr,
		Handler: newWebHandler(callHandler),
	}
{'fraction_non_alphanumeric': 0.15447608412432534, 'fraction_numerical': 0.004839009864135492, 'mean_word_length': 4.483673469387755, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1639847', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2024, 'n_words': 430}