2018年7月15日 星期日

CentOS 7 把網卡eno16777736改成eth0

CentOS 7預設網卡名稱是eno16777736
看了很不習慣上網找了修改方法

1. vi /etc/sysconfig/grub
找到GRUB_CMDLINE_LINUX="...."這行
在雙引號內加入net.ifnames=0 biosdevname=0

2. 用 grub2-mkconfig 指令重新建立 GRUB 的設定檔
grub2-mkconfig -o /boot/grub2/grub.cfg

3. 改掉ifcfg-eno16777736名稱
mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0

4. 修改ifcfg-eth0
NAME=eth0

5.reboot

Asterisk manager API (AMI)

Asterisk manager API(AMI)
Asterisk控制介面(AMI)允許管理用戶端程式連接到一個asterisk實例並且可以通過TCP/IP流發送命令或讀取事件。這在試圖跟蹤asterisk的狀態或其中的電話用戶端狀態時很有用,AMI說明了用戶端基於的一般(可能是動態的)規則。
一種簡單的"key: value"協定用於已連接的管理用戶端和asteriskPBX之間的資訊傳遞。每行都用回車換行(/r/n)來結束。

協定特點:
在發送命令前,你必須建立一個連接。
在認證後,資料包任何時間都可以在兩個方向上互相傳輸。
資料包第一行為"Action"時表明是由管理用戶端發送到asterisk,第一行為"Event"或"Response"表明有asterisk發送到管理用戶端。資料包內各行順序可以變化,對資料包沒有影響。
回車換行由於區分每一行,空行(兩個連續回車換行)用於表明命令結束,Asterisk開始處理命令。

資料包類型:
資料包的類型通過一下幾種關鍵字來劃分
Action:一個由管理用戶端發送到Asterisk的資料包,請求執行特定的動作。只有有限的幾種動作供用戶端使用,每個動作是由Asterisk伺服器上的模組所決定的。一次只能執行一個動作,該動作資料包包含了動作名稱以及執行所必需的參數。
Response:Asterisk對管理用戶端動作的回應。
Event: 有關Asterisk核心或擴展模組發生事件的資訊。

建立管理連接和用戶身份驗證:     
為了與Asterisk進行管理通話,管理用戶端必須建立到Asterisk伺服器偵聽埠(一般是5038)的TCP/IP連接,並使用登陸動作進行身份驗證。這就要求在Asterisk伺服器上創建用戶帳戶,用戶帳戶在/etc/asterisk/manager.conf中配置。帳戶由允許登陸的主機,登錄密碼以及被授予的許可權列表組成。
登錄和身份驗證的經理,你必須發送一個" 登錄 "行動,用您的用戶名和秘密(密碼作為參數)。 Here is an example:下面是一個例子:
Action: login
Username: admin
Secret: secret

你還可以通過"Events: off"阻止事件資料包發送到你的連接。例如:
Action: login
Username: admin
Secret: secret
Events: off

動作數據包:     
向Asterisk發送動作時,額外的關鍵字可以提供進一步的動作資訊。例如,你可能希望指定號碼或通道的斷開。此外,如果您的操作會導致Asterisk來執行撥號規則中的條目,你可以傳遞變數給撥號規則。這與你傳遞關鍵字的方式是一樣的。
向Asterisk發送動作資料包時,按照以下格式:
Action: <action type><CRLF>
<Key 1>: <Value 1><CRLF>
<Key 2>: <Value 2><CRLF>
...
Variable: <Variable 1>=<Value 1><CRLF>
Variable: <Variable 2>=<Value 2><CRLF>
...
<CRLF>

管理動作(Action):     
通過CLI命令show manager commands的輸出結果就是管理動作列表。
具體如下:
AbsoluteTimeout:這個命令將要求Asterisk在指定秒數後掛斷特定的通道,從而有效地結束通話。
參數:
Channel :哪些管道掛斷,如SIP/123-1c20
Timeout :到通道應掛斷的秒數
例子:
請求資訊
Action: AbsoluteTimeout
Channel: SIP/123-1c20
Timeout: 20

返回成功資訊
Response: Success
Message: Timeout Set

返回失敗資訊
Response: Error
Message: No such channel

ChangeMonitor:更改記錄某通道資訊檔案名。
參數:
Channel:通道名稱
File:檔案名

例子:
發送請求
ACTION: ChangeMonitor
Channel: SIP/x7065558529-1c20
File: 20050103-140105_cc51

返回失敗資訊
Response: Error
Message: No such channel

返回成功資訊
Response: Success
Message: Stopped monitoring channel

Command:發送Asterisk CLI命令。
參數:
Command:Asterisk CLI 命令。

例子:
發送請求
ACTION: COMMAND
command: Show Channels

返回資訊
Response: Follows
Channel (Context Extension Pri ) State Appl. Data
0 active channel(s)
--END COMMAND-

注意:返回的事件響應結果並不是發送一個回車換行(/r/n),而只發送回車(/n),如果你在中斷處理常式中只等待回車換行,那麼這條資訊將會被被拋棄。
例如command返回資訊如下:
Response: Follows/r/n
Channel Location State Application(Data)/n
SIP/x7065551212b-1af (None) Ringing AppDial((Outgoing Line))/n
SIP/x7065551212c-2aa 29@default:2 Ring Dial(SIP/x7065551212b)/n
2 active channels/n
1 active call/r/n
--END COMMAND--/r/n
/r/n


