Skip to content

Commit decc010

Browse files
committed
Fix pw.cgi
1 parent 72875d8 commit decc010

3 files changed

Lines changed: 85 additions & 9 deletions

File tree

www/cgi-bin/pw.cgi

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ case "$task" in
209209
fi
210210

211211
echo ""
212-
213212
if ! pgrep pppwn > /dev/null; then
214213

215214
if /etc/init.d/pppoe-server status | grep -q "running"; then
@@ -256,7 +255,6 @@ case "$task" in
256255
fi
257256

258257
echo ""
259-
260258
pids=$(pgrep pppwn)
261259
for pid in $pids; do
262260
kill $pid
@@ -267,7 +265,7 @@ case "$task" in
267265
exit 1
268266

269267
;;
270-
"enable")
268+
"params")
271269

272270
if ! [ "$token" = "$stoken" ]; then
273271

@@ -279,7 +277,53 @@ case "$task" in
279277
fi
280278

281279
echo ""
280+
if [ -f /root/pw.conf ]; then
281+
if grep -q "interface=" "/root/pw.conf"; then
282+
sed -i "s/interface=.*/interface=$adapter/" "/root/pw.conf"
283+
else
284+
echo -e "interface=$adapter" >> "/root/pw.conf"
285+
fi
286+
if grep -q "version=" "/root/pw.conf"; then
287+
sed -i "s/version=.*/version=$version/" "/root/pw.conf"
288+
else
289+
echo -e "version=$version" >> "/root/pw.conf"
290+
fi
291+
if grep -q "timeout=" "/root/pw.conf"; then
292+
sed -i "s/timeout=.*/timeout=$timeout/" "/root/pw.conf"
293+
else
294+
echo -e "timeout=$timeout" >> "/root/pw.conf"
295+
fi
296+
if grep -q "stage1=" "/root/pw.conf"; then
297+
sed -i "/stage1=.*/d" "/root/pw.conf"
298+
echo -e "stage1=$stage1" >> "/root/pw.conf"
299+
fi
300+
if grep -q "stage2=" "/root/pw.conf"; then
301+
sed -i "/stage2=.*/d" "/root/pw.conf"
302+
echo -e "stage2=$stage2" >> "/root/pw.conf"
303+
fi
304+
else
305+
echo -e "interface=$adapter" > /root/pw.conf
306+
echo -e "version=$version" >> /root/pw.conf
307+
echo -e "timeout=$timeout" >> /root/pw.conf
308+
echo -e "stage1=$stage1" >> /root/pw.conf
309+
echo -e "stage2=$stage2" >> /root/pw.conf
310+
fi
311+
312+
echo "{\"output\":\"Save settings\"}"
313+
314+
;;
315+
"enable")
316+
317+
if ! [ "$token" = "$stoken" ]; then
282318

319+
echo "Status: 400 Bad Request"
320+
echo ""
321+
echo "{\"output\":\"Invalid token!\"}"
322+
exit 1
323+
324+
fi
325+
326+
echo ""
283327
if ! grep -q "/root/run.sh" /etc/rc.local; then
284328
sed -i '/exit 0/d' /etc/rc.local
285329
echo "/root/run.sh &" >> /etc/rc.local
@@ -335,7 +379,6 @@ case "$task" in
335379
fi
336380

337381
echo ""
338-
339382
if grep -q "/root/run.sh" /etc/rc.local; then
340383
sed -i '/\/root\/run\.sh/d' /etc/rc.local
341384
fi
@@ -354,7 +397,6 @@ case "$task" in
354397
fi
355398

356399
echo ""
357-
358400
"$(wget -O /tmp/installer.sh https://raw.githubusercontent.com/CodeInvers3/PPPwn_ow/main/installer.sh)"
359401
chmod +x /tmp/installer.sh
360402
if command -v pppwn > /dev/null 2>&1; then
@@ -376,6 +418,7 @@ case "$task" in
376418
exit 1
377419
fi
378420

421+
echo ""
379422
rm -f /usr/bin/pppwn
380423
rm -rf /root/*
381424
rm -rf /www/pppwn
@@ -396,7 +439,6 @@ case "$task" in
396439
fi
397440

398441
echo ""
399-
400442
echo "{"
401443
if /etc/init.d/pppoe-server status | grep -q "running"; then
402444
/etc/init.d/pppoe-server stop
@@ -422,7 +464,6 @@ case "$task" in
422464
fi
423465

424466
echo ""
425-
426467
if ! grep -q "/root/run.sh" /etc/rc.button/switch; then
427468
sed -i "s/action=on/action=on\n\n\/root\/run\.sh/" /etc/rc.button/switch
428469
fi

www/pppwn.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ <h1>PPPwn web</h1>
6868
<div class="field-group box">
6969
<div class="col-group group-center">
7070
<button type="button" id="action_pw" class="btn-form input-attach sec-auto"></button>
71+
<button type="button" id="params_pw" class="btn-form input-attach sec-auto">Save Settings</button>
7172
<button type="button" id="switch_pw" class="btn-form input-attach sec-auto"></button>
7273
<% if(pppoe == 'inactive'){ %>
7374
<button type="button" id="pppoe_pw" class="btn-form input-attach sec-auto">PPPoe start</button>

www/pppwn/main.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,45 @@ var appView = Backbone.View.extend({
7070
}
7171
button.prop('task', 'start').addClass('active').text('Execute');
7272
}).catch(function(err, textStatus, errorThrown){
73-
if(err.responseText) self.textareaOut.append(err.responseText+"\n");
73+
if(err.responseJSON) self.textareaOut.append(err.responseJSON.output+"\n");
7474
if(err.textStatus) self.textareaOut.append(err.textStatus+"\n");
7575
button.prop('task', 'start').addClass('active').text('Execute');
7676
});
7777

78+
},
79+
'click button#params_pw': function(event){
80+
81+
var self = this;
82+
83+
if(!this.inputRoot.val() || !this.inputTimeout.val() || !this.inputAdapter.val() || !this.inputVersion.val()){
84+
$.modal(function (modal) {
85+
modal.content(self.templates.msg({message: 'Required options fields.'}));
86+
});
87+
return;
88+
}
89+
90+
this.model.fetch({
91+
method: 'POST',
92+
data: {
93+
task:'params',
94+
token:this.webToken,
95+
root:this.inputRoot.val(),
96+
stage1:this.stage1[this.inputVersion.val()],
97+
stage2:this.stage2[this.inputVersion.val()],
98+
timeout:this.inputTimeout.val(),
99+
adapter:this.inputAdapter.val(),
100+
version:this.inputVersion.val()
101+
}
102+
}).then(function(response){
103+
console.log(response);
104+
if(response.output){
105+
self.textareaOut.append(response.output+"\n");
106+
}
107+
}).catch(function(err){
108+
console.log(err);
109+
self.textareaOut.append(err.responseJSON.output+"\n");
110+
});
111+
78112
},
79113
'click button#switch_pw': function(event){
80114

@@ -115,7 +149,7 @@ var appView = Backbone.View.extend({
115149
self.textareaOut.append(response.output+"\n");
116150
}
117151
}).catch(function(err){
118-
self.textareaOut.append(err.responseText+"\n");
152+
self.textareaOut.append(err.responseJSON.output+"\n");
119153
});
120154

121155
},

0 commit comments

Comments
 (0)