-
Notifications
You must be signed in to change notification settings - Fork 3
/
tr_settings.php
276 lines (246 loc) · 11 KB
/
tr_settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
/*
* advanced.php
*
* Copyright (C) 2013-2024 by Erland Hedman <erland@hedmanshome.se>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
include 'cgi-bin/common.php';
//if (count($_POST)) {echo "<pre>"; print_r($_POST); echo "</pre>";}
if (count($_POST) && $_POST["POST_ACTION"] == "OK") {
if (! function_exists('pcntl_fork')) die('PCNTL functions not available on this PHP installation');
$pid = pcntl_fork();
if ($pid == -1) {
echo("<pre>pcntl_fork: failed - check the extension for pcntl.so\n");
print_r(error_get_last());
echo "</pre>\n"; exit;
} else if (!$pid) {
// We are the child
@system("/usr/bin/systemctl stop transmission-daemon.service");
do_transmission(implode(" ", $_POST));
if ($_POST['f_tr_enabled'] == 0)
@system("/usr/bin/systemctl disable transmission-daemon.service");
else {
@system("/usr/bin/systemctl enable transmission-daemon.service");
@system("/usr/bin/systemctl restart transmission-daemon.service");
}
if (g_srvstat("shorewall") == true)
do_firewall_mgm("restart");
} else {
// We are the parent
$tmo=10;
header('Location: http://'. $_SERVER["SERVER_ADDR"]. '/wait.php?seconds='.$tmo.'&loc='.$_SERVER['SCRIPT_NAME']);
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/css/bridge.css">
<title><?php p_title(); ?></title>
<script>
<?php include 'inc/general.js.php' ?>
<?php setTimeout(); ?>
function initPage()
{
var f=getObj("form");
f.tr_enabled.checked=<?php echo g_srvstat("transmission-daemon")? "true":"false" ?>;
f.tr_port.value=<?php echo trim(exec("grep rpc-port ".g_trcfg()." | awk -F: '{gsub(/,/,\"\"); print \$2}'")); ?>;
f.tr_user_name.value="<?php echo trim(exec("grep rpc-username ".g_trcfg()." | awk -F\\\" '{gsub(/,/,\"\"); print \$4}'")); ?>";
if (<?php echo trim(exec("grep rpc-authentication-required ".g_trcfg()." | awk -F: '{gsub(/,/,\"\"); print \$2}'")); ?>)
{
f.tr_auth.checked=true;
getObj("show_auth").style.display = "block";
} else getObj("show_auth").style.display = "none";
return true;
}
function checkPage()
{
var f=getObj("form");
if (isFieldBlank(getObj("tr_port").value) == true) {
getObj("tr_port").select();
alert("Server Port field is blank");
return false;
}
if (isDecimal(getObj("tr_port").value) == false) {
getObj("tr_port").select();
alert("Server Port field is not a number");
return false;
}
if (getObj("tr_folder").value == "none") {
alert("No download folder selected");
return false;
}
if (f.tr_auth.checked == true) {
if (isFieldBlank(getObj("tr_user_name").value) == true) {
getObj("tr_user_name").select();
alert("User Name field is blank");
return false;
}
if (isFieldAscii(getObj("tr_user_name").value) == false) {
getObj("tr_user_name").select();
alert("User Name field is garbled");
return false;
}
if (isFieldBlank(getObj("tr_user_pw").value) == true) {
getObj("tr_user_pw").select();
alert("User Password field is blank");
return false;
}
if (isFieldAscii(getObj("tr_user_pw").value) == false) {
getObj("tr_user_pw").select();
alert("User Password field is garbled");
return false;
}
f.f_tr_auth.value=1;
}
f.POST_ACTION.value = "OK";
f.submit();
return true;
}
function setEnable(obj)
{
var f=getObj("form");
f.f_tr_enabled.value = obj.checked == true? 1:0;
return true;
}
function setAuth(obj)
{
var f=getObj("form");
if (obj.checked == true) {
getObj("show_auth").style.display = "block";
f.f_tr_auth.value = 1;
} else {
getObj("show_auth").style.display = "none";
f.f_tr_auth.value = 0;
}
}
function setDlf()
{
var f=getObj("form");
var sf="<?php echo trim(exec("grep download-dir ".g_trcfg()." | awk -F/ '{gsub(/\",/,\"\"); print \$(NF-1)}'")); ?>";
var fld=f.tr_folder;
for (var i = 0; i < fld.length; i++)
{
if (fld.options[i].text == sf) {
fld.selectedIndex=i;
}
}
}
</script>
</head>
<body onload="initPage();"><script>onbody();</script>
<form name="form" id="form" method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" onsubmit="return checkPage();">
<input name="POST_ACTION" value="0" type="hidden">
<input name="f_tr_enabled" value="<?php echo g_srvstat("transmission-daemon")? "1":"0"; ?>" type="hidden">
<input name="f_tr_auth" value="0" type="hidden">
<table id="topContainer">
<tr>
<td class="laCN">Project Page : <a href="<?php p_productHome(); ?>" target=_blank><?php p_serverName(); ?></a></td>
<td class="raCN">Version : <?php p_firmware("-ro");?> </td>
</tr>
</table>
<table id="topTable">
<tr>
<td id="topBarLeft"><a id="logo" href="<?php p_productHome(); ?>"></a></td>
<td id="topBarRight"></td>
</tr>
</table>
<table id="topMenuTable">
<tr>
<td class="ledPanel">
<img class="led" alt="fwstat" title="Firewall" src="/img/<?php echo g_srvstat("shorewall")? "on":"off" ?>.png">
<img class="led" alt="dnsstat" title="DNS" src="/img/<?php echo g_srvstat("named")? "on":"off" ?>.png">
<img class="led" alt="dhcpstat" title="DHCP" src="/img/<?php echo g_srvstat("dhcpd")? "on":"off" ?>.png">
</td>
<td class="topMenuLink"><a href="/network.php">Setup</a></td>
<td class="topMenuThis"><a href="/advanced.php">Advanced</a></td>
<td class="topMenuLink"><a href="/admin.php">MAINTENANCE</a></td>
<td class="topMenuLink"><a href="/status.php">Status</a></td>
<td class="topMenuLink"><a href="/logout.php"><span id="timer"></span></a></td>
</tr>
</table>
<table id="mainContentTable">
<tr style="vertical-align: top;">
<td class="leftMenyContatiner">
<div class="leftNavLink">
<ul style="width: 100%">
<li><div class="leftnavLink"><a href="/storage.php">Storage</a></div></li>
<li><div class="leftnavLink"><a href="/transmission.php">Transmission</a></div></li>
<li><div id="left" class="navThis">Settings</div></li>
</ul>
</div>
</td>
<td id="contentHeading">
<div id="contentBox">
<h1>Settings</h1>
Here you can setup your <?php p_mode(); ?> to act as a BitTorrent Server for for most computers on your LAN.
<br><br>
<?php if (g_srvstat("smbd")) {?><input value="Save Settings" type="submit"> <?php }?>
<input value="Don't Save Settings" onclick="cancelSettings()" type="button">
<?php echo g_srvstat("transmission-daemon")? '<b style="color:#090;">Transmission Service is active</b>':'<b style="color:#f00;">Transmission Service is disabled.</b>'; ?>
</div><div class="vbr"></div>
<div class="actionBox">
<h2 class="actionHeader">Transmission Settings</h2>
This section manages the settings for Transmission.<br><br>
<table>
<tr>
<td class="raCN" style="width:30%"><b>Service enabled :</b></td>
<td>
<input type="checkbox" id="tr_enabled" onchange="setEnable(this);" <?php echo g_srvstat("smbd")? "":'disabled="disabled"'; ?>>
</td>
</tr>
<tr>
<td class="raCN"><b>Server Port :</b></td>
<td> <input style="width:8%" type="text" id="tr_port" name="tr_port" maxlength="4" value=""></td>
</tr>
<tr>
<td class="raCN"><b>Download folder : </b></td>
<td>
<select id="tr_folder" name="tr_folder">
<option value="none">none</option><?php system('cifsshares | awk -F, \'{ printf "<option value=\"%s\">%s</option>", $3, $1}\''); ?>
</select> /transmision
<script>setDlf();</script>
</td>
</tr>
<tr>
<td class="raCN"><b>Authentication-required :</b></td>
<td>
<input type="checkbox" id="tr_auth" onchange="setAuth(this);">
</td>
</tr>
</table>
<div id="show_auth">
<table>
<tr>
<td class="raCN" style="width:30%"><b>User Name :</b></td>
<td> <input type="text" id="tr_user_name" name="tr_user_name" maxlength="60" value=""></td>
</tr>
<tr>
<td class="raCN"><b>Password :</b></td>
<td> <input type="text" id="tr_user_pw" name="tr_user_pw" maxlength="60" value=""></td>
</tr>
</table>
</div>
</div>
</td>
<td id="quickHelpContent"><strong>Help...</strong><br>
<br>
To enable this service, you must have a disk partition and shares defined in the STORAGE menu.
</td>
</tr>
<tr>
<td colspan="3" id="footer">
Copyright © <?php p_copyRight(); ?>
</td>
</tr>
</table>
</form>
</body>
</html>