Events:事件控制流,用於啟用/禁用發送給管理用戶端的事件。
參數:
EventMask: 'on'表示所有事件均會被發送到管理用戶端。
'off'表示所有時間都不會被發送。
'system,call,log'用於選擇被發送的事件。
提示:有些事件是啟用或禁已經在.conf檔中配置了, They might be disabled by default.他們可能是默認為禁用。

例子:
注意在此例子中EventMask事件沒有立即返回的回應資訊,只有在設備登出時才返回相關資訊。
發送請求:
ACTION: EVENTS
EVENTMASK: ON
返回資訊:
Event: PeerStatus
Peer: SIP/ChannelName
PeerStatus: Unregistered
Cause: Expired

當EventMask參數為'off'時會立即返回回應資訊,如下:
發送:
ACTION: EVENTS
EVENTMASK: OFF
返回:
Response: Events Off

ExtensionState:檢查分機的狀態。
參數:Exten,Context,ActionID

例子:
發送:
ACTION: ExtensionState
Context: default
Exten: 301
ActionID: 1

接收:
Response: Success
ActionID: 1
Message: Extension Status
Exten: 2001
Context: default
Hint: SIP/2001
Status: 0

Status狀態碼:
-1 =擴展找不到
0 =空閒
1 =在使用
2 =忙
4 =不可用
8 =振鈴
16 =正等待

GetVar:獲取一個通道變數。
參數:Channel,Variable,actionID
ActionID是一個可選的參數匹配資訊。

例子:
發送:
ACTION: GetVar
Channel: SIP/5060-44d225d0
Variable: extension
成功返回:
Response: Success
Value: 17065551419
失敗返回:
Response: Error
Message: No such channel

Response: Success
varname: (null)

Hangup:掛斷指定通道。
參數:Channel

例子:

發送:
ACTION: Hangup
Channel: SIP/x7065558529-99a0

接收:
Event: Unlink
Channel1: SIP/127.180.254.109-44df88e8
Channel2: SIP/x7065558529-99a0
Uniqueid1: 1124989110.20473
Uniqueid2: 1124989110.20474

Event: Hangup
Channel: SIP/x7065558529-99a0
Uniqueid: 1124989110.20474
Cause: 16

Event: Hangup
Channel: SIP/127.180.254.109-44df88e8
Uniqueid: 1124989110.20473
Cause: 16

Response: Success
Message: Channel Hungup

IAXpeers:顯示iax資訊清單。
例子:

發送:
Action: IAXPeers

接收:
Name/Username Host Mask Port Status
8002 (Unspecified) (D) 255.255.255.255 0 UNKNOWN
8001 192.168.0.91 (D) 255.255.255.255 4569 OK (5 ms)
2 iax2 peers [1 online, 1 offline, 0 unmonitored]

ListCommands:顯示命令清單。
參數:ActionID

例子:
發送:
Action:ListCommands
接收:Response: Success
AbsoluteTimeout: Set Absolute Timeout (Priv: call,all)
AgentCallbackLogin: Sets an agent as logged in by callback (Priv: agent,all)
AgentLogoff: Sets an agent as no longer logged in (Priv: agent,all)
Agents: Lists agents and their status (Priv: agent,all)
ChangeMonitor: Change monitoring filename of a channel (Priv: call,all)
Command: Execute Asterisk CLI Command (Priv: command,all)
DBGet: Get DB Entry (Priv: system,all)
DBPut: Put DB Entry (Priv: system,all)
Events: Control Event Flow (Priv: )
ExtensionState: Check Extension Status (Priv: call,all)
Getvar: Gets a Channel Variable (Priv: call,all)
Hangup: Hangup Channel (Priv: call,all)
IAXnetstats: Show IAX Netstats (Priv: )
IAXpeers: List IAX Peers (Priv: )
ListCommands: List available manager commands (Priv: )
Logoff: Logoff Manager (Priv: )
MailboxCount: Check Mailbox Message Count (Priv: call,all)
MailboxStatus: Check Mailbox (Priv: call,all)
MeetmeMute: Mute a Meetme user (Priv: call,all)
MeetmeUnmute: Unmute a Meetme user (Priv: call,all)
Monitor: Monitor a channel (Priv: call,all)
Originate: Originate Call (Priv: call,all)
Park: Park a channel (Priv: call,all)
ParkedCalls: List parked calls (Priv: )
PauseMonitor: Pause monitoring of a channel (Priv: call,all)
Ping: Keepalive command (Priv: )
PlayDTMF: Play DTMF signal on a specific channel. (Priv: call,all)
QueueAdd: Add interface to queue. (Priv: agent,all)
QueuePause: Makes a queue member temporarily unavailable (Priv: agent,all)
QueueRemove: Remove interface from queue. (Priv: agent,all)
Queues: Queues (Priv: )
QueueStatus: Queue Status (Priv: )
Redirect: Redirect (transfer) a call (Priv: call,all)
SetCDRUserField: Set the CDR UserField (Priv: call,all)
Setvar: Set Channel Variable (Priv: call,all)
SIPpeers: List SIP peers (text format) (Priv: system,all)
SIPshowpeer: Show SIP peer (text format) (Priv: system,all)
Status: Lists channel status (Priv: call,all)
StopMonitor: Stop monitoring a channel (Priv: call,all)
UnpauseMonitor: Unpause monitoring of a channel (Priv: call,all)
UserEvent: Send an arbitrary event (Priv: user,all)
WaitEvent: Wait for an event to occur (Priv: )
ZapDialOffHook: Dial over channel while offhook (Priv: )
ZapDNDoff: Toggle channel Do Not Disturb status OFF (Priv: )
ZapDNDon: Toggle channel Do Not Disturb status ON (Priv: )
ZapHangup: Hangup Channel (Priv: )
ZapRestart: Fully Restart channels (terminates calls) (Priv: )
ZapShowChannels: Show status channels (Priv: )
ZapTransfer: Transfer Channel (Priv: )

