-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1062 lines (934 loc) · 40.8 KB
/
Copy pathscript.js
File metadata and controls
1062 lines (934 loc) · 40.8 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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// R8.0207.1726
// ==================================================
// グローバル変数と定数
// ==================================================
let currentLanguage = 'en';
let currentTheme = 'auto';
// デフォルト設定(キャッシュクリア時の復元用)
const DEFAULT_ADDRESSES = [
'192.168.1.1',
'192.168.0.1',
'192.168.10.1',
'192.168.100.1',
'openwrt.lan',
'10.0.0.1',
'172.16.0.1'
];
const DEFAULT_SERVICES = {
luci: { name: 'LuCI', port: '80', protocol: 'http' },
ttyd: { name: 'ttyd', port: '7681', protocol: 'http' },
filebrowser: { name: 'filebrowser', port: '8080', protocol: 'http' },
adguard: { name: 'AdGuardHome', port: '8000', protocol: 'http' },
netdata: { name: 'netdata', port: '19999', protocol: 'http' }
};
const AIOS_URL = 'https://raw.githubusercontent.com/site-u2023/aios/main/aios';
const AIOS_URL2 = 'https://site-u.pages.dev/www/aios2.sh';
const PROXY_URL = 'https://proxy.site-u.workers.dev/proxy?url=';
const BASE_DIR = '/tmp/aios';
const BASE_DIR2 = '/tmp/aios2';
const AIOS_PATH = `${BASE_DIR}/aios`;
const AIOS_PATH2 = `${BASE_DIR2}/aios2.sh`;
// .batテンプレート
const BAT_TEMPLATES = {
aios2: `@echo off
setlocal
REM Self-elevate using VBScript
>nul 2>&1 "%SYSTEMROOT%\\system32\\cacls.exe" "%SYSTEMROOT%\\system32\\config\\system"
if %errorLevel% neq 0 (
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\\getadmin.vbs"
"%temp%\\getadmin.vbs"
del "%temp%\\getadmin.vbs"
goto :eof
)
set AIOS2_URL=https://site-u.pages.dev/www/aios2.sh
set BASE_DIR=/tmp/aios2
set SCRIPT_PATH=%BASE_DIR%/aios2.sh
echo ========================================
echo aios2 - OpenWrt Setup
echo ========================================
echo.
REM Detect default gateway
set "IP=__IP_ADDRESS__"
for /f "tokens=3" %%a in ('route print 0.0.0.0 ^| findstr /R "0\\.0\\.0\\.0.*0\\.0\\.0\\.0"') do (
set "GW=%%a"
goto :check_gw
)
goto :gw_done
:check_gw
for /f "tokens=1,2 delims=." %%x in ("%GW%") do (
if "%%x"=="10" set "IP=%GW%"
if "%%x"=="192" if "%%y"=="168" set "IP=%GW%"
if "%%x"=="172" set "IP=%GW%"
)
:gw_done
set /p "IP=Enter OpenWrt IP address [%IP%]: "
echo.
echo Target: %IP%
echo.
echo [1/2] Checking connection...
ping -n 1 -w 1000 %IP% >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo ERROR: Cannot reach %IP%
pause
exit /b 1
)
echo Connected.
echo.
echo [2/2] Executing installation script...
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL -o GlobalKnownHostsFile=NUL -o LogLevel=ERROR -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -tt root@%IP% "mkdir -p %BASE_DIR% && wget --no-check-certificate -O %SCRIPT_PATH% %AIOS2_URL% && chmod +x %SCRIPT_PATH% && %SCRIPT_PATH% && echo '#!/bin/sh' > /usr/bin/aios2 && echo 'mkdir -p /tmp/aios2' >> /usr/bin/aios2 && echo 'wget --no-check-certificate -O /tmp/aios2/aios2.sh \\"https://site-u.pages.dev/www/aios2.sh?t=\\$(date +%%s)\\"' >> /usr/bin/aios2 && echo 'chmod +x /tmp/aios2/aios2.sh' >> /usr/bin/aios2 && echo 'exec /tmp/aios2/aios2.sh \\"\\$@\\"' >> /usr/bin/aios2 && chmod +x /usr/bin/aios2"
if %ERRORLEVEL% EQU 0 (
echo.
echo Installation completed successfully!
echo Persistent command '/usr/bin/aios2' has been created.
echo After running aios2.bat, you can run 'aios2' from the OpenWrt console.
) else (
echo.
echo ERROR: Installation failed.
)
echo.
echo Press any key to close this window...
pause >nul
exit /b`,
aios: `@echo off
setlocal
REM Self-elevate using VBScript
>nul 2>&1 "%SYSTEMROOT%\\system32\\cacls.exe" "%SYSTEMROOT%\\system32\\config\\system"
if %errorLevel% neq 0 (
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\\getadmin.vbs"
"%temp%\\getadmin.vbs"
del "%temp%\\getadmin.vbs"
goto :eof
)
set AIOS_URL=https://raw.githubusercontent.com/site-u2023/aios/main/aios
set PROXY_URL=https://proxy.site-u.workers.dev/proxy?url=
set BASE_DIR=/tmp/aios
set SCRIPT_PATH=%BASE_DIR%/aios
echo ========================================
echo aios - OpenWrt Menu Script
echo ========================================
echo.
REM Detect default gateway
set "IP=__IP_ADDRESS__"
for /f "tokens=3" %%a in ('route print 0.0.0.0 ^| findstr /R "0\\.0\\.0\\.0.*0\\.0\\.0\\.0"') do (
set "GW=%%a"
goto :check_gw
)
goto :gw_done
:check_gw
for /f "tokens=1,2 delims=." %%x in ("%GW%") do (
if "%%x"=="10" set "IP=%GW%"
if "%%x"=="192" if "%%y"=="168" set "IP=%GW%"
if "%%x"=="172" set "IP=%GW%"
)
:gw_done
set /p "IP=Enter OpenWrt IP address [%IP%]: "
echo.
echo Target: %IP%
echo.
echo [1/2] Checking connection...
ping -n 1 -w 1000 %IP% >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo ERROR: Cannot reach %IP%
pause
exit /b 1
)
echo Connected.
echo.
echo [2/2] Executing menu script...
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL -o GlobalKnownHostsFile=NUL -o LogLevel=ERROR -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -tt root@%IP% "mkdir -p %BASE_DIR% && wget --no-check-certificate -O %SCRIPT_PATH% '%PROXY_URL%%AIOS_URL%' && chmod +x %SCRIPT_PATH% && %SCRIPT_PATH%"
echo.
echo Press any key to close this window...
pause >nul
exit /b`,
ssh: `@echo off
setlocal
REM Self-elevate using VBScript
>nul 2>&1 "%SYSTEMROOT%\\system32\\cacls.exe" "%SYSTEMROOT%\\system32\\config\\system"
if %errorLevel% neq 0 (
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\\getadmin.vbs"
"%temp%\\getadmin.vbs"
del "%temp%\\getadmin.vbs"
goto :eof
)
echo ========================================
echo SSH - OpenWrt Connection
echo ========================================
echo.
REM Detect default gateway
set "IP=__IP_ADDRESS__"
for /f "tokens=3" %%a in ('route print 0.0.0.0 ^| findstr /R "0\\.0\\.0\\.0.*0\\.0\\.0\\.0"') do (
set "GW=%%a"
goto :check_gw
)
goto :gw_done
:check_gw
for /f "tokens=1,2 delims=." %%x in ("%GW%") do (
if "%%x"=="10" set "IP=%GW%"
if "%%x"=="192" if "%%y"=="168" set "IP=%GW%"
if "%%x"=="172" set "IP=%GW%"
)
:gw_done
set /p "IP=Enter OpenWrt IP address [%IP%]: "
echo.
echo Target: root@%IP%
echo.
echo Connecting...
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL -o GlobalKnownHostsFile=NUL -o LogLevel=ERROR -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -tt root@%IP%
echo.
echo Press any key to close this window...
pause >nul`
};
const DEFAULT_TERMINALS = {
openwrtconnect: {
name: 'aios-connect.msi'
},
aios2: {
name: 'aios2.bat'
},
aios: {
name: 'aios.bat (Old version)'
},
ssh: {
name: 'SSH.bat'
}
};
// プロンプト用デフォルト値(一元管理)
const PROMPT_DEFAULTS = {
newAddress: '192.168.1.2',
serviceName: 'custom',
portNumber: '10000',
protocol: 'http',
terminalName: 'custom',
defaultCommand: '',
setupName: 'custom',
setupLink: 'https://example.com'
};
// 現在の設定(localStorage と DEFAULT をマージして使用)
let currentAddresses = [];
let currentServices = {};
let currentTerminals = {};
let currentIP = '192.168.1.1';
let currentSelectedService = 'luci';
let currentSelectedTerminal = 'openwrtconnect';
// Multi-language Support
const translations = {
ja: {
address: 'アドレス',
browser: 'ブラウザ',
terminal: 'ターミナル (Windows用)',
initialSetup: '初期設定 (ターミナル用)',
apply: '適用',
open: '開く',
download: 'ダウンロード',
qrCodeDisplay: 'QRコード',
qrCodeArea: 'QRコード表示エリア',
OpenWrtCustom: 'カスタムファームウェアビルダー',
firmwareDownload: 'デバイス用のOpenWtファームウェアをダウンロード',
disclaimerPageTitle: '免責事項',
disclaimerSiteUTitle: 'site-u(当サイト)に関する免責事項',
disclaimerOpenWrtTitle: 'OpenWrtに関する免責事項',
disclaimerSiteUParagraph: '当サイトで公開されているコンテンツ(ウェブサイト、スクリプト、その他の著作物を含む)は全てオープンであり、自由にご利用いただけます。しかしながら、これらのコンテンツの利用によって生じたいかなる損害についても、当サイトの運営者は一切の責任を負いません。利用者の皆様の責任においてご利用くださいますようお願いいたします。',
disclaimerOpenWrtParagraph: 'OpenWrtはSoftware Freedom Conservancyの登録商標です。当サイトはOpenWrtプロジェクトとは提携しておらず、また推奨もされていません。OpenWrtに関する公式情報やサポートについては、OpenWrt公式サイトをご参照ください。',
footerMemo: 'OpenWrt 初心者備忘録',
footerCopyright: '© site-u',
footerDisclaimer: '免責事項',
langEn: 'English',
langJa: '日本語',
// Terminal Explanations
aiosExplanation: '旧版',
aiosExplanationLink: 'https://github.com/site-u2023/aios/blob/main/README.md',
aios2Explanation: 'aios2.bat実行後はOpenWrtコンソールで "aios2" コマンドから実行できます',
aios2ExplanationLink: 'https://github.com/site-u2023/site-u2023.github.io/blob/main/www/README.md',
openwrtconnectExplanation: 'Windowsインストーラー<br>※ブラウザ警告が出た場合は「詳細を表示」>「保持する」を選択してください',
openwrtconnectExplanationLink: 'https://github.com/site-u2023/site-u2023.github.io/releases/tag/release',
sshExplanation: 'SSHログイン',
// iPhone
termius: 'Termius (SSH)',
appStore: 'App Storeで開く',
connectNote: 'ダウンロード後、設定したIPアドレスでSSH接続して下さい',
// Android
juiceSSH: 'JuiceSSH',
googlePlay: 'Google Playで開く',
// Setup Explanations
windowsSetupExplanation: 'プロトコルハンドラー登録 (レジストリファイルをダウンロードし、ダブルクリックしてインストールして下さい)',
windowsSetupExplanationLink: 'https://github.com/site-u2023/site-u2023.github.io/blob/main/file/sshcmd.reg',
iphoneSetupExplanation: 'Termiusインストール (App StoreからTermiusをインストールし、設定したIPアドレスでSSH接続して下さい)',
androidSetupExplanation: 'JuiceSSHインストール (Google PlayからJuiceSSHをインストールし、設定したIPアドレスでSSH接続して下さい)',
// Dialog Messages - 日本語追加
promptNewAddress: '新しいIPアドレスまたはホスト名を入力して下さい:',
alertMinimumAddress: '最低1つのアドレスは必要です',
promptServiceName: 'サービス名を入力してください:',
promptPortNumber: 'ポート番号を入力してください:',
promptProtocol: 'プロトコル(http/https)を入力してください:',
confirmDeleteService: 'サービス "{0}" を削除しますか?',
alertMinimumService: '最低1つのサービスは必要です',
promptTerminalName: 'ターミナル名を入力してください:',
promptDefaultCommand: 'デフォルトコマンドを入力してください:',
confirmDeleteTerminal: 'ターミナル "{0}" を削除しますか?',
alertMinimumTerminal: '最低1つのターミナルは必要です',
promptSetupName: '初期設定名を入力してください:',
promptSetupLink: 'リンクまたはファイルパスを入力してください:',
confirmDeleteSetup: '初期設定 "{0}" を削除しますか?',
alertMinimumSetup: '最低1つの初期設定は必要です',
promptItemName: '項目名を入力してください:',
promptValue: '値を入力してください:',
alertMinimumItem: '最低1つの項目は必要です',
confirmDeleteItem: '項目 "{0}" を削除します'
},
en: {
address: 'Address',
browser: 'Browser',
terminal: 'Terminal (for Windows)',
initialSetup: 'Initial Setup (for Terminal)',
apply: 'Apply',
open: 'Open',
download: 'Download',
qrCodeDisplay: 'QR Code',
qrCodeArea: 'QR Code Display Area',
explanation: 'Explanation',
OpenWrtCustom: 'Custom Firmware Builder ',
firmwareDownload: 'Download OpenWrt firmware for your device',
disclaimerPageTitle: 'Disclaimer',
disclaimerSiteUTitle: 'Disclaimer regarding site-u (this site)',
disclaimerOpenWrtTitle: 'Disclaimer regarding OpenWrt',
disclaimerSiteUParagraph: 'All content published on this site (including websites, scripts, and other works) is open and available for free use. However, the site operator assumes no responsibility for any damages arising from the use of this content. Please use at your own risk.',
disclaimerOpenWrtParagraph: 'OpenWrt is a registered trademark of Software Freedom Conservancy. This site is not affiliated with or endorsed by the OpenWrt project. For official information and support regarding OpenWrt, please refer to the official OpenWrt website.',
footerMemo: 'OpenWrt A Beginner\'s Notebook',
footerCopyright: '© site-u',
footerDisclaimer: 'Disclaimer',
langEn: 'English',
langJa: '日本語',
// Terminal Explanations
aiosExplanation: 'Old version',
aiosExplanationLink: 'https://github.com/site-u2023/aios/blob/main/README.md',
aios2Explanation: 'After running aios2.bat, you can run "aios2" command from the OpenWrt console',
aios2ExplanationLink: 'https://github.com/site-u2023/site-u2023.github.io/blob/main/www/README.md',
openwrtconnectExplanation: 'Windows Installer<br>*If browser warning appears, click "Show more" → "Keep"',
openwrtconnectExplanationLink: 'https://github.com/site-u2023/site-u2023.github.io/releases/tag/release',
sshExplanation: 'SSH login',
// iPhone
termius: 'Termius (SSH)',
appStore: 'Open in App Store',
// Android
juiceSSH: 'JuiceSSH',
googlePlay: 'Open in Google Play',
// Setup Explanations
setupExplanation: 'Explanation',
windowsSetupExplanation: 'Protocol handler registration (Please download the registry file and double-click to install)',
windowsSetupExplanationLink: 'https://github.com/site-u2023/site-u2023.github.io/blob/main/file/sshcmd.reg',
iphoneSetupExplanation: 'Termius installation (Please install Termius from App Store and connect via SSH using your configured IP address)',
androidSetupExplanation: 'JuiceSSH installation (Please install JuiceSSH from Google Play and connect via SSH using your configured IP address)',
// Dialog Messages
promptNewAddress: 'Please enter a new IP address or hostname:',
alertMinimumAddress: 'At least one address is required',
promptServiceName: 'Please enter service name:',
promptPortNumber: 'Please enter port number:',
promptProtocol: 'Please enter protocol (http/https):',
confirmDeleteService: 'Delete service "{0}"?',
alertMinimumService: 'At least one service is required',
promptTerminalName: 'Please enter terminal name:',
promptDefaultCommand: 'Please enter default command:',
confirmDeleteTerminal: 'Delete terminal "{0}"?',
alertMinimumTerminal: 'At least one terminal is required',
promptSetupName: 'Please enter setup name:',
promptSetupLink: 'Please enter link or file path:',
confirmDeleteSetup: 'Delete setup "{0}"?',
alertMinimumSetup: 'At least one setup is required',
promptItemName: 'Please enter item name:',
promptValue: 'Please enter value:',
alertMinimumItem: 'At least one item is required',
confirmDeleteItem: 'Deleting item "{0}"'
}
};
// 翻訳テキスト取得関数
function getText(key, ...args) {
let text = translations[currentLanguage][key] || translations['en'][key] || key;
// {0}, {1} などのプレースホルダーを置換
args.forEach((arg, index) => {
text = text.replace(`{${index}}`, arg);
});
return text;
}
// ==================================================
// 初期化
// ==================================================
document.addEventListener('DOMContentLoaded', function() {
initializeSettings();
bindEvents();
updateAllDisplays();
});
function initializeSettings() {
// 言語設定の復元
const savedLanguage = localStorage.getItem('language') || 'en';
currentLanguage = savedLanguage;
// 翻訳を適用
updateLanguageDisplay();
// テーマ設定の復元
const savedTheme = localStorage.getItem('theme') || 'auto';
currentTheme = savedTheme;
applyTheme(currentTheme);
// アドレス設定の復元
const savedAddresses = localStorage.getItem('addresses');
currentAddresses = savedAddresses ? JSON.parse(savedAddresses) : [...DEFAULT_ADDRESSES];
// サービス設定の復元
const savedServices = localStorage.getItem('services');
currentServices = savedServices ? JSON.parse(savedServices) : {...DEFAULT_SERVICES};
// ターミナル設定の復元
const savedTerminals = localStorage.getItem('terminals');
currentTerminals = savedTerminals ? JSON.parse(savedTerminals) : {...DEFAULT_TERMINALS};
// UI要素の初期化
updateAddressSelector();
updateServiceSelector();
updateTerminalSelector();
// **修正: より確実な値の設定**
setTimeout(() => {
restoreUIValues();
}, 10);
}
// **新規追加: UI要素の値を確実に復元する関数**
function restoreUIValues() {
const ipSelector = document.getElementById('global-ip-input');
if (ipSelector) {
ipSelector.value = currentIP;
console.log('IP selector restored to:', currentIP);
}
const serviceSelector = document.getElementById('service-selector');
if (serviceSelector) {
serviceSelector.value = currentSelectedService;
console.log('Service selector restored to:', currentSelectedService);
}
const terminalSelector = document.getElementById('terminal-selector');
if (terminalSelector) {
terminalSelector.value = currentSelectedTerminal;
console.log('Terminal selector restored to:', currentSelectedTerminal);
}
// 各要素の表示を更新
updateServicePort();
updateTerminalExplanation();
}
function bindEvents() {
// IPアドレス関連
const ipSelector = document.getElementById('global-ip-input');
const globalIpUpdate = document.getElementById('global-ip-update');
const addressAdd = document.getElementById('address-add');
const addressRemove = document.getElementById('address-remove');
if (ipSelector) {
ipSelector.addEventListener('change', function() {
currentIP = this.value;
localStorage.setItem('currentIP', currentIP);
console.log('IP changed to:', currentIP);
updateAllDisplays();
});
}
if (globalIpUpdate) {
globalIpUpdate.addEventListener('click', function() {
if (ipSelector) {
currentIP = ipSelector.value;
localStorage.setItem('currentIP', currentIP);
console.log('IP updated to:', currentIP);
updateAllDisplays();
}
});
}
if (addressAdd) {
addressAdd.addEventListener('click', function() {
const newAddress = prompt(getText('promptNewAddress'), PROMPT_DEFAULTS.newAddress);
if (newAddress && newAddress.trim()) {
const trimmedAddress = newAddress.trim();
if (!currentAddresses.includes(trimmedAddress)) {
currentAddresses.push(trimmedAddress);
localStorage.setItem('addresses', JSON.stringify(currentAddresses));
// 新しく追加したアドレスを選択
currentIP = trimmedAddress;
localStorage.setItem('currentIP', currentIP);
updateAddressSelector();
// セレクタの値を確実に設定
setTimeout(() => {
if (ipSelector) {
ipSelector.value = currentIP;
}
updateAllDisplays();
}, 10);
}
}
});
}
if (addressRemove) {
addressRemove.addEventListener('click', function() {
if (currentAddresses.length > 1) {
const currentValue = ipSelector ? ipSelector.value : currentIP;
const index = currentAddresses.indexOf(currentValue);
if (index > -1) {
currentAddresses.splice(index, 1);
localStorage.setItem('addresses', JSON.stringify(currentAddresses));
// 削除後の新しい選択値を設定
currentIP = currentAddresses[0];
localStorage.setItem('currentIP', currentIP);
updateAddressSelector();
// セレクタの値を確実に設定
setTimeout(() => {
if (ipSelector) {
ipSelector.value = currentIP;
}
updateAllDisplays();
}, 10);
}
} else {
alert(getText('alertMinimumAddress'));
}
});
}
// ブラウザ関連
const serviceSelector = document.getElementById('service-selector');
const portInput = document.getElementById('port-input');
const browserUpdate = document.getElementById('browser-update');
const openCurrentUrl = document.getElementById('open-current-url');
const serviceAdd = document.getElementById('service-add');
const serviceRemove = document.getElementById('service-remove');
if (serviceSelector) {
serviceSelector.addEventListener('change', function() {
currentSelectedService = this.value;
localStorage.setItem('currentSelectedService', currentSelectedService);
console.log('Service changed to:', currentSelectedService);
updateServicePort();
});
}
if (portInput) {
portInput.addEventListener('input', function() {
const serviceSelector = document.getElementById('service-selector');
if (serviceSelector) {
const selectedService = serviceSelector.value;
if (currentServices[selectedService]) {
currentServices[selectedService].port = this.value;
localStorage.setItem('services', JSON.stringify(currentServices));
}
}
updateBrowserDisplay();
});
}
if (browserUpdate) {
browserUpdate.addEventListener('click', function() {
updateBrowserDisplay();
});
}
if (openCurrentUrl) {
openCurrentUrl.addEventListener('click', function() {
const url = generateBrowserURL();
if (url) {
window.open(url, '_blank');
}
});
}
if (serviceAdd) {
serviceAdd.addEventListener('click', function() {
const serviceName = prompt(getText('promptServiceName'), PROMPT_DEFAULTS.serviceName);
if (serviceName && serviceName.trim()) {
const serviceKey = serviceName.toLowerCase().replace(/[^a-z0-9]/g, '');
const port = prompt(getText('promptPortNumber'), PROMPT_DEFAULTS.portNumber);
const protocol = prompt(getText('promptProtocol'), PROMPT_DEFAULTS.protocol);
if (serviceKey && port && !currentServices[serviceKey]) {
currentServices[serviceKey] = {
name: serviceName.trim(),
port: port.trim(),
protocol: protocol.trim() || 'http'
};
localStorage.setItem('services', JSON.stringify(currentServices));
// 新しく追加したサービスを選択
currentSelectedService = serviceKey;
localStorage.setItem('currentSelectedService', currentSelectedService);
updateServiceSelector();
// セレクタの値を確実に設定
setTimeout(() => {
if (serviceSelector) {
serviceSelector.value = currentSelectedService;
}
updateServicePort();
}, 10);
}
}
});
}
if (serviceRemove) {
serviceRemove.addEventListener('click', function() {
const selectedService = serviceSelector ? serviceSelector.value : currentSelectedService;
if (selectedService && Object.keys(currentServices).length > 1) {
if (confirm(getText('confirmDeleteService', currentServices[selectedService].name))) {
delete currentServices[selectedService];
localStorage.setItem('services', JSON.stringify(currentServices));
// 削除後の新しい選択値を設定
currentSelectedService = Object.keys(currentServices)[0];
localStorage.setItem('currentSelectedService', currentSelectedService);
updateServiceSelector();
// セレクタの値を確実に設定
setTimeout(() => {
if (serviceSelector) {
serviceSelector.value = currentSelectedService;
}
updateServicePort();
}, 10);
}
} else if (Object.keys(currentServices).length <= 1) {
alert(getText('alertMinimumService'));
}
});
}
// ターミナル関連
const terminalSelector = document.getElementById('terminal-selector');
const openTerminal = document.getElementById('open-terminal');
if (terminalSelector) {
terminalSelector.addEventListener('change', function() {
currentSelectedTerminal = this.value;
localStorage.setItem('currentSelectedTerminal', currentSelectedTerminal);
console.log('Terminal changed to:', currentSelectedTerminal);
updateTerminalExplanation();
});
}
if (openTerminal) {
openTerminal.addEventListener('click', function() {
const terminalSelector = document.getElementById('terminal-selector');
const terminalType = terminalSelector ? terminalSelector.value : 'openwrtconnect';
// openwrtconnect の場合は直接リンクを開く
if (terminalType === 'openwrtconnect') {
window.open('https://site-u.pages.dev/aios-connect.msi', '_blank');
} else {
downloadBatFile(terminalType);
}
});
}
}
// ==================================================
// アドレス管理機能
// ==================================================
function updateAddressSelector() {
const ipSelector = document.getElementById('global-ip-input');
if (!ipSelector) return;
// セレクタをクリア
ipSelector.innerHTML = '';
// アドレス一覧を追加
currentAddresses.forEach(address => {
const option = document.createElement('option');
option.value = address;
option.textContent = address;
ipSelector.appendChild(option);
});
// **修正: 現在のIPが確実に選択されるように**
if (currentAddresses.includes(currentIP)) {
ipSelector.value = currentIP;
} else {
// 現在のIPがリストにない場合は最初のアドレスを使用
currentIP = currentAddresses[0] || '192.168.1.1';
ipSelector.value = currentIP;
localStorage.setItem('currentIP', currentIP);
}
}
// ==================================================
// サービス管理機能
// ==================================================
function updateServiceSelector() {
const serviceSelector = document.getElementById('service-selector');
if (!serviceSelector) return;
// セレクタをクリア
serviceSelector.innerHTML = '';
// サービス一覧を追加
Object.keys(currentServices).forEach(key => {
const service = currentServices[key];
const option = document.createElement('option');
option.value = key;
option.textContent = service.name;
serviceSelector.appendChild(option);
});
// **修正: 現在選択中のサービスが確実に選択されるように**
if (currentServices[currentSelectedService]) {
serviceSelector.value = currentSelectedService;
} else {
// 現在選択中のサービスが存在しない場合は最初のサービスを使用
currentSelectedService = Object.keys(currentServices)[0] || 'luci';
serviceSelector.value = currentSelectedService;
localStorage.setItem('currentSelectedService', currentSelectedService);
}
}
function updateServicePort() {
const serviceSelector = document.getElementById('service-selector');
const portInput = document.getElementById('port-input');
if (serviceSelector && portInput) {
const selectedService = serviceSelector.value || currentSelectedService;
const service = currentServices[selectedService];
if (service) {
portInput.value = service.port;
}
updateBrowserDisplay();
}
}
function updateBrowserDisplay() {
updateQRCode();
}
function generateBrowserURL() {
const serviceSelector = document.getElementById('service-selector');
const portInput = document.getElementById('port-input');
const selectedService = serviceSelector ? serviceSelector.value : currentSelectedService;
const service = currentServices[selectedService];
const port = portInput ? portInput.value : (service ? service.port : '80');
const protocol = service ? service.protocol : 'http';
return `${protocol}://${currentIP}:${port}`;
}
// ==================================================
// ターミナル管理機能
// ==================================================
function updateTerminalSelector() {
const terminalSelector = document.getElementById('terminal-selector');
if (!terminalSelector) return;
// セレクタをクリア
terminalSelector.innerHTML = '';
// ターミナル一覧を追加
Object.keys(currentTerminals).forEach(key => {
const terminal = currentTerminals[key];
const option = document.createElement('option');
option.value = key;
option.textContent = terminal.name;
terminalSelector.appendChild(option);
});
// **修正: 現在選択中のターミナルが確実に選択されるように**
if (currentTerminals[currentSelectedTerminal]) {
terminalSelector.value = currentSelectedTerminal;
} else {
// 現在選択中のターミナルが存在しない場合は最初のターミナルを使用
currentSelectedTerminal = Object.keys(currentTerminals)[0] || 'openwrtconnect';
terminalSelector.value = currentSelectedTerminal;
localStorage.setItem('currentSelectedTerminal', currentSelectedTerminal);
}
}
// ターミナル説明文更新機能
function updateTerminalExplanation() {
const terminalSelector = document.getElementById('terminal-selector');
const explanationText = document.getElementById('terminal-explanation-text');
if (!terminalSelector || !explanationText) return;
const selectedType = terminalSelector.value || currentSelectedTerminal;
let explanationKey, linkKey;
switch(selectedType) {
case 'openwrtconnect':
explanationKey = 'openwrtconnectExplanation';
linkKey = 'openwrtconnectExplanationLink';
break;
case 'aios':
explanationKey = 'aiosExplanation';
linkKey = 'aiosExplanationLink';
break;
case 'aios2':
explanationKey = 'aios2Explanation';
linkKey = 'aios2ExplanationLink';
break;
case 'ssh':
explanationKey = 'sshExplanation';
linkKey = null;
break;
default:
explanationKey = 'openwrtconnectExplanation';
linkKey = 'openwrtconnectExplanationLink';
}
const text = getText(explanationKey);
const link = linkKey ? getText(linkKey) : null;
explanationText.setAttribute('data-i18n', explanationKey);
if (link) {
explanationText.innerHTML = `${text}<br><a href="${link}" target="_blank" rel="noopener noreferrer" style="color: inherit; text-decoration: underline;">${link}</a>`;
} else {
explanationText.textContent = text;
}
}
// ==================================================
// .bat ファイルダウンロード機能
// ==================================================
function downloadBatFile(terminalType) {
try {
const template = BAT_TEMPLATES[terminalType];
if (!template) {
throw new Error(`Template not found: ${terminalType}`);
}
// IP置換後、改行コードをCRLFに変換
const batContent = template
.replace(/__IP_ADDRESS__/g, currentIP)
.replace(/\r?\n/g, '\r\n');
const blob = new Blob([batContent], { type: 'text/plain' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${terminalType}.bat`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
console.log(`${terminalType}.bat downloaded with IP: ${currentIP}`);
} catch (error) {
console.error('Failed to download BAT file:', error);
alert('BATファイルのダウンロードに失敗しました。');
}
}
// ==================================================
// QRコード機能
// ==================================================
function updateQRCode() {
const qrCodeContainer = document.getElementById('qrcode-detail');
if (!qrCodeContainer) return;
const url = generateBrowserURL();
if (!url) return;
try {
qrCodeContainer.innerHTML = '';
const qr = new QRious({
element: document.createElement('canvas'),
value: url,
size: 180,
foreground: getComputedStyle(document.documentElement).getPropertyValue('--qr-dark').trim(),
background: getComputedStyle(document.documentElement).getPropertyValue('--qr-light').trim()
});
qrCodeContainer.appendChild(qr.element);
} catch (error) {
console.error('QRコード生成エラー:', error);
qrCodeContainer.innerHTML = '<div style="width: 180px; height: 180px; background: var(--text-color); margin: 0 auto; display: flex; align-items: center; justify-content: center; color: var(--block-bg); font-size: 12px;"><span data-i18n="qrCodeArea">QRコード表示エリア</span></div>';
}
}
// ==================================================
// テーマ切り替え機能
// ==================================================
function updateLogo() {
const logoImg = document.getElementById('site-logo');
if (!logoImg) return;
const currentThemeAttr = document.documentElement.getAttribute('data-theme');
if (currentThemeAttr === 'dark') {
logoImg.src = 'img/openwrt_text_white_and_blue.svg';
} else {
logoImg.src = 'img/openwrt_text_blue_and_dark_blue.svg';
}
}
function applyTheme(theme) {
const html = document.documentElement;
if (theme === 'auto') {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
html.setAttribute('data-theme', prefersDark ? 'dark' : 'light');
} else {
html.setAttribute('data-theme', theme);
}
currentTheme = theme;
localStorage.setItem('theme', theme);
updateLogo();
setTimeout(updateQRCode, 100);
}
// ==================================================
// 多言語対応機能
// ==================================================
function updateLanguageDisplay() {
const elements = document.querySelectorAll('[data-i18n]');
elements.forEach(element => {
const key = element.getAttribute('data-i18n');
if (translations[currentLanguage] && translations[currentLanguage][key]) {
element.textContent = translations[currentLanguage][key];
}
});
// 動的コンテンツも更新
updateTerminalExplanation();
}
function updateLanguage(lang) {
currentLanguage = lang;
localStorage.setItem('language', lang);
updateLanguageDisplay();
}
// ==================================================
// 共通更新機能
// ==================================================
function updateAllDisplays() {
updateServicePort();
updateTerminalExplanation();
updateQRCode();
}
// ==================================================
// ヘッダー・フッター対応(動的読み込み用)
// ==================================================
function loadHeaderFooter() {
// ヘッダーの読み込み
fetch('header.html')
.then(response => response.text())
.then(html => {
const headerContainer = document.querySelector('.main-header');
if (headerContainer) {
headerContainer.innerHTML = html;
}
})
.catch(error => console.error('ヘッダー読み込みエラー:', error));
// フッターの読み込み
fetch('footer.html')
.then(response => response.text())
.then(html => {
const footerContainer = document.querySelector('.page-footer-area');
if (footerContainer) {
footerContainer.innerHTML = html;
bindFooterEvents();
}
})
.catch(error => console.error('フッター読み込みエラー:', error));
}
function bindHeaderEvents() {
updateLogo();
}
function bindFooterEvents() {
const langButtons = document.querySelectorAll('.lang-button');
langButtons.forEach(button => {
button.addEventListener('click', function() {
const lang = this.getAttribute('data-lang');
if (lang) {
updateLanguage(lang);
updateLanguageButtons();