Ejemplo n.º 1
0
func eBackground(sess *agi.Session, dir string, phrases []string) {
	for _, phrase := range phrases {
		sess.Verbose("Phrase: " + phrase)
		_, err := sess.Exec("Background", fmt.Sprintf("%s%s", dir, phrase))
		if err != nil {
			LoggerErr(err)
		}
	}
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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)
		}
	}

}