Ejemplo n.º 1
0
func Upload(w http.ResponseWriter, req *http.Request) {
	req.ParseMultipartForm(32 << 20)

	uploadedFile, handler, err := req.FormFile("file")
	if log.PrintError("frontend upload", err) != nil {
		fmt.Fprintf(w, "ERROR")
		return
	}
	defer uploadedFile.Close()

	err = os.MkdirAll(viper.GetString("upload"), 0700)
	if log.PrintError("frontend upload", err) != nil {
		fmt.Fprintf(w, "ERROR")
		return
	}
	serverFile, err := os.OpenFile(
		viper.GetString("upload")+handler.Filename,
		os.O_WRONLY|os.O_CREATE,
		0600,
	)
	if log.PrintError("frontend upload", err) != nil {
		fmt.Fprintf(w, "ERROR")
		return
	}
	defer serverFile.Close()

	if !Check(uploadedFile) {
		fmt.Fprintf(w, "ERROR")
		return
	}
	// io.Copy(serverFile, uploadedFile)
	fmt.Fprintf(w, "OK")
}
Ejemplo n.º 2
0
func Start(mux *http.ServeMux, address, port, cert, key string) {
	listen := fmt.Sprintf("%s:%s", address, port)
	if cert == "" || key == "" {
		fmt.Printf("About to listen on http://%s/\n", listen)
		err := http.ListenAndServe(listen, mux)
		log.PrintError("serving frontend", err)
	} else {
		fmt.Printf("About to listen on https://%s/\n", listen)
		err := http.ListenAndServeTLS(listen, cert, key, mux)
		log.PrintError("serving frontend", err)
	}
}
Ejemplo n.º 3
0
func NewPair(name, comment, email string) (*openpgp.Entity, error) {
	entity, err := openpgp.NewEntity(name, comment, email, nil)
	if err != nil {
		log.PrintError("telem.crypto.NewPair", err)
		return nil, err
	}

	// Sign all the identities
	for _, id := range entity.Identities {
		err := id.SelfSignature.SignUserId(id.UserId.Id, entity.PrimaryKey, entity.PrivateKey, nil)
		if err != nil {
			log.PrintError("telem.crypto.NewPair", err)
			return nil, err
		}
	}
	return entity, nil
}
Ejemplo n.º 4
0
func Private(entity *openpgp.Entity) (string, error) {
	var output bytes.Buffer
	writeBuffer := bufio.NewWriter(&output)
	private, err := armor.Encode(writeBuffer, openpgp.PrivateKeyType, nil)
	if err != nil {
		log.PrintError("telem.crypto.Private", err)
		return "", err
	}

	entity.SerializePrivate(private, nil)
	private.Close()
	writeBuffer.Flush()
	return output.String(), nil
}
Ejemplo n.º 5
0
func Gen() {
	pair, err := NewPair(
		viper.GetString("name"),
		viper.GetString("comment"),
		viper.GetString("email"),
	)
	if log.PrintError("crypto", err) != nil {
		return
	}
	public, err := Public(pair)
	if log.PrintError("crypto", err) != nil {
		return
	}
	private, err := Private(pair)
	if log.PrintError("crypto", err) != nil {
		return
	}
	if viper.GetBool("stdout") {
		fmt.Println(public)
		fmt.Println(private)
	}
	if viper.GetString("path") != "" {
		err := os.MkdirAll(viper.GetString("path"), 0700)
		if log.PrintError("crypto", err) != nil {
			return
		}
		err = ioutil.WriteFile(
			viper.GetString("path")+"public.pgp",
			[]byte(public),
			0600,
		)
		if log.PrintError("crypto", err) != nil {
			return
		}
		err = ioutil.WriteFile(
			viper.GetString("path")+"private.pgp",
			[]byte(private),
			0600,
		)
		if log.PrintError("crypto", err) != nil {
			return
		}
	}
}