Projects STRLCPY Osmedeus Commits dc3f23af
🤬
  • Adding new queue command to scan the input from the queue

  • Loading...
  • j3ssie committed 2 years ago
    dc3f23af
    1 parent ae0c1fbf
Showing first 22 files as there are too many
  • ■ ■ ■ ■ ■ ■
    README.md
    skipped 17 lines
    18 18   
    19 19  ## 🔥 What is Osmedeus?
    20 20   
    21  -Osmedeus is a Workflow Engine for Offensive Security. It was designed to build a foundation with the capability and flexibility that allows you to build your own reconnaissance system and run it on a large number of targets.
     21 +Osmedeus is a Workflow Engine for Offensive Security. It was designed to build a foundation with the capability and
     22 +flexibility that allows you to build your own reconnaissance system and run it on a large number of targets.
    22 23   
    23 24  ## 📖 Documentation & FAQ
    24 25   
    25  -You can check out the documentation at [**docs.osmedeus.org**](https://docs.osmedeus.org) and the Frequently Asked Questions at [**here**](https://docs.osmedeus.org/faq) for more information.
    26  - 
     26 +You can check out the documentation at [**docs.osmedeus.org**](https://docs.osmedeus.org) and the Frequently Asked
     27 +Questions at [**here**](https://docs.osmedeus.org/faq) for more information.
    27 28   
    28 29  ## 📦 Installation
    29 30   
    skipped 14 lines
    44 45  Check out [**this page**](https://docs.osmedeus.org/installation/) for more the install on other platforms
    45 46   
    46 47  ## 🚀 Key Features of Osmedeus
     48 + 
    47 49  - [x] Significantly speed up your recon process
    48 50  - [x] Organize your scan results
    49 51  - [x] Efficiently to customize and optimize your recon process
    skipped 44 lines
    94 96   osmedeus utils cron --for --cmd 'osmedeus scan -t example.com'
    95 97  ```
    96 98   
    97  -Check out [**this page**](https://docs.osmedeus.org/installation/usage/) for full usage and the [**Practical Usage**](https://docs.osmedeus.org/installation/practical-usage/) to see how to use Osmedeus in a practical way.
    98  - 
     99 +Check out [**this page**](https://docs.osmedeus.org/installation/usage/) for full usage and the [**Practical
     100 +Usage**](https://docs.osmedeus.org/installation/practical-usage/) to see how to use Osmedeus in a practical way.
    99 101   
    100 102  ## 💬 Community & Discussion
    101 103   
    skipped 14 lines
  • ■ ■ ■ ■ ■ ■
    cmd/cloud.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/fatih/color"
    6  - "github.com/j3ssie/osmedeus/distribute"
    7  - "io"
    8  - "os"
    9  - "path"
    10  - "strings"
    11  - 
    12  - "github.com/j3ssie/osmedeus/core"
    13  - "github.com/j3ssie/osmedeus/libs"
    14  - "github.com/j3ssie/osmedeus/utils"
    15  - "github.com/spf13/cobra"
     4 + "fmt"
     5 + "github.com/fatih/color"
     6 + "github.com/j3ssie/osmedeus/core"
     7 + "github.com/j3ssie/osmedeus/distribute"
     8 + "github.com/j3ssie/osmedeus/libs"
     9 + "github.com/j3ssie/osmedeus/utils"
     10 + "github.com/spf13/cobra"
     11 + "golang.org/x/text/cases"
     12 + "golang.org/x/text/language"
     13 + "io"
     14 + "os"
     15 + "path"
    16 16  )
    17 17   
    18 18  func init() {
    19  - var cloudCmd = &cobra.Command{
    20  - Use: "cloud",
    21  - Short: "Run scan in Distributed Cloud mode",
    22  - Long: core.Banner(),
    23  - RunE: runCloud,
    24  - }
     19 + var cloudCmd = &cobra.Command{
     20 + Use: "cloud",
     21 + Short: "Run scan in Distributed Cloud mode",
     22 + Long: core.Banner(),
     23 + RunE: runCloud,
     24 + }
    25 25   
    26  - // core options
    27  - cloudCmd.Flags().StringVarP(&options.Cloud.Module, "module", "m", "", "module name for running")
    28  - cloudCmd.Flags().StringVarP(&options.Cloud.Flow, "flow", "f", "general", "Flow name for running (default: general)")
    29  - cloudCmd.Flags().StringVarP(&options.Cloud.Workspace, "workspace", "w", "", "Name of workspace (default is same as target)")
    30  - cloudCmd.Flags().StringSliceVarP(&options.Cloud.Params, "params", "p", []string{}, "Custom params -p='foo=bar' (Multiple -p flags are accepted)")
     26 + // core options
     27 + cloudCmd.Flags().StringVarP(&options.Cloud.Module, "module", "m", "", "module name for running")
     28 + cloudCmd.Flags().StringVarP(&options.Cloud.Flow, "flow", "f", "general", "Flow name for running (default: general)")
     29 + cloudCmd.Flags().StringVarP(&options.Cloud.Workspace, "workspace", "w", "", "Name of workspace (default is same as target)")
     30 + cloudCmd.Flags().StringSliceVarP(&options.Cloud.Params, "params", "p", []string{}, "Custom params -p='foo=bar' (Multiple -p flags are accepted)")
    31 31   
    32  - // chunk inputs
    33  - cloudCmd.Flags().BoolVar(&options.Cloud.EnablePrivateIP, "privateIP", false, "Enable Private IP")
    34  - cloudCmd.Flags().BoolVar(&options.Cloud.TargetAsFile, "as-file", false, "Run target as file (use -T targets.txt file instead of -t targets.txt at cloud instance)")
    35  - cloudCmd.Flags().StringVar(&options.Cloud.LocalSyncFolder, "rfolder", fmt.Sprintf("/root/.%s/workspaces/", libs.BINARY), "Remote Folder to sync back to local")
     32 + // chunk inputs
     33 + cloudCmd.Flags().BoolVar(&options.Cloud.EnablePrivateIP, "privateIP", false, "Enable Private IP")
     34 + cloudCmd.Flags().BoolVar(&options.Cloud.TargetAsFile, "as-file", false, "Run target as file (use -T targets.txt file instead of -t targets.txt at cloud instance)")
     35 + cloudCmd.Flags().StringVar(&options.Cloud.LocalSyncFolder, "rfolder", fmt.Sprintf("/root/.%s/workspaces/", libs.BINARY), "Remote Folder to sync back to local")
    36 36   
    37  - // commands on cloud
    38  - cloudCmd.Flags().IntVar(&options.Cloud.Threads, "threads", 1, "Concurrency level on remote cloud")
    39  - cloudCmd.Flags().StringVar(&options.Cloud.Extra, "extra", "", "append raw command after the command builder")
    40  - cloudCmd.Flags().StringVar(&options.Cloud.RawCommand, "cmd", "", "specific raw command and override everything (eg: --cmd 'curl {{.Target}}')")
    41  - cloudCmd.Flags().StringVar(&options.Cloud.CloudWait, "wait", "30m", "time to wait before next queue check")
    42  - cloudCmd.Flags().StringVar(&options.Cloud.ClearTime, "clear", "10m", "time to wait before next clear check")
    43  - cloudCmd.Flags().StringVar(&options.Cloud.TempTarget, "tempTargets", "/tmp/osm-tmp-inputs/", "Temp Folder to store targets file")
     37 + // commands on cloud
     38 + cloudCmd.Flags().IntVar(&options.Cloud.Threads, "threads", 1, "Concurrency level on remote cloud")
     39 + cloudCmd.Flags().StringVar(&options.Cloud.Extra, "extra", "", "append raw command after the command builder")
     40 + cloudCmd.Flags().StringVar(&options.Cloud.RawCommand, "cmd", "", "specific raw command and override everything (eg: --cmd 'curl {{.Target}}')")
     41 + cloudCmd.Flags().StringVar(&options.Cloud.CloudWait, "wait", "30m", "time to wait before next queue check")
     42 + cloudCmd.Flags().StringVar(&options.Cloud.ClearTime, "clear", "10m", "time to wait before next clear check")
     43 + cloudCmd.Flags().StringVar(&options.Cloud.TempTarget, "tempTargets", "/tmp/osm-tmp-inputs/", "Temp Folder to store targets file")
    44 44   
    45  - // mics option
    46  - cloudCmd.Flags().BoolVar(&options.Cloud.EnableSyncWorkflow, "sync-workflow", false, "Enable Sync Workflow folder to remote machine first before starting the scan")
    47  - cloudCmd.Flags().BoolVarP(&options.Cloud.CopyWorkspaceToGit, "gws", "G", false, "Enable Copy Workspace to Git (run -f sync after done)")
    48  - cloudCmd.Flags().BoolVarP(&options.Cloud.DisableLocalSync, "no-lsync", "z", false, "Disable sync back data to local machine")
    49  - cloudCmd.Flags().BoolVar(&options.Cloud.BackgroundRun, "bg", false, "Send command to instance without checking if process is done or not")
    50  - cloudCmd.Flags().BoolVar(&options.Cloud.EnableTerraform, "tf", false, "Use terraform to create cloud instance")
    51  - cloudCmd.Flags().BoolVar(&options.Cloud.NoDelete, "no-del", false, "Don't delete instance after done")
    52  - cloudCmd.Flags().BoolVar(&options.Cloud.IgnoreProcess, "no-ps", false, "Disable checking process on remote machine")
    53  - cloudCmd.Flags().IntVar(&options.Cloud.Retry, "retry", 10, "Number of retry when command is error")
    54  - cloudCmd.SetHelpFunc(CloudHelp)
    55  - RootCmd.AddCommand(cloudCmd)
     45 + // mics option
     46 + cloudCmd.Flags().BoolVar(&options.Cloud.EnableSyncWorkflow, "sync-workflow", false, "Enable Sync Workflow folder to remote machine first before starting the scan")
     47 + cloudCmd.Flags().BoolVarP(&options.Cloud.CopyWorkspaceToGit, "gws", "G", false, "Enable Copy Workspace to Git (run -f sync after done)")
     48 + cloudCmd.Flags().BoolVarP(&options.Cloud.DisableLocalSync, "no-lsync", "z", false, "Disable sync back data to local machine")
     49 + cloudCmd.Flags().BoolVar(&options.Cloud.BackgroundRun, "bg", false, "Send command to instance without checking if process is done or not")
     50 + cloudCmd.Flags().BoolVar(&options.Cloud.EnableTerraform, "tf", false, "Use terraform to create cloud instance")
     51 + cloudCmd.Flags().BoolVar(&options.Cloud.NoDelete, "no-del", false, "Don't delete instance after done")
     52 + cloudCmd.Flags().BoolVar(&options.Cloud.IgnoreProcess, "no-ps", false, "Disable checking process on remote machine")
     53 + cloudCmd.Flags().IntVar(&options.Cloud.Retry, "retry", 10, "Number of retry when command is error")
     54 + cloudCmd.SetHelpFunc(CloudHelp)
     55 + RootCmd.AddCommand(cloudCmd)
    56 56   
    57 57  }
    58 58   
    59 59  func runCloud(cmd *cobra.Command, _ []string) error {
    60  - DBInit()
    61  - // parse some argument
    62  - threads, _ := cmd.Flags().GetInt("thread")
    63  - if threads > 1 || options.Cloud.Threads <= 1 {
    64  - options.Cloud.Threads = threads
    65  - }
    66  - utils.GoodF("%v %v by %v", strings.Title(libs.BINARY), libs.VERSION, libs.AUTHOR)
    67  - utils.GoodF("Store log file to: %v", options.LogFile)
     60 + DBInit()
     61 + utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
     62 + utils.InforF("Storing the log file to: %v", color.CyanString(options.LogFile))
    68 63   
    69  - // get pre run commands
    70  - getPreRun(&options)
     64 + // parse some arguments
     65 + threads, _ := cmd.Flags().GetInt("thread")
     66 + if threads > 1 || options.Cloud.Threads <= 1 {
     67 + options.Cloud.Threads = threads
     68 + }
     69 + 
     70 + // get pre run commands
     71 + getPreRun(&options)
    71 72   
    72  - // change targets list if chunk mode enable
    73  - if options.Cloud.EnableChunk {
    74  - utils.InforF("Running cloud scan in chunk mode")
    75  - for _, target := range options.Scan.Inputs {
    76  - chunkTargets := HandleChunksInputs(target)
    77  - if len(chunkTargets) == 0 {
    78  - continue
    79  - }
     73 + // change targets list if chunk mode enable
     74 + if options.Cloud.EnableChunk {
     75 + utils.InforF("Running cloud scan in chunk mode")
     76 + for _, target := range options.Scan.Inputs {
     77 + chunkTargets := HandleChunksInputs(target)
     78 + if len(chunkTargets) == 0 {
     79 + continue
     80 + }
    80 81   
    81  - distribute.InitCloud(options, chunkTargets)
    82  - // remove chunk inputs
    83  - utils.DebugF("Remove chunk inputs file")
    84  - for _, ctarget := range chunkTargets {
    85  - os.RemoveAll(ctarget)
    86  - }
    87  - }
    88  - return nil
    89  - }
     82 + distribute.InitCloud(options, chunkTargets)
     83 + // remove chunk inputs
     84 + utils.DebugF("Remove chunk inputs file")
     85 + for _, ctarget := range chunkTargets {
     86 + os.RemoveAll(ctarget)
     87 + }
     88 + }
     89 + return nil
     90 + }
    90 91   
    91  - // @NOTE: pro-tips
    92  - if options.Concurrency > 1 && len(options.Scan.Inputs) == 1 {
    93  - if !utils.FileExists(options.Scan.Inputs[0]) {
    94  - utils.WarnF("You're using %v in cloud scan but your input %v is just a single domain", color.HiMagentaString(`'-c %v'`, options.Concurrency), color.HiMagentaString(`'-t %v'`, options.Scan.Inputs[0]))
    95  - utils.WarnF("Consider running: osmedeus cloud -c 5 -T list-of-targets.txt")
    96  - }
    97  - }
     92 + // @NOTE: pro-tips
     93 + if options.Concurrency > 1 && len(options.Scan.Inputs) == 1 {
     94 + if !utils.FileExists(options.Scan.Inputs[0]) {
     95 + utils.WarnF("You're using %v in cloud scan but your input %v is just a single domain", color.HiMagentaString(`'-c %v'`, options.Concurrency), color.HiMagentaString(`'-t %v'`, options.Scan.Inputs[0]))
     96 + utils.WarnF("Consider running: osmedeus cloud -c 5 -T list-of-targets.txt")
     97 + }
     98 + }
    98 99   
    99  - distribute.InitCloud(options, options.Scan.Inputs)
    100  - return nil
     100 + distribute.InitCloud(options, options.Scan.Inputs)
     101 + return nil
    101 102  }
    102 103   
    103 104  // HandleChunksInputs split the inputs to multiple file first
    104 105  func HandleChunksInputs(target string) []string {
    105  - var chunkTargets []string
    106  - utils.MakeDir(options.Cloud.ChunkInputs)
     106 + var chunkTargets []string
     107 + utils.MakeDir(options.Cloud.ChunkInputs)
    107 108   
    108  - if !utils.FileExists(target) {
    109  - utils.ErrorF("error to split input file: %v", target)
    110  - return chunkTargets
    111  - }
     109 + if !utils.FileExists(target) {
     110 + utils.ErrorF("error to split input file: %v", target)
     111 + return chunkTargets
     112 + }
    112 113   
    113  - if options.Cloud.NumberOfParts == 0 {
    114  - options.Cloud.NumberOfParts = options.Concurrency
    115  - }
     114 + if options.Cloud.NumberOfParts == 0 {
     115 + options.Cloud.NumberOfParts = options.Concurrency
     116 + }
    116 117   
    117  - utils.DebugF("Splitting %v to %v part", target, options.Cloud.NumberOfParts)
    118  - rawChunks, err := utils.SplitLineChunks(target, options.Cloud.NumberOfParts)
    119  - if err != nil || len(rawChunks) == 0 {
    120  - utils.ErrorF("error to split input file: %v", target)
    121  - return chunkTargets
    122  - }
    123  - fp, err := os.Open(target)
    124  - if err != nil {
    125  - utils.ErrorF("error to open input file: %v", target)
    126  - return chunkTargets
    127  - }
    128  - for index, offset := range rawChunks {
    129  - targetName := fmt.Sprintf("%s-chunk-%v", utils.CleanPath(target), index)
    130  - targetName = path.Join(options.Cloud.ChunkInputs, targetName)
     118 + utils.DebugF("Splitting %v to %v part", target, options.Cloud.NumberOfParts)
     119 + rawChunks, err := utils.SplitLineChunks(target, options.Cloud.NumberOfParts)
     120 + if err != nil || len(rawChunks) == 0 {
     121 + utils.ErrorF("error to split input file: %v", target)
     122 + return chunkTargets
     123 + }
     124 + fp, err := os.Open(target)
     125 + if err != nil {
     126 + utils.ErrorF("error to open input file: %v", target)
     127 + return chunkTargets
     128 + }
     129 + for index, offset := range rawChunks {
     130 + targetName := fmt.Sprintf("%s-chunk-%v", utils.CleanPath(target), index)
     131 + targetName = path.Join(options.Cloud.ChunkInputs, targetName)
    131 132   
    132  - sectionReader := io.NewSectionReader(fp, offset.Start, offset.Stop-offset.Start)
    133  - targetFile, err := os.OpenFile(targetName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
    134  - if err != nil {
    135  - utils.ErrorF("error when create chunk file: %v", target)
    136  - continue
    137  - }
     133 + sectionReader := io.NewSectionReader(fp, offset.Start, offset.Stop-offset.Start)
     134 + targetFile, err := os.OpenFile(targetName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
     135 + if err != nil {
     136 + utils.ErrorF("error when create chunk file: %v", target)
     137 + continue
     138 + }
    138 139   
    139  - _, err = io.Copy(targetFile, sectionReader)
    140  - if err != nil {
    141  - utils.ErrorF("error to read chunk file: %s", err)
    142  - continue
    143  - }
    144  - targetFile.Close()
    145  - chunkTargets = append(chunkTargets, targetName)
    146  - }
     140 + _, err = io.Copy(targetFile, sectionReader)
     141 + if err != nil {
     142 + utils.ErrorF("error to read chunk file: %s", err)
     143 + continue
     144 + }
     145 + targetFile.Close()
     146 + chunkTargets = append(chunkTargets, targetName)
     147 + }
    147 148   
    148  - return chunkTargets
     149 + return chunkTargets
    149 150  }
    150 151   
    151 152  func getPreRun(options *libs.Options) {
    152  - if options.Cloud.Module != "" {
    153  - module := core.DirectSelectModule(*options, options.Cloud.Module)
    154  - if module == "" {
    155  - utils.ErrorF("Error to select module: %s", options.Cloud.Module)
    156  - return
    157  - }
    158  - parsedModule, err := core.ParseModules(module)
    159  - if err == nil {
    160  - options.Cloud.RemotePreRun = parsedModule.RemotePreRun
    161  - options.Cloud.LocalPostRun = parsedModule.LocalPostRun
    162  - options.Cloud.LocalPreRun = parsedModule.LocalPreRun
    163  - options.Cloud.LocalSteps = parsedModule.LocalSteps
    164  - }
    165  - return
    166  - }
     153 + if options.Cloud.Module != "" {
     154 + module := core.DirectSelectModule(*options, options.Cloud.Module)
     155 + if module == "" {
     156 + utils.ErrorF("Error to select module: %s", options.Cloud.Module)
     157 + return
     158 + }
     159 + parsedModule, err := core.ParseModules(module)
     160 + if err == nil {
     161 + options.Cloud.RemotePreRun = parsedModule.RemotePreRun
     162 + options.Cloud.LocalPostRun = parsedModule.LocalPostRun
     163 + options.Cloud.LocalPreRun = parsedModule.LocalPreRun
     164 + options.Cloud.LocalSteps = parsedModule.LocalSteps
     165 + }
     166 + return
     167 + }
    167 168   
    168  - if options.Cloud.Flow != "" {
    169  - flows := core.SelectFlow(options.Cloud.Flow, *options)
    170  - for _, flow := range flows {
    171  - parseFlow, err := core.ParseFlow(flow)
    172  - if err == nil {
    173  - options.Cloud.RemotePreRun = parseFlow.RemotePreRun
    174  - options.Cloud.LocalPostRun = parseFlow.LocalPostRun
    175  - options.Cloud.LocalPreRun = parseFlow.LocalPreRun
    176  - }
    177  - }
    178  - }
     169 + if options.Cloud.Flow != "" {
     170 + flows := core.SelectFlow(options.Cloud.Flow, *options)
     171 + for _, flow := range flows {
     172 + parseFlow, err := core.ParseFlow(flow)
     173 + if err == nil {
     174 + options.Cloud.RemotePreRun = parseFlow.RemotePreRun
     175 + options.Cloud.LocalPostRun = parseFlow.LocalPostRun
     176 + options.Cloud.LocalPreRun = parseFlow.LocalPreRun
     177 + }
     178 + }
     179 + }
    179 180  }
    180 181   
  • ■ ■ ■ ■ ■ ■
    cmd/config.go
    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   
  • ■ ■ ■ ■ ■ ■
    cmd/exec.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "github.com/j3ssie/osmedeus/core"
    5  - "github.com/j3ssie/osmedeus/utils"
    6  - "github.com/spf13/cobra"
    7  - "os"
     4 + "github.com/j3ssie/osmedeus/core"
     5 + "github.com/j3ssie/osmedeus/utils"
     6 + "github.com/spf13/cobra"
     7 + "os"
    8 8  )
    9 9   
    10 10  func init() {
    11  - var execCmd = &cobra.Command{
    12  - Use: "exec",
    13  - Short: "Execute inline osmedeus scripts",
    14  - Long: core.Banner(),
    15  - RunE: runExec,
    16  - }
     11 + var execCmd = &cobra.Command{
     12 + Use: "exec",
     13 + Short: "Execute inline osmedeus scripts",
     14 + Long: core.Banner(),
     15 + RunE: runExec,
     16 + }
    17 17   
    18  - execCmd.Flags().String("script", "", "Scripts to run (Multiple -s flags are accepted)")
    19  - execCmd.Flags().StringP("scriptFile", "S", "", "File contain list of scripts")
    20  - RootCmd.AddCommand(execCmd)
     18 + execCmd.Flags().String("script", "", "Scripts to run (Multiple -s flags are accepted)")
     19 + execCmd.Flags().StringP("scriptFile", "S", "", "File contain list of scripts")
     20 + RootCmd.AddCommand(execCmd)
    21 21  }
    22 22   
    23 23  func runExec(cmd *cobra.Command, _ []string) error {
    24  - script, _ := cmd.Flags().GetString("script")
    25  - scriptFile, _ := cmd.Flags().GetString("scriptFile")
     24 + script, _ := cmd.Flags().GetString("script")
     25 + scriptFile, _ := cmd.Flags().GetString("scriptFile")
    26 26   
    27  - var scripts []string
    28  - if script != "" {
    29  - scripts = append(scripts, script)
    30  - }
    31  - if scriptFile != "" {
    32  - moreScripts := utils.ReadingFileUnique(scriptFile)
    33  - if len(moreScripts) > 0 {
    34  - scripts = append(scripts, moreScripts...)
    35  - }
    36  - }
     27 + var scripts []string
     28 + if script != "" {
     29 + scripts = append(scripts, script)
     30 + }
     31 + if scriptFile != "" {
     32 + moreScripts := utils.ReadingFileUnique(scriptFile)
     33 + if len(moreScripts) > 0 {
     34 + scripts = append(scripts, moreScripts...)
     35 + }
     36 + }
    37 37   
    38  - if len(scripts) == 0 {
    39  - utils.ErrorF("No scripts provided")
    40  - os.Exit(0)
    41  - }
    42  - runner, _ := core.InitRunner("example.com", options)
     38 + if len(scripts) == 0 {
     39 + utils.ErrorF("No scripts provided")
     40 + os.Exit(0)
     41 + }
     42 + runner, _ := core.InitRunner("example.com", options)
    43 43   
    44  - for _, t := range options.Scan.Inputs {
    45  - // start to run scripts
    46  - options.Scan.ROptions = core.ParseInput(t, options)
    47  - for _, rscript := range scripts {
    48  - script = core.ResolveData(rscript, options.Scan.ROptions)
    49  - utils.InforF("Script: %v", script)
    50  - runner.RunScript(script)
    51  - }
    52  - }
     44 + for _, t := range options.Scan.Inputs {
     45 + // start to run scripts
     46 + options.Scan.ROptions = core.ParseInput(t, options)
     47 + for _, rscript := range scripts {
     48 + script = core.ResolveData(rscript, options.Scan.ROptions)
     49 + utils.InforF("Script: %v", script)
     50 + runner.RunScript(script)
     51 + }
     52 + }
    53 53   
    54  - return nil
     54 + return nil
    55 55  }
    56 56   
  • ■ ■ ■ ■ ■ ■
    cmd/health.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/fatih/color"
    6  - "github.com/j3ssie/osmedeus/core"
    7  - "github.com/j3ssie/osmedeus/execution"
    8  - "github.com/j3ssie/osmedeus/libs"
    9  - "github.com/j3ssie/osmedeus/utils"
    10  - "github.com/olekukonko/tablewriter"
    11  - "github.com/spf13/cobra"
    12  - "os"
    13  - "path"
    14  - "sort"
     4 + "fmt"
     5 + "github.com/fatih/color"
     6 + "github.com/j3ssie/osmedeus/core"
     7 + "github.com/j3ssie/osmedeus/execution"
     8 + "github.com/j3ssie/osmedeus/libs"
     9 + "github.com/j3ssie/osmedeus/utils"
     10 + "github.com/olekukonko/tablewriter"
     11 + "github.com/spf13/cobra"
     12 + "os"
     13 + "path"
     14 + "sort"
    15 15  )
    16 16   
    17 17  func init() {
    18  - var execCmd = &cobra.Command{
    19  - Use: "health",
    20  - Aliases: []string{"hea", "heal", "health", "healht"},
    21  - Short: "Run diagnostics to check configurations",
    22  - Long: core.Banner(),
    23  - RunE: runHealth,
    24  - }
    25  - RootCmd.AddCommand(execCmd)
     18 + var healthCmd = &cobra.Command{
     19 + Use: "health",
     20 + Aliases: []string{"hea", "heal", "health", "healht"},
     21 + Short: "Run diagnostics to check configurations",
     22 + Long: core.Banner(),
     23 + RunE: runHealth,
     24 + }
     25 + RootCmd.AddCommand(healthCmd)
    26 26  }
    27 27   
    28 28  func runHealth(_ *cobra.Command, args []string) error {
    29  - if options.PremiumPackage {
    30  - fmt.Printf("�� Osmedeus %s: Run diagnostics to check if everything okay\n", libs.VERSION)
    31  - } else {
    32  - fmt.Printf("�� Osmedeus %s: Run diagnostics to check if everything okay\n", libs.VERSION)
    33  - }
     29 + if options.PremiumPackage {
     30 + fmt.Printf("�� Osmedeus %s: Run diagnostics to check if everything okay\n", libs.VERSION)
     31 + } else {
     32 + fmt.Printf("�� Osmedeus %s: Run diagnostics to check if everything okay\n", libs.VERSION)
     33 + }
    34 34   
    35  - sort.Strings(args)
    36  - var err error
    37  - for _, arg := range args {
    38  - switch arg {
    39  - case "store", "git", "storages", "stora":
    40  - err = checkStorages()
    41  - case "cloud", "dist", "provider":
    42  - err = checkCloud()
    43  - case "all", "a", "full":
    44  - err = checkStorages()
    45  - if err != nil {
    46  - fmt.Println(color.YellowString("⚠️️ There is might be something wrong with your storages: %v\n", err))
    47  - }
    48  - err = checkCloud()
    49  - if err != nil {
    50  - fmt.Println(color.YellowString("%s If you install osmedeus on a single machine then it's okay to ignore the cloud setup\n", "[!] Cloud config setup incorrectly."))
    51  - }
    52  - err = generalCheck()
    53  - if err != nil {
    54  - fmt.Printf("‼️ There is might be something wrong with your setup: %v\n", err)
    55  - return nil
    56  - }
    57  - break
    58  - }
    59  - if err != nil {
    60  - fmt.Println(color.YellowString("⚠️️ There is might be something wrong with your cloud or storages setup: %v\n", err))
    61  - return nil
    62  - }
    63  - }
    64  - if len(args) > 0 {
    65  - return nil
    66  - }
     35 + sort.Strings(args)
     36 + var err error
     37 + for _, arg := range args {
     38 + switch arg {
     39 + case "store", "git", "storages", "stora":
     40 + err = checkStorages()
     41 + case "cloud", "dist", "provider":
     42 + err = checkCloud()
     43 + case "all", "a", "full":
     44 + err = checkStorages()
     45 + if err != nil {
     46 + fmt.Println(color.YellowString("⚠️️ There is might be something wrong with your storages: %v\n", err))
     47 + }
     48 + err = checkCloud()
     49 + if err != nil {
     50 + fmt.Println(color.YellowString("%s If you install osmedeus on a single machine then it's okay to ignore the cloud setup\n", "[!] Cloud config setup incorrectly."))
     51 + }
     52 + err = generalCheck()
     53 + if err != nil {
     54 + fmt.Printf("‼️ There is might be something wrong with your setup: %v\n", color.HiRedString("%v", err))
     55 + return nil
     56 + }
     57 + break
     58 + }
     59 + if err != nil {
     60 + fmt.Println(color.YellowString("⚠️️ There is might be something wrong with your cloud or storages setup: %v\n", err))
     61 + return nil
     62 + }
     63 + }
     64 + if len(args) > 0 {
     65 + return nil
     66 + }
    67 67   
    68  - err = generalCheck()
    69  - if err != nil {
    70  - fmt.Printf("‼️ There is might be something wrong with your setup: %v\n", err)
    71  - return nil
    72  - }
     68 + err = generalCheck()
     69 + if err != nil {
     70 + fmt.Printf("‼️ There is might be something wrong with your setup: %v\n", err)
     71 + return nil
     72 + }
    73 73   
    74  - err = listFlows()
    75  - if err != nil {
    76  - fmt.Printf("‼️ There is might be something wrong with your setup: %v\n", err)
    77  - return nil
    78  - }
    79  - fmt.Printf(color.GreenString("\n�� It’s all good. Happy Hacking ��\n"))
    80  - return nil
     74 + err = listFlows()
     75 + if err != nil {
     76 + fmt.Printf("‼️ There is might be something wrong with your setup: %v\n", err)
     77 + return nil
     78 + }
     79 + fmt.Printf(color.GreenString("\n�� It’s all good. Happy Hacking ��\n"))
     80 + return nil
    81 81  }
    82 82   
    83 83  func checkCloud() error {
    84  - // check packer program
    85  - if _, err := utils.RunCommandWithErr("packer -h"); err != nil {
    86  - if _, err := utils.RunCommandWithErr(fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "packer"))); err != nil {
    87  - color.Red("[-] Packer program setup incorrectly")
    88  - return fmt.Errorf("error checking core programs: %v", fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "packer")))
    89  - }
    90  - }
     84 + // check packer program
     85 + if _, err := utils.RunCommandWithErr("packer -h"); err != nil {
     86 + if _, err := utils.RunCommandWithErr(fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "packer"))); err != nil {
     87 + color.Red("[-] Packer program setup incorrectly")
     88 + return fmt.Errorf("error checking core programs: %v", fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "packer")))
     89 + }
     90 + }
    91 91   
    92  - // check config files
    93  - if !utils.FileExists(options.CloudConfigFile) {
    94  - return fmt.Errorf("distributed cloud config doesn't exist: %v", path.Join(options.Env.CloudConfigFolder, "provider.yaml"))
    95  - }
    96  - if utils.DirLength(path.Join(options.Env.CloudConfigFolder, "providers")) == 0 {
    97  - return fmt.Errorf("providers file doesn't exist: %v", path.Join(options.Env.CloudConfigFolder, "providers"))
    98  - }
     92 + // check config files
     93 + if !utils.FileExists(options.CloudConfigFile) {
     94 + return fmt.Errorf("distributed cloud config doesn't exist: %v", path.Join(options.Env.CloudConfigFolder, "provider.yaml"))
     95 + }
     96 + if utils.DirLength(path.Join(options.Env.CloudConfigFolder, "providers")) == 0 {
     97 + return fmt.Errorf("providers file doesn't exist: %v", path.Join(options.Env.CloudConfigFolder, "providers"))
     98 + }
    99 99   
    100  - // check SSH Keys
    101  - if !utils.FileExists(options.Cloud.SecretKey) {
    102  - keysDir := path.Dir(options.Cloud.SecretKey)
    103  - os.RemoveAll(keysDir)
    104  - utils.MakeDir(keysDir)
    105  - utils.DebugF("Generate SSH Key at: %v", options.Cloud.SecretKey)
    106  - if _, err := utils.RunCommandWithErr(fmt.Sprintf(`ssh-keygen -t ed25519 -f %s -q -N ''`, options.Cloud.SecretKey)); err != nil {
    107  - color.Red("[-] error generated SSH Key for cloud config at: %v", options.Cloud.SecretKey)
    108  - return fmt.Errorf("[-] error generated SSH Key for cloud config at: %v", options.Cloud.SecretKey)
    109  - }
    110  - }
    111  - if !utils.FileExists(options.Cloud.PublicKey) {
    112  - return fmt.Errorf("providers SSH Key missing: %v", options.Cloud.PublicKey)
    113  - }
     100 + // check SSH Keys
     101 + if !utils.FileExists(options.Cloud.SecretKey) {
     102 + keysDir := path.Dir(options.Cloud.SecretKey)
     103 + os.RemoveAll(keysDir)
     104 + utils.MakeDir(keysDir)
     105 + utils.DebugF("Generate SSH Key at: %v", options.Cloud.SecretKey)
     106 + if _, err := utils.RunCommandWithErr(fmt.Sprintf(`ssh-keygen -t ed25519 -f %s -q -N ''`, options.Cloud.SecretKey)); err != nil {
     107 + color.Red("[-] error generated SSH Key for cloud config at: %v", options.Cloud.SecretKey)
     108 + return fmt.Errorf("[-] error generated SSH Key for cloud config at: %v", options.Cloud.SecretKey)
     109 + }
     110 + }
     111 + if !utils.FileExists(options.Cloud.PublicKey) {
     112 + return fmt.Errorf("providers SSH Key missing: %v", options.Cloud.PublicKey)
     113 + }
    114 114   
    115  - fmt.Printf("[+] Health Check Cloud Config: %s\n", color.GreenString("✔"))
    116  - return nil
     115 + fmt.Printf("[+] Health Check Cloud Config: %s\n", color.GreenString("✔"))
     116 + return nil
    117 117  }
    118 118   
    119 119  func checkStorages() error {
    120  - utils.DebugF("Checking storages setup")
    121  - if !execution.ValidGitURL(options.Storages["summary_repo"]) {
    122  - return fmt.Errorf("invalid git summary: %v", options.Storages["summary_repo"])
    123  - }
     120 + utils.DebugF("Checking storages setup")
     121 + if !execution.ValidGitURL(options.Storages["summary_repo"]) {
     122 + return fmt.Errorf("invalid git summary: %v", options.Storages["summary_repo"])
     123 + }
    124 124   
    125  - utils.DebugF("Check if your summary directory is exist or not: %v", options.Env.StoragesFolder)
    126  - if utils.DirLength(options.Env.StoragesFolder) < 1 {
    127  - return fmt.Errorf("storages folder doesn't exist: %v", options.Env.StoragesFolder)
    128  - }
     125 + utils.DebugF("Check if your summary directory is exist or not: %v", options.Env.StoragesFolder)
     126 + if utils.DirLength(options.Env.StoragesFolder) < 1 {
     127 + return fmt.Errorf("storages folder doesn't exist: %v", options.Env.StoragesFolder)
     128 + }
    129 129   
    130  - utils.DebugF("Check the secret key for git usage: %v", options.Storages["secret_key"])
    131  - if !utils.FileExists(options.Storages["secret_key"]) {
    132  - return fmt.Errorf("secret key for git command doesn't exist: %v", options.Storages["secret_key"])
    133  - }
     130 + utils.DebugF("Check the secret key for git usage: %v", options.Storages["secret_key"])
     131 + if !utils.FileExists(options.Storages["secret_key"]) {
     132 + return fmt.Errorf("secret key for git command doesn't exist: %v", options.Storages["secret_key"])
     133 + }
    134 134   
    135  - fmt.Printf("[+] Health Check Storages Config: %s\n", color.GreenString("✔"))
    136  - return nil
     135 + fmt.Printf("[+] Health Check Storages Config: %s\n", color.GreenString("✔"))
     136 + return nil
    137 137  }
    138 138   
    139 139  func generalCheck() error {
    140  - exist := utils.FolderExists(options.Env.BaseFolder)
    141  - if !exist {
    142  - color.Red("[-] Core folder setup incorrect: %v", options.Env.BaseFolder)
    143  - return fmt.Errorf("error running diagnostics")
    144  - }
     140 + exist := utils.FolderExists(options.Env.BaseFolder)
     141 + if !exist {
     142 + color.Red("[-] Core folder setup incorrect: %v", options.Env.BaseFolder)
     143 + return fmt.Errorf("error running diagnostics")
     144 + }
    145 145   
    146  - // check core programs
    147  - var err error
    148  - _, err = utils.RunCommandWithErr("jaeles -h")
    149  - if err != nil {
    150  - color.Red("[-] Core program setup incorrectly")
    151  - return fmt.Errorf("error checking core programs: %v", "jaeles")
     146 + // check core programs
     147 + var err error
     148 + _, err = utils.RunCommandWithErr("jaeles -h")
     149 + if err != nil {
     150 + color.Red("[-] Core program setup incorrectly")
     151 + return fmt.Errorf("error checking core programs: %v", "jaeles")
    152 152   
    153  - }
    154  - _, err = utils.RunCommandWithErr("amass -h")
    155  - if err != nil {
    156  - color.Red("[-] Core program setup incorrectly")
    157  - return fmt.Errorf("error checking core programs: %v", "amass")
     153 + }
     154 + _, err = utils.RunCommandWithErr("amass -h")
     155 + if err != nil {
     156 + color.Red("[-] Core program setup incorrectly")
     157 + return fmt.Errorf("error checking core programs: %v", "amass")
    158 158   
    159  - }
    160  - _, err = utils.RunCommandWithErr(fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "httprobe")))
    161  - if err != nil {
    162  - color.Red("[-] Core program setup incorrectly")
    163  - return fmt.Errorf("error checking core programs: %v", fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "httprobe")))
    164  - }
    165  - fmt.Printf("[+] Health Check Core Programs: %s\n", color.GreenString("✔"))
     159 + }
     160 + _, err = utils.RunCommandWithErr(fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "httprobe")))
     161 + if err != nil {
     162 + color.Red("[-] Core program setup incorrectly")
     163 + return fmt.Errorf("error checking core programs: %v", fmt.Sprintf("%s -h", path.Join(options.Env.BinariesFolder, "httprobe")))
     164 + }
     165 + fmt.Printf("[+] Health Check Core Programs: %s\n", color.GreenString("✔"))
    166 166   
    167  - // Check core signatures
    168  - okVuln := false
    169  - if utils.DirLength("~/.jaeles/base-signatures/") > 0 || utils.DirLength("~/pro-signatures/") > 0 {
    170  - okVuln = true
    171  - }
     167 + // Check core signatures
     168 + okVuln := false
     169 + if utils.DirLength("~/.jaeles/base-signatures/") > 0 || utils.DirLength("~/pro-signatures/") > 0 {
     170 + okVuln = true
     171 + }
    172 172   
    173  - if utils.DirLength("~/nuclei-templates") > 0 {
    174  - okVuln = true
    175  - }
     173 + if utils.DirLength("~/nuclei-templates") > 0 {
     174 + okVuln = true
     175 + }
    176 176   
    177  - if okVuln {
    178  - fmt.Printf("[+] Health Check Vulnerability scanning config: %s\n", color.GreenString("✔"))
    179  - } else {
    180  - color.Red("vulnerability scanning config setup incorrectly")
    181  - return fmt.Errorf("vulnerability scanning config setup incorrectly")
    182  - }
     177 + if okVuln {
     178 + fmt.Printf("[+] Health Check Vulnerability scanning config: %s\n", color.GreenString("✔"))
     179 + } else {
     180 + color.Red("vulnerability scanning config setup incorrectly")
     181 + return fmt.Errorf("vulnerability scanning config setup incorrectly")
     182 + }
    183 183   
    184  - // check data folder
    185  - if utils.FolderExists(options.Env.DataFolder) {
    186  - fmt.Printf("[+] Health Check Data Config: %s\n", color.GreenString("✔"))
    187  - } else {
    188  - color.Red("[-] Data setup incorrectly: %v", options.Env.DataFolder)
    189  - return fmt.Errorf("[-] Data setup incorrectly: %v", options.Env.DataFolder)
    190  - }
    191  - return nil
     184 + // check data folder
     185 + if utils.FolderExists(options.Env.DataFolder) {
     186 + fmt.Printf("[+] Health Check Data Config: %s\n", color.GreenString("✔"))
     187 + } else {
     188 + color.Red("[-] Data setup incorrectly: %v", options.Env.DataFolder)
     189 + return fmt.Errorf("[-] Data setup incorrectly: %v", options.Env.DataFolder)
     190 + }
     191 + return nil
    192 192  }
    193 193   
    194 194  func listFlows() error {
    195  - flows := core.ListFlow(options)
    196  - if len(flows) == 0 {
    197  - color.Red("[-] Error to list workflows: %s", options.Env.WorkFlowsFolder)
    198  - return fmt.Errorf("[-] Error to list workflows: %s", options.Env.WorkFlowsFolder)
    199  - }
    200  - fmt.Printf("[+] Health Check Workflows: %s\n", color.GreenString("✔"))
     195 + flows := core.ListFlow(options)
     196 + if len(flows) == 0 {
     197 + color.Red("[-] Error to list workflows: %s", options.Env.WorkFlowsFolder)
     198 + return fmt.Errorf("[-] Error to list workflows: %s", options.Env.WorkFlowsFolder)
     199 + }
     200 + fmt.Printf("[+] Health Check Workflows: %s\n", color.GreenString("✔"))
    201 201   
    202  - var content [][]string
    203  - for _, flow := range flows {
    204  - parsedFlow, err := core.ParseFlow(flow)
    205  - if err != nil {
    206  - utils.ErrorF("Error parsing flow: %v", flow)
    207  - continue
    208  - }
    209  - row := []string{
    210  - parsedFlow.Name, parsedFlow.Desc,
    211  - }
    212  - content = append(content, row)
    213  - }
    214  - fmt.Printf("\nFound %v available workflows at: %s \n\n", color.HiGreenString("%v", len(content)), color.HiCyanString(options.Env.WorkFlowsFolder))
     202 + var content [][]string
     203 + for _, flow := range flows {
     204 + parsedFlow, err := core.ParseFlow(flow)
     205 + if err != nil {
     206 + utils.ErrorF("Error parsing flow: %v", flow)
     207 + continue
     208 + }
     209 + row := []string{
     210 + parsedFlow.Name, parsedFlow.Desc,
     211 + }
     212 + content = append(content, row)
     213 + }
     214 + fmt.Printf("\nFound %v available workflows at: %s \n\n", color.HiGreenString("%v", len(content)), color.HiCyanString(options.Env.WorkFlowsFolder))
    215 215   
    216  - table := tablewriter.NewWriter(os.Stdout)
    217  - table.SetAutoFormatHeaders(false)
    218  - table.SetHeader([]string{"Flow Name", "Description"})
    219  - table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
    220  - table.SetColWidth(120)
    221  - table.AppendBulk(content) // Add Bulk Data
    222  - table.Render()
     216 + table := tablewriter.NewWriter(os.Stdout)
     217 + table.SetAutoFormatHeaders(false)
     218 + table.SetHeader([]string{"Flow Name", "Description"})
     219 + table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
     220 + table.SetColWidth(120)
     221 + table.AppendBulk(content) // Add Bulk Data
     222 + table.Render()
    223 223   
    224  - h := "\nUsage:\n"
    225  - h += color.HiCyanString(" osmedeus scan -f [flowName] -t [target] \n")
    226  - fmt.Printf(h)
    227  - return nil
     224 + h := "\nUsage:\n"
     225 + h += color.HiCyanString(" osmedeus scan -f [flowName] -t [target] \n")
     226 + fmt.Printf(h)
     227 + return nil
    228 228  }
    229 229   
  • ■ ■ ■ ■ ■ ■
    cmd/provider.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/j3ssie/osmedeus/core"
    6  - "github.com/j3ssie/osmedeus/distribute"
    7  - "github.com/j3ssie/osmedeus/provider"
    8  - "github.com/j3ssie/osmedeus/utils"
    9  - "github.com/olekukonko/tablewriter"
    10  - "github.com/panjf2000/ants"
    11  - "github.com/spf13/cobra"
    12  - "os"
    13  - "sync"
     4 + "fmt"
     5 + "github.com/j3ssie/osmedeus/core"
     6 + "github.com/j3ssie/osmedeus/distribute"
     7 + "github.com/j3ssie/osmedeus/provider"
     8 + "github.com/j3ssie/osmedeus/utils"
     9 + "github.com/olekukonko/tablewriter"
     10 + "github.com/panjf2000/ants"
     11 + "github.com/spf13/cobra"
     12 + "os"
     13 + "sync"
    14 14  )
    15 15   
    16 16  func init() {
    17  - var providerCmd = &cobra.Command{
    18  - Use: "provider",
    19  - Short: "Cloud utils for Distributed Mode",
    20  - Long: core.Banner(),
    21  - RunE: runProvider,
    22  - }
     17 + var providerCmd = &cobra.Command{
     18 + Use: "provider",
     19 + Short: "Cloud utils for Distributed Mode",
     20 + Long: core.Banner(),
     21 + RunE: runProvider,
     22 + }
    23 23   
    24  - providerCmd.PersistentFlags().StringVar(&options.Cloud.RawCommand, "cmd", "", "raw command")
    25  - providerCmd.PersistentFlags().StringVar(&options.Cloud.CloudWait, "wait", "30m", "timeout to wait before next queue check")
    26  - providerCmd.PersistentFlags().BoolVar(&options.Cloud.CheckingLimit, "check", false, "Only check for limit of config")
    27  - providerCmd.PersistentFlags().StringVar(&options.Cloud.InstanceName, "name", "", "override instance name")
    28  - providerCmd.PersistentFlags().BoolVar(&options.Cloud.BackgroundRun, "bg", false, "Send command to instance and run it in background")
    29  - providerCmd.PersistentFlags().BoolVar(&options.Cloud.IgnoreConfigFile, "ic", false, "Ignore token in the config file")
    30  - providerCmd.PersistentFlags().IntVar(&options.Cloud.Retry, "retry", 8, "Number of retry when command is error")
    31  - providerCmd.PersistentFlags().StringSlice("id", []string{}, "Instance IDs that will be delete")
     24 + providerCmd.PersistentFlags().StringVar(&options.Cloud.RawCommand, "cmd", "", "raw command")
     25 + providerCmd.PersistentFlags().StringVar(&options.Cloud.CloudWait, "wait", "30m", "timeout to wait before next queue check")
     26 + providerCmd.PersistentFlags().BoolVar(&options.Cloud.CheckingLimit, "check", false, "Only check for limit of config")
     27 + providerCmd.PersistentFlags().StringVar(&options.Cloud.InstanceName, "name", "", "override instance name")
     28 + providerCmd.PersistentFlags().BoolVar(&options.Cloud.BackgroundRun, "bg", false, "Send command to instance and run it in background")
     29 + providerCmd.PersistentFlags().BoolVar(&options.Cloud.IgnoreConfigFile, "ic", false, "Ignore token in the config file")
     30 + providerCmd.PersistentFlags().IntVar(&options.Cloud.Retry, "retry", 8, "Number of retry when command is error")
     31 + providerCmd.PersistentFlags().StringSlice("id", []string{}, "Instance IDs that will be delete")
    32 32   
    33  - var providerWizard = &cobra.Command{
    34  - Use: "wizard",
    35  - Aliases: []string{"wi", "wiz", "wizazrd"},
    36  - Short: "Start a cloud config wizard",
    37  - Long: core.Banner(),
    38  - RunE: runCloudInit,
    39  - }
    40  - providerWizard.PersistentFlags().BoolVar(&options.Cloud.AddNewProvider, "add", false, "Open wizard to add new provider only")
     33 + var providerWizard = &cobra.Command{
     34 + Use: "wizard",
     35 + Aliases: []string{"wi", "wiz", "wizazrd"},
     36 + Short: "Start a cloud config wizard",
     37 + Long: core.Banner(),
     38 + RunE: runCloudInit,
     39 + }
     40 + providerWizard.PersistentFlags().BoolVar(&options.Cloud.AddNewProvider, "add", false, "Open wizard to add new provider only")
    41 41   
    42  - var providerBuild = &cobra.Command{
    43  - Use: "build",
    44  - Short: "Build snapshot image",
    45  - Long: core.Banner(),
    46  - RunE: runProviderBuild,
    47  - }
    48  - var providerCreate = &cobra.Command{
    49  - Use: "create",
    50  - Short: "Create cloud instance based on image",
    51  - Long: core.Banner(),
    52  - RunE: runProviderCreate,
    53  - }
     42 + var providerBuild = &cobra.Command{
     43 + Use: "build",
     44 + Short: "Build snapshot image",
     45 + Long: core.Banner(),
     46 + RunE: runProviderBuild,
     47 + }
     48 + var providerCreate = &cobra.Command{
     49 + Use: "create",
     50 + Short: "Create cloud instance based on image",
     51 + Long: core.Banner(),
     52 + RunE: runProviderCreate,
     53 + }
    54 54   
    55  - var providerHealth = &cobra.Command{
    56  - Use: "health",
    57  - Short: "Run a health check on running cloud instances",
    58  - Long: core.Banner(),
    59  - RunE: runCloudHealth,
    60  - }
     55 + var providerHealth = &cobra.Command{
     56 + Use: "health",
     57 + Short: "Run a health check on running cloud instances",
     58 + Long: core.Banner(),
     59 + RunE: runCloudHealth,
     60 + }
    61 61   
    62  - var providerValidate = &cobra.Command{
    63  - Use: "validate",
    64  - Short: "Run validate of the existing cloud configs",
    65  - Long: core.Banner(),
    66  - RunE: runProviderValidate,
    67  - }
    68  - var providerList = &cobra.Command{
    69  - Use: "list",
    70  - Aliases: []string{"ls"},
    71  - Short: "List all instances",
    72  - Long: core.Banner(),
    73  - RunE: runProviderListing,
    74  - }
    75  - var providerDel = &cobra.Command{
    76  - Use: "delete",
    77  - Aliases: []string{"del"},
    78  - Short: "Delete instances",
    79  - Long: core.Banner(),
    80  - RunE: runProviderDelete,
    81  - }
    82  - providerCmd.AddCommand(providerWizard)
    83  - providerCmd.AddCommand(providerList)
    84  - providerCmd.AddCommand(providerDel)
    85  - providerCmd.AddCommand(providerValidate)
    86  - providerCmd.AddCommand(providerHealth)
    87  - providerCmd.AddCommand(providerCreate)
    88  - providerCmd.AddCommand(providerBuild)
    89  - providerCmd.SetHelpFunc(CloudHelp)
    90  - RootCmd.AddCommand(providerCmd)
     62 + var providerValidate = &cobra.Command{
     63 + Use: "validate",
     64 + Short: "Run validate of the existing cloud configs",
     65 + Long: core.Banner(),
     66 + RunE: runProviderValidate,
     67 + }
     68 + var providerList = &cobra.Command{
     69 + Use: "list",
     70 + Aliases: []string{"ls"},
     71 + Short: "List all instances",
     72 + Long: core.Banner(),
     73 + RunE: runProviderListing,
     74 + }
     75 + var providerDel = &cobra.Command{
     76 + Use: "delete",
     77 + Aliases: []string{"del"},
     78 + Short: "Delete instances",
     79 + Long: core.Banner(),
     80 + RunE: runProviderDelete,
     81 + }
     82 + providerCmd.AddCommand(providerWizard)
     83 + providerCmd.AddCommand(providerList)
     84 + providerCmd.AddCommand(providerDel)
     85 + providerCmd.AddCommand(providerValidate)
     86 + providerCmd.AddCommand(providerHealth)
     87 + providerCmd.AddCommand(providerCreate)
     88 + providerCmd.AddCommand(providerBuild)
     89 + providerCmd.SetHelpFunc(CloudHelp)
     90 + RootCmd.AddCommand(providerCmd)
    91 91  }
    92 92   
    93 93  func runCloudHealth(_ *cobra.Command, _ []string) error {
    94  - DBInit()
    95  - distribute.CheckingCloudInstance(options)
    96  - return nil
     94 + DBInit()
     95 + distribute.CheckingCloudInstance(options)
     96 + return nil
    97 97  }
    98 98   
    99 99  func runCloudInit(_ *cobra.Command, _ []string) error {
    100  - DBInit()
    101  - // interactive mode to show config file here
    102  - distribute.InitCloudSetup(options)
    103  - return nil
     100 + DBInit()
     101 + // interactive mode to show config file here
     102 + distribute.InitCloudSetup(options)
     103 + return nil
    104 104  }
    105 105   
    106 106  func runProvider(_ *cobra.Command, args []string) error {
    107  - DBInit()
    108  - if len(args) == 0 {
    109  - fmt.Println(CloudUsage())
    110  - }
    111  - return nil
     107 + DBInit()
     108 + if len(args) == 0 {
     109 + fmt.Println(CloudUsage())
     110 + }
     111 + return nil
    112 112  }
    113 113   
    114 114  func runProviderBuild(_ *cobra.Command, _ []string) error {
    115  - options.Cloud.OnlyCreateDroplet = true
    116  - options.Cloud.ReBuildBaseImage = true
     115 + options.Cloud.OnlyCreateDroplet = true
     116 + options.Cloud.ReBuildBaseImage = true
    117 117   
    118  - // building multiple tokens
    119  - options.Cloud.TokensFile = utils.NormalizePath(options.Cloud.TokensFile)
    120  - if options.Cloud.TokensFile != "" {
    121  - tokens := utils.ReadingFileUnique(options.Cloud.TokensFile)
    122  - if len(tokens) == 0 {
    123  - utils.ErrorF("token file not found: %v", options.Cloud.TokensFile)
    124  - return nil
    125  - }
     118 + // building multiple tokens
     119 + options.Cloud.TokensFile = utils.NormalizePath(options.Cloud.TokensFile)
     120 + if options.Cloud.TokensFile != "" {
     121 + tokens := utils.ReadingFileUnique(options.Cloud.TokensFile)
     122 + if len(tokens) == 0 {
     123 + utils.ErrorF("token file not found: %v", options.Cloud.TokensFile)
     124 + return nil
     125 + }
    126 126   
    127  - var wg sync.WaitGroup
    128  - p, _ := ants.NewPoolWithFunc(options.Concurrency, func(i interface{}) {
    129  - lOptions := options
    130  - lOptions.Cloud.Token = i.(string)
     127 + var wg sync.WaitGroup
     128 + p, _ := ants.NewPoolWithFunc(options.Concurrency, func(i interface{}) {
     129 + lOptions := options
     130 + lOptions.Cloud.Token = i.(string)
    131 131   
    132  - distribute.InitCloud(lOptions, lOptions.Scan.Inputs)
    133  - wg.Done()
    134  - }, ants.WithPreAlloc(true))
    135  - defer p.Release()
     132 + distribute.InitCloud(lOptions, lOptions.Scan.Inputs)
     133 + wg.Done()
     134 + }, ants.WithPreAlloc(true))
     135 + defer p.Release()
    136 136   
    137  - for _, token := range tokens {
    138  - wg.Add(1)
    139  - _ = p.Invoke(token)
    140  - }
    141  - wg.Wait()
    142  - return nil
     137 + for _, token := range tokens {
     138 + wg.Add(1)
     139 + _ = p.Invoke(token)
     140 + }
     141 + wg.Wait()
     142 + return nil
    143 143   
    144  - }
     144 + }
    145 145   
    146  - distribute.InitCloud(options, options.Scan.Inputs)
    147  - return nil
     146 + distribute.InitCloud(options, options.Scan.Inputs)
     147 + return nil
    148 148  }
    149 149   
    150 150  func runProviderCreate(_ *cobra.Command, _ []string) error {
    151  - options.Cloud.OnlyCreateDroplet = true
    152  - if len(options.Scan.Inputs) == 0 {
    153  - options.Scan.Inputs = append(options.Scan.Inputs, utils.RandomString(4))
    154  - }
     151 + options.Cloud.OnlyCreateDroplet = true
     152 + if len(options.Scan.Inputs) == 0 {
     153 + options.Scan.Inputs = append(options.Scan.Inputs, utils.RandomString(4))
     154 + }
    155 155   
    156  - distribute.InitCloud(options, options.Scan.Inputs)
    157  - return nil
     156 + distribute.InitCloud(options, options.Scan.Inputs)
     157 + return nil
    158 158  }
    159 159   
    160 160  func runProviderValidate(_ *cobra.Command, _ []string) error {
    161  - cloudValidate()
    162  - return nil
     161 + cloudValidate()
     162 + return nil
    163 163  }
    164 164   
    165 165  func runProviderListing(_ *cobra.Command, _ []string) error {
    166  - cloudRunners := distribute.GetClouds(options)
    167  - cloudListing(cloudRunners)
    168  - return nil
     166 + cloudRunners := distribute.GetClouds(options)
     167 + cloudListing(cloudRunners)
     168 + return nil
    169 169  }
    170 170   
    171 171  func runProviderDelete(cmd *cobra.Command, _ []string) error {
    172  - cloudRunners := distribute.GetClouds(options)
    173  - InstanceIDs, _ := cmd.Flags().GetStringSlice("id")
     172 + cloudRunners := distribute.GetClouds(options)
     173 + InstanceIDs, _ := cmd.Flags().GetStringSlice("id")
    174 174   
    175  - for _, InstanceID := range InstanceIDs {
    176  - for _, cloudRunner := range cloudRunners {
    177  - cloudRunner.Provider.DeleteInstance(InstanceID)
    178  - }
    179  - }
     175 + for _, InstanceID := range InstanceIDs {
     176 + for _, cloudRunner := range cloudRunners {
     177 + cloudRunner.Provider.DeleteInstance(InstanceID)
     178 + }
     179 + }
    180 180   
    181  - cloudListing(cloudRunners)
    182  - return nil
     181 + cloudListing(cloudRunners)
     182 + return nil
    183 183  }
    184 184   
    185 185  func cloudListing(cloudRunners []distribute.CloudRunner) {
    186  - var content [][]string
    187  - for _, cloudRunner := range cloudRunners {
    188  - cloudRunner.Provider.Action(provider.ListInstance)
    189  - for _, instance := range cloudRunner.Provider.Instances {
    190  - row := []string{
    191  - cloudRunner.Provider.ProviderName,
    192  - cloudRunner.Provider.RedactedToken,
    193  - instance.InstanceID,
    194  - instance.InstanceName,
    195  - instance.IPAddress,
    196  - }
    197  - content = append(content, row)
    198  - }
    199  - }
    200  - table := tablewriter.NewWriter(os.Stderr)
    201  - table.SetAutoFormatHeaders(false)
    202  - table.SetHeader([]string{"Provider", "Token", "Instance ID", "Instance Name", "IP Address"})
    203  - table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
    204  - table.SetCenterSeparator("|")
    205  - table.AppendBulk(content) // Add Bulk Data
    206  - table.Render()
     186 + var content [][]string
     187 + for _, cloudRunner := range cloudRunners {
     188 + cloudRunner.Provider.Action(provider.ListInstance)
     189 + for _, instance := range cloudRunner.Provider.Instances {
     190 + row := []string{
     191 + cloudRunner.Provider.ProviderName,
     192 + cloudRunner.Provider.RedactedToken,
     193 + instance.InstanceID,
     194 + instance.InstanceName,
     195 + instance.IPAddress,
     196 + }
     197 + content = append(content, row)
     198 + }
     199 + }
     200 + table := tablewriter.NewWriter(os.Stderr)
     201 + table.SetAutoFormatHeaders(false)
     202 + table.SetHeader([]string{"Provider", "Token", "Instance ID", "Instance Name", "IP Address"})
     203 + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
     204 + table.SetCenterSeparator("|")
     205 + table.AppendBulk(content) // Add Bulk Data
     206 + table.Render()
    207 207  }
    208 208   
    209 209  func cloudValidate() {
    210  - cloudRunners := distribute.GetClouds(options)
     210 + cloudRunners := distribute.GetClouds(options)
    211 211   
    212  - var content [][]string
    213  - for _, cloudRunner := range cloudRunners {
    214  - row := []string{
    215  - cloudRunner.Provider.ProviderName,
    216  - cloudRunner.Provider.RedactedToken,
    217  - cloudRunner.Provider.SSHKeyID,
    218  - cloudRunner.Provider.SnapshotID,
    219  - }
    220  - content = append(content, row)
    221  - }
    222  - table := tablewriter.NewWriter(os.Stderr)
    223  - table.SetAutoFormatHeaders(false)
    224  - table.SetHeader([]string{"Provider", "Token", "SSH Key ID", "Osmedeus Snapshot ID"})
    225  - table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
    226  - table.SetCenterSeparator("|")
    227  - table.AppendBulk(content) // Add Bulk Data
    228  - table.Render()
     212 + var content [][]string
     213 + for _, cloudRunner := range cloudRunners {
     214 + row := []string{
     215 + cloudRunner.Provider.ProviderName,
     216 + cloudRunner.Provider.RedactedToken,
     217 + cloudRunner.Provider.SSHKeyID,
     218 + cloudRunner.Provider.SnapshotID,
     219 + }
     220 + content = append(content, row)
     221 + }
     222 + table := tablewriter.NewWriter(os.Stderr)
     223 + table.SetAutoFormatHeaders(false)
     224 + table.SetHeader([]string{"Provider", "Token", "SSH Key ID", "Osmedeus Snapshot ID"})
     225 + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
     226 + table.SetCenterSeparator("|")
     227 + table.AppendBulk(content) // Add Bulk Data
     228 + table.Render()
    229 229   
    230 230  }
    231 231   
  • ■ ■ ■ ■ ■ ■
    cmd/queue.go
     1 +package cmd
     2 + 
     3 +import (
     4 + "fmt"
     5 + "github.com/fatih/color"
     6 + "github.com/j3ssie/osmedeus/core"
     7 + "github.com/j3ssie/osmedeus/libs"
     8 + "github.com/j3ssie/osmedeus/utils"
     9 + jsoniter "github.com/json-iterator/go"
     10 + "github.com/spf13/cobra"
     11 + "path"
     12 + "strings"
     13 +)
     14 + 
     15 +func init() {
     16 + var queueCmd = &cobra.Command{
     17 + Use: "queue",
     18 + Short: "Running the scan with input from queue file",
     19 + Aliases: []string{"queq", "quee", "queu", "que"},
     20 + Long: core.Banner(),
     21 + RunE: runQueue,
     22 + }
     23 + queueCmd.PersistentFlags().StringVarP(&options.Queue.QueueFile, "queue-file", "Q", fmt.Sprintf("~/.%s/queue/queue-mimic.txt", libs.BINARY), "File contain list of target to simulate the queue")
     24 + queueCmd.PersistentFlags().BoolVar(&options.Queue.Add, "add", false, "Add new input to the queue file")
     25 + queueCmd.PersistentFlags().BoolVarP(&options.Queue.InputAsFile, "as-file", "F", false, "treat input as a file")
     26 + queueCmd.PersistentFlags().StringVar(&options.Queue.RawCommand, "cmd", "", "Raw Command to run")
     27 + queueCmd.SetHelpFunc(QueueHelp)
     28 + RootCmd.AddCommand(queueCmd)
     29 +}
     30 + 
     31 +func runQueue(_ *cobra.Command, _ []string) error {
     32 + DBInit()
     33 + 
     34 + options.Queue.QueueFile = utils.NormalizePath(options.Queue.QueueFile)
     35 + options.Queue.QueueFolder = path.Dir(options.Queue.QueueFile)
     36 + if !utils.FolderExists(options.Queue.QueueFolder) {
     37 + utils.MakeDir(options.Queue.QueueFolder)
     38 + }
     39 + 
     40 + if options.Queue.Add {
     41 + addInput()
     42 + return nil
     43 + }
     44 + 
     45 + if !utils.FileExists(options.Queue.QueueFile) {
     46 + utils.WriteToFile(options.Queue.QueueFile, "")
     47 + }
     48 + 
     49 + content := utils.ReadingFileUnique(options.Queue.QueueFile)
     50 + if len(content) == 0 {
     51 + utils.WarnF("Queue file is empty: %v", options.Queue.QueueFile)
     52 + utils.WarnF("Consider to add a input to it:" + color.HiGreenString(" osmedeus queue --add -t example.com"))
     53 + } else {
     54 + utils.InforF("Queue file is not empty: %v", color.HiCyanString(options.Queue.QueueFile))
     55 + utils.InforF("Consider to delete it if you want a fresh scan")
     56 + }
     57 + 
     58 + core.QueueWatcher(options)
     59 + return nil
     60 +}
     61 + 
     62 +func addInput() {
     63 + utils.InforF("Adding new input to the queue file: %v", color.HiCyanString(options.Queue.QueueFile))
     64 + // osmedeus queue --add -t example.com
     65 + if options.Queue.RawCommand == "" {
     66 + utils.WriteToFile(options.Queue.QueueFile, strings.Join(options.Scan.Inputs, "\n"))
     67 + return
     68 + }
     69 + 
     70 + // osmedeus queue --add -t /tmp/cidr --cmd "osmedeus -t {{.Input}} -m recon -w"
     71 + for _, target := range options.Scan.Inputs {
     72 + queueInput := libs.InputFormat{
     73 + Input: target,
     74 + Command: options.Queue.RawCommand,
     75 + InputAsFile: options.Queue.InputAsFile,
     76 + }
     77 + if line, ok := jsoniter.MarshalToString(queueInput); ok == nil {
     78 + utils.AppendToContent(options.Queue.QueueFile, line)
     79 + }
     80 + }
     81 +}
     82 + 
  • ■ ■ ■ ■ ■ ■
    cmd/report.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "github.com/fatih/color"
    5  - "github.com/j3ssie/osmedeus/core"
    6  - "github.com/j3ssie/osmedeus/utils"
    7  - "github.com/spf13/cobra"
    8  - "io/ioutil"
    9  - "net/http"
     4 + "github.com/fatih/color"
     5 + "github.com/j3ssie/osmedeus/core"
     6 + "github.com/j3ssie/osmedeus/utils"
     7 + "github.com/spf13/cobra"
     8 + "io/ioutil"
     9 + "net/http"
     10 + "path/filepath"
    10 11  )
    11 12   
    12 13  func init() {
    13  - var reportCmd = &cobra.Command{
    14  - Use: "report",
    15  - Short: "Show report of existing workspace",
    16  - Long: core.Banner(),
    17  - RunE: runReport,
    18  - }
    19  - 
    20  - var lsCmd = &cobra.Command{
    21  - Use: "list",
    22  - Aliases: []string{"ls"},
    23  - Short: "List all current existing workspace",
    24  - Long: core.Banner(),
    25  - RunE: runReportList,
    26  - }
    27  - reportCmd.AddCommand(lsCmd)
     14 + var reportCmd = &cobra.Command{
     15 + Use: "report",
     16 + Short: "Show report of existing workspace",
     17 + Long: core.Banner(),
     18 + RunE: runReport,
     19 + }
    28 20   
    29  - var viewCmd = &cobra.Command{
    30  - Use: "view",
    31  - Short: "View all reports of existing workspace",
    32  - Long: core.Banner(),
    33  - RunE: runReportView,
    34  - }
    35  - reportCmd.AddCommand(viewCmd)
     21 + var lsCmd = &cobra.Command{
     22 + Use: "list",
     23 + Aliases: []string{"ls"},
     24 + Short: "List all current existing workspace",
     25 + Long: core.Banner(),
     26 + RunE: runReportList,
     27 + }
     28 + reportCmd.AddCommand(lsCmd)
    36 29   
    37  - var extractCmd = &cobra.Command{
    38  - Use: "extract",
    39  - Short: "Extract a compressed workspace",
    40  - Long: core.Banner(),
    41  - RunE: runReportExtract,
    42  - }
    43  - extractCmd.Flags().StringVar(&options.Report.WorkspaceFile, "ws", "", "Workspace file to extract")
    44  - reportCmd.AddCommand(extractCmd)
     30 + var viewCmd = &cobra.Command{
     31 + Use: "view",
     32 + Aliases: []string{"vi", "v"},
     33 + Short: "View all reports of existing workspace",
     34 + Long: core.Banner(),
     35 + RunE: runReportView,
     36 + }
     37 + reportCmd.AddCommand(viewCmd)
    45 38   
    46  - reportCmd.PersistentFlags().BoolVar(&options.Report.Raw, "raw", false, "Show all the file in the workspace")
    47  - reportCmd.PersistentFlags().StringVar(&options.Report.PublicIP, "ip", "", "Show downloadable file with the given IP address")
    48  - reportCmd.PersistentFlags().BoolVar(&options.Report.Static, "static", false, "Show report file with Prefix Static")
     39 + var extractCmd = &cobra.Command{
     40 + Use: "extract",
     41 + Aliases: []string{"ext", "ex", "e"},
     42 + Short: "Extract a compressed workspace",
     43 + Long: core.Banner(),
     44 + RunE: runReportExtract,
     45 + }
     46 + extractCmd.Flags().StringVar(&options.Report.ExtractFolder, "dest", "", "Destination folder to extract data to")
     47 + reportCmd.AddCommand(extractCmd)
    49 48   
    50  - reportCmd.SetHelpFunc(ReportHelp)
    51  - RootCmd.AddCommand(reportCmd)
     49 + reportCmd.PersistentFlags().BoolVar(&options.Report.Raw, "raw", false, "Show all the file in the workspace")
     50 + reportCmd.PersistentFlags().StringVar(&options.Report.PublicIP, "ip", "", "Show downloadable file with the given IP address")
     51 + reportCmd.PersistentFlags().BoolVar(&options.Report.Static, "static", false, "Show report file with Prefix Static")
     52 + reportCmd.SetHelpFunc(ReportHelp)
     53 + RootCmd.AddCommand(reportCmd)
    52 54  }
    53 55   
    54 56  func runReportList(_ *cobra.Command, _ []string) error {
    55  - core.ListWorkspaces(options)
    56  - return nil
     57 + core.ListWorkspaces(options)
     58 + return nil
    57 59  }
    58 60   
    59 61  func runReportView(_ *cobra.Command, _ []string) error {
    60  - if options.Report.PublicIP == "" {
    61  - if utils.GetOSEnv("IPAddress", "127.0.0.1") == "127.0.0.1" {
    62  - options.Report.PublicIP = utils.GetOSEnv("IPAddress", "127.0.0.1")
    63  - }
    64  - }
     62 + if options.Report.PublicIP == "" {
     63 + if utils.GetOSEnv("IPAddress", "127.0.0.1") == "127.0.0.1" {
     64 + options.Report.PublicIP = utils.GetOSEnv("IPAddress", "127.0.0.1")
     65 + }
     66 + }
    65 67   
    66  - if options.Report.PublicIP == "0" || options.Report.PublicIP == "0.0.0.0" {
    67  - options.Report.PublicIP = getPublicIP()
    68  - }
     68 + if options.Report.PublicIP == "0" || options.Report.PublicIP == "0.0.0.0" {
     69 + options.Report.PublicIP = getPublicIP()
     70 + }
    69 71   
    70  - if len(options.Scan.Inputs) == 0 {
    71  - core.ListWorkspaces(options)
    72  - utils.InforF("Please select workspace to view report. Try %s", color.HiCyanString(`'osmedeus report view -t target.com'`))
    73  - return nil
    74  - }
     72 + if len(options.Scan.Inputs) == 0 {
     73 + core.ListWorkspaces(options)
     74 + utils.InforF("Please select workspace to view report. Try %s", color.HiCyanString(`'osmedeus report view -t target.com'`))
     75 + return nil
     76 + }
    75 77   
    76  - for _, target := range options.Scan.Inputs {
    77  - core.ListSingleWorkspace(options, target)
    78  - }
    79  - return nil
     78 + for _, target := range options.Scan.Inputs {
     79 + core.ListSingleWorkspace(options, target)
     80 + }
     81 + return nil
    80 82  }
    81 83   
    82 84  func runReportExtract(_ *cobra.Command, _ []string) error {
    83  - core.ListWorkspaces(options)
    84  - return nil
     85 + var err error
     86 + if options.Report.ExtractFolder == "" {
     87 + options.Report.ExtractFolder = options.Env.WorkspacesFolder
     88 + } else {
     89 + options.Report.ExtractFolder, err = filepath.Abs(filepath.Dir(options.Report.ExtractFolder))
     90 + if err != nil {
     91 + return err
     92 + }
     93 + }
     94 + 
     95 + for _, target := range options.Scan.Inputs {
     96 + core.ExtractBackup(target, options)
     97 + }
     98 + 
     99 + return nil
    85 100  }
    86 101   
    87 102  func runReport(_ *cobra.Command, _ []string) error {
    88  - if options.Report.PublicIP == "" {
    89  - if utils.GetOSEnv("IPAddress", "127.0.0.1") == "127.0.0.1" {
    90  - options.Report.PublicIP = utils.GetOSEnv("IPAddress", "127.0.0.1")
    91  - }
    92  - }
     103 + if options.Report.PublicIP == "" {
     104 + if utils.GetOSEnv("IPAddress", "127.0.0.1") == "127.0.0.1" {
     105 + options.Report.PublicIP = utils.GetOSEnv("IPAddress", "127.0.0.1")
     106 + }
     107 + }
    93 108   
    94  - if options.Report.PublicIP == "0" || options.Report.PublicIP == "0.0.0.0" {
    95  - options.Report.PublicIP = getPublicIP()
    96  - }
     109 + if options.Report.PublicIP == "0" || options.Report.PublicIP == "0.0.0.0" {
     110 + options.Report.PublicIP = getPublicIP()
     111 + }
    97 112   
    98  - return nil
     113 + return nil
    99 114  }
    100 115   
    101 116  func getPublicIP() string {
    102  - utils.DebugF("getting Public IP Address")
    103  - req, err := http.Get("https://api.ipify.org")
    104  - if err != nil {
    105  - return "127.0.0.1"
    106  - }
    107  - defer req.Body.Close()
     117 + utils.DebugF("getting Public IP Address")
     118 + req, err := http.Get("https://api.ipify.org")
     119 + if err != nil {
     120 + return "127.0.0.1"
     121 + }
     122 + defer req.Body.Close()
    108 123   
    109  - body, err := ioutil.ReadAll(req.Body)
    110  - if err != nil {
    111  - return "127.0.0.1"
    112  - }
    113  - return string(body)
     124 + body, err := ioutil.ReadAll(req.Body)
     125 + if err != nil {
     126 + return "127.0.0.1"
     127 + }
     128 + return string(body)
    114 129  }
    115 130   
  • ■ ■ ■ ■ ■ ■
    cmd/root.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "bufio"
    5  - "fmt"
    6  - "github.com/j3ssie/osmedeus/database"
    7  - "os"
    8  - "strings"
     4 + "bufio"
     5 + "fmt"
     6 + "github.com/j3ssie/osmedeus/database"
     7 + "os"
     8 + "strings"
    9 9   
    10  - "github.com/j3ssie/osmedeus/core"
    11  - "github.com/j3ssie/osmedeus/libs"
    12  - "github.com/j3ssie/osmedeus/utils"
    13  - "github.com/spf13/cobra"
     10 + "github.com/j3ssie/osmedeus/core"
     11 + "github.com/j3ssie/osmedeus/libs"
     12 + "github.com/j3ssie/osmedeus/utils"
     13 + "github.com/spf13/cobra"
    14 14  )
    15 15   
    16 16  var options = libs.Options{}
    skipped 2 lines
    19 19  //var DB *gorm.DB
    20 20   
    21 21  var RootCmd = &cobra.Command{
    22  - Use: fmt.Sprintf("%s", libs.BINARY),
    23  - Short: fmt.Sprintf("%s - %s", libs.BINARY, libs.DESC),
    24  - Long: core.Banner(),
     22 + Use: fmt.Sprintf("%s", libs.BINARY),
     23 + Short: fmt.Sprintf("%s - %s", libs.BINARY, libs.DESC),
     24 + Long: core.Banner(),
    25 25  }
    26 26   
    27 27  // Execute main function
    28 28  func Execute() {
    29  - if err := RootCmd.Execute(); err != nil {
    30  - fmt.Println(err)
    31  - os.Exit(1)
    32  - }
     29 + if err := RootCmd.Execute(); err != nil {
     30 + fmt.Println(err)
     31 + os.Exit(1)
     32 + }
    33 33  }
    34 34   
    35 35  func init() {
    36  - RootCmd.PersistentFlags().StringVar(&options.Env.RootFolder, "rootFolder", fmt.Sprintf("~/.%s/", libs.BINARY), "Root Folder to store Result")
    37  - RootCmd.PersistentFlags().StringVar(&options.Env.BaseFolder, "baseFolder", fmt.Sprintf("~/%s-base/", libs.BINARY), "Base Folder which is store data, binaries and workflows")
    38  - RootCmd.PersistentFlags().StringVar(&options.ConfigFile, "configFile", fmt.Sprintf("~/.%s/config.yaml", libs.BINARY), "Config File")
    39  - RootCmd.PersistentFlags().StringVar(&options.Env.WorkspacesFolder, "wsFolder", fmt.Sprintf("~/.%s/workspaces", libs.BINARY), "Root Workspace folder")
    40  - RootCmd.PersistentFlags().StringVar(&options.Env.WorkFlowsFolder, "wfFolder", "", fmt.Sprintf("Custom Workflow folder (default will get from '$HOME/%s-base/workflow')", libs.BINARY))
    41  - RootCmd.PersistentFlags().StringVar(&options.LogFile, "log", "", fmt.Sprintf("Log File (default will store in '%s')", libs.LDIR))
    42  - RootCmd.PersistentFlags().IntVarP(&options.Concurrency, "concurrency", "c", 1, "Concurrency level (recommend to keep it as 1 on machine has RAM smaller than 2GB)")
     36 + RootCmd.PersistentFlags().StringVar(&options.Env.RootFolder, "rootFolder", fmt.Sprintf("~/.%s/", libs.BINARY), "Root Folder to store Result")
     37 + RootCmd.PersistentFlags().StringVar(&options.Env.BaseFolder, "baseFolder", fmt.Sprintf("~/%s-base/", libs.BINARY), "Base Folder which is store data, binaries and workflows")
     38 + RootCmd.PersistentFlags().StringVar(&options.ConfigFile, "configFile", fmt.Sprintf("~/.%s/config.yaml", libs.BINARY), "Config File")
     39 + RootCmd.PersistentFlags().StringVar(&options.Env.DataFolder, "dataFolder", fmt.Sprintf("~/%s-base/data", libs.BINARY), "Root Workspace folder")
     40 + RootCmd.PersistentFlags().StringVar(&options.Env.WorkspacesFolder, "wsFolder", fmt.Sprintf("~/.%s/workspaces", libs.BINARY), "Root Workspace folder")
     41 + RootCmd.PersistentFlags().StringVar(&options.Env.WorkFlowsFolder, "wfFolder", "", fmt.Sprintf("Custom Workflow folder (default will get from '$HOME/%s-base/workflow')", libs.BINARY))
     42 + RootCmd.PersistentFlags().StringVar(&options.LogFile, "log", "", fmt.Sprintf("Log File (default will store in '%s')", libs.LDIR))
     43 + RootCmd.PersistentFlags().IntVarP(&options.Concurrency, "concurrency", "c", 1, "Concurrency level (recommend to keep it as 1 on machine has RAM smaller than 2GB)")
    43 44   
    44  - // parse target as global flag
    45  - RootCmd.PersistentFlags().StringSliceVarP(&options.Scan.Inputs, "target", "t", []string{}, "Target to running")
    46  - RootCmd.PersistentFlags().StringVarP(&options.Scan.InputList, "targets", "T", "", "List of target as a file")
     45 + // parse target as global flag
     46 + RootCmd.PersistentFlags().StringSliceVarP(&options.Scan.Inputs, "target", "t", []string{}, "Target to running")
     47 + RootCmd.PersistentFlags().StringVarP(&options.Scan.InputList, "targets", "T", "", "List of target as a file")
    47 48   
    48  - // cloud flags
    49  - RootCmd.PersistentFlags().BoolVar(&options.Cloud.EnableChunk, "chunk", false, "Enable chunk mode")
    50  - RootCmd.PersistentFlags().IntVarP(&options.Cloud.NumberOfParts, "chunk-parts", "P", 0, "Number of chunks file to split (default: equal with concurrency)")
    51  - RootCmd.PersistentFlags().StringVar(&options.Cloud.ChunkInputs, "chunkFolder", "/tmp/chunk-inputs/", "Temp Folder to store chunk inputs")
    52  - RootCmd.PersistentFlags().StringVar(&options.Timeout, "timeout", "", "Global timeout for each step (e.g: 60s, 30m, 2h)")
    53  - RootCmd.PersistentFlags().StringVar(&options.Cloud.Size, "size", "", "Override Size of cloud provider (default will get from 'cloud/provider.yaml')")
    54  - RootCmd.PersistentFlags().StringVar(&options.Cloud.Region, "region", "", "Override Region of cloud provider (default will get from 'cloud/provider.yaml')")
    55  - RootCmd.PersistentFlags().StringVar(&options.Cloud.Token, "token", "", "Override token of cloud provider (default will get from 'cloud/provider.yaml')")
    56  - RootCmd.PersistentFlags().StringVar(&options.Cloud.TokensFile, "token-file", "", "Override token of cloud provider (default will get from 'cloud/provider.yaml')")
    57  - RootCmd.PersistentFlags().StringVar(&options.Cloud.Provider, "provider", "", "Provider config file (default will get from 'cloud/provider.yaml')")
    58  - RootCmd.PersistentFlags().BoolVar(&options.Cloud.ReBuildBaseImage, "rebuild", false, "Forced to rebuild the images event though the version didn't change")
     49 + // Scan command
     50 + RootCmd.PersistentFlags().StringSliceVarP(&options.Scan.Modules, "module", "m", []string{}, "Target to running")
     51 + RootCmd.PersistentFlags().StringVarP(&options.Scan.Flow, "flow", "f", "general", "Flow name for running (default: general)")
     52 + RootCmd.PersistentFlags().StringVarP(&options.Scan.CustomWorkspace, "workspace", "w", "", "Name of workspace (default is same as target)")
     53 + RootCmd.PersistentFlags().StringSliceVarP(&options.Scan.Params, "params", "p", []string{}, "Custom params -p='foo=bar' (Multiple -p flags are accepted)")
    59 54   
    60  - // mics option
    61  - RootCmd.PersistentFlags().StringVarP(&options.ScanID, "sid", "s", "", "Scan ID to continue the scan without create new scan record")
    62  - RootCmd.PersistentFlags().BoolVarP(&options.Resume, "resume", "R", false, "Enable Resume mode to skip modules that have already been finished")
    63  - RootCmd.PersistentFlags().BoolVar(&options.Debug, "debug", false, "Enable Debug output")
    64  - RootCmd.PersistentFlags().BoolVarP(&options.Quite, "quite", "q", false, "Show only essential information")
    65  - RootCmd.PersistentFlags().BoolVar(&options.WildCardCheck, "ww", false, "Check for wildcard target")
    66  - RootCmd.PersistentFlags().BoolVar(&options.DisableValidateInput, "nv", false, "Disable Validate Input")
    67  - RootCmd.PersistentFlags().BoolVar(&options.Update.NoUpdate, "nu", false, "Disable Update options")
    68  - RootCmd.PersistentFlags().BoolVarP(&options.EnableFormatInput, "format-input", "J", false, "Enable special input format")
     55 + // cloud flags
     56 + RootCmd.PersistentFlags().BoolVar(&options.Cloud.EnableChunk, "chunk", false, "Enable chunk mode")
     57 + RootCmd.PersistentFlags().IntVarP(&options.Cloud.NumberOfParts, "chunk-parts", "P", 0, "Number of chunks file to split (default: equal with concurrency)")
     58 + RootCmd.PersistentFlags().StringVar(&options.Cloud.ChunkInputs, "chunkFolder", "/tmp/chunk-inputs/", "Temp Folder to store chunk inputs")
     59 + RootCmd.PersistentFlags().StringVar(&options.Timeout, "timeout", "", "Global timeout for each step (e.g: 60s, 30m, 2h)")
     60 + RootCmd.PersistentFlags().StringVar(&options.Cloud.Size, "size", "", "Override Size of cloud provider (default will get from 'cloud/provider.yaml')")
     61 + RootCmd.PersistentFlags().StringVar(&options.Cloud.Region, "region", "", "Override Region of cloud provider (default will get from 'cloud/provider.yaml')")
     62 + RootCmd.PersistentFlags().StringVar(&options.Cloud.Token, "token", "", "Override token of cloud provider (default will get from 'cloud/provider.yaml')")
     63 + RootCmd.PersistentFlags().StringVar(&options.Cloud.TokensFile, "token-file", "", "Override token of cloud provider (default will get from 'cloud/provider.yaml')")
     64 + RootCmd.PersistentFlags().StringVar(&options.Cloud.Provider, "provider", "", "Provider config file (default will get from 'cloud/provider.yaml')")
     65 + RootCmd.PersistentFlags().BoolVar(&options.Cloud.ReBuildBaseImage, "rebuild", false, "Forced to rebuild the images event though the version didn't change")
    69 66   
    70  - // disable options
    71  - RootCmd.PersistentFlags().BoolVar(&options.NoNoti, "nn", false, "No notification")
    72  - RootCmd.PersistentFlags().BoolVar(&options.NoBanner, "nb", false, "No banner")
    73  - RootCmd.PersistentFlags().BoolVarP(&options.NoDB, "no-db", "D", false, "No store DB record")
    74  - RootCmd.PersistentFlags().BoolVarP(&options.NoGit, "no-git", "N", false, "No git storage")
    75  - RootCmd.PersistentFlags().BoolVarP(&options.NoClean, "no-clean", "C", false, "No clean junk output")
    76  - RootCmd.PersistentFlags().StringSliceVarP(&options.Exclude, "exclude", "x", []string{}, "Exclude module name (Multiple -x flags are accepted)")
    77  - RootCmd.PersistentFlags().BoolVarP(&options.CustomGit, "git", "g", false, "Use custom Git repo")
     67 + // mics option
     68 + RootCmd.PersistentFlags().StringVarP(&options.ScanID, "sid", "s", "", "Scan ID to continue the scan without create new scan record")
     69 + RootCmd.PersistentFlags().BoolVarP(&options.Resume, "resume", "R", false, "Enable Resume mode to skip modules that have already been finished")
     70 + RootCmd.PersistentFlags().BoolVar(&options.Debug, "debug", false, "Enable Debug output")
     71 + RootCmd.PersistentFlags().BoolVarP(&options.Quite, "quite", "q", false, "Show only essential information")
     72 + RootCmd.PersistentFlags().BoolVar(&options.WildCardCheck, "ww", false, "Check for wildcard target")
     73 + RootCmd.PersistentFlags().BoolVar(&options.DisableValidateInput, "nv", false, "Disable Validate Input")
     74 + RootCmd.PersistentFlags().BoolVar(&options.Update.NoUpdate, "nu", false, "Disable Update options")
     75 + RootCmd.PersistentFlags().BoolVarP(&options.EnableFormatInput, "format-input", "J", false, "Enable special input format")
    78 76   
    79  - // sync options
    80  - RootCmd.PersistentFlags().BoolVar(&options.EnableDeStorage, "des", false, "Enable Dedicated Storages")
    81  - RootCmd.PersistentFlags().BoolVar(&options.GitSync, "sync", false, "Enable Sync Check before doing git push")
    82  - RootCmd.PersistentFlags().IntVar(&options.SyncTimes, "sync-timee", 15, "Number of times to check before force push")
    83  - RootCmd.PersistentFlags().IntVar(&options.PollingTime, "poll-timee", 100, "Number of seconds to sleep before do next sync check")
    84  - RootCmd.PersistentFlags().BoolVar(&options.NoCdn, "no-cdn", false, "Disable CDN feature")
    85  - RootCmd.PersistentFlags().BoolVarP(&options.EnableBackup, "backup", "b", false, "Enable Backup after done")
     77 + // disable options
     78 + RootCmd.PersistentFlags().BoolVar(&options.NoNoti, "nn", false, "No notification")
     79 + RootCmd.PersistentFlags().BoolVar(&options.NoBanner, "nb", false, "No banner")
     80 + RootCmd.PersistentFlags().BoolVarP(&options.NoDB, "no-db", "D", false, "No store DB record")
     81 + RootCmd.PersistentFlags().BoolVarP(&options.NoGit, "no-git", "N", false, "No git storage")
     82 + RootCmd.PersistentFlags().BoolVarP(&options.NoClean, "no-clean", "C", false, "No clean junk output")
     83 + RootCmd.PersistentFlags().StringSliceVarP(&options.Exclude, "exclude", "x", []string{}, "Exclude module name (Multiple -x flags are accepted)")
     84 + RootCmd.PersistentFlags().BoolVarP(&options.CustomGit, "git", "g", false, "Use custom Git repo")
    86 85   
    87  - // update options
    88  - RootCmd.PersistentFlags().BoolVar(&options.Update.IsUpdateBin, "bin", false, "Update binaries too")
    89  - RootCmd.PersistentFlags().BoolVar(&options.Update.EnableUpdate, "update", false, "Enable auto update")
    90  - RootCmd.PersistentFlags().StringVar(&options.Update.UpdateFolder, "update-folder", "/tmp/osm-update", "Folder to clone the update folder")
     86 + // sync options
     87 + RootCmd.PersistentFlags().BoolVar(&options.EnableDeStorage, "des", false, "Enable Dedicated Storages")
     88 + RootCmd.PersistentFlags().BoolVar(&options.GitSync, "sync", false, "Enable Sync Check before doing git push")
     89 + RootCmd.PersistentFlags().IntVar(&options.SyncTimes, "sync-timee", 15, "Number of times to check before force push")
     90 + RootCmd.PersistentFlags().IntVar(&options.PollingTime, "poll-timee", 100, "Number of seconds to sleep before do next sync check")
     91 + RootCmd.PersistentFlags().BoolVar(&options.NoCdn, "no-cdn", false, "Disable CDN feature")
     92 + RootCmd.PersistentFlags().BoolVarP(&options.EnableBackup, "backup", "b", false, "Backup the result after the scan is done")
    91 93   
    92  - RootCmd.SetHelpFunc(RootHelp)
    93  - cobra.OnInitialize(initConfig)
     94 + // update options
     95 + RootCmd.PersistentFlags().BoolVar(&options.Update.IsUpdateBin, "bin", false, "Update binaries too")
     96 + RootCmd.PersistentFlags().BoolVar(&options.Update.EnableUpdate, "update", false, "Enable auto update")
     97 + RootCmd.PersistentFlags().StringVar(&options.Update.UpdateFolder, "update-folder", "/tmp/osm-update", "Folder to clone the update folder")
     98 + 
     99 + RootCmd.SetHelpFunc(RootHelp)
     100 + cobra.OnInitialize(initConfig)
    94 101  }
    95 102   
    96 103  // initConfig reads in config file and ENV variables if set.
    97 104  func initConfig() {
    98  - if options.JsonOutput {
    99  - options.Quite = true
    100  - }
     105 + if options.JsonOutput {
     106 + options.Quite = true
     107 + }
    101 108   
    102  - /* Really Start the program */
    103  - utils.InitLog(&options)
    104  - utils.InitHTTPClient()
    105  - if err := core.InitConfig(&options); err != nil {
    106  - utils.ErrorF("config file does not writable: %v", options.ConfigFile)
    107  - utils.BlockF("fatal", "Make sure you are login as 'root user' if your installation done via root user")
    108  - }
     109 + /* Really Start the program */
     110 + utils.InitLog(&options)
     111 + utils.InitHTTPClient()
     112 + if err := core.InitConfig(&options); err != nil {
     113 + utils.ErrorF("config file does not writable: %v", options.ConfigFile)
     114 + utils.BlockF("fatal", "Make sure you are login as 'root user' if your installation done via root user")
     115 + }
     116 + core.LoadConfig(&options)
    109 117   
    110  - // parse inputs
    111  - if options.Scan.InputList != "" {
    112  - if utils.FileExists(options.Scan.InputList) {
    113  - options.Scan.Inputs = append(options.Scan.Inputs, utils.ReadingFileUnique(options.Scan.InputList)...)
    114  - }
    115  - }
     118 + // parse inputs
     119 + if options.Scan.InputList != "" {
     120 + if utils.FileExists(options.Scan.InputList) {
     121 + options.Scan.Inputs = append(options.Scan.Inputs, utils.ReadingFileUnique(options.Scan.InputList)...)
     122 + }
     123 + }
    116 124   
    117  - // detect if anything came from stdin
    118  - stat, _ := os.Stdin.Stat()
    119  - if (stat.Mode() & os.ModeCharDevice) == 0 {
    120  - sc := bufio.NewScanner(os.Stdin)
    121  - for sc.Scan() {
    122  - target := strings.TrimSpace(sc.Text())
    123  - if err := sc.Err(); err == nil && target != "" {
    124  - options.Scan.Inputs = append(options.Scan.Inputs, target)
    125  - }
    126  - }
    127  - }
     125 + // detect if anything came from stdin
     126 + stat, _ := os.Stdin.Stat()
     127 + if (stat.Mode() & os.ModeCharDevice) == 0 {
     128 + sc := bufio.NewScanner(os.Stdin)
     129 + for sc.Scan() {
     130 + target := strings.TrimSpace(sc.Text())
     131 + if err := sc.Err(); err == nil && target != "" {
     132 + options.Scan.Inputs = append(options.Scan.Inputs, target)
     133 + }
     134 + }
     135 + }
    128 136  }
    129 137   
    130 138  // DBInit init database connection
    131 139  func DBInit() {
    132  - //var err error
    133  - _, err := database.InitDB(options)
    134  - if err != nil {
    135  - // simple retry
    136  - _, err = database.InitDB(options)
    137  - if err != nil {
    138  - fmt.Printf("[panic] Can't connect to DB at %v\n", options.Server.DBPath)
    139  - os.Exit(-1)
    140  - }
    141  - }
     140 + //var err error
     141 + _, err := database.InitDB(options)
     142 + if err != nil {
     143 + // simple retry
     144 + _, err = database.InitDB(options)
     145 + if err != nil {
     146 + fmt.Printf("[panic] Can't connect to DB at %v\n", options.Server.DBPath)
     147 + os.Exit(-1)
     148 + }
     149 + }
    142 150  }
    143 151   
  • ■ ■ ■ ■ ■ ■
    cmd/scan.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "github.com/fatih/color"
    5  - "github.com/j3ssie/osmedeus/core"
    6  - "github.com/j3ssie/osmedeus/libs"
    7  - "github.com/j3ssie/osmedeus/utils"
    8  - "github.com/panjf2000/ants"
    9  - "github.com/spf13/cobra"
    10  - "strings"
    11  - "sync"
     4 + "github.com/fatih/color"
     5 + "github.com/j3ssie/osmedeus/core"
     6 + "github.com/j3ssie/osmedeus/libs"
     7 + "github.com/j3ssie/osmedeus/utils"
     8 + "github.com/panjf2000/ants"
     9 + "github.com/spf13/cobra"
     10 + "golang.org/x/text/cases"
     11 + "golang.org/x/text/language"
     12 + "strings"
     13 + "sync"
    12 14  )
    13 15   
    14 16  func init() {
    15  - var scanCmd = &cobra.Command{
    16  - Use: "scan",
    17  - Short: "Do Scan based on predefined flow",
    18  - Long: core.Banner(),
    19  - RunE: runScan,
    20  - }
     17 + var scanCmd = &cobra.Command{
     18 + Use: "scan",
     19 + Short: "Do Scan based on predefined flow",
     20 + Long: core.Banner(),
     21 + RunE: runScan,
     22 + }
    21 23   
    22  - scanCmd.Flags().StringSliceVarP(&options.Scan.Modules, "module", "m", []string{}, "Target to running")
    23  - scanCmd.Flags().StringVarP(&options.Scan.Flow, "flow", "f", "general", "Flow name for running (default: general)")
    24  - scanCmd.Flags().StringVarP(&options.Scan.CustomWorkspace, "workspace", "w", "", "Name of workspace (default is same as target)")
    25  - scanCmd.Flags().StringSliceVarP(&options.Scan.Params, "params", "p", []string{}, "Custom params -p='foo=bar' (Multiple -p flags are accepted)")
    26  - scanCmd.SetHelpFunc(ScanHelp)
    27  - RootCmd.AddCommand(scanCmd)
     24 + scanCmd.SetHelpFunc(ScanHelp)
     25 + RootCmd.AddCommand(scanCmd)
    28 26  }
    29 27   
    30 28  func runScan(_ *cobra.Command, _ []string) error {
    31  - DBInit()
    32  - utils.GoodF("%v %v by %v", strings.Title(libs.BINARY), libs.VERSION, libs.AUTHOR)
    33  - utils.GoodF("Store log file to: %v", options.LogFile)
     29 + DBInit()
     30 + utils.GoodF("%v %v by %v", cases.Title(language.Und, cases.NoLower).String(libs.BINARY), libs.VERSION, color.HiMagentaString(libs.AUTHOR))
     31 + utils.InforF("Storing the log file to: %v", color.CyanString(options.LogFile))
    34 32   
    35  - var wg sync.WaitGroup
    36  - p, _ := ants.NewPoolWithFunc(options.Concurrency, func(i interface{}) {
    37  - // really start to scan
    38  - CreateRunner(i)
    39  - wg.Done()
    40  - }, ants.WithPreAlloc(true))
    41  - defer p.Release()
     33 + var wg sync.WaitGroup
     34 + p, _ := ants.NewPoolWithFunc(options.Concurrency, func(i interface{}) {
     35 + // really start to scan
     36 + CreateRunner(i)
     37 + wg.Done()
     38 + }, ants.WithPreAlloc(true))
     39 + defer p.Release()
    42 40   
    43  - if options.Cloud.EnableChunk {
    44  - for _, target := range options.Scan.Inputs {
    45  - chunkTargets := HandleChunksInputs(target)
    46  - for _, chunkTarget := range chunkTargets {
    47  - wg.Add(1)
    48  - _ = p.Invoke(chunkTarget)
    49  - }
    50  - }
    51  - } else {
    52  - for _, target := range options.Scan.Inputs {
    53  - wg.Add(1)
    54  - _ = p.Invoke(strings.TrimSpace(target))
    55  - }
    56  - }
     41 + if options.Cloud.EnableChunk {
     42 + for _, target := range options.Scan.Inputs {
     43 + chunkTargets := HandleChunksInputs(target)
     44 + for _, chunkTarget := range chunkTargets {
     45 + wg.Add(1)
     46 + _ = p.Invoke(chunkTarget)
     47 + }
     48 + }
     49 + } else {
     50 + for _, target := range options.Scan.Inputs {
     51 + wg.Add(1)
     52 + _ = p.Invoke(strings.TrimSpace(target))
     53 + }
     54 + }
    57 55   
    58  - wg.Wait()
    59  - return nil
     56 + wg.Wait()
     57 + return nil
    60 58  }
    61 59   
    62 60  func CreateRunner(j interface{}) {
    63  - target := j.(string)
    64  - if core.IsRootDomain(target) && options.Scan.Flow == "general" {
    65  - utils.WarnF("looks like you scanning a subdomain '%s' with general flow. The result might be much less than usual", color.HiCyanString(target))
    66  - utils.WarnF("Better input should be root domain with TLD like '-t target.com'")
    67  - }
     61 + target := j.(string)
     62 + if core.IsRootDomain(target) && options.Scan.Flow == "general" {
     63 + utils.WarnF("looks like you scanning a subdomain '%s' with general flow. The result might be much less than usual", color.HiCyanString(target))
     64 + utils.WarnF("Better input should be root domain with TLD like '-t target.com'")
     65 + }
    68 66   
    69  - runner, err := core.InitRunner(target, options)
    70  - if err != nil {
    71  - utils.ErrorF("Error init runner with: %s", target)
    72  - return
    73  - }
    74  - runner.Start()
     67 + runner, err := core.InitRunner(target, options)
     68 + if err != nil {
     69 + utils.ErrorF("Error init runner with: %s", target)
     70 + return
     71 + }
     72 + runner.Start()
    75 73  }
    76 74   
  • ■ ■ ■ ■ ■ ■
    cmd/server.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
     4 + "fmt"
    5 5   
    6  - "github.com/j3ssie/osmedeus/core"
    7  - "github.com/j3ssie/osmedeus/server"
    8  - "github.com/spf13/cobra"
     6 + "github.com/j3ssie/osmedeus/core"
     7 + "github.com/j3ssie/osmedeus/server"
     8 + "github.com/spf13/cobra"
    9 9  )
    10 10   
    11 11  func init() {
    12  - var serverCmd = &cobra.Command{
    13  - Use: "server",
    14  - Short: "Start Web Server",
    15  - Long: core.Banner(),
    16  - RunE: runServer,
    17  - }
    18  - serverCmd.Flags().String("host", "0.0.0.0", "IP address to bind the server")
    19  - serverCmd.Flags().String("port", "8000", "Port")
    20  - serverCmd.Flags().IntVar(&options.Server.PollingTime, "poll-time", 60, "Polling time to check next task")
    21  - serverCmd.Flags().BoolVar(&options.Server.DisableSSL, "disable-ssl", false, "Disable workspaces directory listing")
    22  - serverCmd.Flags().BoolVar(&options.Server.DisableWorkspaceListing, "disable-listing", false, "Disable workspaces directtory listing")
    23  - serverCmd.Flags().BoolVar(&options.Server.PreFork, "prefork", false, "Enable Prefork mode for api server")
    24  - RootCmd.AddCommand(serverCmd)
     12 + var serverCmd = &cobra.Command{
     13 + Use: "server",
     14 + Short: "Start Web Server",
     15 + Long: core.Banner(),
     16 + RunE: runServer,
     17 + }
     18 + serverCmd.Flags().String("host", "0.0.0.0", "IP address to bind the server")
     19 + serverCmd.Flags().String("port", "8000", "Port")
     20 + serverCmd.Flags().IntVar(&options.Server.PollingTime, "poll-time", 60, "Polling time to check next task")
     21 + serverCmd.Flags().BoolVar(&options.Server.DisableSSL, "disable-ssl", false, "Disable workspaces directory listing")
     22 + serverCmd.Flags().BoolVar(&options.Server.DisableWorkspaceListing, "disable-listing", false, "Disable workspaces directtory listing")
     23 + serverCmd.Flags().BoolVar(&options.Server.PreFork, "prefork", false, "Enable Prefork mode for the api server")
     24 + serverCmd.Flags().BoolVar(&options.Server.NoAuthen, "no-auth", false, "Disable authentication for the api server")
     25 + RootCmd.AddCommand(serverCmd)
    25 26  }
    26 27   
    27 28  func runServer(cmd *cobra.Command, _ []string) error {
    28  - host, _ := cmd.Flags().GetString("host")
    29  - port, _ := cmd.Flags().GetString("port")
    30  - options.Server.Bind = fmt.Sprintf("%v:%v", host, port)
    31  - DBInit()
     29 + host, _ := cmd.Flags().GetString("host")
     30 + port, _ := cmd.Flags().GetString("port")
     31 + options.Server.Bind = fmt.Sprintf("%v:%v", host, port)
     32 + DBInit()
    32 33   
    33  - server.StartServer(options)
    34  - return nil
     34 + server.StartServer(options)
     35 + return nil
    35 36  }
    36 37   
  • ■ ■ ■ ■ ■ ■
    cmd/update.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "github.com/j3ssie/osmedeus/core"
    5  - "github.com/j3ssie/osmedeus/utils"
    6  - "github.com/spf13/cobra"
     4 + "github.com/j3ssie/osmedeus/core"
     5 + "github.com/j3ssie/osmedeus/utils"
     6 + "github.com/spf13/cobra"
    7 7  )
    8 8   
    9 9  func init() {
    10  - var updateCmd = &cobra.Command{
    11  - Use: "update",
    12  - Short: "Check latest Update",
    13  - Long: core.Banner(),
    14  - RunE: runUpdate,
    15  - }
    16  - updateCmd.Flags().String("meta", "", "Custom MetaData URL")
    17  - updateCmd.Flags().BoolVar(&options.Update.ForceUpdate, "force", false, "Force Update")
    18  - updateCmd.Flags().BoolVar(&options.Update.CleanOldData, "clean", false, "Clean Old Data")
    19  - updateCmd.Flags().BoolVar(&options.Update.VulnUpdate, "vuln", false, "Update Vulnerability Database only")
    20  - // generate update meta data
    21  - updateCmd.Flags().StringVar(&options.Update.GenerateMeta, "gen", "", "Generate metadata for update")
    22  - RootCmd.AddCommand(updateCmd)
     10 + var updateCmd = &cobra.Command{
     11 + Use: "update",
     12 + Short: "Check latest Update",
     13 + Long: core.Banner(),
     14 + RunE: runUpdate,
     15 + }
     16 + updateCmd.Flags().String("meta", "", "Custom MetaData URL")
     17 + updateCmd.Flags().BoolVar(&options.Update.ForceUpdate, "force", false, "Force Update")
     18 + updateCmd.Flags().BoolVar(&options.Update.CleanOldData, "clean", false, "Clean Old Data")
     19 + updateCmd.Flags().BoolVar(&options.Update.VulnUpdate, "vuln", false, "Update Vulnerability Database only")
     20 + // generate update meta data
     21 + updateCmd.Flags().StringVar(&options.Update.GenerateMeta, "gen", "", "Generate metadata for update")
     22 + RootCmd.AddCommand(updateCmd)
    23 23  }
    24 24   
    25 25  func runUpdate(cmd *cobra.Command, _ []string) error {
    26  - meta, _ := cmd.Flags().GetString("meta")
    27  - if meta != "" {
    28  - options.Update.MetaDataURL = meta
    29  - }
     26 + meta, _ := cmd.Flags().GetString("meta")
     27 + if meta != "" {
     28 + options.Update.MetaDataURL = meta
     29 + }
    30 30   
    31  - if options.Update.GenerateMeta != "" {
    32  - core.GenerateMetaData(options)
    33  - return nil
    34  - }
     31 + if options.Update.GenerateMeta != "" {
     32 + core.GenerateMetaData(options)
     33 + return nil
     34 + }
    35 35   
    36  - if options.Update.VulnUpdate {
    37  - core.UpdateVuln(options)
    38  - return nil
    39  - }
     36 + if options.Update.VulnUpdate {
     37 + core.UpdateVuln(options)
     38 + return nil
     39 + }
    40 40   
    41  - var shouldUpdate bool
    42  - options.Update.UpdateURL = core.GetUpdateURL(options)
     41 + var shouldUpdate bool
     42 + options.Update.UpdateURL = core.GetUpdateURL(options)
    43 43   
    44  - if options.Update.ForceUpdate {
    45  - shouldUpdate = true
    46  - utils.InforF("Force to Update latest release")
    47  - } else {
    48  - shouldUpdate = core.CheckUpdate(&options)
    49  - }
     44 + if options.Update.ForceUpdate {
     45 + shouldUpdate = true
     46 + utils.InforF("Force to Update latest release")
     47 + } else {
     48 + shouldUpdate = core.CheckUpdate(&options)
     49 + }
    50 50   
    51  - if shouldUpdate {
    52  - err := core.RunUpdate(options)
    53  - if err != nil {
    54  - return err
    55  - }
    56  - }
     51 + if shouldUpdate {
     52 + err := core.RunUpdate(options)
     53 + if err != nil {
     54 + return err
     55 + }
     56 + }
    57 57   
    58  - return nil
     58 + return nil
    59 59  }
    60 60   
  • ■ ■ ■ ■ ■ ■
    cmd/usage.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/fatih/color"
    6  - "github.com/j3ssie/osmedeus/core"
    7  - "github.com/j3ssie/osmedeus/libs"
    8  - "github.com/spf13/cobra"
     4 + "fmt"
     5 + "github.com/fatih/color"
     6 + "github.com/j3ssie/osmedeus/core"
     7 + "github.com/j3ssie/osmedeus/libs"
     8 + "github.com/spf13/cobra"
    9 9  )
    10 10   
    11 11  // RootUsage base help
    12 12  func RootUsage() {
    13  - var h string
    14  - h += ScanUsage()
    15  - h += CloudUsage()
    16  - h += UtilsUsage()
     13 + var h string
     14 + h += ScanUsage()
     15 + h += CloudUsage()
     16 + h += QueueUsage()
     17 + h += ReportUsage()
     18 + h += UtilsUsage()
    17 19   
    18  - fmt.Println(h)
     20 + fmt.Println(h)
    19 21  }
    20 22   
    21 23  func ScanUsage() string {
    22  - h := color.HiCyanString("Example Scan Commands:")
    23  - h += `
     24 + h := color.HiCyanString("Example Scan Commands:")
     25 + h += `
    24 26   ## Start a simple scan with default 'general' flow
    25 27   osmedeus scan -t sample.com
    26 28  
    skipped 26 lines
    53 55   ## Start the scan with your custom workflow folder
    54 56   osmedeus scan --wfFolder ~/custom-workflow/ -f your-custom-workflow -t sample.com
    55 57   
    56  - ## Start the scan with chunkk inputs to review the output way more much faster
     58 + ## Start the scan with chunk inputs to review the output way more much faster
    57 59   osmedeus scan --chunk --chunk-parts 20 -f cidr -t list-of-100-cidr.txt
    58 60   
    59 61   ## Continuously run the scan on a target right after it finished
    60 62   osmedeus utils cron --for --cmd 'osmedeus scan -t example.com'
    61 63   `
    62  - h += color.HiCyanString("\nScan Usage:\n")
    63  - h += " osmedeus scan -f [flowName] -t [target] \n"
    64  - h += " osmedeus scan -m [modulePath] -T [targetsFile] \n"
    65  - h += " osmedeus scan -f /path/to/flow.yaml -t [target] \n"
    66  - h += " osmedeus scan -m /path/to/module.yaml -t [target] --params 'port=9200'\n"
    67  - h += " osmedeus scan -m /path/to/module.yaml -t [target] -l /tmp/log.log\n"
    68  - h += " cat targets | osmedeus scan -f sample\n"
     64 + h += color.HiCyanString("\nScan Usage:\n")
     65 + h += " osmedeus scan -f [flowName] -t [target] \n"
     66 + h += " osmedeus scan -m [modulePath] -T [targetsFile] \n"
     67 + h += " osmedeus scan -f /path/to/flow.yaml -t [target] \n"
     68 + h += " osmedeus scan -m /path/to/module.yaml -t [target] --params 'port=9200'\n"
     69 + h += " osmedeus scan -m /path/to/module.yaml -t [target] -l /tmp/log.log\n"
     70 + h += " cat targets | osmedeus scan -f sample\n"
    69 71   
    70  - h += color.HiCyanString("\nPractical Scan Usage:\n")
    71  - h += " osmedeus scan -T list_of_targets.txt -W custom_workspaces\n"
    72  - h += " osmedeus scan -t target.com -w workspace_name --debug\n"
    73  - h += " osmedeus scan -f general -t sample.com\n"
    74  - h += " osmedeus scan -f extensive -t sample.com -t another.com\n"
    75  - h += " cat list_of_urls.txt | osmedeus scan -f urls\n"
    76  - h += " osmedeus scan -m ~/.osmedeus/core/workflow/test/dirbscan.yaml -t list_of_urls.txt\n"
    77  - h += " osmedeus scan --wfFolder ~/custom-workflow/ -f your-custom-workflow -t list_of_urls.txt\n"
    78  - h += " osmedeus scan --chunk --chunk-part 40 -c 2 -f cidr -t list-of-cidr.txt\n"
     72 + h += color.HiCyanString("\nPractical Scan Usage:\n")
     73 + h += " osmedeus scan -T list_of_targets.txt -W custom_workspaces\n"
     74 + h += " osmedeus scan -t target.com -w workspace_name --debug\n"
     75 + h += " osmedeus scan -f general -t sample.com\n"
     76 + h += " osmedeus scan -f extensive -t sample.com -t another.com\n"
     77 + h += " cat list_of_urls.txt | osmedeus scan -f urls\n"
     78 + h += " osmedeus scan -m ~/.osmedeus/core/workflow/test/dirbscan.yaml -t list_of_urls.txt\n"
     79 + h += " osmedeus scan --wfFolder ~/custom-workflow/ -f your-custom-workflow -t list_of_urls.txt\n"
     80 + h += " osmedeus scan --chunk --chunk-part 40 -c 2 -f cidr -t list-of-cidr.txt\n"
    79 81   
    80  - return h
     82 + return h
    81 83  }
    82 84   
    83 85  func UtilsUsage() string {
    84  - h := color.HiCyanString("\nUtilities Usage:\n")
    85  - h += " osmedeus health \n"
    86  - h += " osmedeus health git\n"
    87  - h += " osmedeus health cloud\n"
    88  - h += " osmedeus version --json \n"
    89  - h += " osmedeus update \n"
    90  - h += " osmedeus update --vuln\n"
    91  - h += " osmedeus update --force --clean \n"
    92  - h += " osmedeus utils tmux ls \n"
    93  - h += " osmedeus utils tmux logs -A -l 10 \n"
    94  - h += " osmedeus utils ps \n"
    95  - h += " osmedeus utils ps --proc 'jaeles' \n"
    96  - h += " osmedeus utils cron --cmd 'osmdeus scan -t example.com' --sch 60\n"
    97  - h += " osmedeus utils cron --for --cmd 'osmedeus scan -t example.com'\n"
    98  - return h
     86 + h := color.HiCyanString("\nUtilities Usage:\n")
     87 + h += " osmedeus health \n"
     88 + h += " osmedeus health git\n"
     89 + h += " osmedeus health cloud\n"
     90 + h += " osmedeus version --json \n"
     91 + h += " osmedeus update \n"
     92 + h += " osmedeus update --vuln\n"
     93 + h += " osmedeus update --force --clean \n"
     94 + h += " osmedeus utils tmux ls \n"
     95 + h += " osmedeus utils tmux logs -A -l 10 \n"
     96 + h += " osmedeus utils ps \n"
     97 + h += " osmedeus utils ps --proc 'jaeles' \n"
     98 + h += " osmedeus utils cron --cmd 'osmdeus scan -t example.com' --sch 60\n"
     99 + h += " osmedeus utils cron --for --cmd 'osmedeus scan -t example.com'\n"
     100 + return h
    99 101  }
    100 102   
    101 103  func ConfigUsage() string {
    102  - h := color.HiCyanString("\nConfig Usage:\n")
    103  - h += " osmedeus config [action] [OPTIONS] \n"
    104  - h += " osmedeus config init -p https://github.com/j3ssie/osmedeus-plugins\n"
    105  - h += " osmedeus config --user newusser --pass newpassword\n"
    106  - h += " osmedeus config reload \n"
    107  - h += " osmedeus config clean \n"
    108  - h += " osmedeus config delete -t woskapce \n"
    109  - h += " osmedeus config delete -w workspace_name \n"
    110  - return h
     104 + h := color.HiCyanString("\nConfig Usage:\n")
     105 + h += " osmedeus config [action] [OPTIONS] \n"
     106 + h += " osmedeus config init -p https://github.com/j3ssie/osmedeus-plugins\n"
     107 + h += " osmedeus config --user newusser --pass newpassword\n"
     108 + h += " osmedeus config reload \n"
     109 + h += " osmedeus config clean \n"
     110 + h += " osmedeus config delete -t woskapce \n"
     111 + h += " osmedeus config delete -w workspace_name \n"
     112 + return h
     113 +}
     114 + 
     115 +func QueueUsage() string {
     116 + h := color.HiCyanString("\nQueue Usage:\n")
     117 + h += " osmedeus queue -Q /tmp/queue-file.txt -c 2\n"
     118 + h += " osmedeus queue --add -t example.com -Q /tmp/queue-file.txt \n"
     119 + return h
     120 +}
     121 + 
     122 +func QueueHelp(cmd *cobra.Command, _ []string) {
     123 + fmt.Println(core.Banner())
     124 + fmt.Println(cmd.UsageString())
     125 + h := QueueUsage()
     126 + fmt.Println(h)
     127 + printDocs()
    111 128  }
    112 129   
    113 130  func CloudUsage() string {
    114  - h := color.HiCyanString("\nProvider Usage:\n")
    115  - h += " osmedeus provider wizard \n"
    116  - h += " osmedeus provider validate \n"
    117  - h += " osmedeus provider build --token xxx --rebuild --ic\n"
    118  - h += " osmedeus provider create --name 'sample' \n"
    119  - h += " osmedeus provider health --debug \n"
    120  - h += " osmedeus provider list \n"
    121  - h += " osmedeus provider delete --id 34317111 --id 34317112 \n"
     131 + h := color.HiCyanString("\nProvider Usage:\n")
     132 + h += " osmedeus provider wizard \n"
     133 + h += " osmedeus provider validate \n"
     134 + h += " osmedeus provider build --token xxx --rebuild --ic\n"
     135 + h += " osmedeus provider create --name 'sample' \n"
     136 + h += " osmedeus provider health --debug \n"
     137 + h += " osmedeus provider list \n"
     138 + h += " osmedeus provider delete --id 34317111 --id 34317112 \n"
    122 139   
    123  - h += color.HiCyanString("\nCloud Usage:\n")
    124  - h += " osmedeus cloud -f [flowName] -t [target] \n"
    125  - h += " osmedeus cloud -m [modulePath] -t [target] \n"
    126  - h += " osmedeus cloud -c 10 -f [flowName] -T [targetsFile] \n"
    127  - h += " osmedeus cloud --token xxx -G -c 10 -f [flowName] -T [targetsFile] \n"
    128  - h += " osmedeus cloud --chunk -c 10 -f [flowName] -t [targetsFile] \n"
     140 + h += color.HiCyanString("\nCloud Usage:\n")
     141 + h += " osmedeus cloud -f [flowName] -t [target] \n"
     142 + h += " osmedeus cloud -m [modulePath] -t [target] \n"
     143 + h += " osmedeus cloud -c 10 -f [flowName] -T [targetsFile] \n"
     144 + h += " osmedeus cloud --token xxx -G -c 10 -f [flowName] -T [targetsFile] \n"
     145 + h += " osmedeus cloud --chunk -c 10 -f [flowName] -t [targetsFile] \n"
    129 146   
    130  - return h
     147 + return h
    131 148  }
    132 149   
    133 150  func ReportUsage() string {
    134  - h := color.HiCyanString("\nReport Usage:\n")
    135  - h += " osmedeus report list\n"
    136  - h += " osmedeus report view --raw -t target.com\n"
    137  - h += " osmedeus report view --static -t target.com\n"
    138  - h += " osmedeus report view --static --ip 0 -t target.com\n"
    139  - return h
     151 + h := color.HiCyanString("\nReport Usage:\n")
     152 + h += " osmedeus report list\n"
     153 + h += " osmedeus report extract -t target.com.tar.gz\n"
     154 + h += " osmedeus report extract -t target.com.tar.gz --dest .\n"
     155 + h += " osmedeus report view --raw -t target.com\n"
     156 + h += " osmedeus report view --static -t target.com\n"
     157 + h += " osmedeus report view --static --ip 0 -t target.com\n"
     158 + return h
    140 159  }
    141 160   
    142 161  // ScanHelp scan help message
    143 162  func ScanHelp(cmd *cobra.Command, _ []string) {
    144  - fmt.Println(core.Banner())
    145  - fmt.Println(cmd.UsageString())
    146  - h := ScanUsage()
    147  - fmt.Println(h)
    148  - printDocs()
     163 + fmt.Println(core.Banner())
     164 + fmt.Println(cmd.UsageString())
     165 + h := ScanUsage()
     166 + fmt.Println(h)
     167 + printDocs()
    149 168  }
    150 169   
    151 170  // CloudHelp scan help message
    152 171  func CloudHelp(cmd *cobra.Command, _ []string) {
    153  - fmt.Println(core.Banner())
    154  - fmt.Println(cmd.UsageString())
    155  - h := CloudUsage()
    156  - fmt.Println(h)
    157  - printDocs()
     172 + fmt.Println(core.Banner())
     173 + fmt.Println(cmd.UsageString())
     174 + h := CloudUsage()
     175 + fmt.Println(h)
     176 + printDocs()
    158 177  }
    159 178   
    160 179  // ConfigHelp config help message
    161 180  func ConfigHelp(cmd *cobra.Command, _ []string) {
    162  - fmt.Println(core.Banner())
    163  - fmt.Println(cmd.UsageString())
    164  - h := ConfigUsage()
    165  - fmt.Println(h)
    166  - printDocs()
     181 + fmt.Println(core.Banner())
     182 + fmt.Println(cmd.UsageString())
     183 + h := ConfigUsage()
     184 + fmt.Println(h)
     185 + printDocs()
    167 186  }
    168 187   
    169 188  // UtilsHelp utils help message
    170 189  func UtilsHelp(cmd *cobra.Command, _ []string) {
    171  - fmt.Println(core.Banner())
    172  - fmt.Println(cmd.UsageString())
    173  - h := UtilsUsage()
    174  - fmt.Println(h)
    175  - printDocs()
     190 + fmt.Println(core.Banner())
     191 + fmt.Println(cmd.UsageString())
     192 + h := UtilsUsage()
     193 + fmt.Println(h)
     194 + printDocs()
    176 195  }
    177 196   
    178 197  // ReportHelp utils help message
    179 198  func ReportHelp(cmd *cobra.Command, _ []string) {
    180  - fmt.Println(core.Banner())
    181  - fmt.Println(cmd.UsageString())
    182  - h := ReportUsage()
    183  - fmt.Println(h)
    184  - printDocs()
     199 + fmt.Println(core.Banner())
     200 + fmt.Println(cmd.UsageString())
     201 + h := ReportUsage()
     202 + fmt.Println(h)
     203 + printDocs()
    185 204  }
    186 205   
    187 206  // RootHelp print help message
    188 207  func RootHelp(cmd *cobra.Command, _ []string) {
    189  - fmt.Println(core.Banner())
    190  - fmt.Println(cmd.UsageString())
    191  - RootUsage()
    192  - printDocs()
     208 + fmt.Println(core.Banner())
     209 + fmt.Println(cmd.UsageString())
     210 + RootUsage()
     211 + printDocs()
    193 212  }
    194 213   
    195 214  func printDocs() {
    196  - fmt.Printf("�� Documentation can be found here: %s\n", color.GreenString(libs.DOCS))
     215 + fmt.Printf("�� Documentation can be found here: %s\n", color.GreenString(libs.DOCS))
    197 216  }
    198 217   
  • ■ ■ ■ ■ ■ ■
    cmd/utils.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/fatih/color"
    6  - "github.com/j3ssie/osmedeus/core"
    7  - "github.com/j3ssie/osmedeus/execution"
    8  - "github.com/j3ssie/osmedeus/libs"
    9  - jsoniter "github.com/json-iterator/go"
    10  - "github.com/spf13/cobra"
     4 + "fmt"
     5 + "github.com/fatih/color"
     6 + "github.com/j3ssie/osmedeus/core"
     7 + "github.com/j3ssie/osmedeus/execution"
     8 + "github.com/j3ssie/osmedeus/libs"
     9 + "github.com/j3ssie/osmedeus/utils"
     10 + jsoniter "github.com/json-iterator/go"
     11 + "github.com/spf13/cobra"
    11 12  )
    12 13   
    13 14  func init() {
    14  - var utilsCmd = &cobra.Command{
    15  - Use: "utils",
    16  - Short: "Utils to get some information from the system",
    17  - Long: core.Banner(),
    18  - RunE: runProvider,
    19  - }
     15 + var utilsCmd = &cobra.Command{
     16 + Use: "utils",
     17 + Short: "Utils to get some information from the system",
     18 + Long: core.Banner(),
     19 + RunE: runProvider,
     20 + }
    20 21   
    21  - var psCmd = &cobra.Command{
    22  - Use: "ps",
    23  - Short: "Utility to get information about running process",
    24  - Long: core.Banner(),
    25  - RunE: runPs,
    26  - }
    27  - psCmd.Flags().StringSlice("proc", []string{}, "Process name")
     22 + var psCmd = &cobra.Command{
     23 + Use: "ps",
     24 + Short: "Utility to get information about running process",
     25 + Long: core.Banner(),
     26 + RunE: runPs,
     27 + }
     28 + psCmd.Flags().StringSlice("proc", []string{}, "Process name")
     29 + psCmd.Flags().Bool("kill", false, "Kill the process")
     30 + psCmd.Flags().Bool("osm", false, "Osmedeus related process only")
    28 31   
    29  - var tmuxCmd = &cobra.Command{
    30  - Use: "tmux",
    31  - Short: "Utility to get info from tmux",
    32  - Long: core.Banner(),
    33  - RunE: runTmux,
    34  - }
     32 + var tmuxCmd = &cobra.Command{
     33 + Use: "tmux",
     34 + Short: "Utility to get info from tmux",
     35 + Long: core.Banner(),
     36 + RunE: runTmux,
     37 + }
    35 38   
    36  - tmuxCmd.Flags().BoolVarP(&options.Tmux.ApplyAll, "all", "A", false, "Apply for all tmux sessions")
    37  - tmuxCmd.Flags().StringVarP(&options.Tmux.SelectedWindow, "name", "n", "", "Apply for all tmux sessions")
    38  - tmuxCmd.Flags().StringVarP(&options.Tmux.Exclude, "exclude", "e", "server", "Exclude tmux session")
    39  - tmuxCmd.Flags().IntVarP(&options.Tmux.Limit, "limit", "l", 0, "Size of output content")
     39 + tmuxCmd.Flags().BoolVarP(&options.Tmux.ApplyAll, "all", "A", false, "Apply for all tmux sessions")
     40 + tmuxCmd.Flags().StringVarP(&options.Tmux.SelectedWindow, "name", "n", "", "Apply for all tmux sessions")
     41 + tmuxCmd.Flags().StringVarP(&options.Tmux.Exclude, "exclude", "e", "server", "Exclude tmux session")
     42 + tmuxCmd.Flags().IntVarP(&options.Tmux.Limit, "limit", "l", 0, "Size of output content")
    40 43   
    41  - var cronCmd = &cobra.Command{
    42  - Use: "cron",
    43  - Short: "Utility to run command schedule",
    44  - Long: core.Banner(),
    45  - RunE: runCron,
    46  - }
    47  - cronCmd.Flags().IntVar(&options.Cron.Schedule, "sch", 0, "Number of minutes to schedule the job")
    48  - cronCmd.Flags().BoolVar(&options.Cron.Forever, "for", false, "Keep running forever right after the command done")
    49  - cronCmd.Flags().StringVar(&options.Cron.Command, "cmd", "", "Command to run")
     44 + var cronCmd = &cobra.Command{
     45 + Use: "cron",
     46 + Short: "Utility to run command schedule",
     47 + Long: core.Banner(),
     48 + RunE: runCron,
     49 + }
     50 + cronCmd.Flags().IntVar(&options.Cron.Schedule, "sch", 0, "Number of minutes to schedule the job")
     51 + cronCmd.Flags().BoolVar(&options.Cron.Forever, "for", false, "Keep running forever right after the command done")
     52 + cronCmd.Flags().StringVar(&options.Cron.Command, "cmd", "", "Command to run")
    50 53   
    51  - // add command
    52  - utilsCmd.PersistentFlags().BoolVar(&options.JsonOutput, "json", false, "Output as JSON")
    53  - utilsCmd.AddCommand(cronCmd)
    54  - utilsCmd.AddCommand(tmuxCmd)
    55  - utilsCmd.AddCommand(psCmd)
    56  - utilsCmd.SetHelpFunc(UtilsHelp)
    57  - RootCmd.AddCommand(utilsCmd)
     54 + // add command
     55 + utilsCmd.PersistentFlags().BoolVar(&options.JsonOutput, "json", false, "Output as JSON")
     56 + utilsCmd.AddCommand(cronCmd)
     57 + utilsCmd.AddCommand(tmuxCmd)
     58 + utilsCmd.AddCommand(psCmd)
     59 + utilsCmd.SetHelpFunc(UtilsHelp)
     60 + RootCmd.AddCommand(utilsCmd)
    58 61  }
    59 62   
    60 63  func runPs(cmd *cobra.Command, _ []string) error {
    61  - processes, _ := cmd.Flags().GetStringSlice("process")
    62  - if len(processes) == 0 {
    63  - processes = append(processes, libs.BINARY)
    64  - }
     64 + processes, _ := cmd.Flags().GetStringSlice("process")
     65 + osmRelated, _ := cmd.Flags().GetBool("osm")
     66 + killProcess, _ := cmd.Flags().GetBool("kill")
    65 67   
    66  - for _, process := range processes {
    67  - pss := execution.GetOsmProcess(process)
    68  - for _, ps := range pss {
    69  - if options.JsonOutput {
    70  - if data, err := jsoniter.MarshalToString(ps); err == nil {
    71  - fmt.Println(data)
    72  - }
    73  - continue
    74  - }
    75  - fmt.Printf("pid:%v %s %v\n", color.HiCyanString("%v", ps.PID), color.HiMagentaString("--"), ps.Command)
    76  - }
    77  - }
     68 + if osmRelated {
     69 + pids := execution.ListAllOsmedeusProcess()
     70 + for _, pid := range pids {
     71 + if killProcess {
     72 + utils.RunOSCommand(fmt.Sprintf("kill -9 %d", pid))
     73 + }
     74 + }
     75 + return nil
     76 + }
     77 + 
     78 + if len(processes) == 0 {
     79 + processes = append(processes, libs.BINARY)
     80 + }
    78 81   
    79  - return nil
     82 + for _, process := range processes {
     83 + pss := execution.GetOsmProcess(process)
     84 + for _, ps := range pss {
     85 + if options.JsonOutput {
     86 + if data, err := jsoniter.MarshalToString(ps); err == nil {
     87 + fmt.Println(data)
     88 + }
     89 + continue
     90 + }
     91 + fmt.Printf("pid:%v %s %v\n", color.HiCyanString("%v", ps.PID), color.HiMagentaString("--"), ps.Command)
     92 + }
     93 + }
     94 + 
     95 + return nil
    80 96  }
    81 97   
    82 98  func runTmux(_ *cobra.Command, args []string) error {
    83  - tmux, err := core.InitTmux(options)
    84  - if err != nil {
    85  - return err
    86  - }
     99 + tmux, err := core.InitTmux(options)
     100 + if err != nil {
     101 + return err
     102 + }
    87 103   
    88  - for _, argument := range args {
    89  - switch argument {
    90  - case "l", "ls", "list":
    91  - tmux.ListTmux()
    92  - case "t", "log", "logs", "tai", "tail":
    93  - tmux.CatchSession()
    94  - }
    95  - }
    96  - return nil
     104 + for _, argument := range args {
     105 + switch argument {
     106 + case "l", "ls", "list":
     107 + tmux.ListTmux()
     108 + case "t", "log", "logs", "tai", "tail":
     109 + tmux.CatchSession()
     110 + }
     111 + }
     112 + return nil
    97 113  }
    98 114   
    99 115  func runCron(_ *cobra.Command, _ []string) error {
    100  - if options.Cron.Schedule == 0 && options.Cron.Forever == false {
    101  - return fmt.Errorf("missing '--sche' flag")
    102  - }
    103  - if options.Cron.Forever {
    104  - options.Cron.Schedule = -1
    105  - }
    106  - core.RunCron(options.Cron.Command, options.Cron.Schedule)
    107  - return nil
     116 + if options.Cron.Schedule == 0 && options.Cron.Forever == false {
     117 + return fmt.Errorf("missing '--sche' flag")
     118 + }
     119 + if options.Cron.Forever {
     120 + options.Cron.Schedule = -1
     121 + }
     122 + core.RunCron(options.Cron.Command, options.Cron.Schedule)
     123 + return nil
    108 124  }
    109 125   
  • ■ ■ ■ ■ ■ ■
    cmd/version.go
    1 1  package cmd
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/j3ssie/osmedeus/core"
    6  - "github.com/j3ssie/osmedeus/libs"
    7  - "github.com/j3ssie/osmedeus/utils"
    8  - jsoniter "github.com/json-iterator/go"
    9  - "github.com/mackerelio/go-osstat/cpu"
    10  - "github.com/mackerelio/go-osstat/memory"
    11  - "github.com/spf13/cobra"
    12  - "os"
    13  - "strings"
    14  - "time"
     4 + "fmt"
     5 + "github.com/j3ssie/osmedeus/core"
     6 + "github.com/j3ssie/osmedeus/libs"
     7 + "github.com/j3ssie/osmedeus/utils"
     8 + jsoniter "github.com/json-iterator/go"
     9 + "github.com/mackerelio/go-osstat/cpu"
     10 + "github.com/mackerelio/go-osstat/memory"
     11 + "github.com/spf13/cobra"
     12 + "os"
     13 + "strings"
     14 + "time"
    15 15  )
    16 16   
    17 17  func init() {
    18  - var versionCmd = &cobra.Command{
    19  - Use: "version",
    20  - Short: "Show core version",
    21  - Long: core.Banner(),
    22  - RunE: runVersion,
    23  - }
    24  - versionCmd.Flags().BoolVarP(&options.Verbose, "verbose", "V", false, "Show stat info too")
    25  - versionCmd.Flags().BoolVar(&options.JsonOutput, "json", false, "Output as JSON")
    26  - RootCmd.AddCommand(versionCmd)
     18 + var versionCmd = &cobra.Command{
     19 + Use: "version",
     20 + Short: "Show core version",
     21 + Long: core.Banner(),
     22 + RunE: runVersion,
     23 + }
     24 + versionCmd.Flags().BoolVarP(&options.Verbose, "verbose", "V", false, "Show stat info too")
     25 + versionCmd.Flags().BoolVar(&options.JsonOutput, "json", false, "Output as JSON")
     26 + RootCmd.AddCommand(versionCmd)
    27 27  }
    28 28   
    29 29  func runVersion(_ *cobra.Command, _ []string) error {
    30  - if options.JsonOutput {
    31  - fmt.Println(PrintStat())
    32  - return nil
    33  - }
     30 + if options.JsonOutput {
     31 + fmt.Println(PrintStat())
     32 + return nil
     33 + }
    34 34   
    35  - if !options.Verbose {
    36  - fmt.Printf("osmedeus %s by %s\n", libs.VERSION, libs.AUTHOR)
    37  - } else {
    38  - statInfo := PrintStat()
    39  - fmt.Printf("osmedeus %s by %s -- %s\n", libs.VERSION, libs.AUTHOR, statInfo)
    40  - }
    41  - return nil
     35 + if !options.Verbose {
     36 + fmt.Printf("osmedeus %s by %s\n", libs.VERSION, libs.AUTHOR)
     37 + } else {
     38 + statInfo := PrintStat()
     39 + fmt.Printf("osmedeus %s by %s -- %s\n", libs.VERSION, libs.AUTHOR, statInfo)
     40 + }
     41 + return nil
    42 42  }
    43 43   
    44 44  // StatData overview struct
    45 45  type StatData struct {
    46  - CPU string `json:"cpu"`
    47  - Mem string `json:"mem"`
    48  - Name string `json:"name"`
    49  - Version string `json:"version"`
     46 + CPU string `json:"cpu"`
     47 + Mem string `json:"mem"`
     48 + Name string `json:"name"`
     49 + Version string `json:"version"`
    50 50  }
    51 51   
    52 52  // PrintStat print status
    53 53  func PrintStat() string {
    54  - data := GetStat()
    55  - if data.CPU.Idle == 0.0 {
    56  - return strings.TrimSpace(utils.Emojif(":thought_balloon:", "not responding"))
    57  - }
    58  - var cpu string
    59  - cpuUsage := 100.0 - data.CPU.Idle
    60  - if cpuUsage <= 20.0 {
    61  - cpu = utils.Emojif(":green_circle:", " cpu: %0.2f", cpuUsage)
    62  - } else if (cpuUsage > 20.0) && (cpuUsage <= 50.0) {
    63  - cpu = utils.Emojif(":green_circle:", " cpu: %0.2f", cpuUsage)
    64  - } else if (cpuUsage > 50.0) && (cpuUsage <= 80.0) {
    65  - cpu = utils.Emojif(":orange_circle:", " cpu: %0.2f", cpuUsage)
    66  - } else {
    67  - cpu = utils.Emojif(":red_circle:", " cpu: %0.2f", cpuUsage)
    68  - }
     54 + data := GetStat()
     55 + if data.CPU.Idle == 0.0 {
     56 + return strings.TrimSpace(utils.Emojif(":thought_balloon:", "not responding"))
     57 + }
     58 + var cpu string
     59 + cpuUsage := 100.0 - data.CPU.Idle
     60 + if cpuUsage <= 20.0 {
     61 + cpu = utils.Emojif(":green_circle:", " cpu: %0.2f", cpuUsage)
     62 + } else if (cpuUsage > 20.0) && (cpuUsage <= 50.0) {
     63 + cpu = utils.Emojif(":green_circle:", " cpu: %0.2f", cpuUsage)
     64 + } else if (cpuUsage > 50.0) && (cpuUsage <= 80.0) {
     65 + cpu = utils.Emojif(":orange_circle:", " cpu: %0.2f", cpuUsage)
     66 + } else {
     67 + cpu = utils.Emojif(":red_circle:", " cpu: %0.2f", cpuUsage)
     68 + }
    69 69   
    70  - var mem string
    71  - memUsage := 100.0 - (data.Mem.Free/data.Mem.Total)*100
    72  - if memUsage <= 20.0 {
    73  - mem = utils.Emojif(":green_circle:", " mem: %0.2f", memUsage)
    74  - } else if (memUsage > 20.0) && (memUsage <= 50.0) {
    75  - mem = utils.Emojif(":green_circle:", " mem: %0.2f", memUsage)
    76  - } else if (memUsage > 50.0) && (memUsage <= 80.0) {
    77  - mem = utils.Emojif(":orange_circle:", " mem: %0.2f", memUsage)
    78  - } else {
    79  - mem = utils.Emojif(":red_circle:", " mem: %0.2f", memUsage)
    80  - }
     70 + var mem string
     71 + memUsage := 100.0 - (data.Mem.Free/data.Mem.Total)*100
     72 + if memUsage <= 20.0 {
     73 + mem = utils.Emojif(":green_circle:", " mem: %0.2f", memUsage)
     74 + } else if (memUsage > 20.0) && (memUsage <= 50.0) {
     75 + mem = utils.Emojif(":green_circle:", " mem: %0.2f", memUsage)
     76 + } else if (memUsage > 50.0) && (memUsage <= 80.0) {
     77 + mem = utils.Emojif(":orange_circle:", " mem: %0.2f", memUsage)
     78 + } else {
     79 + mem = utils.Emojif(":red_circle:", " mem: %0.2f", memUsage)
     80 + }
    81 81   
    82  - name, _ := os.Hostname()
    83  - if options.JsonOutput {
    84  - stat := StatData{
    85  - CPU: fmt.Sprintf("%v", cpuUsage),
    86  - Mem: fmt.Sprintf("%v", memUsage),
    87  - Name: name,
    88  - Version: fmt.Sprintf("osmedeus %s by %s", libs.VERSION, libs.AUTHOR),
    89  - }
    90  - if data, err := jsoniter.MarshalToString(stat); err == nil {
    91  - return data
    92  - }
    93  - }
     82 + name, _ := os.Hostname()
     83 + if options.JsonOutput {
     84 + stat := StatData{
     85 + CPU: fmt.Sprintf("%v", cpuUsage),
     86 + Mem: fmt.Sprintf("%v", memUsage),
     87 + Name: name,
     88 + Version: fmt.Sprintf("osmedeus %s by %s", libs.VERSION, libs.AUTHOR),
     89 + }
     90 + if data, err := jsoniter.MarshalToString(stat); err == nil {
     91 + return data
     92 + }
     93 + }
    94 94   
    95  - return fmt.Sprintf("%s: %12s - %s", name, strings.TrimSpace(cpu), strings.TrimSpace(mem))
     95 + return fmt.Sprintf("%s: %12s - %s", name, strings.TrimSpace(cpu), strings.TrimSpace(mem))
    96 96  }
    97 97   
    98 98  type ServerStatData struct {
    99  - CPU struct {
    100  - System float64
    101  - User float64
    102  - Idle float64
    103  - }
    104  - Mem struct {
    105  - Total float64
    106  - Used float64
    107  - Free float64
    108  - Cached float64
    109  - }
     99 + CPU struct {
     100 + System float64
     101 + User float64
     102 + Idle float64
     103 + }
     104 + Mem struct {
     105 + Total float64
     106 + Used float64
     107 + Free float64
     108 + Cached float64
     109 + }
    110 110  }
    111 111   
    112 112  // GetStat get stat data
    113 113  func GetStat() ServerStatData {
    114  - var stat ServerStatData
     114 + var stat ServerStatData
    115 115   
    116  - before, err := cpu.Get()
    117  - if err != nil {
    118  - return stat
    119  - }
    120  - time.Sleep(time.Duration(1) * time.Second)
    121  - after, err := cpu.Get()
    122  - if err != nil {
    123  - return stat
    124  - }
    125  - total := float64(after.Total - before.Total)
    126  - stat.CPU.User = float64(after.User-before.User) / total * 100
    127  - stat.CPU.System = float64(after.System-before.System) / total * 100
    128  - stat.CPU.Idle = float64(after.Idle-before.Idle) / total * 100
    129  - // memory part
    130  - memory, err := memory.Get()
    131  - if err != nil {
    132  - return stat
    133  - }
    134  - stat.Mem.Total = float64(memory.Total+memory.SwapTotal) / (1024 * 1024 * 1024)
    135  - stat.Mem.Used = float64(memory.Used+memory.SwapUsed) / (1024 * 1024 * 1024)
    136  - stat.Mem.Used = float64(memory.Used+memory.SwapUsed) / (1024 * 1024 * 1024)
    137  - stat.Mem.Cached = float64(memory.Cached) / (1024 * 1024 * 1024)
    138  - stat.Mem.Free = float64(memory.Free+memory.SwapFree) / (1024 * 1024 * 1024)
    139  - return stat
     116 + before, err := cpu.Get()
     117 + if err != nil {
     118 + return stat
     119 + }
     120 + time.Sleep(time.Duration(1) * time.Second)
     121 + after, err := cpu.Get()
     122 + if err != nil {
     123 + return stat
     124 + }
     125 + total := float64(after.Total - before.Total)
     126 + stat.CPU.User = float64(after.User-before.User) / total * 100
     127 + stat.CPU.System = float64(after.System-before.System) / total * 100
     128 + stat.CPU.Idle = float64(after.Idle-before.Idle) / total * 100
     129 + // memory part
     130 + memory, err := memory.Get()
     131 + if err != nil {
     132 + return stat
     133 + }
     134 + stat.Mem.Total = float64(memory.Total+memory.SwapTotal) / (1024 * 1024 * 1024)
     135 + stat.Mem.Used = float64(memory.Used+memory.SwapUsed) / (1024 * 1024 * 1024)
     136 + stat.Mem.Used = float64(memory.Used+memory.SwapUsed) / (1024 * 1024 * 1024)
     137 + stat.Mem.Cached = float64(memory.Cached) / (1024 * 1024 * 1024)
     138 + stat.Mem.Free = float64(memory.Free+memory.SwapFree) / (1024 * 1024 * 1024)
     139 + return stat
    140 140  }
    141 141   
  • ■ ■ ■ ■ ■ ■
    core/backup.go
    1 1  package core
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/j3ssie/osmedeus/libs"
    6  - "github.com/j3ssie/osmedeus/utils"
    7  - "os"
    8  - "path"
     4 + "github.com/fatih/color"
     5 + "github.com/j3ssie/osmedeus/execution"
     6 + "github.com/j3ssie/osmedeus/libs"
     7 + "github.com/j3ssie/osmedeus/utils"
     8 + "os"
     9 + "path"
     10 + "strings"
    9 11  )
    10 12   
    11  -func BackupWorkspace(options libs.Options) {
    12  - if !options.EnableBackup {
    13  - return
    14  - }
     13 +func (r *Runner) BackupWorkspace() {
     14 + outputDir := r.Target["Output"]
     15 + dest := path.Join(r.Opt.Env.BackupFolder, r.Target["Workspace"]) + ".tar.gz"
     16 + if utils.FileExists(dest) {
     17 + os.Remove(dest)
     18 + }
    15 19   
    16  - outputDir := options.Scan.ROptions["Output"]
    17  - dest := path.Join(options.Env.BackupFolder, options.Scan.ROptions["Workspace"]) + ".zip"
    18  - if utils.FileExists(dest) {
    19  - os.Remove(dest)
    20  - }
     20 + execution.Compress(dest, outputDir)
     21 + if utils.FileExists(dest) {
     22 + utils.GoodF("Backup workspace save at %s", color.HiMagentaString(dest))
     23 + }
     24 +}
    21 25   
    22  - zipCommand := fmt.Sprintf("zip -9 -q -r %s %s", dest, outputDir)
    23  - utils.RunCmdWithOutput(zipCommand)
    24  - if utils.FileExists(dest) {
    25  - utils.GoodF("Backup workspace save at: %s", dest)
    26  - }
     26 +func ExtractBackup(src string, opt libs.Options) {
     27 + if !utils.FileExists(src) {
     28 + utils.ErrorF("Backup file not found: %s", src)
     29 + return
     30 + }
     31 + 
     32 + target := strings.ReplaceAll(path.Base(src), ".tar.gz", "")
     33 + dest := opt.Report.ExtractFolder
     34 + if !strings.HasSuffix(dest, "/") {
     35 + dest += "/"
     36 + }
     37 + 
     38 + if utils.FolderExists(dest) {
     39 + utils.MakeDir(dest)
     40 + }
     41 + execution.Decompress(dest, src)
     42 + utils.GoodF("Extracting the %v to %s", color.HiCyanString(target), color.HiMagentaString(dest))
    27 43  }
    28 44   
  • ■ ■ ■ ■ ■ ■
    core/banner.go
    1 1  package core
    2 2   
    3 3  import (
    4  - "github.com/fatih/color"
    5  - "github.com/j3ssie/osmedeus/libs"
     4 + "github.com/fatih/color"
     5 + "github.com/j3ssie/osmedeus/libs"
    6 6  )
    7 7   
    8 8  // Banner print ascii banner
    9 9  func Banner() string {
    10  - version := color.HiWhiteString(libs.VERSION)
    11  - author := color.MagentaString(libs.AUTHOR)
    12  - //W := color.HiWhiteString(``)
    13  - b := color.GreenString(``)
     10 + version := color.HiWhiteString(libs.VERSION)
     11 + author := color.MagentaString(libs.AUTHOR)
     12 + //W := color.HiWhiteString(``)
     13 + b := color.GreenString(``)
    14 14   
    15  - b += color.GreenString(`
     15 + b += color.GreenString(`
    16 16  
    17 17   .;1tfLCL1,
    18 18   .,,..;i;f0G;
    skipped 15 lines
    34 34   .,::::::::,.
    35 35   `)
    36 36   
    37  - //
    38  - //
    39  - //b += "\n\t" + color.GreenString(` @@@@@@`)
    40  - //b += "\n\t" + color.GreenString(` .@@' '@@.`)
    41  - //b += "\n\t" + color.GreenString(` :@ @:`)
    42  - //b += "\n\t" + color.GreenString(` :@ %v:@`, W) + color.GreenString(` @:`)
    43  - //b += "\n\t" + color.GreenString(` :@ %v:@`, W) + color.GreenString(` @:`)
    44  - //
    45  - //b += "\n\t" + color.GreenString(` :@ @:`)
    46  - //b += "\n\t" + color.GreenString(` '@@. .@@'`)
    47  - //b += "\n\t" + color.GreenString(` @@@@@@`)
    48  - //b += "\n\t" + color.GreenString(` @@`)
    49  - //b += "\n\t" + color.HiCyanString(` @ `) + color.GreenString(`@@`) + color.HiCyanString(` @`)
    50  - //b += "\n\t" + color.HiWhiteString(` +@@`) + color.GreenString(` @@ `) + color.HiWhiteString(` @@+`)
    51  - //b += "\n\t" + color.GreenString(` @@:@#@,@@,@#@:@@`)
    52  - //b += "\n\t" + color.GreenString(` ;@+@@'#@@@@#'@@+@;`)
    53  - //b += "\n\t" + color.GreenString(` @+ #@@ @@ @@# +@`)
    54  - //b += "\n\t" + color.GreenString(` @@ @+'@@@@@@'+@ @@`)
    55  - //b += "\n\t" + color.GreenString(` @. @ ;@@; @ .@`)
    56  - //b += "\n\t" + color.BlueString(` #@ '@ @; @#`)
     37 + //
     38 + //
     39 + //b += "\n\t" + color.GreenString(` @@@@@@`)
     40 + //b += "\n\t" + color.GreenString(` .@@' '@@.`)
     41 + //b += "\n\t" + color.GreenString(` :@ @:`)
     42 + //b += "\n\t" + color.GreenString(` :@ %v:@`, W) + color.GreenString(` @:`)
     43 + //b += "\n\t" + color.GreenString(` :@ %v:@`, W) + color.GreenString(` @:`)
     44 + //
     45 + //b += "\n\t" + color.GreenString(` :@ @:`)
     46 + //b += "\n\t" + color.GreenString(` '@@. .@@'`)
     47 + //b += "\n\t" + color.GreenString(` @@@@@@`)
     48 + //b += "\n\t" + color.GreenString(` @@`)
     49 + //b += "\n\t" + color.HiCyanString(` @ `) + color.GreenString(`@@`) + color.HiCyanString(` @`)
     50 + //b += "\n\t" + color.HiWhiteString(` +@@`) + color.GreenString(` @@ `) + color.HiWhiteString(` @@+`)
     51 + //b += "\n\t" + color.GreenString(` @@:@#@,@@,@#@:@@`)
     52 + //b += "\n\t" + color.GreenString(` ;@+@@'#@@@@#'@@+@;`)
     53 + //b += "\n\t" + color.GreenString(` @+ #@@ @@ @@# +@`)
     54 + //b += "\n\t" + color.GreenString(` @@ @+'@@@@@@'+@ @@`)
     55 + //b += "\n\t" + color.GreenString(` @. @ ;@@; @ .@`)
     56 + //b += "\n\t" + color.BlueString(` #@ '@ @; @#`)
    57 57   
    58  - b += "\n\n\t" + color.GreenString(` Osmedeus Next Generation %v`, version) + color.GreenString(` by %v`, author)
    59  - b += "\n\n" + color.HiCyanString(` %s`, libs.DESC) + "\n"
    60  - b += "\n" + color.HiWhiteString(` ¯\_(ツ)_/¯`) + "\n\n"
    61  - color.Unset()
    62  - return b
     58 + b += "\n\n\t" + color.GreenString(` Osmedeus Next Generation %v`, version) + color.GreenString(` by %v`, author)
     59 + b += "\n\n" + color.HiCyanString(` %s`, libs.DESC) + "\n"
     60 + b += "\n" + color.HiWhiteString(` ¯\_(ツ)_/¯`) + "\n\n"
     61 + color.Unset()
     62 + return b
    63 63  }
    64 64   
  • ■ ■ ■ ■ ■ ■
    core/config.go
    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   
  • ■ ■ ■ ■ ■ ■
    core/cron.go
    1 1  package core
    2 2   
    3 3  import (
    4  - "github.com/fatih/color"
    5  - "github.com/j3ssie/osmedeus/utils"
    6  - "github.com/jasonlvhit/gocron"
    7  - "github.com/spf13/cast"
     4 + "github.com/fatih/color"
     5 + "github.com/j3ssie/osmedeus/utils"
     6 + "github.com/jasonlvhit/gocron"
     7 + "github.com/spf13/cast"
    8 8  )
    9 9   
    10 10  func taskWithParams(cmd string) {
    11  - utils.InforF("Exec: %v", color.HiMagentaString(cmd))
    12  - _, err := utils.RunCommandSteamOutput(cmd)
    13  - if err != nil {
    14  - utils.ErrorF("Error running command: %v", err)
    15  - }
     11 + utils.InforF("Exec: %v", color.HiMagentaString(cmd))
     12 + _, err := utils.RunCommandSteamOutput(cmd)
     13 + if err != nil {
     14 + utils.ErrorF("Error running command: %v", err)
     15 + }
    16 16  }
    17 17   
    18 18  func RunCron(cmd string, schedule int) {
    19 19   
    20  - if schedule == -1 {
    21  - utils.InforF("Run command forever: %v", cmd)
    22  - for {
    23  - taskWithParams(cmd)
    24  - }
    25  - }
     20 + if schedule == -1 {
     21 + utils.InforF("Run command forever: %v", cmd)
     22 + for {
     23 + taskWithParams(cmd)
     24 + }
     25 + }
    26 26   
    27  - utils.InforF("Start cron job with %v seconds: %v", schedule, color.HiCyanString(cmd))
    28  - gocron.Every(cast.ToUint64(schedule)).Minutes().Do(taskWithParams, cmd)
    29  - <-gocron.Start()
     27 + utils.InforF("Start cron job with %v seconds: %v", schedule, color.HiCyanString(cmd))
     28 + gocron.Every(cast.ToUint64(schedule)).Minutes().Do(taskWithParams, cmd)
     29 + <-gocron.Start()
    30 30  }
    31 31   
  • ■ ■ ■ ■ ■ ■
    core/db.go
    1 1  package core
    2 2   
    3 3  import (
    4  - "github.com/fatih/color"
    5  - "github.com/j3ssie/osmedeus/database"
    6  - "github.com/j3ssie/osmedeus/libs"
    7  - "github.com/j3ssie/osmedeus/utils"
    8  - jsoniter "github.com/json-iterator/go"
    9  - "github.com/robertkrimen/otto"
    10  - "github.com/spf13/cast"
    11  - "os"
    12  - "path"
    13  - "strings"
     4 + "github.com/fatih/color"
     5 + "github.com/j3ssie/osmedeus/database"
     6 + "github.com/j3ssie/osmedeus/libs"
     7 + "github.com/j3ssie/osmedeus/utils"
     8 + jsoniter "github.com/json-iterator/go"
     9 + "github.com/robertkrimen/otto"
     10 + "github.com/spf13/cast"
     11 + "os"
     12 + "path"
     13 + "strings"
    14 14  )
    15 15   
    16 16  func (r *Runner) LoadDBScripts() string {
    17  - var output string
     17 + var output string
    18 18   
    19  - r.VM.Set(TotalSubdomain, func(call otto.FunctionCall) otto.Value {
    20  - length := utils.FileLength(call.Argument(0).String())
    21  - r.TargetObj.TotalAssets = length
    22  - utils.InforF("Total subdomain found: %v", color.HiMagentaString("%v", length))
    23  - return otto.Value{}
    24  - })
     19 + r.VM.Set(TotalSubdomain, func(call otto.FunctionCall) otto.Value {
     20 + length := utils.FileLength(call.Argument(0).String())
     21 + r.TargetObj.TotalAssets = length
     22 + utils.InforF("Total subdomain found: %v", color.HiMagentaString("%v", length))
     23 + return otto.Value{}
     24 + })
    25 25   
    26  - r.VM.Set(TotalDns, func(call otto.FunctionCall) otto.Value {
    27  - length := utils.FileLength(call.Argument(0).String())
    28  - r.TargetObj.TotalDns = length
    29  - utils.InforF("Total Dns: %v", color.HiMagentaString("%v", length))
    30  - return otto.Value{}
    31  - })
     26 + r.VM.Set(TotalDns, func(call otto.FunctionCall) otto.Value {
     27 + length := utils.FileLength(call.Argument(0).String())
     28 + r.TargetObj.TotalDns = length
     29 + utils.InforF("Total Dns: %v", color.HiMagentaString("%v", length))
     30 + return otto.Value{}
     31 + })
    32 32   
    33  - r.VM.Set(TotalScreenShot, func(call otto.FunctionCall) otto.Value {
    34  - length := utils.FileLength(call.Argument(0).String())
    35  - r.TargetObj.TotalScreenShot = length
    36  - utils.InforF("Total ScreenShot: %v", color.HiMagentaString("%v", length))
    37  - return otto.Value{}
    38  - })
     33 + r.VM.Set(TotalScreenShot, func(call otto.FunctionCall) otto.Value {
     34 + length := utils.FileLength(call.Argument(0).String())
     35 + r.TargetObj.TotalScreenShot = length
     36 + utils.InforF("Total ScreenShot: %v", color.HiMagentaString("%v", length))
     37 + return otto.Value{}
     38 + })
    39 39   
    40  - r.VM.Set(TotalTech, func(call otto.FunctionCall) otto.Value {
    41  - length := utils.FileLength(call.Argument(0).String())
    42  - r.TargetObj.TotalTech = length
    43  - utils.InforF("Total Tech: %v", color.HiMagentaString("%v", length))
    44  - return otto.Value{}
    45  - })
     40 + r.VM.Set(TotalTech, func(call otto.FunctionCall) otto.Value {
     41 + length := utils.FileLength(call.Argument(0).String())
     42 + r.TargetObj.TotalTech = length
     43 + utils.InforF("Total Tech: %v", color.HiMagentaString("%v", length))
     44 + return otto.Value{}
     45 + })
    46 46   
    47  - r.VM.Set(TotalVulnerability, func(call otto.FunctionCall) otto.Value {
    48  - data := utils.ReadingFileUnique(call.Argument(0).String())
    49  - var length int
    50  - for _, line := range data {
    51  - if !strings.Contains(line, "-info") {
    52  - length += 1
    53  - }
    54  - }
    55  - r.TargetObj.TotalVulnerability = length
    56  - utils.InforF("Total Vulnerability: %v", color.HiMagentaString("%v", length))
    57  - return otto.Value{}
    58  - })
     47 + r.VM.Set(TotalVulnerability, func(call otto.FunctionCall) otto.Value {
     48 + data := utils.ReadingFileUnique(call.Argument(0).String())
     49 + var length int
     50 + for _, line := range data {
     51 + if !strings.Contains(line, "-info") {
     52 + length += 1
     53 + }
     54 + }
     55 + r.TargetObj.TotalVulnerability = length
     56 + utils.InforF("Total Vulnerability: %v", color.HiMagentaString("%v", length))
     57 + return otto.Value{}
     58 + })
    59 59   
    60  - r.VM.Set(TotalArchive, func(call otto.FunctionCall) otto.Value {
    61  - length := utils.FileLength(call.Argument(0).String())
    62  - r.TargetObj.TotalArchive = length
    63  - utils.InforF("Total Archive: %v", color.HiMagentaString("%v", length))
    64  - return otto.Value{}
    65  - })
     60 + r.VM.Set(TotalArchive, func(call otto.FunctionCall) otto.Value {
     61 + length := utils.FileLength(call.Argument(0).String())
     62 + r.TargetObj.TotalArchive = length
     63 + utils.InforF("Total Archive: %v", color.HiMagentaString("%v", length))
     64 + return otto.Value{}
     65 + })
    66 66   
    67  - r.VM.Set(TotalLink, func(call otto.FunctionCall) otto.Value {
    68  - length := utils.FileLength(call.Argument(0).String())
    69  - r.TargetObj.TotalLink = length
    70  - utils.InforF("Total Link: %v", color.HiMagentaString("%v", length))
    71  - return otto.Value{}
    72  - })
     67 + r.VM.Set(TotalLink, func(call otto.FunctionCall) otto.Value {
     68 + length := utils.FileLength(call.Argument(0).String())
     69 + r.TargetObj.TotalLink = length
     70 + utils.InforF("Total Link: %v", color.HiMagentaString("%v", length))
     71 + return otto.Value{}
     72 + })
    73 73   
    74  - r.VM.Set(TotalDirb, func(call otto.FunctionCall) otto.Value {
    75  - length := utils.FileLength(call.Argument(0).String())
    76  - r.TargetObj.TotalDirb = length
    77  - utils.InforF("Total Dirb: %v", color.HiMagentaString("%v", length))
    78  - return otto.Value{}
    79  - })
     74 + r.VM.Set(TotalDirb, func(call otto.FunctionCall) otto.Value {
     75 + length := utils.FileLength(call.Argument(0).String())
     76 + r.TargetObj.TotalDirb = length
     77 + utils.InforF("Total Dirb: %v", color.HiMagentaString("%v", length))
     78 + return otto.Value{}
     79 + })
    80 80   
    81  - // CreateReport('report', 'subdomain')
    82  - r.VM.Set(CreateReport, func(call otto.FunctionCall) otto.Value {
    83  - args := call.ArgumentList
    84  - report := args[0].String()
    85  - if utils.FileExists(report) {
    86  - return otto.Value{}
    87  - }
    88  - moduleName := "inline"
    89  - if len(args) > 1 {
    90  - moduleName = args[1].String()
    91  - }
     81 + // CreateReport('report', 'subdomain')
     82 + r.VM.Set(CreateReport, func(call otto.FunctionCall) otto.Value {
     83 + args := call.ArgumentList
     84 + report := args[0].String()
     85 + if utils.FileExists(report) {
     86 + return otto.Value{}
     87 + }
     88 + moduleName := "inline"
     89 + if len(args) > 1 {
     90 + moduleName = args[1].String()
     91 + }
    92 92   
    93  - reportObj := database.Report{
    94  - ReportName: path.Base(report),
    95  - Module: moduleName,
    96  - ReportPath: report,
    97  - ReportType: "",
    98  - TargetRefer: r.TargetObj.ID,
    99  - }
    100  - database.NewReport(&reportObj)
    101  - return otto.Value{}
    102  - })
     93 + reportObj := database.Report{
     94 + ReportName: path.Base(report),
     95 + Module: moduleName,
     96 + ReportPath: report,
     97 + ReportType: "",
     98 + TargetRefer: r.TargetObj.ID,
     99 + }
     100 + database.NewReport(&reportObj)
     101 + return otto.Value{}
     102 + })
    103 103   
    104  - return output
     104 + return output
    105 105  }
    106 106   
    107 107  func (r *Runner) DBNewTarget() {
    108  - if r.Opt.NoDB {
    109  - return
    110  - }
     108 + if r.Opt.NoDB {
     109 + return
     110 + }
    111 111   
    112  - //// this is just sample org
    113  - //org := database.Org{
    114  - // Name: "Sample Org",
    115  - // Desc: "Sample Desc",
    116  - // //Targets: nil,
    117  - //}
    118  - //database.NewOrg(&org)
     112 + //// this is just sample org
     113 + //org := database.Org{
     114 + // Name: "Sample Org",
     115 + // Desc: "Sample Desc",
     116 + // //Targets: nil,
     117 + //}
     118 + //database.NewOrg(&org)
    119 119   
    120  - r.TargetObj = database.Target{
    121  - InputName: r.Input,
    122  - Workspace: r.Workspace,
    123  - InputType: r.InputType,
    124  - //OrgRefer: org.ID,
    125  - }
    126  - database.DBUpdateTarget(&r.TargetObj)
     120 + r.TargetObj = database.Target{
     121 + InputName: r.Input,
     122 + Workspace: r.Workspace,
     123 + InputType: r.InputType,
     124 + //OrgRefer: org.ID,
     125 + }
     126 + database.DBUpdateTarget(&r.TargetObj)
    127 127  }
    128 128   
    129 129  func (r *Runner) DBNewScan() {
    130  - if r.Opt.NoDB {
    131  - return
    132  - }
     130 + if r.Opt.NoDB {
     131 + return
     132 + }
    133 133   
    134  - r.ScanObj = database.Scan{
    135  - TaskType: r.RoutineType,
    136  - TaskName: path.Base(r.RoutineName),
     134 + r.ScanObj = database.Scan{
     135 + TaskType: r.RoutineType,
     136 + TaskName: path.Base(r.RoutineName),
    137 137   
    138  - // this should be user id as uuid
    139  - //UID: r.RunnerSource,
     138 + // this should be user id as uuid
     139 + //UID: r.RunnerSource,
    140 140   
    141  - TotalSteps: r.TotalSteps,
    142  - InputName: r.Input,
    143  - InputType: r.InputType,
     141 + TotalSteps: r.TotalSteps,
     142 + InputName: r.Input,
     143 + InputType: r.InputType,
    144 144   
    145  - LogFile: r.Opt.LogFile,
    146  - Target: r.TargetObj,
    147  - ProcessID: os.Getpid(),
    148  - IsRunning: true,
    149  - IsDone: false,
    150  - IsPrepared: true,
    151  - }
     145 + LogFile: r.Opt.LogFile,
     146 + Target: r.TargetObj,
     147 + ProcessID: os.Getpid(),
     148 + IsRunning: true,
     149 + IsDone: false,
     150 + IsPrepared: true,
     151 + }
    152 152   
    153  - if r.Opt.ScanID != "" {
    154  - utils.InforF("Continue scanning on scan id: %v", r.Opt.ScanID)
    155  - r.ScanObj.ID = cast.ToUint(r.Opt.ScanID)
    156  - }
     153 + if r.Opt.ScanID != "" {
     154 + utils.InforF("Continue scanning on scan id: %v", r.Opt.ScanID)
     155 + r.ScanObj.ID = cast.ToUint(r.Opt.ScanID)
     156 + }
    157 157   
    158  - if r.RunnerType == "cloud" {
    159  - r.ScanObj.IsCloud = true
    160  - }
     158 + if r.RunnerType == "cloud" {
     159 + r.ScanObj.IsCloud = true
     160 + }
    161 161   
    162  - database.DBNewScan(&r.ScanObj)
     162 + database.DBNewScan(&r.ScanObj)
    163 163  }
    164 164   
    165 165  func (r *Runner) DBUpdateScan() {
    166  - r.ScanObj.DoneStep = r.DoneStep
    167  - r.ScanObj.CurrentModule = r.CurrentModule
    168  - r.ScanObj.RunningTime = r.RunningTime
    169  - r.ScanObj.ProcessID = os.Getpid()
     166 + r.ScanObj.DoneStep = r.DoneStep
     167 + r.ScanObj.CurrentModule = r.CurrentModule
     168 + r.ScanObj.RunningTime = r.RunningTime
     169 + r.ScanObj.ProcessID = os.Getpid()
    170 170   
    171  - if r.ScanObj.DoneStep == r.ScanObj.TotalSteps {
    172  - r.ScanObj.IsDone = true
    173  - r.ScanObj.IsRunning = false
    174  - } else {
    175  - r.ScanObj.IsRunning = true
    176  - r.ScanObj.IsDone = false
    177  - }
     171 + if r.ScanObj.DoneStep == r.ScanObj.TotalSteps {
     172 + r.ScanObj.IsDone = true
     173 + r.ScanObj.IsRunning = false
     174 + } else {
     175 + r.ScanObj.IsRunning = true
     176 + r.ScanObj.IsDone = false
     177 + }
    178 178   
    179  - utils.DebugF("[DB] Done module %v with %v/%v steps ", r.CurrentModule, r.DoneStep, r.TotalSteps)
    180  - database.DBUpdateScan(&r.ScanObj)
     179 + utils.DebugF("[DB] Done module %v with %v/%v steps ", r.CurrentModule, r.DoneStep, r.TotalSteps)
     180 + database.DBUpdateScan(&r.ScanObj)
    181 181   
    182  - r.ScanObj.Target = r.TargetObj
    183  - runtimeData, err := jsoniter.MarshalToString(r.ScanObj)
    184  - if err == nil {
    185  - utils.WriteToFile(r.RuntimeFile, runtimeData)
    186  - }
     182 + r.ScanObj.Target = r.TargetObj
     183 + runtimeData, err := jsoniter.MarshalToString(r.ScanObj)
     184 + if err == nil {
     185 + utils.WriteToFile(r.RuntimeFile, runtimeData)
     186 + }
    187 187  }
    188 188   
    189 189  func (r *Runner) DBDoneScan() {
    190  - r.ScanObj.CurrentModule = "done"
    191  - r.ScanObj.RunningTime = r.RunningTime
     190 + r.ScanObj.CurrentModule = "done"
     191 + r.ScanObj.RunningTime = r.RunningTime
    192 192   
    193  - r.ScanObj.DoneStep = r.TotalSteps
    194  - r.ScanObj.IsDone = true
    195  - r.ScanObj.IsRunning = false
     193 + r.ScanObj.DoneStep = r.TotalSteps
     194 + r.ScanObj.IsDone = true
     195 + r.ScanObj.IsRunning = false
    196 196   
    197  - utils.DebugF("[DB] Done the scan: %v -- %v", r.ScanObj.InputName, r.ScanObj.TaskName)
    198  - database.DBUpdateScan(&r.ScanObj)
     197 + utils.DebugF("[DB] Done the scan: %v -- %v", r.ScanObj.InputName, r.ScanObj.TaskName)
     198 + database.DBUpdateScan(&r.ScanObj)
    199 199  }
    200 200   
    201 201  func (r *Runner) DBUpdateTarget() {
    202  - database.DBUpdateTarget(&r.TargetObj)
     202 + database.DBUpdateTarget(&r.TargetObj)
    203 203  }
    204 204   
    205 205  func (r *Runner) DBNewReports(module libs.Module) {
    206  - if r.Opt.NoDB {
    207  - return
    208  - }
     206 + if r.Opt.NoDB {
     207 + return
     208 + }
    209 209   
    210  - r.ScanObj.CurrentModule = r.CurrentModule
    211  - r.ScanObj.RunningTime = r.RunningTime
    212  - database.DBUpdateScan(&r.ScanObj)
     210 + r.ScanObj.CurrentModule = r.CurrentModule
     211 + r.ScanObj.RunningTime = r.RunningTime
     212 + database.DBUpdateScan(&r.ScanObj)
    213 213   
    214  - var reports []string
    215  - reports = append(reports, module.Report.Final...)
    216  - reports = append(reports, module.Report.Noti...)
    217  - reports = append(reports, module.Report.Diff...)
     214 + var reports []string
     215 + reports = append(reports, module.Report.Final...)
     216 + reports = append(reports, module.Report.Noti...)
     217 + reports = append(reports, module.Report.Diff...)
    218 218   
    219  - utils.DebugF("Updating reports")
    220  - for _, report := range reports {
    221  - reportObj := database.Report{
    222  - ReportName: path.Base(report),
    223  - ModulePath: module.ModulePath,
    224  - Module: module.Name,
    225  - ReportPath: report,
    226  - ReportType: "",
    227  - TargetRefer: r.TargetObj.ID,
    228  - }
     219 + utils.DebugF("Updating reports")
     220 + for _, report := range reports {
     221 + reportObj := database.Report{
     222 + ReportName: path.Base(report),
     223 + ModulePath: module.ModulePath,
     224 + Module: module.Name,
     225 + ReportPath: report,
     226 + ReportType: "",
     227 + TargetRefer: r.TargetObj.ID,
     228 + }
    229 229   
    230  - database.NewReport(&reportObj)
    231  - r.TargetObj.Reports = append(r.TargetObj.Reports, reportObj)
    232  - }
     230 + database.NewReport(&reportObj)
     231 + r.TargetObj.Reports = append(r.TargetObj.Reports, reportObj)
     232 + }
    233 233  }
    234 234   
  • ■ ■ ■ ■ ■ ■
    core/external.go
    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   
  • ■ ■ ■ ■ ■ ■
    core/flow.go
    1 1  package core
    2 2   
    3 3  import (
    4  - "fmt"
    5  - "github.com/j3ssie/osmedeus/utils"
    6  - "github.com/thoas/go-funk"
    7  - "path"
    8  - "path/filepath"
    9  - "strings"
     4 + "fmt"
     5 + "github.com/j3ssie/osmedeus/utils"
     6 + "github.com/thoas/go-funk"
     7 + "path"
     8 + "path/filepath"
     9 + "strings"
    10 10   
    11  - "github.com/j3ssie/osmedeus/libs"
     11 + "github.com/j3ssie/osmedeus/libs"
    12 12  )
    13 13   
    14 14  // ListFlow list all available mode
    15 15  func ListFlow(options libs.Options) (result []string) {
    16  - modePath := path.Join(options.Env.WorkFlowsFolder, "/*.yaml")
    17  - result, err := filepath.Glob(modePath)
    18  - if err != nil {
    19  - return result
    20  - }
    21  - return result
     16 + modePath := path.Join(options.Env.WorkFlowsFolder, "/*.yaml")
     17 + result, err := filepath.Glob(modePath)
     18 + if err != nil {
     19 + return result
     20 + }
     21 + return result
    22 22  }
    23 23   
    24 24  // SelectFlow select flow to run
    25 25  func SelectFlow(flowName string, options libs.Options) []string {
    26  - flows := ListFlow(options)
    27  - var selectedFlow []string
     26 + flows := ListFlow(options)
     27 + var selectedFlow []string
    28 28   
    29  - // absolute path like -f customflows/general.yaml
    30  - if strings.HasSuffix(flowName, ".yaml") {
    31  - if utils.FileExists(flowName) {
    32  - selectedFlow = append(selectedFlow, flowName)
    33  - return selectedFlow
    34  - }
    35  - }
     29 + // absolute path like -f customflows/general.yaml
     30 + if strings.HasSuffix(flowName, ".yaml") {
     31 + if utils.FileExists(flowName) {
     32 + selectedFlow = append(selectedFlow, flowName)
     33 + return selectedFlow
     34 + }
     35 + }
    36 36   
    37  - // -f test
    38  - if !strings.Contains(flowName, ",") {
    39  - selectedFlow = append(selectedFlow, singleMode(flowName, flows)...)
    40  - }
     37 + // -f test
     38 + if !strings.Contains(flowName, ",") {
     39 + selectedFlow = append(selectedFlow, singleMode(flowName, flows)...)
     40 + }
    41 41   
    42  - // -f test1,test2
    43  - flowNames := strings.Split(flowName, ",")
    44  - for _, item := range flowNames {
    45  - selectedFlow = append(selectedFlow, singleMode(item, flows)...)
    46  - }
     42 + // -f test1,test2
     43 + flowNames := strings.Split(flowName, ",")
     44 + for _, item := range flowNames {
     45 + selectedFlow = append(selectedFlow, singleMode(item, flows)...)
     46 + }
    47 47   
    48  - // default custom flow folder
    49  - if !utils.FileExists(flowName) {
    50  - flowName = path.Join(options.Env.WorkFlowsFolder, "default-flows", flowName)
    51  - if utils.FileExists(flowName) {
    52  - selectedFlow = append(selectedFlow, flowName)
    53  - } else if utils.FileExists(flowName + ".yaml") {
    54  - flowName = flowName + ".yaml"
    55  - selectedFlow = append(selectedFlow, flowName)
    56  - }
    57  - }
     48 + // default custom flow folder
     49 + if !utils.FileExists(flowName) {
     50 + flowName = path.Join(options.Env.WorkFlowsFolder, "default-flows", flowName)
     51 + if utils.FileExists(flowName) {
     52 + selectedFlow = append(selectedFlow, flowName)
     53 + } else if utils.FileExists(flowName + ".yaml") {
     54 + flowName = flowName + ".yaml"
     55 + selectedFlow = append(selectedFlow, flowName)
     56 + }
     57 + }
    58 58   
    59  - selectedFlow = funk.UniqString(selectedFlow)
    60  - return selectedFlow
     59 + selectedFlow = funk.UniqString(selectedFlow)
     60 + return selectedFlow
    61 61  }
    62 62   
    63 63  func singleMode(modeName string, modes []string) (selectedMode []string) {
    64  - for _, mode := range modes {
    65  - basemodeName := strings.TrimRight(strings.TrimRight(filepath.Base(mode), "yaml"), ".")
    66  - // select workflow file in workflow directory
    67  - if strings.ToLower(basemodeName) == strings.ToLower(modeName) {
    68  - selectedMode = append(selectedMode, mode)
    69  - }
    70  - }
    71  - return selectedMode
     64 + for _, mode := range modes {
     65 + basemodeName := strings.TrimRight(strings.TrimRight(filepath.Base(mode), "yaml"), ".")
     66 + // select workflow file in workflow directory
     67 + if strings.ToLower(basemodeName) == strings.ToLower(modeName) {
     68 + selectedMode = append(selectedMode, mode)
     69 + }
     70 + }
     71 + return selectedMode
    72 72  }
    73 73   
    74 74  // ListModules list all available module
    75 75  func ListModules(options libs.Options) (modules []string) {
    76  - modePath := path.Join(options.Env.WorkFlowsFolder, "general/*.yaml")
    77  - if options.Flow.Type != "" {
    78  - modePath = path.Join(options.Env.WorkFlowsFolder, fmt.Sprintf("%v/*.yaml", options.Flow.Type))
    79  - }
    80  - if strings.HasSuffix(options.Scan.Flow, ".yaml") {
    81  - if options.Flow.Type == "" {
    82  - options.Flow.Type = "general"
    83  - }
    84  - modePath = path.Join(path.Dir(options.Scan.Flow), options.Flow.Type) + "/*.yaml"
    85  - }
    86  - modules, err := filepath.Glob(modePath)
    87  - if err != nil {
    88  - return modules
    89  - }
    90  - return modules
     76 + modePath := path.Join(options.Env.WorkFlowsFolder, "general/*.yaml")
     77 + if options.Flow.Type != "" {
     78 + modePath = path.Join(options.Env.WorkFlowsFolder, fmt.Sprintf("%v/*.yaml", options.Flow.Type))
     79 + }
     80 + if strings.HasSuffix(options.Scan.Flow, ".yaml") {
     81 + if options.Flow.Type == "" {
     82 + options.Flow.Type = "general"
     83 + }
     84 + modePath = path.Join(path.Dir(options.Scan.Flow), options.Flow.Type) + "/*.yaml"
     85 + }
     86 + modules, err := filepath.Glob(modePath)
     87 + if err != nil {
     88 + return modules
     89 + }
     90 + return modules
    91 91  }
    92 92   
    93 93  // SelectModules return list of modules name
    94 94  func SelectModules(moduleNames []string, options libs.Options) []string {
    95  - if strings.Contains(options.Flow.Type, "{{.") {
    96  - options.Flow.Type = ResolveData(options.Flow.Type, options.Scan.ROptions)
    97  - }
    98  - modules := ListModules(options)
    99  - var selectedModules []string
    100  - for _, item := range moduleNames {
    101  - selectedModules = append(selectedModules, singleSelectModule(item, modules)...)
    102  - }
    103  - selectedModules = funk.UniqString(selectedModules)
     95 + if strings.Contains(options.Flow.Type, "{{.") {
     96 + options.Flow.Type = ResolveData(options.Flow.Type, options.Scan.ROptions)
     97 + }
     98 + modules := ListModules(options)
     99 + var selectedModules []string
     100 + for _, item := range moduleNames {
     101 + selectedModules = append(selectedModules, singleSelectModule(item, modules)...)
     102 + }
     103 + selectedModules = funk.UniqString(selectedModules)
    104 104   
    105  - utils.DebugF("Select module name %v: %v", moduleNames, selectedModules)
    106  - return selectedModules
     105 + utils.DebugF("Select module name %v: %v", moduleNames, selectedModules)
     106 + return selectedModules
    107 107  }
    108 108   
    109 109  func singleSelectModule(moduleName string, modules []string) (selectedModules []string) {
    110  - for _, module := range modules {
    111  - baseModuleName := strings.Trim(strings.TrimRight(filepath.Base(module), "yaml"), ".")
    112  - if strings.ToLower(baseModuleName) == strings.ToLower(moduleName) {
    113  - selectedModules = append(selectedModules, module)
    114  - }
    115  - }
    116  - return selectedModules
     110 + for _, module := range modules {
     111 + baseModuleName := strings.Trim(strings.TrimRight(filepath.Base(module), "yaml"), ".")
     112 + if strings.ToLower(baseModuleName) == strings.ToLower(moduleName) {
     113 + selectedModules = append(selectedModules, module)
     114 + }
     115 + }
     116 + return selectedModules
    117 117  }
    118 118   
    119 119  // DirectSelectModule select module from ~/.osmedeus/core/workflow/plugins/
    120 120  func DirectSelectModule(options libs.Options, moduleName string) string {
    121  - // got absolutely path
    122  - if utils.FileExists(moduleName) {
    123  - return moduleName
    124  - }
     121 + // got absolutely path
     122 + if utils.FileExists(moduleName) {
     123 + return moduleName
     124 + }
    125 125   
    126  - // select in cloud folder first if we're running the cloud scan
    127  - // ~/.osmedeus/core/workflow/cloud-modules/
    128  - basePlugin := path.Join(options.Env.WorkFlowsFolder, "cloud-modules")
    129  - modulePath := path.Join(basePlugin, moduleName)
    130  - if utils.FileExists(modulePath) {
    131  - utils.DebugF("Load module path: %v", modulePath)
    132  - return modulePath
    133  - }
     126 + // select in cloud folder first if we're running the cloud scan
     127 + // ~/.osmedeus/core/workflow/cloud-modules/
     128 + basePlugin := path.Join(options.Env.WorkFlowsFolder, "cloud-modules")
     129 + modulePath := path.Join(basePlugin, moduleName)
     130 + if utils.FileExists(modulePath) {
     131 + utils.DebugF("Load module path: %v", modulePath)
     132 + return modulePath
     133 + }
    134 134   
    135  - modulePath = path.Join(basePlugin, moduleName+".yaml")
    136  - if utils.FileExists(modulePath) {
    137  - utils.DebugF("Load module path: %v", modulePath)
    138  - return modulePath
    139  - }
     135 + modulePath = path.Join(basePlugin, moduleName+".yaml")
     136 + if utils.FileExists(modulePath) {
     137 + utils.DebugF("Load module path: %v", modulePath)
     138 + return modulePath
     139 + }
    140 140   
    141  - // ~/.osmedeus/core/workflow/default-modules/
    142  - basePlugin = path.Join(options.Env.WorkFlowsFolder, "default-modules")
    143  - modulePath = path.Join(basePlugin, moduleName)
    144  - utils.DebugF("Load module path: %v", modulePath)
    145  - if utils.FileExists(modulePath) {
    146  - return modulePath
    147  - }
     141 + // ~/.osmedeus/core/workflow/default-modules/
     142 + basePlugin = path.Join(options.Env.WorkFlowsFolder, "default-modules")
     143 + modulePath = path.Join(basePlugin, moduleName)
     144 + utils.DebugF("Load module path: %v", modulePath)
     145 + if utils.FileExists(modulePath) {
     146 + return modulePath
     147 + }
    148 148   
    149  - modulePath = path.Join(basePlugin, moduleName+".yaml")
    150  - utils.DebugF("Load module path: %v", modulePath)
    151  - if utils.FileExists(modulePath) {
    152  - return modulePath
    153  - }
    154  - utils.DebugF("No plugin found with: %v", moduleName)
    155  - return ""
     149 + modulePath = path.Join(basePlugin, moduleName+".yaml")
     150 + utils.DebugF("Load module path: %v", modulePath)
     151 + if utils.FileExists(modulePath) {
     152 + return modulePath
     153 + }
     154 + utils.DebugF("No plugin found with: %v", moduleName)
     155 + return ""
    156 156  }
    157 157   
    158 158  // ListScripts list all available mode
    159 159  func ListScripts(options libs.Options) (result []string) {
    160  - modePath := path.Join(options.Env.OseFolder, "/*.js")
    161  - result, err := filepath.Glob(modePath)
    162  - if err != nil {
    163  - return result
    164  - }
     160 + modePath := path.Join(options.Env.OseFolder, "/*.js")
     161 + result, err := filepath.Glob(modePath)
     162 + if err != nil {
     163 + return result
     164 + }
    165 165   
    166  - modePath = path.Join(options.Env.OseFolder, "/*/*.js")
    167  - DepthResult, err := filepath.Glob(modePath)
    168  - if err == nil {
    169  - result = append(result, DepthResult...)
    170  - }
    171  - return result
     166 + modePath = path.Join(options.Env.OseFolder, "/*/*.js")
     167 + DepthResult, err := filepath.Glob(modePath)
     168 + if err == nil {
     169 + result = append(result, DepthResult...)
     170 + }
     171 + return result
    172 172  }
    173 173   
    174 174  func SelectScript(scriptName string, options libs.Options) string {
    175  - scripts := ListScripts(options)
    176  - for _, script := range scripts {
    177  - if strings.Contains(scriptName, "/") {
    178  - if strings.HasSuffix(script, scriptName) || strings.HasSuffix(script, scriptName+".js") {
    179  - return script
    180  - }
    181  - }
     175 + scripts := ListScripts(options)
     176 + for _, script := range scripts {
     177 + if strings.Contains(scriptName, "/") {
     178 + if strings.HasSuffix(script, scriptName) || strings.HasSuffix(script, scriptName+".js") {
     179 + return script
     180 + }
     181 + }
    182 182   
    183  - compareName := path.Base(script)
    184  - if compareName == scriptName {
    185  - return script
    186  - }
    187  - if compareName == fmt.Sprintf("%s.js", scriptName) {
    188  - return script
    189  - }
    190  - }
    191  - return ""
     183 + compareName := path.Base(script)
     184 + if compareName == scriptName {
     185 + return script
     186 + }
     187 + if compareName == fmt.Sprintf("%s.js", scriptName) {
     188 + return script
     189 + }
     190 + }
     191 + return ""
    192 192  }
    193 193   
Please wait...
Page is in error, reload to recover