-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Fancygotchi.py
6156 lines (5461 loc) · 270 KB
/
Fancygotchi.py
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
import argparse
import asyncio
import copy
import glob
import importlib.util
import json
import logging
import math
import numpy as np
import os
import random
import re
import requests
import shutil
import struct
import subprocess
import sys
import tempfile
import threading
import time
import toml
import traceback
import zipfile
from io import BytesIO
from multiprocessing.connection import Client, Listener
from os import system
from shutil import copy2, copyfile, copytree
from textwrap import TextWrapper
from toml import dump, load
from PIL import Image, ImageChops, ImageDraw, ImageFont, ImageOps, ImageSequence
from flask import abort, jsonify, make_response, render_template_string, send_file
import pwnagotchi
import pwnagotchi.plugins as plugins
import pwnagotchi.ui.faces as faces
import pwnagotchi.ui.fonts as fonts
from pwnagotchi import utils
from pwnagotchi.plugins import toggle_plugin
from pwnagotchi.ui import display
from pwnagotchi.ui.hw import display_for
from pwnagotchi.utils import load_config, merge_config, save_config
V0RT3X_REPO = "https://github.com/V0r-T3x"
FANCY_REPO = os.path.join(V0RT3X_REPO, "Fancygotchi")
THEMES_REPO = "https://api.github.com/repos/V0r-T3x/Fancygotchi_themes/contents/fancygotchi_2.0/themes"
LOGO = """░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓████▓▓▓▓▓▓▓▓▓████████▓▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓███████▓▓▓▓▓▓▓▓██████████▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█▓█████▓▓▓▓▓▓▓▓▓▓▓██████████▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██████████▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓█▓▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓███████████▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█▓▓▓█▓▒▒▒▒▓▓▓▓▓▓▓▓▓█████████████▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░▒▓▓▓█▓▓▓█▓▓██████████████████████████████▓▓▓▓▓▓▓▒░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████▓░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░▒████████▓▓▓▓▓▓▓▓██████████████████████████████████▒░░░░▒▒▒▒░░░░░░░░░░
░░░░░░░░░▓▓▒░░░░░░░░░░▓█████▓▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███████▓░░░░░░▓▓▓▓▓▓▓▓▓░░░░░
░░░░░░░░▒▒▒▓▒░░░░░░░░░░░▒▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓██▓▒░░░░░░░░░█▓▓▓▓▓█▓░░░░░░
░░░░░░░░▓░░▒▒▓▒░░░░░░░░░░░░▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓░░░░░░░░░░░▒▒▓▓▓▓▓█▒░░░░░░
░░░░░░░▓▒▒▒▒▒▓▓▒░░░░░░░░░░░▓▒▒▓████▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓█████▓▓▓▓░░░░░░░░░░░▒▒▒▒▒▒▓▓░░░░░░░
░░░░░░░▒▒░░░░▒▒▓░░░░░░░░░░░▓▒▒▒██▓▓████▓▒▒▒▒▒▒▒▒▒▒▓▓████▓███▓▓▓▒░░░░░░░░░░▒▓▓▓▓▓▒▓▒░░░░░░░
░░░░░░░░▓░░░░░▒▓░░░░░░░░░░░░▓▒▒▒███████▓▒▒▒▒▒▒▒▒▒▒▒▓███████▓▓▓▓░░░░░░░░░░░░░▓▓██▓▓░░░░░░░░
░░░░░░░▒▓▒░░░░▓▓▒▒▒░░░░░░░░░▒▓▒▒▒▓███▓▒▒▓▓▓▓▒▒▒▓▓▓▒▒▒▓████▓▓▓▓░░░░░░░░░░░▒▒▓▓▓█░░░░░░░░░░░
░░░░░░░▒▓▓▒▓▒▒▓▓▓█▓▓░░░░░░░░░░▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▒▒▒▒▒▒▒▒▒▓▓▓▓░░░░░░░░░░░▓▒▒█▓▓▓░░░░░░░░░░░
░░░░░░░░▒█▒▓▓▓▓▓███▓▒░░░░░░░░▒▓█▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓██▒░░░░░░░░░░░█▓▓█▓█▒▒▒░░░░░░░░░
░░░░░░░░░▓░▓▓▓▒▒▓██▓▓▓▒░░░░▒▓███▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓████▓▒░░░░░░░░▓▓██████▓▒▓░░░░░░░░
░░░░░░░░░▒▓▒▒▒▓▓████▓▓▓▓▒▒▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓███▓▒▒░▒▒▓▒▒▓██████▓▒▓░░░░░░░░
░░░░░░░░░░░░░▒████▓██▓▓▓▓▓▓▓▒▒▒▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▒▒▓██████▓▒▓▒░░░░░░░░
░░░░░░░░░░░░░░▒████▓▒▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓█████▓▒▒░░░░░░░░░░
░░░░░░░░░▒██░░░▓█████▓▒▒▒▒▒▒▒▒▒▒▒▒▓▓█▓▒▒▒▒▒▒▓█▓▓▒▒▒▒▒▒▓█▓▓▒▒▒▒▒▒▒▒▒▒▒▒▓███▓█▓▒▒░░░░░░░░░░░
░░░░░░░░▒██░░░░▒▒████████▓▓▓▓▓▓██████▓▒▒▒▒▒▓█████▓▒▒▒▒▒████████▓▓▓▓▓█████░▒██▓██▓░░░░░░░░░
░░░░░░░░▓██░░░▒░░▒█████████▓▓████████▓▒▒▒▒▓███████▓▒▒▒▒████████████████▓░░░▒▒░▒██▓░░░░░░░░
░░░░░░░░▒███▒░░░▒████▒░██▓███▓███████▒▒▒▒▓█████████▓▒▒▒▒████████▓██▓██▓░░░░░░░▒███░░░░░░░░
░░░░░░░░░▒███████████▒▒█▓▓██▓▓▓█████▒▒▒▒▒███████████▓▒▒▒▒██████▓▓█████▓▒░░░░░░▓██▓░░░░░░░░
░░░░░░░░░░░▒▓▓██████▓▓███▓███▓▒▒▓▓▒▒▒▒▒▓██████████████▒▒▒▒▒▓▓▒▒▒██████▓▓▓▒▒▒▓▓███▒░░░░░░░░
░░░░░░░░░░░░░▓███████████▓▓████▓▓▒▒▒▓▓███████▓▒▓██▓█████▓▒▒▒▒▒▓████████████████▓░░░░░░░░░░
░░░░░░░░░░░░░░▓███████████▓███████████████▒░░░░░░░▓▓██████████████▓█████████▓▒░░░░░░░░░░░░
░░░░░░░░░░░░░░░▒▓▓██████▓░░▒█████████████▒░░░░░░░░░▓█▓███████████▒░░▓▓█▓▓▓▓▒░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░▒░░░░░░░▒▓██▓██▓███▓▒░░░░░░░░░░░░▓██▓█████▓▒░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"""
INDEX = """
{% extends "base.html" %}
{% set active_page = "plugins" %}
{% block title %}
Fancygotchi
{% endblock %}
{% block meta %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=0" />
{% endblock %}
{% block styles %}
{{ super() }}
<style>
body {
position: relative;
min-height: 100vh;
}
#wrap {
width: 100%;
float:left;
padding: 10px;
padding-bottom: 50px;
align-items: center;
justify-content: center;
flex-grow: 1;
display: flex;
border-bottom: 1px solid black;
flex-direction: column; /* Display tabs menu and content vertically */}
#tabs {
border-bottom: 1px solid black;
text-align: center;}
.theme {
width: 100%;
margin-bottom: 20px;}
.theme-columns {
display: flex;}
.select,
.theme-description {
flex: 1;
margin-right: 20px;}
#uploader {
margin-top: 20px;}
#tabs{
width: 100%}
#config_content {
text-align: left;}
label {
text-align: center;}
.ui-image {
width: 100%;
max-width: 600px;
left: 50%;
transform: translateX(-50%);
position: relative;
background-color: black;
}
.config-box {
max-width: 100%;
width: 600px;
max-height: 300px;
resize: both; /* allow resizing in both directions */
overflow: auto;
padding: 10px;
border: 1px solid #ccc;}
#fancygotchi {
font-size: 10px;
text-align: center;
white-space: pre; /* Preserve the spaces in ASCII art */
font-family: monospace;
}
#sticky-button {
max-width: 150px;
position: fixed;
bottom: 15px; /* Distance from the bottom of the screen */
left: 50%; /* Center the button horizontally */
transform: translateX(-50%); /* Adjust the centering */
cursor: pointer;
z-index: 1000; /* Ensure it stays above other elements */
}
.preserve-line-breaks {
white-space: pre-wrap;
}
.glitch-line {
display: inline-block;
position: relative;
animation: glitch 0.3s ease-in-out forwards; /* Slower animation duration */
}
/* Style the button */
.scroll-to-top-btn {
max-width: 100px;
position: fixed;
bottom: 00px;
right: 40px;
z-index: 100; /* Ensure it's on top of other elements */
cursor: pointer;
display: none; /* Initially hidden */
font-size: 24px; /* Make the arrow bigger */
}
#theNet{
display: none;
position: absolute;
bottom: 0px;
font-size: 9px;
right: 25px;
padding:10px;
cursor: context-menu;
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera and Firefox */
}
/* Show button when scrolling */
.scroll-to-top-btn.show {
display: block;
}
#footer {
backkground-color: black;
position: fixed;
bottom: 0;
width: 400px;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
text-align: center;
}
#logo {
#left: 50%;
#transform: translate(-50%, -50%);
margin-right: 40px;
margin-left: 40px;
}
.dev {
#display: none;
}
@keyframes glitch {
0% {
transform: translateX(0);
}
20% {
transform: translateX(-2px); /* Smaller shift */
}
40% {
transform: translateX(2px); /* Smaller shift */
}
60% {
transform: translateX(-1px); /* Smaller shift */
}
80% {
transform: translateX(1px); /* Smaller shift */
}
100% {
transform: translateX(0);
}
}
/* Main container with 3 sections */
.container {
display: flex;
width: 100%;
max-width: 1000px; /* adjust as needed */
margin: 0 auto;
align-items: center;
gap: 10px;
}
/* Left section centered within its area */
.left-container {
display: flex;
justify-content: center;
width: 33.33%;
}
.left {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
}
/* Center element truly centered */
.center-container {
display: flex;
justify-content: center;
width: 33.33%;
}
.center img {
max-width: 100%;
height: auto;
}
/* Right section centered within its area */
.right-container {
display: flex;
justify-content: center;
width: 33.33%;
}
.right img {
max-width: 100%;
height: auto;
}
/* Responsive stacking for small screens */
@media (max-width: 600px) {
.container {
flex-direction: column;
align-items: center;
}
.left-container, .center-container, .right-container {
width: auto;
margin-bottom: 10px;
}
/* Style individual arrow buttons */
.arrow-button {
font-weight: bold;
font-size: 24px; /* Makes the arrow icon larger */
}
#download_window {
display: none;
}
#loading-spinner{
}
</style>
{% endblock %}
{% block content %}
<div id="editor">
<div id="main" data-role="navbar">
<ul>
<li>
<form class="action" method="post" action="/shutdown" onsubmit="return confirm('this will halt the unit, continue?');">
<input type="submit" class="button ui-btn ui-corner-all" value="Shutdown"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
</form>
</li>
<li>
<form class="action" method="post" action="/reboot" onsubmit="return confirm('this will reboot the unit, continue?');">
<input type="submit" class="button ui-btn ui-corner-all" value="Reboot"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
</form>
</li>
<li>
<form class="action" method="post" action="/restart" onsubmit="return confirm('This will restart the service in Manu mode, continue?');">
<input type="submit" class="button ui-btn ui-corner-all" value="Restart in Manu mode"/>
<input type="hidden" name="mode" value="MANU"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
</form>
</li>
<li>
<form class="action" method="post" action="/restart" onsubmit="return confirm('This will restart the service in Auto mode, continue?');">
<input type="submit" class="button ui-btn ui-corner-all" value="Restart in Auto mode"/>
<input type="hidden" name="mode" value="AUTO"/>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
</form>
</li>
</ul>
</div>
<div id="display" data-role="navbar" class="dev">
<ul>
<li>
<button id="display_hijack" onclick="display_hijack()">Second hardware display</button>
</li>
<li>
<button id="display_pwny" onclick="display_pwny()">Pwnagotchi hardware display</button>
</li>
</ul>
<ul>
<li>
<button id="display_next" onclick="display_next()">Next second screen mode</button>
</li>
<li>
<button id="display_previous" onclick="display_previous()">Previous second screen mode</button>
</li>
<li>
<button id="screen_saver_next" onclick="screen_saver_next()">Next screen saver</button>
</li>
<li>
<button id="screen_saver_previous" onclick="screen_saver_previous()">Previous screen saver</button>
</li>
</ul>
</div>
<div class="container">
<!-- Left Div with 3x3 grid -->
<div class="left-container">
<div class="left">
<div><button id="toggle" onclick="navigate('toggle')">Toggle</button></div>
<div><button id="up" onclick="navigate('up')" class="arrow-button">↑</button></div>
<div><button id="stealth" onclick="stealth()">Stealth</button></div>
<div><button id="left" onclick="navigate('left')" class="arrow-button">←</button></div>
<div><button id="select" onclick="navigate('select')">Select</button></div>
<div><button id="right" onclick="navigate('right')" class="arrow-button">→</button></div>
<div></div>
<div><button id="down" onclick="navigate('down')" class="arrow-button">↓</button></div>
<div></div>
</div>
</div>
<!-- Center Image -->
<div class="center-container">
<div class="center">
<img class="ui-image pixelated" src="/ui" id="ui" style="width: 400px" />
</div>
</div>
<!-- Right Image -->
<div class="right-container">
<div class="right">
<img class="ui-image pixelated" src="/plugins/Fancygotchi/ui2" id="ui2" style="width: 400px" />
</div>
</div>
</div>
<div id="wrap" data-role="tabs">
<div id="tabs" data-role="navbar">
<ul>
<li class="ui-btn-active"><a href="#theme" data-theme="a" data-ajax="false">Theme manager</a></li>
<li class=""><a href="#theme_downloader" data-theme="a" data-ajax="false">Theme downloader</a></li>
<li class=""><a href="#config" data-theme="a" data-ajax="false">Configuration</a></li>
<li class=""><a href="#theme_editor" data-theme="a" data-ajax="false">Theme editor</a></li>
</ul>
</div>
<div id="theme" class="ui-content theme">
<div id="theme-columns" class="row theme-columns">
<div id="select" class="column select">
<label for="theme-selector">Select a theme:</label>
<select id="theme-selector">
<option value="Default"{% if default_theme == '' %}selected{% endif %}>Default</option>
{% for theme in themes %}
<option value="{{ theme }}"{% if default_theme == theme %}selected{% endif %}>{{ theme }}</option>
{% endfor %}
</select>
<br>
<label for="orientation-selector">Select an orientation:</label>
<select id="orientation-selector">
<option value=0{% if rotation == 0 %} selected{% endif %}>0</option>
<option value=90{% if rotation == 90 %} selected{% endif %}>90</option>
<option value=180{% if rotation == 180 %} selected{% endif %}>180</option>
<option value=270{% if rotation == 270 %} selected{% endif %}>270</option>
</select>
<button id="select-theme-button" onclick="theme_select()">Select Theme</button>
<button id="copy-theme-button" onclick="copyTheme()">Copy Theme</button>
<button id="rename-theme-button" onclick="renameTheme()">Rename Theme</button>
<button id="select-theme-button" onclick="theme_delete()">Delete Theme</button>
<button id="export-theme-button" onclick="theme_export()">Export Theme</button>
<div id="uploader" class="ui-content">
<form id="uploadForm" enctype="multipart/form-data">
<input type="file" name="zipFile" id="zipFile">
<input type="submit" value="Upload Theme Zip" onclick="theme_upload(event)">
</form>
<div id="message"></div>
</div>
<div id="create-theme">
<h3>Create New Theme</h3>
<input type="text" id="new-theme-name" placeholder="Enter new theme name">
<label><input type="checkbox" id="use-resolution"> Use Resolution System</label>
<label><input type="checkbox" id="use-orientation"> Use Orientation System</label>
<button id="create-theme-button" onclick="createNewTheme()">Create Theme</button>
</div>
</div>
<div id="theme-description" class="column theme-description">
<h3>Theme Description</h3>
<div id="theme-description-content"></div>
<img id="screenshot" src="/img/screenshot.png" onerror="this.onerror=null; this.src='/screenshots/screenshot.png';"></img>
</br><input type="checkbox" name="fancyserver" data-on-text="Fancyserver" data-off-text="Fancyserver" data-role="flipswitch" id="fancyserver-selector" onchange="fancyserver()" {% if fancyserver %}checked{% endif %} data-wrapper-class="custom-size-flipswitch"></input>
</div>
</div>
</div>
<div id="theme_downloader" class="ui-content theme">
<div id="download_list_refresh">
<p align="center">
<button id="select-theme-downloader-btn" onclick="loadThemeRepo()">Load theme list</button>
</p>
</div>
<div id="loading-spinner" style="display:none;"><p align="center">Loading...</p></div>
<div id="download_window" style="display:none;">
<div id="theme-downloader-columns" class="row theme-columns">
<div id="downloader-select" class="column select">
<label for="theme-downloader-selector">Select a theme:</label>
<select id="theme-downloader-selector">
<!-- Themes will be dynamically populated here -->
</select>
<br>
<button id="select-theme-downloader-button" onclick="theme_download_select()">Select Theme</button>
</div>
<div id="theme-downloader-description" class="column theme-description">
<h3>Theme Description</h3>
<div id="theme-downloader-description-content"><p>No description available</p></div>
<img id="repo_screenshot" src="/screenshots/screenshot.png" onerror="this.onerror=null; this.src='/screenshots/screenshot.png';"></img>
</div>
</div>
</div>
</div>
<div id="config" class="ui-content">
<h2>No configuration for the default theme</h2> <!-- Updated dynamically -->
<div id="hidden">
<button onclick="saveConfig()" id="sticky-button">Save Configuration</button>
<h3>Configuration editor</h3>
<h4>Config Path</h4> <!-- Updated dynamically -->
<div id="config_content"></div> <!-- Config data inserted here dynamically -->
<h3>CSS editor</h3>
<h4>CSS Path</h4> <!-- css path inserted here dynamically -->
<div contenteditable="true" id="CSS" class="config-box"></div> <!-- css content inserted here dynamically -->
<h3>Info editor</h3>
<h4>Info Path</h4> <!-- css path inserted here dynamically -->
<div contenteditable="true" id="Info" class="config-box"></div> <!-- Info content inserted here dynamically -->
</div>
<button onclick="resetCSS()">Reset Pwnagotchi core CSS</button>
</div>
<div id="theme_editor" class="ui-content">
<div id="fancygotchi">
<h2>Theme editor</h2>
<div id="theme_editor_content">
<h2>Coming soon !</h2>
<h2>If you like the project feel free to contribute !</h2>
<h2><a href='{{fancy_repo}}'>Fancygotchi</a> is made with ❤ by <a href='https://linktr.ee/v0r_t3x'>V0rT3x</a></h2>
</div>
<div id="logo">
<pre>
{% for line in logo.splitlines() %}<span>{{ line }}</span>
{% endfor %}
</pre>
</div>
</div>
<div id="theNet"><a onclick="theNet()">π</a></div>
</div>
</div>
<div id="footer">
<a href='{{fancy_repo}}'>Fancygotchi</a> {{ version }} made with ❤ by <a href='https://linktr.ee/v0r_t3x'>{{ author }}</a>
</div>
</div>
<div data-role="popup" id="delete-dialog" data-overlay-theme="b" data-theme="b" data-dismissible="false" style="max-width:400px;">
<div role="main" class="ui-content">
<h3 class="ui-title">Confirm Deletion</h3>
<p>Are you sure you want to delete the selected theme?</p>
<a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">Cancel</a>
<a href="#" id="confirm-delete" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">Delete</a>
</div>
</div>
<button id="scrollToTopBtn" class="scroll-to-top-btn">▲</button>
{% endblock %}
{% block script %}
theme_info("{{name}}");
loadConfig(0, "{{name}}");
var scrollToTopBtn = document.getElementById("scrollToTopBtn");
function theNet() {
var div = document.querySelector(".dev");
var logo = document.querySelector("#logo");
if (!div || !logo) {
console.error('Element not found: .dev or #logo');
return;
}
var computedColor = window.getComputedStyle(logo).color;
console.log(computedColor)
function rgbToColor(rgb) {
return rgb.replace(/\s+/g, '').toLowerCase();
}
var limeColor = rgbToColor("rgb(0, 255, 0)");
if (div.style.display === "none" || div.style.display === "") {
if (rgbToColor(computedColor) === limeColor) {
logo.style.color = "red";
} else {
logo.style.color = "lime";
}
glitchEffect(true);
div.style.display = "block";
logo.style.backgroundColor = "black";
} else {
div.style.display = "none";
logo.style.color = "";
logo.style.backgroundColor = "";
}
}
window.onload = function() {
var image = document.getElementById("ui");
var image2 = document.getElementById("ui2");
function updateImage() {
image.src = image.src.split("?")[0] + "?" + new Date().getTime();
image2.src = image2.src.split("?")[0] + "?" + new Date().getTime();
}
setInterval(updateImage, {{webui_fps}});
}
window.onscroll = function() {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
scrollToTopBtn.classList.add("show");
} else {
scrollToTopBtn.classList.remove("show");
}
};
scrollToTopBtn.addEventListener("click", function() {
window.scrollTo({top: 0, behavior: 'smooth'});
});
function active_theme(callback) {
loadJSON("Fancygotchi/active_theme", function(response) {
callback(response.theme);
});
}
function resetCSS() {
var json = {"reset_css": true};
sendJSON("Fancygotchi/reset_css", json, function(response) {
console.log("CSS reset successful!");
alert("CSS reset successful!");
});
}
function theme_select() {
var theme = document.getElementById("theme-selector").value;
var rotation = document.getElementById("orientation-selector").value;
var json = {"theme": theme, "rotation": rotation};
sendJSON("Fancygotchi/theme_select", json, function(response) {
loadConfig(1, theme);
});
}
function fancyserver(){
var fancyserver = document.getElementById("fancyserver-selector").checked;
console.log(fancyserver);
var json = {"fancyserver": fancyserver};
sendJSON("Fancygotchi/fancyserver", json);
}
function loadConfig(a, theme) {
if (a == 1) {
alert(theme + ' selected');
}
if (theme == "Default") {
document.querySelector("#config h2").innerText = "No configuration for the default theme";
document.getElementById("hidden").style.visibility = "hidden";
document.getElementById("hidden").style.display = "none";
} else {
document.getElementById("hidden").style.visibility = "visible";
document.getElementById("hidden").style.display = "inline-block";
}
loadJSON("Fancygotchi/load_config", function(response) {
updateConfigSection(response);
});
}
function escapeHtml(text) {
return text
.replace(/</g, "<")
.replace(/>/g, ">");
}
function updateConfigSection(data) {
populateConfig(data.config)
if (data.name == "Default" || data.name == "") {
document.querySelector("#config h2").innerText = "No configuration for the default theme";
} else {
document.querySelector("#config h2").innerText = "Configuration of " + data.name;
}
document.querySelector("#config h4:nth-of-type(1)").innerText = data.cfg_path;
document.querySelector("#config h4:nth-of-type(2)").innerText = data.css_path;
var cssContent = document.getElementById("CSS");
cssContent.innerHTML = '<div class="preserve-line-breaks">' + escapeHtml(data.css) + '</div>';
document.querySelector("#config h4:nth-of-type(3)").innerText = data.info_path;
var infoContent = document.getElementById("Info");
infoContent.innerHTML = '<div class="preserve-line-breaks">' + escapeHtml(data.info) + '</div>';
}
function populateConfig(config) {
var configContent = $('#config_content');
configContent.empty();
var table = jsonToTable(flattenJson(config));
configContent.append(table);
}
function jsonToTable(json) {
var table = document.createElement("table");
table.id = "tableOptions";
var tr = table.insertRow();
var thDel = document.createElement("th");
thDel.innerHTML = "";
var thOpt = document.createElement("th");
thOpt.innerHTML = "Option";
var thVal = document.createElement("th");
thVal.innerHTML = "Value";
tr.appendChild(thDel);
tr.appendChild(thOpt);
tr.appendChild(thVal);
var td, divDelBtn, btnDel;
Object.keys(json).forEach(function(key) {
tr = table.insertRow();
divDelBtn = document.createElement("div");
divDelBtn.className = "del_btn_wrapper";
td = document.createElement("td");
td.setAttribute("data-label", "");
if (!key.startsWith("theme.options")) {
btnDel = document.createElement("Button");
btnDel.innerHTML = "X";
btnDel.setAttribute("data-key", key);
btnDel.onclick = function(){ delRow(this);};
btnDel.className = "remove";
divDelBtn.appendChild(btnDel);
td.appendChild(divDelBtn);
}
tr.appendChild(td);
td = document.createElement("td");
td.setAttribute("data-label", "Option");
td.innerHTML = key;
tr.appendChild(td);
td = document.createElement("td");
td.setAttribute("data-label", "Value");
if(typeof(json[key])==='boolean'){
var input = document.createElement("select");
input.setAttribute("id", "boolSelect");
var tvalue = document.createElement("option");
tvalue.setAttribute("value", "true");
var ttext = document.createTextNode("True")
tvalue.appendChild(ttext);
var fvalue = document.createElement("option");
fvalue.setAttribute("value", "false");
var ftext = document.createTextNode("False");
fvalue.appendChild(ftext);
input.appendChild(tvalue);
input.appendChild(fvalue);
input.value = json[key];
td.appendChild(input);
} else {
var input = document.createElement("input");
if(Array.isArray(json[key])) {
input.type = 'text';
input.value = '[' + json[key].join(', ') + ']';
} else {
input.type = typeof(json[key]);
input.value = json[key];
}
td.appendChild(input);
}
tr.appendChild(td);
});
var newTr = table.insertRow();
var newTd = newTr.insertCell();
newTd.setAttribute("data-label", "");
var addButton = document.createElement("button");
addButton.innerHTML = "+";
addButton.onclick = function() {
var newRow = table.insertRow();
var newTd = newRow.insertCell();
var delButton = document.createElement("button");
delButton.innerHTML = "X";
delButton.onclick = function() {
this.parentNode.parentNode.remove();
};
newTd.appendChild(delButton);
var newKeyCell = newRow.insertCell();
var newKeyInput = document.createElement("input");
newKeyInput.type = "text";
newKeyInput.placeholder = "New Key";
newKeyCell.appendChild(newKeyInput);
var newValueCell = newRow.insertCell();
var newValueInput = document.createElement("input");
newValueInput.type = "text";
newValueInput.placeholder = "New Value";
newValueCell.appendChild(newValueInput);
};
newTd.appendChild(addButton);
newTr.appendChild(newTd);
newTr.appendChild(document.createElement("td"));
return table;
}
function delRow(btn) {
var key = btn.getAttribute("data-key");
var tr = btn.closest("tr");
if (tr && key) {
tr.parentNode.removeChild(tr);
}
}
function saveConfig() {
var config = document.getElementById("tableOptions");
var css = document.getElementById("CSS").textContent;
var info = document.getElementById("Info").textContent;
console.log(info)
console.log(css)
var data = {
config: tableToJson(config),
css: css,
info: info
};
sendJSON("Fancygotchi/save_config", data, function(response) {
if (response.status == "200") {
alert("Config got updated");
} else {
alert("Error while updating the config (err-code: " + response.status + ")");
}
});
active_theme(function(activeTheme) {
loadConfig(0, activeTheme)
theme_info(activeTheme)
});
}
function tableToJson(table) {
var rows = table.getElementsByTagName("tr");
var i, td, key, value;
var json = {};
for (i = 0; i < rows.length; i++) {
td = rows[i].getElementsByTagName("td");
if (td.length == 3) {
key = td[1].textContent || td[1].innerText;
console.log(td[1].textContent || td[1].innerText);
var input = td[2].getElementsByTagName("input");
var select = td[2].getElementsByTagName("select");
console.log(key);
if (input && input.length > 0) {
if (input[0].type == "text") {
const inputValue = input[0].value.trim();
if (inputValue === "") {
value = "";
} else if (inputValue.startsWith("[") && inputValue.endsWith("]")) {
try {
value = JSON.parse(inputValue);
} catch (e) {
console.error('Invalid JSON array:', inputValue);
value = inputValue;
}
} else if (inputValue === 'true' || inputValue === 'false') {
value = inputValue === 'true';
} else if (!isNaN(inputValue)) {
value = parseInt(inputValue, 10);
} else {
value = inputValue;
}
} else if (input[0].type == "number") {
value = Number(input[0].value);
}
} else if (select && select.length > 0) {
value = select[0].options[select[0].selectedIndex].value === 'true';
}
var keyParts = key.split('.');
var currentObj = json;
for (var j = 0; j < keyParts.length - 1; j++) {
if (!currentObj[keyParts[j]]) {
currentObj[keyParts[j]] = {};
}
currentObj = currentObj[keyParts[j]];
}
currentObj[keyParts[keyParts.length - 1]] = value;
}
}
var newRows = document.querySelectorAll("tr input[type='text'][placeholder='New Key']");
newRows.forEach(function(newKeyInput) {
var newValueInput = newKeyInput.closest("tr").querySelector("input[placeholder='New Value']");
var newKey = newKeyInput.value.trim();
var newValue = newValueInput.value.trim();
if (newKey) {
if (newValue === "") {
newValue = "";
} else if (newValue.startsWith("[") && newValue.endsWith("]")) {
try {
newValue = JSON.parse(newValue);
} catch (e) {
console.error('Invalid JSON array:', newValue);
newValue = newValue;
}
} else if (newValue === 'true' || newValue === 'false') {
newValue = newValue === 'true';
} else if (!isNaN(newValue)) {
newValue = parseFloat(newValue);
} else {
newValue = newValue;
}
var newKeyParts = newKey.split('.');
var currentNewObj = json;
console.log(newKeyParts)
for (var k = 0; k < newKeyParts.length - 1; k++) {
if (!currentNewObj[newKeyParts[k]]) {
currentNewObj[newKeyParts[k]] = {};
}
currentNewObj = currentNewObj[newKeyParts[k]];
}
currentNewObj[newKeyParts[newKeyParts.length - 1]] = newValue;
}
});
return unFlattenJson(json);
}
function unFlattenJson(data) {
"use strict";
if (Object(data) !== data || Array.isArray(data))
return data;
var result = {}, cur, prop, idx, last, temp, inarray;
for(var p in data) {
cur = result, prop = "", last = 0, inarray = false;
do {
idx = p.indexOf(".", last);
temp = p.substring(last, idx !== -1 ? idx : undefined);
inarray = temp.startsWith('#') && !isNaN(parseInt(temp.substring(1)))
cur = cur[prop] || (cur[prop] = (inarray ? [] : {}));
if (inarray){
prop = temp.substring(1);
}else{
prop = temp;
}
last = idx + 1;
} while(idx >= 0);
cur[prop] = data[p];
}
return result[""];
}
function createNewTheme() {
var themeName = document.getElementById("new-theme-name").value;
var useResolution = document.getElementById("use-resolution").checked;
var useOrientation = document.getElementById("use-orientation").checked;
if (!themeName) {
alert("Please enter a theme name");
return;
}
var json = {
"theme_name": themeName,
"use_resolution": useResolution,
"use_orientation": useOrientation
};
sendJSON("Fancygotchi/create_theme", json, function(response) {
if (response.status == 200) {
alert("Theme created successfully");
theme_list();
} else {
alert("Error creating theme: " + response.responseText);
}
});
}
function copyTheme() {
var theme = document.getElementById("theme-selector").value;
if (theme != "Default") {
if (theme) {
var newName = theme + '-copy';
sendJSON("Fancygotchi/theme_copy", {"theme": theme, "new_name": newName}, function(response) {
if (response.status == 200) {
alert("Theme copied successfully");
theme_list();
} else {
alert("Error copying theme: " + response.responseText);
}
});
} else {
alert('Please select a theme to copy.');
}
} else {
alert('Default theme cannot be copied.');
}
}
function renameTheme() {
var theme = document.getElementById("theme-selector").value;
active_theme(function(activeTheme) {
if (theme !== "Default" && theme !== activeTheme) {
if (theme) {
var newName = prompt("Enter new name for the theme:", theme);
if (newName && newName !== theme) {
sendJSON("Fancygotchi/theme_rename", {"theme": theme, "new_name": newName}, function(response) {
if (response.status == 200) {
alert("Theme renamed successfully");
theme_list();
} else {
alert("Error renaming theme: " + response.responseText);
}
});
}
} else {
alert('Please select a theme to rename.');
}
} else {
alert('Default theme or active theme cannot be renamed.');
}
});