#!/usr/bin/perl =head1 NAME freepbx_massadd v1.1 Copyright Noel Butler 2019. All Rights Reserved. Licenced under GPL v3.0 - https://www.gnu.org/licenses/gpl-3.0.en.html This entitles you to freely share or modify this scipt providing original author and copyright information is retained. =head1 Description Mass create new FreePBX extensions with DID and CID. Suitable for retirement villages, minning camps and other large environments. By default it uses Australian telephone numbering, and expects that you are using 1:1 matching, eg: ext 8080 would be created with a CID/DID of 07 5550 8080 for direct indialing and outbound caller ID.. As with all methods of creating DID's, you need to ascertain if local dialing requires your local area code, or not. Please consult your trunk provider to ensure you set the correct DID/CID prefixes, some require for example if in qld - 07, +07, 617, or +617 once you've got that nutted out you can set your prefixes correctly. =head1 Usage First, have a plan B and run a full system backup, and a Backup from within FreePBX as well. Next, edit $start and $end extension numbers, as well as the $did and $cid lead prefixes. Run ./freepbx_massadd Then use the FreePBX Bulk Handler module to import the Extensions and DIDs from the created CSV files in your current directory: new_exts.csv and new_dids.csv =head1 WARNING Read and select the import options carefully, as by default import REPLACES all existing entries if they exist. If you want to keep your existing extensions as is, change the "Replace/Update" button to NO. =head1 NOTES * If you only need extensions and not CID/DID's, set the $cid and $did prefixes blank, and don't import new_dids.csv * If you see any "row" errors, it means it has found an existing entry and did not overwrite it. * Don't forget to apply config. * You're done! =head1 EXAMPLES Lets say you are located in Queensland Australia and have been issued a consecutive: 2000 block: 07 5550 [67]xxx you would set $start to 6000, $end to 7999, $did and $cid fields to 075550 1000 block: 07 5550 6xxx - you would set $start to 6000, $end to 6999, $did and $cid fields to 075550 100 block: 07 5550 56xx - you would set $start to 600, $end to 699, $did and $cid fields to 0755505 =cut # Extensions $start = "8001"; $end = "8999"; # Lead Prefixes $did = "075550"; $cid = "075550"; # -------- Nothing to edit below here -------- # open(ECSV,">new_exts.csv") ||die ("Ooops.... can't open new_exts.csv for writting, check permissions?"); open(DCSV,">new_dids.csv") ||die ("Ooops.... can't open new_dids.csv for writting, check permissions?"); print ECSV "extension,password,name,voicemail,ringtimer,noanswer,recording,outboundcid,sipname,noanswer_cid,busy_cid,chanunavail_cid,noanswer_dest,busy_dest,chanunavail_dest,mohclass,id,tech,dial,devicetype,user,description,emergency_cid,hint_override,recording_in_external,recording_out_external,recording_in_internal,recording_out_internal,recording_ondemand,recording_priority,answermode,intercom,cid_masquerade,concurrency_limit,accountcode,aggregate_mwi,allow,avpf,callerid,context,defaultuser,device_state_busy_at,disallow,dtmfmode,force_rport,icesupport,mailbox,match,max_contacts,maximum_expiration,media_encryption,media_encryption_optimistic,media_use_received_transport,minimum_expiration,mwi_subscription,namedcallgroup,namedpickupgroup,outbound_proxy,qualifyfreq,rewrite_contact,rtcp_mux,rtp_symmetric,secret,sendrpid,sipdriver,timers,transport,trustrpid,callwaiting_enable,findmefollow_strategy,findmefollow_grptime,findmefollow_grppre,findmefollow_grplist,findmefollow_annmsg_id,findmefollow_postdest,findmefollow_dring,findmefollow_needsconf,findmefollow_remotealert_id,findmefollow_toolate_id,findmefollow_ringing,findmefollow_pre_ring,findmefollow_voicemail,findmefollow_calendar_id,findmefollow_calendar_match,findmefollow_changecid,findmefollow_fixedcid,findmefollow_enabled,voicemail_enable,voicemail_vmpwd,voicemail_email,voicemail_pager,voicemail_options,voicemail_same_exten,disable_star_voicemail,vmx_unavail_enabled,vmx_busy_enabled,vmx_temp_enabled,vmx_play_instructions,vmx_option_0_number,vmx_option_1_number,vmx_option_2_number\n"; print DCSV "cidnum,extension,destination,privacyman,alertinfo,ringing,mohclass,description,grppre,delay_answer,pricid,pmmaxretries,pmminlength,reversal,rvolume,fanswer,indication_zone,callrecording\n"; for ($n=$start;$n<=$end;$n++) { if (length $start == 2 ) { $n = sprintf("%02d", $n); } if (length $start == 3 ) { $n = sprintf("%03d", $n); } my @chars = (a..z, 0..9); my $passwd; $passwd .= $chars[rand @chars] for 1..28; if (defined $cid && $cid ne '') {$cidp = "$cid$n"} print ECSV "$n,,$n,default,60,,,$cidp,,,,,,,,default,$n,pjsip,PJSIP/$n,fixed,$n,$n,,,dontcare,dontcare,dontcare,dontcare,disabled,10,disabled,disabled,$n,1,,no,,no,\"$n <$n>\",from-internal,,0,,rfc4733,yes,no,$n@device,,1,7200,no,no,no,60,auto,,,,60,yes,no,yes,$passwd,pai,chan_pjsip,yes,,yes,ENABLED,ringallv2-prim,20,,$n,,\"ext-local,$n,dest\",,,,,Ring,7,default,,yes,default,,,yes,$n,,,attach=no|saycid=no|envelope=no|delete=no,no,no,,,,1,,,\n"; if (defined $did && $did ne '') { print DCSV ",$did$n,\"from-did-direct,$n,1\",0,,,default,,,0,,,,,,,default,dontcare\n"; } } close ECSV; close DCSV; print "All going well, your CSV files new_exts.csv and new_dids.csv are created in your current working directory and ready for import.\n";