Showing first 22 files as there are too many
-
-
-
1 1 package cmd 2 2 3 3 import ( 4 - "fmt" 5 - "github.com/j3ssie/osmedeus/database" 6 - "github.com/j3ssie/osmedeus/execution" 7 - "os" 8 - "sort" 4 + "fmt" 5 + "github.com/j3ssie/osmedeus/database" 6 + "github.com/j3ssie/osmedeus/execution" 7 + "os" 8 + "sort" 9 9 10 - "github.com/j3ssie/osmedeus/core" 11 - "github.com/j3ssie/osmedeus/utils" 12 - "github.com/spf13/cobra" 10 + "github.com/j3ssie/osmedeus/core" 11 + "github.com/j3ssie/osmedeus/utils" 12 + "github.com/spf13/cobra" 13 13 ) 14 14 15 15 func init() { 16 - var configCmd = &cobra.Command{ 17 - Use: "config", 18 - Short: "Do some config stuff", 19 - Long: core.Banner(), 20 - RunE: runConfig, 21 - } 16 + var configCmd = &cobra.Command{ 17 + Use: "config", 18 + Short: "Do some config stuff", 19 + Long: core.Banner(), 20 + RunE: runConfig, 21 + } 22 22 23 - configCmd.Flags().StringP("action", "a", "", "Action") 24 - configCmd.Flags().StringP("pluginsRepo", "p", "[email protected]:j3ssie/osmedeus-plugins.git", "Osmedeus Plugins repository") 25 - // for cred action 26 - configCmd.Flags().String("user", "", "Username") 27 - configCmd.Flags().String("pass", "", "Password") 28 - configCmd.Flags().StringP("workspace", "w", "", "Name of workspace") 23 + configCmd.Flags().StringP("action", "a", "", "Action") 24 + configCmd.Flags().String("pluginsRepo", "[email protected]:j3ssie/osmedeus-plugins.git", "Osmedeus Plugins repository") 25 + // for cred action 26 + configCmd.Flags().String("user", "", "Username") 27 + configCmd.Flags().String("pass", "", "Password") 28 + configCmd.Flags().StringP("workspace", "w", "", "Name of workspace") 29 29 30 - configCmd.SetHelpFunc(ConfigHelp) 31 - RootCmd.AddCommand(configCmd) 30 + configCmd.SetHelpFunc(ConfigHelp) 31 + RootCmd.AddCommand(configCmd) 32 32 } 33 33 34 34 func runConfig(cmd *cobra.Command, args []string) error { 35 - sort.Strings(args) 36 - action, _ := cmd.Flags().GetString("action") 37 - //pluginsRepo, _ := cmd.Flags().GetString("pluginsRepo") 38 - workspace, _ := cmd.Flags().GetString("workspace") 39 - DBInit() 35 + sort.Strings(args) 36 + action, _ := cmd.Flags().GetString("action") 37 + //pluginsRepo, _ := cmd.Flags().GetString("pluginsRepo") 38 + workspace, _ := cmd.Flags().GetString("workspace") 39 + DBInit() 40 40 41 - // backward compatible 42 - if action == "" && len(args) > 0 { 43 - action = args[0] 44 - } 41 + // backward compatible 42 + if action == "" && len(args) > 0 { 43 + action = args[0] 44 + } 45 45 46 - switch action { 47 - case "init": 48 - if utils.FolderExists(fmt.Sprintf("%vcore", options.Env.RootFolder)) { 49 - utils.GoodF("Look like you got properly setup.") 50 - } 51 - break 52 - case "cred": 53 - username, _ := cmd.Flags().GetString("user") 54 - password, _ := cmd.Flags().GetString("pass") 55 - //database.CreateUser(username, password) 56 - utils.GoodF("Create new credentials %v:%v \n", username, password) 57 - break 46 + switch action { 47 + case "init": 48 + if utils.FolderExists(fmt.Sprintf("%vcore", options.Env.RootFolder)) { 49 + utils.GoodF("Look like you got properly setup.") 50 + } 51 + break 52 + case "cred": 53 + username, _ := cmd.Flags().GetString("user") 54 + password, _ := cmd.Flags().GetString("pass") 55 + //database.CreateUser(username, password) 56 + utils.GoodF("Create new credentials %v:%v \n", username, password) 57 + break 58 58 59 - case "reload": 60 - core.ReloadConfig(options) 61 - break 59 + case "reload": 60 + core.ReloadConfig(options) 61 + break 62 62 63 - case "delete": 64 - options.Scan.Input = workspace 65 - options.Scan.ROptions = core.ParseInput(options.Scan.Input, options) 66 - utils.InforF("Delete Workspace: %v", options.Scan.ROptions["Workspace"]) 67 - os.RemoveAll(options.Scan.ROptions["Output"]) 68 - //ws := database.SelectScan(options.Scan.ROptions["Workspace"]) 69 - //database.DeleteScan(int(ws.ID)) 70 - break 63 + case "delete": 64 + options.Scan.Input = workspace 65 + options.Scan.ROptions = core.ParseInput(options.Scan.Input, options) 66 + utils.InforF("Delete Workspace: %v", options.Scan.ROptions["Workspace"]) 67 + os.RemoveAll(options.Scan.ROptions["Output"]) 68 + //ws := database.SelectScan(options.Scan.ROptions["Workspace"]) 69 + //database.DeleteScan(int(ws.ID)) 70 + break 71 71 72 - case "pull": 73 - for repo := range options.Storages { 74 - execution.PullResult(repo, options) 75 - } 76 - break 72 + case "pull": 73 + for repo := range options.Storages { 74 + execution.PullResult(repo, options) 75 + } 76 + break 77 77 78 - case "update": 79 - core.Update(options) 80 - break 78 + case "update": 79 + core.Update(options) 80 + break 81 81 82 - case "clean", "cl", "c": 83 - database.ClearDB() 84 - break 85 - } 82 + case "clean", "cl", "c": 83 + database.ClearDB() 84 + break 85 + } 86 86 87 - return nil 87 + return nil 88 88 } 89 89 -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1 1 package core 2 2 3 3 import ( 4 - "fmt" 5 - "github.com/fatih/color" 6 - "github.com/j3ssie/osmedeus/execution" 7 - "github.com/j3ssie/osmedeus/libs" 8 - "github.com/j3ssie/osmedeus/provider" 9 - "github.com/j3ssie/osmedeus/utils" 10 - "github.com/mitchellh/go-homedir" 11 - "github.com/spf13/viper" 12 - "net/url" 13 - "os" 14 - "path" 15 - "path/filepath" 16 - "strings" 4 + "fmt" 5 + "github.com/fatih/color" 6 + "github.com/j3ssie/osmedeus/execution" 7 + "github.com/j3ssie/osmedeus/libs" 8 + "github.com/j3ssie/osmedeus/provider" 9 + "github.com/j3ssie/osmedeus/utils" 10 + "github.com/spf13/viper" 11 + "net/url" 12 + "os" 13 + "path" 14 + "path/filepath" 15 + "strings" 17 16 ) 17 + 18 + var v *viper.Viper 18 19 19 20 // InitConfig Init the config 20 21 func InitConfig(options *libs.Options) error { 21 - // ~/.osmedeus 22 - RootFolder := filepath.Dir(utils.NormalizePath(options.ConfigFile)) 23 - if !utils.FolderExists(RootFolder) { 24 - if err := os.MkdirAll(RootFolder, 0750); err != nil { 25 - return err 26 - } 27 - } 22 + // ~/.osmedeus 23 + RootFolder := filepath.Dir(utils.NormalizePath(options.ConfigFile)) 24 + if !utils.FolderExists(RootFolder) { 25 + if err := os.MkdirAll(RootFolder, 0750); err != nil { 26 + return err 27 + } 28 + } 28 29 29 - // Base folder 30 - // ~/osmedeus-base 31 - BaseFolder := utils.NormalizePath(options.Env.BaseFolder) 32 - if !utils.FolderExists(BaseFolder) { 33 - if err := os.MkdirAll(BaseFolder, 0750); err != nil { 34 - return err 35 - } 36 - } 30 + // Base folder 31 + // ~/osmedeus-base 32 + BaseFolder := utils.NormalizePath(options.Env.BaseFolder) 33 + if !utils.FolderExists(BaseFolder) { 34 + fmt.Printf("%v Base folder not found at: %v\n", color.RedString("[Panic]"), color.HiGreenString(BaseFolder)) 35 + fmt.Printf(color.HiYellowString("[!]")+" Consider running the installation script first: %v\n", color.HiGreenString("bash <(curl -fsSL %v)", libs.INSTALL)) 36 + fmt.Printf(color.HiYellowString("[!]")+" Or better visit the installation guide at: %v\n", color.HiMagentaString("https://docs.osmedeus.org/installation/")) 37 + os.Exit(-1) 38 + } 37 39 38 - // init config 39 - v := viper.New() 40 - v.AddConfigPath(RootFolder) 41 - v.SetConfigName("config") 42 - v.SetConfigType("yaml") 40 + // init config 41 + options.ConfigFile = utils.NormalizePath(options.ConfigFile) 42 + v = viper.New() 43 + v.AddConfigPath(options.ConfigFile) 44 + v.SetConfigType("yaml") 43 45 44 - if !utils.FileExists(options.ConfigFile) { 45 - // Some default config if config file doesn't exist 46 - secret := utils.GenHash(utils.RandomString(8) + utils.GetTS()) 47 - prefix := secret[len(secret)-20 : len(secret)-1] 46 + if !utils.FileExists(options.ConfigFile) { 47 + // Some default config if config file doesn't exist 48 + secret := utils.GenHash(utils.RandomString(8) + utils.GetTS()) 49 + prefix := secret[len(secret)-20 : len(secret)-1] 48 50 49 - v.SetDefault("Server", map[string]string{ 50 - "bind": "0.0.0.0:8000", 51 - "cors": "*", 52 - "secret": secret, 53 - "prefix": prefix, 54 - "ui": path.Join(RootFolder, "server/ui"), 55 - "cert_file": path.Join(RootFolder, "server/ssl/cert.pem"), 56 - "key_file": path.Join(RootFolder, "server/ssl/key.pem"), 57 - "master_pass": "", 58 - }) 51 + v.SetDefault("Server", map[string]string{ 52 + "bind": "0.0.0.0:8000", 53 + "cors": "*", 54 + "secret": secret, 55 + "prefix": prefix, 56 + "ui": path.Join(RootFolder, "server/ui"), 57 + "cert_file": path.Join(RootFolder, "server/ssl/cert.pem"), 58 + "key_file": path.Join(RootFolder, "server/ssl/key.pem"), 59 + "master_pass": "", 60 + }) 59 61 60 - // DB connection config 61 - dbPath := utils.NormalizePath(path.Join(RootFolder, "sqlite.db")) 62 - v.SetDefault("Database", map[string]string{ 63 - "db_host": utils.GetOSEnv("DB_HOST", "127.0.0.1"), 64 - "db_port": utils.GetOSEnv("DB_PORT", "3306"), 65 - "db_name": utils.GetOSEnv("DB_NAME", "osm-core"), 66 - "db_user": utils.GetOSEnv("DB_USER", "root"), 67 - "db_pass": utils.GetOSEnv("DB_PASS", ""), 68 - // sqlite or mysql 69 - "db_path": utils.GetOSEnv("DB_PATH", dbPath), 70 - "db_type": utils.GetOSEnv("DB_TYPE", "sqlite"), 71 - }) 62 + // DB connection config 63 + dbPath := utils.NormalizePath(path.Join(RootFolder, "sqlite.db")) 64 + v.SetDefault("Database", map[string]string{ 65 + "db_host": utils.GetOSEnv("DB_HOST", "127.0.0.1"), 66 + "db_port": utils.GetOSEnv("DB_PORT", "3306"), 67 + "db_name": utils.GetOSEnv("DB_NAME", "osm-core"), 68 + "db_user": utils.GetOSEnv("DB_USER", "root"), 69 + "db_pass": utils.GetOSEnv("DB_PASS", ""), 70 + // sqlite or mysql 71 + "db_path": utils.GetOSEnv("DB_PATH", dbPath), 72 + "db_type": utils.GetOSEnv("DB_TYPE", "sqlite"), 73 + }) 72 74 73 - // default user 74 - password := utils.GenHash(utils.GetTS())[:15] 75 - v.SetDefault("Client", map[string]string{ 76 - "username": "osmedeus", 77 - "password": password, 78 - "jwt": "", 79 - "dest": "http://127.0.0.1:8000", 80 - }) 75 + // default user 76 + password := utils.GenHash(utils.GetTS())[:15] 77 + v.SetDefault("Client", map[string]string{ 78 + "username": "osmedeus", 79 + "password": password, 80 + "jwt": "", 81 + "dest": "http://127.0.0.1:8000", 82 + }) 81 83 82 - v.SetDefault("Environments", map[string]string{ 83 - // RootFolder --> ~/.osmedeus/ 84 - "storages": path.Join(RootFolder, "storages"), 85 - "workspaces": path.Join(RootFolder, "workspaces"), 86 - "backups": path.Join(RootFolder, "backups"), 87 - //"cloud_data": path.Join(RootFolder, "clouds"), 88 - "provider_config": path.Join(RootFolder, "provider"), 84 + v.SetDefault("Environments", map[string]string{ 85 + // RootFolder --> ~/.osmedeus/ 86 + "storages": path.Join(RootFolder, "storages"), 87 + "workspaces": path.Join(RootFolder, "workspaces"), 88 + "backups": path.Join(RootFolder, "backups"), 89 + "provider_config": path.Join(RootFolder, "provider"), 89 90 90 - // this update casually 91 - // BaseFolder --> ~/osmedeus-base/ 92 - "workflows": path.Join(BaseFolder, "workflow"), 93 - "binaries": path.Join(BaseFolder, "binaries"), 94 - "data": path.Join(BaseFolder, "data"), 95 - "cloud_config": path.Join(BaseFolder, "cloud"), 96 - }) 91 + // this update casually 92 + // BaseFolder --> ~/osmedeus-base/ 93 + "workflows": path.Join(BaseFolder, "workflow"), 94 + "binaries": path.Join(BaseFolder, "binaries"), 95 + "data": path.Join(BaseFolder, "data"), 96 + "cloud_config": path.Join(BaseFolder, "cloud"), 97 + }) 97 98 98 - // things should be reloaded by env 99 - v.SetDefault("Storages", map[string]string{ 100 - // path of secret key for push result 101 - // ~/.osmedeus/storages_key 102 - "secret_key": utils.GetOSEnv("SECRET_KEY", "SECRET_KEY"), 103 - // the repo format should be like this "[email protected]:j3ssie/example.git", 104 - "summary_storage": path.Join(options.Env.RootFolder, "storages/summary"), 105 - "summary_repo": utils.GetOSEnv("SUMMARY_REPO", "SUMMARY_REPO"), 106 - "subdomain_storage": path.Join(options.Env.RootFolder, "storages/subdomain"), 107 - "subdomain_repo": utils.GetOSEnv("SUBDOMAIN_REPO", "SUBDOMAIN_REPO"), 108 - "assets_storage": path.Join(options.Env.RootFolder, "storages/assets"), 109 - "assets_repo": utils.GetOSEnv("ASSETS_REPO", "ASSETS_REPO"), 110 - "ports_storage": path.Join(options.Env.RootFolder, "storages/ports"), 111 - "ports_repo": utils.GetOSEnv("PORTS_REPO", "PORTS_REPO"), 112 - "http_storage": path.Join(options.Env.RootFolder, "storages/http"), 113 - "http_repo": utils.GetOSEnv("HTTP_REPO", "HTTP_REPO"), 114 - "vuln_storage": path.Join(options.Env.RootFolder, "storages/vuln"), 115 - "vuln_repo": utils.GetOSEnv("VULN_REPO", "VULN_REPO"), 116 - "paths_storage": path.Join(options.Env.RootFolder, "storages/paths"), 117 - "paths_repo": utils.GetOSEnv("PATHS_REPO", "PATHS_REPO"), 118 - "mics_storage": path.Join(options.Env.RootFolder, "storages/mics"), 119 - "mics_repo": utils.GetOSEnv("MICS_REPO", "MICS_REPO"), 120 - }) 99 + // things should be reloaded by env 100 + v.SetDefault("Storages", map[string]string{ 101 + // path of secret key for push result 102 + // ~/.osmedeus/storages_key 103 + "secret_key": utils.GetOSEnv("SECRET_KEY", "SECRET_KEY"), 104 + // the repo format should be like this "[email protected]:j3ssie/example.git", 105 + "summary_storage": path.Join(options.Env.RootFolder, "storages/summary"), 106 + "summary_repo": utils.GetOSEnv("SUMMARY_REPO", "SUMMARY_REPO"), 107 + "subdomain_storage": path.Join(options.Env.RootFolder, "storages/subdomain"), 108 + "subdomain_repo": utils.GetOSEnv("SUBDOMAIN_REPO", "SUBDOMAIN_REPO"), 109 + "assets_storage": path.Join(options.Env.RootFolder, "storages/assets"), 110 + "assets_repo": utils.GetOSEnv("ASSETS_REPO", "ASSETS_REPO"), 111 + "ports_storage": path.Join(options.Env.RootFolder, "storages/ports"), 112 + "ports_repo": utils.GetOSEnv("PORTS_REPO", "PORTS_REPO"), 113 + "http_storage": path.Join(options.Env.RootFolder, "storages/http"), 114 + "http_repo": utils.GetOSEnv("HTTP_REPO", "HTTP_REPO"), 115 + "vuln_storage": path.Join(options.Env.RootFolder, "storages/vuln"), 116 + "vuln_repo": utils.GetOSEnv("VULN_REPO", "VULN_REPO"), 117 + "paths_storage": path.Join(options.Env.RootFolder, "storages/paths"), 118 + "paths_repo": utils.GetOSEnv("PATHS_REPO", "PATHS_REPO"), 119 + "mics_storage": path.Join(options.Env.RootFolder, "storages/mics"), 120 + "mics_repo": utils.GetOSEnv("MICS_REPO", "MICS_REPO"), 121 + }) 121 122 122 - v.SetDefault("Tokens", map[string]string{ 123 - "slack": utils.GetOSEnv("SLACK_API_TOKEN", "SLACK_API_TOKEN"), 124 - "telegram": utils.GetOSEnv("TELEGRAM_API_TOKEN", "TELEGRAM_API_TOKEN"), 125 - "gitlab": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 126 - "github": utils.GetOSEnv("GITHUB_API_KEY", "GITHUB_API_KEY"), 127 - }) 123 + v.SetDefault("Tokens", map[string]string{ 124 + "slack": utils.GetOSEnv("SLACK_API_TOKEN", "SLACK_API_TOKEN"), 125 + "telegram": utils.GetOSEnv("TELEGRAM_API_TOKEN", "TELEGRAM_API_TOKEN"), 126 + "gitlab": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 127 + "github": utils.GetOSEnv("GITHUB_API_KEY", "GITHUB_API_KEY"), 128 + }) 128 129 129 - // dedicated storages 130 - v.SetDefault("Git", map[string]string{ 131 - "base_url": utils.GetOSEnv("GITLAB_BASE_URL", "https://gitlab.com"), 132 - "api": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 133 - "username": utils.GetOSEnv("GITLAB_USER", "GITLAB_USER"), 134 - "password": utils.GetOSEnv("GITLAB_PASS", "GITLAB_PASS"), 135 - "group": utils.GetOSEnv("GITLAB_GROUP", "GITLAB_GROUP"), 136 - "prefix_name": utils.GetOSEnv("GITLAB_PREFIX_NAME", "deosm"), 137 - "default_tag": utils.GetOSEnv("GITLAB_DEFAULT_TAG", "osmd"), 138 - "default_user": utils.GetOSEnv("GITLAB_DEFAULT_USER", "j3ssie"), 139 - "default_uid": utils.GetOSEnv("GITLAB_DEFAULT_UID", "3537075"), 140 - "destorage": path.Join(options.Env.RootFolder, "destorage"), 141 - }) 130 + // dedicated storages 131 + v.SetDefault("Git", map[string]string{ 132 + "base_url": utils.GetOSEnv("GITLAB_BASE_URL", "https://gitlab.com"), 133 + "api": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 134 + "username": utils.GetOSEnv("GITLAB_USER", "GITLAB_USER"), 135 + "password": utils.GetOSEnv("GITLAB_PASS", "GITLAB_PASS"), 136 + "group": utils.GetOSEnv("GITLAB_GROUP", "GITLAB_GROUP"), 137 + "prefix_name": utils.GetOSEnv("GITLAB_PREFIX_NAME", "deosm"), 138 + "default_tag": utils.GetOSEnv("GITLAB_DEFAULT_TAG", "osmd"), 139 + "default_user": utils.GetOSEnv("GITLAB_DEFAULT_USER", "j3ssie"), 140 + "default_uid": utils.GetOSEnv("GITLAB_DEFAULT_UID", "3537075"), 141 + "destorage": path.Join(options.Env.RootFolder, "destorage"), 142 + }) 142 143 143 - v.Set("Notification", map[string]string{ 144 - "client_name": utils.GetOSEnv("CLIENT_NAME", "CLIENT_NAME"), 145 - "slack_status_channel": utils.GetOSEnv("SLACK_STATUS_CHANNEL", "SLACK_STATUS_CHANNEL"), 146 - "slack_report_channel": utils.GetOSEnv("SLACK_REPORT_CHANNEL", "SLACK_REPORT_CHANNEL"), 147 - "slack_diff_channel": utils.GetOSEnv("SLACK_DIFF_CHANNEL", "SLACK_DIFF_CHANNEL"), 148 - "slack_webhook": utils.GetOSEnv("SLACK_WEBHOOK", "SLACK_WEBHOOK"), 149 - "telegram_channel": utils.GetOSEnv("TELEGRAM_CHANNEL", "TELEGRAM_CHANNEL"), 150 - "telegram_status_channel": utils.GetOSEnv("TELEGRAM_STATUS_CHANNEL", "TELEGRAM_STATUS_CHANNEL"), 151 - "telegram_report_channel": utils.GetOSEnv("TELEGRAM_REPORT_CHANNEL", "TELEGRAM_REPORT_CHANNEL"), 152 - "telegram_sensitive_channel": utils.GetOSEnv("TELEGRAM_SENSITIVE_CHANNEL", "TELEGRAM_SENSITIVE_CHANNEL"), 153 - "telegram_dirb_channel": utils.GetOSEnv("TELEGRAM_DIRB_CHANNEL", "TELEGRAM_DIRB_CHANNEL"), 154 - "telegram_mics_channel": utils.GetOSEnv("TELEGRAM_MICS_CHANNEL", "TELEGRAM_MICS_CHANNEL"), 155 - }) 144 + v.Set("Notification", map[string]string{ 145 + "client_name": utils.GetOSEnv("CLIENT_NAME", "CLIENT_NAME"), 146 + "slack_status_channel": utils.GetOSEnv("SLACK_STATUS_CHANNEL", "SLACK_STATUS_CHANNEL"), 147 + "slack_report_channel": utils.GetOSEnv("SLACK_REPORT_CHANNEL", "SLACK_REPORT_CHANNEL"), 148 + "slack_diff_channel": utils.GetOSEnv("SLACK_DIFF_CHANNEL", "SLACK_DIFF_CHANNEL"), 149 + "slack_webhook": utils.GetOSEnv("SLACK_WEBHOOK", "SLACK_WEBHOOK"), 150 + "telegram_channel": utils.GetOSEnv("TELEGRAM_CHANNEL", "TELEGRAM_CHANNEL"), 151 + "telegram_status_channel": utils.GetOSEnv("TELEGRAM_STATUS_CHANNEL", "TELEGRAM_STATUS_CHANNEL"), 152 + "telegram_report_channel": utils.GetOSEnv("TELEGRAM_REPORT_CHANNEL", "TELEGRAM_REPORT_CHANNEL"), 153 + "telegram_sensitive_channel": utils.GetOSEnv("TELEGRAM_SENSITIVE_CHANNEL", "TELEGRAM_SENSITIVE_CHANNEL"), 154 + "telegram_dirb_channel": utils.GetOSEnv("TELEGRAM_DIRB_CHANNEL", "TELEGRAM_DIRB_CHANNEL"), 155 + "telegram_mics_channel": utils.GetOSEnv("TELEGRAM_MICS_CHANNEL", "TELEGRAM_MICS_CHANNEL"), 156 + }) 156 157 157 - // used for scaling 158 - //v.SetDefault("Master", map[string]string{ 159 - // "host": utils.GetOSEnv("MASTER_HOST", "MASTER_HOST"), 160 - // "cred": utils.GetOSEnv("MASTER_CRED", "MASTER_CRED"), 161 - //}) 162 - //v.SetDefault("Pool", map[string]string{ 163 - // "host": utils.GetOSEnv("POOL_HOST", "POOL_HOST"), 164 - // "cred": utils.GetOSEnv("POOL_CRED", "POOL_CRED"), 165 - //}) 166 - // enable sync 167 - //v.SetDefault("Sync", map[string]string{ 168 - // "firebase_url": utils.GetOSEnv("FIREBASE_URL", "FIREBASE_URL"), 169 - // "firebase_prefix": utils.GetOSEnv("FIREBASE_PREFIX", "FIREBASE_PREFIX"), 170 - // "firebase_pool": utils.GetOSEnv("FIREBASE_POOL", "FIREBASE_POOL"), 171 - //}) 158 + v.SetDefault("Mics", map[string]string{ 159 + "docs": utils.GetOSEnv("OSM_DOCS", libs.DOCS), 160 + }) 172 161 173 - v.SetDefault("Cdn", map[string]string{ 174 - "osm_cdn_url": utils.GetOSEnv("OSM_CDN_URL", "OSM_CDN_URL"), 175 - "osm_cdn_wsurl": utils.GetOSEnv("OSM_CDN_WSURL", "OSM_CDN_WSURL"), 176 - "osm_cdn_auth": utils.GetOSEnv("OSM_CDN_AUTH", "OSM_CDN_AUTH"), 177 - "osm_cdn_prefix": utils.GetOSEnv("OSM_CDN_PREFIX", "OSM_CDN_PREFIX"), 178 - "osm_cdn_index": utils.GetOSEnv("OSM_CDN_INDEX", "OSM_CDN_INDEX"), 179 - "osm_cdn_secret": utils.GetOSEnv("OSM_CDN_SECRET", "OSM_CDN_SECRET"), 180 - }) 162 + if err := v.WriteConfigAs(options.ConfigFile); err != nil { 163 + utils.ErrorF("Error writing config file: %s", err) 164 + } 181 165 182 - //v.SetDefault("Cloud", map[string]string{ 183 - // "cloud_public_key": utils.GetOSEnv("CLOUD_PUBLIC_KEY", "CLOUD_PUBLIC_KEY"), 184 - // "cloud_secret_key": utils.GetOSEnv("CLOUD_SECRET_KEY", "CLOUD_SECRET_KEY"), 185 - // "build_repo": utils.GetOSEnv("CLOUD_BUILD_REPO", "CLOUD_BUILD_REPO"), 186 - //}) 187 - 188 - //v.SetDefault("Update", map[string]string{ 189 - // "update_type": "http", 190 - // "update_url": utils.GetOSEnv("UPDATE_BASE_URL", "UPDATE_BASE_URL"), 191 - // "update_date": utils.GetOSEnv("UPDATE_DATE", "UPDATE_DATE"), 192 - // //"update_meta": utils.GetOSEnv("META_URL", "META_URL"), 193 - // "workflow": utils.GetOSEnv("UPDATE_URL", "UPDATE_URL"), 194 - //}) 166 + utils.InforF("Write config file to %s", options.ConfigFile) 167 + } 195 168 196 - v.SetDefault("Mics", map[string]string{ 197 - "docs": utils.GetOSEnv("OSM_DOCS", libs.DOCS), 198 - }) 169 + if isWritable, _ := utils.IsWritable(options.ConfigFile); isWritable { 170 + utils.ErrorF("config file does not writable: %v", options.ConfigFile) 171 + utils.BlockF("fatal", "Make sure you are login as 'root user' if your installation done via root user") 172 + os.Exit(-1) 173 + } 199 174 200 - v.WriteConfigAs(options.ConfigFile) 201 - } 175 + return nil 176 + } 202 177 203 - if isWritable, _ := utils.IsWritable(options.ConfigFile); isWritable { 204 - utils.ErrorF("config file does not writable: %v", options.ConfigFile) 205 - utils.BlockF("fatal", "Make sure you are login as 'root user' if your installation done via root user") 206 - os.Exit(-1) 207 - } 178 + func LoadConfig(options *libs.Options) { 179 + v = viper.New() 180 + v.SetConfigName("config") 181 + v.SetConfigType("yaml") 182 + v.AddConfigPath(options.ConfigFile) 183 + v.AddConfigPath(path.Dir(options.ConfigFile)) 208 184 209 - GetEnv(options) 210 - GetStorages(options) 211 - GetNotification(options) 212 - GetServer(options) 213 - GetClient(options) 214 - GetRemote(options) 215 - GetGit(options) 216 - //GetSync(options) 217 - GetCdn(options) 218 - SetupOpt(options) 219 - GetCloud(options) 220 - return nil 221 - } 185 + if err := v.ReadInConfig(); err != nil { 186 + utils.ErrorF("Error reading config file, %s", err) 187 + } 222 188 223 - // LoadConfig load config 224 - func LoadConfig(options libs.Options) (*viper.Viper, error) { 225 - options.ConfigFile, _ = homedir.Expand(options.ConfigFile) 226 - RootFolder := filepath.Dir(options.ConfigFile) 227 - v := viper.New() 228 - v.SetConfigName("config") 229 - v.SetConfigType("yaml") 230 - v.AddConfigPath(RootFolder) 231 - // InitConfig(&options) 232 - if err := v.ReadInConfig(); err != nil { 233 - InitConfig(&options) 234 - return v, nil 235 - } 236 - return v, nil 189 + GetEnv(options) 190 + GetStorages(options) 191 + GetNotification(options) 192 + GetServer(options) 193 + GetClient(options) 194 + GetRemote(options) 195 + GetGit(options) 196 + //GetSync(options) 197 + //GetCdn(options) 198 + SetupOpt(options) 199 + GetCloud(options) 237 200 } 238 201 239 202 // GetEnv get environment options 240 203 func GetEnv(options *libs.Options) { 241 - v, _ := LoadConfig(*options) 242 - envs := v.GetStringMapString("Environments") 204 + envs := v.GetStringMapString("Environments") 243 205 244 - // config 245 - options.Env.BinariesFolder = utils.NormalizePath(envs["binaries"]) 246 - utils.MakeDir(options.Env.BinariesFolder) 206 + // config 207 + options.Env.BinariesFolder = utils.NormalizePath(envs["binaries"]) 208 + utils.MakeDir(options.Env.BinariesFolder) 247 209 248 - options.Env.DataFolder = utils.NormalizePath(envs["data"]) 249 - utils.MakeDir(options.Env.DataFolder) 250 - // ose folder 251 - options.Env.OseFolder = path.Join(options.Env.BaseFolder, "ose") 252 - utils.MakeDir(options.Env.DataFolder) 210 + options.Env.DataFolder = utils.NormalizePath(envs["data"]) 211 + utils.MakeDir(options.Env.DataFolder) 212 + // ose folder 213 + options.Env.OseFolder = path.Join(options.Env.BaseFolder, "ose") 214 + utils.MakeDir(options.Env.DataFolder) 253 215 254 - options.Env.ScriptsFolder = path.Join(options.Env.BaseFolder, "scripts") 255 - options.Env.UIFolder = path.Join(options.Env.BaseFolder, "ui") 216 + options.Env.ScriptsFolder = path.Join(options.Env.BaseFolder, "scripts") 217 + options.Env.UIFolder = path.Join(options.Env.BaseFolder, "ui") 256 218 257 - // local data 258 - options.Env.StoragesFolder = utils.NormalizePath(envs["storages"]) 259 - utils.MakeDir(options.Env.StoragesFolder) 260 - options.Env.WorkspacesFolder = utils.NormalizePath(envs["workspaces"]) 261 - utils.MakeDir(options.Env.WorkspacesFolder) 219 + // local data 220 + options.Env.StoragesFolder = utils.NormalizePath(envs["storages"]) 221 + utils.MakeDir(options.Env.StoragesFolder) 222 + options.Env.WorkspacesFolder = utils.NormalizePath(envs["workspaces"]) 223 + utils.MakeDir(options.Env.WorkspacesFolder) 262 224 263 - // get workflow folder 264 - if options.Env.WorkFlowsFolder != "" { 265 - options.Env.WorkFlowsFolder = utils.NormalizePath(options.Env.WorkFlowsFolder) 266 - } 225 + // get workflow folder 226 + if options.Env.WorkFlowsFolder != "" { 227 + options.Env.WorkFlowsFolder = utils.NormalizePath(options.Env.WorkFlowsFolder) 228 + } 267 229 268 - customWorkflow := utils.GetOSEnv("CUSTOM_OSM_WORKFLOW", "CUSTOM_OSM_WORKFLOW") 269 - if customWorkflow != "CUSTOM_OSM_WORKFLOW" && options.Env.WorkFlowsFolder == "" { 270 - options.Env.WorkFlowsFolder = utils.NormalizePath(customWorkflow) 271 - } 230 + customWorkflow := utils.GetOSEnv("CUSTOM_OSM_WORKFLOW", "CUSTOM_OSM_WORKFLOW") 231 + if customWorkflow != "CUSTOM_OSM_WORKFLOW" && options.Env.WorkFlowsFolder == "" { 232 + options.Env.WorkFlowsFolder = utils.NormalizePath(customWorkflow) 233 + } 272 234 273 - if options.Env.WorkFlowsFolder == "" { 274 - options.Env.WorkFlowsFolder = utils.NormalizePath(envs["workflows"]) 275 - } 235 + if options.Env.WorkFlowsFolder == "" { 236 + options.Env.WorkFlowsFolder = utils.NormalizePath(envs["workflows"]) 237 + } 276 238 277 - if utils.FileExists(path.Join(options.Env.WorkFlowsFolder, "premium.md")) { 278 - options.PremiumPackage = true 279 - } 239 + if utils.FileExists(path.Join(options.Env.WorkFlowsFolder, "premium.md")) { 240 + options.PremiumPackage = true 241 + } 280 242 281 - // backup data 282 - options.Env.BackupFolder = utils.NormalizePath(envs["backups"]) 283 - utils.MakeDir(options.Env.BackupFolder) 243 + // backup data 244 + options.Env.BackupFolder = utils.NormalizePath(envs["backups"]) 245 + utils.MakeDir(options.Env.BackupFolder) 284 246 285 - // cloud stuff 247 + // cloud stuff 286 248 287 - // ~/.osmedeus/providers/ 288 - options.Env.ProviderFolder = utils.NormalizePath(envs["provider_config"]) 289 - utils.MakeDir(options.Env.ProviderFolder) 290 - // ~/osmedeus-base/clouds/ 291 - options.Env.CloudConfigFolder = utils.NormalizePath(envs["cloud_config"]) 249 + // ~/.osmedeus/providers/ 250 + options.Env.ProviderFolder = utils.NormalizePath(envs["provider_config"]) 251 + utils.MakeDir(options.Env.ProviderFolder) 252 + // ~/osmedeus-base/clouds/ 253 + options.Env.CloudConfigFolder = utils.NormalizePath(envs["cloud_config"]) 292 254 293 - //update := v.GetStringMapString("Update") 294 - //options.Update.UpdateURL = update["update_url"] 295 - //options.Update.UpdateType = update["update_type"] 296 - //options.Update.UpdateDate = update["update_date"] 297 - //options.Update.UpdateKey = update["update_key"] 298 - //options.Update.MetaDataURL = update["update_meta"] 299 - //UpdateMetadata(*options) 255 + //update := v.GetStringMapString("Update") 256 + //options.Update.UpdateURL = update["update_url"] 257 + //options.Update.UpdateType = update["update_type"] 258 + //options.Update.UpdateDate = update["update_date"] 259 + //options.Update.UpdateKey = update["update_key"] 260 + //options.Update.MetaDataURL = update["update_meta"] 261 + //UpdateMetadata(*options) 300 262 } 301 263 302 264 // SetupOpt get storage repos 303 265 func SetupOpt(options *libs.Options) { 304 - // auto append PATH with Plugin folder 305 - osPATH := utils.GetOSEnv("PATH", "PATH") 306 - if !strings.Contains(osPATH, options.Env.BinariesFolder) { 307 - utils.DebugF("Append $PATH with: %s", options.Env.BinariesFolder) 308 - os.Setenv("PATH", fmt.Sprintf("%s:%s", osPATH, strings.TrimRight(options.Env.BinariesFolder, "/"))) 309 - } 266 + // auto append PATH with Plugin folder 267 + osPATH := utils.GetOSEnv("PATH", "PATH") 268 + if !strings.Contains(osPATH, options.Env.BinariesFolder) { 269 + utils.DebugF("Append $PATH with: %s", options.Env.BinariesFolder) 270 + os.Setenv("PATH", fmt.Sprintf("%s:%s", osPATH, strings.TrimRight(options.Env.BinariesFolder, "/"))) 271 + } 310 272 311 - /* some special conditions below */ 273 + /* some special conditions below */ 312 274 313 - // change {{.Storage}} from ~/.osmedeus/storages to ~/.osmedeus/destorages 314 - if options.EnableDeStorage { 315 - utils.DebugF("Dedicated Storage Enabled") 316 - options.Env.StoragesFolder = options.Git.DeStorage 317 - if !utils.FolderExists(options.Env.StoragesFolder) { 318 - utils.MakeDir(options.Env.StoragesFolder) 319 - } 320 - } 275 + // change {{.Storage}} from ~/.osmedeus/storages to ~/.osmedeus/destorages 276 + if options.EnableDeStorage { 277 + utils.DebugF("Dedicated Storage Enabled") 278 + options.Env.StoragesFolder = options.Git.DeStorage 279 + if !utils.FolderExists(options.Env.StoragesFolder) { 280 + utils.MakeDir(options.Env.StoragesFolder) 281 + } 282 + } 321 283 } 322 284 323 285 func GetStorages(options *libs.Options) { 324 - if !options.PremiumPackage || utils.GetOSEnv("ENABLE_GIT_STORAGES", "") != "TRUE" { 325 - return 326 - } 286 + if !options.PremiumPackage || utils.GetOSEnv("ENABLE_GIT_STORAGES", "") != "TRUE" { 287 + return 288 + } 327 289 328 - v, _ := LoadConfig(*options) 329 - storages := v.GetStringMapString("Storages") 290 + storages := v.GetStringMapString("Storages") 330 291 331 - // get variables from config.yaml 332 - storagesOptions := make(map[string]string) 333 - for k, dest := range storages { 334 - storages[k] = utils.NormalizePath(dest) 335 - storagesOptions[k] = utils.NormalizePath(dest) 336 - } 337 - secretKey := storages["secret_key"] 338 - if secretKey == "" || secretKey == "SECRET_KEY" { 339 - return 340 - } 292 + // get variables from config.yaml 293 + storagesOptions := make(map[string]string) 294 + for k, dest := range storages { 295 + storages[k] = utils.NormalizePath(dest) 296 + storagesOptions[k] = utils.NormalizePath(dest) 297 + } 298 + secretKey := storages["secret_key"] 299 + if secretKey == "" || secretKey == "SECRET_KEY" { 300 + return 301 + } 341 302 342 - storagesOptions["secret_key"] = secretKey 343 - // load default existing key if it exists 344 - defaultKey := path.Join(options.Env.BaseFolder, "secret/storages_key") 345 - if !utils.FileExists(secretKey) && utils.FileExists(defaultKey) { 346 - utils.InforF("Loaded default secret for storages from: %v", color.HiCyanString(defaultKey)) 347 - if _, err := utils.RunCommandWithErr(fmt.Sprintf("cp %s %s && chmod 600 %s", defaultKey, secretKey, secretKey)); err != nil { 348 - utils.ErrorF("error copying default secret key: %v", defaultKey) 349 - } 350 - } 303 + storagesOptions["secret_key"] = secretKey 304 + // load default existing key if it exists 305 + defaultKey := path.Join(options.Env.BaseFolder, "secret/storages_key") 306 + if !utils.FileExists(secretKey) && utils.FileExists(defaultKey) { 307 + utils.InforF("Loaded default secret for storages from: %v", color.HiCyanString(defaultKey)) 308 + if _, err := utils.RunCommandWithErr(fmt.Sprintf("cp %s %s && chmod 600 %s", defaultKey, secretKey, secretKey)); err != nil { 309 + utils.ErrorF("error copying default secret key: %v", defaultKey) 310 + } 311 + } 351 312 352 - if !utils.FileExists(secretKey) { 353 - utils.InforF("No SSH key for storages found. Generate a new one at: %v", color.HiCyanString(secretKey)) 354 - if _, err := utils.RunCommandWithErr(fmt.Sprintf(`ssh-keygen -t ed25519 -f %s -q -N ''`, secretKey)); err != nil { 355 - color.Red("[-] error generated SSH Key for storages at: %v", secretKey) 356 - return 357 - } 358 - utils.InforF("Please add the public key at %v to your gitlab profile", color.HiCyanString(secretKey+".pub")) 359 - } 313 + if !utils.FileExists(secretKey) { 314 + utils.InforF("No SSH key for storages found. Generate a new one at: %v", color.HiCyanString(secretKey)) 315 + if _, err := utils.RunCommandWithErr(fmt.Sprintf(`ssh-keygen -t ed25519 -f %s -q -N ''`, secretKey)); err != nil { 316 + color.Red("[-] error generated SSH Key for storages at: %v", secretKey) 317 + return 318 + } 319 + utils.InforF("Please add the public key at %v to your gitlab profile", color.HiCyanString(secretKey+".pub")) 320 + } 360 321 361 - if !utils.FileExists("~/.gitconfig") { 362 - utils.WarnF("Looks like you didn't set up the git user at %v yet", color.HiCyanString("~/.gitconfig")) 363 - utils.WarnF(" Init git info with this command: %s", color.HiCyanString(`git config --global user.name "your-username" && git config --global user.email "[email protected]"`)) 364 - } 322 + if !utils.FileExists("~/.gitconfig") { 323 + utils.WarnF("Looks like you didn't set up the git user at %v yet", color.HiCyanString("~/.gitconfig")) 324 + utils.WarnF(" Init git info with this command: %s", color.HiCyanString(`git config --global user.name "your-username" && git config --global user.email "[email protected]"`)) 325 + } 365 326 366 - if options.CustomGit { 367 - // in case custom repo is set 368 - for _, env := range os.Environ() { 369 - // the ENV should be OSM_SUMMARY_STORAGE, OSM_SUMMARY_REPO 370 - if strings.HasSuffix(env, "OSM_") { 371 - data := strings.Split(env, "=") 372 - key := strings.ToLower(data[0]) 373 - value := strings.Replace(env, data[0]+"=", "", -1) 327 + if options.CustomGit { 328 + // in case custom repo is set 329 + for _, env := range os.Environ() { 330 + // the ENV should be OSM_SUMMARY_STORAGE, OSM_SUMMARY_REPO 331 + if strings.HasSuffix(env, "OSM_") { 332 + data := strings.Split(env, "=") 333 + key := strings.ToLower(data[0]) 334 + value := strings.Replace(env, data[0]+"=", "", -1) 374 335 375 - if strings.HasSuffix(key, "summary_storage") { 376 - storagesOptions["summary_storage"] = value 377 - } 378 - if strings.HasSuffix(key, "summary_repo") { 379 - storagesOptions["summary_repo"] = value 380 - } 336 + if strings.HasSuffix(key, "summary_storage") { 337 + storagesOptions["summary_storage"] = value 338 + } 339 + if strings.HasSuffix(key, "summary_repo") { 340 + storagesOptions["summary_repo"] = value 341 + } 381 342 382 - if strings.HasSuffix(key, "assets_storage") { 383 - storagesOptions["assets_storage"] = value 384 - } 385 - if strings.HasSuffix(key, "assets_repo") { 386 - storagesOptions["assets_repo"] = value 387 - } 343 + if strings.HasSuffix(key, "assets_storage") { 344 + storagesOptions["assets_storage"] = value 345 + } 346 + if strings.HasSuffix(key, "assets_repo") { 347 + storagesOptions["assets_repo"] = value 348 + } 388 349 389 - if strings.HasSuffix(key, "ports_storage") { 390 - storagesOptions["ports_storage"] = value 391 - } 392 - if strings.HasSuffix(key, "ports_repo") { 393 - storagesOptions["ports_repo"] = value 394 - } 395 - } 396 - } 397 - } 350 + if strings.HasSuffix(key, "ports_storage") { 351 + storagesOptions["ports_storage"] = value 352 + } 353 + if strings.HasSuffix(key, "ports_repo") { 354 + storagesOptions["ports_repo"] = value 355 + } 356 + } 357 + } 358 + } 398 359 399 - storagesOptions[storages["summary_storage"]] = storages["summary_repo"] 400 - storagesOptions[storages["subdomain_storage"]] = storages["subdomain_repo"] 401 - storagesOptions[storages["http_storage"]] = storages["http_repo"] 402 - storagesOptions[storages["assets_storage"]] = storages["assets_repo"] 403 - storagesOptions[storages["mics_storage"]] = storages["mics_repo"] 404 - storagesOptions[storages["ports_storage"]] = storages["ports_repo"] 405 - storagesOptions[storages["paths_storage"]] = storages["paths_repo"] 406 - storagesOptions[storages["vuln_storage"]] = storages["vuln_repo"] 407 - options.Storages = storagesOptions 360 + storagesOptions[storages["summary_storage"]] = storages["summary_repo"] 361 + storagesOptions[storages["subdomain_storage"]] = storages["subdomain_repo"] 362 + storagesOptions[storages["http_storage"]] = storages["http_repo"] 363 + storagesOptions[storages["assets_storage"]] = storages["assets_repo"] 364 + storagesOptions[storages["mics_storage"]] = storages["mics_repo"] 365 + storagesOptions[storages["ports_storage"]] = storages["ports_repo"] 366 + storagesOptions[storages["paths_storage"]] = storages["paths_repo"] 367 + storagesOptions[storages["vuln_storage"]] = storages["vuln_repo"] 368 + options.Storages = storagesOptions 408 369 409 - // disable git feature or no secret key found 410 - if options.NoGit { 411 - options.Storages["secret_key"] = "" 412 - } 413 - if options.Storages["secret_key"] == "" { 414 - options.NoGit = true 415 - } 370 + // disable git feature or no secret key found 371 + if options.NoGit { 372 + options.Storages["secret_key"] = "" 373 + } 374 + if options.Storages["secret_key"] == "" { 375 + options.NoGit = true 376 + } 416 377 417 - if options.NoGit { 418 - return 419 - } 420 - execution.CloneRepo(storages["summary_repo"], storages["summary_storage"], *options) 421 - execution.CloneRepo(storages["http_repo"], storages["http_storage"], *options) 422 - execution.CloneRepo(storages["assets_repo"], storages["assets_storage"], *options) 423 - execution.CloneRepo(storages["subdomain_repo"], storages["subdomain_storage"], *options) 424 - execution.CloneRepo(storages["ports_repo"], storages["ports_storage"], *options) 425 - execution.CloneRepo(storages["mics_repo"], storages["mics_storage"], *options) 426 - execution.CloneRepo(storages["paths_repo"], storages["paths_storage"], *options) 427 - execution.CloneRepo(storages["vuln_repo"], storages["vuln_storage"], *options) 378 + if options.NoGit { 379 + return 380 + } 381 + execution.CloneRepo(storages["summary_repo"], storages["summary_storage"], *options) 382 + execution.CloneRepo(storages["http_repo"], storages["http_storage"], *options) 383 + execution.CloneRepo(storages["assets_repo"], storages["assets_storage"], *options) 384 + execution.CloneRepo(storages["subdomain_repo"], storages["subdomain_storage"], *options) 385 + execution.CloneRepo(storages["ports_repo"], storages["ports_storage"], *options) 386 + execution.CloneRepo(storages["mics_repo"], storages["mics_storage"], *options) 387 + execution.CloneRepo(storages["paths_repo"], storages["paths_storage"], *options) 388 + execution.CloneRepo(storages["vuln_repo"], storages["vuln_storage"], *options) 428 389 } 429 390 430 391 // GetNotification get storge repos 431 392 func GetNotification(options *libs.Options) { 432 - v, _ := LoadConfig(*options) 433 - noti := v.GetStringMapString("Notification") 434 - tokens := v.GetStringMapString("Tokens") 393 + noti := v.GetStringMapString("Notification") 394 + tokens := v.GetStringMapString("Tokens") 435 395 436 - // tokens 437 - options.Noti.SlackToken = tokens["slack"] 438 - options.Noti.TelegramToken = tokens["telegram"] 396 + // tokens 397 + options.Noti.SlackToken = tokens["slack"] 398 + options.Noti.TelegramToken = tokens["telegram"] 439 399 440 - // this mean you're not setup the notification yet 441 - if len(options.Noti.TelegramToken) < 20 { 442 - options.NoNoti = true 443 - } 400 + // this mean you're not setup the notification yet 401 + if len(options.Noti.TelegramToken) < 20 { 402 + options.NoNoti = true 403 + } 444 404 445 - options.Noti.ClientName = noti["client_name"] 405 + options.Noti.ClientName = noti["client_name"] 446 406 447 - options.Noti.SlackStatusChannel = noti["slack_status_channel"] 448 - options.Noti.SlackReportChannel = noti["slack_report_channel"] 449 - options.Noti.SlackDiffChannel = noti["slack_diff_channel"] 450 - options.Noti.SlackWebHook = noti["slack_webhook"] 451 - options.Noti.TelegramChannel = noti["telegram_channel"] 452 - options.Noti.TelegramSensitiveChannel = noti["telegram_sensitive_channel"] 453 - options.Noti.TelegramReportChannel = noti["telegram_report_channel"] 454 - options.Noti.TelegramStatusChannel = noti["telegram_status_channel"] 455 - options.Noti.TelegramDirbChannel = noti["telegram_dirb_channel"] 456 - options.Noti.TelegramMicsChannel = noti["telegram_mics_channel"] 407 + options.Noti.SlackStatusChannel = noti["slack_status_channel"] 408 + options.Noti.SlackReportChannel = noti["slack_report_channel"] 409 + options.Noti.SlackDiffChannel = noti["slack_diff_channel"] 410 + options.Noti.SlackWebHook = noti["slack_webhook"] 411 + options.Noti.TelegramChannel = noti["telegram_channel"] 412 + options.Noti.TelegramSensitiveChannel = noti["telegram_sensitive_channel"] 413 + options.Noti.TelegramReportChannel = noti["telegram_report_channel"] 414 + options.Noti.TelegramStatusChannel = noti["telegram_status_channel"] 415 + options.Noti.TelegramDirbChannel = noti["telegram_dirb_channel"] 416 + options.Noti.TelegramMicsChannel = noti["telegram_mics_channel"] 457 417 } 458 418 459 419 func GetCloud(options *libs.Options) { 460 - if !options.PremiumPackage { 461 - return 462 - } 420 + if !options.PremiumPackage { 421 + return 422 + } 463 423 464 - // ~/osemedeus-base/cloud/provider.yaml 465 - cloudConfigFile := path.Join(options.Env.CloudConfigFolder, "provider.yaml") 424 + // ~/osemedeus-base/cloud/provider.yaml 425 + cloudConfigFile := path.Join(options.Env.CloudConfigFolder, "provider.yaml") 466 426 467 - options.CloudConfigFile = cloudConfigFile 468 - utils.DebugF("Parsing cloud config from: %s", options.CloudConfigFile) 469 - providerConfigs, err := provider.ParseProvider(options.CloudConfigFile) 427 + options.CloudConfigFile = cloudConfigFile 428 + utils.DebugF("Parsing cloud config from: %s", options.CloudConfigFile) 429 + providerConfigs, err := provider.ParseProvider(options.CloudConfigFile) 470 430 471 - if err != nil { 472 - utils.InforF(" You can start the wizard with the command: %s", color.HiCyanString("%s provider wizard", libs.BINARY)) 473 - } 431 + if err != nil { 432 + utils.InforF(" You can start the wizard with the command: %s", color.HiCyanString("%s provider wizard", libs.BINARY)) 433 + } 474 434 475 - options.Cloud.BuildRepo = providerConfigs.Builder.BuildRepo 476 - options.Cloud.SecretKey = utils.NormalizePath(providerConfigs.Builder.SecretKey) 477 - options.Cloud.PublicKey = utils.NormalizePath(providerConfigs.Builder.PublicKey) 478 - if options.Cloud.SecretKey == "" { 479 - options.Cloud.SecretKey = path.Join(options.Env.CloudConfigFolder, "ssh/cloud") 480 - options.Cloud.PublicKey = path.Join(options.Env.CloudConfigFolder, "ssh/cloud.pub") 481 - } 435 + options.Cloud.BuildRepo = providerConfigs.Builder.BuildRepo 436 + options.Cloud.SecretKey = utils.NormalizePath(providerConfigs.Builder.SecretKey) 437 + options.Cloud.PublicKey = utils.NormalizePath(providerConfigs.Builder.PublicKey) 438 + if options.Cloud.SecretKey == "" { 439 + options.Cloud.SecretKey = path.Join(options.Env.CloudConfigFolder, "ssh/cloud") 440 + options.Cloud.PublicKey = path.Join(options.Env.CloudConfigFolder, "ssh/cloud.pub") 441 + } 482 442 483 - // check SSH Keys 484 - if !utils.FileExists(options.Cloud.SecretKey) { 485 - keysDir := path.Dir(options.Cloud.SecretKey) 486 - os.RemoveAll(keysDir) 487 - utils.MakeDir(keysDir) 443 + // check SSH Keys 444 + if !utils.FileExists(options.Cloud.SecretKey) { 445 + keysDir := path.Dir(options.Cloud.SecretKey) 446 + os.RemoveAll(keysDir) 447 + utils.MakeDir(keysDir) 488 448 489 - utils.InforF("Generate SSH Key at: %v", options.Cloud.SecretKey) 490 - var err error 491 - _, err = utils.RunCommandWithErr(fmt.Sprintf(`ssh-keygen -t ed25519 -f %s -q -N ''`, options.Cloud.SecretKey)) 492 - if err != nil { 493 - color.Red("[-] error generated SSH Key for cloud config at: %v", options.Cloud.SecretKey) 494 - return 495 - } 496 - } 449 + utils.InforF("Generate SSH Key at: %v", options.Cloud.SecretKey) 450 + var err error 451 + _, err = utils.RunCommandWithErr(fmt.Sprintf(`ssh-keygen -t ed25519 -f %s -q -N ''`, options.Cloud.SecretKey)) 452 + if err != nil { 453 + color.Red("[-] error generated SSH Key for cloud config at: %v", options.Cloud.SecretKey) 454 + return 455 + } 456 + } 497 457 498 - if utils.FileExists(options.Cloud.SecretKey) { 499 - utils.DebugF("Detected secret key: %v", options.Cloud.SecretKey) 500 - utils.DebugF("Detected public key: %v", options.Cloud.PublicKey) 501 - options.Cloud.SecretKeyContent = strings.TrimSpace(utils.GetFileContent(options.Cloud.SecretKey)) 502 - options.Cloud.PublicKeyContent = strings.TrimSpace(utils.GetFileContent(options.Cloud.PublicKey)) 503 - } 458 + if utils.FileExists(options.Cloud.SecretKey) { 459 + utils.DebugF("Detected secret key: %v", options.Cloud.SecretKey) 460 + utils.DebugF("Detected public key: %v", options.Cloud.PublicKey) 461 + options.Cloud.SecretKeyContent = strings.TrimSpace(utils.GetFileContent(options.Cloud.SecretKey)) 462 + options.Cloud.PublicKeyContent = strings.TrimSpace(utils.GetFileContent(options.Cloud.PublicKey)) 463 + } 504 464 } 505 465 506 466 // GetServer get server options 507 467 func GetServer(options *libs.Options) { 508 - v, _ := LoadConfig(*options) 509 - server := v.GetStringMapString("Server") 468 + server := v.GetStringMapString("Server") 510 469 511 - options.Server.Bind = server["bind"] 512 - options.Server.Cors = server["cors"] 513 - options.Server.JWTSecret = server["secret"] 514 - options.Server.StaticPrefix = server["prefix"] 515 - options.Server.UIPath = utils.NormalizePath(server["ui"]) 516 - utils.MakeDir(path.Dir(options.Server.UIPath)) 470 + options.Server.Bind = server["bind"] 471 + options.Server.Cors = server["cors"] 472 + options.Server.JWTSecret = server["secret"] 473 + options.Server.StaticPrefix = server["prefix"] 474 + options.Server.UIPath = utils.NormalizePath(server["ui"]) 475 + utils.MakeDir(path.Dir(options.Server.UIPath)) 517 476 518 - options.Server.MasterPassword = server["master_pass"] 519 - options.Server.CertFile = utils.NormalizePath(server["cert_file"]) 520 - options.Server.KeyFile = utils.NormalizePath(server["key_file"]) 521 - utils.MakeDir(path.Dir(options.Server.CertFile)) 477 + options.Server.MasterPassword = server["master_pass"] 478 + options.Server.CertFile = utils.NormalizePath(server["cert_file"]) 479 + options.Server.KeyFile = utils.NormalizePath(server["key_file"]) 480 + utils.MakeDir(path.Dir(options.Server.CertFile)) 522 481 523 - db := v.GetStringMapString("Database") 482 + db := v.GetStringMapString("Database") 524 483 525 - options.Server.DBPath = utils.NormalizePath(db["db_path"]) 526 - options.Server.DBType = db["db_type"] 527 - // this should be remote one 528 - if options.Server.DBType == "mysql" { 529 - options.Server.DBUser = db["db_user"] 530 - options.Server.DBPass = db["db_pass"] 531 - options.Server.DBHost = db["db_host"] 532 - options.Server.DBPort = db["db_port"] 533 - options.Server.DBName = db["db_name"] 484 + options.Server.DBPath = utils.NormalizePath(db["db_path"]) 485 + options.Server.DBType = db["db_type"] 486 + // this should be remote one 487 + if options.Server.DBType == "mysql" { 488 + options.Server.DBUser = db["db_user"] 489 + options.Server.DBPass = db["db_pass"] 490 + options.Server.DBHost = db["db_host"] 491 + options.Server.DBPort = db["db_port"] 492 + options.Server.DBName = db["db_name"] 534 493 535 - // “user:password@/dbname?charset=utf8&parseTime=True&loc=Local” 536 - cred := fmt.Sprintf("%v:%v", options.Server.DBUser, options.Server.DBPass) 537 - dest := fmt.Sprintf("%v:%v", options.Server.DBHost, options.Server.DBPort) 538 - dbURL := fmt.Sprintf("%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=Local", cred, dest, options.Server.DBName) 539 - options.Server.DBConnection = dbURL 540 - } 494 + // “user:password@/dbname?charset=utf8&parseTime=True&loc=Local” 495 + cred := fmt.Sprintf("%v:%v", options.Server.DBUser, options.Server.DBPass) 496 + dest := fmt.Sprintf("%v:%v", options.Server.DBHost, options.Server.DBPort) 497 + dbURL := fmt.Sprintf("%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=Local", cred, dest, options.Server.DBName) 498 + options.Server.DBConnection = dbURL 499 + } 541 500 } 542 501 543 502 // GetRemote get server remote options 544 503 func GetRemote(options *libs.Options) { 545 - v, _ := LoadConfig(*options) 546 - master := v.GetStringMapString("Master") 547 - pool := v.GetStringMapString("Pool") 504 + master := v.GetStringMapString("Master") 505 + pool := v.GetStringMapString("Pool") 548 506 549 - options.Remote.MasterHost = master["host"] 550 - options.Remote.MasterCred = master["cred"] 551 - options.Remote.PoolHost = pool["host"] 552 - options.Remote.PoolCred = pool["cred"] 507 + options.Remote.MasterHost = master["host"] 508 + options.Remote.MasterCred = master["cred"] 509 + options.Remote.PoolHost = pool["host"] 510 + options.Remote.PoolCred = pool["cred"] 553 511 } 554 512 555 513 // GetClient get options for client 556 514 func GetClient(options *libs.Options) map[string]string { 557 - v, _ := LoadConfig(*options) 558 - client := v.GetStringMapString("Client") 559 - options.Client.Username = client["username"] 560 - options.Client.Password = client["password"] 561 - return client 515 + client := v.GetStringMapString("Client") 516 + options.Client.Username = client["username"] 517 + options.Client.Password = client["password"] 518 + return client 562 519 } 563 520 564 521 // GetGit get options for client 565 522 func GetGit(options *libs.Options) { 566 - v, _ := LoadConfig(*options) 567 - git := v.GetStringMapString("Git") 568 - options.Git.BaseURL = git["base_url"] 569 - options.Git.DeStorage = git["destorage"] 570 - options.Git.Token = git["api"] 571 - options.Git.Username = git["username"] 572 - options.Git.Password = git["password"] 573 - options.Git.Group = git["group"] 574 - options.Git.DefaultPrefix = git["prefix_name"] 575 - options.Git.DefaultTag = git["default_tag"] 576 - options.Git.DefaultUser = git["default_user"] 577 - options.Git.DefaultUID = utils.StrToInt(git["default_uid"]) 523 + git := v.GetStringMapString("Git") 524 + options.Git.BaseURL = git["base_url"] 525 + options.Git.DeStorage = git["destorage"] 526 + options.Git.Token = git["api"] 527 + options.Git.Username = git["username"] 528 + options.Git.Password = git["password"] 529 + options.Git.Group = git["group"] 530 + options.Git.DefaultPrefix = git["prefix_name"] 531 + options.Git.DefaultTag = git["default_tag"] 532 + options.Git.DefaultUser = git["default_user"] 533 + options.Git.DefaultUID = utils.StrToInt(git["default_uid"]) 578 534 } 579 535 580 - // 581 - //// GetSync get options for client 582 - //func GetSync(options *libs.Options) { 583 - // v, _ := LoadConfig(*options) 584 - // fb := v.GetStringMapString("Sync") 585 - // options.Sync.BaseURL = fb["firebase_url"] 586 - // options.Sync.Prefix = fb["firebase_prefix"] 587 - // options.Sync.Pool = fb["firebase_pool"] 588 - //} 589 - 590 536 // GetCdn get options for client 591 537 func GetCdn(options *libs.Options) { 592 - v, _ := LoadConfig(*options) 593 - cdn := v.GetStringMapString("Cdn") 594 - options.Cdn.URL = cdn["osm_cdn_url"] 595 - options.Cdn.WSURL = cdn["osm_cdn_wsurl"] 596 - options.Cdn.Prefix = cdn["osm_cdn_prefix"] 597 - options.Cdn.Index = cdn["osm_cdn_index"] 538 + cdn := v.GetStringMapString("Cdn") 539 + options.Cdn.URL = cdn["osm_cdn_url"] 540 + options.Cdn.WSURL = cdn["osm_cdn_wsurl"] 541 + options.Cdn.Prefix = cdn["osm_cdn_prefix"] 542 + options.Cdn.Index = cdn["osm_cdn_index"] 598 543 599 - // in case we have prefix 600 - if options.Cdn.Prefix != "OSM_CDN_PREFIX" { 601 - u, err := url.Parse(options.Cdn.URL) 602 - if err == nil { 603 - u.Path = path.Join(u.Path, options.Cdn.Prefix) 604 - options.Cdn.URL = u.String() 605 - } 544 + // in case we have prefix 545 + if options.Cdn.Prefix != "OSM_CDN_PREFIX" { 546 + u, err := url.Parse(options.Cdn.URL) 547 + if err == nil { 548 + u.Path = path.Join(u.Path, options.Cdn.Prefix) 549 + options.Cdn.URL = u.String() 550 + } 606 551 607 - u, err = url.Parse(options.Cdn.WSURL) 608 - if err == nil { 609 - u.Path = path.Join(u.Path, options.Cdn.Prefix) 610 - options.Cdn.WSURL = u.String() 611 - } 612 - } 552 + u, err = url.Parse(options.Cdn.WSURL) 553 + if err == nil { 554 + u.Path = path.Join(u.Path, options.Cdn.Prefix) 555 + options.Cdn.WSURL = u.String() 556 + } 557 + } 613 558 614 - options.Cdn.Auth = cdn["osm_cdn_auth"] 559 + options.Cdn.Auth = cdn["osm_cdn_auth"] 615 560 } 616 561 617 562 // ReloadConfig get credentials 618 563 func ReloadConfig(options libs.Options) { 619 - utils.InforF("Reload Env for config file: %v", options.ConfigFile) 620 - v, _ := LoadConfig(options) 564 + utils.InforF("Reload Env for config file: %v", options.ConfigFile) 621 565 622 - // options.ConfigFile, _ = homedir.Expand(options.ConfigFile) 623 - RootFolder := filepath.Dir(utils.NormalizePath(options.ConfigFile)) 624 - if !utils.FolderExists(RootFolder) { 625 - os.MkdirAll(RootFolder, 0750) 626 - } 627 - // Base folder 628 - BaseFolder := utils.NormalizePath(options.Env.BaseFolder) 629 - if !utils.FolderExists(BaseFolder) { 630 - os.MkdirAll(BaseFolder, 0750) 631 - } 566 + // options.ConfigFile, _ = homedir.Expand(options.ConfigFile) 567 + RootFolder := filepath.Dir(utils.NormalizePath(options.ConfigFile)) 568 + if !utils.FolderExists(RootFolder) { 569 + os.MkdirAll(RootFolder, 0750) 570 + } 571 + // Base folder 572 + BaseFolder := utils.NormalizePath(options.Env.BaseFolder) 573 + if !utils.FolderExists(BaseFolder) { 574 + os.MkdirAll(BaseFolder, 0750) 575 + } 632 576 633 - v.Set("Environments", map[string]string{ 634 - // RootFolder --> ~/.osmedeus/ 635 - "storages": path.Join(RootFolder, "storages"), 636 - "workspaces": path.Join(RootFolder, "workspaces"), 637 - "backups": path.Join(RootFolder, "backups"), 638 - "provider_config": path.Join(RootFolder, "provider"), 577 + v.Set("Environments", map[string]string{ 578 + // RootFolder --> ~/.osmedeus/ 579 + "storages": path.Join(RootFolder, "storages"), 580 + "workspaces": path.Join(RootFolder, "workspaces"), 581 + "backups": path.Join(RootFolder, "backups"), 582 + "provider_config": path.Join(RootFolder, "provider"), 639 583 640 - // this update casually 641 - // BaseFolder --> ~/osmedeus-base/ 642 - "workflows": path.Join(BaseFolder, "workflow"), 643 - "binaries": path.Join(BaseFolder, "binaries"), 644 - "data": path.Join(BaseFolder, "data"), 645 - "cloud_config": path.Join(BaseFolder, "cloud"), 646 - }) 584 + // this update casually 585 + // BaseFolder --> ~/osmedeus-base/ 586 + "workflows": path.Join(BaseFolder, "workflow"), 587 + "binaries": path.Join(BaseFolder, "binaries"), 588 + "data": path.Join(BaseFolder, "data"), 589 + "cloud_config": path.Join(BaseFolder, "cloud"), 590 + }) 647 591 648 - // things should be reload by env 649 - v.Set("Storages", map[string]string{ 650 - // path of secret key for push result 651 - "secret_key": utils.GetOSEnv("SECRET_KEY", "SECRET_KEY"), 652 - // the repo format should be like this "[email protected]:j3ssie/example.git", 653 - "summary_storage": path.Join(options.Env.RootFolder, "storages/summary"), 654 - "summary_repo": utils.GetOSEnv("SUMMARY_REPO", "SUMMARY_REPO"), 655 - "subdomain_storage": path.Join(options.Env.RootFolder, "storages/subdomain"), 656 - "subdomain_repo": utils.GetOSEnv("SUBDOMAIN_REPO", "SUBDOMAIN_REPO"), 657 - "assets_storage": path.Join(options.Env.RootFolder, "storages/assets"), 658 - "assets_repo": utils.GetOSEnv("ASSETS_REPO", "ASSETS_REPO"), 659 - "ports_storage": path.Join(options.Env.RootFolder, "storages/ports"), 660 - "ports_repo": utils.GetOSEnv("PORTS_REPO", "PORTS_REPO"), 661 - "http_storage": path.Join(options.Env.RootFolder, "storages/http"), 662 - "http_repo": utils.GetOSEnv("HTTP_REPO", "HTTP_REPO"), 663 - "vuln_storage": path.Join(options.Env.RootFolder, "storages/vuln"), 664 - "vuln_repo": utils.GetOSEnv("VULN_REPO", "VULN_REPO"), 665 - "paths_storage": path.Join(options.Env.RootFolder, "storages/paths"), 666 - "paths_repo": utils.GetOSEnv("PATHS_REPO", "PATHS_REPO"), 667 - "mics_storage": path.Join(options.Env.RootFolder, "storages/mics"), 668 - "mics_repo": utils.GetOSEnv("MICS_REPO", "MICS_REPO"), 669 - }) 592 + // things should be reload by env 593 + v.Set("Storages", map[string]string{ 594 + // path of secret key for push result 595 + "secret_key": utils.GetOSEnv("SECRET_KEY", "SECRET_KEY"), 596 + // the repo format should be like this "[email protected]:j3ssie/example.git", 597 + "summary_storage": path.Join(options.Env.RootFolder, "storages/summary"), 598 + "summary_repo": utils.GetOSEnv("SUMMARY_REPO", "SUMMARY_REPO"), 599 + "subdomain_storage": path.Join(options.Env.RootFolder, "storages/subdomain"), 600 + "subdomain_repo": utils.GetOSEnv("SUBDOMAIN_REPO", "SUBDOMAIN_REPO"), 601 + "assets_storage": path.Join(options.Env.RootFolder, "storages/assets"), 602 + "assets_repo": utils.GetOSEnv("ASSETS_REPO", "ASSETS_REPO"), 603 + "ports_storage": path.Join(options.Env.RootFolder, "storages/ports"), 604 + "ports_repo": utils.GetOSEnv("PORTS_REPO", "PORTS_REPO"), 605 + "http_storage": path.Join(options.Env.RootFolder, "storages/http"), 606 + "http_repo": utils.GetOSEnv("HTTP_REPO", "HTTP_REPO"), 607 + "vuln_storage": path.Join(options.Env.RootFolder, "storages/vuln"), 608 + "vuln_repo": utils.GetOSEnv("VULN_REPO", "VULN_REPO"), 609 + "paths_storage": path.Join(options.Env.RootFolder, "storages/paths"), 610 + "paths_repo": utils.GetOSEnv("PATHS_REPO", "PATHS_REPO"), 611 + "mics_storage": path.Join(options.Env.RootFolder, "storages/mics"), 612 + "mics_repo": utils.GetOSEnv("MICS_REPO", "MICS_REPO"), 613 + }) 670 614 671 - v.Set("Tokens", map[string]string{ 672 - "slack": utils.GetOSEnv("SLACK_API_TOKEN", "SLACK_API_TOKEN"), 673 - "gitlab": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 674 - "github": utils.GetOSEnv("GITHUB_API_KEY", "GITHUB_API_KEY"), 675 - "telegram": utils.GetOSEnv("TELEGRAM_API_TOKEN", "TELEGRAM_API_TOKEN"), 676 - }) 615 + v.Set("Tokens", map[string]string{ 616 + "slack": utils.GetOSEnv("SLACK_API_TOKEN", "SLACK_API_TOKEN"), 617 + "gitlab": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 618 + "github": utils.GetOSEnv("GITHUB_API_KEY", "GITHUB_API_KEY"), 619 + "telegram": utils.GetOSEnv("TELEGRAM_API_TOKEN", "TELEGRAM_API_TOKEN"), 620 + }) 677 621 678 - v.Set("Git", map[string]string{ 679 - "base_url": utils.GetOSEnv("GITLAB_BASE_URL", "https://gitlab.com"), 680 - "api": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 681 - "username": utils.GetOSEnv("GITLAB_USER", "GITLAB_USER"), 682 - "password": utils.GetOSEnv("GITLAB_PASS", "GITLAB_PASS"), 683 - "group": utils.GetOSEnv("GITLAB_GROUP", "GITLAB_GROUP"), 684 - "prefix_name": utils.GetOSEnv("GITLAB_PREFIX_NAME", "deosm"), 685 - "default_tag": utils.GetOSEnv("GITLAB_DEFAULT_TAG", "osmd"), 686 - "default_user": utils.GetOSEnv("GITLAB_DEFAULT_USER", "j3ssie"), 687 - "default_uid": utils.GetOSEnv("GITLAB_DEFAULT_UID", "3537075"), 688 - "destorage": path.Join(options.Env.RootFolder, "destorage"), 689 - }) 622 + v.Set("Git", map[string]string{ 623 + "base_url": utils.GetOSEnv("GITLAB_BASE_URL", "https://gitlab.com"), 624 + "api": utils.GetOSEnv("GITLAB_API_TOKEN", "GITLAB_API_TOKEN"), 625 + "username": utils.GetOSEnv("GITLAB_USER", "GITLAB_USER"), 626 + "password": utils.GetOSEnv("GITLAB_PASS", "GITLAB_PASS"), 627 + "group": utils.GetOSEnv("GITLAB_GROUP", "GITLAB_GROUP"), 628 + "prefix_name": utils.GetOSEnv("GITLAB_PREFIX_NAME", "deosm"), 629 + "default_tag": utils.GetOSEnv("GITLAB_DEFAULT_TAG", "osmd"), 630 + "default_user": utils.GetOSEnv("GITLAB_DEFAULT_USER", "j3ssie"), 631 + "default_uid": utils.GetOSEnv("GITLAB_DEFAULT_UID", "3537075"), 632 + "destorage": path.Join(options.Env.RootFolder, "destorage"), 633 + }) 690 634 691 - v.Set("Notification", map[string]string{ 692 - "client_name": utils.GetOSEnv("CLIENT_NAME", "CLIENT_NAME"), 693 - "slack_status_channel": utils.GetOSEnv("SLACK_STATUS_CHANNEL", "SLACK_STATUS_CHANNEL"), 694 - "slack_report_channel": utils.GetOSEnv("SLACK_REPORT_CHANNEL", "SLACK_REPORT_CHANNEL"), 695 - "slack_diff_channel": utils.GetOSEnv("SLACK_DIFF_CHANNEL", "SLACK_DIFF_CHANNEL"), 696 - "slack_webhook": utils.GetOSEnv("SLACK_WEBHOOK", "SLACK_WEBHOOK"), 697 - "telegram_channel": utils.GetOSEnv("TELEGRAM_CHANNEL", "TELEGRAM_CHANNEL"), 698 - "telegram_status_channel": utils.GetOSEnv("TELEGRAM_STATUS_CHANNEL", "TELEGRAM_STATUS_CHANNEL"), 699 - "telegram_report_channel": utils.GetOSEnv("TELEGRAM_REPORT_CHANNEL", "TELEGRAM_REPORT_CHANNEL"), 700 - "telegram_sensitive_channel": utils.GetOSEnv("TELEGRAM_SENSITIVE_CHANNEL", "TELEGRAM_SENSITIVE_CHANNEL"), 701 - "telegram_dirb_channel": utils.GetOSEnv("TELEGRAM_DIRB_CHANNEL", "TELEGRAM_DIRB_CHANNEL"), 702 - "telegram_mics_channel": utils.GetOSEnv("TELEGRAM_MICS_CHANNEL", "TELEGRAM_MICS_CHANNEL"), 703 - }) 704 - 705 - v.Set("Cdn", map[string]string{ 706 - "osm_cdn_url": utils.GetOSEnv("OSM_CDN_URL", "OSM_CDN_URL"), 707 - "osm_cdn_wsurl": utils.GetOSEnv("OSM_CDN_WSURL", "OSM_CDN_WSURL"), 708 - "osm_cdn_auth": utils.GetOSEnv("OSM_CDN_AUTH", "OSM_CDN_AUTH"), 709 - "osm_cdn_prefix": utils.GetOSEnv("OSM_CDN_PREFIX", "OSM_CDN_PREFIX"), 710 - "osm_cdn_index": utils.GetOSEnv("OSM_CDN_INDEX", "OSM_CDN_INDEX"), 711 - "osm_cdn_secret": utils.GetOSEnv("OSM_CDN_SECRET", "OSM_CDN_SECRET"), 712 - }) 635 + v.Set("Notification", map[string]string{ 636 + "client_name": utils.GetOSEnv("CLIENT_NAME", "CLIENT_NAME"), 637 + "slack_status_channel": utils.GetOSEnv("SLACK_STATUS_CHANNEL", "SLACK_STATUS_CHANNEL"), 638 + "slack_report_channel": utils.GetOSEnv("SLACK_REPORT_CHANNEL", "SLACK_REPORT_CHANNEL"), 639 + "slack_diff_channel": utils.GetOSEnv("SLACK_DIFF_CHANNEL", "SLACK_DIFF_CHANNEL"), 640 + "slack_webhook": utils.GetOSEnv("SLACK_WEBHOOK", "SLACK_WEBHOOK"), 641 + "telegram_channel": utils.GetOSEnv("TELEGRAM_CHANNEL", "TELEGRAM_CHANNEL"), 642 + "telegram_status_channel": utils.GetOSEnv("TELEGRAM_STATUS_CHANNEL", "TELEGRAM_STATUS_CHANNEL"), 643 + "telegram_report_channel": utils.GetOSEnv("TELEGRAM_REPORT_CHANNEL", "TELEGRAM_REPORT_CHANNEL"), 644 + "telegram_sensitive_channel": utils.GetOSEnv("TELEGRAM_SENSITIVE_CHANNEL", "TELEGRAM_SENSITIVE_CHANNEL"), 645 + "telegram_dirb_channel": utils.GetOSEnv("TELEGRAM_DIRB_CHANNEL", "TELEGRAM_DIRB_CHANNEL"), 646 + "telegram_mics_channel": utils.GetOSEnv("TELEGRAM_MICS_CHANNEL", "TELEGRAM_MICS_CHANNEL"), 647 + }) 713 648 714 - v.WriteConfig() 649 + v.WriteConfig() 715 650 } 716 651 -
-
-
1 1 package core 2 2 3 3 import ( 4 - "fmt" 5 - "github.com/j3ssie/osmedeus/execution" 6 - "github.com/j3ssie/osmedeus/utils" 7 - "github.com/robertkrimen/otto" 8 - "path" 9 - "time" 4 + "fmt" 5 + "github.com/j3ssie/osmedeus/execution" 6 + "github.com/j3ssie/osmedeus/utils" 7 + "github.com/robertkrimen/otto" 8 + "path" 9 + "time" 10 10 ) 11 11 12 12 func (r *Runner) LoadExternalScripts() string { 13 - var output string 14 - vm := r.VM 13 + var output string 14 + vm := r.VM 15 15 16 - // special scripts 17 - vm.Set(Cleaning, func(call otto.FunctionCall) otto.Value { 18 - if r.Opt.NoClean { 19 - utils.InforF("Disabled Cleaning") 20 - return otto.Value{} 21 - } 22 - execution.Cleaning(call.Argument(0).String(), r.Reports) 23 - return otto.Value{} 24 - }) 16 + // special scripts 17 + vm.Set(Cleaning, func(call otto.FunctionCall) otto.Value { 18 + if r.Opt.NoClean { 19 + utils.InforF("Disabled Cleaning") 20 + return otto.Value{} 21 + } 22 + execution.Cleaning(call.Argument(0).String(), r.Reports) 23 + return otto.Value{} 24 + }) 25 25 26 - // scripts for cleaning modules 27 - vm.Set(CleanAmass, func(call otto.FunctionCall) otto.Value { 28 - src := call.Argument(0).String() 29 - dest := call.Argument(1).String() 30 - execution.CleanAmass(src, dest) 31 - return otto.Value{} 32 - }) 26 + // scripts for cleaning modules 27 + vm.Set(CleanAmass, func(call otto.FunctionCall) otto.Value { 28 + src := call.Argument(0).String() 29 + dest := call.Argument(1).String() 30 + execution.CleanAmass(src, dest) 31 + return otto.Value{} 32 + }) 33 33 34 - vm.Set(CleanRustScan, func(call otto.FunctionCall) otto.Value { 35 - src := call.Argument(0).String() 36 - dest := call.Argument(1).String() 37 - execution.CleanRustScan(src, dest) 38 - return otto.Value{} 39 - }) 34 + vm.Set(CleanRustScan, func(call otto.FunctionCall) otto.Value { 35 + src := call.Argument(0).String() 36 + dest := call.Argument(1).String() 37 + execution.CleanRustScan(src, dest) 38 + return otto.Value{} 39 + }) 40 40 41 - vm.Set(CleanGoBuster, func(call otto.FunctionCall) otto.Value { 42 - src := call.Argument(0).String() 43 - dest := call.Argument(1).String() 44 - execution.CleanGoBuster(src, dest) 45 - return otto.Value{} 46 - }) 47 - vm.Set(CleanMassdns, func(call otto.FunctionCall) otto.Value { 48 - src := call.Argument(0).String() 49 - dest := call.Argument(1).String() 50 - execution.CleanMassdns(src, dest) 51 - return otto.Value{} 52 - }) 41 + vm.Set(CleanGoBuster, func(call otto.FunctionCall) otto.Value { 42 + src := call.Argument(0).String() 43 + dest := call.Argument(1).String() 44 + execution.CleanGoBuster(src, dest) 45 + return otto.Value{} 46 + }) 47 + vm.Set(CleanMassdns, func(call otto.FunctionCall) otto.Value { 48 + src := call.Argument(0).String() 49 + dest := call.Argument(1).String() 50 + execution.CleanMassdns(src, dest) 51 + return otto.Value{} 52 + }) 53 53 54 - vm.Set(CleanSWebanalyze, func(call otto.FunctionCall) otto.Value { 55 - src := call.Argument(0).String() 56 - dest := call.Argument(1).String() 57 - execution.CleanSWebanalyze(src, dest) 58 - return otto.Value{} 59 - }) 60 - vm.Set(CleanJSONDnsx, func(call otto.FunctionCall) otto.Value { 61 - src := call.Argument(0).String() 62 - dest := call.Argument(1).String() 63 - execution.CleanJSONDnsx(src, dest) 64 - return otto.Value{} 65 - }) 54 + vm.Set(CleanSWebanalyze, func(call otto.FunctionCall) otto.Value { 55 + src := call.Argument(0).String() 56 + dest := call.Argument(1).String() 57 + execution.CleanSWebanalyze(src, dest) 58 + return otto.Value{} 59 + }) 60 + vm.Set(CleanJSONDnsx, func(call otto.FunctionCall) otto.Value { 61 + src := call.Argument(0).String() 62 + dest := call.Argument(1).String() 63 + execution.CleanJSONDnsx(src, dest) 64 + return otto.Value{} 65 + }) 66 66 67 - vm.Set(CleanJSONHttpx, func(call otto.FunctionCall) otto.Value { 68 - src := call.Argument(0).String() 69 - dest := call.Argument(1).String() 70 - execution.CleanJSONHttpx(src, dest) 71 - return otto.Value{} 72 - }) 67 + vm.Set(CleanJSONHttpx, func(call otto.FunctionCall) otto.Value { 68 + src := call.Argument(0).String() 69 + dest := call.Argument(1).String() 70 + execution.CleanJSONHttpx(src, dest) 71 + return otto.Value{} 72 + }) 73 73 74 - // Deprecated 75 - vm.Set(CleanWebanalyze, func(call otto.FunctionCall) otto.Value { 76 - src := call.Argument(0).String() 77 - dest := call.Argument(1).String() 78 - args := call.ArgumentList 74 + // Deprecated 75 + vm.Set(CleanWebanalyze, func(call otto.FunctionCall) otto.Value { 76 + src := call.Argument(0).String() 77 + dest := call.Argument(1).String() 78 + args := call.ArgumentList 79 79 80 - techSum := path.Join(path.Dir(dest), fmt.Sprintf("tech-overview-%v.txt", r.Target["Workspace"])) 81 - if len(args) > 3 { 82 - techSum = args[2].String() 83 - } 84 - execution.CleanWebanalyze(src, dest, techSum) 85 - return otto.Value{} 86 - }) 80 + techSum := path.Join(path.Dir(dest), fmt.Sprintf("tech-overview-%v.txt", r.Target["Workspace"])) 81 + if len(args) > 3 { 82 + techSum = args[2].String() 83 + } 84 + execution.CleanWebanalyze(src, dest, techSum) 85 + return otto.Value{} 86 + }) 87 87 88 - vm.Set(CleanArjun, func(call otto.FunctionCall) otto.Value { 89 - // src mean folder contain arjun output 90 - src := call.Argument(0).String() 91 - dest := call.Argument(1).String() 92 - execution.CleanArjun(src, dest) 93 - return otto.Value{} 94 - }) 88 + vm.Set(CleanArjun, func(call otto.FunctionCall) otto.Value { 89 + // src mean folder contain arjun output 90 + src := call.Argument(0).String() 91 + dest := call.Argument(1).String() 92 + execution.CleanArjun(src, dest) 93 + return otto.Value{} 94 + }) 95 95 96 - vm.Set(CleanFFUFJson, func(call otto.FunctionCall) otto.Value { 97 - src := call.Argument(0).String() 98 - dest := call.Argument(1).String() 99 - execution.CleanFFUFJson(src, dest) 100 - return otto.Value{} 101 - }) 96 + vm.Set(CleanFFUFJson, func(call otto.FunctionCall) otto.Value { 97 + src := call.Argument(0).String() 98 + dest := call.Argument(1).String() 99 + execution.CleanFFUFJson(src, dest) 100 + return otto.Value{} 101 + }) 102 102 103 - vm.Set(GenNucleiReport, func(call otto.FunctionCall) otto.Value { 104 - src := call.Argument(0).String() 105 - dest := call.Argument(1).String() 106 - args := call.ArgumentList 103 + vm.Set(GenNucleiReport, func(call otto.FunctionCall) otto.Value { 104 + src := call.Argument(0).String() 105 + dest := call.Argument(1).String() 106 + args := call.ArgumentList 107 107 108 - templateFile := "" 109 - if len(args) >= 3 { 110 - templateFile = args[2].String() 111 - } 112 - execution.GenNucleiReport(r.Opt, src, dest, templateFile) 113 - return otto.Value{} 114 - }) 108 + templateFile := "" 109 + if len(args) >= 3 { 110 + templateFile = args[2].String() 111 + } 112 + execution.GenNucleiReport(r.Opt, src, dest, templateFile) 113 + return otto.Value{} 114 + }) 115 115 116 - return output 116 + return output 117 117 } 118 118 119 119 func (r *Runner) LoadGitScripts() string { 120 - var output string 121 - vm := r.VM 122 - options := r.Opt 120 + var output string 121 + vm := r.VM 122 + options := r.Opt 123 123 124 - // Clone("[email protected]", "/tmp/dest") 125 - vm.Set(Clone, func(call otto.FunctionCall) otto.Value { 126 - execution.GitClone(call.Argument(0).String(), call.Argument(1).String(), false, options) 127 - return otto.Value{} 128 - }) 129 - // like clone but delete the destination folder first 130 - vm.Set(FClone, func(call otto.FunctionCall) otto.Value { 131 - execution.GitClone(call.Argument(0).String(), call.Argument(1).String(), true, options) 132 - return otto.Value{} 133 - }) 124 + // Clone("[email protected]", "/tmp/dest") 125 + vm.Set(Clone, func(call otto.FunctionCall) otto.Value { 126 + execution.GitClone(call.Argument(0).String(), call.Argument(1).String(), false, options) 127 + return otto.Value{} 128 + }) 129 + // like clone but delete the destination folder first 130 + vm.Set(FClone, func(call otto.FunctionCall) otto.Value { 131 + execution.GitClone(call.Argument(0).String(), call.Argument(1).String(), true, options) 132 + return otto.Value{} 133 + }) 134 134 135 - vm.Set(PushResult, func(call otto.FunctionCall) otto.Value { 136 - for folder := range options.Storages { 137 - execution.PullResult(folder, options) 138 - time.Sleep(3 * time.Second) 139 - execution.PullResult(folder, options) 140 - commitMess := fmt.Sprintf("%v|%v|%v", options.Module.Name, options.Scan.ROptions["Workspace"], utils.GetCurrentDay()) 141 - execution.PushResult(folder, commitMess, options) 142 - } 143 - return otto.Value{} 144 - }) 145 - // push result but specific folder 146 - vm.Set(PushFolder, func(call otto.FunctionCall) otto.Value { 147 - folder := call.Argument(0).String() 148 - execution.PullResult(folder, options) 149 - time.Sleep(3 * time.Second) 150 - execution.PullResult(folder, options) 151 - commitMess := fmt.Sprintf("%v|%v|%v", options.Module.Name, options.Scan.ROptions["Workspace"], utils.GetCurrentDay()) 152 - execution.PushResult(folder, commitMess, options) 153 - return otto.Value{} 154 - }) 135 + vm.Set(PushResult, func(call otto.FunctionCall) otto.Value { 136 + for folder := range options.Storages { 137 + execution.PullResult(folder, options) 138 + time.Sleep(3 * time.Second) 139 + execution.PullResult(folder, options) 140 + commitMess := fmt.Sprintf("%v|%v|%v", options.Module.Name, options.Scan.ROptions["Workspace"], utils.GetCurrentDay()) 141 + execution.PushResult(folder, commitMess, options) 142 + } 143 + return otto.Value{} 144 + }) 145 + // push result but specific folder 146 + vm.Set(PushFolder, func(call otto.FunctionCall) otto.Value { 147 + folder := call.Argument(0).String() 148 + execution.PullResult(folder, options) 149 + time.Sleep(3 * time.Second) 150 + execution.PullResult(folder, options) 151 + commitMess := fmt.Sprintf("%v|%v|%v", options.Module.Name, options.Scan.ROptions["Workspace"], utils.GetCurrentDay()) 152 + execution.PushResult(folder, commitMess, options) 153 + return otto.Value{} 154 + }) 155 155 156 - // push result but specific folder 157 - vm.Set(PullFolder, func(call otto.FunctionCall) otto.Value { 158 - folder := call.Argument(0).String() 159 - execution.PullResult(folder, options) 160 - time.Sleep(3 * time.Second) 161 - execution.PullResult(folder, options) 162 - return otto.Value{} 163 - }) 156 + // push result but specific folder 157 + vm.Set(PullFolder, func(call otto.FunctionCall) otto.Value { 158 + folder := call.Argument(0).String() 159 + execution.PullResult(folder, options) 160 + time.Sleep(3 * time.Second) 161 + execution.PullResult(folder, options) 162 + return otto.Value{} 163 + }) 164 164 165 - vm.Set(DiffCompare, func(call otto.FunctionCall) otto.Value { 166 - src := call.Argument(0).String() 167 - dest := call.Argument(1).String() 168 - output := call.Argument(2).String() 169 - execution.DiffCompare(src, dest, output, options) 170 - return otto.Value{} 171 - }) 165 + vm.Set(DiffCompare, func(call otto.FunctionCall) otto.Value { 166 + src := call.Argument(0).String() 167 + dest := call.Argument(1).String() 168 + output := call.Argument(2).String() 169 + execution.DiffCompare(src, dest, output, options) 170 + return otto.Value{} 171 + }) 172 172 173 - vm.Set(GitDiff, func(call otto.FunctionCall) otto.Value { 174 - args := call.ArgumentList 175 - src := args[0].String() 176 - output := call.Argument(1).String() 177 - history := "1" 178 - if len(args) < 2 { 179 - history = call.Argument(2).String() 180 - } 181 - execution.GitDiff(src, output, history, options) 182 - return otto.Value{} 183 - }) 184 - vm.Set(LoopGitDiff, func(call otto.FunctionCall) otto.Value { 185 - args := call.ArgumentList 186 - src := args[0].String() 187 - output := call.Argument(1).String() 188 - execution.LoopGitDiff(src, output, options) 189 - return otto.Value{} 190 - }) 173 + vm.Set(GitDiff, func(call otto.FunctionCall) otto.Value { 174 + args := call.ArgumentList 175 + src := args[0].String() 176 + output := call.Argument(1).String() 177 + history := "1" 178 + if len(args) < 2 { 179 + history = call.Argument(2).String() 180 + } 181 + execution.GitDiff(src, output, history, options) 182 + return otto.Value{} 183 + }) 184 + vm.Set(LoopGitDiff, func(call otto.FunctionCall) otto.Value { 185 + args := call.ArgumentList 186 + src := args[0].String() 187 + output := call.Argument(1).String() 188 + execution.LoopGitDiff(src, output, options) 189 + return otto.Value{} 190 + }) 191 191 192 - vm.Set(GetFileFromCDN, func(call otto.FunctionCall) otto.Value { 193 - args := call.ArgumentList 194 - src := args[0].String() 195 - output := args[1].String() 196 - execution.GetFileFromCDN(options, src, output) 197 - return otto.Value{} 198 - }) 192 + vm.Set(GetFileFromCDN, func(call otto.FunctionCall) otto.Value { 193 + args := call.ArgumentList 194 + src := args[0].String() 195 + output := args[1].String() 196 + execution.GetFileFromCDN(options, src, output) 197 + return otto.Value{} 198 + }) 199 199 200 - vm.Set(GetWSFromCDN, func(call otto.FunctionCall) otto.Value { 201 - args := call.ArgumentList 202 - src := args[0].String() 203 - output := args[1].String() 204 - execution.GetWSFromCDN(options, src, output) 205 - return otto.Value{} 206 - }) 200 + vm.Set(GetWSFromCDN, func(call otto.FunctionCall) otto.Value { 201 + args := call.ArgumentList 202 + src := args[0].String() 203 + output := args[1].String() 204 + execution.GetWSFromCDN(options, src, output) 205 + return otto.Value{} 206 + }) 207 207 208 - vm.Set(DownloadFile, func(call otto.FunctionCall) otto.Value { 209 - args := call.ArgumentList 210 - src := args[0].String() 211 - output := args[1].String() 212 - execution.DownloadFile(options, src, output) 213 - return otto.Value{} 214 - }) 215 - /* --- Gitlab API --- */ 208 + vm.Set(DownloadFile, func(call otto.FunctionCall) otto.Value { 209 + args := call.ArgumentList 210 + src := args[0].String() 211 + output := args[1].String() 212 + execution.DownloadFile(options, src, output) 213 + return otto.Value{} 214 + }) 215 + /* --- Gitlab API --- */ 216 216 217 - // CreateRepo("repo-name") 218 - // CreateRepo("repo-name", "tags") 219 - vm.Set(CreateRepo, func(call otto.FunctionCall) otto.Value { 220 - args := call.ArgumentList 221 - repoName := args[0].String() 222 - tags := "" 223 - if len(args) > 1 { 224 - tags = args[1].String() 225 - } 226 - execution.CreateGitlabRepo(repoName, tags, options) 227 - return otto.Value{} 228 - }) 217 + // CreateRepo("repo-name") 218 + // CreateRepo("repo-name", "tags") 219 + vm.Set(CreateRepo, func(call otto.FunctionCall) otto.Value { 220 + args := call.ArgumentList 221 + repoName := args[0].String() 222 + tags := "" 223 + if len(args) > 1 { 224 + tags = args[1].String() 225 + } 226 + execution.CreateGitlabRepo(repoName, tags, options) 227 + return otto.Value{} 228 + }) 229 229 230 - vm.Set(DeleteRepo, func(call otto.FunctionCall) otto.Value { 231 - args := call.ArgumentList 232 - repoName := args[0].String() 233 - execution.DeleteRepo(repoName, 0, options) 234 - return otto.Value{} 235 - }) 236 - vm.Set(DeleteRepoByPid, func(call otto.FunctionCall) otto.Value { 237 - args := call.ArgumentList 238 - pid, err := args[0].ToInteger() 239 - if err != nil { 240 - return otto.Value{} 241 - } 242 - execution.DeleteRepo("", int(pid), options) 243 - return otto.Value{} 244 - }) 245 - vm.Set(ListProjects, func(call otto.FunctionCall) otto.Value { 246 - args := call.ArgumentList 247 - if len(args) > 0 { 248 - uid, err := args[0].ToInteger() 249 - if err == nil { 250 - execution.ListProjects(int(uid), options) 251 - } 252 - return otto.Value{} 253 - } 254 - execution.ListProjects(0, options) 255 - return otto.Value{} 256 - }) 230 + vm.Set(DeleteRepo, func(call otto.FunctionCall) otto.Value { 231 + args := call.ArgumentList 232 + repoName := args[0].String() 233 + execution.DeleteRepo(repoName, 0, options) 234 + return otto.Value{} 235 + }) 236 + vm.Set(DeleteRepoByPid, func(call otto.FunctionCall) otto.Value { 237 + args := call.ArgumentList 238 + pid, err := args[0].ToInteger() 239 + if err != nil { 240 + return otto.Value{} 241 + } 242 + execution.DeleteRepo("", int(pid), options) 243 + return otto.Value{} 244 + }) 245 + vm.Set(ListProjects, func(call otto.FunctionCall) otto.Value { 246 + args := call.ArgumentList 247 + if len(args) > 0 { 248 + uid, err := args[0].ToInteger() 249 + if err == nil { 250 + execution.ListProjects(int(uid), options) 251 + } 252 + return otto.Value{} 253 + } 254 + execution.ListProjects(0, options) 255 + return otto.Value{} 256 + }) 257 257 258 - return output 258 + return output 259 259 } 260 260 -