Exemple #1
0
/*
 * Handle callback from parser.
 * @param mode int - parameter mode
 * @param param *Parameter - reference to new parameter
 * @return bool - successful operation?
 */
func callback(mode int, param *parser.Parameter) bool {
	// if parameter is specified
	if param != nil {

		// print incoming parameter
		logger.Printf(logger.DBG, "[sid.config] %d: `%s=%s`\n", mode, param.Name, param.Value)

		if mode != parser.LIST {
			switch param.Name {
			case "LogFile":
				CfgData.LogFile = param.Value
			case "LogToFile":
				CfgData.LogState = (param.Value == "ON")
			case "LogLevel":
				logger.SetLogLevelFromName(param.Value)
			case "CrtlPort":
				SetIntValue(&CfgData.CtrlPort, param.Value)
			case "CrtlAllow":
				CfgData.CtrlAllow = param.Value
			case "HttpPort":
				SetIntValue(&CfgData.HttpPort, param.Value)
			case "HttpAllow":
				CfgData.HttpAllow = param.Value
			case "UseSocks":
				CfgData.UseSocks = (param.Value == "ON")
			case "SocksAddr":
				CfgData.SocksAddr = param.Value
			case "Path":
				CfgData.Upload.Path = param.Value
			case "Keyring":
				CfgData.Upload.Keyring = param.Value
			case "SharePrimeOfs":
				SetIntValue(&CfgData.Upload.SharePrimeOfs, param.Value)
			case "ShareTreshold":
				SetIntValue(&CfgData.Upload.ShareTreshold, param.Value)
			default:
				if CustomConfigHandler != nil {
					return CustomConfigHandler(mode, param)
				}
			}
		} else {
			if CustomConfigHandler != nil {
				return CustomConfigHandler(mode, param)
			}
		}
	}
	return true
}
Exemple #2
0
/*
 * Handle client connection.
 * @param client net.Conn - connection to client
 */
func (c *ControlSrv) Process(client net.Conn) {

	b := bufio.NewReadWriter(bufio.NewReader(client), bufio.NewWriter(client))
	for repeat := true; repeat; {

		// show control menu
		b.WriteString("\n-----------------------------------\n")
		b.WriteString("Change (L)og level [" + logger.GetLogLevel() + "]\n")
		b.WriteString("(T)erminate application\n")
		b.WriteString("e(X)it\n")
		b.WriteString("-----------------------------------\n")
		b.WriteString("Enter command: ")
		b.Flush()

		// get command input
		cmd, err := readCmd(b)
		if err != nil {
			break
		}

		// handle command
		logger.Println(logger.INFO, "[sid.ctrl] command '"+cmd+"'")
		switch cmd {
		//-------------------------------------------------
		// Terminate application
		//-------------------------------------------------
		case "T":
			b.WriteString("Are you sure? Enter YES to continue: ")
			b.Flush()
			cmd, _ = readCmd(b)
			if cmd == "YES" {
				logger.Println(logger.WARN, "[sid.ctrl] Terminating application")
				b.WriteString("Terminating application...")
				b.Flush()
				c.Ch <- true
			} else {
				logger.Println(logger.WARN, "[sid.ctrl] Response '"+cmd+"' -- Termination aborted!")
				b.WriteString("Wrong response -- Termination aborted!")
				b.Flush()
			}

		//-------------------------------------------------
		// Change logging level
		//-------------------------------------------------
		case "L":
			b.WriteString("Enter new log level (ERROR,WARN,INFO,DBG_HIGH,DBG,DBG_ALL): ")
			b.Flush()
			cmd, _ = readCmd(b)
			logger.SetLogLevelFromName(cmd)

		//-------------------------------------------------
		//	Quit control session
		//-------------------------------------------------
		case "X":
			repeat = false

		//-------------------------------------------------
		//	Unknown command
		//-------------------------------------------------
		default:
			b.WriteString("Unkonwn command '" + cmd + "'\n")
		}
	}
	client.Close()
}