Logoff:註銷管理用戶端。
例子:
發送:
ACTION: LOGOFF
接收:
Response: Goodbye
Message: Thanks for all the fish.

MailboxCount:檢查語音信箱是否有新資訊。
參數:MailBox,actionID
例子:
發送:
Action: MailboxCount
Mailbox: 2001@device
接收:
Response: Success
Message: Mailbox Message Count
Mailbox: 2001@device
NewMessages: 1
OldMessages: 0

MailboxStatus:檢查語音信箱狀態。
參數:MailBox,actionID
例子:
發送:
Action: MailboxStatus
Mailbox: 2001@device
接收:
Response: Success
Message: Mailbox Status
Mailbox: 2001@device
Waiting: 1

Monitor:監聽某個通道。
參數:Channel, File, Format, Mix
例子:
發送:
ACTION: Monitor
Channel: SIP/x7062618529-643d
File: channelsavefile
Mix: 1

返回:
Response: Success
Message: Started monitoring channel

失敗返回
Response: Error
Message: No such channel

Originate:產生一個呼叫。(privilege: call,all)     
參數:
Channel:呼叫連接產生的通道。
Context:呼叫連接所使用的Context(Context,Exten,Priority必須同時使用)
Exten: 呼叫連接所使用的分機(Context,Exten,Priority必須同時使用)

Priority:呼叫連接的優先順序。(Context,Exten,Priority必須同時使用)
TimeOut:呼叫連接的超時(,單位為毫秒,預設為30000毫秒)
CallID:呼叫連接的來電顯示。
Variable:通道變數設置。本地通道和連接通道都將被設置。
Account:呼叫所用密碼。
Application:使用此次呼叫的應用程式。(使用參數和資料)
Data:應用程式參數所使用的資料。
Async:呼叫是否為非同步。(允許多次調用不等待響應生成)
ActionID:請求識別字。 It allows you to identify the response to thisrequest.它允許您確定這一請求的回應資訊。 You may use a number or a string. Useful whenyou make several simultaneous requests.當您有用幾個併發請求,您可以使用一個數位或字串來區分。

事件的順序:首先SGI通道鳴響,然後當他被接聽後,通過上下文呼叫另一端的分機。注意超時只用於呼叫通道,呼叫分機時的超時另外指定。

使用非同步導致1 OriginateResponse事件,包含了失敗的原因。 Reason may be one of the following:原因可能是下列之一:
0 = no such extension or number 0 =沒有這樣的延長或編號
1 = no answer 1 =無應答
4 = answered 4 =回答
8 = congested or not available 8 =擁擠或不可用

例1(從SIP通道呼叫一個分機,這將導致外部呼叫無法產生直到sip通道掛斷)
發送:
Action: Originate
Channel: SIP/101test
Context: default
Exten: 8135551212
Priority: 1
Callerid: 3125551212
Timeout: 30000
Variable: var1=23|var2=24|var3=25
ActionID: ABC45678901234567890

分機8135551212是外呼號碼。這個例子表明了變數的使用方法

例2(從呼出通道呼叫一個本地分機,這將導致該分機不再響鈴直到zap通道掛斷)
發送:
Action: Originate
Channel: Zap/g2/8135551212
Context: default
Exten: 101
Priority: 1
Timeout: 30000
Callerid: 3125551212

101為一個本地分機號。

例3(運行系統命令)
發送:
Action: Originate
Channel: Local/1@dummy
Application: system
Data: /path/to/script

提示:如果你希望通道連接到任意分機和上下文,需要指定一個本地通道

ParkedCalls:設置顯示保持的呼叫清單。
參數:ActionID
發送:
Action: PakedCalls

返回:
Response: Success
Message: Parked calls will follow

Event: ParkedCallsComplete
Ping     
例子:
發送:
Action: ping
返回:
Response: Pong

QueueAdd:添加佇列成員。
參數:
Queue:添加成員的佇列名。
Interface: 成員名(例如sip/2001)
Penalty:數值,值越高越靠後。
Paused:暫停(true)或不暫停(false)
ActionID:(前面已介紹)

例子:
發送:
Action: QueueAdd
Queue: 200
Interface: sip/3001
Penalty: 1
Paused: true
返回:
Response: Success
Message: Added interface to queue

Event: QueueMemberAdded
Privilege: agent,all
Queue: 200
Location: sip/3001
MemberName: sip/3001
Membership: dynamic
Penalty: 1
CallsTaken: 0
LastCall: 0
Status: 5
Paused: 1

QueueRemove:移除佇列成員。
參數:
Queue:移除成員的佇列名。
Interface: 成員名(例如sip/2001)

例子:
發送:
Action: QueueRemove
Queue: 200
Interface: sip/3001
返回:
Response: Success
Message: Removed interface from queue

Event: QueueMemberRemoved
Privilege: agent,all
Queue: 200
Location: sip/3001
MemberName: sip/3001

Queues:返回全部佇列的配置以及電話資料資訊。
例子:
發送:
Action: Queues
返回:
200 has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime), W:0, C:0, A:0, SL:0.0% within 0s
Members:
Local/2002@from-internal/n (Invalid) has taken no calls yet
Local/2003@from-internal/n (Invalid) has taken no calls yet
Local/2001@from-internal/n (Invalid) has taken no calls yet
No Callers

