예제 #1
0
파일: http.go 프로젝트: johnnywww/swd
func GetSessionUserInfoByForm(form url.Values) (userInfo *model.UserInfo, errorMsg string) {
	userInfo = nil
	username := form.Get("username")
	password := form.Get("password")
	if utils.IsEmptyStr(username) {
		errorMsg = "用户名为空"
		return
	}
	if utils.IsEmptyStr(password) {
		errorMsg = "密码为空"
		return
	}
	setupInfo := &model.SetupInfo{}
	if !model.NewSetupHandle().GetSetupInfo(setupInfo) {
		errorMsg = "没有配置信息,请找管理员"
		return
	}
	for _, userInfo1 := range setupInfo.Users {
		if userInfo1.Equal(username, password) {
			userInfo = &userInfo1
			break
		}
	}
	if nil == userInfo {
		errorMsg = "用户名或密码错误"
	}
	return userInfo, errorMsg
}
예제 #2
0
func (propertiesFileServiceImpl *propertiesFileServiceImpl) GetInfo(fileName string) (map[string]string, error) {
	if utils.IsEmptyStr(fileName) {
		return nil, errors.New("没有文件")
	}
	if !utils.IsFileExist(fileName) {
		return nil, errors.New(fmt.Sprintf("文件%s不存在", fileName))
	}
	fi, err := os.Open(fileName)
	if nil != err {
		return nil, err
	}
	defer fi.Close()
	r := bufio.NewReader(fi)
	result := make(map[string]string)
	for {
		//buf,err := r.ReadBytes('\n')
		str, err := r.ReadString('\n')
		if nil != err {
			if err == io.EOF {
				break
			}
			return nil, err
		}
		if !utils.IsEmptyStr(str) {
			strvs := strings.Split(str, "=")
			if len(strvs) > 1 {
			}
			result[strvs[0]] = strvs[1]
		}
	}
	return result, nil
}
예제 #3
0
func (getServerIdInfoImpl *getServerIdInfoImpl) getInfo(serverName string) (string, error) {
	result := ""
	serverInfo, vInfo, err := NewGetServerSetupInfo().GetInfo(serverName)
	if nil != err {
		return result, err
	}
	switch serverInfo.Type {
	case common.SERVER_TYPE_APS:
		{
			aPSServerSetupInfo := vInfo.(*model.APSServerSetupInfo)
			result = aPSServerSetupInfo.APSInfo.Id
			if utils.IsEmptyStr(result) {
				return result, errors.New(fmt.Sprintf("没有找到服务器程序%s对应的服务器编号", serverName))
			}
		}
	case common.SERVER_TYPE_SIP:
		{
			sIPServerSetupInfo := vInfo.(*model.SIPServerSetupInfo)
			result = sIPServerSetupInfo.SIPInfo.Id
			if utils.IsEmptyStr(result) {
				return result, errors.New(fmt.Sprintf("没有找到服务器程序%s对应的服务器编号", serverName))
			}
		}
	case common.SERVER_TYPE_MTS:
		{
			mTSServerSetupInfo := vInfo.(*model.MTSServerSetupInfo)
			result = mTSServerSetupInfo.MTSInfo.Id
			if utils.IsEmptyStr(result) {
				return result, errors.New(fmt.Sprintf("没有找到服务器程序%s对应的服务器编号", serverName))
			}
		}
	}
	return result, nil
}
예제 #4
0
func Test_GetSIPServerSetupInfo(t *testing.T) {
	setupInfo := &SIPServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/mnt/hgfs/Source/c++/iVideo/Source/SIPServer/config.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	if utils.IsEmptyStr(setupInfo.ActiveMQInfo.AddressInfo.IP) {
		t.Error("没有ActiveMQ地址")
	}
	if utils.IsEmptyStr(setupInfo.ActiveMQInfo.Topic) {
		t.Error("没有ActiveMQ主题")
	}
}
예제 #5
0
func (routeUserSave *RouteUserSave) Routes(m *martini.ClassicMartini) {
	m.Post("/user/save", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /user/save")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取用户信息失败")
		}
		r.ParseForm()
		log.WriteLog("user save %v", r.Form)
		ousername := r.Form.Get("ousername")
		username := r.Form.Get("username")
		addFlag := utils.IsEmptyStr(ousername)
		password := r.Form.Get("password")
		if utils.IsEmptyStr(username) {
			return model.GetErrorDtoJson("没有用户名称")
		}
		if utils.IsEmptyStr(password) {
			return model.GetErrorDtoJson("没有密码")
		}
		index := setupInfo.GetUserIndexByUserName(username)
		oindex := setupInfo.GetUserIndexByUserName(ousername)
		var pUserInfo *model.UserInfo = nil
		if addFlag {
			if index > -1 {
				return model.GetErrorDtoJson("用户名称输入重复")
			}
			userInfo := model.UserInfo{UserName: username, Password: password}
			setupInfo.AddUserInfo(userInfo)
			pUserInfo = &userInfo
		} else {
			if oindex < 0 {
				return model.GetErrorDtoJson("没有找到用户")
			} else {
				if index > -1 && oindex != index {
					return model.GetErrorDtoJson("用户名称输入重复")
				}
			}
			setupInfo.Users[oindex].UserName = username
			setupInfo.Users[oindex].Password = password
			pUserInfo = &setupInfo.Users[oindex]
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除用户信息失败")
			return model.GetErrorDtoJson("保存删除用信息失败")
		}
		return model.GetDataDtoJson(model.UserSaveInfo{UserInfo: *pUserInfo, OUserName: ousername, AddFlag: addFlag})
	})

}
예제 #6
0
func getCMSWebPath(cmdLine string) (string, error) {
	result := utils.GetFileDir(utils.GetFileDir(cmdLine))
	if utils.IsEmptyStr(result) {
		return result, errors.New("不是正确的中心管理服务器路径")
	}
	return result, nil
}
func (serverConfigSaveRequestHandleImpl *serverConfigSaveRequestHandleImpl) Save(r *http.Request) error {
	if nil == r {
		return errors.New("没有请求")
	}

	serverName := r.FormValue("servername")
	if utils.IsEmptyStr(serverName) {
		return errors.New("没有服务器名称")
	}
	serverInfo, err := NewGetServerInfoByServerName().getInfo(serverName)
	if nil != err {
		return err
	}
	err = NewServerConfigSaveHandle().Save(r, serverInfo)
	if nil != err {
		return err
	}
	processInfo, err := NewGetProcessInfoByServerInfo().GetInfo(serverInfo)
	if nil != processInfo {
		err = NewRestartServerProcessInfo().Restart(serverName, r.FormValue("oServerId"))
		if nil != err {
			return err
		}
	}
	return nil
}
예제 #8
0
func Test_GetMTSServerSetupInfo(t *testing.T) {
	setupInfo := &MTSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/mnt/hgfs/Source/c++/iVideo/Source/mts/config.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	if utils.IsEmptyStr(setupInfo.MTSInfo.AddressInfo.IP) {
		t.Error("没有服务器地址")
	}
	if utils.IsEmptyStr(setupInfo.SipServerInfo.AddressInfo.IP) {
		t.Error("没有SIP服务器地址")
	}
	if utils.IsEmptyStr(setupInfo.CMSServerInfo.Address) {
		t.Error("没有CMS地址")
	}
}
예제 #9
0
func (setupInfoServiceXmlImpl *setupInfoServiceXmlImpl) SaveSetupInfo(setupInfo interface{}, fileName string, encoding string) error {
	fout, err := os.Create(fileName)
	if nil != err {
		log.WriteLog("error: %v", err)
		return err
	}
	defer fout.Close()
	if nil == setupInfo {
		log.WriteLog("没有配置对象")
		return err
	}
	output, err := xml.MarshalIndent(setupInfo, "  ", "    ")
	if nil != err {
		log.WriteLog("error: %v\n", err)
		return err
	}
	head := `<?xml version="1.0" `
	if !utils.IsEmptyStr(encoding) {
		head = head + "encoding=\"" + encoding + "\""
	}
	head = head + "?>\n"
	fout.Write([]byte(head))
	if nil != setupInfoServiceXmlImpl.saveXMLContentBefore {
		err = setupInfoServiceXmlImpl.saveXMLContentBefore.saveContentBefore(setupInfo, fout)
		if nil != err {
			return err
		}
	}
	fout.Write(output)
	return nil
}
func (getAPSServerSetupInfoByConfigFile *getAPSServerSetupInfoByConfigFile) GetInfo(cfgFileName string) (interface{}, error) {
	var result interface{} = nil
	if utils.IsEmptyStr(cfgFileName) {
		return nil, errors.New("没有配置文件")
	}
	var aPSServerSetupInfo = model.APSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(&aPSServerSetupInfo, cfgFileName)
	if nil != err {
		return nil, err
	}
	result = &aPSServerSetupInfo
	if utils.IsEmptyStr(aPSServerSetupInfo.APSInfo.Id) {
		return nil, errors.New("配置文件格式不正确")
	}
	return result, nil
}
func (getServerStatusXMLInfoLinuxCommon *getServerStatusXMLInfoLinuxCommon) getInfo(serverId string) (*respQueryStatusXmlInfo, error) {
	if utils.IsEmptyStr(serverId) {
		return nil, errors.New("没有服务器编号")
	}
	respQueryStatusXmlInfo := respQueryStatusXmlInfo{}
	err := getAbstarctUnixSocketXMLInfo(serverId, common.SERVER_COMMAND_QUERYSTATUS, &respQueryStatusXmlInfo)
	return &respQueryStatusXmlInfo, err
}
예제 #12
0
func gotoServerInfo(w http.ResponseWriter, r *http.Request, re render.Render) {
	log.WriteLog("addr: /serverinfo")
	if !shttp.CheckSessionUserLogin(w, r) {
		gotoLoginPage(w, r, re)
		return
	}
	r.ParseForm()
	servername := r.FormValue("servername")
	if utils.IsEmptyStr(servername) {
		servername = getFirstServerName()
	}
	retInfos := make(map[string]string)
	retInfos["serverName"] = servername
	if utils.IsEmptyStr(servername) {
		retInfos["errorInfo"] = "没有服务器"
	}
	re.HTML(200, "serverInfo", retInfos)
}
예제 #13
0
func (getServerStatusXMLInfoImpl *getServerStatusXMLInfoImpl) getInfo(serverId string) (*respQueryStatusXmlInfo, error) {
	var getServerStatusXMLInfo GetServerStatusXMLInfo = nil
	if !utils.IsEmptyStr(serverId) {
		getServerStatusXMLInfo = &getServerStatusXMLInfoLinuxCommon{}
	} else {
		getServerStatusXMLInfo = &getServerStatusXMLInfoLinuxCMS{}
	}
	return getServerStatusXMLInfo.getInfo(serverId)
}
예제 #14
0
파일: route.go 프로젝트: johnnywww/swd
func checkLoginUser(form url.Values, re render.Render, errorUrl string) *model.UserInfo {
	result, errorMsg := shttp.GetSessionUserInfoByForm(form)
	retInfos := make(map[string]string)
	retInfos["userName"] = form.Get("username")
	retInfos["password"] = "******"
	if !utils.IsEmptyStr(errorMsg) {
		retInfos["errorInfo"] = errorMsg
		re.HTML(200, errorUrl, retInfos)
	}
	return result
}
예제 #15
0
func (routeServerList *RouteServerList) Routes(m *martini.ClassicMartini) {
	m.Get("/serverList", func(w http.ResponseWriter, r *http.Request, re render.Render) {
		log.WriteLog("addr: /serverList")

		serverName := getUniqueServerName()
		if utils.IsEmptyStr(serverName) {
			routeServerList.routeMoreServer(r, re)
		} else {
			gotoServerInfo(w, r, re)
		}

	})

}
func (quitServerProcessInfoLinuxCommon *quitServerProcessInfoLinuxCommon) Quit(serverInfo *model.ServerInfo, oServerId string) error {
	if common.SERVER_TYPE_CMS == serverInfo.Type {
		return errors.New("不支持的类型")
	}
	serverId := ""
	var err error = nil
	if !utils.IsEmptyStr(oServerId) {
		serverId = oServerId
	} else {
		_, err = NewGetProcessInfo().GetInfo(serverInfo.Address)
		if nil == err {
			serverId1, err := NewGetServerIdInfo().getInfo(serverInfo.ServerName)
			if nil != err {
				return err
			}
			if utils.IsEmptyStr(serverId1) {
				return errors.New(fmt.Sprintf("没有找到服务器程序%s对应的服务器编号", serverInfo.ServerName))
			}
			serverId = serverId1
		} else {
			return nil
		}
	}
	respQuitXmlInfo := respQuitXmlInfo{}
	err = getAbstarctUnixSocketXMLInfo(serverId, common.SERVER_COMMAND_QUIT, &respQuitXmlInfo)
	if nil != err {
		return err
	}
	if common.SERVER_COMMAND_QUIT != respQuitXmlInfo.CmdType {
		return errors.New("返回的命令不为退出命令")
	}
	if !processHandleTimerFunc(serverInfo.Address, 15, &processTimerFuncHandleQuitProc{}) {
		return errors.New(fmt.Sprintf("无法停止服务器%s程序", serverInfo.ServerName))
	}
	return nil
}
예제 #17
0
func (serverConfigSaveHandleAPSImpl *serverConfigSaveHandleAPSImpl) Save(r *http.Request, serverInfo *model.ServerInfo) error {
	if nil == r {
		return errors.New("没有请求")
	}
	setupInfo, err := NewGetServerDetailSetupInfo().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	apsSetupInfo := setupInfo.(*model.APSServerSetupInfo)
	apsSetupInfo.APSInfo.Id = r.FormValue("serverId")
	apsSetupInfo.APSInfo.Password = r.FormValue("password")
	apsSetupInfo.APSInfo.RegisterInterval, err = strconv.Atoi(r.FormValue("registerInterval"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.DefaultHeartInterval, err = strconv.Atoi(r.FormValue("defaultHeartInterval"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.AddressInfo.IP = r.FormValue("address")
	apsSetupInfo.APSInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("port"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.LogInfo.Logcfgfile = r.FormValue("logcfgfile")
	if utils.IsEmptyStr(apsSetupInfo.APSInfo.LogInfo.Logcfgfile) {
		return errors.New("没有日志配置文件")
	}
	if !utils.IsFileExist(utils.GetFileDir(serverInfo.Address) + "/" + apsSetupInfo.APSInfo.LogInfo.Logcfgfile) {
		return errors.New("日志配置文件不存在")
	}
	apsSetupInfo.APSInfo.LogInfo.SaveCatalog = r.FormValue("saveCatalog")
	apsSetupInfo.SipServerInfo.Id = r.FormValue("sipServerId")
	apsSetupInfo.SipServerInfo.Domain = r.FormValue("sipServerDomain")
	apsSetupInfo.SipServerInfo.AddressInfo.IP = r.FormValue("sipServerAddress")
	apsSetupInfo.SipServerInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("sipServerPort"))
	if nil != err {
		return err
	}
	apsSetupInfo.CMSServerInfo.Address = r.FormValue("cmsServerAddress")
	cfgFileName, err := NewGetServerInfoConfigFileName().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	err = setup.NewSetupInfoService().SaveSetupInfo(apsSetupInfo, cfgFileName, common.XML_ENCODE_GB2312)
	return err

}
예제 #18
0
func (routeServerConfigRoot *routeServerConfigRoot) Routes(m *martini.ClassicMartini) {
	m.Get("/serverconfig", func(w http.ResponseWriter, r *http.Request, re render.Render) string {
		log.WriteLog("addr: /serverconfig")
		shttp.SetResponseJsonHeader(w)
		r.ParseForm()
		serverName := r.FormValue("servername")
		if utils.IsEmptyStr(serverName) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		serverInfo, serverSetupInfo, err := service.NewGetServerSetupInfo().GetInfo(serverName)
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		return model.GetDataDtoJson([]interface{}{serverInfo, serverSetupInfo})
	})
}
func (getServerInfoConfigFileNameImpl *getServerInfoConfigFileNameImpl) GetInfo(serverInfo *model.ServerInfo) (string, error) {
	if nil == serverInfo {
		return "", errors.New("没有服务器对象")
	}
	var configFileName string = ""
	switch serverInfo.Type {
	case common.SERVER_TYPE_APS, common.SERVER_TYPE_MTS, common.SERVER_TYPE_SIP:
		configFileName = utils.GetServerConfigFileName(serverInfo.Address)
	case common.SERVER_TYPE_CMS:
		configFileName = getCMSConfigFileName(serverInfo.Address)
	}
	if utils.IsEmptyStr(configFileName) {
		return "", errors.New("不支持的服务器类型")
	}
	if !utils.IsFileExist(configFileName) {
		return "", errors.New("服务器配置文件不存在")
	}
	return configFileName, nil
}
func (getCMSServerSetupInfoByConfigFile *getCMSServerSetupInfoByConfigFile) GetInfo(cfgFileName string) (interface{}, error) {
	if utils.IsEmptyStr(cfgFileName) {
		return nil, errors.New("没有配置文件")
	}
	var cMSServerSetupInfo = model.CMSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(&cMSServerSetupInfo, cfgFileName)
	if nil != err {
		return nil, err
	}
	password, err := cMSServerSetupInfo.GetProperty("connection.password")
	if nil != err {
		return nil, errors.New("配置文件格式不正确")
	}
	result := make(map[string]string)
	result["dbPassword"] = password
	result["dbAddress"], _ = cMSServerSetupInfo.GetProperty("connection.url")
	result["dbUserName"], _ = cMSServerSetupInfo.GetProperty("connection.username")
	result["dbDefaultSchema"], _ = cMSServerSetupInfo.GetProperty("default_schema")
	return result, nil
}
예제 #21
0
func (propertiesFileServiceImpl *propertiesFileServiceImpl) SaveInfo(infos map[string]string, fileName string) error {
	if utils.IsEmptyStr(fileName) {
		return errors.New("没有文件")
	}
	fo, err := os.Create(fileName)
	if nil != err {
		return err
	}
	defer fo.Close()
	w := bufio.NewWriter(fo)
	for key, v := range infos {
		str := key + "=" + v + "\n"
		_, err = w.WriteString(str)
		if nil != err {
			return err
		}
	}
	err = w.Flush()
	return err
}
예제 #22
0
func (routeServerProcessInfo *RouteServerProcessInfo) Routes(m *martini.ClassicMartini) {
	m.Get("/server/info/process", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/info/process")
		shttp.SetResponseJsonHeader(w)
		r.ParseForm()
		serverName := r.FormValue("servername")
		if utils.IsEmptyStr(serverName) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		serverProcessInfo, err := service.NewGetServerProcessInfo().GetInfo(serverName)
		if nil != err {
			return model.GetErrorObjDtoJson(err)
		}
		result := map[string]string{}
		result["cpuRate"] = fmt.Sprintf("%.1f%%", serverProcessInfo.CPURate)
		result["memRate"] = fmt.Sprintf("%.1f%%", serverProcessInfo.MemRate)
		result["realMem"] = fmt.Sprintf("%s", utils.DisplaySizeStr(float64(serverProcessInfo.MemRealSize)))
		result["virtualMem"] = fmt.Sprintf("%s", utils.DisplaySizeStr(float64(serverProcessInfo.MemVmSize)))
		result["state"] = serverProcessInfo.State
		return model.GetDataDtoJson(result)
	})
}
예제 #23
0
func (routeServerSave *RouteServerSave) Routes(m *martini.ClassicMartini) {
	m.Post("/server/save", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/save")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取服务器信息失败")
		}
		r.ParseForm()
		log.WriteLog("server save %v", r.Form)
		oservername := r.Form.Get("oservername")
		servername := r.Form.Get("servername")
		addFlag := utils.IsEmptyStr(oservername)
		address := r.Form.Get("address")
		iType, err := strconv.Atoi(r.FormValue("servertype"))
		if nil != err {
			log.WriteLog("error: %v", err)
			iType = common.SERVER_TYPE_CMS
		}
		if utils.IsEmptyStr(servername) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		if utils.IsEmptyStr(address) {
			return model.GetErrorDtoJson("没有服务器地址")
		}
		index := setupInfo.GetServerIndexByServerName(servername)
		oindex := setupInfo.GetServerIndexByServerName(oservername)
		var pServerInfo *model.ServerInfo = nil
		if addFlag {
			if index > -1 {
				return model.GetErrorDtoJson("服务器名称输入重复")
			}
			serverInfo := model.ServerInfo{ServerName: servername, Address: address, Type: iType}
			setupInfo.AddServerInfo(serverInfo)
			pServerInfo = &serverInfo
		} else {
			if oindex < 0 {
				return model.GetErrorDtoJson("没有找到服务器")
			} else {
				if index > -1 && oindex != index {
					return model.GetErrorDtoJson("服务器名称输入重复")
				}
			}
			setupInfo.Servers[oindex].ServerName = servername
			setupInfo.Servers[oindex].Address = address
			setupInfo.Servers[oindex].Type = iType
			pServerInfo = &setupInfo.Servers[oindex]
		}
		if nil != routeServerSave.CheckServerSave {
			err := routeServerSave.CheckServerSave.CheckServerSave(oservername, pServerInfo)
			if nil != err {
				return model.GetErrorObjDtoJson(err)
			}
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除服务器信息失败")
			return model.GetErrorDtoJson("保存删除服务器信息失败")
		}
		return model.GetDataDtoJson(model.ServerSaveInfo{ServerInfo: *pServerInfo, OServerName: oservername, AddFlag: addFlag})
	})
}