Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#!/usr/bin/perl use DBI; use JSON; use Number; use strict; use Asterisk::AGI; use LWP::UserAgent; use constant TIMEOUT => 5; my $AGI = new Asterisk::AGI; my %input = $AGI->ReadParse(); my $callerid = $input{'callerid'}; $callerid =~ s/^7//g; my ($db_failed, $skeep); my $db_bill = DBI->connect("DBI:mysql:database=bill;host=xxxx","xxx","xxx", {mysql_connect_timeout => 3}) or $db_failed = 1; my $db_convex = DBI->connect("DBI:mysql:database=traffstat;host=xxxx","xxx","xxx", {mysql_connect_timeout => 3}) or $db_failed = 1; if ($db_failed) { $AGI->verbose("Db connect failed"); $AGI->exec('Goto', "cl_Callcenter,3820382,1"); exit(0); } if (!(($callerid =~ /343\d{7}/) || ($callerid =~ /9\d{9}/))) { $AGI->verbose("Invalid Number"); $AGI->exec('Goto', "cl_Callcenter,3820382,1"); exit(0); } my $limit_input = 0; my ($buh_id) = getBuhId($callerid); unless ($buh_id) { INPUT_BUHID: $AGI->exec('Playback', 'ivr_new/Наберите_9_цифр'); $buh_id = $AGI->get_data('beep',10000,9); $AGI->verbose("Input digits: $buh_id"); $skeep = 1; $limit_input++; } if (!$skeep) { $AGI->exec('Background', "ivr_new/Приветствие&ivr_new/Все_разговоры_записываются"); } my ($address_building_id, $client_contract_id) = getInfo($buh_id); my ($ip) = getClientIp($address_building_id, $client_contract_id); my ($node_status) = getNodeStatus($ip); my ($node_order) = getOrderOnNode($address_building_id); my ($av_funds, $balance) = getBalance($buh_id); if (!$address_building_id) { $AGI->verbose("Not found buh_id"); if ($limit_input >= 3) { $AGI->verbose("Input limit exceeded"); $AGI->exec('Goto', "cl_Callcenter,3820382,1"); exit(0); } goto INPUT_BUHID; } $AGI->verbose("buh_id: $buh_id, ip: $ip, node_status: $node_status, ab_id: $address_building_id, cc_id: $client_contract_id, balance: $balance"); #если узел абона лежит if ($node_status eq 'CRITICAL') { createOrder($buh_id, $callerid); $AGI->exec('Goto', "cl_Callcenter,3820382,1"); exit(0); } #если нет лавэшки if ($av_funds <= 0) { playBalance($buh_id, $balance); $AGI->exec('Goto', "cl_Callcenter,3820382,1"); exit(0); } #если узел ОК & баланс OK $AGI->exec('Background', "ivr_new/Заявка_в_автоматическом_режиме&ivr_new/2"); my $step = $AGI->wait_for_digit(5000); $step = chr($step); if ($step == 2) { $AGI->exec('Goto', 'ivr_test,s,1'); exit(0); } #redirect к ТП2 $AGI->exec('Goto', "cl_Callcenter,5666,1"); exit(0); sub createOrder() { my ($buh_id, $callerid) = @_; my $browser = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 },); my $res = $browser->post("https://xxxxx/rpc?func=order_add_ivr", [ 'ls' => $buh_id, 'phone' => $callerid, 'contact' => $callerid, 'serv' => 1, 'do_sms_inform' => 1, 'rpc_passwd' => 'xxxx', ] ); if ($res->is_success) { my $orders_id = $res->content; if ($orders_id =~ m/^\d+$/) { $AGI->exec('Playback', 'ivr_new/Зафиксирована_авария'); my @orders_id_digits = split //, $orders_id; foreach my $digit (@orders_id_digits) { $AGI->exec('Playback', "ivr_new/$digit"); } } } else { $AGI->exec('Goto', "cl_Callcenter,3820382,1"); exit(0); } } sub playBalance() { my ($buh_id, $balance) = @_; $AGI->exec('Playback', 'ivr_new/Номер_лицевого_счёта'); if ($buh_id =~ /(\d{3})(\d{3})(\d{3})/) { my $part1 = $1; my $part2 = $2; my $part3 = $3; my @buh_id_parts = ($part1, $part2, $part3); foreach my $part (@buh_id_parts) { $AGI->verbose("Buh_id part: $part"); my $buh_id_word = Number::in_words($part, undef); my @buh_id_digits = split / /, $buh_id_word; foreach my $digit (@buh_id_digits) { $AGI->exec('Playback', "$digit"); } } } $AGI->exec('Playback', 'ivr_new/Недостаточно_средств'); $AGI->exec('Playback', 'ivr_new/Ваш_баланс'); $balance =~ s/-//g; my $balance_word = Number::in_words($balance, 1); my @balance_digits = split / /, $balance_word; $AGI->exec('Playback', "minus") unless ($balance == 0); foreach my $digit (@balance_digits) { $AGI->exec('Playback', "$digit"); } $AGI->exec('Playback', 'ivr_new/Необходимо_пополнить_баланс'); } sub getBuhId() { my $callerid = shift; my $q_get_buhid = $db_bill->prepare(" SELECT cc.buh_id FROM client_tel ct JOIN client_contract cc ON cc.client_id=ct.client_id WHERE (tel = ? OR tel1 = ? OR tel2 = ? OR tel3 = ? OR tel4 = ?) AND ( cc.buh_id LIKE '11%' OR cc.buh_id LIKE '13%' OR cc.buh_id LIKE '15%' OR cc.buh_id LIKE '17%' OR cc.buh_id LIKE '43%' OR cc.buh_id LIKE '19%' OR cc.buh_id LIKE '31%' OR cc.buh_id LIKE '35%' OR cc.buh_id LIKE '39%' OR cc.buh_id LIKE '37%' ) GROUP BY cc.address_building_id"); $q_get_buhid->execute( $callerid, $callerid, $callerid, $callerid, $callerid ); my @result = $q_get_buhid->fetchrow_array(); return '' if (!@result); return @result; } sub getInfo() { my $buh_id = shift; return '' unless($buh_id); my $q_get_info = $db_bill->prepare(" SELECT address_building_id, client_contract_id FROM client_contract where buh_id = ?"); $q_get_info->execute( $buh_id ); my @result = $q_get_info->fetchrow_array(); return '' if (!@result); return @result; } sub getClientIp() { my ($address_building_id, $client_contract_id) = @_; my $q_get_ip = $db_bill->prepare(" SELECT s_ip.addr FROM client_contract cc JOIN services s ON s.client_contract_id = cc.client_contract_id LEFT JOIN services_ip s_ip ON s_ip.services_id=s.services_id WHERE s.address_building_id = ? AND cc.client_contract_id= ? AND s_ip.addr IS NOT NULL"); $q_get_ip->execute( $address_building_id, $client_contract_id ); my @result = $q_get_ip->fetchrow_array(); return '' if (!@result); return @result; } sub getNodeStatus() { my $ip = shift; my $browser = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0, timeout => TIMEOUT }); my $res = $browser->post("https://bill.ural.ru/rpc?func=node_status", [ 'rpc_passwd' => 'd38e5a13', 'ip' => $ip ] ); if ($res->is_success) { my $result = decode_json($res->content); if ($result->{errno} == 0) { if ($result->{0} =~ /^(\w+)/) { return $1; } } } else { return ''; } } sub getOrderOnNode() { my $address_building_id = shift; my $q_get_order = $db_bill->prepare(" SELECT orders_id FROM orders WHERE address_building_id = ? AND orders_type_id = 534 and status not in (2,3)"); $q_get_order->execute( $address_building_id ); my @result = $q_get_order->fetchrow_array(); return '' if (!@result); return @result; } sub getBalance() { my $buh_id = shift; my $q_get_balance = $db_convex->prepare(" SELECT ROUND(SUM(account-credit)) AS av_funds, CEIL(account) AS balance FROM firms WHERE buh_id = ?"); $q_get_balance->execute( $buh_id ); my @result = $q_get_balance->fetchrow_array(); return '' if (!@result); return @result; }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
work.png.txt
3 hours ago | 475.67 KB
Disable Drag and Drop Image Improved Plugin i...
PHP | 4 hours ago | 1.31 KB
SAVE
5 hours ago | 0.06 KB
ZELAH
5 hours ago | 0.01 KB
z66is_archive.zip.txt
6 hours ago | 1.53 KB
programming
7 hours ago | 0.03 KB
thought
7 hours ago | 0.14 KB
STORY ENGINE
7 hours ago | 1.14 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!