99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package catalog
|
||
|
||
import (
|
||
"bufio"
|
||
"fmt"
|
||
"rubric/modules/infosecmodules"
|
||
"rubric/utils"
|
||
"strconv"
|
||
"strings"
|
||
)
|
||
|
||
var InfoSecBook = Book{
|
||
Key: "infosec",
|
||
Aliases: []string{"sec", "security", "is"},
|
||
Title: "Справочник по InfoSec",
|
||
Description: "Основы ИБ, криптография, PKI/TLS, сетевая безопасность, OWASP, hardening, инструменты",
|
||
Run: runInfoSecBook,
|
||
}
|
||
|
||
func runInfoSecBook(scanner *bufio.Scanner) {
|
||
for {
|
||
showInfoSecMenu()
|
||
input, ok := ReadLine(scanner)
|
||
if !ok {
|
||
return
|
||
}
|
||
if input == "" {
|
||
continue
|
||
}
|
||
if IsQuit(input) {
|
||
fmt.Printf("\n %s%sДо свидания!%s\n\n", utils.ColorBold, utils.ColorCyan, utils.ColorReset)
|
||
return
|
||
}
|
||
if IsBack(input) {
|
||
return
|
||
}
|
||
if n, err := strconv.Atoi(input); err == nil {
|
||
if n >= 1 && n <= len(infosecmodules.All) {
|
||
infosecmodules.All[n-1].Run()
|
||
waitInfoSecBack(scanner)
|
||
continue
|
||
}
|
||
fmt.Printf("\n %s%sНомер %d вне диапазона (1–%d)%s\n",
|
||
utils.ColorBold, utils.ColorRed, n, len(infosecmodules.All), utils.ColorReset)
|
||
continue
|
||
}
|
||
if m, ok := infosecmodules.Find(input); ok {
|
||
m.Run()
|
||
waitInfoSecBack(scanner)
|
||
continue
|
||
}
|
||
fmt.Printf("\n %s%sНе понял '%s'. Номер, ключ раздела, b — назад.%s\n",
|
||
utils.ColorBold, utils.ColorRed, input, utils.ColorReset)
|
||
}
|
||
}
|
||
|
||
func showInfoSecMenu() {
|
||
utils.Header("Справочник InfoSec")
|
||
fmt.Printf(" %s%sРазделы:%s\n\n", utils.ColorBold, utils.ColorWhite, utils.ColorReset)
|
||
for i, m := range infosecmodules.All {
|
||
aliases := ""
|
||
if len(m.Aliases) > 0 {
|
||
aliases = fmt.Sprintf("%s [%s]%s", utils.ColorDim, strings.Join(m.Aliases, ", "), utils.ColorReset)
|
||
}
|
||
fmt.Printf(" %s%s %2d.%s %s%-12s%s %s%-30s%s%s\n",
|
||
utils.ColorBold, utils.ColorCyan, i+1, utils.ColorReset,
|
||
utils.ColorYellow+utils.ColorBold, m.Key, utils.ColorReset,
|
||
utils.ColorWhite, m.Title, utils.ColorReset, aliases)
|
||
fmt.Printf(" %s%s%s\n\n", utils.ColorDim, m.Description, utils.ColorReset)
|
||
}
|
||
fmt.Printf(" %s%sРаздел (номер / ключ / b — главное меню / q — выход):%s ",
|
||
utils.ColorBold, utils.ColorGreen, utils.ColorReset)
|
||
}
|
||
|
||
type infosecBackSignal struct{}
|
||
|
||
func waitInfoSecBack(scanner *bufio.Scanner) {
|
||
fmt.Printf("\n %s%s[Enter — назад в меню InfoSec, b — главное меню]%s ",
|
||
utils.ColorDim, utils.ColorCyan, utils.ColorReset)
|
||
if scanner.Scan() {
|
||
if IsBack(strings.TrimSpace(scanner.Text())) {
|
||
panic(infosecBackSignal{})
|
||
}
|
||
}
|
||
}
|
||
|
||
func init() {
|
||
orig := InfoSecBook.Run
|
||
InfoSecBook.Run = func(scanner *bufio.Scanner) {
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
if _, ok := r.(infosecBackSignal); !ok {
|
||
panic(r)
|
||
}
|
||
}
|
||
}()
|
||
orig(scanner)
|
||
}
|
||
}
|