default has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime), W:0, C:0, A:0, SL:0.0% within 0s
No Members
No Callers

QueueStatus:返回全部佇列的電話資料資訊。
例子:
發送:
Action: QueueStatus
返回:
Response: Success
Message: Queue status will follow

Event: QueueParams
Queue: 200
Max: 0
Calls: 0
Holdtime: 0
Completed: 0
Abandoned: 0
ServiceLevel: 0
ServicelevelPerf: 0.0
Weight: 0

Event: QueueMember
Queue: 200
Name: Local/2002@from-internal/n
Location: Local/2002@from-internal/n
Membership: static
Penalty: 0
CallsTaken: 0
LastCall: 0
Status: 4
Paused: 0

Event: QueueMember
Queue: 200
Name: Local/2003@from-internal/n
Location: Local/2003@from-internal/n
Membership: static
Penalty: 0
CallsTaken: 0
LastCall: 0
Status: 4
Paused: 0

Event: QueueMember
Queue: 200
Name: Local/2001@from-internal/n
Location: Local/2001@from-internal/n
Membership: static
Penalty: 0
CallsTaken: 0
LastCall: 0
Status: 4
Paused: 0

Event: QueueParams
Queue: default
Max: 0
Calls: 0
Holdtime: 0
Completed: 0
Abandoned: 0
ServiceLevel: 0
ServicelevelPerf: 0.0
Weight: 0

Event: QueueStatusComplete

Redirect:重定向一個呼叫。
參數:
Channel:重定向的通道。
ExtraChannel:重定向的第二通道(可選)
Exten:重定向的分機。
Context: 重定向的上下文。
Priority:重定向的優先順序
ActionID:(可選)

例子(把兩個呼叫重定向到meetme房間)
Action: Redirect
Channel: Zap/73-1
ExtraChannel: SIP/199testphone-1f3c
Exten: 8600029
Context: default
Priority: 1


8600029的上下文是default,並將進入meetme房間。

SetCDRUserField:設置使用者的呼叫詳細記錄。
參數:UserField,Channel,Append

SetVar:設置通道變數。
參數:Channel, Variable, Value

例子:
發送:
Action: Setvar
Channel: Zap/1-1
Variable: AtestVariable
Value: This is now set

SIPpeers:顯示sip使用者清單。
例子:
發送:
Action: SIPpeers
返回
Response: Success
Message: Peer status list will follow

Event: PeerEntry
Channeltype: SIP
ObjectName: 3001
ChanObjectType: peer
IPaddress: -none-
IPport: 0
Dynamic: yes
Natsupport: yes
VideoSupport: no
ACL: no
Status: UNKNOWN
RealtimeDevice: no

Event: PeerEntry
Channeltype: SIP
ObjectName: 2003
ChanObjectType: peer
IPaddress: -none-
IPport: 0
Dynamic: yes
Natsupport: yes
VideoSupport: no
ACL: no
Status: UNKNOWN
RealtimeDevice: no

Event: PeerEntry
Channeltype: SIP
ObjectName: 2002
ChanObjectType: peer
IPaddress: -none-
IPport: 0
Dynamic: yes
Natsupport: yes
VideoSupport: no
ACL: no
Status: UNKNOWN
RealtimeDevice: no

Event: PeerEntry
Channeltype: SIP
ObjectName: 2001
ChanObjectType: peer
IPaddress: -none-
IPport: 0
Dynamic: yes
Natsupport: yes
VideoSupport: no
ACL: no
Status: UNKNOWN
RealtimeDevice: no

Event: PeerlistComplete
ListItems: 4

Status:返回所有開放通道或指定通道的狀態。
參數:Channel (可選), ActionID (可選)
例子:
發送:
Action:Status

返回:
Response: Success
Message: Channel status will follow

Event: StatusComplete

StopMonitor:停止檢測某通道。
參數:Channel
例子:
發送:
Action: StopMonitor
Channel: Zap/1-1

ZapDialOffhook:從空閒的ZAP通道撥打呼叫。
參數:
ZapChannel: ZAP 通道
Number: 所撥打的號碼

ZapDNDoff:綁定ZAP通道而不影響其關閉狀態
參數:ZAPChannel

ZapDNDon:綁定ZAP通道而不影響其開放狀態
參數:ZAPChannel

ZapHangup:掛斷ZAP通道。
參數:ZAPChannel

ZapTransfer:轉撥ZAP通道。
參數:ZAPChannel

ZapShowChannels:顯示所有ZAP通道資訊。
參數:ActionID(可選)

Asterisk 1.2.1新增:
AgentCallBackLogin:設置使用者以回撥方式登錄。
參數:
Agent:用戶登錄的ID
Exten: 用於回撥的分機
Context: 用於回撥的上下文
AckCall: 設置在用戶回撥時進行驗證
WrapupTime: 掛斷重撥的最小間隔時間
ActionID:

例子:
發送:
Action: AgentCallBackLogin
Agent: 1234
Exten: 1234
Context: myqueues
AckCall: true
WrapupTime: 30
ActionID: 12345

AgentLogoff:註銷一個用戶。
參數:
Agent:用戶登錄Id

例子:
發送:
Action: AgentLogoff
Agent: 1234

Agents:顯示所有使用者資訊。
例子:
發送:
Action: Agents

DBGet:查詢資料庫資訊。
參數:Family,Key

