<commit_before>package conf

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"os"
	"os/user"
	"strings"
	"time"

	"github.com/BurntSushi/toml"
	"github.com/blacknon/lssh/common"
)

type Config struct {
	Log      LogConfig
	Include  map[string]IncludeConfig
	Includes IncludesConfig
	Common   ServerConfig
	Server   map[string]ServerConfig
	Proxy    map[string]ProxyConfig
}

type LogConfig struct {
	Enable    bool   `toml:"enable"`
	Timestamp bool   `toml:"timestamp"`
	Dir       string `toml:"dirpath"`
}

type IncludesConfig struct {
	Path []string `toml:"path"`
}

type IncludeConfig struct {
	Path string `toml:"path"`
}

type ServerConfig struct {
	Addr              string   `toml:"addr"`
	Port              string   `toml:"port"`
	User              string   `toml:"user"`
	Pass              string   `toml:"pass"`
	Passes            []string `toml:"passes"`
	Key               string   `toml:"key"`
	KeyPass           string   `toml:"keypass"`
	Keys              []string `toml:"keys"` // "keypath::passphase"
	AgentAuth         bool     `toml:"agentauth"`
	SSHAgentUse       bool     `toml:"ssh_agent"`
	SSHAgentKeyPath   []string `toml:"ssh_agent_key"`   // "keypath::passphase"
	CommonAuthUse     string   `toml:"common_auth_use"` // yes|no (default: yes)
	PreCmd            string   `toml:"pre_cmd"`
	PostCmd           string   `toml:"post_cmd"`
	ProxyType         string   `toml:"proxy_type"`
	Proxy             string   `toml:"proxy"`
	LocalRcUse        string   `toml:"local_rc"` // yes|no (default: yes)
	LocalRcPath       []string `toml:"local_rc_file"`
	LocalRcDecodeCmd  string   `toml:"local_rc_decode_cmd"`
	PortForwardLocal  string   `toml:"port_forward_local"`  // port forward (local). "host:port"
	PortForwardRemote string   `toml:"port_forward_remote"` // port forward (remote). "host:port"
	Note              string   `toml:"note"`
}

type ProxyConfig struct {
	Addr string `toml:"addr"`
	Port string `toml:"port"`
	User string `toml:"user"`
	Pass string `toml:"pass"`
	Note string `toml:"note"`
}

func ReadConf(confPath string) (checkConf Config) {
	// user path
	usr, _ := user.Current()

	if !common.IsExist(confPath) {
		fmt.Printf("Config file(%s) Not Found.\nPlease create file.\n\n", confPath)
		fmt.Printf("sample: %s\n", "https://raw.githubusercontent.com/blacknon/lssh/master/example/config.tml")
		os.Exit(1)
	}

	// Read config file
	_, err := toml.DecodeFile(confPath, &checkConf)
	if err != nil {
		panic(err)
	}

	// reduce common setting (in .lssh.conf servers)
	for key, value := range checkConf.Server {<commit_msg>change<commit_after>package conf

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"os"
	"os/user"
	"strings"
	"time"

	"github.com/BurntSushi/toml"
	"github.com/blacknon/lssh/common"
)

type Config struct {
	Log      LogConfig
	Include  map[string]IncludeConfig
	Includes IncludesConfig
	Common   ServerConfig
	Server   map[string]ServerConfig
	Proxy    map[string]ProxyConfig
}

type LogConfig struct {
	Enable    bool   `toml:"enable"`
	Timestamp bool   `toml:"timestamp"`
	Dir       string `toml:"dirpath"`
}

type IncludesConfig struct {
	Path []string `toml:"path"`
}

type IncludeConfig struct {
	Path string `toml:"path"`
}

type ServerConfig struct {
	// Connect Setting
	Addr string `toml:"addr"`
	Port string `toml:"port"`
	User string `toml:"user"`

	// Connect auth Setting
	Pass            string   `toml:"pass"`
	Passes          []string `toml:"passes"`
	Key             string   `toml:"key"`
	KeyPass         string   `toml:"keypass"`
	Keys            []string `toml:"keys"` // "keypath::passphase"
	AgentAuth       bool     `toml:"agentauth"`
	SSHAgentUse     bool     `toml:"ssh_agent"`
	SSHAgentKeyPath []string `toml:"ssh_agent_key"`  // "keypath::passphase"
	PKCS11Provider  string   `toml:"pkcs11provider"` // PKCS11 Provider PATH
	PKCS11PIN       string   `toml:"pkcs11PIN"`      // PKCS11 PIN code

	// pre | post command setting
	PreCmd  string `toml:"pre_cmd"`
	PostCmd string `toml:"post_cmd"`

	// proxy setting
	ProxyType string `toml:"proxy_type"`
	Proxy     string `toml:"proxy"`

	// local rcfile setting
	LocalRcUse       string   `toml:"local_rc"` // yes|no (default: yes)
	LocalRcPath      []string `toml:"local_rc_file"`
	LocalRcDecodeCmd string   `toml:"local_rc_decode_cmd"`

	// port forwarding setting
	PortForwardLocal  string `toml:"port_forward_local"`  // port forward (local). "host:port"
	PortForwardRemote string `toml:"port_forward_remote"` // port forward (remote). "host:port"
	Note              string `toml:"note"`
}

type ProxyConfig struct {
	Addr string `toml:"addr"`
	Port string `toml:"port"`
	User string `toml:"user"`
	Pass string `toml:"pass"`
	Note string `toml:"note"`
}

func ReadConf(confPath string) (checkConf Config) {
	// user path
	usr, _ := user.Current()

	if !common.IsExist(confPath) {
		fmt.Printf("Config file(%s) Not Found.\nPlease create file.\n\n", confPath)
		fmt.Printf("sample: %s\n", "https://raw.githubusercontent.com/blacknon/lssh/master/example/config.tml")
		os.Exit(1)
	}

	// Read config file
	_, err := toml.DecodeFile(confPath, &checkConf)
	if err != nil {
		panic(err)
	}

	// reduce common setting (in .lssh.conf servers)
	for key, value := range checkConf.Server {
{'fraction_non_alphanumeric': 0.1357622243528284, 'fraction_numerical': 0.0030680728667305847, 'mean_word_length': 3.3648535564853557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2790412', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1796, 'n_words': 417}