-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurrogafier.php
More file actions
4341 lines (3744 loc) · 119 KB
/
surrogafier.php
File metadata and controls
4341 lines (3744 loc) · 119 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
<?php
#
# Surrogafier v1.9.1.1b
#
# Author: Brad Cable
# Email: brad@bcable.net
# License: Modified BSD
# License Details:
# http://bcable.net/license.php
#
# CONFIG {{{
global $CONFIG;
$CONFIG=array();
# Timezone setting for PHP; really this doesn't matter since no timezone is ever
# printed by this script, but it's required to be set now. [GMT]
$CONFIG['SYS_TIMEZONE']='GMT';
# Default to simple mode when the page is loaded. [false]
$CONFIG['DEFAULT_SIMPLE']=false;
# Force the page to always be in simple mode (no advanced mode option). [false]
$CONFIG['FORCE_SIMPLE']=false;
# Width for the URL box when in simple mode (CSS "width" attribute). [300px]
$CONFIG['SIMPLE_MODE_URLWIDTH']='300px';
# Disables POST and COOKIES for a much leaner script, at the expense of
# functionality. [false]
$CONFIG['DISABLE_POST_COOKIES']=false;
# Header file to include for the proxy main page. []
$CONFIG['INCLUDE_MAIN_HEADER']='';
# Footer file to include for the proxy main page. []
$CONFIG['INCLUDE_MAIN_FOOTER']='';
# Header file to include for the proxy URL form page. []
$CONFIG['INCLUDE_URL_HEADER']='';
# Default value for tunnel server. []
$CONFIG['DEFAULT_TUNNEL_IP']='';
# Default value for tunnel port. []
$CONFIG['DEFAULT_TUNNEL_PORT']='';
# Force the default values of the tunnel fields, and disallow user input.
# [false]
$CONFIG['FORCE_DEFAULT_TUNNEL']=false;
# Default value for User-Agent. []
$CONFIG['DEFAULT_USER_AGENT']='';
# Force the default value of the user agent field, and disallow user input.
# [false]
$CONFIG['FORCE_DEFAULT_USER_AGENT']=false;
# Default value for "Persistent URL" checkbox. [true]
$CONFIG['DEFAULT_URL_FORM']=true;
# Force the default value of the "Persistent URL" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_URL_FORM']=false;
# Default value for "Remove Cookies" checkbox. [false]
$CONFIG['DEFAULT_REMOVE_COOKIES']=false;
# Force the default value of the "Remove Cookies" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_REMOVE_COOKIES']=false;
# Default value for "Remove Referer Field" checkbox. [false]
$CONFIG['DEFAULT_REMOVE_REFERER']=false;
# Force the default value of the "Remove Referer Field" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_REMOVE_REFERER']=false;
# Default value for "Remove Scripts" checkbox. [false]
$CONFIG['DEFAULT_REMOVE_SCRIPTS']=false;
# Force the default value of the "Remove Scripts" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_REMOVE_SCRIPTS']=false;
# Default value for "Remove Objects" checkbox. [false]
$CONFIG['DEFAULT_REMOVE_OBJECTS']=false;
# Force the default value of the "Remove Objects" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_REMOVE_OBJECTS']=false;
# Default value for "Encrypt URLs" checkbox. [false]
$CONFIG['DEFAULT_ENCRYPT_URLS']=false;
# Force the default value of the "Encrypt URLs" field, and disallow user input.
# [false]
$CONFIG['FORCE_DEFAULT_ENCRYPT_URLS']=false;
# Default value for "Encrypt Cookies" checkbox. [false]
$CONFIG['DEFAULT_ENCRYPT_COOKIES']=false;
# Force the default value of the "Encrypt Cookies" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_ENCRYPT_COOKIES']=false;
# Default value for "Encode HTML" checkbox. [false]
$CONFIG['DEFAULT_ENCODE_HTML']=false;
# Force the default value of the "Encode HTML" field, and disallow user
# input. [false]
$CONFIG['FORCE_DEFAULT_ENCODE_HTML']=false;
/*/ Address Blocking Notes \*\
Formats for address blocking are as follows:
1.2.3.4 - plain IP address
1.0.0.0/16 - subnet blocking
1.0/16 - subnet blocking
1/8 - subnet blocking
php.net - domain blocking
Default Value: '10/8','172/8','192.168/16','127/8','169.254/16'
\*\ End Address Blocking Notes /*/
$CONFIG['BLOCKED_ADDRESSES']=
array('10/8','172/8','192.168/16','127/8','169.254/16');
#$CONFIG['BLOCKED_ADDRESSES']=array(); // DEBUG
# }}}
# ADVANCED CONFIG {{{
# The following options alter the way documents are parsed on the page, and how
# the internals of th escript actually function.
# ONLY EDIT THIS STUFF IF YOU REALLY KNOW WHAT YOU ARE DOING!
# 500 is the most reasonable number I could come up with as a maximum URL length
# limit. I ran into a 1200+ character long URL once and it nearly melted the
# processor on my laptop trying to parse it. Honestly, who needs this long of a
# URL anyway? [500]
$CONFIG['MAXIMUM_URL_LENGTH']=500;
# Time limit in seconds for a single request and parse. [30]
$CONFIG['TIME_LIMIT']=30;
# Time limit in minutes for a DNS entry to be kept in the cache. [10]
$CONFIG['DNS_CACHE_EXPIRE']=10;
# Maximum memory usage, as specified by memory_limit in php.ini. [16M]
$CONFIG['MEMORY_LIMIT']='128M';
# Use persistent connections [true]
$CONFIG['PERSISTENT_CONNECTIONS']=true;
# Timeout for persistent connections [30]
$CONFIG['PERSISTENT_CONNECTIONS_TIMEOUT']=30;
# PCRE maximum recursion limit (these need to be changed for sites like
# Facebook since they don't use linebreaks when they encode their Javascript
# [5000000] [5000000]
$CONFIG['PCRE_BACKTRACK_LIMIT']=200000;
$CONFIG['PCRE_RECURSION_LIMIT']=200000;
# Use gzip (if possible) to compress the connection between the proxy and the
# user (less bandwidth, more CPU). [true]
$CONFIG['GZIP_PROXY_USER']=false;
# Use gzip (if possible) to compress the connection between the proxy and the
# server (less bandwidth, more CPU). [true]
$CONFIG['GZIP_PROXY_SERVER']=false;
# Protocol that proxy is running on. Change this to a value other than false
# to manually define it. If you leave this value as false, the code detects
# if you are running on an HTTPS connection. If you are, then 'https' is used
# as the PROTO value, otherwise 'http' is used.
$CONFIG['PROTO']=false;
# ignored filetypes for SSL check
$CONFIG['SSL_WARNING_IGNORE_FILETYPES'] = array(
'.css', '.js', '.gif', '.jpeg', '.jpg', '.png', '.bmp'
);
# }}}
# LABEL {{{
global $LABEL;
$LABEL=array();
# TITLE: title text above form
$LABEL['TITLE']='Surrogafier';
# URL: text for URL text field
$LABEL['URL']='URL:';
# TUNNEL: text for tunnel proxy text fields
$LABEL['TUNNEL']='Tunnel Proxy:';
# USER_AGENT: text for user-agent select field
$LABEL['USER_AGENT']='User-Agent:';
# USER_AGENT_CUSTOM: text for user-agent custom text field
$LABEL['USER_AGENT_CUSTOM']='';
# URL_FORM: text for persistent URL form checkbox
$LABEL['URL_FORM']='Persistent URL Form';
# REMOVE_COOKIES: text for remove cookies checkbox
$LABEL['REMOVE_COOKIES']='Remove Cookies';
# REMOVE_REFERER: text for remove referer checkbox
$LABEL['REMOVE_REFERER']='Remove Referer Field';
# REMOVE_SCRIPTS: text for remove scripts checkbox
$LABEL['REMOVE_SCRIPTS']='Remove Scripts (JS, VBS, etc)';
# REMOVE_OBJECTS: text for remove objects checkbox
$LABEL['REMOVE_OBJECTS']='Remove Objects (Flash, Java, etc)';
# ENCRYPT_URLS: text for encrypt URLs checkbox
$LABEL['ENCRYPT_URLS']='Encrypt URLs';
# ENCRYPT_COOKIES: text for encrypt cookies checkbox
$LABEL['ENCRYPT_COOKIES']='Encrypt Cookies';
# ENCODE_HTML: text for encode HTML checkbox
$LABEL['ENCODE_HTML']='Encode HTML';
# SUBMIT_MAIN: text for the main submit button
$LABEL['SUBMIT_MAIN']='Surrogafy';
# SUBMIT_SIMPLE: text for the simple submit button
$LABEL['SUBMIT_SIMPLE']='Surrogafy';
# }}}
# STYLE {{{
# The $STYLE configuration variable can be used to override CSS for the main
# page of Surrogafier. Likewise, the $STYLE_URL_FORM configuration variable can
# be used to override CSS for the URL form. EVERY entry is looped through and
# added as if it were raw CSS. This is free-form and can do whatever you want,
# so below are only the default values of this variable. You can add as many
# CSS entries as you'd like.
global $STYLE;
$STYLE=array();
# body of whole document
$STYLE['body']='
font-family: bitstream vera sans, arial;
margin: 0px;
padding: 0px;
';
# <form>
$STYLE['form#proxy_form']='
margin: 0px;
padding: 0px;
';
# <table>
$STYLE['table#proxy_table']='
margin: 0px;
padding: 0px;
margin-left: auto;
margin-right: auto;
';
# the title text above form
$STYLE['td#proxy_title']='
font-weight: bold;
font-size: 1.4em;
text-align: center;
';
# class for all text fields
$STYLE['input.proxy_text']='
width: 100%;
border: 1px solid #000000;
';
# class for all select fields
$STYLE['select.proxy_select']='
width: 100%;
border: 1px solid #000000;
';
# class for all proxy defined links
$STYLE['a.proxy_link']='
color: #000000;
';
# class for all submit buttons
$STYLE['input.proxy_submit']='
border: 1px solid #000000;
background-color: #FFFFFF;
';
# the simple submit button
$STYLE['input#proxy_submit_simple']='';
# the main submit button
$STYLE['input#proxy_submit_main']='
width: 100%;
';
# the tunnel proxy ip field
$STYLE['input#proxy_tunnel_ip']='
float: left;
width: 73%;
';
# the tunnel proxy port field
$STYLE['input#proxy_tunnel_port']='
float: right;
width: 23%;
';
# the link for script information and a link to the author
$STYLE['a#proxy_link_author']='
float: left;
';
# the link for toggling modes
$STYLE['a#proxy_link_mode']='
float: right;
';
# }}}
# STYLE_URL_FORM {{{
# The default value for $STYLE_URL_FORM is to be completely blank. Add entries
# as you please.
global $STYLE_URL_FORM;
$STYLE_URL_FORM=array();
# }}}
// DON'T EDIT ANYTHING AFTER THIS POINT \\
#
# (unless you absolutely know what you are doing...)
#
# USER CONFIG {{{
define('THIS_FILE',"{$_SERVER['DOCUMENT_ROOT']}{$_SERVER['PHP_SELF']}");
$file_ext_pos=strrpos(THIS_FILE,'.');
define('CONFIG_FILE',
substr(THIS_FILE,0,$file_ext_pos).
'.conf'.
substr(THIS_FILE,$file_ext_pos)
);
if(file_exists(CONFIG_FILE))
include(CONFIG_FILE);
# }}}
# TESTING CENTER {{{
if($IS_SANDBOX){
// these values must be false for the output to be plain text
$CONFIG['GZIP_PROXY_USER']=false;
$CONFIG['GZIP_PROXY_SERVER']=false;
}
# }}}
# COOKIE & SESSION SETUP {{{
//$totstarttime=microtime(true); # BENCHMARK
# set error level to not display notices
error_reporting(E_ALL^E_NOTICE);
# set timezone (required now in PHP)
date_default_timezone_set($CONFIG['SYS_TIMEZONE']);
# PCRE
ini_set('pcre.backtrack_limit', $CONFIG['PCRE_BACKTRACK_LIMIT']);
ini_set('pcre.recursion_limit', $CONFIG['PCRE_RECURSION_LIMIT']);
# set time and memory limits to their defined values, if not in safe mode
if(!ini_get('safe_mode')) set_time_limit($CONFIG['TIME_LIMIT']);
if(!ini_get('safe_mode')) ini_set('memory_limit', $CONFIG['MEMORY_LIMIT']);
# use gzip compression if available and enabled
if($CONFIG['GZIP_PROXY_USER'] && extension_loaded('zlib') &&
!ini_get('zlib.output_compression')
) ob_start('ob_gzhandler');
# reverse magic quotes if enabled
if(
ini_get('magic_quotes_sybase')==1 ||
(ini_get('magic_quotes_sybase')=='' && get_magic_quotes_gpc())
){
function stripslashes_recurse($var){
if(is_array($var)) $var=array_map('stripslashes_recurse',$var);
else{
if(ini_get('magic_quotes_sybase')==1 && get_magic_quotes_gpc())
$var=str_replace('\\\'','\'',$var);
else
$var=stripslashes($var);
}
return $var;
}
$_GET=stripslashes_recurse($_GET);
$_POST=stripslashes_recurse($_POST);
$_COOKIE=stripslashes_recurse($_COOKIE);
}
# script environment constants
$CONFIG['PROTO']=(
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on'?
'https':'http'
);
define('VERSION','1.9.1b');
define('THIS_SCRIPT',
$CONFIG['PROTO']."://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}");
# randomized cookie prefixes
function gen_randstr($len){
$chars=null;
for($i=0;$i<$len;$i++){
$char=rand(0,25);
$char=chr($char+97);
$chars.=$char;
}
return $chars;
}
function dosetcookie($cookname,$cookval,$expire=null){
$_COOKIE[$cookname]=$cookval;
if($expire===null) setcookie($cookname,$cookval);
else setcookie($cookname,$cookval,$expire);
}
if(!isset($_SESSION)) session_start();
define('SESS_PREF_LEN',30);
if(empty($_SESSION['sesspref'])){
$sesspref=gen_randstr(SESS_PREF_LEN);
$_SESSION['sesspref']=$sesspref;
}
else $sesspref=$_SESSION['sesspref'];
if(empty($_COOKIE['user'])){
define('COOK_PREF_LEN',12);
$cookpref=gen_randstr(COOK_PREF_LEN);
dosetcookie('user',$cookpref);
} else {
$cookpref=$_COOKIE['user'];
// the reason we do this dynamically is to support the sandbox asserts
define('COOK_PREF_LEN',strlen($cookpref));
}
define('SESS_PREF',$sesspref);
define('COOK_PREF',$cookpref);
define('FERP_KOOC',strrev($cookpref));
define('COOKIE_SEPARATOR','__'.COOK_PREF.'__');
unset($sesspref,$cookpref);
global $proxy_variables;
$proxy_variables=array(
'user', COOK_PREF, COOK_PREF.'_set_values',
COOK_PREF.'_tunnel_ip',COOK_PREF.'_tunnel_port',
COOK_PREF.'_useragent',COOK_PREF.'_useragent_custom',
COOK_PREF.'_url_form',
COOK_PREF.'_remove_cookies',COOK_PREF.'_remove_referer',
COOK_PREF.'_remove_scripts',COOK_PREF.'_remove_objects',
COOK_PREF.'_encrypt_urls',COOK_PREF.'_encrypt_cookies');
# ssl domains array handling
if(!empty($_GET[COOK_PREF.'_ssl_domain'])){
if(!is_array($_SESSION['ssl_domains'])) $_SESSION['ssl_domains']=array();
$_SESSION['ssl_domains'][]=$_GET[COOK_PREF.'_ssl_domain'];
exit();
}
# }}}
# ENVIRONMENT SETUP {{{
global $postandget,$dns_cache_array;
$postandget=array_merge($_GET,$_POST);
define('PAGETYPE_MINIREGEXP','(=[_\.\-]?\&=|=)?');
define('PAGETYPE_REGEXP','/^'.PAGETYPE_MINIREGEXP.'(.*)$/');
$pagetype_str=preg_replace(PAGETYPE_REGEXP,'\1',$_SERVER['QUERY_STRING']);
define('QUERY_STRING',
substr($_SERVER['QUERY_STRING'],
strlen($pagetype_str),
strlen($_SERVER['QUERY_STRING'])-strlen($pagetype_str)));
define('PAGETYPE_NULL',0);
define('PAGETYPE_FORCE_MAIN',1);
define('PAGETYPE_FRAME_TOP',2);
define('PAGETYPE_FRAMED_PAGE',3);
# framing children for crimes isn't very nice, but the script does it anyway
define('PAGETYPE_FRAMED_CHILD',4);
switch($pagetype_str){
case '=&=': define('PAGETYPE_ID',PAGETYPE_FRAME_TOP); break;
case '=_&=': define('PAGETYPE_ID',PAGETYPE_FRAMED_PAGE); break;
case '=-&=': define('PAGETYPE_ID',PAGETYPE_FORCE_MAIN); break;
case '=.&=': define('PAGETYPE_ID',PAGETYPE_FRAMED_CHILD); break;
# this is one more unencoded string for future features
# case '=*&=': define('PAGETYPE_ID',); break;
default: define('PAGETYPE_ID',PAGETYPE_NULL); break;
}
unset($pagetype_str);
define('NEW_PAGETYPE_FRAME_TOP',(
PAGETYPE_ID===PAGETYPE_FRAMED_CHILD?
PAGETYPE_FRAMED_CHILD:PAGETYPE_FRAME_TOP
));
define('NEW_PAGETYPE_FRAMED_PAGE',(
PAGETYPE_ID===PAGETYPE_FRAMED_CHILD?
PAGETYPE_FRAMED_CHILD:PAGETYPE_FRAMED_PAGE
));
if(!empty($postandget[COOK_PREF])){
$oenc_url="{$postandget[COOK_PREF]}?";
foreach($postandget as $key=>$val){
if(!in_array($key,$proxy_variables) && $key!=''){
$key=urlencode($key);
$val=urlencode($val);
$oenc_url.="{$key}={$val}&";
}
}
$oenc_url=substr($oenc_url,0,-1);
} else $oenc_url=QUERY_STRING;
if(
strpos(substr($oenc_url,0,6),'%')!==false ||
strpos($oenc_url,'%')<strpos($oenc_url,'/') ||
strpos($oenc_url,'%')<strpos($oenc_url,':')
) $oenc_url=urldecode($oenc_url);
define('OENC_URL',preg_replace('/^([^\?\&]+)\&/i','\1?',$oenc_url));
unset($oenc_url);
define('ORIG_URL',proxdec(OENC_URL));
global $curr_url;
$curr_url=ORIG_URL;
define('PAGE_FRAMED',
PAGETYPE_ID===PAGETYPE_FRAMED_PAGE ||
PAGETYPE_ID===PAGETYPE_FRAMED_CHILD ||
QUERY_STRING=='js_regexps_framed' ||
QUERY_STRING=='js_funcs_framed'
);
# ENVIRONMENT SETUP: OPTIONS {{{
global $OPTIONS;
$OPTIONS=array();
define('IS_FORM_INPUT',!empty($postandget[COOK_PREF.'_set_values']));
# registers an option with the OPTIONS array
function register_option(
$config_type,
$config_name,
$cookie_name=null,
$force_name=null
){
if($cookie_name==null)
$cookie_name=strtolower($config_name);
if($force_name==null)
$force_name=$config_name;
global $CONFIG,$OPTIONS,$postandget;
# get user input
$user_input=(
IS_FORM_INPUT?
(
isset($postandget[COOK_PREF."_{$cookie_name}"])?
$postandget[COOK_PREF."_{$cookie_name}"]:false
):
(
isset($_COOKIE[COOK_PREF."_{$cookie_name}"])?
$_COOKIE[COOK_PREF."_{$cookie_name}"]:false
)
);
# option parsers
switch($config_type){
# integer option
case 2:
$user_input=intval($user_input);
break;
# true/false option
case 1:
$user_input=(
IS_FORM_INPUT?
!empty($user_input):
$user_input=='true'
);
break;
# standard option
case 0:
default:
break;
}
# set option value
$OPTIONS[$config_name]=(
$CONFIG["FORCE_DEFAULT_{$force_name}"] || (
!IS_FORM_INPUT && !isset($_COOKIE[COOK_PREF."_{$cookie_name}"])
)?
$CONFIG["DEFAULT_{$config_name}"]:
$user_input
);
# set cookies
if(IS_FORM_INPUT){
dosetcookie(COOK_PREF."_{$cookie_name}",false,0);
if($OPTIONS[$config_name]!=$CONFIG["DEFAULT_{$config_name}"]){
if($config_type==1)
dosetcookie(
COOK_PREF."_{$cookie_name}",
($OPTIONS[$config_name]?'true':'false')
);
else
dosetcookie(COOK_PREF."_{$cookie_name}",$OPTIONS[$config_name]);
}
}
}
# register standard options
register_option(0,'TUNNEL_IP',null,'TUNNEL');
register_option(1,'URL_FORM');
register_option(1,'REMOVE_COOKIES');
register_option(1,'REMOVE_REFERER');
register_option(1,'REMOVE_SCRIPTS');
register_option(1,'REMOVE_OBJECTS');
register_option(1,'ENCRYPT_URLS');
register_option(1,'ENCRYPT_COOKIES');
register_option(1,'ENCODE_HTML');
# register custom defined options
$OPTIONS['USER_AGENT']=(
$CONFIG['FORCE_DEFAULT_USER_AGENT'] || empty($_COOKIE['_useragent'])?
$CONFIG['DEFAULT_USER_AGENT']:(
$_COOKIE[COOK_PREF.'_useragent']=='1'?
$_COOKIE[COOK_PREF.'_useragent_custom']:
$_COOKIE[COOK_PREF.'_useragent']
)
);
register_option(2,'TUNNEL_PORT',null,'TUNNEL');
if($OPTIONS['TUNNEL_PORT']<1 || $OPTIONS['TUNNEL_PORT']>65535)
$OPTIONS['TUNNEL_PORT']=null;
$OPTIONS['SIMPLE_MODE']=$CONFIG['DEFAULT_SIMPLE'] || $CONFIG['FORCE_SIMPLE'];
if(empty($OPTIONS['USER_AGENT']))
$OPTIONS['USER_AGENT']=$_SERVER['HTTP_USER_AGENT'];
# }}}
# }}}
# PHP DECODING FUNCTIONS {{{
function my_base64_decode($string){
return base64_decode(str_replace(' ','+',urldecode($string)));
}
function proxdec($url){
if(strlen($url)==0 || ($url{0}!='~' && strtolower(substr($url,0,3))!='%7e'))
return $url;
#while(strpos($url,'%')!==false) $url=urldecode($url);
#$url=urldecode($url);
while($url{0}=='~' || strtolower(substr($url,0,3))=='%7e'){
$url=substr($url,1);
$url=my_base64_decode($url);
$new_url=null;
for($i=0;$i<strlen($url);$i++){
$char=ord($url{$i});
$char-=ord(substr(SESS_PREF,$i%strlen(SESS_PREF),1));
while($char<32) $char+=94;
$new_url.=chr($char);
}
$url=$new_url;
}
return urldecode($url);
}
# }}}
# FIRST PAGE DISPLAYED WHEN ACCESSING PROXY {{{
if(
PAGETYPE_ID===PAGETYPE_FORCE_MAIN ||
(substr(QUERY_STRING,0,3)!='js_' && ORIG_URL==null)
){
$useragent_platforms=array(
array('Windows', 'windows', 'win32'),
array('Linux', 'linux'),
array('Macintosh', 'macintosh', 'mac_powerpc'),
array('BSD', 'bsd')
);
$useragent_browsers=array(
'firefox' => 'Firefox',
'iceweasel' => 'Iceweasel',
'konqueror' => 'Konqueror',
'msie' => 'Internet Explorer',
'netscape' => 'Netscape',
'opera' => 'Opera',
'safari' => 'Safari',
'seamonkey' => 'SeaMonkey'
);
$useragentinfo=null;
# parse platform
$dobreak=false;
foreach($useragent_platforms as $platform){
for($i=1; $i<count($platform); $i++){
if(stristr($_SERVER['HTTP_USER_AGENT'], $platform[$i])!==false){
$useragentinfo.=$platform[0];
$dobreak=true;
break;
}
}
if($dobreak)
break;
}
if(!$dobreak)
$useragentinfo.='Unknown';
# separator
$useragentinfo.=' / ';
# parse browser
$found=false;
foreach($useragent_browsers as $substr=>$browser){
if(stristr($_SERVER['HTTP_USER_AGENT'],$browser)!==false){
$useragentinfo.=$browser;
$found=true;
break;
}
}
if(!$found)
$useragentinfo.='Unknown';
# construct useragent options
$ver=array(
'dillo' => '0.8.6',
'firefox' => '2.0',
'gecko' => '20061024',
'konq' => '3.5',
'konq_minor' => '3.5.5',
'links' => '2.1pre19',
'lynx' => '2.8.5rel.1',
'moz_rev' => '1.8.1',
'msie6' => '6.0',
'msie7' => '7.0',
'opera' => '9.02',
'safari' => '3.0',
'webkit' => '521.25',
'wget' => '1.10.2',
'windows' => 'NT 5.1'
);
$useragent_array=array(
array(null,"Actual ({$useragentinfo})"),
array('-1',' [ Don\'t Send ] '),
array("Mozilla/5.0 (Windows; U; Windows {$ver['windows']}; en-US; ".
"rv:{$ver['moz_rev']}) Gecko/{$ver['gecko']} Firefox/".
$ver['firefox'],
"Windows XP / Firefox {$ver['firefox']}"),
array("Mozilla/4.0 (compatible; MSIE {$ver['msie7']}; Windows ".
"{$ver['windows']}; SV1)", 'Windows XP / Internet Explorer 7'),
array("Mozilla/4.0 (compatible; MSIE {$ver['msie6']}; Windows ".
"{$ver['windows']}; SV1)", 'Windows XP / Internet Explorer 6'),
array("Opera/{$ver['opera']} (Windows {$ver['windows']}; U; en)",
"Windows XP / Opera {$ver['opera']}"),
array("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:".
"{$ver['moz_rev']}) Gecko/{$ver['gecko']} Firefox/{$ver['firefox']}",
"Mac OS X / Firefox {$ver['firefox']}"),
array("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/".
"{$ver['webkit']} (KHTML, like Gecko) Safari/{$ver['webkit']}",
'Mac OS X / Safari 3.0'),
array("Opera/{$ver['opera']} (Macintosh; PPC Mac OS X; U; en)",
"Mac OS X / Opera {$ver['opera']}"),
array("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:{$ver['moz_rev']}) ".
"Gecko/{$ver['gecko']} Firefox/{$ver['firefox']}",
"Linux / Firefox {$ver['firefox']}"),
array("Opera/{$ver['opera']} (X11; Linux i686; U; en)",
"Linux / Opera {$ver['opera']}"),
array("Mozilla/5.0 (compatible; Konqueror/{$ver['konq']}; Linux) KHTML/".
"{$ver['konq_minor']} (like Gecko)",
"Linux / Konqueror {$ver['konq_minor']}"),
array("Links ({$ver['links']}; Linux 2.6 i686; x)",
"Linux / Links ({$ver['links']})"),
array("Lynx/{$ver['lynx']}","Any / Lynx {$ver['lynx']}"),
array("Dillo/{$ver['dillo']}","Any / Dillo {$ver['dillo']}"),
array("Wget/{$ver['wget']}","Any / Wget {$ver['wget']}"),
array('1',' [ Custom ]')
);
define('IPREGEXP',
'/^((?:[0-2]{0,2}[0-9]{1,2}\.){3}[0-2]{0,2}[0-9]{1,2})\:([0-9]{1,5}$/');
$checkbox_array=array(
'URL_FORM',
'REMOVE_COOKIES',
'REMOVE_REFERER',
'REMOVE_SCRIPTS',
'REMOVE_OBJECTS',
'ENCRYPT_URLS',
'ENCRYPT_COOKIES',
'ENCODE_HTML'
);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo($LABEL['TITLE']); ?></title>
<link rel="stylesheet" type="text/css"
href="<?php echo(THIS_SCRIPT); ?>?css_main" />
<style>
input#proxy_submit_simple {
display: <?php echo(($OPTIONS['SIMPLE_MODE']?'inline':'none')); ?>;
}
</style>
<noscript><style>
input#proxy_url { display: none; }
a#proxy_link_author { float: none; }
a#proxy_link_mode { display: none; }
td#proxy_links_td { text-align: center; }
</style></noscript>
<script type="text/javascript"
src="<?php echo(THIS_SCRIPT); ?>?js_funcs_nowrap"></script>
<script type="text/javascript" language="javascript"><!--
var advanced_mode=<?php echo(($OPTIONS['SIMPLE_MODE']?'false':'true')); ?>;
//--></script>
</head>
<body>
<? if( // main header include
!empty($CONFIG['INCLUDE_MAIN_HEADER']) &&
file_exists($CONFIG['INCLUDE_MAIN_HEADER'])
) include($CONFIG['INCLUDE_MAIN_HEADER']); ?>
<form method="post" id="proxy_form" onsubmit="return main_submit_code();"
action="<?php echo(THIS_SCRIPT); ?>">
<input type="hidden" name="<?php echo(COOK_PREF); ?>_set_values" value="1" />
<input type="hidden" id="proxy_url_hidden" disabled="disabled"
name="<?php echo(COOK_PREF); ?>" />
<table id="proxy_table" cellpadding="0" cellspacing="4">
<tr>
<td colspan="2" id="proxy_title"><?php echo($LABEL['TITLE']); ?></td>
</tr>
<tr>
<td><?php echo($LABEL['URL']); ?></td>
<td>
<input type="text" id="proxy_url" class="proxy_text"
value="<?php echo(ORIG_URL); ?>" />
<noscript>
<input type="text" id="proxy_url_noscript" class="proxy_text"
name="<?php echo(COOK_PREF); ?>"
value="<?php echo(ORIG_URL); ?>" />
</noscript>
<input type="submit" id="proxy_submit_simple" class="proxy_submit"
value="<?php echo($LABEL['SUBMIT_SIMPLE']); ?>" />
</td>
</tr>
<?php if(!$CONFIG['FORCE_DEFAULT_TUNNEL']){ ?>
<tr name="advanced_mode">
<td><?php echo($LABEL['TUNNEL']); ?></td>
<td>
<input type="text" id="proxy_tunnel_ip" class="proxy_text"
name="<?php echo(COOK_PREF); ?>_tunnel_ip"
value="<?php echo($OPTIONS['TUNNEL_IP']); ?>" />
<input type="text" size="5" maxlength="5"
id="proxy_tunnel_port" class="proxy_text"
name="<?php echo(COOK_PREF); ?>_tunnel_port"
value="<?php echo($OPTIONS['TUNNEL_PORT']); ?>" />
</td>
</tr>
<?php } ?>
<?php if(!$CONFIG['FORCE_DEFAULT_USER_AGENT']){ ?>
<tr name="advanced_mode">
<td><?php echo($LABEL['USER_AGENT']); ?></td>
<td>
<select name="<?php echo(COOK_PREF); ?>_useragent"
id="proxy_useragent" class="proxy_select"
onchange="useragent_change();">
<?php foreach($useragent_array as $useragent){ ?>
<option value="<?php echo($useragent[0]); ?>"
<?php if($OPTIONS['USER_AGENT']==$useragent[0])
echo ' selected="selected"'; ?>
><?php echo($useragent[1]); ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr id="proxy_useragent_custom_tr" name="advanced_mode"
class="display_<?php echo(($OPTIONS['USER_AGENT']=='1'?'tr':'none')); ?>">
<td><?php echo($LABEL['USER_AGENT_CUSTOM']); ?></td>
<td>
<input type="text" id="proxy_useragent_custom" class="proxy_text"
name="<?php echo(COOK_PREF); ?>_useragent_custom"
value="<?php echo($OPTIONS['USER_AGENT']); ?>" />
</td>
</tr>
<?php } ?>
<?php
foreach($checkbox_array as $checkbox){
if(!$CONFIG['FORCE_DEFAULT_'.$checkbox]){
$lowername=strtolower($checkbox);
?>
<tr name="advanced_mode">
<td> </td>
<td>
<input type="checkbox" id="proxy_<?php echo($lowername); ?>"
class="proxy_checkbox"
name="<?php echo(COOK_PREF); ?>_<?php echo($lowername); ?>"
<?php if($OPTIONS[$checkbox]) echo 'checked="checked"'; ?>
/> <?php echo($LABEL[$checkbox]); ?>
</td>
</tr>
<?php }
} ?>
<tr name="advanced_mode">
<td colspan="2">
<input type="submit" id="proxy_submit_main" class="proxy_submit"
value="<?php echo($LABEL['SUBMIT_MAIN']); ?>" />
</td>
</tr>
<tr>
<td colspan="2" id="proxy_links_td">
<a id="proxy_link_author" class="proxy_link" href="http://bcable.net/">
Surrogafier v<?php echo(VERSION); ?>
<b>·</b> Brad Cable
</a>
<a id="proxy_link_mode" class="proxy_link" href="#"
onclick="toggle_mode();">
<?php echo($OPTIONS['SIMPLE_MODE']?'Advanced':'Simple');
?> Mode
</a>
</td>
</tr>
</table>
</form>
<? if( // main footer include
!empty($CONFIG['INCLUDE_MAIN_FOOTER']) &&
file_exists($CONFIG['INCLUDE_MAIN_FOOTER'])
) include($CONFIG['INCLUDE_MAIN_FOOTER']); ?>
<noscript>
<br />
<b>**</b> Surrogafier has detected that your browser does not have Javascript
enabled. <b>**</b>
<br />
<b>**</b> Surrogafier requires Javascript in order to function to its full
potential. It is highly recommended that you have Javascript enabled for
privacy and security reasons. <b>**</b>
</noscript>
</body>
</html>
<?php exit(); }
# }}}
# FRAMED PAGE WITH URL FORM {{{
if(
PAGETYPE_ID===PAGETYPE_FRAME_TOP &&
$OPTIONS['URL_FORM'] &&
ORIG_URL!=null
){ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo($LABEL['TITLE']); ?></title>
<style>
html, body {
font-family: bitstream vera sans, arial;
margin: 0px;
padding: 0px;
height: 100%;
overflow: hidden;
}
form#url_form {
margin: 0px;
padding: 0px;
height: 100%;
}
table#url_table {
margin: 0px;