發送:
Action: DBGet
Family:
Key:

失敗返回:
Response: Error
Message: Database entry not found

成功返回:
Response: Success
Message: Result will follow

Event: DBGetResponse
Family:
Key:
Val:

在Perl腳本中的運用:
use Asterisk::Manager;
my $astman = new Asterisk::Manager;
$astman->user('');
$astman->secret('');
$astman->host('');
$astman->connect || die $astman->error . "/n";

$astman->sendcommand(Action => 'DBGet', Family => '', Key => '');
my @result = $astman->sendcommand(Event => 'DBGetResponse');
$astman->disconnect;

my $value = $result[7]; -> Value 7 is the returned Value
DBPut:更新資料庫資訊。
發送:
Action: DBPut
Family:
Key:
Value:  (note, as of Asterisk 1.4 The Manager API wants Val: )

返回:
Response: Success
Message: Updated database successfully

使用方法同DBGet一樣。

QueuePause:停止/開啟佇列中某個成員的使用。
參數:
Queue: 成員所在佇列名.(可選,如無此項將在成員所在的所有佇列停止成員的使用)
Interface: 佇列成員名 (如sip/1000, zap/1-1, agent/1000)
Paused: 停止或開啟 (true or false)

SIPshowPeer:顯示指定peer資訊     
參數: peer:指定的peer。

Asterisk 1.4.0新增:
PlayDTMF:在指定通道上發送雙音多頻信號數位。
參數:
Channel:指定的通道
Digit:雙音多頻信號數位

發送:
Action: PlayDTMF
Channel: SIP/123-e2b2
Digit: 1

成功返回:
Response: Success
Message: DTMF successfully queued

失敗返回:
Response: Error
Message: No such channel

UpdateConfig:更新設定檔。
參數:
SrcFilename: 要讀取的設定檔(.conf)
DstFilename: 要更新的設定檔(.conf)
Reload: 是否重新載入(asterisk或者模組名稱)
Action-XXXXXX: 採取的動作 (NewCat、RenameCat、DelCat、Update、Delete、Append)
Cat-XXXXXX: 操作物件
Var-XXXXXX: 採用的變數
Value-XXXXXX: 變數的值
Match-XXXXXX: 其他匹配資訊

例1:(更新manager.conf)
action: updateconfig
reload: yes
srcfilename: manager.conf
dstfilename: manager.conf
action-000000: append
cat-000000: newuser
var-000000: secret
value-000000: nottelling
例2:(更新extension.conf,通過'>'增加首碼)
action:updateconfig
reload:yes
srcfilename: extensions.conf
dstfilename: extensions.conf
Action-000000:append
Cat-000000: ami-test
Var-000000: exten
Value-000000: >999,1,Dial(SIP/Bob)

例3:(刪除manager.conf中的配置資訊)
action: updateconfig
srcfilename: manager.conf
dstfilename: manager.conf
action-000000: delete
cat-000000: newuser
var-000000: secret
value-000000: nottelling
match-000000: nottelling

刪除時必須設置'value'和'match',不設置'match'將會刪除變數為'var'所有條目

GetConfig:顯示設定檔內容,主要給AJAM和asterisk圖形介面使用。
變數:FileName:顯示的檔案名(.conf)。




Asterisk事件(Event):     
以下的事件都在asterisk源碼中定義。

使用者狀態事件:     

'Agentcallbacklogin' 事件 :
描述:
[來源於chan_agent.c]

示例:
Event: Agentcallbacklogin
Agent:
Loginchan:
Uniqueid:

'Agentcallbacklogoff'事件
描述:
[來源於chan_agent.c]

示例:
Event: Agentcallbacklogoff
Agent:
Loginchan:
Logintime:
Reason: Autologoff
Uniqueid:

Event: Agentcallbacklogoff
Agent:
Loginchan:
Logintime:
Uniqueid:


'AgentCalled'事件
描述:
[來源於 app_queue.c]

示例:
Event: AgentCalled
AgentCalled:
ChannelCalling:
CallerID:
Context:
Extension:
Priority:

'AgentComplete'事件
描述:
[來源於 app_queue.c]

示例:
Event: AgentComplete
Queue:
Uniqueid:
Channel:
Member:
MemberName:
HoldTime:
TalkTime:
Reason:


'AgentConnect'事件
描述:
[來源於 app_queue.c]

示例:
Event: AgentConnect
Queue:
Uniqueid:
Channel:
Member:
MemberName:
Holdtime:
BridgedChannel:


'AgentDump'事件
描述:
[來源於 app_queue.c]

示例:
Event: AgentDump
Queue:
Uniqueid:
Channel:
Member:
MemberName:


'Agentlogin'事件
描述:
[來源於 chan_agent.c]

示例:
Event: Agentlogin
Agent:
Channel:
Uniqueid:


'Agentlogoff'事件
描述:
[來源於 chan_agent.c]

示例:
Event: Agentlogoff
Agent:
Logintime:
Uniqueid:


'QueueMemberAdded'事件
描述:

佇列增加成員動作
[來源於 app_queue.c]

示例:
Queue: testing
Location: Agent/AgentId
Membership: dynamic
Penalty: 0
CallsTaken: 0
LastCall: 0
Status: 4
Paused: 1


'QueueMemberPaused'事件

描述:

回應動作: QueuePause
[來源於 app_queue.c]

示例:
Event: QueueMemberPaused
Location:
MemberName:
Paused:

'QueueMemberStatus'事件
描述:
[來源於 app_queue.c]


