Fix my self...(can't dial out with A400P and dahdi 2.2.0 ,asterisk 1.4.23.1 line is busy and recive call my pstn hangup)

hi all i am new on freepbx and i need a help for us tnx again

my sterisk stat is :
linuxCLI> dahdi show channels
Chan Extension Context Language MOH Interpret
pseudo default default
1 from-internal en default
2 from-zaptel en default
linux
CLI>
my chan.dahdi conf
;# Flash Operator Panel will parse this file for dahdi trunk buttons
;# AMPLABEL will be used for the display labels on the buttons

;# %c Dahdi Channel number
;# %n Line number
;# %N Line number, but restart counter
;# Example:
;# ;AMPLABEL:Channel %c - Button %n

;# For Dahdi/* buttons use the following
;# (where x=number of buttons to dislpay)
;# ;AMPWILDCARDLABEL(x):MyLabel
[trunkgroups]

[channels]

language=en

;signalling=fxs_ks
;callerid=24********
;group=1
;context=from-zaptel
;channel => 2
signalling=fxs_ks
callerid=asreceived
group=0
context=from-zaptel
cidsignalling=dtmf
cidstart=ring
sendcalleridafter=1
relaxdtmf=yes
usecallerid=yes
channel => 2
context=default

;faxdetect=both
;faxdetect=incoming
;faxdetect=outgoing
;faxdetect=no

#include zapata_additional.conf
;#include dahdi-channels.conf
zapata_additional.conf
;;;;;;[203]
signalling=fxo_ks
pickupgroup=
mailbox=203@default
immediate=no
echotraining=800
echocancelwhenbridged=no
echocancel=yes
context=from-internal
callprogress=no
callgroup=
callerid=device <203>
busydetect=no
busycount=7
accountcode=
channel=>1

dahdi-channels.conf

; Autogenerated by /usr/sbin/dahdi_genconf on Tue Feb 10 16:47:31 2009 – do not hand edit
; Dahdi Channels Configurations (chan_dahdi.conf)
;
; This is not intended to be a complete chan_dahdi.conf. Rather, it is intended
; to be #include-d by /etc/asterisk/chan_dahdi.conf that will include the global settings
;

; Span 1: WCTDM/4 “Wildcard TDM400P REV E/F Board 5” (MASTER)
;;; line="1 WCTDM/4/0 FXOKS (In use) (EC: MG2)"
signalling=fxo_ks
callerid=“Channel 1” <4001>
mailbox=4001
group=5
context=from-internal
channel => 1
callerid=
mailbox=
group=
context=default

;;; line="2 WCTDM/4/1 FXSKS (In use) (EC: MG2)"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 2
callerid=
group=
context=default

if call out nuber pstn line buzy :frowning:

Verbosity is at least 3
– Starting simple switch on ‘Zap/2-1’
– Executing [s@from-zaptel:1] NoOp(“Zap/2-1”, "Entering from-zaptel with DID == ") in new stack
– Executing [s@from-zaptel:2] Ringing(“Zap/2-1”, “”) in new stack
– Executing [s@from-zaptel:3] Set(“Zap/2-1”, “DID=s”) in new stack
– Executing [s@from-zaptel:4] NoOp(“Zap/2-1”, “DID is now s”) in new stack
– Executing [s@from-zaptel:5] GotoIf(“Zap/2-1”, “1?zapok:notzap”) in new stack
– Goto (from-zaptel,s,8)
– Executing [s@from-zaptel:8] NoOp(“Zap/2-1”, “Is a Zaptel Channel”) in new stack
– Executing [s@from-zaptel:9] Set(“Zap/2-1”, “CHAN=2-1”) in new stack
– Executing [s@from-zaptel:10] Set(“Zap/2-1”, “CHAN=2”) in new stack
– Executing [s@from-zaptel:11] Macro(“Zap/2-1”, “from-zaptel-2|s|1”) in new stack
– Executing [s@from-zaptel:12] NoOp(“Zap/2-1”, “Returned from Macro from-zaptel-2”) in new stack
– Executing [s@from-zaptel:13] Goto(“Zap/2-1”, “from-pstn|s|1”) in new stack
– Goto (from-pstn,s,1)
– Executing [s@from-pstn:1] Set(“Zap/2-1”, “__FROM_DID=s”) in new stack
– Executing [s@from-pstn:2] Gosub(“Zap/2-1”, “app-blacklist-check|s|1”) in new stack
– Executing [s@app-blacklist-check:1] LookupBlacklist(“Zap/2-1”, “”) in new stack
– Executing [s@app-blacklist-check:2] GotoIf(“Zap/2-1”, “0?blacklisted”) in new stack
– Executing [s@app-blacklist-check:3] Return(“Zap/2-1”, “”) in new stack
– Executing [s@from-pstn:3] ExecIf(“Zap/2-1”, “1 |Set|CALLERID(name)=”) in new stack
– Executing [s@from-pstn:4] Set(“Zap/2-1”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
– Executing [s@from-pstn:5] SetCallerPres(“Zap/2-1”, “allowed_not_screened”) in new stack
– Executing [s@from-pstn:6] Goto(“Zap/2-1”, “ext-group|300|1”) in new stack
– Goto (ext-group,300,1)
– Executing [300@ext-group:1] Macro(“Zap/2-1”, “user-callerid|”) in new stack
– Executing [s@macro-user-callerid:1] Set(“Zap/2-1”, “AMPUSER=”) in new stack
– Executing [s@macro-user-callerid:2] GotoIf(“Zap/2-1”, “0?report”) in new stack
– Executing [s@macro-user-callerid:3] ExecIf(“Zap/2-1”, “1|Set|REALCALLERIDNUM=”) in new stack
– Executing [s@macro-user-callerid:4] Set(“Zap/2-1”, “AMPUSER=”) in new stack
– Executing [s@macro-user-callerid:5] Set(“Zap/2-1”, “AMPUSERCIDNAME=”) in new stack
– Executing [s@macro-user-callerid:6] GotoIf(“Zap/2-1”, “1?report”) in new stack
– Goto (macro-user-callerid,s,11)
– Executing [s@macro-user-callerid:11] GotoIf(“Zap/2-1”, “0?continue”) in new stack
– Executing [s@macro-user-callerid:12] Set(“Zap/2-1”, “__TTL=64”) in new stack
– Executing [s@macro-user-callerid:13] GotoIf(“Zap/2-1”, “1?continue”) in new stack
– Goto (macro-user-callerid,s,20)
– Executing [s@macro-user-callerid:20] NoOp(“Zap/2-1”, “Using CallerID “” <>”) in new stack
– Executing [300@ext-group:2] GotoIf(“Zap/2-1”, “1?skipdb”) in new stack
– Goto (ext-group,300,4)
– Executing [300@ext-group:4] Set(“Zap/2-1”, “__NODEST=”) in new stack
– Executing [300@ext-group:5] Set(“Zap/2-1”, “__BLKVM_OVERRIDE=BLKVM/300/Zap/2-1”) in new stack
– Executing [300@ext-group:6] Set(“Zap/2-1”, “__BLKVM_BASE=300”) in new stack
– Executing [300@ext-group:7] Set(“Zap/2-1”, “DB(BLKVM/300/Zap/2-1)=TRUE”) in new stack
– Executing [300@ext-group:8] Set(“Zap/2-1”, “RRNODEST=”) in new stack
– Executing [300@ext-group:9] Set(“Zap/2-1”, “__NODEST=300”) in new stack
– Executing [300@ext-group:10] Set(“Zap/2-1”, “RecordMethod=Group”) in new stack
– Executing [300@ext-group:11] Macro(“Zap/2-1”, “record-enable|202-204-203|Group”) in new stack
– Executing [s@macro-record-enable:1] MacroExit(“Zap/2-1”, “”) in new stack
– Executing [300@ext-group:12] Set(“Zap/2-1”, “RingGroupMethod=ringall”) in new stack
– Executing [300@ext-group:13] Macro(“Zap/2-1”, “dial|20|tr|202-204-203”) in new stack
– Executing [s@macro-dial:1] GotoIf(“Zap/2-1”, “1?dial”) in new stack
– Goto (macro-dial,s,3)
– Executing [s@macro-dial:3] AGI(“Zap/2-1”, “dialparties.agi”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/dialparties.agi
dialparties.agi: Starting New Dialparties.agi
== Parsing ‘/etc/asterisk/manager.conf’: Found
== Parsing ‘/etc/asterisk/manager_additional.conf’: Found
== Parsing ‘/etc/asterisk/manager_custom.conf’: Found
== Manager ‘admin’ logged on from 127.0.0.1
dialparties.agi: Caller ID name is ‘unknown’ number is 'unknown’
dialparties.agi: Methodology of ring is ‘ringall’
– dialparties.agi: Added extension 202 to extension map
– dialparties.agi: Added extension 204 to extension map
– dialparties.agi: Added extension 203 to extension map
– dialparties.agi: Extension 202 cf is disabled
– dialparties.agi: Extension 204 cf is disabled
– dialparties.agi: Extension 203 cf is disabled
– dialparties.agi: Extension 202 do not disturb is disabled
– dialparties.agi: Extension 204 do not disturb is disabled
– dialparties.agi: Extension 203 do not disturb is disabled
– dialparties.agi: DbDel CALLTRACE/202 - Caller ID is not defined
– dialparties.agi: DbDel CALLTRACE/204 - Caller ID is not defined
– dialparties.agi: DbDel CALLTRACE/203 - Caller ID is not defined
– dialparties.agi: Filtered ARG3: 202-204-203
== Manager ‘admin’ logged off from 127.0.0.1
– AGI Script dialparties.agi completed, returning 0
– Executing [s@macro-dial:7] Dial(“Zap/2-1”, “SIP/202&SIP/204&ZAP/1|20|trM(auto-blkvm)”) in new stack
– Called 204
– Called 1
– Zap/1-1 is ringing
– SIP/204-085ba5d8 is ringing
– Zap/1-1 is ringing
– SIP/204-085ba5d8 answered Zap/2-1
– Hungup ‘Zap/1-1’
– Executing [s@macro-auto-blkvm:1] Set(“SIP/204-085ba5d8”, “__MACRO_RESULT=”) in new stack
– Executing [s@macro-auto-blkvm:2] DBdel(“SIP/204-085ba5d8”, “BLKVM/300/Zap/2-1”) in new stack
– DBdel: family=BLKVM, key=300/Zap/2-1
– Executing [h@macro-dial:1] Macro(“Zap/2-1”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] ResetCDR(“Zap/2-1”, “w”) in new stack
– Executing [s@macro-hangupcall:2] NoCDR(“Zap/2-1”, “”) in new stack
– Executing [s@macro-hangupcall:3] GotoIf(“Zap/2-1”, “1?skiprg”) in new stack
– Goto (macro-hangupcall,s,6)
– Executing [s@macro-hangupcall:6] GotoIf(“Zap/2-1”, “0?skipblkvm”) in new stack
– Executing [s@macro-hangupcall:7] NoOp(“Zap/2-1”, “Cleaning Up Block VM Flag: BLKVM/300/Zap/2-1”) in new stack
– Executing [s@macro-hangupcall:8] DBdel(“Zap/2-1”, “BLKVM/300/Zap/2-1”) in new stack
– DBdel: family=BLKVM, key=300/Zap/2-1
– DBdel: Error deleting key from database.
– Executing [s@macro-hangupcall:9] GotoIf(“Zap/2-1”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,11)
– Executing [s@macro-hangupcall:11] Hangup(“Zap/2-1”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 11) exited non-zero on ‘Zap/2-1’ in macro ‘hangupcall’
== Spawn h extension (macro-dial, h, 1) exited non-zero on ‘Zap/2-1’
== Spawn extension (macro-dial, s, 7) exited non-zero on ‘Zap/2-1’ in macro ‘dial’
== Spawn extension (ext-group, 300, 13) exited non-zero on ‘Zap/2-1’
– Hungup ‘Zap/2-1’

and now call out for my pstn :frowning:

Verbosity is at least 3
– Executing [2*********@from-internal:1] Macro(“SIP/204-085b6060”, “user-callerid|SKIPTTL|”) in new stack
– Executing [s@macro-user-callerid:1] Set(“SIP/204-085b6060”, “AMPUSER=204”) in new stack
– Executing [s@macro-user-callerid:2] GotoIf(“SIP/204-085b6060”, “0?report”) in new stack
– Executing [s@macro-user-callerid:3] ExecIf(“SIP/204-085b6060”, “1|Set|REALCALLERIDNUM=204”) in new stack
– Executing [s@macro-user-callerid:4] Set(“SIP/204-085b6060”, “AMPUSER=204”) in new stack
– Executing [s@macro-user-callerid:5] Set(“SIP/204-085b6060”, “AMPUSERCIDNAME=pantelis”) in new stack
– Executing [s@macro-user-callerid:6] GotoIf(“SIP/204-085b6060”, “0?report”) in new stack
– Executing [s@macro-user-callerid:7] Set(“SIP/204-085b6060”, “AMPUSERCID=204”) in new stack
– Executing [s@macro-user-callerid:8] Set(“SIP/204-085b6060”, “CALLERID(all)=“pantelis” <204>”) in new stack
– Executing [s@macro-user-callerid:9] Set(“SIP/204-085b6060”, “REALCALLERIDNUM=204”) in new stack
– Executing [s@macro-user-callerid:10] ExecIf(“SIP/204-085b6060”, “0|Set|CHANNEL(language)=”) in new stack
– Executing [s@macro-user-callerid:11] GotoIf(“SIP/204-085b6060”, “1?continue”) in new stack
– Goto (macro-user-callerid,s,20)
– Executing [s@macro-user-callerid:20] NoOp(“SIP/204-085b6060”, “Using CallerID “pantelis” <204>”) in new stack
– Executing [@from-internal:2] Set(“SIP/204-085b6060”, “_NODEST=”) in new stack
– Executing [
@from-internal:3] Macro(“SIP/204-085b6060”, “record-enable|204|OUT|”) in new stack
– Executing [s@macro-record-enable:1] MacroExit(“SIP/204-085b6060”, “”) in new stack
– Executing [@from-internal:4] Macro(“SIP/204-085b6060”, “dialout-trunk|1|*||") in new stack
– Executing [s@macro-dialout-trunk:1] Set(“SIP/204-085b6060”, “DIAL_TRUNK=1”) in new stack
– Executing [s@macro-dialout-trunk:2] GosubIf(“SIP/204-085b6060”, “0?sub-pincheck|s|1”) in new stack
– Executing [s@macro-dialout-trunk:3] GotoIf(“SIP/204-085b6060”, “0?disabletrunk|1”) in new stack
– Executing [s@macro-dialout-trunk:4] Set(“SIP/204-085b6060”, "DIAL_NUMBER=
”) in new stack
– Executing [s@macro-dialout-trunk:5] Set(“SIP/204-085b6060”, “DIAL_TRUNK_OPTIONS=tr”) in new stack
– Executing [s@macro-dialout-trunk:6] Set(“SIP/204-085b6060”, “OUTBOUND_GROUP=OUT_1”) in new stack
– Executing [s@macro-dialout-trunk:7] GotoIf(“SIP/204-085b6060”, “0?nomax”) in new stack
– Executing [s@macro-dialout-trunk:8] GotoIf(“SIP/204-085b6060”, “0?chanfull”) in new stack
– Executing [s@macro-dialout-trunk:9] GotoIf(“SIP/204-085b6060”, “0?skipoutcid”) in new stack
– Executing [s@macro-dialout-trunk:10] Set(“SIP/204-085b6060”, “DIAL_TRUNK_OPTIONS=”) in new stack
– Executing [s@macro-dialout-trunk:11] Macro(“SIP/204-085b6060”, “outbound-callerid|1”) in new stack
– Executing [s@macro-outbound-callerid:1] ExecIf(“SIP/204-085b6060”, “0|SetCallerPres|”) in new stack
– Executing [s@macro-outbound-callerid:2] ExecIf(“SIP/204-085b6060”, “0|Set|REALCALLERIDNUM=204”) in new stack
– Executing [s@macro-outbound-callerid:3] GotoIf(“SIP/204-085b6060”, “1?normcid”) in new stack
– Goto (macro-outbound-callerid,s,6)
– Executing [s@macro-outbound-callerid:6] Set(“SIP/204-085b6060”, “USEROUTCID=”) in new stack
– Executing [s@macro-outbound-callerid:7] Set(“SIP/204-085b6060”, “EMERGENCYCID=”) in new stack
– Executing [s@macro-outbound-callerid:8] Set(“SIP/204-085b6060”, “TRUNKOUTCID=2467023766”) in new stack
– Executing [s@macro-outbound-callerid:9] GotoIf(“SIP/204-085b6060”, “1?trunkcid”) in new stack
– Goto (macro-outbound-callerid,s,12)
– Executing [s@macro-outbound-callerid:12] ExecIf(“SIP/204-085b6060”, “1|Set|CALLERID(all)=2467023766”) in new stack
– Executing [s@macro-outbound-callerid:13] GotoIf(“SIP/204-085b6060”, “1?exit”) in new stack
– Goto (macro-outbound-callerid,s,11)
– Executing [s@macro-outbound-callerid:11] MacroExit(“SIP/204-085b6060”, “”) in new stack
– Executing [s@macro-dialout-trunk:12] ExecIf(“SIP/204-085b6060”, “1|AGI|fixlocalprefix”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/fixlocalprefix
== fixlocalprefix: Dialpattern . matched. *********** -> ***********
– AGI Script fixlocalprefix completed, returning 0
– Executing [s@macro-dialout-trunk:13] Set(“SIP/204-085b6060”, "OUTNUM=
") in new stack
– Executing [s@macro-dialout-trunk:14] Set(“SIP/204-085b6060”, “custom=ZAP/2”) in new stack
– Executing [s@macro-dialout-trunk:15] ExecIf(“SIP/204-085b6060”, “0|Set|DIAL_TRUNK_OPTIONS=M(setmusic^)”) in new stack
– Executing [s@macro-dialout-trunk:16] Macro(“SIP/204-085b6060”, “dialout-trunk-predial-hook|”) in new stack
– Executing [s@macro-dialout-trunk-predial-hook:1] MacroExit(“SIP/204-085b6060”, “”) in new stack
– Executing [s@macro-dialout-trunk:17] GotoIf(“SIP/204-085b6060”, “0?bypass|1”) in new stack
– Executing [s@macro-dialout-trunk:18] GotoIf(“SIP/204-085b6060”, “0?customtrunk”) in new stack
– Executing [s@macro-dialout-trunk:19] Dial(“SIP/204-085b6060”, "ZAP/2/|300|") in new stack
– Called 2/246********
– Hungup ‘Zap/2-1’
== Everyone is busy/congested at this time (1:0/0/1)
– Executing [s@macro-dialout-trunk:20] Goto(“SIP/204-085b6060”, “s-CHANUNAVAIL|1”) in new stack
– Goto (macro-dialout-trunk,s-CHANUNAVAIL,1)
– Executing [s-CHANUNAVAIL@macro-dialout-trunk:1] GotoIf(“SIP/204-085b6060”, “1?noreport”) in new stack
– Goto (macro-dialout-trunk,s-CHANUNAVAIL,3)
– Executing [s-CHANUNAVAIL@macro-dialout-trunk:3] NoOp(“SIP/204-085b6060”, “TRUNK Dial failed due to CHANUNAVAIL (hangupcause: 0) - failing through to other trunks”) in new stack
– Executing [
@from-internal:5] Macro(“SIP/204-085b6060”, “outisbusy|”) in new stack
– Executing [s@macro-outisbusy:1] Playback(“SIP/204-085b6060”, “all-circuits-busy-now|noanswer”) in new stack
– <SIP/204-085b6060> Playing ‘all-circuits-busy-now’ (language ‘en’)
– Executing [s@macro-outisbusy:2] Playback(“SIP/204-085b6060”, “pls-try-call-later|noanswer”) in new stack
– <SIP/204-085b6060> Playing ‘pls-try-call-later’ (language ‘en’)
== Spawn extension (macro-outisbusy, s, 2) exited non-zero on ‘SIP/204-085b6060’ in macro ‘outisbusy’
== Spawn extension (from-internal, ***********, 5) exited non-zero on ‘SIP/204-085b6060’
– Executing [h@from-internal:1] Macro(“SIP/204-085b6060”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] ResetCDR(“SIP/204-085b6060”, “w”) in new stack
– Executing [s@macro-hangupcall:2] NoCDR(“SIP/204-085b6060”, “”) in new stack
– Executing [s@macro-hangupcall:3] GotoIf(“SIP/204-085b6060”, “1?skiprg”) in new stack
– Goto (macro-hangupcall,s,6)
– Executing [s@macro-hangupcall:6] GotoIf(“SIP/204-085b6060”, “1?skipblkvm”) in new stack
– Goto (macro-hangupcall,s,9)
– Executing [s@macro-hangupcall:9] GotoIf(“SIP/204-085b6060”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,11)
– Executing [s@macro-hangupcall:11] Hangup(“SIP/204-085b6060”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 11) exited non-zero on ‘SIP/204-085b6060’ in macro ‘hangupcall’
== Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/204-085b6060’
linux
CLI>

i tetst and trixbox for same set and workkkkkkkkkkk!! :///////////// but i hate this pack no lake me… and try 7 days and test lot set but still no work :confused:
i now to all have lot work to make freepbx beter if have litle time plz help me i am noob tnx again. <3


ok tnx for no help i fix my self this problem and works fine :slight_smile:

down load all current ver. of asterisk 1.6.current add on and all staff and dahdi to

after install all asterisk,freepbx and all staff edit my /etc/asterisk/asterisk.conf file and change the follow :

  1. on this line: [directories] (!) ; remove the (!) to enable this
    [directories] ; remove the (!) to enable this ( to make asterisk to create on /var/run/asterisk/asterisk.pid file )

  2. edit my /etc/amportal.conf and enable this line :(to make freepbx support dahdi)

ZAP2DAHDICOMPAT=true

DEFAULT VALUE: false

If set to true, FreePBX will check if you have chan_dadhi installed. If so, it will

automatically use all your ZAP configuration settings (devices and trunks) and

silently convert them, under the covers, to DAHDI so no changes are needed. The

GUI will continue to refer to these as ZAP but it will use the proper DAHDI channels.

This will also keep Zap Channel DIDs working.

  1. edit /etc/dahdi/modules and lave only this module

Digium TDM400P: up to 4 analog ports

wctdm

  1. run dahdi tool :#dahdi_genconf
    #dahdi_cfg -vvvv

  2. edit /etc/asterisk/chan_dahdi.conf (and add freepbx file to add auto pstn extension )

[channels]

;;; line="2 WCTDM/4/1"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 2

#include chan_dahdi_additional.conf ( if u need to add any extension direct on free pbx use this line only )
;#include dahdi-channels.conf ( if u need to use dahdi auto conf use only this line )


I hope to help i am not expert and sry for my bad English but i make to work this card for that way.

One more this is Debian script to install asterisk and freepbx :

first before run this script download kernel Debian source file and copy on
(#aptitude -y install linux-source-(ver to use on system of u)
/tmp/kernel

#!/bin/bash

VER_ASTERISK=“1.6.0.5”;
VER_DAHDI=“2.1.0.4”;
VER_DAHDITOOL=“2.1.0.2”;
VER_LIBPRI=“1.4.7”;
VER_ADDONS=“1.6.0.1”;

VER_FREEPBX=“2.5.0”;

VER=“0.3.2”;

echo "##################################################################"
echo "# Automated installer for Asterisk with FreePBX #"
echo "# #"
echo "# Yoann QUERET - [email protected] #"
echo "# http://www.queret.net/asterisk/ #"
echo "# #"
echo "# #"
echo "### ---------------------------------------------------------- ###"
echo "-> Asterisk ${VER_ASTERISK}"
echo "-> Dahdi ${VER_DAHDI}"
echo "-> Libpri ${VER_LIBPRI}"
echo "-> Addons ${VER_ADDONS}"
echo "-> FreePBX ${VER_FREEPBX} (+ apache2 php5 mysql5)"
echo "### ---------------------------------------------------------- ###"
echo "# Press to continue #"
echo "##################################################################"
read

echo "##################################################################"
echo "# == SYSTEM CONFIGURATION REQUIRED == #"
echo "# Linux Debian based with kernel 2.6 #"
echo "# #"
echo "# File /etc/apt/sources.list must be up to date #"
echo "# #"
echo "# == NETWORK CONFIGURATION REQUIRED == #"
echo "# Your server must be connected to internet, and must be use #"
echo "# aptitude and wget command. #"
echo "# #"
echo "# #"
echo "### ---------------------------------------------------------- ###"
echo "# Press to continue #"
echo "##################################################################"
read

echo "±---------------------------------------------------------------+"
echo "| Check if this script is loading from user root |"
echo "| user root = uid 0 |"
echo "±---------------------------------------------------------------+"
echo " Press to continue"
read
if [ $UID != “0” ]; then
echo " ERROR : You must run this script from user root (UID 0)"
echo ""
echo " Installation stopped !"
exit
fi
echo “Find UID 0, We can continu installation …”

echo "±---------------------------------------------------------------+"
echo "| Check if you use the last version of this script |"
echo "±---------------------------------------------------------------+"
echo " Press to continue"
read
wget -q http://www.queret.net/download/Asterisk_FreePBX/scripts/current_version -O /tmp/current_version
if [ $(stat -c%s “/tmp/current_version”) == “0” ]; then
echo " ERROR : Can not get current version."
echo " Please check your network setting."
echo ""
echo " Installation stopped !"
exit
fi
VER_SRV=cat /tmp/current_version
if [ ${VER_SRV} != ${VER} ]; then
echo " You don’t have the last version of this script."
echo " - You use version : ${VER}"
echo " - Current version is : ${VER_SRV}"
echo " For more informations : http://www.queret.net/asterisk/"
echo ""
echo " Installation stopped !"
exit
fi
echo “You have the last version, We can continu installation …”

echo "±---------------------------------------------------------------+"
echo "| System check (Debian version and kernel version) |"
echo "±---------------------------------------------------------------+"
echo " Press to continue"
read
KERNEL_VERSION=uname -r
KERNEL_VERSION=echo ${KERNEL_VERSION} | sed -e "s/\-\(.*\)//"
KERNEL_UP_VERSION=echo ${KERNEL_VERSION} | sed -e "s/\(2\.[4,6]\)\(.*\)/\1/"

if [ ${KERNEL_VERSION} != ‘2.6.24’ ]; then
echo " ERROR : This script must be used with a kernel 2.6."
echo " Also, you use a kernel : ${KERNEL_UP_VERSION}"
echo " Installation stopped !"
exit
fi

if [ ! -f /etc/debian_version ]; then
echo " ERROR : This script must be used with a Linux Debian based."
echo " Installation stopped !"
exit
fi
echo " You use a Linux Debian based, with kernel ${KERNEL_UP_VERSION}."
echo " We can continu installation."
echo " Press to continue"
read

clear
echo "##################################################################"
echo "# PART 1 - Asterisk installation #"
echo "### ---------------------------------------------------------- ###"
echo "# Press to continue #"
echo "##################################################################"
read

echo "±---------------------------------------------------------------+"
echo "| Check if asterisk already installed |"
echo "±---------------------------------------------------------------+"
echo " Press to continue"
read
if [ -f /usr/sbin/asterisk ]; then
echo "Asterisk seem to be already installed.“
key=”"
while [ “$key” != “y” ] && [ “$key” != “n” ];do
echo ""
read -n 1 -p “Do you want process to new asterisk installation ? [y/N]” key
done
echo ""
if [ $key == “n” ]; then
ASTERISK_INSTALLATION_DISABLE=“1”;
fi
fi

if [ “${ASTERISK_INSTALLATION_DISABLE}” != “1” ]; then
echo "±---------------------------------------------------------------+"
echo "| Download sources to /tmp/asterisk/ |"
echo "±---------------------------------------------------------------+"
echo " Press to continue"
read
if [ ! -d /tmp/asterisk/ ]; then
mkdir /tmp/asterisk/
fi
wget http://downloads.digium.com/pub/telephony/asterisk/asterisk-${VER_ASTERISK}.tar.gz -O /tmp/asterisk/asterisk-${VER_ASTERISK}.tar.gz
wget http://downloads.digium.com/pub/telephony/dahdi-linux/releases/dahdi-linux-${VER_DAHDI}.tar.gz -O /tmp/asterisk/dahdi-linux-${VER_DAHDI}.tar.gz
wget http://downloads.digium.com/pub/telephony/dahdi-tools/releases/dahdi-tools-${VER_DAHDITOOL}.tar.gz -O /tmp/asterisk/dahdi-tools-${VER_DAHDITOOL}.tar.gz
wget http://downloads.digium.com/pub/telephony/libpri/libpri-${VER_LIBPRI}.tar.gz -O /tmp/asterisk/libpri-${VER_LIBPRI}.tar.gz
wget http://downloads.digium.com/pub/telephony/asterisk/asterisk-addons-${VER_ADDONS}.tar.gz -O /tmp/asterisk/asterisk-addons-${VER_ADDONS}.tar.gz

echo "+----------------------------------------------------------------+"
echo "| Installing required packages                                   |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
aptitude update
aptitude -y install kernel-package g++ libncurses5-dev linux-kernel-headers sqlite libnewt-dev libusb-dev zlib1g-dev libmysqlclient15-dev libsqlite0-dev

echo "+----------------------------------------------------------------+"
echo "| Download kernel sources                                        |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ ! -d /tmp/kernel/ ]; then
	mkdir /tmp/kernel/
fi
#wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-${KERNEL_VERSION}.tar.bz2 -O /tmp/kernel/linux-${KERNEL_VERSION}.tar.bz2

echo "+----------------------------------------------------------------+"
echo "| Configuring of kernel sources                                  |"
echo "+----------------------------------------------------------------+"
echo "****************************************************************"
echo "** == ATTENTION ==                                            **"
echo "** If you don't understand next question, just press <enter>. **"
echo "** --                                                         **"
echo "** Next NEW elements are some new options for your kernel     **"
echo "****************************************************************"
echo "--"
echo " Press <enter> to continue"
read
cd /usr/src/
tar xvjf /tmp/kernel/linux-source-${KERNEL_VERSION}.tar.bz2
if [ -h /usr/src/linux ]; then
	unlink /usr/src/linux
fi
ln -s /usr/src/linux-source-${KERNEL_VERSION} /usr/src/linux
cd /usr/src/linux/
cp /boot/config-`uname -r` ./.config
make oldconfig
make prepare
make prepare scripts

echo "+----------------------------------------------------------------+"
echo "| Decompresing sources in /usr/src/                              |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cd /usr/src/
tar zxvf /tmp/asterisk/asterisk-${VER_ASTERISK}.tar.gz
tar zxvf /tmp/asterisk/asterisk-addons-${VER_ADDONS}.tar.gz
tar zxvf /tmp/asterisk/libpri-${VER_LIBPRI}.tar.gz 
tar zxvf /tmp/asterisk/dahdi-linux-${VER_DAHDI}.tar.gz
tar zxvf /tmp/asterisk/dahdi-tools-${VER_DAHDITOOL}.tar.gz
echo "+----------------------------------------------------------------+"
echo "| Compiling dahdi                                                |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cd /usr/src/dahdi-linux-${VER_DAHDI}
echo "== ATTENTION =="
echo "If you don't understand next question, choose NO."
echo "--"
key=""
while [ "$key" != "y" ] && [ "$key" != "n" ];do
	echo ""
	read -n 1 -p "Do you want to select dahdi modules to install (make menuconfig) ? [y/N]" key
done
echo ""
if [ $key == "y" ]; then
	make menuconfig
fi
make
make install
cd /usr/src/dahdi-tools-${VER_DAHDITOOL}
./configure
   make
make install
make config

echo "+----------------------------------------------------------------+"
echo "| Compiling libpri                                               |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cd /usr/src/libpri-${VER_LIBPRI}
make install

echo "+----------------------------------------------------------------+"
echo "| Compiling Asterisk                                             |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cd /usr/src/asterisk-${VER_ASTERISK}

echo "> Apply patch on apps/app_voicemail.c"
echo "> READ http://forums.digium.com/viewtopic.php?t=18332"
echo " Press <enter> to continue"
read

sed -i "s/\(chmod(template*\)\(.*\)/\/* \1\2 *\//" /usr/src/asterisk-${VER_ASTERISK}/apps/app_voicemail.c
sed -i "s/\(chmod(newtmp*\)\(.*\)/\/* \1\2 *\//" /usr/src/asterisk-${VER_ASTERISK}/apps/app_voicemail.c
sed -i "s/\(chmod(tmptxtfile*\)\(.*\)/\/* \1\2 *\//" /usr/src/asterisk-${VER_ASTERISK}/apps/app_voicemail.c

echo "> Apply patch on apps/app_voicemail.c"
echo "> READ http://www.asterisk-france.net/community/showthread.php?p=30494"
echo " Press <enter> to continue"
read

sed -i "s/\(res = ast_play_and_wait(chan, \"vm-no\");\)/res = say_and_wait(chan, 0 , chan->language);/" /usr/src/asterisk-${VER_ASTERISK}/apps/app_voicemail.c
./configure

make
make install
make samples

echo "+----------------------------------------------------------------+"
echo "| Compiling Asterisk Addons                                      |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cd /usr/src/asterisk-addons-${VER_ADDONS}
./configure

echo "== ATTENTION =="
echo "If you don't understand next question, choose NO."
echo "--"
key=""
while [ "$key" != "y" ] && [ "$key" != "n" ];do
	echo ""
	read -n 1 -p "Do you want to select Asterisk Addons modules to install (make menuconfig) ? [y/N]" key
done
echo ""
if [ $key == "y" ]; then
	make menuconfig
fi
make
make install
make samples

echo "+----------------------------------------------------------------+"
echo "| Creating symlinks (Modules)                                    |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ -h /lib/modules/`uname -r`/asterisk ]; then
	unlink /lib/modules/`uname -r`/asterisk
fi
ln -s /lib/modules/${KERNEL_VERSION}/ /lib/modules/`uname -r`/asterisk
depmod

echo "+----------------------------------------------------------------+"
echo "| Loading ztdummy at boot time                                   |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
echo ztdummy >> /etc/modules

echo "+----------------------------------------------------------------+"
echo "| Prompt FR (French Voice)                                       |"
echo "+----------------------------------------------------------------+"
key=""
while [ "$key" != "y" ] && [ "$key" != "n" ];do
	echo ""
	read -n 1 -p "Do you want install French voice ? [y/N]" key
done
echo ""
if [ $key == "y" ]; then
	wget http://www.queret.net/download/Asterisk_FreePBX/prompt/fr/prompt-fr-france-aurelie_bassard_2.1_repack.tgz -O /tmp/asterisk/prompt-fr-france-aurelie_bassard_2.1_repack.tgz
	cd /var/lib/asterisk/
	tar zxvf /tmp/asterisk/prompt-fr-france-aurelie_bassard_2.1_repack.tgz
fi

echo "##################################################################"
echo "# PART1 : Asterisk installation : Done                           #"
echo "### ---------------------------------------------------------- ###"
echo "#                   Press <enter> to continue                    #"
echo "##################################################################"
read

ASTERISK_INSTALLATION="1";

fi

###################################################################################################

###################################################################################################

###################################################################################################

clear
echo "##################################################################"
echo "# PART 2 - FreePBX installation #"
echo "### ---------------------------------------------------------- ###"
echo "# Press to continue #"
echo "##################################################################"
read

if [ -f /usr/local/sbin/amportal ]; then
echo "FreePBX seem to be already installed."
echo "New installation erase all data/configuration file.“
key=”"
while [ “$key” != “y” ] && [ “$key” != “n” ];do
echo ""
read -n 1 -p “Do you want really re-install FreePBX ? [y/N]” key
done
echo ""
if [ $key == “n” ]; then
FREEPBX_INSTALLATION_DISABLE=“1”;
fi
fi

if [ “${FREEPBX_INSTALLATION_DISABLE}” != “1” ]; then
echo "±---------------------------------------------------------------+"
echo "| Installing packages |"
echo "±---------------------------------------------------------------+"
echo " Press to continue"
read
aptitude update
aptitude install -y apache2 php5 php5-cli mysql-server-5.0 php-pear php5-mysql php-db libapache2-mod-php5 php5-gd php5-curl

echo "+----------------------------------------------------------------+"
echo "| Downloading source to /tmp/freepbx/                            |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ ! -d /tmp/freepbx/ ]; then
	mkdir /tmp/freepbx/
fi
wget http://www.queret.net/download/Asterisk_FreePBX/freepbx/freepbx-${VER_FREEPBX}.tar.gz -O /tmp/freepbx/freepbx-${VER_FREEPBX}.tar.gz

echo "+----------------------------------------------------------------+"
echo "| Decompresing FreePBX sources in /usr/src/                      |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cd /usr/src
tar zxvf /tmp/freepbx/freepbx-${VER_FREEPBX}.tar.gz

echo "+----------------------------------------------------------------+"
echo "| Changing maximum upload limit in PHP                           |"
echo "|        & memory limit in PHP                                   |"
echo "|        & magic_quotes_gpc in PHP                               |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ ! -f  /etc/php5/apache2/php.ini-orig ]; then
	cp /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini-orig
fi
sed -i "s/\(upload_max_filesize *= *\)\(.*\)/\120M/" /etc/php5/apache2/php.ini
sed -i "s/\(memory_limit *= *\)\(.*\)/\1100M/" /etc/php5/apache2/php.ini
sed -i "s/\(magic_quotes_gpc *= *\)\(.*\)/\1Off/" /etc/php5/apache2/php.ini

echo "+----------------------------------------------------------------+"
echo "| Music on hold  (symlink)                                       |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ -h /var/lib/asterisk/mohmp3 ]; then
	unlink /var/lib/asterisk/mohmp3
fi
ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

echo "+----------------------------------------------------------------+"
echo "| Setting permissions for asterisk user                          |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
adduser asterisk --quiet --no-create-home --disabled-password --gecos "asterisk PBX" --home /var/lib/asterisk
adduser www-data asterisk

echo "+----------------------------------------------------------------+"
echo "| Changing apache user and group to 'asterisk'                   |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ ! -f  /etc/apache2/apache2.conf-orig ]; then
	cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf-orig
fi

sed -i "s/\(^User *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf
sed -i "s/\(^Group *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf

echo "+----------------------------------------------------------------+"
echo "| Check is mysql root password is setting                        |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read

SQL_RESULT=`echo "show databases;" | mysql -u root  2>&1`
SQL_RESULT=`echo "${SQL_RESULT}" | sed "s/\(.*\)\(Access denied\)\(.*\)/\2/"`
SQL_ROOT_PASSWORD=""
if [ "${SQL_RESULT}" = "Access denied" ]; then
	echo "MySQL root password is setting"
fi

key=""
while [ "${SQL_RESULT}" = "Access denied" ];do
	read -p "Please enter MySQL root password ? " SQL_ROOT_PASSWORD
	if [ "${SQL-ROOT_PASSWORD}" != "" ]; then
		SQL_ROOT_PASSWORD="-p${SQL_ROOT_PASSWORD}"
	fi
	SQL_RESULT=`echo "show databases;" | mysql -u root  ${SQL_ROOT_PASSWORD} 2>&1`
	SQL_RESULT=`echo "${SQL_RESULT}" | sed "s/\(.*\)\(Access denied\)\(.*\)/\2/"`
	if [ "${SQL_RESULT}" = "Access denied" ]; then
		echo "ERROR : Password you have enter is wrong."
	fi
done

echo "+----------------------------------------------------------------+"
echo "| MySQL                                                          |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
echo "CREATE DATABASE IF NOT EXISTS asteriskcdrdb;" | mysql -u root ${SQL_ROOT_PASSWORD}
echo "CREATE DATABASE IF NOT EXISTS asterisk;" | mysql -u root ${SQL_ROOT_PASSWORD}
echo "GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';" | mysql -u root ${SQL_ROOT_PASSWORD}
echo "GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109';" | mysql -u root ${SQL_ROOT_PASSWORD}

sed -i "s/\(CREATE TABLE cdr\)/DROP TABLE IF EXISTS \`cdr\`;\n\1/" /usr/src/freepbx-${VER_FREEPBX}/SQL/cdr_mysql_table.sql
mysql -u asteriskuser -pamp109 asteriskcdrdb < /usr/src/freepbx-${VER_FREEPBX}/SQL/cdr_mysql_table.sql
mysql -u asteriskuser -pamp109 asterisk < /usr/src/freepbx-${VER_FREEPBX}/SQL/newinstall.sql

echo "+----------------------------------------------------------------+"
echo "| Configuring Asterisk to use FreePBX                            |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ ! -f  /etc/asterisk/asterisk.conf.orig ]; then
	cp /etc/asterisk/asterisk.conf /etc/asterisk/asterisk.conf.orig
fi
sed -i "s/\(astrundir *=> *\)\(.*\)/\1\/var\/run\/asterisk/" /etc/asterisk/asterisk.conf

if [ ! -d /var/run/asterisk ]; then
	mkdir /var/run/asterisk
fi
#chown -R asterisk:asterisk /var/run/asterisk


echo "+----------------------------------------------------------------+"
echo "| Loading Asterisk Post Installation                             |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ -f /var/run/asterisk/asterisk.pid ]; then
	/usr/local/sbin/amportal stop
	echo "Please wait ..."
	sleep 8;
fi
if [ -f /var/run/asterisk/asterisk.pid ]; then
	asteriskPID=$(cat /var/run/asterisk/asterisk.pid)
	kill -9 $(cat /var/run/asterisk/asterisk.pid)
fi
/usr/sbin/asterisk

echo "+----------------------------------------------------------------+"
echo "| Modifying FreePBX configuration files                          |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cp /usr/src/freepbx-${VER_FREEPBX}/install_amp /usr/src/freepbx-${VER_FREEPBX}/install_amp-orig
sed -i "s/\(^\$webroot*\)\(.*\)/\1 = \"\/var\/www\";/" /usr/src/freepbx-${VER_FREEPBX}/install_amp
chmod 755 /usr/src/freepbx-${VER_FREEPBX}/install_amp

LOCAL_IP=`ifconfig eth0 | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | egrep -v '255|(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})'`
sed -i "s/xx.xx.xx.xx/${LOCAL_IP}/g" "/usr/src/freepbx-${VER_FREEPBX}/install_amp"

chmod 755 /usr/src/freepbx-${VER_FREEPBX}/install_amp

echo "+----------------------------------------------------------------+"
echo "| Installation of FreePBX                                        |"
echo "+----------------------------------------------------------------+"
echo "| Simply press <Enter> at each question.                         |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
if [ -f /etc/amportal.conf ]; then
	mv /etc/amportal.conf /etc/amportal.conf.old
fi
if [ -f /etc/asterisk/manager.conf ]; then
	mv /etc/asterisk/manager.conf /etc/asterisk/manager.conf.old
fi
if [ -f /etc/asterisk/vm_email.inc ]; then
	mv /etc/asterisk/vm_email.inc /etc/asterisk/vm_email.inc.old
fi
if [ -f /etc/asterisk/indications.conf ]; then
	mv /etc/asterisk/indications.conf /etc/asterisk/indications.conf.old
fi
if [ -f /etc/asterisk/cdr_mysql.conf ]; then
	mv /etc/asterisk/cdr_mysql.conf /etc/asterisk/cdr_mysql.conf.old
fi

cd /usr/src/freepbx-${VER_FREEPBX}/
./install_amp

/usr/src/freepbx-${VER_FREEPBX}/apply_conf.sh

echo "+----------------------------------------------------------------+"
echo "| Stop Asterisk Post Installation                                |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
asteriskPID=$(cat /var/run/asterisk/asterisk.pid)
kill -9 $(cat /var/run/asterisk/asterisk.pid)
echo "Please wait ..."
sleep 8;


echo "+----------------------------------------------------------------+"
echo "| Remove Apache2 Redirect                                        |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
sed -i "s/\(RedirectMatch*\)\(.*\)//" /etc/apache2/sites-enabled/000-default

echo "+----------------------------------------------------------------+"
echo "| Reload apache                                                  |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
/etc/init.d/apache2 restart

echo "+----------------------------------------------------------------+"
echo "| Changing permissions                                           |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read

chown -R asterisk:asterisk /etc/asterisk
chmod 770 /etc/asterisk/

chown -R asterisk:asterisk /var/lib/asterisk/
chmod 770 /var/lib/asterisk/

chown -R asterisk:asterisk /var/www/


echo "+----------------------------------------------------------------+"
echo "| Copying missing images                                    |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
cp /var/www/admin/modules/dashboard/images/notify_* /var/www/admin/images/

echo "+----------------------------------------------------------------+"
echo "| FOP - French FOP Support                                       |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
key=""
while [ "$key" != "y" ] && [ "$key" != "n" ];do
	echo ""
	read -n 1 -p "Do you want install French FOP support ? [y/N]" key
done
echo ""
if [ $key == "y" ]; then
	FILE="/var/www/panel/op_lang_fr.cfg"
	echo '; Language configuration file' >> ${FILE}
	echo ';' >> ${FILE}
	echo '; Laurent Mele - [email protected]' >> ${FILE}
	echo '; 2005' >> ${FILE}
	echo ';' >> ${FILE}
	echo 'dialing=NumΓ©rotation' >> ${FILE}
	echo 'calling=Appel de $1' >> ${FILE}
	echo 'incoming=Appel entrant du $1' >> ${FILE}
	echo 'parked=ParquΓ© au $1' >> ${FILE}
	echo 'registered=EnregistrΓ©' >> ${FILE}
	echo 'notregistered=Non enregistrΓ©' >> ${FILE}
	echo 'reachable=Disponible. $1' >> ${FILE}
	echo 'unreachable=Indisponible $1' >> ${FILE}
	echo 'lagged=Lenteur $1' >> ${FILE}
	echo 'newold=Nouveau $1, Ancien $2' >> ${FILE}
	echo 'waitingonqueue=$1 utilisateur$2 en attente' >> ${FILE}
	echo 'memberonconference=$1 participant$2' >> ${FILE}
	echo 'version_mismatch=IncohΓ©rence de version Client/Serveur!' >> ${FILE}
	echo '; client side' >> ${FILE}
	echo 'clid_label=Information' >> ${FILE}
	echo 'detail_title=DΓ©tails du dernier appel' >> ${FILE}
	echo 'detail_from=De:' >> ${FILE}
	echo 'detail_to=Vers:' >> ${FILE}
	echo 'detail_duration=DurΓ©e:' >> ${FILE}
	echo 'security_code_title=Entrez le code de sΓ©curitΓ©' >> ${FILE}
	echo 'btn_security_text=Authentification de l''administrateur' >> ${FILE}
	echo 'btn_restart_text=RedΓ©marre Asterisk' >> ${FILE}
	echo 'btn_reload_text=Recharge la configuration' >> ${FILE}
	echo 'btn_debug_text=Ouvre/Ferme la fenΓtre de dΓ©verminage' >> ${FILE}
	echo 'btn_help_text=Ouvre la fenΓtre d''aide' >> ${FILE}
	echo 'tab_call_text=Appel' >> ${FILE}
	echo 'tab_queue_text=File d''attente' >> ${FILE}
	echo 'calls_taken_text=Appels pris' >> ${FILE}
	echo 'no_data_text=Pas d''information disponible' >> ${FILE}
	echo 'debug_window_title=FenΓtre de dΓ©verminage' >> ${FILE}
	echo 'paused=En pause' >> ${FILE}
	echo 'idle=Inactif' >> ${FILE}
	echo 'channels=$1 canal$2 utilisΓ©' >> ${FILE}

	FILE="/var/www/panel/help_fr.html"
	echo '<p>Avant de faire des actions, vous devez entrer votre mot de passe.<br />' >> ${FILE}
	echo '<br />' >> ${FILE}
	echo 'Après vous pouvez:' >> ${FILE}
	echo '<ul>' >> ${FILE}
	echo '<li> TransfΓ©rer les appels: en dΓ©placeant l''icΓ΄ne du tΓ©lΓ©phone et en le dΓ©posant sur la destination que vous voulez</li>' >> ${FILE}
	echo '<li> Interrompre un appel: en double cliquant sur le bouton rouge</li>' >> ${FILE}
	echo '<li> CrΓ©er un appel: en dΓ©placeant une extension valide vers une destination valide</li>' >> ${FILE}
	echo '<li> ConfΓ©rence: vous pouvez ajouter une tierce personne Γ  un appel en cours en dΓ©placeant une extension valide vers un appel existant. </li>' >> ${FILE}
	echo '</ul>' >> ${FILE}
	echo 'Vous pouvez aussi ajouter des informations complΓ©mentaires dans la boΓ®te Info avant de transfΓ©rer l''appel ou de le crΓ©er. Si du texte est ajoutΓ© dans la boΓ®te Info, il sera utilisΓ© comme texte dans l''identifiant de l''appel par exemple "555-1212 Bob Jones/IBM" ' >> ${FILE}
	echo '</p>' >> ${FILE}

fi

echo "+----------------------------------------------------------------+"
echo "| Startup script (Asterisk+FrePBX)                                  |"
echo "| /etc/init.d/freepbx [start|stop|restart]                       |"
echo "+----------------------------------------------------------------+"
echo " Press <enter> to continue"
read
STARTUP_SCRIPT="/etc/init.d/freepbx";
echo "Creating file ${STARTUP_SCRIPT} ...";

echo '#!/bin/bash' > ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo 'AMPORTAL_BIN=/usr/local/sbin/amportal' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo 'if [ ! -x ${AMPORTAL_BIN} ]; then'  >> ${STARTUP_SCRIPT}
echo '        echo "error : amportal binary can not be found (${AMPORTAL_BIN})"' >> ${STARTUP_SCRIPT}
echo '        exit 0' >> ${STARTUP_SCRIPT}
echo 'fi' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo 'start() {' >> ${STARTUP_SCRIPT}
echo '	echo "Starting FreePBX ..."' >> ${STARTUP_SCRIPT}
echo '	${AMPORTAL_BIN} start'  >> ${STARTUP_SCRIPT}
echo '}' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo 'stop() {' >> ${STARTUP_SCRIPT}
echo '	echo "Stopping FreePBX ..."' >> ${STARTUP_SCRIPT}
echo '	${AMPORTAL_BIN} stop'  >> ${STARTUP_SCRIPT}
echo '}' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo 'case "$1" in' >> ${STARTUP_SCRIPT}
echo '  start)' >> ${STARTUP_SCRIPT}
echo '        start' >> ${STARTUP_SCRIPT}
echo '        ;;' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo '  stop)' >> ${STARTUP_SCRIPT}
echo '        stop' >> ${STARTUP_SCRIPT}
echo '        ;;' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo '  restart)' >> ${STARTUP_SCRIPT}
echo '	stop' >> ${STARTUP_SCRIPT}
echo '        start' >> ${STARTUP_SCRIPT}
echo '        ;;' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo '  *)' >> ${STARTUP_SCRIPT}
echo '        echo $"Usage: $0 {start|stop|restart}"' >> ${STARTUP_SCRIPT}
echo '        exit 1' >> ${STARTUP_SCRIPT}
echo 'esac' >> ${STARTUP_SCRIPT}
echo '' >> ${STARTUP_SCRIPT}
echo 'exit 0' >> ${STARTUP_SCRIPT}
chmod 755 ${STARTUP_SCRIPT}

echo "Update services loading at boot time..."
update-rc.d freepbx defaults


echo "##################################################################"
echo "# PART 2 - FreePBX installation : Done                           #"
echo "### ---------------------------------------------------------- ###"
echo "#                   Press <enter> to continue                    #"
echo "##################################################################"
read

FREEPBX_INSTALLATION="1";

fi

###################################################################################################

###################################################################################################

###################################################################################################

clear
echo "##################################################################"
echo "# PART 3 - Security #"
echo "### ---------------------------------------------------------- ###"
echo "# Press to continue #"
echo "##################################################################"
read

if [ “${FREEPBX_INSTALLATION}” != “1” ]; then
echo "FreePBX installation is not finish."
echo "We can not set security parameters."
exit
fi

echo "±---------------------------------------------------------------+"
echo "| Change passwords for asterisk SQL user |"
echo "| > Change AMPDBPASS=amp109 in /etc/amportal.conf |"
echo "| > Change password = amp109 in /etc/asterisk/cdr_mysql.conf |"
echo "| > Change SQL PASSWORD |"
echo "±---------------------------------------------------------------+“
key=”"
read -p "NEW asteriskuser SQL password ? " key
echo $key
sed -i “s/(^AMPDBPASS=)(.)/\1$key/” /etc/amportal.conf
sed -i “s/(^password = )(.)/\1$key/” /etc/asterisk/cdr_mysql.conf
echo “SET PASSWORD FOR ‘asteriskuser’@‘localhost’ = PASSWORD(’$key’);” | mysql -u root ${SQL_ROOT_PASSWORD}

echo "±---------------------------------------------------------------+"
echo "| Change the default password for Asterisk Manager |"
echo "| > Change secret = amp111 in /etc/asterisk/manager.conf |"
echo "| > Change AMPMGRPASS=amp111 in /etc/amportal.conf |"
echo "±---------------------------------------------------------------+“
key=”"
read -p "NEW Asterisk Manager password ? " key
echo $key

sed -i “s/(^secret = )(.)/\1$key/” /etc/asterisk/manager.conf
sed -i “s/(^AMPMGRPASS=)(.)/\1$key/” /etc/amportal.conf

echo "±---------------------------------------------------------------+"
echo "| ATTENTION : Do not forget to change the root user MySQL |"
echo "| password. By default it is blank |"
echo "| -------------------------------------------------------------- |"
echo "| SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(’’); |"
echo "±---------------------------------------------------------------+“
key=”"
while [ “$key” != “y” ] && [ “$key” != “n” ];do
echo ""
read -n 1 -p “Do you want change mysql root password now ? [y/N]” key
done
echo "“
if [ $key == “y” ]; then
key=”"
read -p "Your NEW mysql root password ? " key
echo “SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(’$key’);” | mysql -u root ${SQL_ROOT_PASSWORD}
fi
echo ""
echo "##################################################################"
echo "# PART 3 - Security : Done #"
echo "### ---------------------------------------------------------- ###"
echo "# Press to continue #"
echo "##################################################################"
read

clear
echo "±---------------------------------------------------------------+"
echo "| Asterisk with FreePBX installation is finish. |"
echo "| For running asterisk+freepbx you must be use this command : |"
echo "| # /etc/init.d/freepbx start |"
echo "| |"
echo "| !! NEVER LOAD ASTERISK DIRECTLY !! |"
echo "| |"
echo "| ---------------------------------------------------------- |"
echo "| Web interface at this url :"
echo "| -> http://${LOCAL_IP}"
echo "|"
echo "| FOP (Flash Operator Panel) password is :"
echo "| -> passw0rd"
echo "| ---------------------------------------------------------- |"
echo "| |"
echo “±---------------------------------------------------------------+”

echo "±---------------------------------------------------------------+"
echo "| Done, enjoy |"
echo “±---------------------------------------------------------------+”