main.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2016, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package main
  20. import (
  21. "flag"
  22. "fmt"
  23. "io/ioutil"
  24. "os"
  25. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/server"
  26. )
  27. func main() {
  28. flag.Parse()
  29. args := flag.Args()
  30. // TODO: add working directory flag
  31. configFilename := server.SERVER_CONFIG_FILENAME
  32. serverEntryFilename := server.SERVER_ENTRY_FILENAME
  33. if len(args) < 1 {
  34. fmt.Errorf("usage: '%s generate' or '%s run'", os.Args[0])
  35. os.Exit(1)
  36. } else if args[0] == "generate" {
  37. // TODO: flags to set generate params
  38. configFileContents, serverEntryFileContents, err := server.GenerateConfig(
  39. &server.GenerateConfigParams{})
  40. if err != nil {
  41. fmt.Errorf("generate failed: %s", err)
  42. os.Exit(1)
  43. }
  44. err = ioutil.WriteFile(configFilename, configFileContents, 0600)
  45. if err != nil {
  46. fmt.Errorf("error writing configuration file: %s", err)
  47. os.Exit(1)
  48. }
  49. err = ioutil.WriteFile(serverEntryFilename, serverEntryFileContents, 0600)
  50. if err != nil {
  51. fmt.Errorf("error writing server entry file: %s", err)
  52. os.Exit(1)
  53. }
  54. } else if args[0] == "run" {
  55. configFileContents, err := ioutil.ReadFile(configFilename)
  56. if err != nil {
  57. fmt.Errorf("error loading configuration file: %s", err)
  58. os.Exit(1)
  59. }
  60. err = server.RunServices(configFileContents)
  61. if err != nil {
  62. fmt.Errorf("run failed: %s", err)
  63. os.Exit(1)
  64. }
  65. }
  66. }