Customize CPE configuration and put in MongoDB

Hi community,

How can I customize CPE configuration based on a configuration template? For example, I created a config_generate.js file and put it in the directory “/config/ext”. When I run the file, I got error message: faultMessage=“No such function ‘template’ in extension ‘config_generate’”.
What is the good way to achieve that?


template = template.replace(new RegExp(’{{VLAN}}’,‘g’),sipLine[1]);
template = template.replace(new RegExp(’{{IP_ADDR}}’,‘g’),DBCheck.LANIP);

Please review the wiki article on extension scripts.

Thanks so much mate.
Sorted. :slight_smile:

Another question, how should I upload the configuration into MongoDB? Here is my code, I need to upload template.cfg into MongoDB. Thanks a lot.

function getConfig (args, callback){
	var template = config_template;
	template = template.replace(new RegExp('{{VLAN}}','g'),vlan.value);
	template = template.replace(new RegExp('{{IP_ADDR}}','g'),ip.value);
	template = template.replace(new RegExp('{{MASK}}','g'),mask.value);
            callback(null, template);

exports.getConfig = getConfig;

The script must be created in the /config/ext/ directory. (you’ll have to create the /ext/ directory)

Please do not upload anything directly into/directly edit the data in the mongo db. What you put in the db can get squashed because Genie uses redis for caching.