-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsettings.php
More file actions
611 lines (554 loc) · 25.4 KB
/
settings.php
File metadata and controls
611 lines (554 loc) · 25.4 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<?php
if (!isset($_POST['password'])) {
die();
}
echo "<!DOCTYPE html>\n";
echo "<html lang=\"en\">\n";
echo "\n";
echo "<head>\n";
echo " <meta charset=\"utf-8\">\n";
echo " <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n";
echo " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
echo " <meta name=\"description\" content=\"OpenFLIXR Setup\">\n";
echo " <meta name=\"author\" content=\"OpenFLIXR\">\n";
echo " <title>OpenFLIXR Setup</title>\n";
echo " <link href=\"css/bootstrap.min.css\" rel=\"stylesheet\">\n";
echo " <link href=\"css/stylish-portfolio.css\" rel=\"stylesheet\">\n";
echo " <link href=\"css/gsdk-base.css\" rel=\"stylesheet\" />\n";
echo " <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css\">\n";
echo "<script type=\"text/javascript\">\n";
echo " window.onbeforeunload = function() {\n";
echo " return \"Do not refresh this page! It will leave OpenFLIXR in an unusable state!\";\n";
echo " }\n";
echo "</script>\n";
echo "\n";
echo " <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->\n";
echo " <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->\n";
echo " <!--[if lt IE 9]>\n";
echo " <script src=\"https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js\"></script>\n";
echo " <script src=\"https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js\"></script>\n";
echo " <![endif]-->\n";
echo "\n";
echo "</head>\n";
echo "\n";
echo "<body>\n";
echo " <div class=\"image-container set-full-height\" style=\"background-color: #4c4c4c;;\">\n";
echo " <div class=\"container\">\n";
echo " <div class=\"row\">\n";
echo " <div class=\"col-sm-10 col-sm-offset-1\">\n";
echo " <div class=\"wizard-container\">\n";
echo " <div class=\"card wizard-card ct-wizard-azzure\" id=\"wizard\">\n";
echo " <form action=\"settings.php\" method=\"POST\" id=\"registration-form\">\n";
echo " <div class=\"wizard-header\">\n";
echo " <h3>Configuring <b>OpenFLIXR</b><br><br></h3>\n";
echo " </div>\n";
echo " <br><br><br><center><div class=\"countdown-styled\"></div></center>\n";
echo "<BR><center><div><h4 class=\"info-text\"><a href=\"/\" style=\"text-decoration:none\">When timer reaches ZERO, click here</a></h4></div></center>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo "</body>\n";
echo "<script src=\"js/jquery-1.10.2.js\" type=\"text/javascript\"></script>\n";
echo "<script src=\"js/bootstrap.min.js\" type=\"text/javascript\"></script>\n";
echo "<script src=\"js/jquery.bootstrap.wizard.js\" type=\"text/javascript\"></script>\n";
echo "<script src=\"js/jquery.validate.min.js\"></script>\n";
echo "<script src=\"js/wizard.js\"></script>\n";
echo "<script src=\"js/custom.js\"></script>\n";
echo " <script src=\"js/jquery.countdown.js\"></script>\n";
echo "<script type=\"text/javascript\"> $(function() {\n";
echo " $('.countdown-styled').countdown({\n";
echo " date: +(new Date) + 900000,\n";
echo " render: function(data) {\n";
echo " var el = $(this.el);\n";
echo " el.empty()\n";
echo " .append(\"<div>\" + this.leadingZeros(data.min, 2) + \" <span>min</span></div>\")\n";
echo " .append(\"<div>\" + this.leadingZeros(data.sec, 2) + \" <span>sec</span></div>\");\n";
echo " }\n";
echo " });\n";
echo "\n";
echo " $('.stop').on('click', function(e) {\n";
echo " e.preventDefault();\n";
echo " $('.countdown-styled').data('countdown').stop();\n";
echo " });\n";
echo "\n";
echo " $('.start').on('click', function(e) {\n";
echo " e.preventDefault();\n";
echo " $('.countdown-styled').data('countdown').start();\n";
echo " });\n";
echo "\n";
echo " $('.countdown-callback').countdown({\n";
echo " date: +(new Date) + 10000,\n";
echo " render: function(data) {\n";
echo " $(this.el).text(this.leadingZeros(data.sec, 2) + \" sec\");\n";
echo " },\n";
echo " onEnd: function() {\n";
echo " $(this.el).addClass('ended');\n";
echo " }\n";
echo " }).on(\"click\", function() {\n";
echo " $(this).removeClass('ended').data('countdown').update(+(new Date) + 10000).start();\n";
echo " });\n";
echo "\n";
echo " });</script>\n";
echo "\n";
echo "</html>\n";
$password = $_POST['password'];
$networkconfig = $_POST['networkconfig'];
$ip = $_POST['ip'];
$subnet = $_POST['subnet'];
$gateway = $_POST['gateway'];
$dns = $_POST['dns'];
$letsencrypt = $_POST['letsencrypt'];
$domainname = strtolower($_POST['domainname']);
$email = strtolower($_POST['email']);
$usenetdescription = $_POST['usenetdescription'];
$usenetservername = $_POST['usenetservername'];
$usenetusername = $_POST['usenetusername'];
$usenetpassword = $_POST['usenetpassword'];
$usenetport = $_POST['usenetport'];
$usenetthreads = $_POST['usenetthreads'];
$usenetssl = $_POST['usenetssl'];
$newznabprovider = $_POST['newznabprovider'];
$newznaburl = $_POST['newznaburl'];
$newznabapi = $_POST['newznabapi'];
$tvshowdl = $_POST['tvshowdl'];
$nzbdl = $_POST['nzbdl'];
$mopidy = $_POST['mopidy'];
$hass = $_POST['hass'];
$ntopng = $_POST['ntopng'];
$headphonesuser = $_POST['headphonesuser'];
$headphonespass = $_POST['headphonespass'];
$anidbuser = $_POST['anidbuser'];
$anidbpass = $_POST['anidbpass'];
$spotuser = $_POST['spotuser'];
$spotpass = $_POST['spotpass'];
$imdb = $_POST['imdb'];
$comicvine = $_POST['comicvine'];
if(!filter_var($ip, FILTER_VALIDATE_IP)) {
$ip='';
}
if(!filter_var($subnet, FILTER_VALIDATE_IP)) {
$ip='';
}
if(!filter_var($gateway, FILTER_VALIDATE_IP)) {
$ip='';
}
if(!filter_var($dns, FILTER_VALIDATE_IP)) {
$ip='';
}
#write setup.sh
$file = fopen("setup.sh","w");
fwrite($file,"#!/bin/bash
exec 1> >(tee -a /var/log/openflixrsetup.log) 2>&1
TODAY=$(date)
echo \"-----------------------------------------------------\"
echo \"Date: \$TODAY\"
echo \"-----------------------------------------------------\"
THISUSER=$(whoami)
if [ \$THISUSER != 'root' ]
then
echo 'You must use sudo to run this script, sorry!'
exit 1
fi
## report hypervisor
hypervisor=$(sudo dmidecode -s system-product-name)
version=$(cat /opt/openflixr/version)
if [ \"\$hypervisor\" == 'VirtualBox' ]
then
curl -s \"http://www.openflixr.com/stats.php?vm=VirtualBox&version=\$version\"
elif [ \"\$hypervisor\" == 'Virtual Machine' ]
then
curl -s \"http://www.openflixr.com/stats.php?vm=HyperV&version=\$version\"
elif [ \"\$hypervisor\" == 'Parallels Virtual Platform' ]
then
curl -s \"http://www.openflixr.com/stats.php?vm=Parallels&version=\$version\"
elif [ \"\$hypervisor\" == 'VMware Virtual Platform' ]
then
curl -s \"http://www.openflixr.com/stats.php?vm=VMware&version=\$version\"
else
curl -s \"http://www.openflixr.com/stats.php?vm=Other&version=\$version\"
fi
## variables
networkconfig=$networkconfig
ip='$ip'
subnet='$subnet'
gateway='$gateway'
dns='$dns'
password='$password'
letsencrypt=$letsencrypt
domainname=$domainname
email=$email
usenetdescription='$usenetdescription'
usenetservername=$usenetservername
usenetusername='$usenetusername'
usenetpassword='$usenetpassword'
usenetport=$usenetport
usenetthreads=$usenetthreads
usenetssl=$usenetssl
newznabprovider='$newznabprovider'
newznaburl=$newznaburl
newznabapi='$newznabapi'
tvshowdl=$tvshowdl
nzbdl=$nzbdl
mopidy=$mopidy
hass=$hass
ntopng=$ntopng
headphonesuser='$headphonesuser'
headphonespass='$headphonespass'
anidbuser='$anidbuser'
anidbpass='$anidbpass'
spotuser='$spotuser'
spotpass='$spotpass'
imdb=$imdb
comicvine='$comicvine'
oldpassword=$(crudini --get /usr/share/nginx/html/setup/config.ini password oldpassword)
if [ \"\$oldpassword\" == '' ]
then
oldpassword='openflixr'
fi
## stop services
service couchpotato stop
service headphones stop
service htpcmanager stop
service mylar stop
service sickrage stop
service jackett stop
service mopidy stop
service ntopng stop
service monit stop
## generate api keys
couchapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
sickapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
headapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
mylapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
sabapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
jackapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
sonapi=$(uuidgen | tr -d - | tr -d '' | tr '[:upper:]' '[:lower:]')
echo \"Couchpotato \$couchapi\" >/opt/openflixr/api.keys
echo \"Sickrage \$sickapi\" >>/opt/openflixr/api.keys
echo \"Headphones \$headapi\" >>/opt/openflixr/api.keys
echo \"Mylar \$mylapi\" >>/opt/openflixr/api.keys
echo \"SABnzbd \$sabapi\" >>/opt/openflixr/api.keys
echo \"Jackett \$jackapi\" >>/opt/openflixr/api.keys
echo \"Sonarr \$sonapi\" >>/opt/openflixr/api.keys
## htpcmanager
cd /opt/HTPCManager/userdata
sqlite3 database.db \"UPDATE setting SET val='\$couchapi' where key='couchpotato_apikey';\"
sqlite3 database.db \"UPDATE setting SET val='\$headapi' where key='headphones_apikey';\"
sqlite3 database.db \"UPDATE setting SET val='\$sabapi' where key='sabnzbd_apikey';\"
sqlite3 database.db \"UPDATE setting SET val='\$sickapi' where key='sickrage_apikey';\"
sqlite3 database.db \"UPDATE setting SET val='\$mylapi' where key='mylar_apikey';\"
sqlite3 database.db \"UPDATE setting SET val='\$sonapi' where key='sonarr_apikey';\"
## couchpotato
crudini --set /opt/CouchPotato/settings.conf core api_key \$couchapi
crudini --set /opt/CouchPotato/settings.conf sabnzbd api_key \$sabapi
## sickrage
crudini --set /opt/sickrage/config.ini SABnzbd sab_apikey \$sabapi
crudini --set /opt/sickrage/config.ini General api_key \$sickapi
## headphones
crudini --set /opt/headphones/config.ini General api_key \$headapi
crudini --set /opt/headphones/config.ini SABnzbd sab_apikey \$sabapi
## mylar
crudini --set /opt/Mylar/config.ini General api_key \$mylapi
crudini --set /opt/Mylar/config.ini SABnzbd sab_apikey \$sabapi
## plex
cp /opt/config/monit/plex /etc/monit/conf.d/
## plexrequests
plexreqapi=$(curl -s -X GET --header 'Accept: application/json' 'http://localhost:3579/request/api/apikey?username=openflixr&password='\$oldpassword'' | cut -c10-41)
curl -s -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
\"ApiKey\": \"'\$couchapi'\",
\"Enabled\": true,
\"Ip\": \"localhost\",
\"Port\": 5050,
\"SubDir\": \"couchpotato\"
}' 'http://localhost:3579/request/api/settings/couchpotato?apikey='\$plexreqapi''
curl -s -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
\"ApiKey\": \"'\$headapi'\",
\"Enabled\": true,
\"Ip\": \"localhost\",
\"Port\": 8181,
\"SubDir\": \"headphones\"
}' 'http://localhost:3579/request/api/settings/headphones?apikey='\$plexreqapi''
curl -s -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
\"CurrentPassword\": \"'\$oldpassword'\",
\"NewPassword\": \"'\$password'\"
}' 'http://localhost:3579/request/api/credentials/openflixr?apikey='\$plexreqapi''
## usenet
if [ \"\$usenetpassword\" != '' ]
then
service sabnzbdplus stop
sleep 5
sed -i 's/^api_key.*/api_key = '1234567890'/' /home/openflixr/.sabnzbd/sabnzbd.ini
service sabnzbdplus start
sleep 5
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&enable=1&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&ssl=$usenetssl&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&displayname=$usenetdescription&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&username=$usenetusername&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&password=$usenetpassword&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&host=$usenetservername&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&port=$usenetport&apikey=1234567890'
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&connections=$usenetthreads&apikey=1234567890'
service sabnzbdplus stop
sed -i 's/^api_key.*/api_key = '\$sabapi'/' /home/openflixr/.sabnzbd/sabnzbd.ini
else
service sabnzbdplus stop
sleep 5
sed -i 's/^api_key.*/api_key = '1234567890'/' /home/openflixr/.sabnzbd/sabnzbd.ini
service sabnzbdplus start
sleep 5
curl -s 'http://localhost:8080/api?mode=set_config§ion=servers&keyword=OpenFLIXR_Usenet_Server&output=xml&enable=0&apikey=1234567890'
service sabnzbdplus stop
sed -i 's/^api_key.*/api_key = '\$sabapi'/' /home/openflixr/.sabnzbd/sabnzbd.ini
fi
## newznab
# if [ \"\$newznabapi\" != '' ]
# then
# newznab config
# else
# reverse
# fi
## tv shows downloader
if [ \"\$tvshowdl\" == 'sickrage' ]
then
curl -s -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
\"ApiKey\": \"'\$sickapi'\",
\"qualityProfile\": \"default\",
\"Enabled\": true,
\"Ip\": \"localhost\",
\"Port\": 8081,
\"SubDir\": \"sickrage\"
}' 'http://localhost:3579/request/api/settings/sickrage?apikey='\$plexreqapi''
systemctl disable sonarr.service
update-rc.d sickrage enable
cp /opt/config/monit/sickrage /etc/monit/conf.d/
rm /etc/monit/conf.d/sonarr
sqlite3 database.db \"UPDATE setting SET val='on' where key='sickrage_enable';\"
sqlite3 database.db \"UPDATE setting SET val='0' where key='sonarr_enable';\"
else
curl -s -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
\"ApiKey\": \"'\$sickapi'\",
\"qualityProfile\": \"default\",
\"Enabled\": false,
\"Ip\": \"localhost\",
\"Port\": 8081,
\"SubDir\": \"sickrage\"
}' 'http://localhost:3579/request/api/settings/sickrage?apikey='\$plexreqapi''
systemctl enable sonarr.service
update-rc.d sickrage disable
cp /opt/config/monit/sonarr /etc/monit/conf.d/
rm /etc/monit/conf.d/sickrage
sqlite3 database.db \"UPDATE setting SET val='0' where key='sickrage_enable';\"
sqlite3 database.db \"UPDATE setting SET val='on' where key='sonarr_enable';\"
fi
## sonarr
service sonarr stop
sed -i 's/^ <ApiKey>.*/ <ApiKey>'\$sonapi'<\/ApiKey>/' /root/.config/NzbDrone/config.xml
## nzb downloader
if [ \"\$nzbdl\" == 'sabnzbd' ]
then
systemctl disable nzbget.service
update-rc.d sabnzbdplus enable
cp /opt/config/monit/sabnzbd /etc/monit/conf.d/
rm /etc/monit/conf.d/nzbget
sqlite3 database.db \"UPDATE setting SET val='on' where key='sabnzbd_enable';\"
sqlite3 database.db \"UPDATE setting SET val='0' where key='nzbget_enable';\"
else
systemctl enable nzbget.service
update-rc.d sabnzbdplus disable
cp /opt/config/monit/nzbget /etc/monit/conf.d/
rm /etc/monit/conf.d/sabnzbd
sqlite3 database.db \"UPDATE setting SET val='0' where key='sabnzbd_enable';\"
sqlite3 database.db \"UPDATE setting SET val='on' where key='nzbget_enable';\"
fi
## mopidy
if [ \"\$mopidy\" == 'enabled' ]
then
update-rc.d mopidy enable
cp /opt/config/monit/mopidy /etc/monit/conf.d/
else
update-rc.d mopidy disable
rm /etc/monit/conf.d/mopidy
fi
## home assistant
if [ \"\$hass\" == 'enabled' ]
then
systemctl enable home-assistant.service
cp /opt/config/monit/hass /etc/monit/conf.d/
else
systemctl disable home-assistant.service
rm /etc/monit/conf.d/hass
fi
## ntopng
if [ \"\$ntopng\" == 'enabled' ]
then
update-rc.d ntopng enable
cp /opt/config/monit/ntopng /etc/monit/conf.d/
else
update-rc.d ntopng disable
rm /etc/monit/conf.d/ntopng
fi
## headphones vip
if [ \"\$headphonespass\" != '' ]
then
crudini --set /opt/headphones/config.ini General hpuser $headphonesuser
crudini --set /opt/headphones/config.ini General hppass $headphonespass
crudini --set /opt/headphones/config.ini General headphones_indexer 1
crudini --set /opt/headphones/config.ini General mirror headphones
else
crudini --set /opt/headphones/config.ini General hpuser
crudini --set /opt/headphones/config.ini General hppass
crudini --set /opt/headphones/config.ini General headphones_indexer 0
crudini --set /opt/headphones/config.ini General mirror musicbrainz.org
fi
## anidb
if [ \"\$anidbpass\" != '' ]
then
crudini --set /opt/sickrage/config.ini ANIDB use_anidb 1
crudini --set /opt/sickrage/config.ini ANIDB anidb_password $anidbuser
crudini --set /opt/sickrage/config.ini ANIDB anidb_username $anidbpass
else
crudini --set /opt/sickrage/config.ini ANIDB use_anidb 0
crudini --set /opt/sickrage/config.ini ANIDB anidb_password
crudini --set /opt/sickrage/config.ini ANIDB anidb_username
fi
## spotify mopidy
if [ \"\$spotpass\" != '' ]
then
crudini --set /etc/mopidy/mopidy.conf spotify username $spotuser
crudini --set /etc/mopidy/mopidy.conf spotify password $spotpass
else
crudini --set /etc/mopidy/mopidy.conf spotify username
crudini --set /etc/mopidy/mopidy.conf spotify password
fi
## imdb url
if [ \"\$imdb\" != '' ]
then
crudini --set /opt/CouchPotato/settings.conf imdb automation_urls $imdb
crudini --set /opt/CouchPotato/settings.conf imdb automation_urls_use 1
else
crudini --set /opt/CouchPotato/settings.conf imdb automation_urls
crudini --set /opt/CouchPotato/settings.conf imdb automation_urls_use 0
fi
## comicvine
if [ \"\$comicvine\" != '' ]
then
crudini --set /opt/Mylar/config.ini General comicvine_api $comicvine
else
crudini --set /opt/Mylar/config.ini General comicvine_api
fi
## spotweb
#users / apikey + passwordhash
#usersettings / id3 / otherprefs | sabnzbd api + password
## passwords
printf \"$password\\n$password\\n\" | sudo smbpasswd -a -s openflixr
echo openflixr:'$password' | sudo chpasswd
htpasswd -b /etc/nginx/.htpasswd openflixr '$password'
## MySQL
service mysql stop
killall -vw mysqld
mysqld_safe --skip-grant-tables >res 2>&1 &
sleep 10
mysql -e \"UPDATE mysql.user SET authentication_string = PASSWORD('$password') WHERE User = 'root' AND Host = 'localhost';FLUSH PRIVILEGES;\"
killall -v mysqld
sleep 5
service mysql restart
sed -i 's/^-F \"mysql.*/-F \"mysql;localhost;ntopng;flows;root;$password\"/' /etc/ntopng/ntopng.conf
sed -i \"s/^.*PSM_DB_PASS.*/define('PSM_DB_PASS', '$password');/\" /usr/share/nginx/html/phpservermonitor/config.php
sed -i \"s/^.*\['pass'\].*/\\\$dbsettings\['pass'\] = '$password';/\" /var/www/spotweb/dbsettings.inc.php
## network
nwadapter=$(ifconfig -a | sed -n 's/^\([^ ]\+\).*/\\1/p' | grep -Fvx -e lo -e dummy0)
if [ \"\$ip\" != '' ]
then
cat > /etc/network/interfaces<<EOF
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo \$nwadapter
iface lo inet loopback
# The primary network interface
iface \$nwadapter inet static
address $ip
netmask $subnet
gateway $gateway
dns-nameservers $dns
EOF
else
cat > /etc/network/interfaces<<EOF
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo \$nwadapter
iface lo inet loopback
# The primary network interface
iface \$nwadapter inet dhcp
dns-nameservers 8.8.8.8 8.8.4.4
EOF
fi
## letsencrypt
if [ \"\$letsencrypt\" == 'on' ]
then
rm -rf /var/log/letsencrypt/
sed -i 's/^email.*/email = $email/' /opt/letsencrypt/cli.ini
sed -i 's/^domains.*/domains = $domainname, www.$domainname/' /opt/letsencrypt/cli.ini
service nginx stop
sudo bash /opt/openflixr/letsencrypt.sh
failed1=$(cat /var/log/letsencrypt/letsencrypt.log | grep \"Failed authorization procedure\")
failed2=$(cat /var/log/letsencrypt/letsencrypt.log | grep \"is not a FQDN\")
if [ \"\$failed1\" == '' ] && [ \"\$failed2\" == '' ]
then
sed -i 's/^server_name.*/server_name openflixr $domainname www.$domainname; #donotremove_domainname/' /etc/nginx/sites-enabled/reverse
sed -i 's/^.*#donotremove_certificatepath/ssl_certificate \/etc\/letsencrypt\/live\/$domainname\/fullchain.pem; #donotremove_certificatepath/' /etc/nginx/sites-enabled/reverse
sed -i 's/^.*#donotremove_certificatekeypath/ssl_certificate_key \/etc\/letsencrypt\/live\/$domainname\/privkey.pem; #donotremove_certificatekeypath/' /etc/nginx/sites-enabled/reverse
sed -i 's/^.*#donotremove_trustedcertificatepath/ssl_trusted_certificate \/etc\/letsencrypt\/live\/$domainname\/fullchain.pem; #donotremove_trustedcertificatepath/' /etc/nginx/sites-enabled/reverse
else
echo \"Failed authorization procedure or is not a FQDN\"
fi
else
sed -i 's/^server_name.*/server_name openflixr; #donotremove_domainname/' /etc/nginx/sites-enabled/reverse
sed -i 's/^.*#donotremove_certificatepath/#ssl_certificate \/etc\/letsencrypt\/live\/example\/fullchain.pem; #donotremove_certificatepath/' /etc/nginx/sites-enabled/reverse
sed -i 's/^.*#donotremove_certificatekeypath/#ssl_certificate_key \/etc\/letsencrypt\/live\/example\/privkey.pem; #donotremove_certificatekeypath/' /etc/nginx/sites-enabled/reverse
sed -i 's/^.*#donotremove_trustedcertificatepath/#ssl_trusted_certificate \/etc\/letsencrypt\/live\/example\/fullchain.pem; #donotremove_trustedcertificatepath/' /etc/nginx/sites-enabled/reverse
fi
crudini --set /usr/share/nginx/html/setup/config.ini network networkconfig $networkconfig
crudini --set /usr/share/nginx/html/setup/config.ini network ip $ip
crudini --set /usr/share/nginx/html/setup/config.ini network subnet $subnet
crudini --set /usr/share/nginx/html/setup/config.ini network gateway $gateway
crudini --set /usr/share/nginx/html/setup/config.ini network dns $dns
crudini --set /usr/share/nginx/html/setup/config.ini password oldpassword $password
crudini --set /usr/share/nginx/html/setup/config.ini access letsencrypt $letsencrypt
crudini --set /usr/share/nginx/html/setup/config.ini access domainname $domainname
crudini --set /usr/share/nginx/html/setup/config.ini access email $email
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetdescription $usenetdescription
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetservername $usenetservername
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetusername $usenetusername
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetpassword $usenetpassword
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetport $usenetport
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetthreads $usenetthreads
crudini --set /usr/share/nginx/html/setup/config.ini usenet usenetssl $usenetssl
crudini --set /usr/share/nginx/html/setup/config.ini newznab newznabprovider $newznabprovider
crudini --set /usr/share/nginx/html/setup/config.ini newznab newznaburl $newznaburl
crudini --set /usr/share/nginx/html/setup/config.ini newznab newznabapi $newznabapi
crudini --set /usr/share/nginx/html/setup/config.ini modules tvshowdl $tvshowdl
crudini --set /usr/share/nginx/html/setup/config.ini modules nzbdl $nzbdl
crudini --set /usr/share/nginx/html/setup/config.ini modules mopidy $mopidy
crudini --set /usr/share/nginx/html/setup/config.ini modules hass $hass
crudini --set /usr/share/nginx/html/setup/config.ini modules ntopng $ntopng
crudini --set /usr/share/nginx/html/setup/config.ini extras headphonesuser $headphonesuser
crudini --set /usr/share/nginx/html/setup/config.ini extras headphonespass $headphonespass
crudini --set /usr/share/nginx/html/setup/config.ini extras anidbuser $anidbuser
crudini --set /usr/share/nginx/html/setup/config.ini extras anidbpass $anidbpass
crudini --set /usr/share/nginx/html/setup/config.ini extras spotuser $spotuser
crudini --set /usr/share/nginx/html/setup/config.ini extras spotpass $spotpass
crudini --set /usr/share/nginx/html/setup/config.ini extras imdb $imdb
crudini --set /usr/share/nginx/html/setup/config.ini extras comicvine $comicvine
systemctl --system daemon-reload
bash /opt/openflixr/updatewkly.sh
reboot now");
fclose($file);
exec('sudo bash /usr/share/nginx/html/setup/setup.sh > /dev/null 2>&1 &');
?>