summaryrefslogtreecommitdiff
path: root/app/controllers/config_pingtel_controller.rb
blob: f161d7d014718b149610f5f544cbcf27621b7af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class ConfigPingtelController < ApplicationController

  before_filter {
    @mac_address = params[:PHYSICAL_ID].to_s.upcase.gsub(/[^0-9A-F]/,'')
  }

  def show
    if @mac_address
      @phone = Phone.where(:mac_address => @mac_address).first
    end

    if ! @phone
      render(
        :status => 404,
        :layout => false,
        :content_type => 'text/plain',
        :text => "<!-- Phone not found -->",
      )
      return false
    end

    @settings = {
      'PHONESET_DEPLOYMENT_SERVER' => "#{request.host_with_port}",
      'PHONESET_ADMIN_DOMAIN' => 'gemeinschaft',
      'PHONESET_LOGICAL_ID' => '1',
      'PHONESET_EXTERNAL_IP_ADDRESS' => '',  
      'PHONESET_DIALPLAN_LENGTH' => '4',
      'PHONESET_LINE.ALLOW_FORWARDING' => 'ENABLE',
      'PHONESET_LINE.REGISTRATION' => 'REGISTER',
      'PHONESET_LINE.URL' => '',
      'PHONESET_AVAILABLE_BEHAVIOR' => 'RING',
      'PHONESET_BUSY_BEHAVIOR' => 'BUSY',
      'PHONESET_CALL_WAITING_BEHAVIOR' => 'ALERT',
      'PHONESET_DND_METHOD' => 'FORWARD_ON_BUSY',
      'PHONESET_HTTP_PORT' => '80',
      'PHONESET_HTTP_PROXY_HOST' => '',
      'PHONESET_HTTP_PROXY_PORT' => '',
      'PHONESET_LOGO_URL' => '',
      'PHONESET_MSG_WAITING_SUBSCRIBE' => '',
      'PHONESET_RINGER' => 'BOTH',
      'PHONESET_SNMP_TRAP_DESTS' => '',
      'PHONESET_TELNET_ACCESS' => 'DISABLE',
      'PHONESET_TIME_DST_RULE' => 'WESTERN_EUROPE',
      'PHONESET_TIME_OFFSET' => '+60',
      'PHONESET_TIME_SERVER' => '130.149.17.21',
      'PHONESET_VOICEMAIL_RETRIEVE' => '',
      'SIP_DIRECTORY_SERVERS' => '',
      'SIP_PROXY_SERVERS' => '',
      'SIP_AUTHENTICATE_SCHEME' => 'NONE',
      'SIP_FORWARD_ON_BUSY' => '',
      'SIP_FORWARD_ON_NO_ANSWER' => '',
      'SIP_FORWARD_UNCONDITIONAL' => '',
      'SIP_REGISTER_PERIOD' => '3600',
      'SIP_SESSION_REINVITE_TIMER' => '',
      'SIP_TCP_PORT' => '', 
      'SIP_UDP_PORT' => '1032',
      'USER_DEFAULT_OUTBOUND_LINE' => 'PHONESET_LINE',
    }

    if @phone.sip_accounts.any?
      sip_accounts = @phone.sip_accounts
    else
      sip_accounts = [@phone.fallback_sip_account]
    end

    if sip_accounts.any?
      sip_account = sip_accounts.first
      @settings['PHONESET_DEPLOYMENT_SERVER'] = sip_account.sip_domain
      @settings['PHONESET_LINE.URL'] = "\"#{sip_account.caller_name}\" <sip:#{sip_account.auth_name}@#{sip_account.sip_domain}>"
      @settings['SIP_DIRECTORY_SERVERS'] = "sip:#{sip_account.sip_domain}"
      @settings['SIP_PROXY_SERVERS'] = "sip:#{sip_account.sip_domain}"
      #@settings['PHONESET_DIGITMAP.(xxxx|xxxxxxxxxx|1xxxxxxxxxx|91xxxxxxxxxx|9xxxxxxxxxx)'] = "\"{digits}\" <sip:{digits}@#{sip_account.sip_domain}>"
      @settings['PHONESET_VOICEMAIL_RETRIEVE'] = "sip:f-vmcheck@#{sip_account.sip_domain}"
      if sip_account.voicemail_account
        @settings['PHONESET_MSG_WAITING_SUBSCRIBE'] = "sip:#{sip_account.voicemail_account.name}@#{sip_account.sip_domain}"
      end
    end

    sip_accounts.each_with_index do |sip_account, index|
      @settings["PHONESET_LINE.CREDENTIAL.#{index+1}.PASSTOKEN"] = Digest::MD5.hexdigest("#{sip_account.auth_name}:#{sip_account.sip_domain}:#{sip_account.password}")
      @settings["PHONESET_LINE.CREDENTIAL.#{index+1}.REALM"] = sip_account.sip_domain
      @settings["PHONESET_LINE.CREDENTIAL.#{index+1}.USERID"] = sip_account.auth_name
    end
  end
end