forked from Matsumot0/webMAN-MOD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
1921 lines (1617 loc) · 53.5 KB
/
main.c
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
#include <sdk_version.h>
#include <cellstatus.h>
#include <cell/cell_fs.h>
#include <cell/rtc.h>
#include <cell/gcm.h>
#include <cell/pad.h>
#include <sys/vm.h>
#include <sysutil/sysutil_common.h>
#include <sys/prx.h>
#include <sys/ppu_thread.h>
#include <sys/event.h>
#include <sys/syscall.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/memory.h>
#include <sys/timer.h>
#include <sys/process.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netex/net.h>
#include <netex/errno.h>
#include <netex/libnetctl.h>
#include <netex/sockinfo.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "flags.h"
#include "types.h"
#include "common.h"
#include "cobra/cobra.h"
#include "cobra/storage.h"
#include "vsh/game_plugin.h"
#include "vsh/netctl_main.h"
#include "vsh/xregistry.h"
#define _game_TitleID _game_info+0x04
#define _game_Title _game_info+0x14
static char _game_info[0x120];
static char search_url[50] = "http://google.com/search?q=";
#ifdef COBRA_ONLY
#include "cobra/netiso.h"
#ifdef LITE_EDITION
#define EDITION " [Lite]"
#else
#ifdef PS3MAPI
#ifdef REX_ONLY
#define EDITION " [Rebug-PS3MAPI]"
#else
#define EDITION " [PS3MAPI]"
#endif
#else
#ifdef REX_ONLY
#define EDITION " [Rebug]"
#else
#define EDITION ""
#endif
#endif
#endif
#else
#ifdef CCAPI
#define EDITION " [CCAPI]"
#else
#define EDITION " [nonCobra]"
#endif
#endif
SYS_MODULE_INFO(WWWD, 0, 1, 0);
SYS_MODULE_START(wwwd_start);
SYS_MODULE_STOP(wwwd_stop);
#define VSH_MODULE_PATH "/dev_blind/vsh/module/"
#define VSH_ETC_PATH "/dev_blind/vsh/etc/"
#define PS2_EMU_PATH "/dev_blind/ps2emu/"
#define REBUG_COBRA_PATH "/dev_blind/rebug/cobra/"
#define HABIB_COBRA_PATH "/dev_blind/habib/cobra/"
#define SYS_COBRA_PATH "/dev_blind/sys/"
#define PS2_CLASSIC_TOGGLER "/dev_hdd0/classic_ps2"
#define REBUG_TOOLBOX "/dev_hdd0/game/RBGTLBOX2/USRDIR/"
#define COLDBOOT_PATH "/dev_blind/vsh/resource/coldboot.raf"
#define ORG_LIBFS_PATH "/dev_flash/sys/external/libfs.sprx"
#define NEW_LIBFS_PATH "/dev_hdd0/tmp/libfs.sprx"
#define PS2_CLASSIC_PLACEHOLDER "/dev_hdd0/game/PS2U10000/USRDIR"
#define PS2_CLASSIC_ISO_PATH "/dev_hdd0/game/PS2U10000/USRDIR/ISO.BIN.ENC"
#define PS2_CLASSIC_ISO_ICON "/dev_hdd0/game/PS2U10000/ICON0.PNG"
#define WM_VERSION "1.43.05 MOD" // webMAN version
#define MM_ROOT_STD "/dev_hdd0/game/BLES80608/USRDIR" // multiMAN root folder
#define MM_ROOT_SSTL "/dev_hdd0/game/NPEA00374/USRDIR" // multiman SingStar® Stealth root folder
#define MM_ROOT_STL "/dev_hdd0/tmp/game_repo/main" // stealthMAN root folder
#define WMCONFIG "/dev_hdd0/tmp/wmconfig.bin" // webMAN config file
#define WMTMP "/dev_hdd0/tmp/wmtmp" // webMAN work/temp folder
#define WM_ICONS_PATH "/dev_hdd0/tmp/wm_icons/" // webMAN icons path
#define WMNOSCAN "/dev_hdd0/tmp/wm_noscan" // webMAN config file
#ifdef WEB_CHAT
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink((char*)"/dev_hdd0/tmp/turnoff"); cellFsUnlink((char*)WMCHATFILE);}
#else
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink((char*)"/dev_hdd0/tmp/turnoff");}
#endif
#define THREAD_NAME "wwwdt"
#define THREAD_NAME_FTP "ftpdt"
#define THREAD_NAME_NET "netiso"
#define THREAD_NAME_NTFS "ntfsd"
#define STOP_THREAD_NAME "wwwds"
////////////
#define HTML_BASE_PATH "/dev_hdd0/xmlhost/game_plugin"
#define FB_XML HTML_BASE_PATH "/fb.xml"
#define MY_GAMES_XML HTML_BASE_PATH "/mygames.xml"
#define MOBILE_HTML HTML_BASE_PATH "/mobile.html"
#define GAMELIST_JS HTML_BASE_PATH "/gamelist.js"
#define DELETE_CACHED_GAMES {cellFsUnlink((char*)WMTMP "/games.html"); cellFsUnlink((char*)GAMELIST_JS);}
////////////
#define SC_COBRA_SYSCALL8 (8)
#define SC_GET_FREE_MEM (352)
#define SC_GET_PLATFORM_INFO (387)
#define SC_RING_BUZZER (392)
#define SC_FS_MOUNT (837)
#define SC_FS_UMOUNT (838)
#define SC_GET_CONSOLE_TYPE (985)
#define SC_GET_PRX_MODULE_BY_ADDRESS (461)
#define SC_STOP_PRX_MODULE (482)
#define SC_UNLOAD_PRX_MODULE (483)
#define SC_PPU_THREAD_EXIT (41)
#define SC_SYS_POWER (379)
#define SYS_SOFT_REBOOT 0x0200
#define SYS_HARD_REBOOT 0x1200
#define SYS_REBOOT 0x8201 /*load LPAR id 1*/
#define SYS_SHUTDOWN 0x1100
#define SYS_NET_EURUS_POST_COMMAND (726)
#define CMD_GET_MAC_ADDRESS 0x103f
#define SYSCALL8_OPCODE_GET_MAMBA 0x7FFFULL
#define BEEP1 { system_call_3(SC_RING_BUZZER, 0x1004, 0x4, 0x6); }
#define BEEP2 { system_call_3(SC_RING_BUZZER, 0x1004, 0x7, 0x36); }
#define BEEP3 { system_call_3(SC_RING_BUZZER, 0x1004, 0xa, 0x1b6); }
#define WWWPORT (80)
#define FTPPORT (21)
#define KB 1024UL
#define _4KB_ 4096UL
#define _8KB_ 8192UL
#define _32KB_ 32768UL
#define _64KB_ 65536UL
#define _128KB_ 131072UL
#define _192KB_ 196608UL
#define _256KB_ 262144UL
#define _1MB_ 1048576UL
#define _32MB_ 33554432UL
#define MIN_MEM _192KB_
#define MODE 0777
#define LINELEN 512 // file listing
#define MAX_LINE_LEN 640 // html games
#define MAX_PATH_LEN 512 // do not change!
#define FAILED -1
#define HTML_RECV_SIZE 2048
static u32 BUFFER_SIZE_FTP = ( _128KB_);
static u32 BUFFER_SIZE = ( 448*KB);
static u32 BUFFER_SIZE_PSX = ( 160*KB);
static u32 BUFFER_SIZE_PSP = ( _32KB_);
static u32 BUFFER_SIZE_PS2 = ( _64KB_);
static u32 BUFFER_SIZE_DVD = ( _192KB_);
static u32 BUFFER_SIZE_ALL = ( 896*KB);
#ifdef COBRA_ONLY
#ifndef LITE_EDITION
static sys_ppu_thread_t thread_id_net =-1;
#endif
static sys_ppu_thread_t thread_id_ntfs =-1;
#endif
static sys_ppu_thread_t thread_id_poll =-1;
static sys_ppu_thread_t thread_id_ftp =-1;
static sys_ppu_thread_t thread_id =-1;
#define SUFIX(a) ((a==1)? "_1" :(a==2)? "_2" :(a==3)? "_3" :(a==4)?"_4":"")
#define SUFIX2(a) ((a==1)?" (1)":(a==2)?" (2)":(a==3)?" (3)":(a==4)?" (4)":"")
#define SUFIX3(a) ((a==1)?" (1).ntfs[":(a==2)?" (2).ntfs[":(a==3)?" (3).ntfs[":(a==4)?" (4).ntfs[":"")
#define IS_ISO_FOLDER (f1>1 && f1<10)
#define IS_PS3_FOLDER (f1<3 || f1>=10)
#define IS_BLU_FOLDER (f1==3)
#define IS_DVD_FOLDER (f1==4)
#define IS_PS2_FOLDER (f1==5)
#define IS_PSX_FOLDER (f1==6 || f1==7)
#define IS_PSP_FOLDER (f1==8 || f1==9)
#define PS3 (1<<0)
#define PS2 (1<<1)
#define PS1 (1<<2)
#define PSP (1<<3)
#define BLU (1<<4)
#define DVD (1<<5)
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define ABS(a) (((a) < 0) ? -(a) : (a))
#define RANGE(a, b, c) ((a) <= (b) ? (b) : (a) >= (c) ? (c) : (a))
#define START_DAEMON (0xC0FEBABE)
#define REFRESH_CONTENT (0xC0FEBAB0)
typedef struct {
uint32_t total;
uint32_t avail;
} _meminfo;
//static bool is_rebug = false;
static u8 profile = 0;
static u8 loading_html = 0;
static u8 loading_games = 0;
static u8 init_running = 0;
#define NTFS (10)
static bool show_info_popup = false;
#ifdef USE_DEBUG
static int debug_s=-1;
static char debug[256];
#endif
static volatile u8 wm_unload_combo = 0;
static volatile u8 working = 1;
static u8 cobra_mode=0;
static u8 max_mapped=0;
static float c_firmware=0.0f;
static u8 dex_mode=0;
static u64 SYSCALL_TABLE = 0;
typedef struct
{
uint8_t usb0;
uint8_t usb1;
uint8_t usb2;
uint8_t usb3;
uint8_t usb6;
uint8_t usb7;
uint8_t netd0;
uint8_t lastp;
uint8_t autob;
uint8_t delay;
uint8_t bootd;
uint8_t boots;
uint8_t blind;
uint8_t nogrp;
uint8_t noset;
uint8_t cmask;
uint32_t netp0;
char neth0[16];
uint8_t poll;
uint8_t ftpd;
uint8_t warn;
uint8_t fanc;
uint8_t temp1;
uint8_t rxvid;
uint8_t bind;
uint8_t refr;
uint8_t manu;
uint8_t temp0;
uint8_t netd1;
uint32_t netp1;
char neth1[16];
uint8_t foot;
uint8_t nopad;
uint8_t nocov;
uint8_t nospoof;
uint8_t ps2temp;
uint8_t pspl;
uint8_t minfan;
uint16_t combo;
uint8_t sidps;
uint8_t spsid;
uint8_t spp;
uint8_t lang;
char vIDPS1[17];
char vIDPS2[17];
char vPSID1[17];
char vPSID2[17];
uint8_t tid;
uint8_t wmdn;
char autoboot_path[256];
uint8_t ps2l;
uint32_t combo2;
uint8_t homeb;
char home_url[256];
uint8_t netd2;
uint32_t netp2;
char neth2[16];
uint8_t profile;
char uaccount[9];
char allow_ip[16];
uint8_t noss;
uint8_t fixgame;
uint8_t bus;
uint8_t dev_sd;
uint8_t dev_ms;
uint8_t dev_cf;
uint8_t ps1emu;
} __attribute__((packed)) WebmanCfg;
#define AUTOBOOT_PATH "/dev_hdd0/PS3ISO/AUTOBOOT.ISO"
#ifdef COBRA_ONLY
#define DEFAULT_AUTOBOOT_PATH "/dev_hdd0/PS3ISO/AUTOBOOT.ISO"
#else
#define DEFAULT_AUTOBOOT_PATH "/dev_hdd0/GAMES/AUTOBOOT"
#endif
#define ISO_EXTENSIONS ".iso.cue.img.mdf.bin"
static CellRtcTick rTick, gTick;
static int set_gamedata_status(u8 status, bool do_mount);
static void set_buffer_sizes(int footprint);
#ifdef COBRA_ONLY
static void select_ps1emu(void);
#endif
int extcmp(const char *s1, const char *s2, size_t n);
int extcasecmp(const char *s1, const char *s2, size_t n);
char *strcasestr(const char *s1, const char *s2);
static void reset_settings(void);
static int save_settings(void);
static u64 backup[6];
static u8 wmconfig[sizeof(WebmanCfg)];
static WebmanCfg *webman_config = (WebmanCfg*) wmconfig;
static bool gmobile_mode = false;
static char ftp_password[20]="";
static char html_base_path[MAX_PATH_LEN]="";
static char smonth[12][4]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static char drives[14][12]={"/dev_hdd0", "/dev_usb000", "/dev_usb001", "/dev_usb002", "/dev_usb003", "/dev_usb006", "/dev_usb007", "/net0", "/net1", "/net2", "/ext", "/dev_sd", "/dev_ms", "/dev_cf"};
static char paths [11][12]={"GAMES", "GAMEZ", "PS3ISO", "BDISO", "DVDISO", "PS2ISO", "PSXISO", "PSXGAMES", "PSPISO", "ISO", "video"};
static char wm_icons[12][60]={WM_ICONS_PATH "icon_wm_album_ps3.png", //024.png [0]
WM_ICONS_PATH "icon_wm_album_psx.png", //026.png [1]
WM_ICONS_PATH "icon_wm_album_ps2.png", //025.png [2]
WM_ICONS_PATH "icon_wm_album_psp.png", //022.png [3]
WM_ICONS_PATH "icon_wm_album_dvd.png", //023.png [4]
WM_ICONS_PATH "icon_wm_ps3.png", //024.png [5]
WM_ICONS_PATH "icon_wm_psx.png", //026.png [6]
WM_ICONS_PATH "icon_wm_ps2.png", //025.png [7]
WM_ICONS_PATH "icon_wm_psp.png", //022.png [8]
WM_ICONS_PATH "icon_wm_dvd.png", //023.png [9]
WM_ICONS_PATH "icon_wm_settings.png", //icon/icon_home.png [10]
WM_ICONS_PATH "icon_wm_eject.png" //icon/icon_home.png [11]
};
static bool covers_exist[7];
static char local_ip[16] = "127.0.0.1";
//uint64_t find_syscall();
//uint64_t search64(uint64_t val);
//uint64_t find_syscall_table();
#define SYSCALLS_UNAVAILABLE 0xFFFFFFFF80010003ULL
#include "include/peek_poke.h"
#include "include/led.h"
#include "include/socket.h"
#include "include/html.h"
#include "include/language.h"
#include "include/ps2_classic.h"
#include "include/vpad.h"
#include "include/idps.h"
#include "include/singstar.h"
#include "include/xmb_savebmp.h"
int wwwd_start(uint64_t arg);
int wwwd_stop(void);
static void stop_prx_module(void);
static void unload_prx_module(void);
static void detect_firmware(void);
static void handleclient(u64 conn_s_p);
static void do_umount(bool clean);
static void mount_autoboot(void);
static bool mount_with_mm(const char *_path, u8 do_eject);
#ifdef COBRA_ONLY
static void do_umount_iso(void);
#endif
static bool from_reboot = false;
static bool is_busy = false;
static bool is_mounting = false;
#ifdef COPY_PS3
static char current_file[MAX_PATH_LEN];
#endif
#include "include/vsh.h"
#include "include/webchat.h"
#include "include/file.h"
#include "include/fix_game.h"
#include "include/ps2_disc.h"
#ifndef COBRA_ONLY
static void string_to_lv2(char* path, u64 addr);
static void add_to_map(char *path1, char *path2);
#endif
static inline void _sys_ppu_thread_exit(uint64_t val)
{
system_call_1(SC_PPU_THREAD_EXIT, val); // prxloader = mandatory; cobra = optional; ccapi = don't use !!!
}
static inline sys_prx_id_t prx_get_module_id_by_address(void *addr)
{
system_call_1(SC_GET_PRX_MODULE_BY_ADDRESS, (uint64_t)(uint32_t)addr);
return (int)p1;
}
#include "include/eject_insert.h"
#ifdef COBRA_ONLY
#include "include/rawseciso.h"
#include "include/netsvr.h"
#endif //#ifdef COBRA_ONLY
#include "include/gamedata.h"
#include "include/psxemu.h"
#include "include/debug_mem.h"
#include "include/ftp.h"
#include "include/fancontrol.h"
#include "include/ps3mapi.h"
#include "include/video_rec.h"
#include "include/stealth.h"
#include "include/games_html.h"
#include "include/games_xml.h"
#include "include/cpursx.h"
#include "include/setup.h"
#include "include/fancontrol2.h"
#include "include/file_manager.h"
#include "include/_mount.h"
static void http_response(int conn_s, char *header, char *param, int code, char *msg)
{
char text[MAX_LINE_LEN]; if(msg[0]=='/') sprintf(text, "%s : OK", msg+1); else sprintf(text, "%s", msg);
sprintf(header, "HTTP/1.1 %i OK\r\n"
"X-PS3-Info: [%s]\r\n"
"Content-Type: text/html\r\n"
"Content-Length: %i\r\n\r\n"
"<body bgcolor=\"#101010\" text=\"#c0c0c0\">"
"<font face=\"Courier New\">"
"webMAN MOD " WM_VERSION "<hr><h2>%s</h2>"
"</font></body>",
code, param, 113+strlen(text), text);
ssend(conn_s, header);
sclose(&conn_s);
if(msg[0]=='/') {show_msg((char*)text); sys_timer_sleep(1); }
}
static void prepare_html(char *buffer, char *templn, char *param, u8 is_ps3_http, u8 is_cpursx, bool mount_ps3)
{
strcpy(buffer, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">"
"<meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\">"
"<meta http-equiv=\"cache-control\" content=\"no-cache\">"
"<meta content='target-densitydpi=device-dpi; width=device-width; initial-scale=0.6; maximum-scale=1.0;' name='viewport'>");
if(is_cpursx) strcat(buffer, "<meta http-equiv=\"refresh\" content=\"6;URL=/cpursx.ps3\">");
if(mount_ps3) { strcat(buffer, "<body bgcolor=\"#101010\">"); return;}
strcat(buffer, "<head><title>webMAN MOD</title>"
"<style type=\"text/css\"><!--\r\n"
"a.s:active{color:#F0F0F0;}"
"a:link{color:#909090;text-decoration:none;}"
"a.f:active{color:#F8F8F8;}"
"a,a.f:link,a:visited{color:#D0D0D0;}");
if(!is_cpursx)
strcat(buffer, "a.d:link{color:#D0D0D0;background-position:0px 2px;background-image:url('data:image/gif;base64,R0lGODlhEAAMAIMAAOenIumzLbmOWOuxN++9Me+1Pe+9QvDAUtWxaffKXvPOcfTWc/fWe/fWhPfckgAAACH5BAMAAA8ALAAAAAAQAAwAAARQMI1Agzk4n5Sa+84CVNUwHAz4KWzLMo3SzDStOkrHMO8O2zmXsAXD5DjIJEdxyRie0KfzYChYr1jpYVAweb/cwrMbAJjP54AXwRa433A2IgIAOw==');padding:0 0 0 20px;background-repeat:no-repeat;margin-left:auto;margin-right: auto;}"
"a.w:link{color:#D0D0D0;background-image:url('data:image/gif;base64,R0lGODlhDgAQAIMAAAAAAOfn5+/v7/f39////////////////////////////////////////////wAAACH5BAMAAA8ALAAAAAAOABAAAAQx8D0xqh0iSHl70FxnfaDohWYloOk6papEwa5g37gt5/zO475fJvgDCW8gknIpWToDEQA7');padding:0 0 0 20px;background-repeat:no-repeat; margin-left:auto; margin-right:auto;}");
strcat(buffer, "a:active,a:active:hover,a:visited:hover,a:link:hover{color:#FFFFFF;}"
".list{display:inline;}"
"input:focus{border:2px solid #0099FF;}"
".gc{float:left;overflow:hidden;position:relative;text-align:center;width:280px;height:260px;margin:3px;border:1px dashed grey;}"
".ic{position:absolute;top:5px;right:5px;left:5px;bottom:40px;}"
".propfont{font-family:\"Courier New\",Courier,monospace;}"
"body,a.s,td,th{color:#F0F0F0;white-space:nowrap;");
if(is_ps3_http==2)
strcat(buffer, "width:800px;}");
else
strcat(buffer, "}");
if(!strstr(param, "/setup.ps3")) strcat(buffer, "td+td{text-align:right;white-space:nowrap}");
if(is_ps3_http==1)
strcat(buffer, ".gi{height:210px;width:267px;");
else
strcat(buffer, ".gi{position:absolute;max-height:210px;max-width:260px;");
strcat(buffer, "position:absolute;bottom:0px;top:0px;left:0px;right:0px;margin:auto;}"
".gn{position:absolute;height:38px;bottom:0px;right:7px;left:7px;text-align:center;}--></style>");
if(param[1]!=NULL) {sprintf(templn, "<base href=\"%s/\">", param); strcat(buffer, templn);}
strcat(buffer, "</head>"
"<body bgcolor=\"#101010\">"
"<font face=\"Courier New\"><b>");
#ifndef ENGLISH_ONLY
if(strlen(STR_TRADBY)==0) language("STR_TRADBY", STR_TRADBY); //strcpy(STR_TRADBY, "<br>");
if(strlen(STR_HOME )==0) language("STR_HOME" , STR_HOME ); //strcpy(STR_HOME , "<br>");
#else
strcpy(STR_HOME, "Home");
#endif
#ifdef PS3MAPI
#ifdef WEB_CHAT
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>] [<a href=\"/games.ps3\">Slider</a>] [<a href=\"/chat.ps3\">Chat</a>] [<a href=\"/home.ps3mapi\">PS3MAPI</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, STR_SETUP); strcat(buffer, templn);
#else
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>] [<a href=\"/games.ps3\">Slider</a>] [<a href=\"/home.ps3mapi\">PS3MAPI</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, STR_SETUP ); strcat(buffer, templn);
#endif
#else
#ifdef WEB_CHAT
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>] [<a href=\"/games.ps3\">Slider</a>] [<a href=\"/chat.ps3\">Chat</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, STR_SETUP); strcat(buffer, templn);
#else
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>] [<a href=\"/games.ps3\">Slider</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, STR_SETUP ); strcat(buffer, templn);
#endif
#endif
}
static void handleclient(u64 conn_s_p)
{
int conn_s = (int)conn_s_p; // main communications socket
char param[HTML_RECV_SIZE];
struct CellFsStat buf;
int fd;
if(conn_s_p==START_DAEMON || conn_s_p==REFRESH_CONTENT)
{
#ifndef ENGLISH_ONLY
update_language();
#endif
if(conn_s_p==START_DAEMON)
{
if(profile || (!(webman_config->wmdn) && strlen(STR_WMSTART)>0))
{
sys_timer_sleep(10);
sprintf(param, "%s%s", STR_WMSTART, SUFIX2(profile));
show_msg((char*)param);
}
}
else //if(conn_s_p==REFRESH_CONTENT)
{
{DELETE_CACHED_GAMES} // refresh XML will force "refresh HTML" to rebuild the cache file
}
init_running = 1;
cellFsMkdir((char*)WMTMP, MODE);
//identify covers folders to be scanned
#ifndef ENGLISH_ONLY
covers_exist[0]=isDir(COVERS_PATH);
#endif
sprintf(param, "%s/covers", MM_ROOT_STD) ; covers_exist[1]=isDir(param);
sprintf(param, "%s/covers", MM_ROOT_STL) ; covers_exist[2]=isDir(param);
sprintf(param, "%s/covers", MM_ROOT_SSTL); covers_exist[3]=isDir(param);
covers_exist[4]=isDir("/dev_hdd0/GAMES/covers");
covers_exist[5]=isDir("/dev_hdd0/GAMEZ/covers");
covers_exist[6]=isDir(WMTMP);
for(u8 i=0; i<12; i++)
{
if(cellFsStat(wm_icons[i], &buf)!=CELL_FS_SUCCEEDED)
{
sprintf(param, "/dev_flash/vsh/resource/explore/icon/%s", wm_icons[i] + 23); strcpy(wm_icons[i], param);
if(cellFsStat(param, &buf)==CELL_FS_SUCCEEDED) continue;
else
if(i==0 || i==5) strcpy(wm_icons[i] + 32, "user/024.png\0"); else //ps3
if(i==1 || i==6) strcpy(wm_icons[i] + 32, "user/026.png\0"); else //psx
if(i==2 || i==7) strcpy(wm_icons[i] + 32, "user/025.png\0"); else //ps2
if(i==3 || i==8) strcpy(wm_icons[i] + 32, "user/022.png\0"); else //psp
if(i==4 || i==9) strcpy(wm_icons[i] + 32, "user/023.png\0"); else //dvd
strcpy(wm_icons[i] + 37, "icon_home.png\0"); //setup / eject
}
}
#ifdef NOSINGSTAR
if(webman_config->noss) no_singstar_icon();
#endif
#ifdef COBRA_ONLY
//if(cobra_mode)
{
u8 cconfig[15];
CobraConfig *cobra_config = (CobraConfig*) cconfig;
memset(cobra_config, 0, 15);
cobra_read_config(cobra_config);
if(webman_config->nospoof)
{
cobra_config->spoof_version=0;
cobra_config->spoof_revision=0;
}
else
{ // cobra spoofer not working on 4.53
if(c_firmware!=4.53f)
{
cobra_config->spoof_version=0x0476;
cobra_config->spoof_revision=65514;
}
}
if( cobra_config->ps2softemu == 0 && cobra_get_ps2_emu_type()==PS2_EMU_SW )
cobra_config->ps2softemu = 1;
cobra_write_config(cobra_config);
}
#endif
#ifdef SPOOF_CONSOLEID
spoof_idps_psid();
#endif
#ifdef COBRA_ONLY
#ifdef REMOVE_SYSCALLS
if(webman_config->spp & 1) //remove syscalls & history
{
sys_timer_sleep(5);
remove_cfw_syscalls();
delete_history(true);
}
else
#endif
if(webman_config->spp & 2) //remove history only
{
delete_history(false);
block_online_servers();
}
#endif
if(update_mygames_xml(conn_s_p)) mount_autoboot();
init_running = 0;
sys_ppu_thread_exit(0);
}
#ifdef USE_DEBUG
ssend(debug_s, "waiting...");
#endif
if(loading_html>10) loading_html=0;
//while((init_running/* || loading_html>3*/) && working) sys_timer_usleep(10000);
sys_net_sockinfo_t conn_info_main;
sys_net_get_sockinfo(conn_s, &conn_info_main, 1);
char ip_address[16];
sprintf(ip_address, "%s", inet_ntoa(conn_info_main.remote_adr));
if( webman_config->bind && ((conn_info_main.local_adr.s_addr!=conn_info_main.remote_adr.s_addr) && strncmp(ip_address, webman_config->allow_ip, strlen(webman_config->allow_ip))!=0))
{
sclose(&conn_s);
loading_html--;
sys_ppu_thread_exit(0);
}
if(!webman_config->netd0 && !webman_config->neth0[0]) strcpy(webman_config->neth0, ip_address);
if(!webman_config->bind) strcpy(webman_config->allow_ip, ip_address);
set_buffer_sizes(webman_config->foot);
_meminfo meminfo;
u8 retries=0;
again3:
{system_call_1(SC_GET_FREE_MEM, (uint64_t)(u32) &meminfo);}
if((meminfo.avail)<( (_64KB_) + MIN_MEM)) //leave if less than min memory
{
#ifdef USE_DEBUG
ssend(debug_s, "!!! NOT ENOUGH MEMORY!\r\n");
#endif
retries++;
sys_timer_sleep(1);
if(retries<5) goto again3;
init_running = 0;
sclose(&conn_s);
loading_html--;
sys_ppu_thread_exit(0);
}
sys_addr_t sysmem=0;
u8 is_binary = 0, served=0; // served http requests
u64 c_len = 0;
char cmd[16], header[HTML_RECV_SIZE];
u8 is_ps3_http=0;
u8 is_cpursx=0;
u8 is_popup=0;
struct timeval tv;
tv.tv_usec = 0;
tv.tv_sec = 3;
setsockopt(conn_s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
while(!served && working)
{
served++;
header[0]=0;
#ifdef USE_DEBUG
ssend(debug_s, "ACC - ");
#endif
if(recv(conn_s, header, HTML_RECV_SIZE, 0) > 0 && header[0]=='G' && header[4]=='/') // serve only GET /xxx requests
{
if(strstr(header, "Mozilla/5.0 (PLAYSTATION 3;")) is_ps3_http=1; else
if(strstr(header, "Gecko/36")) is_ps3_http=2; else is_ps3_http=0;
header[strcspn(header, "\n")] = '\0';
header[strcspn(header, "\r")] = '\0';
ssplit(header, cmd, 15, header, (HTML_RECV_SIZE-1));
ssplit(header, param, (HTML_RECV_SIZE-1), cmd, 15);
bool allow_retry_response=true, small_alloc = true, mobile_mode = false;
#ifdef USE_DEBUG
ssend(debug_s, param);
ssend(debug_s, "\r\n");
#endif
//url decode (unescape)
if(strstr(param, "%"))
{
strcpy(header, param);
u16 pos=0, len=strlen(param);
for(u16 i=0;i<len;i++, pos++)
{
if(header[i]!='%')
param[pos]=header[i];
else
{
i++;
if(header[i]>='0' && header[i]<='9') param[pos]=(header[i]-0x30)*0x10; else
if(header[i]>='A' && header[i]<='F') param[pos]=(header[i]-0x37)*0x10; else
if(header[i]>='a' && header[i]<='f') param[pos]=(header[i]-0x57)*0x10;
i++;
if(header[i]>='0' && header[i]<='9') param[pos]+=header[i]-0x30; else
if(header[i]>='A' && header[i]<='F') param[pos]+=header[i]-0x37; else
if(header[i]>='a' && header[i]<='f') param[pos]+=header[i]-0x57;
}
}
param[pos]=0;
}
#ifdef VIRTUAL_PAD
if(strstr(param, "/pad.ps3"))
{
if(!webman_config->nopad) parse_pad_command(param);
is_binary=0;
http_response(conn_s, header, param, 200, param+9);
loading_html--;
sys_ppu_thread_exit(0);
return;
}
#endif
#ifndef LITE_EDITION
#ifdef WEB_CHAT
if(strstr(param, "/chat.ps3"))
{
is_popup=1; is_binary=0;
goto html_response;
}
#endif
if(strstr(param, "/popup.ps3"))
{
if(param[10]==0) show_info_popup = true; else is_popup=1;
is_binary=0;
goto html_response;
}
if(strstr(param, "/dev_blind"))
{
is_binary=2;
goto html_response;
}
if(strstr(param, "/mkdir.ps3") || strstr(param, "/rmdir.ps3"))
{
if(strstr(param, "/rmdir.ps3"))
{
if(param[10]=='/') {sprintf(param, "%s", param+10); cellFsRmdir((char*)param); for(u16 i = strlen(param); i > 0; i--) if(param[i]=='/') {param[i]=0; break;}}
else {delete_history(true); sprintf(param, "/dev_hdd0");}
}
else if(param[10]=='/') {sprintf(param, "%s", param+10); cellFsMkdir((char*)param, MODE);}
else
{
sprintf(param, "/dev_hdd0");
cellFsMkdir((char*)"/dev_hdd0/packages", MODE);
cellFsMkdir((char*)"/dev_hdd0/GAMES", MODE);
cellFsMkdir((char*)"/dev_hdd0/PS3ISO", MODE);
cellFsMkdir((char*)"/dev_hdd0/PSXISO", MODE);
cellFsMkdir((char*)"/dev_hdd0/PS2ISO", MODE);
cellFsMkdir((char*)"/dev_hdd0/PSPISO", MODE);
cellFsMkdir((char*)"/dev_hdd0/DVDISO", MODE);
cellFsMkdir((char*)"/dev_hdd0/BDISO", MODE);
}
}
#endif
if(strstr(param, "quit.ps3"))
{
http_response(conn_s, header, param, 200, param);
#ifdef LOAD_PRX
quit:
#endif
if(!webman_config->fanc || strstr(param, "?0") || webman_config->ps2temp<33)
restore_fan(0); //restore syscon fan control mode
else
restore_fan(1); //set ps2 fan control mode
working = 0;
sclose(&conn_s);
if(sysmem) sys_memory_free(sysmem);
loading_html=0;
stop_prx_module();
sys_ppu_thread_exit(0);
break;
}
if(strstr(param, "shutdown.ps3"))
{
http_response(conn_s, header, param, 200, param);
working = 0;
{ DELETE_TURNOFF } { BEEP1 }
if(strstr(param, "?"))
vshmain_87BB0001(1); // shutdown using VSH
else
{system_call_4(SC_SYS_POWER, SYS_SHUTDOWN, 0, 0, 0);}
sys_ppu_thread_exit(0);
break;
}
if(strstr(param, "rebuild.ps3"))
{
http_response(conn_s, header, param, 200, param);
cmd[0] = cmd[1] = 0; cmd[2] = 0x03; cmd[3] = 0xE9; // 00 00 03 E9
savefile((char*)"/dev_hdd0/mms/db.err", cmd, 4);
goto restart;
}
if(strstr(param, "recovery.ps3"))
{
#define SC_UPDATE_MANAGER_IF 863
#define UPDATE_MGR_PACKET_ID_READ_EPROM 0x600B
#define UPDATE_MGR_PACKET_ID_WRITE_EPROM 0x600C
#define RECOVER_MODE_FLAG_OFFSET 0x48C61
http_response(conn_s, header, param, 200, param);
{system_call_7(SC_UPDATE_MANAGER_IF, UPDATE_MGR_PACKET_ID_WRITE_EPROM, RECOVER_MODE_FLAG_OFFSET, 0x00, 0, 0, 0, 0);} // set recovery mode
goto reboot; // hard reboot
}
if(strstr(param, "restart.ps3"))
{
http_response(conn_s, header, param, 200, param);
restart:
working = 0;
{ DELETE_TURNOFF } { BEEP2 }
if(strstr(param,"?0")==NULL) savefile((char*)WMNOSCAN, NULL, 0);
vshmain_87BB0001(2); // VSH reboot
sys_ppu_thread_exit(0);
break;
}
if(strstr(param, "reboot.ps3"))
{
http_response(conn_s, header, param, 200, param);
reboot:
working = 0;
{ DELETE_TURNOFF } { BEEP2 }
if(strstr(param, "?v")) vshmain_87BB0001(2); // VSH reboot
else
if(strstr(param, "?q"))
{system_call_3(SC_SYS_POWER, SYS_REBOOT, NULL, 0);} // (quick reboot) load LPAR id 1
else
if(strstr(param, "?s"))
{system_call_3(SC_SYS_POWER, SYS_SOFT_REBOOT, NULL, 0);} // soft reboot
else
{system_call_3(SC_SYS_POWER, SYS_HARD_REBOOT, NULL, 0);} // hard reboot
sys_ppu_thread_exit(0);
break;
}
#ifdef FIX_GAME
if(strstr(param, "/fixgame.ps3"))
{
// fix game folder
char *game_path = param + 12;
if(cellFsStat((char*)game_path, &buf)==CELL_FS_SUCCEEDED)
{
fix_in_progress=true; fix_aborted=false;
#ifdef COBRA_ONLY
if(strcasestr(game_path, ".iso"))
fix_iso(game_path, 0x100000UL, false);
else
#endif //#ifdef COBRA_ONLY
fix_game(game_path);
fix_in_progress=false;
is_popup=1; is_binary=0;
goto html_response;
}
}
#endif
if(strstr(param, "/games.ps3"))
{
mobile_response:
mobile_mode = false;
if(cellFsStat((char*)MOBILE_HTML, &buf)!=CELL_FS_SUCCEEDED)
sprintf(param, "/index.ps3%s", param+10);
else if(strstr(param, "?g="))
sprintf(param, "%s", MOBILE_HTML);
else if(strstr(param, "?"))
{sprintf(param, "/index.ps3%s", param+10); mobile_mode = true;}
else if(cellFsStat((char*)GAMELIST_JS, &buf)!=CELL_FS_SUCCEEDED)
sprintf(param, "%s", "index.ps3?mobile");
else
sprintf(param, "%s", MOBILE_HTML);
}
else mobile_mode = false;