Status的值可能為:
/*設備是有效的,但不知道的通道狀態*/
define AST_DEVICE_UNKNOWN 0

/*設備沒有使用 */
define AST_DEVICE_NOT_INUSE 1

/*設備使用中 */
define AST_DEVICE_INUSE 2


/*設備忙 */
define AST_DEVICE_BUSY 3

/*設備無效 */
define AST_DEVICE_INVALID 4

/*設備不可用 */
define AST_DEVICE_UNAVAILABLE 5

/* 設備在響鈴*/
define AST_DEVICE_RINGING 6

/*設備在響鈴並在使用中*/
define AST_DEVICE_RINGINUSE 7

/*設備在等待 */
define AST_DEVICE_ONHOLD 8


示例:
Event: QueueMemberStatus
Queue:
Location:
MemberName:
Membership:
Penalty: CallsTaken:
LastCall:
Status:
Paused:



命令狀態事件:     

呼叫狀態事件:     

'CDR'事件
描述:
[來源於 cdr_manager.c]

必須在 cdr_manager.conf 設定檔中有:

general
enabled = yes

示例:
Event: Cdr
AccountCode:
Source:
Destination:
DestinationContext:
CallerID:
Channel:
DestinationChannel:
LastApplication:
LastData:
StartTime:
AnswerTime:
EndTime:
Duration:
BillableSeconds:
Disposition:
AMAFlags:
UniqueID:
UserField:


'Dial'事件
描述:
[來源於 app_dial.c]

示例:
Event: Dial
Privilege: call,all
Source: Local/900@default-2dbf,2
Destination: SIP/900-4c21
CallerID:
CallerIDName: default
SrcUniqueID: 1149161705.2
DestUniqueID: 1149161705.4


'ExtensionStatus'事件
描述:
[來源於 manager.c]

示例:
Event: ExtensionStatus
Exten:
Context:
Status:


'Hangup'事件
描述:
[來源於 channel.c]

示例:
Event: Hangup
Channel: SIP/101-3f3f
Uniqueid: 1094154427.10
Cause: 0

Cause 代碼:

未分配 = 1
無到達路由 = 2
無路由目的地 = 3
無效通道 = 6
正在通話中 = 7
正常掛機 = 16
用戶忙 = 17
無應答 = 18
無人接聽 = 19
拒絕接聽 = 21
號碼已更改 = 22
目的次序不對 = 27
無效的數位格式 = 28
設備拒絕 = 29
查詢回應 = 30
正常未指定 = 31
正常的呼叫擁塞 = 34
網路狀態差 = 38
正常的臨時故障 = 41
交換機擁塞 = 42
信息過時 = 43
請求通道無效 = 44
被搶佔 = 45
無呼叫保持或呼叫等待 = 50
禁止呼出 = 52
禁止呼入 = 54
負載過重導致失效 = 57
負載過多導致不可達 = 58
負載過多導致為實現 = 65
通道未實現 = 66
設備未實現 = 69
無效的呼叫證明 = 81
不相容的目的地 = 88
無效的不明資訊 = 95
IE流覽器關閉 = 96
不識別的資訊類型 = 97
錯誤資訊 = 98
無IE流覽器 = 99
無效的IE信息 = 100
呼叫狀態錯誤 = 101
計時到達 = 102
強制性IE流覽器長度誤差 = 103
協定錯誤 = 111
互通 = 127
未定義的 = 0


'MusicOnHold'事件
描述:
事件表示電話等待時,播放音樂
示例:

Event: MusicOnHold
Channel:
State:
Uniqueid:


'Join'事件
描述:
[來源於 app_queue.c]

示例:
Event: Join
Channel:
CallerID:
Queue:
Position:
Count:


'Leave'事件
描述:
[來源於 app_queue.c]

示例:
Event: Leave
Channel:
Queue:
Count:


'Link'事件
描述:
當兩個通道已連接後開始交換聲音資料時發生'link'事件

示例:

Event: Link
Channel1: SIP/101-3f3f
Channel2: Zap/2-1
Uniqueid1: 1094154427.10
Uniqueid2: 1094154427.11


'MeetmeJoin'事件
描述:
[來源於 app_meetme.c]

示例:
Event: MeetmeJoin
Channel:
Uniqueid:
Meetme:
Usernum:


'MeetmeLeave'事件
描述:
[來源於 app_meetme.c]

示例:
Event: MeetmeLeave
Channel:
Uniqueid:
Meetme:
Usernum:


'MeetmeStopTalking'事件
描述:
[來源於 app_meetme.c]

注意:
這要求在meetme應用中以選中T選

示例:

Event: MeetmeStopTalking
Privilege: call,all
Channel: SIP/200-ABC1
Uniqueid: 1234567890.1
Meetme: 400
Usernum: 2



'MeetmeTalking'事件
描述:
[來源於 app_meetme.c]

注意:
這要求在meetme應用中以選中T選項

示例:

Event: MeetmeTalking
Privilege: call,all
Channel: SIP/200-ABC1
Uniqueid: 1234567890.1
Meetme: 400
Usernum: 2


'MessageWaiting'事件
描述:
[來源於 app_voicemail.c]

示例:
Event: MessageWaiting
Mailbox: @
Waiting:
New:
Old:

Event: MessageWaiting
Mailbox:
Waiting:


'Newcallerid'事件
描述:
[來源於 channel.c]

示例:
Event: Newcallerid
Channel:
Callerid:
Uniqueid:


