How to use writeConfig method of main Package

Best Syzkaller code snippet using main.writeConfig

main.go

Source:main.go Github

copy

Full Screen

1package uiqt2import (3 "bufio"4 "bytes"5 "database/sql"6 "fmt"7 "io/ioutil"8 "net/http"9 "net/url"10 "os"11 "regexp"12 "strings"13 "sync"14 "time"15 "github.com/m4xirq/Zertex/XDGv2/api/client"16 "github.com/m4xirq/Zertex/XDGv2/auth"17 "github.com/m4xirq/Zertex/XDGv2/injection"18 "github.com/m4xirq/Zertex/XDGv2/manager"19 "github.com/m4xirq/Zertex/XDGv2/modules"20 "github.com/m4xirq/Zertex/XDGv2/modules/dorkers"21 "github.com/m4xirq/Zertex/XDGv2/qtui"22 "github.com/m4xirq/Zertex/XDGv2/utils"23 "github.com/m4xirq/Zertex/XDGv2/web"24 "github.com/pkg/browser"25 "github.com/spf13/viper"26 "github.com/therecipe/qt/core"27 "github.com/therecipe/qt/gui"28 "github.com/therecipe/qt/widgets"29)30func StopModules(bool) {31 if utils.Module != "Idle" {32 if utils.Module == "Stopping" {33 manager.PManager.CancelAll()34 if !utils.IsClosed(utils.Kill) {35 close(utils.Kill)36 }37 } else {38 utils.Module = "Stopping"39 if !utils.IsClosed(utils.Done) {40 close(utils.Done)41 }42 }43 } else {44 qtui.SimpleMB(qtui.Main, "Already stopping!", "Error")45 }46}47func NewMain() *qtui.MainWindow {48 qtui.Main = qtui.NewMainWindow(nil)49 qtui.Main.SetWindowTitle(fmt.Sprintf("XDumpGO v%s | Created by Quartz Inc. | https://invite.gg/quartzinc", auth.Version))50 qtui.Main.ExploiterInjectablesTable.HorizontalHeader().ResizeSection(0, 160)51 //qtui.Main.DumperTableWidget.HorizontalHeader().ResizeSection(0, 160)52 qtui.Main.TabControl.ConnectCurrentChanged(func(index int) {53 if index == 6 {54 qtui.Main.CleanerUrlsTextBox.SetPlainText(strings.Join(modules.Scraper.Urls, "\r\n"))55 }56 })57 qtui.Main.NewsBox.SetWordWrap(true)58 qtui.Main.CustomerChatbox.SetWordWrap(true)59 qtui.Main.CleanerBtn.ConnectClicked(func(bool) {60 loading := qtui.NewLoadingWindow(qtui.Main)61 loading.ProgressBar.SetMaximum(len(modules.Scraper.Urls))62 loading.ProgressBar.SetValue(0)63 loading.Label.SetText("Cleaning your urls, please wait...")64 go loading.Show()65 cleanRg := regexp.MustCompile(`^http.+\?.+=`)66 go func() {67 modules.Scraper.Urls = []string{}68 domains := make(map[string]interface{})69 i := 070 scanner := bufio.NewScanner(strings.NewReader(qtui.Main.CleanerUrlsTextBox.ToPlainText()))71 for scanner.Scan() {72 i++73 loading.ProgressBar.SetValue(i)74 u, err := url.Parse(scanner.Text())75 if err != nil {76 continue77 }78 if qtui.Main.CleanerDuplicateDomains.IsChecked() {79 if _, ok := domains[u.Hostname()]; ok {80 continue81 }82 domains[u.Hostname()] = nil83 }84 if qtui.Main.CleanerQueryParam.IsChecked() {85 if !cleanRg.MatchString(u.String()) {86 continue87 }88 }89 modules.Scraper.Urls = append(modules.Scraper.Urls, u.String())90 }91 qtui.Main.CleanerUrlsTextBox.SetPlainText(strings.Join(modules.Scraper.Urls, "\r\n"))92 os.Mkdir("cleaned-urls", 0755)93 f := utils.CreateFileTimeStamped("output", "cleaned-urls")94 f.WriteString(strings.Join(modules.Scraper.Urls, "\r\n"))95 f.Close()96 loading.Hide()97 loading.Close()98 }()99 })100 qtui.Main.WebUILaunchBtn.ConnectClicked(func(bool) {101 go web.StartWebUI(qtui.Main.WebUIAddress.Text())102 var address string103 if len(strings.Split(qtui.Main.WebUIAddress.Text(), ":")[0]) == 0 {104 address = "localhost" + qtui.Main.WebUIAddress.Text()105 } else {106 address = qtui.Main.WebUIAddress.Text()107 }108 browser.OpenURL("http://" + address)109 })110 go func() {111 for {112 select {113 case <-time.After(time.Second):114 qtui.Main.StatsModule.SetText(utils.Module)115 qtui.Main.StatsCurrentTimeLcd.Display(time.Now().Format("15:04:05"))116 if utils.Module != "Idle" {117 qtui.Main.StatsRuntimeLcd.Display(utils.FmtDuration(time.Since(utils.StartTime)))118 }119 qtui.Main.DataDorksLcd.Display2(len(modules.Scraper.Dorks))120 qtui.Main.DataUrlsLcd.Display2(len(modules.Scraper.Urls))121 qtui.Main.DataInjectablesLcd.Display2(len(modules.Exploiter.Injectables))122 qtui.Main.DataInjectablesLcd.Repaint()123 qtui.Main.DataProxiesLcd.Display2(len(manager.PManager.Proxies))124 qtui.Main.StatsRequestsLcd.Display2(utils.RequestCounter)125 qtui.Main.StatsRPSLcd.Display2(int(utils.RateCounter.Rate()))126 qtui.Main.StatsErrorLcd.Display2(utils.ErrorCounter)127 qtui.Main.DataThreadsLcd.Display2(len(utils.GlobalSem))128 qtui.Main.DataWorkersLcd.Display2(len(utils.WorkerSem))129 qtui.Main.DumpStatsTablesLcd.Display2(modules.Dumper.Tables)130 qtui.Main.DumpStatsColumnsLcd.Display2(modules.Dumper.Columns)131 qtui.Main.DumpStatsRowsLcd.Display2(modules.Dumper.Rows)132 qtui.Main.DumpStatsRpm.Display(utils.RPMCounter.String())133 switch utils.Module {134 case "Scraper":135 qtui.Main.ParserProgress.SetMaximum(len(modules.Scraper.Dorks))136 qtui.Main.ParserProgress.SetValue(modules.Scraper.Index)137 //qtui.Main.ParserProgress.SetFormat(fmt.Sprintf("%.2f%% %d/%d", float64(modules.Scraper.Index/len(modules.Scraper.Dorks)), modules.Scraper.Index, len(modules.Scraper.Dorks)))138 case "Exploiter":139 qtui.Main.ExploiterProgress.SetMaximum(len(modules.Scraper.Urls))140 qtui.Main.ExploiterProgress.SetValue(modules.Exploiter.Index)141 //qtui.Main.ExploiterProgress.SetFormat(fmt.Sprintf("%.2f%% %d/%d", float64(modules.Exploiter.Index/len(modules.Scraper.Urls)), modules.Exploiter.Index, len(modules.Scraper.Urls)))142 case "Dumper":143 qtui.Main.DumperProgress.SetMaximum(len(modules.Exploiter.Injectables))144 qtui.Main.DumperProgress.SetValue(modules.Dumper.Index)145 //qtui.Main.DumperProgress.SetFormat(fmt.Sprintf("%.2f%% %d/%d", float64(modules.Dumper.Index/len(modules.Exploiter.Injectables)), modules.Dumper.Index, len(modules.Exploiter.Injectables)))146 case "AutoSheller":147 qtui.Main.AutoShellProgress.SetMaximum(len(modules.Exploiter.Injectables))148 qtui.Main.AutoShellProgress.SetValue(modules.AutoSheller.Index)149 //qtui.Main.AutoShellProgress.SetFormat(fmt.Sprintf("%.2f%% %d/%d", float64(modules.AutoSheller.Index/len(modules.Exploiter.Injectables)), modules.AutoSheller.Index, len(modules.Exploiter.Injectables)))150 case "Generator":151 qtui.Main.GeneratorProgress.SetMaximum(len(modules.Generator.Parameters))152 qtui.Main.GeneratorProgress.SetValue(modules.Generator.Index)153 //qtui.Main.GeneratorProgress.SetFormat(fmt.Sprintf("%.2f%% %d/%d", float64(modules.Generator.Index/len(modules.Generator.Parameters)), modules.Generator.Index, len(modules.Generator.Parameters)))154 case "AntiPublic":155 qtui.Main.AntipubProgress.SetMaximum(len(modules.Scraper.Urls))156 qtui.Main.AntipubProgress.SetValue(modules.AntiPublic.Index)157 }158 }159 }160 }()161 /*--------- GENERATOR ----------*/162 var paramNames []string163 for pI, p := range modules.Generator.Parameters {164 paramNames = append(paramNames, fmt.Sprintf("%s-%s", p.Name, pI))165 }166 fmt.Println(paramNames)167 qtui.Main.ComboBoxParameters.AddItems(paramNames)168 // Handles reading the data from the files and showing it169 qtui.Main.ComboBoxParameters.ConnectCurrentIndexChanged(func(index int) {170 if index := qtui.Main.ComboBoxParameters.CurrentIndex(); index > -1 {171 prefix := strings.Split(qtui.Main.ComboBoxParameters.CurrentText(), "-")[1]172 var data []string173 if data = modules.Generator.Parameters[prefix].GetData(); len(data) == 0 {174 if f, err := os.Open(modules.Generator.Parameters[prefix].FilePath); err == nil {175 scanner := bufio.NewScanner(f)176 for scanner.Scan() {177 data = append(data, scanner.Text())178 }179 }180 }181 qtui.Main.PlainTextEditParameters.SetPlainText(strings.Join(data, "\n"))182 }183 })184 qtui.Main.ComboBoxParameters.SetCurrentIndex(0)185 fmt.Println(qtui.Main.ComboBoxParameters.CurrentText())186 qtui.Main.PlainTextEditParameters.SetPlainText(strings.Join(modules.Generator.Parameters[strings.Split(qtui.Main.ComboBoxParameters.CurrentText(), "-")[1]].GetData(), "\n"))187 qtui.Main.PlainTextEditPatterns.SetPlainText(strings.Join(viper.GetStringSlice("generator.Patterns"), "\n"))188 //Handles saving the data written on the box to the text files189 qtui.Main.PlainTextEditParameters.ConnectFocusOutEvent(func(event *gui.QFocusEvent) {190 if index := qtui.Main.ComboBoxParameters.CurrentIndex(); index > -1 {191 prefix := strings.Split(qtui.Main.ComboBoxParameters.CurrentText(), "-")[1]192 modules.Generator.Parameters[prefix].Data = []string{}193 scanner := bufio.NewScanner(strings.NewReader(qtui.Main.PlainTextEditParameters.ToPlainText()))194 for scanner.Scan() {195 modules.Generator.Parameters[prefix].Data = append(modules.Generator.Parameters[prefix].Data, scanner.Text())196 }197 ioutil.WriteFile(modules.Generator.Parameters[prefix].FilePath, []byte(strings.Join(modules.Generator.Parameters[prefix].Data, "\r\n")), os.ModePerm)198 }199 })200 qtui.Main.PlainTextEditPatterns.ConnectFocusOutEvent(func(event *gui.QFocusEvent) {201 modules.Generator.Patterns = []*modules.Pattern{}202 scanner := bufio.NewScanner(strings.NewReader(qtui.Main.PlainTextEditPatterns.ToPlainText()))203 re, _ := regexp.Compile(`\(([^()]+)\)`)204 for scanner.Scan() {205 if strings.TrimSpace(scanner.Text()) != "" {206 if m := re.FindAllString(scanner.Text(), -1); m != nil {207 //Debug208 fmt.Println(m)209 modules.Generator.Patterns = append(modules.Generator.Patterns, &modules.Pattern{210 Prefixes: m,211 TotalDorks: 1,212 PatternStr: scanner.Text(),213 })214 }215 }216 }217 })218 qtui.Main.GeneratorStartBtn.ConnectClicked(func(checked bool) {219 if utils.Module != "Idle" && utils.Module != "Stopping" {220 qtui.SimpleMB(qtui.Main, fmt.Sprintf("Already running module '%s'", utils.Module), "Error")221 return222 }223 qtui.Main.TableGenerator.Clear()224 qtui.Main.TableGenerator.ClearContents()225 qtui.Main.TableGenerator.SetRowCount(0)226 go func() {227 defer func() {228 utils.Module = "Idle"229 }()230 utils.Module = "Generator"231 modules.Generator.Start()232 }()233 })234 qtui.Main.GeneratorStopBtn.ConnectClicked(StopModules)235 viper.SetDefault("generator.limit", true)236 qtui.Main.GeneratorLimiterCheckbox.SetChecked(viper.GetBool("generator.limit"))237 qtui.Main.GeneratorLimiterCheckbox.ConnectClicked(func(checked bool) {238 viper.Set("generator.limit", checked)239 viper.WriteConfig()240 })241 viper.SetDefault("generator.max", 5000)242 qtui.Main.GeneratorLimiterSpinbox.SetMaximum(9999999999)243 qtui.Main.GeneratorLimiterSpinbox.SetValue(viper.GetInt("generator.max"))244 qtui.Main.GeneratorLimiterSpinbox.ConnectValueChanged(func(i int) {245 viper.Set("generator.max", i)246 viper.WriteConfig()247 })248 viper.SetDefault("scraper.customparam", "")249 qtui.Main.ParserCustomParams.SetText(viper.GetString("scraper.customparam"))250 qtui.Main.ParserCustomParams.ConnectTextChanged(func(text string) {251 viper.Set("scraper.customparam", text)252 viper.WriteConfig()253 })254 viper.SetDefault("scraper.engines.google", false)255 qtui.Main.ParserGoogleCheckbox.SetChecked(dorkers.Dorkers["Google"].Enabled)256 qtui.Main.ParserGoogleCheckbox.ConnectClicked(func(checked bool) {257 dorkers.Dorkers["Google"].Enabled = checked258 viper.Set("scraper.Engines.Google", checked)259 viper.WriteConfig()260 })261 viper.SetDefault("scraper.engines.googleapi", false)262 /*qtui.Main.ParserGoogleAPICheckbox.Hide()263 //qtui.Main.ParserGoogleAPICheckbox.SetChecked(dorkers.Dorkers["GoogleAPI"].Enabled)264 qtui.Main.ParserGoogleAPICheckbox.ConnectClicked(func(checked bool) {265 dorkers.Dorkers["GoogleAPI"].Enabled = checked266 viper.Set("scraper.Engines.GoogleAPI", checked)267 viper.WriteConfig()268 })*/269 viper.SetDefault("scraper.engines.bing", false)270 qtui.Main.ParserBingCheckbox.SetChecked(dorkers.Dorkers["Bing"].Enabled)271 qtui.Main.ParserBingCheckbox.ConnectClicked(func(checked bool) {272 dorkers.Dorkers["Bing"].Enabled = checked273 viper.Set("scraper.Engines.Bing", checked)274 viper.WriteConfig()275 })276 viper.SetDefault("scraper.engines.aol", false)277 qtui.Main.ParserAOLCheckbox.SetChecked(dorkers.Dorkers["AOL"].Enabled)278 qtui.Main.ParserAOLCheckbox.ConnectClicked(func(checked bool) {279 dorkers.Dorkers["AOL"].Enabled = checked280 viper.Set("scraper.Engines.AOL", checked)281 viper.WriteConfig()282 })283 viper.SetDefault("scraper.engines.mywebsearch", false)284 qtui.Main.ParserMWSCheckbox.SetChecked(dorkers.Dorkers["MyWebSearch"].Enabled)285 qtui.Main.ParserMWSCheckbox.ConnectClicked(func(checked bool) {286 dorkers.Dorkers["MyWebSearch"].Enabled = checked287 viper.Set("scraper.Engines.MyWebSearch", checked)288 viper.WriteConfig()289 })290 viper.SetDefault("scraper.engines.duckduckgo", false)291 qtui.Main.ParserDuckDuckGoCheckbox.Hide()292 qtui.Main.ParserDuckDuckGoCheckbox.SetChecked(dorkers.Dorkers["DuckDuckGo"].Enabled)293 qtui.Main.ParserDuckDuckGoCheckbox.ConnectClicked(func(checked bool) {294 dorkers.Dorkers["DuckDuckGo"].Enabled = checked295 viper.Set("scraper.Engines.DuckDuckGo", checked)296 viper.WriteConfig()297 })298 viper.SetDefault("scraper.engines.ecosia", false)299 qtui.Main.ParserEcosiaCheckbox.SetChecked(dorkers.Dorkers["Ecosia"].Enabled)300 qtui.Main.ParserEcosiaCheckbox.ConnectClicked(func(checked bool) {301 dorkers.Dorkers["Ecosia"].Enabled = checked302 viper.Set("scraper.Engines.Ecosia", checked)303 viper.WriteConfig()304 })305 /*viper.SetDefault("scraper.engines.qwant", false)306 qtui.Main.ParserQwantCheckbox.Hide()307 qtui.Main.ParserQwantCheckbox.SetChecked(dorkers.Dorkers["Qwant"].Enabled)308 qtui.Main.ParserQwantCheckbox.ConnectClicked(func(checked bool) {309 dorkers.Dorkers["Qwant"].Enabled = checked310 viper.Set("scraper.Engines.Qwant", checked)311 viper.WriteConfig()312 })*/313 viper.SetDefault("scraper.engines.startpage", false)314 qtui.Main.ParserStartPageCheckbox.SetChecked(dorkers.Dorkers["StartPage"].Enabled)315 qtui.Main.ParserStartPageCheckbox.ConnectClicked(func(checked bool) {316 dorkers.Dorkers["StartPage"].Enabled = checked317 viper.Set("scraper.Engines.StartPage", checked)318 viper.WriteConfig()319 })320 viper.SetDefault("scraper.engines.yahoo", false)321 qtui.Main.ParserYahooCheckbox.SetChecked(dorkers.Dorkers["Yahoo"].Enabled)322 qtui.Main.ParserYahooCheckbox.ConnectClicked(func(checked bool) {323 dorkers.Dorkers["Yahoo"].Enabled = checked324 viper.Set("scraper.Engines.Yahoo", checked)325 viper.WriteConfig()326 })327 viper.SetDefault("scraper.engines.yandex", false)328 qtui.Main.ParserYandexCheckbox.SetChecked(dorkers.Dorkers["Yandex"].Enabled)329 qtui.Main.ParserYandexCheckbox.ConnectClicked(func(checked bool) {330 dorkers.Dorkers["Yandex"].Enabled = checked331 viper.Set("scraper.Engines.Yandex", checked)332 viper.WriteConfig()333 })334 viper.SetDefault("scraper.filter", true)335 qtui.Main.ParserFilterUrls.SetChecked(viper.GetBool("scraper.Filter"))336 qtui.Main.ParserFilterUrls.ConnectClicked(func(checked bool) {337 viper.Set("scraper.Filter", checked)338 viper.WriteConfig()339 })340 viper.SetDefault("scraper.pages", 2)341 qtui.Main.ParserPagesSpinbox.SetValue(viper.GetInt("scraper.Pages"))342 qtui.Main.ParserPagesSpinbox.ConnectValueChanged(func(i int) {343 viper.Set("scraper.Pages", i)344 viper.WriteConfig()345 })346 qtui.Main.ParserLoadDorksBtn.ConnectClicked(func(bool) {347 wd, _ := os.Getwd()348 ofd := widgets.NewQFileDialog2(qtui.Main, "Select your Dorks", wd, "Text / List files (*.txt *.lst)")349 ofd.ConnectFileSelected(func(file string) {350 f, err := os.Open(file)351 if err != nil {352 return353 }354 modules.Scraper.Dorks = []string{}355 scanner := bufio.NewScanner(f)356 for scanner.Scan() {357 modules.Scraper.Dorks = append(modules.Scraper.Dorks, scanner.Text())358 }359 f.Close()360 qtui.Main.ParserDorksTextbox.SetPlainText(strings.Join(modules.Scraper.Dorks, "\r\n"))361 })362 ofd.Show()363 modules.Scraper.Index = 0364 })365 qtui.Main.ParserClearDorksBtn.ConnectClicked(func(bool) {366 modules.Scraper.Dorks = make([]string, 0)367 qtui.Main.ParserDorksTextbox.SetPlainText("")368 modules.Scraper.Index = 0369 })370 qtui.Main.ParserDorksTextbox.ConnectTextChanged(func() {371 modules.Scraper.Dorks = []string{}372 scanner := bufio.NewScanner(strings.NewReader(qtui.Main.ParserDorksTextbox.ToPlainText()))373 for scanner.Scan() {374 modules.Scraper.Dorks = append(modules.Scraper.Dorks, scanner.Text())375 }376 })377 qtui.Main.ParserStartBtn.ConnectClicked(func(bool) {378 if utils.Module != "Idle" && utils.Module != "Stopping" {379 go qtui.SimpleMB(qtui.Main, fmt.Sprintf("Already running module '%s'", utils.Module), "Error").Show()380 return381 }382 if len(modules.Scraper.Dorks) == 0 {383 go qtui.SimpleMB(qtui.Main, "Please load dorks.", "Error").Show()384 return385 }386 if qtui.SettingsWindow.LoadProxiesFromAPI.IsChecked() {387 resp, err := http.Get(qtui.SettingsWindow.LineEdit.Text())388 if err != nil {389 qtui.SimpleMB(qtui.Main, "Failed to get proxylist\n"+err.Error(), "Error")390 return391 }392 defer resp.Body.Close()393 raw, err := ioutil.ReadAll(resp.Body)394 if err != nil {395 qtui.SimpleMB(qtui.Main, "Failed to get proxylist\n"+err.Error(), "Error")396 return397 }398 manager.PManager.Proxies = []*manager.Proxy{}399 manager.PManager.LoadScanner(bufio.NewScanner(bytes.NewReader(raw)), qtui.SettingsWindow.ProxyTypeComboBox.CurrentIndex())400 }401 f := sync.WaitGroup{}402 if modules.Scraper.Index > 0 {403 f.Add(1)404 q := qtui.NewYesNo(qtui.Main, "Looks like you have another scrape paused, would you like to continue this?", "Just a moment")405 q.ConnectAccepted(func() {406 f.Done()407 })408 q.ConnectRejected(func() {409 modules.Scraper.Index = 0410 f.Done()411 })412 q.Show()413 }414 go func() {415 defer func() {416 utils.Module = "Idle"417 }()418 f.Wait()419 utils.Module = "Scraper"420 modules.Scraper.Start()421 }()422 })423 qtui.Main.ParserStopBtn.ConnectClicked(StopModules)424 viper.SetDefault("exploiter.threads", 100)425 qtui.Main.ExploiterThreads.SetValue(viper.GetInt("exploiter.threads"))426 qtui.Main.ExploiterThreads.ConnectValueChanged(func(i int) {427 viper.Set("exploiter.threads", i)428 viper.WriteConfig()429 })430 viper.SetDefault("exploiter.workers", 30)431 qtui.Main.ExploiterWorkers.SetValue(viper.GetInt("exploiter.workers"))432 qtui.Main.ExploiterWorkers.ConnectValueChanged(func(i int) {433 viper.Set("exploiter.workers", i)434 viper.WriteConfig()435 })436 viper.SetDefault("exploiter.technique.error", true)437 qtui.Main.ExploiterErrorCheckbox.SetChecked(viper.GetBool("exploiter.technique.error"))438 qtui.Main.ExploiterErrorCheckbox.ConnectClicked(func(checked bool) {439 viper.Set("exploiter.technique.error", checked)440 viper.WriteConfig()441 })442 viper.SetDefault("exploiter.technique.union", true)443 qtui.Main.ExploiterUnionCheckbox.SetChecked(viper.GetBool("exploiter.technique.union"))444 qtui.Main.ExploiterUnionCheckbox.ConnectClicked(func(checked bool) {445 viper.Set("exploiter.technique.union", checked)446 viper.WriteConfig()447 })448 viper.SetDefault("exploiter.technique.blind", false)449 qtui.Main.ExploiterBlindCheckbox.SetChecked(viper.GetBool("exploiter.technique.blind"))450 qtui.Main.ExploiterBlindCheckbox.ConnectClicked(func(checked bool) {451 viper.Set("exploiter.technique.blind", checked)452 viper.WriteConfig()453 })454 viper.SetDefault("exploiter.technique.stacked", false)455 qtui.Main.ExploiterStackedCheckbox.SetChecked(viper.GetBool("exploiter.Techniques.Stacked"))456 qtui.Main.ExploiterStackedCheckbox.ConnectClicked(func(checked bool) {457 viper.Set("exploiter.Technique.Stacked", checked)458 viper.WriteConfig()459 })460 viper.SetDefault("exploiter.heuristics", true)461 qtui.Main.ExploiterHeuristsicsCheckbox.SetChecked(viper.GetBool("exploiter.Heuristics"))462 qtui.Main.ExploiterHeuristsicsCheckbox.ConnectClicked(func(checked bool) {463 viper.Set("exploiter.Heuristics", checked)464 viper.WriteConfig()465 })466 viper.SetDefault("exploiter.intensity", 2)467 qtui.Main.ExploiterIntensityCombo.SetCurrentIndex(viper.GetInt("exploiter.Intensity"))468 qtui.Main.ExploiterIntensityCombo.ConnectCurrentIndexChanged(func(index int) {469 viper.Set("exploiter.Intensity", index)470 viper.WriteConfig()471 })472 qtui.Main.ExploiterLoadUrlsBtn.ConnectClicked(func(bool) {473 wd, _ := os.Getwd()474 ofd := widgets.NewQFileDialog2(qtui.Main, "Select your Urls", wd, "Text (*.txt)")475 ofd.Show()476 ofd.ConnectFileSelected(func(file string) {477 f, err := os.Open(file)478 if err != nil {479 return480 }481 scanner := bufio.NewScanner(f)482 for scanner.Scan() {483 modules.Scraper.Urls = append(modules.Scraper.Urls, scanner.Text())484 }485 f.Close()486 //uiParseDorksTxtbx.SetPlainText(strings.Join(modules.Scraper.Urls, "\r\n"))487 modules.Exploiter.Index = 0488 })489 })490 qtui.Main.ExploiterInjectablesTable.ConnectCustomContextMenuRequested(func(pos *core.QPoint) {491 if qtui.Main.ExploiterInjectablesTable.RowCount() == 0 {492 return493 }494 table := qtui.Main.ExploiterInjectablesTable495 index := table.CurrentRow()496 i := table.Item(index, 0).Text()497 _u, _ := url.Parse(i)498 if injectable, ok := modules.Exploiter.Injectables[_u.Hostname()]; ok {499 menu := widgets.NewQMenu2(injectable.Base.String(), table)500 menu.SetWindowTitle("Actions")501 skip := menu.AddAction(fmt.Sprintf("Open Analyzer - %s", injectable.Base.String()))502 skip.ConnectTriggered(func(bool) {503 modules.Analyzer.Mount(injectable)504 qtui.SingleSiteWindow.Show()505 })506 menu.Exec2(qtui.Main.ExploiterInjectablesTable.Viewport().MapToGlobal(pos), skip)507 menu.Show()508 menu.ActivateWindow()509 }510 })511 qtui.Main.ExploiterClearUrlsBtn.ConnectClicked(func(bool) {512 modules.Scraper.Urls = []string{}513 modules.Exploiter.Index = 0514 })515 qtui.Main.ExploiterStartBtn.ConnectClicked(func(bool) {516 if utils.Module != "Idle" && utils.Module != "Stopping" {517 go qtui.SimpleMB(qtui.Main, fmt.Sprintf("Already running module '%s'", utils.Module), "Error").Show()518 return519 }520 if len(modules.Scraper.Urls) == 0 {521 go qtui.SimpleMB(qtui.Main, "Please load or scrape urls.", "Error").Show()522 } else {523 f := sync.WaitGroup{}524 if modules.Exploiter.Index > 0 {525 f.Add(1)526 q := qtui.NewYesNo(qtui.Main, "Looks like you have another scan paused, would you like to continue this?", "Just a moment")527 q.ConnectAccepted(func() {528 f.Done()529 })530 q.ConnectRejected(func() {531 modules.Exploiter.Index = 0532 qtui.Main.ExploiterInjectablesTable.ClearContents()533 qtui.Main.ExploiterInjectablesTable.SetRowCount(0)534 f.Done()535 })536 q.Show()537 }538 if qtui.SettingsWindow.LoadProxiesFromAPI.IsChecked() {539 resp, err := http.Get(qtui.SettingsWindow.LineEdit.Text())540 if err != nil {541 qtui.SimpleMB(qtui.Main, "Failed to get proxylist\n"+err.Error(), "Error")542 return543 }544 defer resp.Body.Close()545 raw, err := ioutil.ReadAll(resp.Body)546 if err != nil {547 qtui.SimpleMB(qtui.Main, "Failed to get proxylist\n"+err.Error(), "Error")548 return549 }550 manager.PManager.Proxies = []*manager.Proxy{}551 manager.PManager.LoadScanner(bufio.NewScanner(bytes.NewReader(raw)), qtui.SettingsWindow.ProxyTypeComboBox.CurrentIndex())552 }553 go func() {554 defer func() {555 utils.Module = "Idle"556 }()557 f.Wait()558 utils.Module = "Exploiter"559 modules.Exploiter.Start(modules.Scraper.Urls)560 }()561 }562 })563 qtui.Main.ExploiterStopBtn.ConnectClicked(StopModules)564 viper.SetDefault("dumper.threads", 40)565 qtui.Main.DumperThreads.SetValue(viper.GetInt("dumper.threads"))566 qtui.Main.DumperThreads.ConnectValueChanged(func(i int) {567 viper.Set("dumper.threads", i)568 viper.WriteConfig()569 })570 viper.SetDefault("dumper.workers", 20)571 qtui.Main.DumperWorkers.SetValue(viper.GetInt("dumper.workers"))572 qtui.Main.DumperWorkers.ConnectValueChanged(func(i int) {573 viper.Set("dumper.workers", i)574 viper.WriteConfig()575 })576 viper.SetDefault("dumper.targeted", true)577 qtui.Main.DumperTargetedCheckbox.SetChecked(viper.GetBool("dumper.Targeted"))578 qtui.Main.DumperTargetedCheckbox.ConnectClicked(func(checked bool) {579 viper.Set("dumper.Targeted", checked)580 viper.WriteConfig()581 })582 viper.SetDefault("dumper.keepblanks", false)583 qtui.Main.DumperKeepBlanksCheckbox.SetChecked(viper.GetBool("dumper.KeepBlanks"))584 qtui.Main.DumperKeepBlanksCheckbox.ConnectClicked(func(checked bool) {585 viper.Set("dumper.KeepBlanks", checked)586 viper.WriteConfig()587 })588 qtui.Main.DumperLoadInjectablesBtn.ConnectClicked(func(bool) {589 wd, _ := os.Getwd()590 ofd := widgets.NewQFileDialog2(qtui.Main, "Select your Injectables", wd, "Text (*.txt)")591 ofd.Show()592 ofd.ConnectFileSelected(func(file string) {593 f, err := os.Open(file)594 if err != nil {595 return596 }597 scanner := bufio.NewScanner(f)598 for scanner.Scan() {599 inj := injection.ParseUrlString(scanner.Text())600 if inj != nil {601 modules.Exploiter.Injectables[inj.Base.Hostname()] = inj602 }603 }604 f.Close()605 //uiParseDorksTxtbx.SetPlainText(strings.Join(modules.Scraper.Urls, "\r\n"))606 modules.Dumper.Index = 0607 modules.AutoSheller.Index = 0608 })609 })610 qtui.Main.DumperClearInjectablesBtn.ConnectClicked(func(bool) {611 modules.Exploiter.Injectables = make(map[string]*injection.Injection)612 modules.Dumper.Index = 0613 modules.AutoSheller.Index = 0614 })615 qtui.Main.DumperStartBtn.ConnectClicked(func(bool) {616 if utils.Module != "Idle" && utils.Module != "Stopping" {617 go qtui.SimpleMB(qtui.Main, fmt.Sprintf("Already running module '%s'", utils.Module), "Error").Show()618 return619 }620 if len(modules.Exploiter.Injectables) == 0 {621 go qtui.SimpleMB(qtui.Main, "Please load or test injectables.", "Error").Show()622 } else {623 f := sync.WaitGroup{}624 if modules.Dumper.Index > 0 {625 f.Add(1)626 q := qtui.NewYesNo(qtui.Main, "Looks like you have another scrape paused, would you like to continue this?", "Just a moment")627 q.ConnectAccepted(func() {628 f.Done()629 })630 q.ConnectRejected(func() {631 modules.Scraper.Index = 0632 qtui.Main.DumperTableWidget.SetRowCount(0)633 f.Done()634 })635 q.Show()636 }637 if qtui.SettingsWindow.LoadProxiesFromAPI.IsChecked() {638 resp, err := http.Get(qtui.SettingsWindow.LineEdit.Text())639 if err != nil {640 qtui.SimpleMB(qtui.Main, "Failed to get proxylist\n"+err.Error(), "Error")641 return642 }643 defer resp.Body.Close()644 raw, err := ioutil.ReadAll(resp.Body)645 if err != nil {646 qtui.SimpleMB(qtui.Main, "Failed to get proxylist\n"+err.Error(), "Error")647 return648 }649 manager.PManager.Proxies = []*manager.Proxy{}650 manager.PManager.LoadScanner(bufio.NewScanner(bytes.NewReader(raw)), qtui.SettingsWindow.ProxyTypeComboBox.CurrentIndex())651 }652 go func() {653 defer func() {654 utils.Module = "Idle"655 }()656 utils.Module = "Dumper"657 var arr []*injection.Injection658 for _, inj := range modules.Exploiter.Injectables {659 arr = append(arr, inj)660 }661 f.Wait()662 modules.Dumper.Start(arr)663 }()664 }665 })666 qtui.Main.DumperStopBtn.ConnectClicked(StopModules)667 qtui.Main.DumperOpenAnalyzer.ConnectClicked(func(bool) {668 qtui.SingleSiteWindow.Show()669 })670 qtui.Main.DumperTableWidget.ConnectCustomContextMenuRequested(func(pos *core.QPoint) {671 if qtui.Main.DumperTableWidget.CurrentRow() == 0 {672 return673 }674 table := qtui.Main.DumperTableWidget675 index := table.CurrentRow()676 if injectable, ok := modules.Dumper.UIMap[index]; ok {677 menu := widgets.NewQMenu2(injectable.Base.String(), table)678 skip := menu.AddAction("Skip")679 skip.ConnectTriggered(func(bool) {680 injectable.SkipLock.Lock()681 defer injectable.SkipLock.Unlock()682 select {683 case <-injectable.Skip:684 return685 default:686 close(injectable.Skip)687 }688 })689 menu.Exec2(qtui.Main.DumperTableWidget.Viewport().MapToGlobal(pos), skip)690 menu.Show()691 menu.ActivateWindow()692 }693 })694 viper.SetDefault("dumper.minrows", false)695 qtui.Main.DumperMinRowsCheckbox.SetChecked(viper.GetBool("dumper.MinRows"))696 qtui.Main.DumperMinRowsCheckbox.ConnectClicked(func(checked bool) {697 viper.Set("dumper.MinRows", checked)698 viper.WriteConfig()699 })700 viper.SetDefault("dumper.minrowcount", 500)701 qtui.Main.DumperMinRowsSpinbox.SetValue(viper.GetInt("dumper.MinRowCount"))702 qtui.Main.DumperMinRowsSpinbox.ConnectValueChanged(func(i int) {703 viper.Set("dumper.MinRowCount", i)704 viper.WriteConfig()705 })706 viper.SetDefault("dumper.usedios", true)707 qtui.Main.DumperDIOSCheckbox.SetChecked(viper.GetBool("dumper.UseDIOS"))708 qtui.Main.DumperDIOSCheckbox.ConnectClicked(func(checked bool) {709 viper.Set("dumper.UseDIOS", checked)710 viper.WriteConfig()711 })712 qtui.DumperWhitelistWindow.ConnectAccepted(func() {713 viper.WriteConfig()714 })715 viper.SetDefault("dumper.autoskipval", 1000)716 qtui.Main.DumperAutoSkipSpinbox.SetValue(viper.GetInt("dumper.autoskipval"))717 qtui.Main.DumperAutoSkipSpinbox.ConnectValueChanged(func(i int) {718 viper.Set("dumper.autoskipval", i)719 viper.WriteConfig()720 })721 viper.SetDefault("dumper.autoskip", true)722 qtui.Main.DumperAutoSkip.SetChecked(viper.GetBool("dumper.autoskip"))723 qtui.Main.DumperAutoSkip.ConnectClicked(func(checked bool) {724 viper.Set("dumper.autoskip", checked)725 viper.WriteConfig()726 })727 qtui.Main.ChatSendMessage.ConnectClicked(func(bool) {728 if len(qtui.Main.ChatMessagebox.Text()) > 0 {729 err := client.XDGAPI.SendMessage(qtui.Main.ChatMessagebox.Text())730 if err != nil {731 qtui.SimpleMB(qtui.Main, err.Error(), "Error").Show()732 }733 qtui.Main.ChatMessagebox.SetText("")734 }735 })736 qtui.Main.ChatMessagebox.ConnectReturnPressed(func() {737 if len(qtui.Main.ChatMessagebox.Text()) > 0 {738 err := client.XDGAPI.SendMessage(qtui.Main.ChatMessagebox.Text())739 if err != nil {740 qtui.SimpleMB(qtui.Main, err.Error(), "Error").Show()741 }742 qtui.Main.ChatMessagebox.SetText("")743 }744 })745 viper.SetDefault("exploiter.DBMS.MySQL", true)746 qtui.Main.ExploiterMySQL.SetChecked(viper.GetBool("exploiter.DBMS.MySQL"))747 qtui.Main.ExploiterMySQL.ConnectClicked(func(checked bool) {748 viper.Set("exploiter.DBMS.MySQL", checked)749 viper.WriteConfig()750 })751 viper.SetDefault("exploiter.DBMS.Oracle", true)752 qtui.Main.ExploiterOracle.SetChecked(viper.GetBool("exploiter.DBMS.Oracle"))753 qtui.Main.ExploiterOracle.ConnectClicked(func(checked bool) {754 viper.Set("exploiter.DBMS.Oracle", checked)755 viper.WriteConfig()756 })757 viper.SetDefault("exploiter.DBMS.PostGreSQL", true)758 qtui.Main.ExploiterPostgreSQL.SetChecked(viper.GetBool("exploiter.DBMS.PostGreSQL"))759 qtui.Main.ExploiterPostgreSQL.ConnectClicked(func(checked bool) {760 viper.Set("exploiter.DBMS.PostGreSQL", checked)761 viper.WriteConfig()762 })763 viper.SetDefault("exploiter.DBMS.MSSQL", true)764 qtui.Main.ExploiterMSSQL.SetChecked(viper.GetBool("exploiter.DBMS.MSSQL"))765 qtui.Main.ExploiterMSSQL.ConnectClicked(func(checked bool) {766 viper.Set("exploiter.DBMS.MSSQL", checked)767 viper.WriteConfig()768 })769 viper.SetDefault("autosheller.ASP", false)770 qtui.Main.AutoShellASPCheckbox.Hide()771 qtui.Main.AutoShellASPCheckbox.SetChecked(viper.GetBool("autosheller.ASP"))772 qtui.Main.AutoShellASPCheckbox.ConnectClicked(func(checked bool) {773 viper.Set("autosheller.ASP", checked)774 viper.WriteConfig()775 })776 viper.SetDefault("autosheller.PHP", true)777 qtui.Main.AutoShellPHPCheckbox.SetChecked(viper.GetBool("autosheller.PHP"))778 qtui.Main.AutoShellPHPCheckbox.ConnectClicked(func(checked bool) {779 viper.Set("autosheller.PHP", checked)780 viper.WriteConfig()781 })782 viper.SetDefault("autosheller.key", "sdfadsgh4513sdGG435341FDGWWDFGDFHDFGDSFGDFSGDFG")783 qtui.Main.AutoShellKey.SetText(viper.GetString("autosheller.key"))784 qtui.Main.AutoShellKey.ConnectTextChanged(func(text string) {785 viper.Set("autosheller.key", text)786 viper.WriteConfig()787 })788 viper.SetDefault("autosheller.filename", "4O4.php")789 qtui.Main.AutoShellFile.SetText(viper.GetString("autosheller.filename"))790 qtui.Main.AutoShellFile.ConnectTextChanged(func(text string) {791 viper.Set("autosheller.filename", text)792 viper.WriteConfig()793 })794 qtui.Main.AutoShellLoadInjectablesBtn.ConnectClicked(func(bool) {795 wd, _ := os.Getwd()796 ofd := widgets.NewQFileDialog2(qtui.Main, "Select your Injectables", wd, "Text (*.txt)")797 ofd.Show()798 ofd.ConnectFileSelected(func(file string) {799 f, err := os.Open(file)800 if err != nil {801 return802 }803 scanner := bufio.NewScanner(f)804 for scanner.Scan() {805 inj := injection.ParseUrlString(scanner.Text())806 if inj != nil {807 modules.Exploiter.Injectables[inj.Base.Hostname()] = inj808 }809 }810 f.Close()811 //uiParseDorksTxtbx.SetPlainText(strings.Join(modules.Scraper.Urls, "\r\n"))812 modules.Dumper.Index = 0813 modules.AutoSheller.Index = 0814 })815 })816 qtui.Main.AutoShellClearInjectablesBtn.ConnectClicked(func(bool) {817 modules.Exploiter.Injectables = make(map[string]*injection.Injection)818 modules.Dumper.Index = 0819 modules.AutoSheller.Index = 0820 })821 qtui.Main.AutoShellStartBtn.ConnectClicked(func(bool) {822 if utils.Module != "Idle" && utils.Module != "Stopping" {823 qtui.SimpleMB(qtui.Main, fmt.Sprintf("Already running module '%s'", utils.Module), "Error")824 return825 }826 if len(modules.Exploiter.Injectables) == 0 {827 qtui.SimpleMB(qtui.Main, "Please load or test injectables.", "Error").Show()828 } else {829 f := sync.WaitGroup{}830 if modules.Scraper.Index > 0 {831 f.Add(1)832 q := qtui.NewYesNo(qtui.Main, "Looks like you have another run paused, would you like to continue this?", "Just a moment")833 q.ConnectAccepted(func() {834 f.Done()835 })836 q.ConnectRejected(func() {837 modules.AutoSheller.Index = 0838 modules.Dumper.Index = 0839 qtui.Main.AutoShellTable.ClearContents()840 qtui.Main.AutoShellTable.SetRowCount(0)841 f.Done()842 })843 q.Show()844 }845 go func() {846 defer func() {847 utils.Module = "Idle"848 }()849 utils.Module = "AutoSheller"850 f.Wait()851 var arr []*injection.Injection852 for _, inj := range modules.Exploiter.Injectables {853 arr = append(arr, inj)854 }855 modules.AutoSheller.Start(arr)856 }()857 }858 })859 viper.SetDefault("antipub.autosync", false)860 qtui.Main.AntipubAutoSync.SetChecked(viper.GetBool("antipub.autosync"))861 qtui.Main.AntipubAutoSync.ConnectClicked(func(checked bool) {862 viper.Set("antipub.autosync", checked)863 viper.WriteConfig()864 })865 viper.SetDefault("antipub.savepublic", false)866 qtui.Main.AntipubSavePublic.SetChecked(viper.GetBool("antipub.savepublic"))867 qtui.Main.AntipubSavePublic.ConnectClicked(func(checked bool) {868 viper.Set("antipub.savepublic", checked)869 viper.WriteConfig()870 })871 qtui.Main.AntipubClearUrls.ConnectClicked(func(bool) {872 modules.Scraper.Urls = make([]string, 0)873 })874 qtui.Main.AntipubLoadUrls.ConnectClicked(func(bool) {875 wd, _ := os.Getwd()876 ofd := widgets.NewQFileDialog2(qtui.Main, "Select your Urls", wd, "Text (*.txt)")877 ofd.Show()878 ofd.ConnectFileSelected(func(file string) {879 f, err := os.Open(file)880 if err != nil {881 return882 }883 scanner := bufio.NewScanner(f)884 for scanner.Scan() {885 modules.Scraper.Urls = append(modules.Scraper.Urls, scanner.Text())886 }887 f.Close()888 //uiParseDorksTxtbx.SetPlainText(strings.Join(modules.Scraper.Urls, "\r\n"))889 modules.Exploiter.Index = 0890 qtui.Main.AntipubLoaded.Display2(len(modules.Scraper.Urls))891 })892 })893 qtui.Main.AntipubExportDB.ConnectClicked(func(bool) {894 wd, _ := os.Getwd()895 sfd := widgets.NewQFileDialog2(qtui.Main, "Select your output file", wd, "Text (*.txt)")896 sfd.SetFileMode(widgets.QFileDialog__AnyFile)897 sfd.SetAcceptMode(widgets.QFileDialog__AcceptSave)898 sfd.Show()899 sfd.ConnectFileSelected(func(file string) {900 var err error901 var rows *sql.Rows902 switch modules.AntiPublic.GetSelected() {903 case modules.DOMAINS:904 rows, err = modules.AntiPublic.DB.Query("SELECT domain FROM domains")905 case modules.URLS:906 rows, err = modules.AntiPublic.DB.Query("SELECT url FROM urls")907 }908 if err != nil {909 qtui.SimpleMB(qtui.Main, "There was an error getting data from your db", "Error").Show()910 return911 }912 f, err := os.Create(file)913 if err != nil {914 qtui.SimpleMB(qtui.Main, "There was an error creating your output file.", "Error").Show()915 return916 }917 loading := qtui.SimpleMB(qtui.Main, "Exporting your database, please wait...", "Just a moment")918 loading.Show()919 var val string920 var index int921 for rows.Next() {922 index++923 if rows.Scan(&val) != nil {924 continue925 }926 f.WriteString(val + "\r\n")927 }928 loading.SetText(fmt.Sprintf("Successfully exported %d lines", index))929 })930 })931 qtui.Main.AntipubLinkMode.ConnectClicked(func(checked bool) {932 qtui.Main.AntipubDomainMode.SetChecked(false)933 })934 qtui.Main.AntipubDomainMode.ConnectClicked(func(checked bool) {935 qtui.Main.AntipubLinkMode.SetChecked(false)936 })937 qtui.Main.AntipubLoadToDB.ConnectClicked(func(bool) {938 wd, _ := os.Getwd()939 ofd := widgets.NewQFileDialog2(qtui.Main, "Select your list", wd, "Text (*.txt)")940 ofd.Show()941 ofd.ConnectFileSelected(func(file string) {942 i, err := modules.AntiPublic.LoadToDB(file)943 if err != nil {944 fmt.Println(err.Error())945 go qtui.SimpleMB(qtui.Main, "An error was encountered: "+err.Error(), "Error")946 return947 }948 qtui.SimpleMB(qtui.Main, fmt.Sprintf("Added %d rows to the database", i), "Loaded list to DB").Show()949 qtui.Main.AntipubDomainCount.Display2(modules.AntiPublic.Count("domains"))950 qtui.Main.AntipubLinkCount.Display2(modules.AntiPublic.Count("urls"))951 qtui.Main.AntipubSizeOnDisk.SetText(fmt.Sprintf("Size On Disk: %s", utils.ByteCountIEC(modules.AntiPublic.Size())))952 })953 })954 qtui.Main.AntipubStart.ConnectClicked(func(bool) {955 if utils.Module != "Idle" && utils.Module != "Stopping" {956 go qtui.SimpleMB(qtui.Main, fmt.Sprintf("Already running module '%s'", utils.Module), "Error").Show()957 return958 }959 if len(modules.Scraper.Urls) == 0 {960 go qtui.SimpleMB(qtui.Main, "Please load or scrape urls.", "Error").Show()961 return962 }963 go func() {964 defer func() {965 utils.Module = "Idle"966 }()967 utils.Module = "AntiPublic"968 modules.AntiPublic.Start(modules.Scraper.Urls)969 }()970 })971 qtui.Main.AntipubStop.ConnectClicked(StopModules)972 qtui.Main.AutoShellStopBtn.ConnectClicked(StopModules)973 qtui.Main.ActionExit.ConnectTriggered(func(bool) {974 qtui.Application.CloseAllWindowsDefault()975 })976 qtui.Main.ActionOpen_Settings.ConnectTriggered(func(bool) {977 qtui.SettingsWindow.Show()978 })979 qtui.Main.DumperTargetSettingsBtn.ConnectClicked(func(bool) {980 qtui.DumperWhitelistWindow.Show()981 })982 qtui.Main.ButtonParametersSettings.ConnectClicked(func(bool) {983 qtui.ParametersSettingsWindow.Show()984 })985 return qtui.Main986}...

Full Screen

Full Screen

config.go

Source:config.go Github

copy

Full Screen

1package config2import (3 "fmt"4 "log"5 "os"6 "path"7 "reflect"8 "github.com/mitchellh/go-homedir"9 "github.com/mitchellh/mapstructure"10 "github.com/spf13/viper"11)12var (13 // Main holds important settings like api keys14 Main *viper.Viper15)16// Init inits main viper17func Init() {18 Main = viper.New()19 home, err := homedir.Dir()20 if err != nil {21 log.Fatal(err)22 }23 configPath := (path.Join(home, "/.universe"))24 Main.SetConfigName("config")25 Main.AddConfigPath(configPath)26 Main.SetConfigType("yaml")27 err = Main.ReadInConfig()28 if err != nil {29 if _, err := os.Stat(configPath); os.IsNotExist(err) {30 if err := os.Mkdir(configPath, 0755); err != nil {31 log.Fatal(err)32 }33 }34 err := Main.WriteConfigAs(path.Join(configPath, "config.yml"))35 if err != nil {36 log.Fatal(err)37 }38 }39}40// DeleteKey deletes a key41func DeleteKey(key string) error {42 viper.Set(key, nil)43 return viper.WriteConfig()44}45// SetKeyValue sets the given key to value.46// Overrides the given key if it exists.47func SetKeyValue(key string, value interface{}) (interface{}, error) {48 return setKV(key, value, true)49}50// SetKeyValueSafe is like SetKeyValue, but will not override the key51// if it exists.52func SetKeyValueSafe(key string, value interface{}) (interface{}, error) {53 return setKV(key, value, false)54}55func setKV(key string, value interface{}, override bool) (interface{}, error) {56 val := viper.Get(key)57 if val == nil {58 viper.Set(key, value)59 return value, viper.WriteConfig()60 } else if override {61 viper.Set(key, value)62 return value, viper.WriteConfig()63 }64 return val, nil65}66func isNil(i interface{}) bool {67 if i == nil {68 return true69 }70 return reflect.ValueOf(i).IsZero()71}72// AddToArrayM is like AddToArray but for Main viper73func AddToArrayM(key string, value interface{}) (interface{}, error) {74 val := Main.Get(key)75 if isNil(val) {76 Main.Set(key, []interface{}{77 value,78 })79 return nil, Main.WriteConfig()80 }81 arr := val.([]interface{})82 arr = append(arr, value)83 Main.Set(key, arr)84 return arr, Main.WriteConfig()85}86// AddToArray adds a value to a given array and saves it to the current config file87func AddToArray(key string, value interface{}) (interface{}, error) {88 val := viper.Get(key)89 if isNil(val) {90 viper.Set(key, []interface{}{91 value,92 })93 return nil, viper.WriteConfig()94 }95 arr := val.([]interface{})96 arr = append(arr, value)97 viper.Set(key, arr)98 return arr, viper.WriteConfig()99}100// ExistsInArray checks if a given object with the respective searchKey/searchValue pairs exists101func ExistsInArray(key string, searchKey string, searchValue interface{}) (bool, error) {102 obj := viper.Get(key)103 if obj != nil && !reflect.ValueOf(obj).IsZero() {104 parsedObjects := []map[interface{}]interface{}{}105 err := mapstructure.Decode(obj, &parsedObjects)106 if err != nil {107 return false, err108 }109 for _, mapObj := range parsedObjects {110 if mapObj[searchKey] == searchValue {111 return true, nil112 }113 }114 }115 return false, nil116}117// SetArrayIDKeyValue sets key[id] = value118func SetArrayIDKeyValue(arrayKey string, id interface{}, key string, value interface{}) error {119 val := viper.Get(arrayKey)120 if val == nil {121 return fmt.Errorf("no valid element at key %s with id %s", key, id)122 }123 arr := val.([]interface{})124 for _, obj := range arr {125 objMap := obj.(map[interface{}]interface{})126 if objMap["id"] != nil {127 if objMap["id"] == id {128 objMap[key] = value129 viper.Set(arrayKey, arr)130 return viper.WriteConfig()131 }132 } else {133 return fmt.Errorf("key %s has no id key", key)134 }135 }136 return nil137}138// DeleteFromArray deletes a value from an array at the given key.139// Returns an error, if nothing found at the key.140func DeleteFromArray(key string, searchKey string, searchValue interface{}) error {141 val := viper.Get(key)142 if val == nil {143 return nil144 }145 findIndex := -1146 arr := val.([]interface{})147 for index, obj := range arr {148 objMap := obj.(map[interface{}]interface{})149 if objMap[searchKey] != nil {150 if objMap[searchKey] == searchValue {151 findIndex = index152 }153 }154 }155 if findIndex == -1 {156 return fmt.Errorf("%s = %s not found in %s", searchKey, searchValue, key)157 }158 if findIndex != -1 {159 copy(arr[findIndex:], arr[findIndex+1:]) // Shift arr[i+1:] left one index.160 arr[len(arr)-1] = "" // Erarrse larrst element (write zero varrlue).161 arr = arr[:len(arr)-1]162 }163 viper.Set(key, arr)164 return viper.WriteConfig()165}166// DeleteFromArrayM is like DeleteFromArray but for Main viper167func DeleteFromArrayM(key string, searchKey string, searchValue interface{}) error {168 val := Main.Get(key)169 if val == nil {170 return nil171 }172 findIndex := -1173 arr := val.([]interface{})174 for index, obj := range arr {175 objMap := obj.(map[interface{}]interface{})176 if objMap[searchKey] != nil {177 if objMap[searchKey] == searchValue {178 findIndex = index179 }180 }181 }182 if findIndex == -1 {183 return fmt.Errorf("%s = %s not found in %s", searchKey, searchValue, key)184 }185 if findIndex != -1 {186 copy(arr[findIndex:], arr[findIndex+1:]) // Shift arr[i+1:] left one index.187 arr[len(arr)-1] = "" // Erarrse larrst element (write zero varrlue).188 arr = arr[:len(arr)-1]189 }190 Main.Set(key, arr)191 return Main.WriteConfig()192}193// DeleteFromArrayMKey is like DeleteFromArray, but with multiple search key/value pairs194func DeleteFromArrayMKey(key string, searchKeys []string, searchValues []string) error {195 val := viper.Get(key)196 if val == nil {197 return nil198 }199 arr := val.([]interface{})200 for index, obj := range arr {201 objMap := obj.(map[interface{}]interface{})202 findIndex := -1203 delete := true204 for searchKeyIndex, searchKey := range searchKeys {205 if objMap[searchKey] != nil {206 if objMap[searchKey] == searchValues[searchKeyIndex] {207 findIndex = index208 } else {209 delete = false210 }211 }212 }213 if delete && findIndex != -1 {214 copy(arr[findIndex:], arr[findIndex+1:]) // Shift arr[i+1:] left one index.215 arr[len(arr)-1] = "" // Erarrse larrst element (write zero varrlue).216 arr = arr[:len(arr)-1]217 }218 viper.Set(key, arr)219 return viper.WriteConfig()220 }221 return nil222}...

Full Screen

Full Screen

writeConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println("new config failed, err:", err)6 }7 conf.Set("age", "18")8 conf.Set("name", "tom")9 conf.SaveConfigFile("conf/app.conf")10}11import (12func main() {13 conf, err := config.NewConfig("ini", "conf/app.conf")14 if err != nil {15 fmt.Println("new config failed, err:", err)16 }17 name := conf.String("name")18 age := conf.String("age")19 if len(name) == 0 {20 fmt.Println("name is empty")21 }22 fmt.Printf("name:%v, age:%v23}24import (25func main() {26 conf, err := config.NewConfig("ini", "conf/app.conf")27 if err != nil {28 fmt.Println("new config failed, err:", err)29 }30 name := conf.String("name")31 age := conf.String("age")32 if len(name) == 0 {33 fmt.Println("name is empty")34 }35 fmt.Printf("name:%v, age:%v36}37import (38func main() {39 conf, err := config.NewConfig("ini", "conf/app.conf")40 if err != nil {41 fmt.Println("new config failed, err:", err)42 }43 name := conf.String("name")44 age := conf.String("age")45 if len(name) == 0 {

Full Screen

Full Screen

writeConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 main.WriteConfig("config.json")5}6import (7func main() {8 fmt.Println("Hello World")9 main.ReadConfig("config.json")10}11import (12func main() {13 fmt.Println("Hello World")14 main.WriteConfig("config.json")15}16import (17func main() {18 fmt.Println("Hello World")19 main.ReadConfig("config.json")20}21import (22func main() {23 fmt.Println("Hello World")24 main.WriteConfig("config.json")25}26import (27func main() {28 fmt.Println("Hello World")29 main.ReadConfig("config.json")30}31import (32func main() {33 fmt.Println("Hello World")34 main.WriteConfig("config.json")35}36import (37func main() {38 fmt.Println("Hello World")39 main.ReadConfig("config.json")40}41import (42func main() {43 fmt.Println("Hello World")44 main.WriteConfig("config.json")45}46import (47func main() {48 fmt.Println("Hello World")49 main.ReadConfig("config.json")50}51import (

Full Screen

Full Screen

writeConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 func writeConfig() {3 }4}5func main() {6 func readConfig() {7 }8}9Syntax of import keyword:10import "package_name"11func main() {12 func writeConfig() {13 }14}15func main() {16 func readConfig() {17 }18}19func main() {20 func readConfig() {21 }22}23func main() {24 func writeConfig() {25 }26}27import "main"28func main() {29 func readConfig() {30 }31}32import "main"33func main() {34 func writeConfig() {35 }36}37In the above example, we have imported the main package in the 3.go and 4.go files. So, we can use the readConfig and

Full Screen

Full Screen

writeConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 main.WriteConfig()5}6import (7func main() {8 fmt.Println("Hello, playground")9 main.WriteConfig()10}11import (12func main() {13 fmt.Println("Hello, playground")14 main.WriteConfig()15}16import (17func main() {18 fmt.Println("Hello, playground")19 main.WriteConfig()20}21import (22func main() {23 fmt.Println("Hello, playground")24 main.WriteConfig()25}26import (27func main() {28 fmt.Println("Hello, playground")29 main.WriteConfig()30}31import (32func main() {33 fmt.Println("Hello, playground")34 main.WriteConfig()35}36import (37func main() {38 fmt.Println("Hello, playground")39 main.WriteConfig()40}41import (42func main() {43 fmt.Println("Hello, playground")44 main.WriteConfig()45}46import (47func main() {48 fmt.Println("Hello, playground")49 main.WriteConfig()50}51import (

Full Screen

Full Screen

writeConfig

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, World!")4 Config.WriteConfig("config.json", "sample")5}6import (7type Config struct {8}9func WriteConfig(filename string, database string) {10 file, _ := os.Create(filename)11 encoder := json.NewEncoder(file)12 config := Config{Database: database}13 encoder.Encode(config)14}15I'm very new to Go and was wondering if there is a way to simplify the import path to just main?

Full Screen

Full Screen

writeConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 var config = &Config{}3 config.WriteConfig()4}5func (config *Config) WriteConfig() {6 var configData = map[string]interface{}{}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful