diff --git a/cmd/stcli/logger.go b/cmd/stcli/logger.go deleted file mode 100644 index a7883e866..000000000 --- a/cmd/stcli/logger.go +++ /dev/null @@ -1,72 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" -) - -var logger *log.Logger - -func init() { - log.SetOutput(os.Stderr) - logger = log.New(os.Stderr, "", log.Flags()) -} - -func debugln(vals ...interface{}) { - s := fmt.Sprintln(vals...) - logger.Output(2, "DEBUG: "+s) -} - -func debugf(format string, vals ...interface{}) { - s := fmt.Sprintf(format, vals...) - logger.Output(2, "DEBUG: "+s) -} - -func infoln(vals ...interface{}) { - s := fmt.Sprintln(vals...) - logger.Output(2, "INFO: "+s) -} - -func infof(format string, vals ...interface{}) { - s := fmt.Sprintf(format, vals...) - logger.Output(2, "INFO: "+s) -} - -func okln(vals ...interface{}) { - s := fmt.Sprintln(vals...) - logger.Output(2, "OK: "+s) -} - -func okf(format string, vals ...interface{}) { - s := fmt.Sprintf(format, vals...) - logger.Output(2, "OK: "+s) -} - -func warnln(vals ...interface{}) { - s := fmt.Sprintln(vals...) - logger.Output(2, "WARNING: "+s) -} - -func warnf(format string, vals ...interface{}) { - s := fmt.Sprintf(format, vals...) - logger.Output(2, "WARNING: "+s) -} - -func fatalln(vals ...interface{}) { - s := fmt.Sprintln(vals...) - logger.Output(2, "FATAL: "+s) - os.Exit(3) -} - -func fatalf(format string, vals ...interface{}) { - s := fmt.Sprintf(format, vals...) - logger.Output(2, "FATAL: "+s) - os.Exit(3) -} - -func fatalErr(err error) { - if err != nil { - fatalf(err.Error()) - } -} diff --git a/cmd/stcli/tls.go b/cmd/stcli/tls.go index cfc1ce5bc..df71d1fc5 100644 --- a/cmd/stcli/tls.go +++ b/cmd/stcli/tls.go @@ -1,24 +1,11 @@ package main import ( - "crypto/rand" - "crypto/rsa" "crypto/sha256" "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" "encoding/base32" - "encoding/pem" - "math/big" - "os" "path/filepath" "strings" - "time" -) - -const ( - tlsRSABits = 3072 - tlsName = "syncthing" ) func loadCert(dir string) (tls.Certificate, error) { @@ -31,41 +18,3 @@ func certID(bs []byte) string { id := hf.Sum(nil) return strings.Trim(base32.StdEncoding.EncodeToString(id), "=") } - -func newCertificate(dir string) { - infoln("Generating RSA certificate and key...") - - priv, err := rsa.GenerateKey(rand.Reader, tlsRSABits) - fatalErr(err) - - notBefore := time.Now() - notAfter := time.Date(2049, 12, 31, 23, 59, 59, 0, time.UTC) - - template := x509.Certificate{ - SerialNumber: new(big.Int).SetInt64(0), - Subject: pkix.Name{ - CommonName: tlsName, - }, - NotBefore: notBefore, - NotAfter: notAfter, - - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth}, - BasicConstraintsValid: true, - } - - derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv) - fatalErr(err) - - certOut, err := os.Create(filepath.Join(dir, "cert.pem")) - fatalErr(err) - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() - okln("Created RSA certificate file") - - keyOut, err := os.OpenFile(filepath.Join(dir, "key.pem"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - fatalErr(err) - pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}) - keyOut.Close() - okln("Created RSA key file") -} diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 0c9f1fe3a..09622a2e8 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -14,7 +14,6 @@ import ( "time" "code.google.com/p/go.crypto/bcrypt" - "github.com/calmh/syncthing/scanner" "github.com/codegangsta/martini" ) @@ -166,23 +165,6 @@ func restPostReset(req *http.Request) { go restart() } -type guiFile scanner.File - -func (f guiFile) MarshalJSON() ([]byte, error) { - type t struct { - Name string - Size int64 - Modified int64 - Flags uint32 - } - return json.Marshal(t{ - Name: f.Name, - Size: scanner.File(f).Size, - Modified: f.Modified, - Flags: f.Flags, - }) -} - var cpuUsagePercent [10]float64 // The last ten seconds var cpuUsageLock sync.RWMutex diff --git a/cmd/syncthing/util.go b/cmd/syncthing/util.go index 5a9a47f7a..1ded1001b 100644 --- a/cmd/syncthing/util.go +++ b/cmd/syncthing/util.go @@ -10,32 +10,6 @@ import ( "github.com/calmh/syncthing/scanner" ) -func MetricPrefix(n int64) string { - if n > 1e9 { - return fmt.Sprintf("%.02f G", float64(n)/1e9) - } - if n > 1e6 { - return fmt.Sprintf("%.02f M", float64(n)/1e6) - } - if n > 1e3 { - return fmt.Sprintf("%.01f k", float64(n)/1e3) - } - return fmt.Sprintf("%d ", n) -} - -func BinaryPrefix(n int64) string { - if n > 1<<30 { - return fmt.Sprintf("%.02f Gi", float64(n)/(1<<30)) - } - if n > 1<<20 { - return fmt.Sprintf("%.02f Mi", float64(n)/(1<<20)) - } - if n > 1<<10 { - return fmt.Sprintf("%.01f Ki", float64(n)/(1<<10)) - } - return fmt.Sprintf("%d ", n) -} - func Rename(from, to string) error { if runtime.GOOS == "windows" { err := os.Remove(to)