'Newchannel'事件
描述:
[來源於 channel.c]

示例:
Event: Newchannel
Channel: Zap/2-1
State: Rsrvd
Callerid:
Uniqueid: 1094154427.11

Event: Newchannel
Channel: SIP/101-3f3f
State: Ring
Callerid: 101
Uniqueid: 1094154427.10


'Newexten'事件
描述:
當一項PBX函數運行(例如執行撥號規則)時發生此事件。

示例:
Event: Newexten
Channel: SIP/101-00c7
Context: macro-ext
Extension: s
Priority: 3
Application: Goto
AppData: s-BUSY
Uniqueid: 1094154321.8

Event: Newexten
Channel: SIP/101-3f3f
Context: local_extensions
Extension: 917070
Priority: 1
Application: AGI
AppData: /etc/asterisk/agi/ks_doorman_pickup.py|channel_up
Uniqueid: 1094154427.10

Event: Newexten
Channel: SIP/101-3f3f
Context: local_extensions
Extension: 917070
Priority: 2
Application: Dial
AppData: Zap/G1/17070
Uniqueid: 1094154427.10


'ParkedCall'事件
描述:
[來源於 res_features.c]

示例:
Event: ParkedCall
Exten: Channel:
From:
Timeout:
CallerID:


'Rename'事件
描述:
[來源於 channel.c: channel 'rename' event]

示例:
Event: Rename
Oldname:
Newname:
Uniqueid:


'SetCDRUserField'事件
描述:
[來源於 app_setcdruserfield.c]

示例:


'Unlink'事件
描述:

當兩個連接的通道斷開是發生此事件,通常為掛機時

示例:

Event: Unlink
Channel1: SIP/101-3f3f
Channel2: Zap/2-1
Uniqueid1: 1094154427.10
Uniqueid2: 1094154427.11


'UnParkedCall'事件
描述:
[來源於 res_features.c]


日誌狀態事件:     

系統狀態事件:     

'Alarm'事件:
描述:
[來源於 chan_zap.c]

示例:
Event: Alarm
Alarm:<(Red|Yellow|Blue|No|Unknown)Alarm|Recovering|Loopback|Not Open|None>
Channel:


'AlarmClear'事件:
描述:
[來源於 chan_zap.c]

示例:
Event: AlarmClear
Channel:


'DNDState'事件:
描述:
[來源於 chan_dahdi.c]

示例:
Event: DNDState
Channel: Zap/1
Status:


'LogChannel'事件
描述:
[來源於 logger.c]

示例:
Event: LogChannel
Channel: /var/log/asterisk/messages
Enabled: Yes

Event: LogChannel
Channel: /var/log/asterisk/messages
Enabled: No
Reason: 13 - Permission denied



'PeerStatus'事件
描述:
當用戶註冊或註銷時發生此事件
[來源於 chan_sip.c, chan_iax2.c]

示例:
Event: PeerStatus
Peer: SIP/2005
PeerStatus: Registered

Event: PeerStatus
Peer: SIP/2005
PeerStatus: Unregistered
Cause: Expired

Event: PeerStatus
Peer: IAX2/2007
PeerStatus:
Time: 1000



'Registry'事件
描述:

當應戶註冊時發生的事件
[來源於 chan_sip.c, chan_iax2.c]

示例:
Event: Registry
Channel: SIP
Domain: sip.domain
Status: Registered


'Reload'事件
描述:
當 "RELOAD" 命令執行時發生此事件
[來源於 manager.c]

示例:
Event: Reload
Message: Reload Requested


'Shutdown'事件
描述:
[來源於 asterisk.c]

示例:
Event: Shutdown
Shutdown:
Restart: [tr]



User Status事件:     

'UserEvent'事件
描述:
[來源於 app_userevent.c]

示例:
Event:
Channel:
Uniqueid:

Event:
Channel:
Uniqueid:



詳細狀態事件:   
'Newstate'事件
示例:
Event: Newstate
Channel: Zap/2-1
State: Dialing
Callerid: 101
Uniqueid: 1094154427.11

Event: Newstate
Channel: Zap/2-1
State: Up
Callerid: 101
Uniqueid: 1094154427.11


'ParkedCallsComplete:'事件
描述:
發生在ParkedCalls事件之後
示例:
Event: ParkedCallsComplete


'QueueParams:'事件
描述:
回應Queues動作的事件
示例:
Event: QueueParams
Queue: sales
Max: 0
Calls: 0
Holdtime: 0
Completed: 0
Abandoned: 0
ServiceLevel: 0
ServicelevelPerf: 0.0


'QueueMember'事件
描述:
回應Queues動作並且佇列中有成員是發生的事件。
示例:
Event: QueueMember
Queue: sales
Location: SIP/101
Membership: dynamic
Penalty: 0
CallsTaken: 0
LastCall: 0


'QueueStatusEnd'事件
描述:
回應Queues動作表示輸出結束。
示例:
Event: QueueStatusEnd


'Status'事件
示例:
Event: Status
Channel: Zap/2-1
CallerID: 101
Account:
State: Up
Link: SIP/101-5cf0
Uniqueid: 1094166088.26

Event: Status
Channel: SIP/101-5cf0

CallerID: 101
Account:
State: Up
Context: local_extensions
Extension: 917070
Priority: 2
Seconds: 11
Link: Zap/2-1
Uniqueid: 1094166088.25

'StatusComplete'事件
描述:
回應Status動作的事件,表示狀態輸出結束。
示例:
Event: StatusComplete


