Menu

Reboot or Shutdown Raspbx by dialing Extension

himala76
2015-02-03
2016-03-18
  • himala76

    himala76 - 2015-02-03

    Edit /etc/asterisk/extensions_custom.conf and add

    [macro-shutdown]
    exten => s,1,Authenticate(1234)     
    exten => s,1,NoOp(Looks like we're going to shutdown!)
    exten => s,n,System(/usr/bin/sudo /sbin/shutdown -h now)
    
    [macro-reboot]
    exten => s,1,Authenticate(1234)     
    exten => s,1,NoOp(Looks like we're going to reboot!)
    exten => s,n,System(/usr/bin/sudo /sbin/shutdown -r now)
    

    You can change the password what ever you like digits only

    go to Custom Destinations add Custom Destination

    Custom Destination: macro-shutdown,s,1
    Description: SHUTDOWN

    Custom Destination: macro-reboot,s,1
    Description: REBOOT

    then go to Misc Applications add Misc Application

    Description SHUTDOWN
    Feature Code 3001
    Feature Status Enabled

    Destination
    Custom Destinations Shutdown

    Description REBOOT
    Feature Code 3002
    Feature Status Enabled

    Destination
    Custom Destinations REBOOT

    add asterisk to sudo group by

    sudo adduser asterisk sudo
    

    then
    Edit /etc/sudoers using

    sudo visudo
    

    Add lines:

    asterisk ALL=(ALL:ALL) ALL
    %sudo ALL= NOPASSWD: /sbin/shutdown
    

    now reboot the system

    you can dial 3001 and enter password 1234 to shutdown the pbx or dial 3002 and password 1234 to reboot the system

    Thanks
    Himala

     

    Last edit: himala76 2015-02-03
  • pdapunch

    pdapunch - 2015-05-31

    Hi Himala

    Great tutorial and very easy to follow, thanks. I seem to be having trouble though, it appears to execute properly but my Pi2 doesn't restart or shutdown. Any ideas what I could have missed?

    Raspberry Pi 2
    Asterisk Ver. 11.17.0
    FreePBX 12.0.65

    here is my log:

    localhost*CLI>
    == Using SIP RTP TOS bits 184
    == Using SIP RTP CoS mark 5
    -- Executing [3002@from-internal:1] NoOp("SIP/701-00000008", "Running miscapp 2: REBOOT") in new stack
    -- Executing [3002@from-internal:2] Macro("SIP/701-00000008", "user-callerid,") in new stack
    -- Executing [s@macro-user-callerid:1] Set("SIP/701-00000008", "TOUCH_MONITOR=1433094613.10") in new stack
    -- Executing [s@macro-user-callerid:2] Set("SIP/701-00000008", "AMPUSER=701") in new stack
    -- Executing [s@macro-user-callerid:3] GotoIf("SIP/701-00000008", "0?report") in new stack
    -- Executing [s@macro-user-callerid:4] ExecIf("SIP/701-00000008", "1?Set(REALCALLERIDNUM=701)") in new stack
    -- Executing [s@macro-user-callerid:5] Set("SIP/701-00000008", "AMPUSER=701") in new stack
    -- Executing [s@macro-user-callerid:6] GotoIf("SIP/701-00000008", "0?limit") in new stack
    -- Executing [s@macro-user-callerid:7] Set("SIP/701-00000008", "AMPUSERCIDNAME=sanity") in new stack
    -- Executing [s@macro-user-callerid:8] GotoIf("SIP/701-00000008", "0?report") in new stack
    -- Executing [s@macro-user-callerid:9] Set("SIP/701-00000008", "AMPUSERCID=701") in new stack
    -- Executing [s@macro-user-callerid:10] Set("SIP/701-00000008", "DIAL_OPTIONS=Ttr") in new stack
    -- Executing [s@macro-user-callerid:11] Set("SIP/701-00000008", "CALLERID(all)="sanity" <701>") in new stack
    -- Executing [s@macro-user-callerid:12] GotoIf("SIP/701-00000008", "0?limit") in new stack
    -- Executing [s@macro-user-callerid:13] ExecIf("SIP/701-00000008", "0?Set(GROUP(concurrency_limit)=701)") in new stack
    -- Executing [s@macro-user-callerid:14] GotoIf("SIP/701-00000008", "0?continue") in new stack
    -- Executing [s@macro-user-callerid:15] Set("SIP/701-00000008", "
    TTL=64") in new stack
    -- Executing [s@macro-user-callerid:16] GotoIf("SIP/701-00000008", "1?continue") in new stack
    -- Goto (macro-user-callerid,s,27)
    -- Executing [s@macro-user-callerid:27] Set("SIP/701-00000008", "CALLERID(number)=701") in new stack
    -- Executing [s@macro-user-callerid:28] Set("SIP/701-00000008", "CALLERID(name)=sanity") in new stack
    -- Executing [s@macro-user-callerid:29] Set("SIP/701-00000008", "CDR(cnum)=701") in new stack
    -- Executing [s@macro-user-callerid:30] Set("SIP/701-00000008", "CDR(cnam)=sanity") in new stack
    -- Executing [s@macro-user-callerid:31] Set("SIP/701-00000008", "CHANNEL(language)=en") in new stack
    -- Executing [3002@from-internal:3] Goto("SIP/701-00000008", "macro-reboot,s,1") in new stack
    -- Goto (macro-reboot,s,1)
    -- Executing [s@macro-reboot:1] Authenticate("SIP/701-00000008", "1234") in new stack
    > 0x76619530 -- Probation passed - setting RTP source address to 192.168.87.10:17374
    -- <SIP 701-00000008=""> Playing 'agent-pass.ulaw' (language 'en')
    -- <SIP 701-00000008=""> Playing 'auth-thankyou.ulaw' (language 'en')
    -- Executing [s@macro-reboot:2] System("SIP/701-00000008", "/usr/bin/sudo /sbin/shutdown -r now") in new stack
    -- Auto fallthrough, channel 'SIP/701-00000008' status is 'UNKNOWN'

     
  • VoIPuser

    VoIPuser - 2015-06-01

    Did you make the changes in /etc/sudoers and reboot? Although, I think I would have just tried adding this single line first, instead of the two that himala76 suggested - seems a bit more secure because it only removes the need for the password for the shutdown command, and doesn't allow user asterisk to sudo just anything:

    asterisk ALL = NOPASSWD: /sbin/shutdown

    Don't forget to reboot after making this change!

     
  • pdapunch

    pdapunch - 2015-06-03

    Hi VoiPuser

    Yes /etc/sudoers all fine.

    root@localhost:~# sudo -l -U asterisk
    Matching Defaults entries for asterisk on localhost:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

    User asterisk may run the following commands on localhost:
    (ALL : ALL) ALL
    (root) NOPASSWD: /sbin/shutdown
    (ALL : ALL) ALL

     
  • Wes

    Wes - 2016-03-18

    Bit late to the party, but this doesn't work for me.
    I tried using both options (himala and voipuser) for the /etc/sudoers file, rebooting after each change, but no go.
    I double checked each step and everything seems to be correct.

    I'm a new FreePBX user, so I don't know which log to check to see what's happening here.
    Anyone able to fill me in?

    Cheers.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.