Ejemplo n.º 1
0
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()
}
Ejemplo n.º 2
0
func ConfBridgeAccess(sess *agi.Session) {
	sess.Answer()
	_, err := sess.SetVariable("__CONFNO", sess.Env["extension"])
	if err != nil {
		LoggerErr(err)
	}
	_, err = sess.SetVariable("__DYNAMIC_FEATURES", CONFBRIDGE_FEATURES)
	if err != nil {
		LoggerErr(err)
	}
	if sess.Env["extension"] == sess.Env["callerid"] {
		inner_num, err := strconv.Atoi(LEN_INNER_NUM)
		if len(sess.Env["callerid"]) == inner_num {
			_, err = sess.Exec("ConfBridge", fmt.Sprintf("%s,,,%s", sess.Env["extension"], AMENU))
		} else {
			_, err = sess.Exec("ConfBridge", fmt.Sprintf("%s,,,%s", sess.Env["extension"], UMENU))
		}
		if err != nil {
			LoggerErr(err)
		}
	} else {
		_, err = sess.Exec("ConfBridge", fmt.Sprintf("%s,,,%s", sess.Env["extension"], UMENU))
	}
	if err != nil {
		LoggerErr(err)
	}
	LoggerString("Confbridge Admin " + sess.Env["extension"])
}
Ejemplo n.º 3
0
func ConfBridgeConfs(sess *agi.Session) {
	_, err := sess.Exec("DumpChan", "255")
	if err != nil {
		LoggerErr(err)
	}
	_, err = sess.SetVariable("__CONFNO", sess.Env["extension"])
	if err != nil {
		LoggerErr(err)
	}
	_, err = sess.Exec("ConfBridge", fmt.Sprintf("%s,,,%s", sess.Env["extension"], UMENU))
	if err != nil {
		LoggerErr(err)
	}
	LoggerString("Confbridge Admin add " + sess.Env["extension"])
}
Ejemplo n.º 4
0
func InboundCall(sess *agi.Session) {
	//	LoggerString("INCOMING NUM    " + sess.Env["callerid"])
	rex, err := regexp.Compile(`^[7|8](\d{10})$`)
	res := rex.FindStringSubmatch(sess.Env["callerid"])
	if res != nil {
		LoggerString("RES NOT NIL " + sess.Env["callerid"])
		_, err := sess.SetVariable("CALLERID(num)", res[1])
		if err != nil {
			LoggerErr(err)
		} else {
			LoggerString("NUM CHANGED TO  " + res[1])
		}
		_, err = sess.SetVariable("CALLERID(name)", res[1])
		if err != nil {
			LoggerErr(err)
		}
	} else {
		//		LoggerString("NUM NOT CHANGED " + sess.Env["callerid"])
	}
	if err != nil {
		LoggerErr(err)
	}
	rex2, err := regexp.Compile(`^([a|A]nonymous|unknown)$`)
	res2 := rex2.FindStringSubmatch(sess.Env["calleridname"])
	if res2 != nil {
		LoggerString("RES2 " + res2[1])
		_, err := sess.SetVariable("CALLERID(name)", "0")
		if err != nil {
			LoggerErr(err)
		} else {
			LoggerString("NAME CHANGED TO 0")
		}
	}
	rex3, err := regexp.Compile(`^([a|A]nonymous|unknown)$`)
	res3 := rex3.FindStringSubmatch(sess.Env["callerid"])
	if res3 != nil {
		LoggerString("RES3 " + res3[1])
		_, err := sess.SetVariable("CALLERID(num)", "0")
		if err != nil {
			LoggerErr(err)
		} else {
			LoggerString("NUM CHANGED TO 0")
		}
	}
}
Ejemplo n.º 5
0
func CustomerCheck(sess *agi.Session, cc string) {
	CSTMR := make(map[int][]map[string]string)
	customer, err := CustomerGet(sess, cc)
	if err != nil {
		fmt.Println(err.Error())
	} else {
		i := 0
		for _, cust := range customer {
			cstmr := make(map[string]string)
			if cust.Var6 == "2" && cust.Var3 == "0" {
				if sess.Env[CUSTVARC0] != cust.Var7[1:] {
					LoggerString(fmt.Sprintf("%s != %s %s", sess.Env[CUSTVARC0], cust.Var7[1:], "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"))
				}
				cstmr[CUSTVARR0[0]] = cust.Var0
				cstmr[CUSTVARR1[0]] = cust.Var1
				cstmr[CUSTVARR2[0]] = cust.Var2
				cstmr[CUSTVARR3[0]] = cust.Var3
				cstmr[CUSTVARR4[0]] = cust.Var4
				cstmr[CUSTVARR5[0]] = cust.Var5
				cstmr[CUSTVARR6[0]] = cust.Var6
				cstmr[CUSTVARR7[0]] = cust.Var7
				cstmr[CUSTVARR8[0]] = cust.Var8
				LoggerString("\n" +
					CUSTVARC0 + " " + sess.Env[CUSTVARC0] + "\n" +
					CUSTVARR0[0] + " " + cust.Var0 + "\n" +
					CUSTVARR1[0] + " " + cust.Var1 + "\n" +
					CUSTVARR2[0] + " " + cust.Var2 + "\n" +
					CUSTVARR3[0] + " " + cust.Var3 + "\n" +
					CUSTVARR4[0] + " " + cust.Var4 + "\n" +
					CUSTVARR5[0] + " " + cust.Var5 + "\n" +
					CUSTVARR6[0] + " " + cust.Var6 + "\n" +
					CUSTVARR7[0] + " " + cust.Var7[1:] + "\n" +
					CUSTVARR8[0] + " " + cust.Var8 + "\n")
				CSTMR[i] = append(CSTMR[i], cstmr)
				i++
			}
		}
		ii := strconv.Itoa(i)
		if i == 1 {
			/*
				_, err := sess.SetVariable(CUSTVARA0, ii)
			*/

			_, err = sess.SetVariable(CUSTVARA1, CSTMR[0][0][CUSTVARR1[0]])
			/*
				_, err = sess.SetVariable(CUSTVARA2, CSTMR[0][0][CUSTVARR2[0]])
				_, err = sess.SetVariable(CUSTVARA5, CSTMR[0][0][CUSTVARR5[0]])
			*/
			if err != nil {
				LoggerErr(err)
			}
			LoggerString("\n===================================================\n" +
				CUSTVARA0 + " " + ii + "\n" +
				CUSTVARA1 + " " + CSTMR[0][0][CUSTVARR1[0]] + "\n" +
				CUSTVARA2 + " " + CSTMR[0][0][CUSTVARR2[0]] + "\n" +
				CUSTVARA5 + " " + CSTMR[0][0][CUSTVARR5[0]] + "\n" +
				CUSTVARR0[0] + " Count: " + ii + "\n" +
				"===================================================\n")
		} else if i > 1 {
			/*
				_, err := sess.SetVariable(CUSTVARA0, ii)
				if err != nil {
					LoggerErr(err)
				}
			*/
			LoggerString("\n===================================================\n")
			LoggerString(CUSTVARA0 + " " + ii)
			/*
			   			for _, vr := range CSTMR {
			   				LoggerString("++++++!!!!!!!!!!!!!!!!")
			   //				LoggerMap2(vr)

			   				if vr[0][CUSTVARR5[0]] == "1" {
			   					LoggerString(vr[0][CUSTVARR5[0]])
			   					_, err = sess.SetVariable(CUSTVARA5, CSTMR[0][0][CUSTVARR5[0]])
			   					if err != nil {
			   						LoggerErr(err)
			   					}
			   				}

			   				LoggerString("++++++!!!!!!!!!!!!!!!!")
			   			}
			*/
			LoggerString(CUSTVARR0[0] + " Count: " + ii + "\n" +
				"===================================================\n")
		} else {
			LoggerString("\n===================================================\n" +
				CUSTVARC0 + " " + sess.Env[CUSTVARC0] + "\n" +
				CUSTVARR0[0] + " Count: " + ii + "\n" +
				"===================================================\n")
			/*
				_, err = sess.SetVariable(CUSTVARA0, "0")
			*/
			_, err = sess.SetVariable(CUSTVARA1, "0")
			/*
				_, err = sess.SetVariable(CUSTVARA2, "N")
				_, err = sess.SetVariable(CUSTVARA5, "N")
			*/
			if err != nil {
				LoggerErr(err)
			}
		}
	}
}