AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame] | 1 | /**
|
| 2 | * startClient - start pppoe client
|
| 3 | */
|
| 4 | var fs=require("fs");
|
| 5 | var Promise=require('bluebird');
|
| 6 | var execAsync=Promise.promisify(require('child_process').exec);
|
| 7 |
|
| 8 | String.prototype.trim = function() {
|
| 9 | return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
| 10 | }
|
| 11 |
|
| 12 | module.exports={
|
| 13 | verifyFun:function(userName,passWord){
|
| 14 | return execAsync("ifconfig").then(function (result) {
|
| 15 | if(result.indexOf("ppp0") > 0)
|
| 16 | {
|
| 17 | console.log("PPPoE session up.");
|
| 18 | return true;
|
| 19 | }
|
| 20 | else
|
| 21 | {
|
| 22 | var data =
|
| 23 | "noipdefault\n" +
|
| 24 | "usepeerdns\n" +
|
| 25 | "defaultroute\n" +
|
| 26 | "replacedefaultroute\n" +
|
| 27 | "hide-password\n" +
|
| 28 | "lcp-echo-interval 20\n" +
|
| 29 | "lcp-echo-failure 3\n" +
|
| 30 | "noauth\n" +
|
| 31 | "persist\n" +
|
| 32 | "mtu 1442\n" +
|
| 33 | "noaccomp\n" +
|
| 34 | "default-asyncmap\n" +
|
| 35 | "pty \"pppoe -I eth2 -T 80\"\n" +
|
| 36 | "user \"" + userName + "\"\n";
|
| 37 |
|
| 38 | var secretData = "\"" + userName + "\"" + " * " + "\"" + passWord + "\"";
|
| 39 | console.log("data:"+data+",secretData:"+secretData);
|
| 40 |
|
| 41 | fs.writeFile('/etc/ppp/peers/provider',data, function(err){
|
| 42 | if(err) throw err;
|
| 43 | console.log("write provider.");
|
| 44 | });
|
| 45 |
|
| 46 | fs.writeFile('/etc/ppp/chap-secrets',secretData,function(err){
|
| 47 | if(err) throw err;
|
| 48 | console.log("write chap-secrets.");
|
| 49 | });
|
| 50 |
|
| 51 | return execAsync('ps -ef|grep pppd').then(function (result) {
|
| 52 | if (result.indexOf("call provider") > 0)
|
| 53 | {
|
| 54 | execAsync("poff -a").then(function (result) {
|
| 55 | execAsync('pon');
|
| 56 | console.log("restart");
|
| 57 | }, function (err) {
|
| 58 | console.log(err);
|
| 59 | });
|
| 60 | }
|
| 61 | else
|
| 62 | {
|
| 63 | execAsync('pon');
|
| 64 | console.log("start");
|
| 65 | }
|
| 66 | return true;
|
| 67 | }, function (err) {
|
| 68 | console.log(err);
|
| 69 | return false;
|
| 70 | });
|
| 71 | }
|
| 72 | });
|
| 73 | }
|
| 74 | }
|