'ZapShowChannels'事件
描述:
回應ZapShowChannels動作的事件。
示例:
Event: ZapShowChannels
Channel: 2
Signalling: FXS Kewlstart
Context: pstn_menu
Alarm: No Alarm


'ZapShowChannelsComplete事件
描述:
回應ZapShowChannels動作的事件,表示輸出結束。
示例:
Event: ZapShowChannelsComplete



動作回應(Response)     
格式:
Response: ( Success或Error)
Message: (顯示資訊)

示例:
無動作或輸入有誤:
Response: Error
Message: Missing action in request

未知命令:
Response: Error
Message: Invalid/unknown command

無許可權:
Response: Error
Message: Permission denied

成功:
Response: Success
Message: Zap channel status will follow

文章內容參考:http://182.92.241.109/index.php/post/149.html

apache 增加不同port(端口、埠)

vim /etc/httpd/conf/httpd.conf

1.新增監聽的port(端口)
Listen 80 (預設)
Listen 8080

2.新增網站位置
<VirtualHost *:8080>
    DocumentRoot "/var/www/html/website"
    ServerName localhost

<Directory "/var/www/html/website">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
</VirtualHost>

3.重新啟動apach
service httpd restart

2018年7月13日 星期五

mysql忘記密碼重設

停用mysql
/etc/init.d/mysql stop

用下列方法啟動mysql可以跳過驗證
mysqld_safe --skip-grant-tables

不用輸入密碼直接進入
mysql -u root

接著修改密碼
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD("password") WHERE User='root';
mysql> flush privileges;
mysql> quit


最後重新啟動mysql
/etc/init.d/mysql stop
/etc/init.d/mysql start

修改Apache(PHP)寫入權限、檔案上傳權限

查看當前啟動和運行apache的用戶
ps -ef | grep httpd


修改擁有者及權限
chown -R apache /var/www/website/upload

chmod -R 755 /var/www/website/upload


備註:
不建議用777有安全性問題

3 組數字, 分別是代表 owner (7); 群組用戶 (5); 其他用戶 (5)
7 = 4 (讀) + 2 (寫) + 1 (執行)
5 = 4 (讀) + 1 (執行)
4 = 4 (讀)

2018年7月3日 星期二

正則、正規表示式 /i, /g

正規表示式/i, /g, /ig, /gi, /m的區別

/i (忽略大小寫)
/g (找出所有匹配的字)
/m (多行查找)
/gi (全部查找並忽略大小寫)
/ig (全部查找並忽略大小寫)

修改 Apache、PHP 上傳檔案最大限制

開啟php.ini

file_uploads = on ;允許http檔案上傳
upload_max_filesize = xxM ;允許上傳檔案的最大值
post_max_size = xxM ;POST可以傳送的最大值

memory_limit = xxM ;每個PHP頁面所吃掉的最大記憶體

存檔後重新動服務
service apache2 restart

PHP Notice: undefined index 完美解決方式

平時用$_GET[‘xx’] 取得參數值時,如果之前不加判斷在未傳進參數時會出現這樣的警告:

PHP Notice: undefined index xxx

雖然可以通過設置錯誤顯示方式來隱藏這個提示,但是這樣也有隱患,就是在伺服器的日誌中會記錄這些提示,導致日誌檔異常龐大!
下面是引用網上流行的解決方法:

首先,這個不是錯誤,是warning。所以如果伺服器不能改,每個變數使用前應當先定義。

方法1:伺服器配置修改(可以改的話優)
修改php.ini設定檔,error_reporting = E_ALL & ~E_NOTICE

方法2:對變數進行初始化,規範書寫(比較煩瑣,因為有大量的變數)。但還沒有找到好定義方法,望大家指教

方法3:每個檔頭部加上:error_reporting(0); 如果不行,只有打開php.ini,找到display_errors,設置為display_errors = Off。以後任何錯誤都不會提示。

方法4 :做判斷:isset($_GET["page"]) if-else判斷

或者加上'@'表示這行如果有錯誤或是警告不要輸出
如:@$page=$_GET["page"]

方法5:file1.php檔把$xx變數付一個值,用post 傳遞給file2.php,
如果file2.php沒有$xx的定義,而直接使用$yy=$xx; 系統就會報錯:"undifined variaable $xx", 如果file2.php的檔開始用$xx="";定義,那麼file1.php的$xx值就傳不過來了!

file2.php裡可以這樣
if(!isset($xx)) $xx="";

但Jones認為,這些方法都不太方便。你不妨這樣解決:

定義一個函數:
function _get($str){
    $val = !empty($_GET[$str]) ? $_GET[$str] : null;
    return $val;
}
然後在用的時候,直接用 _get('str') 代替 $_GET['str']


另一篇提到

方法一(優)
在$_GET['變數']前加入@

@$_GET['test']

方法二
isset($_GET['變數'])前加入一個if判斷

if(isset($_GET['變數']))
{
   ....
}

資料來源:http://shuai.be/archives/php-undefined-index/
資料來源:http://allenplay.blogspot.tw/2011/04/undefined-index-php.html

2018年7月2日 星期一

解決json_encode中文變成unicode

使用 json_encode 時,中文都會變成 unicode,解決有兩種方法:

1. 先用urlencode將中文編碼,json_encode之後再用 urldecode
urldecode(json_encode(urlencode("中文字串")));

2. 如果使用的PHP是5.4以上的版本,可以增加一個參數:JSON_UNESCAPED_UNICODE
json_encode("中文字串", JSON_UNESCAPED_UNICODE);