コード例 #1
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func ConfBridgeChannelRedirect(sess *agi.Session) {
	confno, err := sess.GetVariable("CONFNO")
	if err != nil {
		LoggerErr(err)
	} else {
		if confno.Dat == sess.Env["callerid"] {
			bridgepeer, err := sess.GetVariable("BRIDGEPEER")
			if err != nil {
				LoggerErr(err)
			}
			var rc1 = make(map[string]string)
			rc1["Channel"] = sess.Env["channel"]
			rc1["Exten"] = confno.Dat
			rc1["Context"] = CONFBRIDGE_CONTEXT
			var rc2 = make(map[string]string)
			rc2["Channel"] = bridgepeer.Dat
			rc2["Exten"] = confno.Dat
			rc2["Context"] = CONFBRIDGE_CONTEXT
			ConfBridgeSettings(sess.Env["uniqueid"])
			RedirectChan(rc1)
			RedirectChan(rc2)
			LoggerString(fmt.Sprintf("Try create Confbridge CONFNO %s Channel1 %s Channel2 %s",
				confno.Dat, sess.Env["channel"], bridgepeer.Dat))
		}
	}
}
コード例 #2
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
//test
func checkIP(ipip string, sess *agi.Session) {
	useragent, err := sess.GetVariable("CHANNEL(useragent)")
	if err != nil {
		LoggerErr(err)
	}
	sipuri, err := sess.GetVariable("SIPURI")
	if err != nil {
		LoggerErr(err)
	}
	anet := false
	cip := net.ParseIP(ipip)
	for _, iprange := range ALLOW {
		ip, ipnet, err := net.ParseCIDR(iprange)
		if err != nil {
			LoggerErr(err)
		}
		for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
			if ip.String() == cip.String() {
				LoggerString("IP FROM ALLOW NETWORK " + ip.String())
				msg := fmt.Sprintf("User Agent: %s\nSIPURI: %s\nExtension: %s\nCallerid: %s",
					useragent.Dat, sipuri.Dat, sess.Env["extension"], sess.Env["callerid"])
				NotifyTG(msg)
				anet = true
				return
			}
		}
	}
	if anet == false {
		whoisIP(ipip)
	}
}
コード例 #3
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func FaxRecv(sess *agi.Session) {
	sess.Answer()
	uid := strings.Split(sess.Env["uniqueid"], ".")
	_, err := sess.SetVariable("FAXFILENAME", fmt.Sprintf("%s_%s_%s", sess.Env["callerid"], sess.Env["dnid"], uid[0]))
	_, err = sess.SetVariable("FAXOPT(headerinfo)", fmt.Sprintf("Received_by_%s_%s", sess.Env["callerid"], uid[0]))
	_, err = sess.SetVariable("FAXOPT(localstationid)", sess.Env["callerid"])
	_, err = sess.SetVariable("FAXOPT(maxrate)", "14400")
	_, err = sess.SetVariable("FAXOPT(minrate)", "4800")
	filename, err := sess.GetVariable("FAXFILENAME")
	_, err = sess.Exec("ReceiveFax", fmt.Sprintf(FAXDIR+FAXRECVSTR, filename.Dat))
	if err != nil {
		LoggerErr(err)
	} else {
		fs, err := sess.GetVariable("FAXSTATUS")
		fp, err := sess.GetVariable("FAXPAGES")
		fb, err := sess.GetVariable("FAXBITRATE")
		fr, err := sess.GetVariable("FAXRESOLUTION")
		if err != nil {
			LoggerErr(err)
		}
		if fs.Dat == "" || fs.Dat == "FAILED" {
			fs.Dat = "FAILED"
		}
		msg := fmt.Sprintf("Статус: %s\nС номера: %s\nНа номер: %s\nКоличество страниц: %s\nСкорость передачи(bitrate): %s\nРазрешение файла: %s",
			fs.Dat,
			sess.Env["callerid"],
			sess.Env["dnid"],
			fp.Dat,
			fb.Dat,
			fr.Dat)
		NotifyMail("ФаксВходящий", sess.Env["callerid"], msg, MAIL)
		NotifyMail("ФаксВходящий", sess.Env["callerid"], msg, "fax-"+sess.Env["dnid"])
	}
	sess.Hangup()
}
コード例 #4
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func agiSess(sess *agi.Session) {
	var err error
	startvar, err := sess.GetVariable("STARTVAR")
	if err == nil {
		switch startvar.Dat {
		case "inbound":
			InboundCall(sess)
		case "block":
			BanIpFromPSTN(sess)
		case "confbridge_access":
			ConfBridgeAccess(sess)
		case "confbridge_channelredirect":
			ConfBridgeChannelRedirect(sess)
		case "confbridge_confs":
			ConfBridgeConfs(sess)
		case "callback_call":
			CallbackCheck(sess)
		case "fax_receive":
			FaxRecv(sess)
		case "blocked_from_pstn":
			BlockedFromPSTN(sess)
		case "balance":
			BalanceInfo(sess)
		case "target_call":
			TargetCall(sess)
		case "call1":
			Call1(sess)
		case "customer_get_test_0":
			CustomerCheck(sess, "p")
		case "customer_get_test_1":
			CustomerCheck(sess, "c")
		case "queue_prio":
			QueuePrio(sess)
		case "ny":
			SetNY(sess)
		case "df":
			Gegensprechanlage(sess)
		default:
			sess.Verbose("DEFAULT STARTVAR")
		}
	}
	sess.Verbose("================== Complete ======================")
	sess.Verbose("STARTVAR IS " + startvar.Dat)
	return
}
コード例 #5
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func QueuePrio(sess *agi.Session) {
	var r = make(map[string]string)
	r[AMIVAR0[0]] = AMIVAR0[1]
	r[AMIVAR0[1]] = AMIVARUE0
	v6, err := sess.GetVariable(CUSTVARA6)
	v7, err := sess.GetVariable(CUSTVARA7)
	v8, err := sess.GetVariable(CUSTVARA8)
	if err != nil {
		LoggerErr(err)
	}
	r[AMIVARQ0[0]] = AMIVARQ0[1]
	r[AMIVARQ1] = sess.Env[CUSTVARC1]
	r[AMIVARQ2] = sess.Env[CUSTVARC2]
	r[AMIVARQ3] = sess.Env[CUSTVARC3]
	r[AMIVARQ6] = v6.Dat
	r[AMIVARQ7] = v7.Dat
	r[AMIVARQ8] = v8.Dat
	LoggerMap(r)
	amiAction(r)
}
コード例 #6
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func BanIpFromPSTN(sess *agi.Session) {
	useragent, err := sess.GetVariable("CHANNEL(useragent)")
	if err != nil {
		LoggerErr(err)
	} else {
		LoggerString("UserAgent " + useragent.Dat)
	}
	sipuri, err := sess.GetVariable("SIPURI")
	if err != nil {
		LoggerErr(err)
	} else {
		LoggerString("SIPURI " + sipuri.Dat)
	}
	var BAN = make(map[string]string)
	rex, err := regexp.Compile(`^sip:(\S*)\@(\S*)\:(\S*)$`)
	res := rex.FindStringSubmatch(sipuri.Dat)
	if res != nil {
		BAN["num"] = res[1]
		BAN["ip"] = res[2]
		BAN["port"] = res[3]
	}
	rex1, err := regexp.Compile(`^sip:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$`)
	res1 := rex1.FindStringSubmatch(sipuri.Dat)
	if res1 != nil {
		BAN["num"] = ""
		BAN["ip"] = res1[1]
		BAN["port"] = ""
	}
	rex2, err := regexp.Compile(`^sip:(\S*)\@(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$`)
	res2 := rex2.FindStringSubmatch(sipuri.Dat)
	if res2 != nil {
		BAN["num"] = res2[1]
		BAN["ip"] = res2[2]
		BAN["port"] = ""
	}
	LoggerMap(BAN)
	if err != nil {
		LoggerString("ERR")
	}
	checkIP(BAN["ip"], sess)
}
コード例 #7
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func CustomerGet(sess *agi.Session, cc string) ([]CustomerJ, error) {
	var q string
	if cc == "p" {
		q = fmt.Sprintf(CUSTURLQ0[0], sess.Env[CUSTVARC0])
	} else if cc == "c" {
		c, err := sess.GetVariable(CUSTVARA3)
		if err != nil {
			LoggerErr(err)
		} else {
			LoggerString(c.Dat)
		}
		q = fmt.Sprintf(CUSTURLQ0[1], c.Dat)
	}
	rsp, err := http.NewRequest(CUSTURL2[0], fmt.Sprintf(CUSTURL2[1], q), nil)
	rq, err := http.DefaultClient.Do(rsp)
	if err != nil {
		return nil, err
	}
	defer rq.Body.Close()
	body, err := ioutil.ReadAll(rq.Body)
	line := strings.Replace(string(body), CUSTVARR0[0], CUSTVARR0[1], -1)
	line = strings.Replace(string(line), CUSTVARR1[0], CUSTVARR1[1], -1)
	line = strings.Replace(string(line), CUSTVARR2[0], CUSTVARR2[1], -1)
	line = strings.Replace(string(line), CUSTVARR3[0], CUSTVARR3[1], -1)
	line = strings.Replace(string(line), CUSTVARR4[0], CUSTVARR4[1], -1)
	line = strings.Replace(string(line), CUSTVARR5[0], CUSTVARR5[1], -1)
	line = strings.Replace(string(line), CUSTVARR6[0], CUSTVARR6[1], -1)
	line = strings.Replace(string(line), CUSTVARR7[0], CUSTVARR7[1], -1)
	line = strings.Replace(string(line), CUSTVARR8[0], CUSTVARR8[1], -1)
	var customerJ []CustomerJ
	err = json.Unmarshal([]byte(line), &customerJ)
	if err != nil {
		return nil, err
	}
	return customerJ, nil
}
コード例 #8
0
ファイル: AGIServer.go プロジェクト: yosh0/agiserver
func BalanceInfo(sess *agi.Session) {
	b, err := sess.GetVariable(BALANCE)
	if err != nil {
		LoggerErr(err)
	} else {
		LoggerString(b.Dat)
	}
	c, err := sess.GetVariable(BALCONTRACT)
	if err != nil {
		LoggerErr(err)
	}
	sess.Verbose(fmt.Sprintf("BALANCE: %s %s %s", b.Dat, c.Dat, sess.Env["callerid"]))
	LoggerString(fmt.Sprintf("BALANCE: %s %s %s", b.Dat, c.Dat, sess.Env["callerid"]))
	bi, err := strconv.Atoi(b.Dat)
	sess.Verbose("BALANCE TO INT")
	bif, err := strconv.ParseFloat(b.Dat, 64)
	sess.Verbose(bi)
	sess.Verbose(bif)
	FILES := make([]string, 0)
	if bif < 0 {
		sess.Verbose("< 0")
		FILES = []string{BALNOMONEY, BALONCONRACT, BALMINUS}
		eBackground(sess, BALDIR, FILES)
		/*
			} else if bif > 0 && bif < 500 {
				sess.Verbose("0 > < 500")
				FILES = []string{BALONCONRACT}
				eBackground(sess, BALDIR, FILES)
			} else if bif > 500 {
				sess.Verbose("> 500")
				FILES = []string{BALRICH, BALONCONRACT}
				eBackground(sess, BALDIR, FILES)
		*/
	} else {
		sess.Verbose("ELSE")
		FILES = []string{BALONCONRACT}
		eBackground(sess, BALDIR, FILES)
	}
	bii := strconv.FormatFloat(bif, 'g', 10, 64)
	rex, err := regexp.Compile(`^(\d+)\.(\d{2})\d*$`)
	res := rex.FindStringSubmatch(bii)
	if res != nil {
		sess.Verbose(res[1] + " " + res[2])
		rub := res[1]
		kop := res[2]
		rex2, err := regexp.Compile(`^0(\d+)$`)
		res2 := rex2.FindStringSubmatch(kop)
		if res2 != nil {
			kop = res2[1]
		}
		if err != nil {
			LoggerErr(err)
		}
		BalanceDigits(sess, BALRUB, rub)
		BalanceDigits(sess, BALKOP, kop)
	}
	rex3, err := regexp.Compile(`^(\d+)\.(\d{1})$`)
	res3 := rex3.FindStringSubmatch(bii)
	if res3 != nil {
		sess.Verbose(res3[1] + " " + res3[2])
		rub := res3[1]
		kop := res3[2]
		BalanceDigits(sess, BALRUB, rub)
		BalanceDigits(sess, BALKOP, kop)
	}
	rex4, err := regexp.Compile(`^(\d+)$`)
	res4 := rex4.FindStringSubmatch(bii)
	if res4 != nil {
		sess.Verbose(res4[1])
		rub := res4[1]
		if rub == "0" {
			FILES = []string{"0", BALRUB + "-i", "0", BALKOP + "-k"}
			eBackground(sess, BALDDIR, FILES)
		} else {
			BalanceDigits(sess, BALRUB, rub)
		}
	}
	rex5, err := regexp.Compile(`^\-(\d+)\.(\d{2})\d*$`)
	res5 := rex5.FindStringSubmatch(bii)
	if res5 != nil {
		sess.Verbose(res5[1] + " " + res5[2])
		rub := res5[1]
		kop := res5[2]
		rex55, err := regexp.Compile(`^0(\d+)$`)
		res55 := rex55.FindStringSubmatch(kop)
		if res55 != nil {
			kop = res55[1]
		}
		if err != nil {
			LoggerErr(err)
		}
		BalanceDigits(sess, BALRUB, rub)
		BalanceDigits(sess, BALKOP, kop)
	}
	rex6, err := regexp.Compile(`^\-(\d+)$`)
	res6 := rex6.FindStringSubmatch(bii)
	if res6 != nil {
		sess.Verbose(res6[1])
		rub := res6[1]
		if rub == "0" {
			FILES = []string{"0", BALRUB + "-i", "0", BALKOP + "-k"}
			eBackground(sess, BALDDIR, FILES)
		} else {
			BalanceDigits(sess, BALRUB, rub)
		}
	}

}