├── deps ├── ok │ ├── libok.so │ ├── libok.so.0 │ ├── ok.o │ ├── test │ ├── libok.a │ ├── libok.so.0.1 │ ├── clib.json │ ├── test.c │ ├── buffer.c │ ├── ok.h │ ├── ok.c │ ├── test-old.c │ ├── b64.h │ ├── encode.c │ ├── Makefile │ └── decode.c ├── b64 │ ├── clib.json │ ├── buffer.c │ ├── b64.h │ ├── encode.c │ └── decode.c └── b6.c ├── cache ├── response.b1a12e0c.fb.com.ttl ├── response.b1a12e0c.b1a13018.alt └── response.b1a12e0c.fb.com.main ├── AUTHORS ├── dnsp ├── decode.o ├── dnsp-h2 ├── encode.o ├── capture.jpg ├── getaddrinfo ├── out.txt ├── .gitignore ├── capture-http2.png ├── Ethernet-arduino.zip ├── DNSProxy_MFantuzzi.ppt ├── hexdump.h ├── polipo ├── polipo.sh └── polipo.conf ├── php-resolver ├── nslookup_original.php ├── full_resolver.php ├── dns.html ├── dnscheck.js ├── ns.php.noEtag ├── nslookup_googlecloud.php ├── nslookup.php └── nslookup-doh.php ├── examples ├── monitor.sh ├── test.sh └── mon.sh ├── hex.c ├── b64.h ├── TODO ├── LICENSE ├── varnish ├── etc-default-varnish └── etc-varnish-default-vcl ├── librb64u.h ├── printout.c ├── Makefile ├── GO └── httpdns.go ├── H2-dialog ├── NGINX ├── nginx.conf └── sites-enabled-default ├── encode.c ├── decode.c ├── DNS_types_info.txt ├── CURL_OPTS ├── curl-multiplex-dld.c ├── librb64u.c ├── arduino └── dnsp-arduino.ino └── dnsp.c.fork.bak /deps/ok/libok.so: -------------------------------------------------------------------------------- 1 | libok.so.0.1 -------------------------------------------------------------------------------- /deps/ok/libok.so.0: -------------------------------------------------------------------------------- 1 | libok.so.0.1 -------------------------------------------------------------------------------- /cache/response.b1a12e0c.fb.com.ttl: -------------------------------------------------------------------------------- 1 | ! -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Massimiliano Fantuzzi 2 | -------------------------------------------------------------------------------- /dnsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/dnsp -------------------------------------------------------------------------------- /decode.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/decode.o -------------------------------------------------------------------------------- /dnsp-h2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/dnsp-h2 -------------------------------------------------------------------------------- /encode.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/encode.o -------------------------------------------------------------------------------- /capture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/capture.jpg -------------------------------------------------------------------------------- /getaddrinfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/getaddrinfo -------------------------------------------------------------------------------- /deps/ok/ok.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/deps/ok/ok.o -------------------------------------------------------------------------------- /deps/ok/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/deps/ok/test -------------------------------------------------------------------------------- /out.txt: -------------------------------------------------------------------------------- 1 | char hex_array[] = { 0x70, 0xc0, 0x7c, 0x4d, 0xfc, 0x7f, 0, 0 }; 2 | -------------------------------------------------------------------------------- /deps/ok/libok.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/deps/ok/libok.a -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | getaddrinfo 2 | ssl.txt 3 | dnsp.c.backup 4 | dnsp.c.bac 5 | dnsp.c.ori 6 | -------------------------------------------------------------------------------- /capture-http2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/capture-http2.png -------------------------------------------------------------------------------- /Ethernet-arduino.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/Ethernet-arduino.zip -------------------------------------------------------------------------------- /deps/ok/libok.so.0.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/deps/ok/libok.so.0.1 -------------------------------------------------------------------------------- /DNSProxy_MFantuzzi.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/DNSProxy_MFantuzzi.ppt -------------------------------------------------------------------------------- /cache/response.b1a12e0c.b1a13018.alt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/cache/response.b1a12e0c.b1a13018.alt -------------------------------------------------------------------------------- /cache/response.b1a12e0c.fb.com.main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fantuz/DNSProxy/HEAD/cache/response.b1a12e0c.fb.com.main -------------------------------------------------------------------------------- /hexdump.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEXDUMP_H 2 | #define _HEXDUMP_H 3 | 4 | void hexdump(void *mem, unsigned int len); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /deps/b64/clib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "b64", 3 | "repo": "jwerle/b64.c", 4 | "version": "0.1.0", 5 | "description": "Base64 encode/decode", 6 | "keywords": ["base", "64", "crypto"], 7 | "src": ["b64.h", "encode.c", "decode.c", "buffer.c"], 8 | "development": { "jwerle/libok": "*" } 9 | } 10 | -------------------------------------------------------------------------------- /deps/ok/clib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ok", 3 | "version": "0.3.1", 4 | "author": "Joseph Werle", 5 | "description": "Super tiny tap output library", 6 | "repo": "jwerle/libok", 7 | "src": [ 8 | "ok.h", 9 | "ok.c", 10 | "Makefile" 11 | ], 12 | "keywords": [ 13 | "tap", 14 | "test" 15 | ] 16 | } -------------------------------------------------------------------------------- /polipo/polipo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ##diskCacheRoot = "/tmp/polipo/" 4 | #diskCacheRoot = "/var/cache/polipo/" 5 | ##localDocumentRoot = "/usr/share/polipo/www/doc/" 6 | 7 | mkdir /tmp/polipo 8 | 9 | if [ -d /var/cache/polipo/ ]; then 10 | polipo -c polipo.conf & 11 | tail -f /var/cache/polipo-access.log 12 | fi 13 | 14 | -------------------------------------------------------------------------------- /php-resolver/nslookup_original.php: -------------------------------------------------------------------------------- 1 | 17 | 18 | -------------------------------------------------------------------------------- /deps/ok/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "b64.h" 5 | 6 | int 7 | main (void) { 8 | unsigned char *str = "brian the monkey and bradley the kinkajou are friends"; 9 | char *enc = b64_encode(str, strlen(str)); 10 | 11 | printf("%s\n", enc); // YnJpYW4gdGhlIG1vbmtleSBhbmQgYnJhZGxleSB0aGUga2lua2Fqb3UgYXJlIGZyaWVuZHM= 12 | 13 | char *dec = b64_decode(enc, strlen(enc)); 14 | 15 | printf("%s\n", dec); // brian the monkey and bradley the kinkajou are friends 16 | free(enc); 17 | free(dec); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /examples/monitor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DNS=$1 4 | PORT=$2 5 | NUM=$3 6 | FILE='./DNS_example_input.txt' 7 | 8 | if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then 9 | echo "parameters missing... ./$(basename $0) 127.0.0.1 53 1000" 10 | echo "parameters missing... ./$(basename $0) server port queries" 11 | exit 127 12 | fi 13 | 14 | head -$NUM $FILE | xargs -n 5 -I {} -P $(echo $NUM/5| bc) \ 15 | dig +retry=0 -p $PORT @$DNS {} | grep -E '^[A-Za-z0-9]|Query time' | \ 16 | awk -v xxx=$NUM 'begin{sum=0}{if (/Query time/) sum+=$4} END { print "\nAverage query time: "sum/xxx" ms"}' 17 | 18 | -------------------------------------------------------------------------------- /deps/b6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "b64/b64.h" 5 | #include "ok/ok.h" 6 | 7 | int 8 | main (void) { 9 | unsigned char *str = "brian the monkey and bradley the kinkajou are friends"; 10 | char *enc = b64_encode(str, strlen(str)); 11 | 12 | printf("%s\n", enc); // YnJpYW4gdGhlIG1vbmtleSBhbmQgYnJhZGxleSB0aGUga2lua2Fqb3UgYXJlIGZyaWVuZHM= 13 | 14 | char *dec = b64_decode(enc, strlen(enc)); 15 | 16 | printf("%s\n", dec); // brian the monkey and bradley the kinkajou are friends 17 | free(enc); 18 | free(dec); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /php-resolver/full_resolver.php: -------------------------------------------------------------------------------- 1 | '; 13 | echo 'ANY
'; 14 | print_r($lookupData); 15 | echo 'AUTH
'; 16 | print_r($authns); 17 | echo 'ADDITIONAL
'; 18 | print_r($addtl); 19 | echo ''; 20 | } 21 | else 22 | echo -100; 23 | } 24 | else 25 | { 26 | echo -150; 27 | } 28 | ?> 29 | -------------------------------------------------------------------------------- /hex.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | long int decimalNumber,remainder,quotient; 4 | int i=1,j,temp; 5 | char hexadecimalNumber[100]; 6 | printf("Enter any decimal number: "); 7 | scanf("%ld",&decimalNumber); 8 | quotient = decimalNumber; 9 | while(quotient!=0) { 10 | temp = quotient % 16; 11 | //To convert integer into character 12 | if( temp < 10) 13 | temp =temp + 48; else 14 | temp = temp + 55; 15 | hexadecimalNumber[i++]= temp; 16 | quotient = quotient / 16; 17 | } 18 | printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber); 19 | for (j = i -1 ;j> 0;j--) 20 | printf("%c",hexadecimalNumber[j]); 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /php-resolver/dns.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | DNS Check 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
DOMAIN:
17 | 18 | 19 | -------------------------------------------------------------------------------- /deps/b64/buffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "b64.h" 4 | 5 | #ifdef b64_USE_CUSTOM_MALLOC 6 | extern void* b64_malloc(size_t); 7 | #endif 8 | 9 | #ifdef b64_USE_CUSTOM_REALLOC 10 | extern void* b64_realloc(void*, size_t); 11 | #endif 12 | 13 | int b64_buf_malloc(b64_buffer_t * buf) 14 | { 15 | buf->ptr = b64_malloc(B64_BUFFER_SIZE); 16 | if(!buf->ptr) return -1; 17 | 18 | buf->bufc = 1; 19 | 20 | return 0; 21 | } 22 | 23 | int b64_buf_realloc(b64_buffer_t* buf, size_t size) 24 | { 25 | if (size > buf->bufc * B64_BUFFER_SIZE) 26 | { 27 | while (size > buf->bufc * B64_BUFFER_SIZE) buf->bufc++; 28 | buf->ptr = b64_realloc(buf->ptr, B64_BUFFER_SIZE * buf->bufc); 29 | if (!buf->ptr) return -1; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /deps/ok/buffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "b64.h" 4 | 5 | #ifdef b64_USE_CUSTOM_MALLOC 6 | extern void* b64_malloc(size_t); 7 | #endif 8 | 9 | #ifdef b64_USE_CUSTOM_REALLOC 10 | extern void* b64_realloc(void*, size_t); 11 | #endif 12 | 13 | int b64_buf_malloc(b64_buffer_t * buf) 14 | { 15 | buf->ptr = b64_malloc(B64_BUFFER_SIZE); 16 | if(!buf->ptr) return -1; 17 | 18 | buf->bufc = 1; 19 | 20 | return 0; 21 | } 22 | 23 | int b64_buf_realloc(b64_buffer_t* buf, size_t size) 24 | { 25 | if (size > buf->bufc * B64_BUFFER_SIZE) 26 | { 27 | while (size > buf->bufc * B64_BUFFER_SIZE) buf->bufc++; 28 | buf->ptr = b64_realloc(buf->ptr, B64_BUFFER_SIZE * buf->bufc); 29 | if (!buf->ptr) return -1; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -n 'q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | base64 -d | xxd 4 | #00000000: abcd 0100 0001 0000 0000 0000 0377 7777 .............www 5 | #00000010: 0765 7861 6d70 6c65 0363 6f6d 0000 0100 .example.com.... 6 | #00000020: 01 7 | 8 | for i in $(seq 1 3); do 9 | for k in www.google.it www.facebook.fr www.repubblica.it www.wired.com www.amazon.fr www.cachot.ch www.facebook.it; do 10 | #echo -n "$k:" && 11 | dig -p 5354 +short +timeout=10 +tries=1 -t A $k @127.0.0.1 2>/dev/null | head -1 & 12 | sleep 5 13 | dig -p 5354 +short +timeout=10 +tries=1 +tcp -t A $k @127.0.0.1 2>/dev/null | head -1 & 14 | sleep 5 15 | //dig -p 5354 +short +timeout=3 +tries=1 +tcp -t A $k @127.0.0.1 2>/dev/null | head -1 16 | # | egrep -v '(^;|^$)' & 17 | done 18 | done 19 | -------------------------------------------------------------------------------- /b64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * `b64.h' - b64 3 | * 4 | * copyright (c) 2014 joseph werle 5 | */ 6 | 7 | #ifndef B64_H 8 | #define B64_H 1 9 | 10 | /** 11 | * Base64 index table. 12 | */ 13 | 14 | static const char b64_table[] = { 15 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 16 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 17 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 18 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 19 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 20 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 21 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 22 | '4', '5', '6', '7', '8', '9', '+', '/' 23 | }; 24 | 25 | /** 26 | * Encode `unsigned char *' source with `size_t' size. 27 | * Returns a `char *' base64 encoded string. 28 | */ 29 | 30 | char * 31 | b64_encode (const unsigned char *, size_t); 32 | 33 | /** 34 | * Dencode `char *' source with `size_t' size. 35 | * Returns a `unsigned char *' base64 decoded string. 36 | */ 37 | unsigned char * 38 | b64_decode (const char *, size_t); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | GOALS OF THE PROJECT: 3 | - conform to D-o-H header specifications given in IETF proposals 4 | not difficult as DNSP born before !! 5 | https://tools.ietf.org/html/draft-ietf-doh-dns-over-https-03 6 | https://tools.ietf.org/html/draft-ietf-dnsop-dns-wireformat-http-01 7 | - implement answers from DNS/API engine: dns.google.com 8 | - add REDIS, test started and looking promising, can be used to cache responses or track usage and distribute DNS blockchain 9 | 10 | Post-IETF status: 11 | - no RAW packet in PHP -> mod library or use NET_DNS2 library !! 12 | - no base64 urlencode... not an issue (but requires SRV/CLN mods) 13 | - TTL, fixed :) but need help to do the proper translation HEX/HEX 14 | 15 | MINORS: 16 | - add compression algo choice/type as option (deflate, brotli, gzip ...) 17 | - remove fixed TTL as is is used just for tests on hex coversion 18 | - fix NS et MX trimming (depending on PHP version 5/7?) 19 | 20 | WORK-IN-PROGRESS: 21 | - extract validity TTL from Content-Type header in response, supporting H1 and H2. Then pass it to the ready-made structure 22 | - multiple listener, UDP & TCP, different parsing needed (2 more bytes in/out) 23 | -------------------------------------------------------------------------------- /php-resolver/dnscheck.js: -------------------------------------------------------------------------------- 1 | 2 | var serverData = false; 3 | 4 | if (window.XMLHttpRequest) 5 | { 6 | serverData = new XMLHttpRequest(); 7 | } 8 | else if (window.ActiveXObject) 9 | { 10 | serverData = new ActiveXObject("Microsoft.XMLHTTP"); 11 | } 12 | 13 | function dnsCheck(inputId,outputId) 14 | { 15 | var outputElem = document.getElementById(outputId); 16 | var inputElem = document.getElementById(inputId); 17 | var lookupResults; 18 | if (serverData) 19 | { 20 | serverData.open('GET','dns.php?domain=' + inputElem.value); 21 | serverData.onreadystatechange = function() 22 | { 23 | if (serverData.readyState == 4 && serverData.status == 200) 24 | { 25 | lookupResults = serverData.responseText; 26 | if (lookupResults == -150) 27 | { 28 | outputElem.innerHTML = "No Domain Given"; 29 | } 30 | else if (lookupResults == -100) 31 | { 32 | outputElem.innerHTML = "Lookup Failed/Invalid Domain"; 33 | } 34 | else 35 | { 36 | outputElem.innerHTML = "IP:

" + lookupResults + ". "; 37 | } 38 | } 39 | } 40 | serverData.send(null); 41 | } 42 | else 43 | { 44 | outputElem.innerHTML = "Failed To Create XMLHttpRequest Object"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2009-2013 Andrea Fabrizi 2 | Copyright (c) 2013-2018 Massimiliano Fantuzzi HB3YOE 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /deps/ok/ok.h: -------------------------------------------------------------------------------- 1 | /** 2 | * `ok.h` - libok 3 | * 4 | * Copyright (C) 2014 Joseph Werle 5 | */ 6 | 7 | #ifndef OK_H 8 | #define OK_H 1 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /** 15 | * libok version 16 | */ 17 | 18 | #ifndef OK_VERSION 19 | #define OK_VERSION "0.3.0" 20 | #endif 21 | 22 | /** 23 | * No-op/void `ok()` function 24 | */ 25 | #ifndef okx 26 | #define okx(...) (void) (0); 27 | #endif 28 | 29 | /** 30 | * Increments ok count and 31 | * outputs a message to stdout 32 | */ 33 | 34 | void 35 | ok (const char *, ...); 36 | 37 | /** 38 | * Completes tests and asserts that 39 | * the expected test count matches the 40 | * actual test count if the expected 41 | * count is greater than 0 42 | */ 43 | 44 | void 45 | ok_done (void); 46 | 47 | /** 48 | * Sets the expectation count 49 | */ 50 | 51 | void 52 | ok_expect (int); 53 | 54 | /** 55 | * Returns the expected count 56 | */ 57 | 58 | int 59 | ok_expected (); 60 | 61 | /** 62 | * Returns the ok count 63 | */ 64 | 65 | int 66 | ok_count (); 67 | 68 | /** 69 | * Resets count and expected counters 70 | */ 71 | 72 | void 73 | ok_reset (); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /varnish/etc-default-varnish: -------------------------------------------------------------------------------- 1 | # Configuration file for Varnish Cache. 2 | # 3 | # /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK 4 | # to be set from this shell script fragment. 5 | # 6 | # Note: If systemd is installed, this file is obsolete and ignored. You will 7 | # need to copy /lib/systemd/system/varnish.service to /etc/systemd/system/ and 8 | # edit that file. 9 | 10 | # Should we start varnishd at boot? Set to "no" to disable. 11 | START=yes 12 | 13 | # Set WARMUP_TIME to force a delay in reload-vcl between vcl.load and vcl.use 14 | # This is useful when backend probe definitions need some time before declaring 15 | # configured backends healthy, to avoid routing traffic to a non-healthy backend. 16 | #WARMUP_TIME=0 17 | 18 | # Maximum number of open files (for ulimit -n) 19 | NFILES=131072 20 | 21 | # Maximum locked memory size (for ulimit -l) 22 | # Used for locking the shared memory log in memory. If you increase log size, 23 | # you need to increase this number as well 24 | MEMLOCK=82000 25 | 26 | DAEMON_OPTS="-a 127.0.0.1:80 \ 27 | -T localhost:6082 \ 28 | -f /etc/varnish/default.vcl \ 29 | -S /etc/varnish/secret \ 30 | -s malloc,1024m" 31 | 32 | -------------------------------------------------------------------------------- /librb64u.h: -------------------------------------------------------------------------------- 1 | /** 2 | * re-entrant base64url 3 | * @author jon 4 | * CC-BY-4.0 5 | */ 6 | #ifndef LIB_RB64U_H 7 | #define LIB_RB64U_H 8 | #include 9 | #include 10 | 11 | #define RB64U_RXBUFSZ (4) 12 | 13 | typedef struct b64ue b64ue_t; 14 | typedef struct b64ud b64ud_t; 15 | 16 | struct b64ue 17 | { 18 | uint8_t f; 19 | size_t q, i, j, n; 20 | uint32_t b[RB64U_RXBUFSZ], t, k; 21 | char r; 22 | }; 23 | 24 | struct b64ud 25 | { 26 | uint8_t f, s, k, q; 27 | uint32_t a, b, c, t; 28 | char r; 29 | }; 30 | 31 | 32 | int base64url_encode(char *dest, const size_t maxlen, const char *src, const size_t len, size_t *dlen); 33 | 34 | int base64url_decode(char *dest, const size_t maxlen, const char *src, const size_t len, size_t *dlen); 35 | 36 | 37 | void base64url_encode_reset(b64ue_t *state); 38 | 39 | int base64url_encode_ingest(b64ue_t *state, char c); 40 | 41 | int base64url_encode_getc(b64ue_t *state); 42 | 43 | int base64url_encode_finish(b64ue_t *state); 44 | 45 | 46 | void base64url_decode_reset(b64ud_t *state); 47 | 48 | int base64url_decode_ingest(b64ud_t *state, unsigned char c); 49 | 50 | int base64url_decode_getc(b64ud_t *state); 51 | 52 | int base64url_decode_finish(b64ud_t *state); 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /deps/ok/ok.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "ok.h" 5 | 6 | /** 7 | * Represents the ok count 8 | */ 9 | 10 | static int ok_count_; 11 | 12 | /** 13 | * Represents an optional 14 | * expected test count 15 | */ 16 | 17 | static int ok_expected_; 18 | 19 | void 20 | ok(const char *format, ...) { 21 | va_list args; 22 | 23 | va_start(args, format); 24 | 25 | if (NULL == format) { 26 | format = (const char *) ""; 27 | } 28 | 29 | printf("ok %d ", ++ok_count_); 30 | vprintf(format, args); 31 | printf("\n"); 32 | va_end(args); 33 | } 34 | 35 | void 36 | ok_done(void) { 37 | if (0 != ok_expected_ && ok_count_ != ok_expected_) { 38 | if (ok_expected_ > ok_count_) { 39 | fprintf(stderr, "expected number of success conditions not met.\n"); 40 | } else { 41 | fprintf(stderr, 42 | "expected number of success conditions is less than the " 43 | "number of given success conditions.\n"); 44 | } 45 | exit(1); 46 | } 47 | 48 | printf("1..%d\n", ok_count_); 49 | } 50 | 51 | void 52 | ok_expect(int expected) { 53 | ok_expected_ = expected; 54 | } 55 | 56 | int 57 | ok_expected() { 58 | return ok_expected_; 59 | } 60 | 61 | int 62 | ok_count() { 63 | return ok_count_; 64 | } 65 | 66 | void 67 | ok_reset() { 68 | ok_count_ = 0; 69 | ok_expected_ = 0; 70 | } 71 | -------------------------------------------------------------------------------- /printout.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MAX_LENGTH 80 6 | 7 | int main(void) 8 | { 9 | FILE *fout = fopen("out.txt", "w"); 10 | 11 | if(ferror(fout)) 12 | { 13 | fprintf(stderr, "Error opening output file"); 14 | return 1; 15 | } 16 | char init_line[] = {"char hex_array[] = { "}; 17 | const int offset_length = strlen(init_line); 18 | 19 | char offset_spc[offset_length]; 20 | 21 | unsigned char buff[1024]; 22 | char curr_out[64]; 23 | 24 | int count, i; 25 | int line_length = 0; 26 | 27 | memset((void*)offset_spc, (char)32, sizeof(char) * offset_length - 1); 28 | offset_spc[offset_length - 1] = '\0'; 29 | 30 | fprintf(fout, "%s", init_line); 31 | 32 | while(!feof(stdin)) 33 | { 34 | count = fread(buff, sizeof(char), sizeof(buff) / sizeof(char), stdin); 35 | 36 | for(i = 0; i < count; i++) 37 | { 38 | line_length += sprintf(curr_out, "%#x, ", buff[i]); 39 | 40 | fprintf(fout, "%s", curr_out); 41 | if(line_length >= MAX_LENGTH - offset_length) 42 | { 43 | fprintf(fout, "\n%s", offset_spc); 44 | line_length = 0; 45 | } 46 | } 47 | } 48 | fseek(fout, -2, SEEK_CUR); 49 | fprintf(fout, " };"); 50 | 51 | fclose(fout); 52 | 53 | return EXIT_SUCCESS; 54 | } 55 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -O2 -Wall -W -pedantic -rdynamic -g 3 | FLAG = -DTLS 4 | CFLAGS += $(FLAG) 5 | #CFLAGS = -std=c99 6 | 7 | LIBS = -lcurl -lrt -lnghttp2 -lssl -lbrotlidec -lz -lcrypto -lpthread -lnghttp2 8 | #LIBS += -lboost_system -lboost_system -lboost_thread 9 | #LIBS += -lb64 10 | #LIBS += -lpsl 11 | #LIBS += -L/usr/local/lib 12 | #TARGET = testflag 13 | 14 | # with mutex 15 | # gcc dnsp.c -W -lcurl -g -lpthread -rdynamic -lrt -lbrotlidec -o dnsp 16 | # with semaphores 17 | # gcc dnsp.c -W -lcurl -g -lpthread -rdynamic -lrt -o dnsp 18 | # with threads 19 | # gcc dnsp.c -DTLS -W -lcurl -g -lpthread -rdynamic -lrt -o dnsp 20 | # asio, boost, nghttp, ssl 21 | # gcc dnsp-h2.c -O2 -g -rdynamic -lcurl -lnghttp2 -lpthread -lssl -lboost_system -lboost_system -lboost_thread -lcrypto -lrt -lbrotlidec -w -o dnsp-h2 22 | 23 | all : dnsp dnsp-h2 24 | 25 | dnsp : dnsp.o 26 | ${CC} dnsp.o ${CFLAGS} ${LIBS} -w -o dnsp 27 | 28 | dnsp.o : dnsp.c 29 | ${CC} -w -c dnsp.c 30 | 31 | dnsp-h2 : dnsp-h2.o 32 | ${CC} encode.o decode.o dnsp-h2.o ${CFLAGS} ${LIBS} -g -w -o dnsp-h2 33 | 34 | dnsp-h2.o : dnsp-h2.c 35 | ${CC} -w -g -c dnsp-h2.c 36 | 37 | #${CC} librb64u.c encode.o decode.o base64.c dnsp-h2.c ${CFLAGS} ${LIBS} -w -o dnsp-h2 38 | 39 | clean : 40 | rm -v dnsp dnsp-h2 dnsp.o dnsp-h2.o 41 | 42 | #$(TARGET): $(TARGET).c 43 | # @echo "In Makefile: FLAG = <$(FLAG)>" 44 | # $(CC) $(CFLAGS) $< -o $@ 45 | # 46 | #clean: 47 | # rm -f $(TARGET) 48 | 49 | -------------------------------------------------------------------------------- /GO/httpdns.go: -------------------------------------------------------------------------------- 1 | //use dnspod's httpdns service to query dns 2 | 3 | 4 | package main 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "github.com/miekg/dns" 10 | "io/ioutil" 11 | "log" 12 | "net/http" 13 | ) 14 | 15 | var server_url string = "http://119.29.29.29/d?dn=%s" 16 | 17 | func get_a(domain string) []string { 18 | url := fmt.Sprintf(server_url, domain) 19 | 20 | r, err := http.Get(url) 21 | 22 | if err != nil { 23 | fmt.Println(err) 24 | return []string{} 25 | } 26 | 27 | defer r.Body.Close() 28 | 29 | buf, err := ioutil.ReadAll(r.Body) 30 | if err != nil { 31 | fmt.Println(err) 32 | return []string{} 33 | } 34 | 35 | ip := []string{} 36 | 37 | ips := bytes.Split(buf, []byte(";")) 38 | 39 | for _, ii := range ips { 40 | ip = append(ip, string(ii)) 41 | } 42 | 43 | return ip 44 | } 45 | 46 | func handleRoot(w dns.ResponseWriter, r *dns.Msg) { 47 | // Only A supported 48 | if r.Question[0].Qtype != dns.TypeA { 49 | dns.HandleFailed(w, r) 50 | return 51 | } 52 | 53 | domain := r.Question[0].Name 54 | 55 | ip := get_a(domain) 56 | 57 | if len(ip) == 0 { 58 | dns.HandleFailed(w, r) 59 | return 60 | } 61 | 62 | msg := new(dns.Msg) 63 | msg.SetReply(r) 64 | 65 | for _, ii := range ip { 66 | s := fmt.Sprintf("%s 3600 IN A %s", 67 | dns.Fqdn(domain), ii) 68 | rr, _ := dns.NewRR(s) 69 | msg.Answer = append(msg.Answer, rr) 70 | } 71 | 72 | w.WriteMsg(msg) 73 | } 74 | 75 | func main() { 76 | dns.HandleFunc(".", handleRoot) 77 | err := dns.ListenAndServe("0.0.0.0:53", "udp", nil) 78 | if err != nil { 79 | log.Fatal(err) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /H2-dialog: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Connected 4 | [NPN] server offers: 5 | * h2 6 | * http/1.1 7 | The negotiated protocol: h2 8 | ----------------------------------- 9 | recv SETTINGS frame 10 | (niv=3) 11 | [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):128] 12 | [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65536] 13 | [SETTINGS_MAX_FRAME_SIZE(0x05):16777215] 14 | 15 | recv WINDOW_UPDATE frame 16 | (window_size_increment=2147418112) 17 | 18 | send SETTINGS frame 19 | (niv=2) 20 | [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100] 21 | [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535] 22 | 23 | send SETTINGS frame 24 | ; ACK 25 | (niv=0) 26 | 27 | send PRIORITY frame 28 | (dep_stream_id=0, weight=201, exclusive=0) 29 | send PRIORITY frame 30 | (dep_stream_id=0, weight=101, exclusive=0) 31 | send PRIORITY frame 32 | (dep_stream_id=0, weight=1, exclusive=0) 33 | send PRIORITY frame 34 | (dep_stream_id=7, weight=1, exclusive=0) 35 | send PRIORITY frame 36 | (dep_stream_id=3, weight=1, exclusive=0) 37 | send HEADERS frame 38 | 39 | send HEADERS frame 40 | ; END_STREAM | END_HEADERS | PRIORITY 41 | (padlen=0, dep_stream_id=11, weight=16, exclusive=0) 42 | ----------------------------------- 43 | ; Open new stream 44 | :method: GET 45 | :path: /nslookup.php?host=fantuz.net 46 | :scheme: https 47 | :authority: www.fantuz.net 48 | accept: \* \/* 49 | accept-encoding: gzip, deflate 50 | user-agent: nghttp2/1.21.90 51 | 52 | -------------------------------------------------------------------------------- /examples/mon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DNS=$1 4 | PORT=$2 5 | NUM=$3 6 | FILE='./DNS_example_input.txt' 7 | 8 | if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then 9 | echo "parameters missing... ./$(basename $0) 127.0.0.1 53 1000" 10 | echo "parameters missing... ./$(basename $0) server port queries" 11 | exit 127 12 | fi 13 | 14 | #cat DNS.txt | head -$NUM | \ 15 | #xargs -n 10 -I {} -P $(echo $NUM/10| bc) \ 16 | a=1 17 | b=0 18 | WAIT="" 19 | 20 | # | xargs -n 5 -I {} -P $(echo $NUM/5| bc) 21 | for i in $(shuf -n $NUM $FILE); do 22 | #if [ $a -lt $(echo $NUM/10 | bc) ]; then 23 | if [ $a -gt $(($NUM % 10)) ]; then 24 | dig +retry=0 -p $PORT +timeout=3 $i @$DNS & 25 | WAIT="$WAIT $!" 26 | let a=a+1 27 | else 28 | dig +retry=0 -p $PORT +timeout=3 $i @$DNS 29 | let a=0 30 | wait $WAIT 31 | fi 32 | done | tee my.count | awk -v tot=$NUM -v times=0 -v noerr=0 -F ' ' 'BEGIN {tsum=0; mism=0; nxdom=0; formerr=0; servfail=0;tout=0} { if (/Query time/) {tsum+=$4 ; times+=1;}; if (/SERVFAIL/) {servfail+=1;}; if (/NOERROR/) {noerr+=1;}; if (/mismatch/) {mism+=1}; if (/NXDOMAIN/) {nxdom+=1}; if (/FORMERR,/) {formerr+=1}; if (/timed out,/) {tout+=1}; } { if (/; <<>>/) {print $0}; if (/HEADER/) {print $0}; if (/mismatch/) {print $0}; if (/connection/) {print $0} } END { print "\nAverage query time: "tsum/tot" ms ("times"/"tot") [ NOERR:"noerr" ERR_MISMATCH:"mism" ERR_FORMERR:"formerr" ERR_NXDOMAIN:"nxdom" ERR_SERVFAIL:"servfail" ERR_TIMEOUT:"tout" ]\n" }' 33 | #|grep time 34 | #dig {} @$DNS | grep -E '^[A-Za-z0-9]|Query time' | \ 35 | echo "Request received SERVFAIL: "$(grep -c 'SERVFAIL' my.count)/$NUM 36 | echo "Request section mismatch : "$(grep -c 'mismatch' my.count)/$NUM 37 | echo "Request failed timeout : "$(grep -c 'timed out' my.count)/$NUM 38 | echo "Connection refused : "$(grep -c 'connection refused' my.count)/$NUM 39 | #;; connection timed out; no servers could be reached 40 | 41 | -------------------------------------------------------------------------------- /deps/ok/test-old.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `test.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | //#include 13 | //#include 14 | //#include 15 | #include 16 | 17 | #include "b64.h" 18 | #include "ok.h" 19 | //#include "deps/ok/ok.h" 20 | //#include "deps/b64/b64.h" 21 | 22 | #define S(x) # x 23 | #define t(m, a, b) ({ \ 24 | char tmp[1024]; \ 25 | sprintf(tmp, "%s(%s) = %s", S(m), S(a), S(b)); \ 26 | char *r = (char *) m(a, strlen((char *) a)); \ 27 | assert(0 == strcmp(b, r)); \ 28 | free(r); \ 29 | ok(tmp); \ 30 | }) 31 | 32 | void* custom_malloc(size_t size){ 33 | if (size == 0){ 34 | /* On some systems malloc doesn't allow for size = 0 */ 35 | return NULL; 36 | } 37 | return malloc(size); 38 | } 39 | 40 | void* custom_realloc(void* ptr, size_t size){ 41 | return realloc(ptr, size); 42 | } 43 | 44 | int 45 | main (void) { 46 | 47 | // encode 48 | { 49 | t(b64_encode, (const unsigned char *) "bradley", "YnJhZGxleQ=="); 50 | t(b64_encode, (const unsigned char *) "kinkajou", "a2lua2Fqb3U="); 51 | t(b64_encode, (const unsigned char *) "vino", "dmlubw=="); 52 | t(b64_encode, 53 | (const unsigned char *) "brian the monkey and bradley the kinkajou are friends", 54 | "YnJpYW4gdGhlIG1vbmtleSBhbmQgYnJhZGxleSB0aGUga2lua2Fqb3UgYXJlIGZyaWVuZHM="); 55 | } 56 | 57 | // decode 58 | { 59 | t(b64_decode, "Y2FzaWxsZXJv", "casillero"); 60 | t(b64_decode, "aGF4", "hax"); 61 | t(b64_decode, "bW9ua2V5cyBhbmQgZG9ncw==", "monkeys and dogs"); 62 | t(b64_decode, 63 | "dGhlIGtpbmtham91IGFuZCBtb25rZXkgZm91Z2h0IG92ZXIgdGhlIGJhbmFuYQ==", 64 | "the kinkajou and monkey fought over the banana"); 65 | } 66 | 67 | ok_done(); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /deps/b64/b64.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `b64.h' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #ifndef B64_H 9 | #define B64_H 1 10 | 11 | typedef struct b64_buffer { 12 | char * ptr; 13 | int bufc; 14 | } b64_buffer_t; 15 | 16 | /** 17 | * Memory allocation functions to use. You can define b64_malloc and 18 | * b64_realloc to custom functions if you want. 19 | */ 20 | 21 | #ifndef b64_malloc 22 | # define b64_malloc(ptr) malloc(ptr) 23 | #endif 24 | #ifndef b64_realloc 25 | # define b64_realloc(ptr, size) realloc(ptr, size) 26 | #endif 27 | 28 | // How much memory to allocate per buffer 29 | #define B64_BUFFER_SIZE (1024 * 64) // 64K 30 | 31 | // Start buffered memory 32 | int b64_buf_malloc(b64_buffer_t * buffer); 33 | 34 | // Update memory size. Returns the same pointer if we 35 | // have enough space in the buffer. Otherwise, we add 36 | // additional buffers. 37 | int b64_buf_realloc(b64_buffer_t * buffer, size_t size); 38 | 39 | /** 40 | * Base64 index table. 41 | */ 42 | 43 | static const char b64_table[] = { 44 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 45 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 46 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 47 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 48 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 49 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 50 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 51 | '4', '5', '6', '7', '8', '9', '+', '/' 52 | }; 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /** 59 | * Encode `unsigned char *' source with `size_t' size. 60 | * Returns a `char *' base64 encoded string. 61 | */ 62 | 63 | char * 64 | b64_encode (const unsigned char *, size_t); 65 | 66 | /** 67 | * Decode `char *' source with `size_t' size. 68 | * Returns a `unsigned char *' base64 decoded string. 69 | */ 70 | unsigned char * 71 | b64_decode (const char *, size_t); 72 | 73 | /** 74 | * Decode `char *' source with `size_t' size. 75 | * Returns a `unsigned char *' base64 decoded string + size of decoded string. 76 | */ 77 | unsigned char * 78 | b64_decode_ex (const char *, size_t, size_t *); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /deps/ok/b64.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `b64.h' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | 10 | #ifndef B64_H 11 | #define B64_H 1 12 | 13 | typedef struct b64_buffer { 14 | char * ptr; 15 | int bufc; 16 | } b64_buffer_t; 17 | 18 | /** 19 | * Memory allocation functions to use. You can define b64_malloc and 20 | * b64_realloc to custom functions if you want. 21 | */ 22 | 23 | #ifndef b64_malloc 24 | # define b64_malloc(ptr) malloc(ptr) 25 | #endif 26 | #ifndef b64_realloc 27 | # define b64_realloc(ptr, size) realloc(ptr, size) 28 | #endif 29 | 30 | // How much memory to allocate per buffer 31 | #define B64_BUFFER_SIZE (1024 * 64) // 64K 32 | 33 | // Start buffered memory 34 | int b64_buf_malloc(b64_buffer_t * buffer); 35 | 36 | // Update memory size. Returns the same pointer if we 37 | // have enough space in the buffer. Otherwise, we add 38 | // additional buffers. 39 | int b64_buf_realloc(b64_buffer_t * buffer, size_t size); 40 | 41 | /** 42 | * Base64 index table. 43 | */ 44 | 45 | static const char b64_table[] = { 46 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 47 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 48 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 49 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 50 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 51 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 52 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 53 | '4', '5', '6', '7', '8', '9', '+', '/' 54 | }; 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | /** 61 | * Encode `unsigned char *' source with `size_t' size. 62 | * Returns a `char *' base64 encoded string. 63 | */ 64 | 65 | char * 66 | b64_encode (const unsigned char *, size_t); 67 | 68 | /** 69 | * Decode `char *' source with `size_t' size. 70 | * Returns a `unsigned char *' base64 decoded string. 71 | */ 72 | unsigned char * 73 | b64_decode (const char *, size_t); 74 | 75 | /** 76 | * Decode `char *' source with `size_t' size. 77 | * Returns a `unsigned char *' base64 decoded string + size of decoded string. 78 | */ 79 | unsigned char * 80 | b64_decode_ex (const char *, size_t, size_t *); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /NGINX/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes 2; 3 | pid /run/nginx.pid; 4 | 5 | events { 6 | worker_connections 2048; 7 | multi_accept on; 8 | } 9 | 10 | http { 11 | 12 | ## 13 | # Basic Settings 14 | ## 15 | #aio threads; 16 | #limit_rate 0; 17 | #resolver 8.8.8.8; 18 | #etag on; 19 | sendfile on; 20 | tcp_nopush on; 21 | tcp_nodelay on; 22 | #keepalive_timeout 0; 23 | keepalive_timeout 30; 24 | #keepalive_requests 256; 25 | types_hash_max_size 2048; 26 | # server_tokens off; 27 | 28 | # server_names_hash_bucket_size 64; 29 | # server_name_in_redirect off; 30 | 31 | include /etc/nginx/mime.types; 32 | default_type application/octet-stream; 33 | 34 | ## 35 | # Logging Settings 36 | ## 37 | 38 | access_log /var/log/nginx/access.log; 39 | error_log /var/log/nginx/error.log; 40 | 41 | ## 42 | # Gzip Settings 43 | ## 44 | 45 | gzip on; 46 | gzip_disable "msie6"; 47 | 48 | # gzip_vary on; 49 | # gzip_proxied any; 50 | # gzip_comp_level 6; 51 | # gzip_buffers 16 8k; 52 | # gzip_http_version 1.1; 53 | # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 54 | 55 | ## 56 | # nginx-naxsi config 57 | ## 58 | # Uncomment it if you installed nginx-naxsi 59 | ## 60 | 61 | #include /etc/nginx/naxsi_core.rules; 62 | 63 | ## 64 | # nginx-passenger config 65 | ## 66 | # Uncomment it if you installed nginx-passenger 67 | ## 68 | 69 | #passenger_root /usr; 70 | #passenger_ruby /usr/bin/ruby; 71 | 72 | ### 73 | # SSL config 74 | ### 75 | 76 | ssl_session_cache shared:SSL:10m; 77 | ssl_session_timeout 10m; 78 | 79 | ## 80 | # Virtual Host Configs 81 | ## 82 | 83 | include /etc/nginx/conf.d/*.conf; 84 | include /etc/nginx/sites-enabled/*; 85 | 86 | } 87 | 88 | #mail { 89 | # # See sample authentication script at: 90 | # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript 91 | # 92 | # # auth_http localhost/auth.php; 93 | # # pop3_capabilities "TOP" "USER"; 94 | # # imap_capabilities "IMAP4rev1" "UIDPLUS"; 95 | # 96 | # server { 97 | # listen localhost:110; 98 | # protocol pop3; 99 | # proxy on; 100 | # } 101 | # 102 | # server { 103 | # listen localhost:143; 104 | # protocol imap; 105 | # proxy on; 106 | # } 107 | #} 108 | -------------------------------------------------------------------------------- /encode.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `encode.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include "b64.h" 11 | 12 | #ifdef b64_USE_CUSTOM_MALLOC 13 | extern void* b64_malloc(size_t); 14 | #endif 15 | 16 | #ifdef b64_USE_CUSTOM_REALLOC 17 | extern void* b64_realloc(void*, size_t); 18 | #endif 19 | 20 | char * 21 | b64_encode (const unsigned char *src, size_t len) { 22 | int i = 0; 23 | int j = 0; 24 | char *enc = NULL; 25 | size_t size = 0; 26 | unsigned char buf[4]; 27 | unsigned char tmp[3]; 28 | 29 | // alloc 30 | enc = (char *) b64_malloc(1); 31 | if (NULL == enc) { return NULL; } 32 | 33 | // parse until end of source 34 | while (len--) { 35 | // read up to 3 bytes at a time into `tmp' 36 | tmp[i++] = *(src++); 37 | 38 | // if 3 bytes read then encode into `buf' 39 | if (3 == i) { 40 | buf[0] = (tmp[0] & 0xfc) >> 2; 41 | buf[1] = ((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4); 42 | buf[2] = ((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6); 43 | buf[3] = tmp[2] & 0x3f; 44 | 45 | // allocate 4 new byts for `enc` and 46 | // then translate each encoded buffer 47 | // part by index from the base 64 index table 48 | // into `enc' unsigned char array 49 | enc = (char *) b64_realloc(enc, size + 4); 50 | for (i = 0; i < 4; ++i) { 51 | enc[size++] = b64_table[buf[i]]; 52 | } 53 | 54 | // reset index 55 | i = 0; 56 | } 57 | } 58 | 59 | // remainder 60 | if (i > 0) { 61 | // fill `tmp' with `\0' at most 3 times 62 | for (j = i; j < 3; ++j) { 63 | tmp[j] = '\0'; 64 | } 65 | 66 | // perform same codec as above 67 | buf[0] = (tmp[0] & 0xfc) >> 2; 68 | buf[1] = ((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4); 69 | buf[2] = ((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6); 70 | buf[3] = tmp[2] & 0x3f; 71 | 72 | // perform same write to `enc` with new allocation 73 | for (j = 0; (j < i + 1); ++j) { 74 | enc = (char *) b64_realloc(enc, size + 1); 75 | enc[size++] = b64_table[buf[j]]; 76 | } 77 | 78 | // while there is still a remainder 79 | // append `=' to `enc' 80 | while ((i++ < 3)) { 81 | enc = (char *) b64_realloc(enc, size + 1); 82 | enc[size++] = '='; 83 | } 84 | } 85 | 86 | // Make sure we have enough space to add '\0' character at end. 87 | enc = (char *) b64_realloc(enc, size + 1); 88 | enc[size] = '\0'; 89 | 90 | return enc; 91 | } 92 | -------------------------------------------------------------------------------- /deps/ok/encode.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `encode.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include "b64.h" 11 | 12 | #ifdef b64_USE_CUSTOM_MALLOC 13 | extern void* b64_malloc(size_t); 14 | #endif 15 | 16 | #ifdef b64_USE_CUSTOM_REALLOC 17 | extern void* b64_realloc(void*, size_t); 18 | #endif 19 | 20 | char * 21 | b64_encode (const unsigned char *src, size_t len) { 22 | int i = 0; 23 | int j = 0; 24 | b64_buffer_t encbuf; 25 | size_t size = 0; 26 | unsigned char buf[4]; 27 | unsigned char tmp[3]; 28 | 29 | // alloc 30 | if(b64_buf_malloc(&encbuf) == -1) { return NULL; } 31 | 32 | // parse until end of source 33 | while (len--) { 34 | // read up to 3 bytes at a time into `tmp' 35 | tmp[i++] = *(src++); 36 | 37 | // if 3 bytes read then encode into `buf' 38 | if (3 == i) { 39 | buf[0] = (tmp[0] & 0xfc) >> 2; 40 | buf[1] = ((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4); 41 | buf[2] = ((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6); 42 | buf[3] = tmp[2] & 0x3f; 43 | 44 | // allocate 4 new byts for `enc` and 45 | // then translate each encoded buffer 46 | // part by index from the base 64 index table 47 | // into `encbuf.ptr' unsigned char array 48 | if (b64_buf_realloc(&encbuf, size + 4) == -1) return NULL; 49 | 50 | for (i = 0; i < 4; ++i) { 51 | encbuf.ptr[size++] = b64_table[buf[i]]; 52 | } 53 | 54 | // reset index 55 | i = 0; 56 | } 57 | } 58 | 59 | // remainder 60 | if (i > 0) { 61 | // fill `tmp' with `\0' at most 3 times 62 | for (j = i; j < 3; ++j) { 63 | tmp[j] = '\0'; 64 | } 65 | 66 | // perform same codec as above 67 | buf[0] = (tmp[0] & 0xfc) >> 2; 68 | buf[1] = ((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4); 69 | buf[2] = ((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6); 70 | buf[3] = tmp[2] & 0x3f; 71 | 72 | // perform same write to `encbuf->ptr` with new allocation 73 | for (j = 0; (j < i + 1); ++j) { 74 | if (b64_buf_realloc(&encbuf, size + 1) == -1) return NULL; 75 | 76 | encbuf.ptr[size++] = b64_table[buf[j]]; 77 | } 78 | 79 | // while there is still a remainder 80 | // append `=' to `encbuf.ptr' 81 | while ((i++ < 3)) { 82 | if (b64_buf_realloc(&encbuf, size + 1) == -1) return NULL; 83 | 84 | encbuf.ptr[size++] = '='; 85 | } 86 | } 87 | 88 | // Make sure we have enough space to add '\0' character at end. 89 | if (b64_buf_realloc(&encbuf, size + 1) == -1) return NULL; 90 | encbuf.ptr[size] = '\0'; 91 | 92 | return encbuf.ptr; 93 | } 94 | -------------------------------------------------------------------------------- /deps/b64/encode.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `encode.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include "b64.h" 11 | 12 | #ifdef b64_USE_CUSTOM_MALLOC 13 | extern void* b64_malloc(size_t); 14 | #endif 15 | 16 | #ifdef b64_USE_CUSTOM_REALLOC 17 | extern void* b64_realloc(void*, size_t); 18 | #endif 19 | 20 | char * 21 | b64_encode (const unsigned char *src, size_t len) { 22 | int i = 0; 23 | int j = 0; 24 | b64_buffer_t encbuf; 25 | size_t size = 0; 26 | unsigned char buf[4]; 27 | unsigned char tmp[3]; 28 | 29 | // alloc 30 | if(b64_buf_malloc(&encbuf) == -1) { return NULL; } 31 | 32 | // parse until end of source 33 | while (len--) { 34 | // read up to 3 bytes at a time into `tmp' 35 | tmp[i++] = *(src++); 36 | 37 | // if 3 bytes read then encode into `buf' 38 | if (3 == i) { 39 | buf[0] = (tmp[0] & 0xfc) >> 2; 40 | buf[1] = ((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4); 41 | buf[2] = ((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6); 42 | buf[3] = tmp[2] & 0x3f; 43 | 44 | // allocate 4 new byts for `enc` and 45 | // then translate each encoded buffer 46 | // part by index from the base 64 index table 47 | // into `encbuf.ptr' unsigned char array 48 | if (b64_buf_realloc(&encbuf, size + 4) == -1) return NULL; 49 | 50 | for (i = 0; i < 4; ++i) { 51 | encbuf.ptr[size++] = b64_table[buf[i]]; 52 | } 53 | 54 | // reset index 55 | i = 0; 56 | } 57 | } 58 | 59 | // remainder 60 | if (i > 0) { 61 | // fill `tmp' with `\0' at most 3 times 62 | for (j = i; j < 3; ++j) { 63 | tmp[j] = '\0'; 64 | } 65 | 66 | // perform same codec as above 67 | buf[0] = (tmp[0] & 0xfc) >> 2; 68 | buf[1] = ((tmp[0] & 0x03) << 4) + ((tmp[1] & 0xf0) >> 4); 69 | buf[2] = ((tmp[1] & 0x0f) << 2) + ((tmp[2] & 0xc0) >> 6); 70 | buf[3] = tmp[2] & 0x3f; 71 | 72 | // perform same write to `encbuf->ptr` with new allocation 73 | for (j = 0; (j < i + 1); ++j) { 74 | if (b64_buf_realloc(&encbuf, size + 1) == -1) return NULL; 75 | 76 | encbuf.ptr[size++] = b64_table[buf[j]]; 77 | } 78 | 79 | // while there is still a remainder 80 | // append `=' to `encbuf.ptr' 81 | while ((i++ < 3)) { 82 | if (b64_buf_realloc(&encbuf, size + 1) == -1) return NULL; 83 | 84 | encbuf.ptr[size++] = '='; 85 | } 86 | } 87 | 88 | // Make sure we have enough space to add '\0' character at end. 89 | if (b64_buf_realloc(&encbuf, size + 1) == -1) return NULL; 90 | encbuf.ptr[size] = '\0'; 91 | 92 | return encbuf.ptr; 93 | } 94 | -------------------------------------------------------------------------------- /deps/ok/Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local 2 | DESTDIR ?= ok 3 | 4 | OS = $(shell uname) 5 | CC ?= cc 6 | AR = ar 7 | LN = ln 8 | RM = rm 9 | VALGRIND ?= valgrind 10 | STRIP = strip 11 | 12 | LIB_NAME = ok 13 | VERSION_MAJOR = 0 14 | VERSION_MINOR = 1 15 | 16 | TARGET_NAME = lib$(LIB_NAME) 17 | TARGET_STATIC = $(TARGET_NAME).a 18 | TARGET_DSOLIB = $(TARGET_NAME).so.$(VERSION_MAJOR).$(VERSION_MINOR) 19 | TARGET_DYLIB = $(TARGET_NAME).$(VERSION_MAJOR).$(VERSION_MINOR).dylib 20 | TARGET_DSO = $(TARGET_NAME).so 21 | 22 | CFLAGS += -I. \ 23 | -std=c99 -Wall -O2 \ 24 | -fvisibility=hidden \ 25 | -fPIC -pedantic 26 | 27 | LDFLAGS += -shared \ 28 | -soname $(TARGET_DSO).$(VERSION_MAJOR) 29 | 30 | OSX_LDFLAGS += -lc \ 31 | -Wl,-install_name,$(TARGET_DSO) \ 32 | -o $(TARGET_DSOLIB) \ 33 | 34 | SRC = $(wildcard *.c) 35 | OBJS = $(SRC:.c=.o) 36 | 37 | TEST_MAIN = ok-test 38 | 39 | ifneq ("Darwin","$(OS)") 40 | CFLAGS += -lm 41 | endif 42 | 43 | ifdef DEBUG 44 | CFLAGS += -DOK_DEBUG 45 | endif 46 | 47 | all: $(TARGET_STATIC) $(TARGET_DSO) 48 | 49 | $(TARGET_STATIC): $(OBJS) 50 | @echo " LIBTOOL-STATIC $(TARGET_STATIC)" 51 | @$(AR) crus $(TARGET_STATIC) $(OBJS) 52 | 53 | $(TARGET_DSO): $(OBJS) 54 | @echo " LIBTOOL-SHARED $(TARGET_DSOLIB)" 55 | @echo " LIBTOOL-SHARED $(TARGET_DSO)" 56 | @echo " LIBTOOL-SHARED $(TARGET_DSO).$(VERSION_MAJOR)" 57 | ifeq ("Darwin","$(OS)") 58 | @$(CC) -shared $(OBJS) $(OSX_LDFLAGS) -o $(TARGET_DSOLIB) 59 | @$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO) 60 | @$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO).$(VERSION_MAJOR) 61 | else 62 | @$(CC) -shared $(OBJS) -o $(TARGET_DSOLIB) 63 | @$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO) 64 | @$(LN) -s $(TARGET_DSOLIB) $(TARGET_DSO).$(VERSION_MAJOR) 65 | @$(STRIP) --strip-unneeded $(TARGET_DSO) 66 | endif 67 | 68 | $(OBJS): 69 | @echo " CC(target) $@" 70 | @$(CC) $(CFLAGS) -c -o $@ $(@:.o=.c) 71 | 72 | check: test 73 | $(VALGRIND) --leak-check=full ./$(TEST_MAIN) 74 | 75 | test: 76 | @echo " LINK(target) ($(TEST_MAIN))" 77 | @$(CC) test.c ./$(TARGET_STATIC) $(CFLAGS) -o $(TEST_MAIN) 78 | @./$(TEST_MAIN) 79 | 80 | clean: 81 | @for item in \ 82 | $(TEST_MAIN) $(OBJS) $(TARGET_STATIC) \ 83 | $(TARGET_DSOLIB) $(TARGET_DSO).$(VERSION_MAJOR) \ 84 | $(TARGET_DSO) $(TARGET_DYLIB) \ 85 | ; do \ 86 | echo " RM $$item"; \ 87 | $(RM) -rf $$item; \ 88 | done; 89 | 90 | 91 | install: all 92 | @test -d $(PREFIX)/$(DESTDIR) || mkdir $(PREFIX)/$(DESTDIR) 93 | @cp *.h $(PREFIX)/include/$(DESTDIR) 94 | @echo " INSTALL $(LIB_NAME).h"; 95 | @install $(LIB_NAME).h $(PREFIX)/include 96 | @echo " INSTALL $(TARGET_STATIC)"; 97 | @install $(TARGET_STATIC) $(PREFIX)/lib 98 | @echo " INSTALL $(TARGET_DSO)"; 99 | @install $(TARGET_DSO) $(PREFIX)/lib 100 | 101 | uninstall: 102 | rm -rf $(PREFIX)/$(DESTDIR) 103 | rm -f $(PREFIX)/lib/$(TARGET_STATIC) 104 | rm -f $(PREFIX)/lib/$(TARGET_DSO) 105 | 106 | -------------------------------------------------------------------------------- /deps/ok/decode.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `decode.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "b64.h" 12 | 13 | #ifdef b64_USE_CUSTOM_MALLOC 14 | extern void* b64_malloc(size_t); 15 | #endif 16 | 17 | #ifdef b64_USE_CUSTOM_REALLOC 18 | extern void* b64_realloc(void*, size_t); 19 | #endif 20 | 21 | unsigned char * 22 | b64_decode (const char *src, size_t len) { 23 | return b64_decode_ex(src, len, NULL); 24 | } 25 | 26 | unsigned char * 27 | b64_decode_ex (const char *src, size_t len, size_t *decsize) { 28 | int i = 0; 29 | int j = 0; 30 | int l = 0; 31 | size_t size = 0; 32 | b64_buffer_t decbuf; 33 | unsigned char buf[3]; 34 | unsigned char tmp[4]; 35 | 36 | // alloc 37 | if (b64_buf_malloc(&decbuf) == -1) { return NULL; } 38 | 39 | // parse until end of source 40 | while (len--) { 41 | // break if char is `=' or not base64 char 42 | if ('=' == src[j]) { break; } 43 | if (!(isalnum(src[j]) || '+' == src[j] || '/' == src[j])) { break; } 44 | 45 | // read up to 4 bytes at a time into `tmp' 46 | tmp[i++] = src[j++]; 47 | 48 | // if 4 bytes read then decode into `buf' 49 | if (4 == i) { 50 | // translate values in `tmp' from table 51 | for (i = 0; i < 4; ++i) { 52 | // find translation char in `b64_table' 53 | for (l = 0; l < 64; ++l) { 54 | if (tmp[i] == b64_table[l]) { 55 | tmp[i] = l; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | // decode 62 | buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4); 63 | buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2); 64 | buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3]; 65 | 66 | // write decoded buffer to `decbuf.ptr' 67 | if (b64_buf_realloc(&decbuf, size + 3) == -1) return NULL; 68 | for (i = 0; i < 3; ++i) { 69 | ((unsigned char*)decbuf.ptr)[size++] = buf[i]; 70 | } 71 | 72 | // reset 73 | i = 0; 74 | } 75 | } 76 | 77 | // remainder 78 | if (i > 0) { 79 | // fill `tmp' with `\0' at most 4 times 80 | for (j = i; j < 4; ++j) { 81 | tmp[j] = '\0'; 82 | } 83 | 84 | // translate remainder 85 | for (j = 0; j < 4; ++j) { 86 | // find translation char in `b64_table' 87 | for (l = 0; l < 64; ++l) { 88 | if (tmp[j] == b64_table[l]) { 89 | tmp[j] = l; 90 | break; 91 | } 92 | } 93 | } 94 | 95 | // decode remainder 96 | buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4); 97 | buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2); 98 | buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3]; 99 | 100 | // write remainer decoded buffer to `decbuf.ptr' 101 | if (b64_buf_realloc(&decbuf, size + (i - 1)) == -1) return NULL; 102 | for (j = 0; (j < i - 1); ++j) { 103 | ((unsigned char*)decbuf.ptr)[size++] = buf[j]; 104 | } 105 | } 106 | 107 | // Make sure we have enough space to add '\0' character at end. 108 | if (b64_buf_realloc(&decbuf, size + 1) == -1) return NULL; 109 | ((unsigned char*)decbuf.ptr)[size] = '\0'; 110 | 111 | // Return back the size of decoded string if demanded. 112 | if (decsize != NULL) { 113 | *decsize = size; 114 | } 115 | 116 | return (unsigned char*) decbuf.ptr; 117 | } 118 | -------------------------------------------------------------------------------- /deps/b64/decode.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `decode.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "b64.h" 12 | 13 | #ifdef b64_USE_CUSTOM_MALLOC 14 | extern void* b64_malloc(size_t); 15 | #endif 16 | 17 | #ifdef b64_USE_CUSTOM_REALLOC 18 | extern void* b64_realloc(void*, size_t); 19 | #endif 20 | 21 | unsigned char * 22 | b64_decode (const char *src, size_t len) { 23 | return b64_decode_ex(src, len, NULL); 24 | } 25 | 26 | unsigned char * 27 | b64_decode_ex (const char *src, size_t len, size_t *decsize) { 28 | int i = 0; 29 | int j = 0; 30 | int l = 0; 31 | size_t size = 0; 32 | b64_buffer_t decbuf; 33 | unsigned char buf[3]; 34 | unsigned char tmp[4]; 35 | 36 | // alloc 37 | if (b64_buf_malloc(&decbuf) == -1) { return NULL; } 38 | 39 | // parse until end of source 40 | while (len--) { 41 | // break if char is `=' or not base64 char 42 | if ('=' == src[j]) { break; } 43 | if (!(isalnum(src[j]) || '+' == src[j] || '/' == src[j])) { break; } 44 | 45 | // read up to 4 bytes at a time into `tmp' 46 | tmp[i++] = src[j++]; 47 | 48 | // if 4 bytes read then decode into `buf' 49 | if (4 == i) { 50 | // translate values in `tmp' from table 51 | for (i = 0; i < 4; ++i) { 52 | // find translation char in `b64_table' 53 | for (l = 0; l < 64; ++l) { 54 | if (tmp[i] == b64_table[l]) { 55 | tmp[i] = l; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | // decode 62 | buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4); 63 | buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2); 64 | buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3]; 65 | 66 | // write decoded buffer to `decbuf.ptr' 67 | if (b64_buf_realloc(&decbuf, size + 3) == -1) return NULL; 68 | for (i = 0; i < 3; ++i) { 69 | ((unsigned char*)decbuf.ptr)[size++] = buf[i]; 70 | } 71 | 72 | // reset 73 | i = 0; 74 | } 75 | } 76 | 77 | // remainder 78 | if (i > 0) { 79 | // fill `tmp' with `\0' at most 4 times 80 | for (j = i; j < 4; ++j) { 81 | tmp[j] = '\0'; 82 | } 83 | 84 | // translate remainder 85 | for (j = 0; j < 4; ++j) { 86 | // find translation char in `b64_table' 87 | for (l = 0; l < 64; ++l) { 88 | if (tmp[j] == b64_table[l]) { 89 | tmp[j] = l; 90 | break; 91 | } 92 | } 93 | } 94 | 95 | // decode remainder 96 | buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4); 97 | buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2); 98 | buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3]; 99 | 100 | // write remainer decoded buffer to `decbuf.ptr' 101 | if (b64_buf_realloc(&decbuf, size + (i - 1)) == -1) return NULL; 102 | for (j = 0; (j < i - 1); ++j) { 103 | ((unsigned char*)decbuf.ptr)[size++] = buf[j]; 104 | } 105 | } 106 | 107 | // Make sure we have enough space to add '\0' character at end. 108 | if (b64_buf_realloc(&decbuf, size + 1) == -1) return NULL; 109 | ((unsigned char*)decbuf.ptr)[size] = '\0'; 110 | 111 | // Return back the size of decoded string if demanded. 112 | if (decsize != NULL) { 113 | *decsize = size; 114 | } 115 | 116 | return (unsigned char*) decbuf.ptr; 117 | } 118 | -------------------------------------------------------------------------------- /decode.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * `decode.c' - b64 4 | * 5 | * copyright (c) 2014 joseph werle 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "b64.h" 12 | 13 | #ifdef b64_USE_CUSTOM_MALLOC 14 | extern void* b64_malloc(size_t); 15 | #endif 16 | 17 | #ifdef b64_USE_CUSTOM_REALLOC 18 | extern void* b64_realloc(void*, size_t); 19 | #endif 20 | 21 | unsigned char * 22 | b64_decode (const char *src, size_t len) { 23 | return b64_decode_ex(src, len, NULL); 24 | } 25 | 26 | unsigned char * 27 | b64_decode_ex (const char *src, size_t len, size_t *decsize) { 28 | int i = 0; 29 | int j = 0; 30 | int l = 0; 31 | size_t size = 0; 32 | unsigned char *dec = NULL; 33 | unsigned char buf[3]; 34 | unsigned char tmp[4]; 35 | 36 | // alloc 37 | dec = (unsigned char *) b64_malloc(1); 38 | if (NULL == dec) { return NULL; } 39 | 40 | // parse until end of source 41 | while (len--) { 42 | // break if char is `=' or not base64 char 43 | if ('=' == src[j]) { break; } 44 | if (!(isalnum(src[j]) || '+' == src[j] || '/' == src[j])) { break; } 45 | 46 | // read up to 4 bytes at a time into `tmp' 47 | tmp[i++] = src[j++]; 48 | 49 | // if 4 bytes read then decode into `buf' 50 | if (4 == i) { 51 | // translate values in `tmp' from table 52 | for (i = 0; i < 4; ++i) { 53 | // find translation char in `b64_table' 54 | for (l = 0; l < 64; ++l) { 55 | if (tmp[i] == b64_table[l]) { 56 | tmp[i] = l; 57 | break; 58 | } 59 | } 60 | } 61 | 62 | // decode 63 | buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4); 64 | buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2); 65 | buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3]; 66 | 67 | // write decoded buffer to `dec' 68 | dec = (unsigned char *) b64_realloc(dec, size + 3); 69 | if (dec != NULL){ 70 | for (i = 0; i < 3; ++i) { 71 | dec[size++] = buf[i]; 72 | } 73 | } else { 74 | return NULL; 75 | } 76 | 77 | // reset 78 | i = 0; 79 | } 80 | } 81 | 82 | // remainder 83 | if (i > 0) { 84 | // fill `tmp' with `\0' at most 4 times 85 | for (j = i; j < 4; ++j) { 86 | tmp[j] = '\0'; 87 | } 88 | 89 | // translate remainder 90 | for (j = 0; j < 4; ++j) { 91 | // find translation char in `b64_table' 92 | for (l = 0; l < 64; ++l) { 93 | if (tmp[j] == b64_table[l]) { 94 | tmp[j] = l; 95 | break; 96 | } 97 | } 98 | } 99 | 100 | // decode remainder 101 | buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4); 102 | buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2); 103 | buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3]; 104 | 105 | // write remainer decoded buffer to `dec' 106 | dec = (unsigned char *) b64_realloc(dec, size + (i - 1)); 107 | if (dec != NULL){ 108 | for (j = 0; (j < i - 1); ++j) { 109 | dec[size++] = buf[j]; 110 | } 111 | } else { 112 | return NULL; 113 | } 114 | } 115 | 116 | // Make sure we have enough space to add '\0' character at end. 117 | dec = (unsigned char *) b64_realloc(dec, size + 1); 118 | if (dec != NULL){ 119 | dec[size] = '\0'; 120 | } else { 121 | return NULL; 122 | } 123 | 124 | // Return back the size of decoded string if demanded. 125 | if (decsize != NULL) { 126 | *decsize = size; 127 | } 128 | 129 | return dec; 130 | } 131 | -------------------------------------------------------------------------------- /polipo/polipo.conf: -------------------------------------------------------------------------------- 1 | #logSyslog = true 2 | logFile = /var/log/polipo/polipo.log 3 | pidFile = /var/run/polipo/polipo.pid 4 | 5 | # for DNSProxy and CURL to be happy, bind the proxy interface on a LAN interface, not to 127.0.0.1 6 | proxyAddress = 192.168.3.93 7 | # 1080 CURL's default, otherwhise 8118 polipo default 8 | proxyPort = 1080 9 | 10 | # used only for resolving the remote's site DNS (i.e. fantuz.net, and not often as is cached too 11 | dnsNameServer = 192.168.1.1 12 | 13 | allowedClients = 127.0.0.1, 192.168.1.0/24, 192.168.2.0/24, 192.168.3.0/24 14 | allowedPorts = 1-65535 15 | 16 | # Uncomment this if there's only one user using this instance of Polipo: 17 | cacheIsShared = false 18 | 19 | #parentProxy = "squid.example.org:3128" 20 | #socksParentProxy = "localhost:1080" 21 | #socksProxyType = socks5 #socksProxyType = socks4a 22 | 23 | #objectHashTableSize integer 32768 Size of the object hash table (0 = auto). 24 | #objectHighMark integer 2048 High object count mark. 25 | objectHighMark=4096 26 | objectHashTableSize=0 27 | #publicObjectLowMark=16384 28 | 29 | diskCacheRoot = /home/polipo/ 30 | #localDocumentRoot = "/usr/share/polipo/www/doc/" 31 | daemonise=true 32 | disableIndexing = false 33 | disableServersList = false 34 | disableLocalInterface = false 35 | disableConfiguration = false 36 | dnsQueryIPv6=no 37 | 38 | maxDiskCacheEntrySize=4096 39 | diskCacheUnlinkTime=7200 40 | 41 | #just in case of redirects... 42 | dontCacheRedirects=false 43 | dontCacheCookies=false 44 | replyUnpipelineTime=8 45 | 46 | maxDiskEntries=65536 47 | maxNoModifiedAge=1800 48 | maxAge=7200 49 | maxExpiresAge=14400 50 | idleTime=900 51 | maxPipelineTrain=32 52 | #replyUnpipelineSize=4194304 53 | serverExpireTime=900 54 | bigBufferSize=65536 55 | 56 | #dnsUseGethostbyname = reluctantly 57 | dnsUseGethostbyname=false 58 | #dnsUseGethostbyname=true 59 | dnsNegativeTtl=60 60 | dnsGethostbynameTtl=60 61 | disableVia=false 62 | 63 | # censoredHeaders = from, accept-language 64 | # censorReferer = maybe 65 | #censoredHeaders = from,accept-language,x-pad,link 66 | # Uncomment this if you're paranoid. This will break a lot of sites, # though: 67 | # censoredHeaders = set-cookie, cookie, cookie2, from, accept-language 68 | #censoredHeaders = Set-Cookie, X-Powered-By, X-Turbo-Charged-By, Server, CF-RAY, Cookie, cookie2, From 69 | #, Accept-Language 70 | 71 | # Uncomment this if you want to use Poor Man's Multiplexing; increase 72 | # the sizes if you're on a fast line. They should each amount to a few 73 | # seconds' worth of transfer; if pmmSize is small, you'll want 74 | # pmmFirstSize to be larger. 75 | # Note that PMM is somewhat unreliable. 76 | # pmmFirstSize = 16384 77 | # pmmSize = 8192 78 | 79 | # Uncomment this if your user-agent does something reasonable with Warning headers (most don't): 80 | # relaxTransparency = maybe 81 | 82 | # Uncomment this if you never want to revalidate instances for which data is available (this is not a good idea): 83 | # relaxTransparency = maybe 84 | 85 | # Uncomment this if you have no network: 86 | # proxyOffline = no 87 | 88 | # Uncomment this if you want to avoid revalidating instances with a Vary header (this is not a good idea): 89 | # mindlesslyCacheVary = true 90 | 91 | chunkHighMark=512M 92 | chunkLowMark=128M 93 | chunkCriticalMark=64M 94 | logLevel = 0x07 95 | #logFacility = user 96 | logSyslog = false 97 | 98 | # Suggestions from Incognito configuration 99 | maxConnectionAge = 30s 100 | maxConnectionRequests=32 101 | pipelineAdditionalRequests=yes 102 | 103 | serverSlots=8 104 | serverMaxSlots=32 105 | #dontTrustVaryETag=maybe 106 | tunnelAllowedPorts=1-65535 107 | serverIdleTimeout=60s 108 | serverTimeout=10s 109 | clientTimeout=30s 110 | dnsMaxTimeout=5s 111 | 112 | #smallRequestTime 30s 113 | #diskCacheTruncateSize integer 1048576 Size to which on-disk objects are truncated. 114 | diskCacheTruncateTime=24h #Time after which on-disk objects are truncated. 115 | diskCacheUnlinkTime=24h #Time after which on-disk objects are removed. 116 | #diskCacheWriteoutOnClose integer 65536 Number of bytes to write out eagerly. 117 | #diskCacheDirectoryPermissions=0700 118 | #diskCacheFilePermissions=0600 119 | 120 | -------------------------------------------------------------------------------- /NGINX/sites-enabled-default: -------------------------------------------------------------------------------- 1 | # You may add here your 2 | # server { 3 | # ... 4 | # } 5 | # statements for each of your virtual hosts to this file 6 | 7 | ## 8 | # You should look at the following URL's in order to grasp a solid understanding 9 | # of Nginx configuration files in order to fully unleash the power of Nginx. 10 | # http://wiki.nginx.org/Pitfalls 11 | # http://wiki.nginx.org/QuickStart 12 | # http://wiki.nginx.org/Configuration 13 | # 14 | # Generally, you will want to move this file somewhere, and start with a clean 15 | # file but keep this around for reference. Or just disable in sites-enabled. 16 | # 17 | # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. 18 | ## 19 | 20 | # server { 21 | # listen 80; 22 | # server_name www.yourdoamin.com; 23 | # rewrite ^ https://$http_host$request_uri? permanent; # force redirect http to https 24 | # } 25 | server { 26 | listen 80 default_server; 27 | #listen [::]:80 default_server ipv6only=on; 28 | 29 | ## rewrite ^ https://$http_host$request_uri? permanent; # force redirect http to https 30 | 31 | root /usr/share/nginx/html; 32 | index index.html index.htm; 33 | 34 | listen 8888 ssl; 35 | 36 | server_name fantuz.mooo.com; 37 | ssl_certificate /srv/ssl/nginx.pem; 38 | ssl_certificate_key /srv/ssl/nginx.key; 39 | 40 | # Make site accessible from http://localhost/ 41 | server_name localhost; 42 | 43 | location ~ [^/]\.php(/|$) { 44 | fastcgi_split_path_info ^(.+?\.php)(/.*)$; 45 | if (!-f $document_root$fastcgi_script_name) { 46 | return 404; 47 | } 48 | 49 | fastcgi_pass unix:/var/run/php5-fpm.sock; 50 | #127.0.0.1:9000; 51 | fastcgi_index index.php; 52 | include fastcgi_params; 53 | } 54 | 55 | location / { 56 | # First attempt to serve request as file, then 57 | # as directory, then fall back to displaying a 404. 58 | try_files $uri $uri/ =404; 59 | # Uncomment to enable naxsi on this location 60 | # include /etc/nginx/naxsi.rules 61 | } 62 | 63 | location /nginx_status { 64 | stub_status on; 65 | access_log off; 66 | allow 127.0.0.1; 67 | deny all; 68 | } 69 | 70 | # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests 71 | #location /RequestDenied { 72 | # proxy_pass http://127.0.0.1:8080; 73 | #} 74 | 75 | #error_page 404 /404.html; 76 | 77 | # redirect server error pages to the static page /50x.html 78 | # 79 | #error_page 500 502 503 504 /50x.html; 80 | #location = /50x.html { 81 | # root /usr/share/nginx/html; 82 | #} 83 | 84 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 85 | # 86 | #location ~ \.php$ { 87 | # fastcgi_split_path_info ^(.+\.php)(/.+)$; 88 | # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 89 | # 90 | # # With php5-cgi alone: 91 | # fastcgi_pass 127.0.0.1:9000; 92 | # # With php5-fpm: 93 | # fastcgi_pass unix:/var/run/php5-fpm.sock; 94 | # fastcgi_index index.php; 95 | # include fastcgi_params; 96 | #} 97 | 98 | # deny access to .htaccess files, if Apache's document root 99 | # concurs with nginx's one 100 | # 101 | #location ~ /\.ht { 102 | # deny all; 103 | #} 104 | } 105 | 106 | 107 | # another virtual host using mix of IP-, name-, and port-based configuration 108 | # 109 | #server { 110 | # listen 8000; 111 | # listen somename:8080; 112 | # server_name somename alias another.alias; 113 | # root html; 114 | # index index.html index.htm; 115 | # 116 | # location / { 117 | # try_files $uri $uri/ =404; 118 | # } 119 | #} 120 | 121 | 122 | # HTTPS server 123 | # 124 | #server { 125 | # listen 443; 126 | # server_name localhost; 127 | # 128 | # root html; 129 | # index index.html index.htm; 130 | # 131 | # ssl on; 132 | # ssl_certificate cert.pem; 133 | # ssl_certificate_key cert.key; 134 | # 135 | # ssl_session_timeout 5m; 136 | # 137 | # ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; 138 | # ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; 139 | # ssl_prefer_server_ciphers on; 140 | # 141 | # location / { 142 | # try_files $uri $uri/ =404; 143 | # } 144 | #} 145 | -------------------------------------------------------------------------------- /DNS_types_info.txt: -------------------------------------------------------------------------------- 1 | 2 | #define NAMESERVER_PORT 53 3 | #define TFTP_PORT 69 4 | #define MAX_PORT 65535u 5 | 6 | #define IN6ADDRSZ 16 7 | #define INADDRSZ 4 8 | 9 | #define PACKETSZ 512 /* maximum packet size */ 10 | #define MAXDNAME 1025 /* maximum presentation domain name */ 11 | #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ 12 | #define MAXLABEL 63 /* maximum length of domain label */ 13 | 14 | #define NOERROR 0 /* no error */ 15 | #define FORMERR 1 /* format error */ 16 | #define SERVFAIL 2 /* server failure */ 17 | #define NXDOMAIN 3 /* non existent domain */ 18 | #define NOTIMP 4 /* not implemented */ 19 | #define REFUSED 5 /* query refused */ 20 | 21 | #define QUERY 0 /* opcode */ 22 | 23 | #define C_IN 1 /* the arpa internet */ 24 | #define C_CHAOS 3 /* for chaos net (MIT) */ 25 | #define C_HESIOD 4 /* hesiod */ 26 | #define C_ANY 255 /* wildcard match */ 27 | 28 | #define T_A 1 29 | #define T_NS 2 30 | #define T_MD 3 31 | #define T_MF 4 32 | #define T_CNAME 5 33 | #define T_SOA 6 34 | #define T_MB 7 35 | #define T_MG 8 36 | #define T_MR 9 37 | #define T_PTR 12 38 | #define T_MINFO 14 39 | #define T_MX 15 40 | #define T_TXT 16 41 | #define T_RP 17 42 | #define T_AFSDB 18 43 | #define T_RT 21 44 | #define T_SIG 24 45 | #define T_PX 26 46 | #define T_AAAA 28 47 | #define T_NXT 30 48 | #define T_SRV 33 49 | #define T_NAPTR 35 50 | #define T_KX 36 51 | #define T_DNAME 39 52 | #define T_OPT 41 53 | #define T_DS 43 54 | #define T_RRSIG 46 55 | #define T_NSEC 47 56 | #define T_DNSKEY 48 57 | #define T_NSEC3 50 58 | #define T_TKEY 249 59 | #define T_TSIG 250 60 | #define T_AXFR 252 61 | #define T_MAILB 253 62 | #define T_ANY 255 63 | 64 | #define EDNS0_OPTION_MAC 65001 /* dyndns.org temporary assignment */ 65 | #define EDNS0_OPTION_CLIENT_SUBNET 8 /* IANA */ 66 | #define EDNS0_OPTION_NOMDEVICEID 65073 /* Nominum temporary assignment */ 67 | #define EDNS0_OPTION_NOMCPEID 65074 /* Nominum temporary assignment */ 68 | 69 | struct dns_header { 70 | u16 id; 71 | u8 hb3,hb4; 72 | u16 qdcount,ancount,nscount,arcount; 73 | }; 74 | 75 | #define HB3_QR 0x80 /* Query */ 76 | #define HB3_OPCODE 0x78 77 | #define HB3_AA 0x04 /* Authoritative Answer */ 78 | #define HB3_TC 0x02 /* TrunCated */ 79 | #define HB3_RD 0x01 /* Recursion Desired */ 80 | 81 | #define HB4_RA 0x80 /* Recursion Available */ 82 | #define HB4_AD 0x20 /* Authenticated Data */ 83 | #define HB4_CD 0x10 /* Checking Disabled */ 84 | #define HB4_RCODE 0x0f 85 | 86 | ----DEBUG 87 | 88 | 89 | 3block x21digits = 63 90 | 91 | 63.63.63.xxx. << -- REMEMBER THE ADDED FINAL DOT !! 92 | total 256 93 | 192: ok 94 | problem between 192+(46-59) 95 | 96 | 100...114 : 45 97 | 100...11411511: 50 98 | 6117118119120 : 13 99 | . : final dot ! 100 | 101 | ... 114 45 -> OK 102 | ... 1141 46 -> ;; Question section mismatch: got XXX11511/A/RESERVED0 103 | ... 11411511 50 -> ;; Question section mismatch: got XXX11511/TYPE4140/CLASS16384 104 | 105 | ... 114115116 51 -> segfault !! (NO NETWORK RESPONSE...) 106 | ... 1141151161 52 -> segfault !! (NO NETWORK RESPONSE...) 107 | ... 11411511611 53 -> segfault !! (NO NETWORK RESPONSE...) 108 | 109 | ... 114115116117 54 -> ;; Question section mismatch: got XXX11511\000\016\001\000/RESERVED0/RESERVED0 110 | 111 | ... 1141151161171 55 -> ;; Question section mismatch: got XXX11511\000\016\001\000\000/RESERVED0/RESERVED0 112 | *** Error in `./dnsp': double free or corruption (!prev): 0x0000000001c869b0 *** 113 | 114 | ... 11411511611711 56 -> ;; Question section mismatch: got XXX11511\000\016\001\000\000\000/RESERVED0/CLASS125 115 | *** Error in `./dnsp': double free or corruption (!prev): 0x0000000001c869b0 *** 116 | 117 | ... 114115116117118 57 -> ;; Question section mismatch: got 118 | 119 | ... 1141151161171181 58 -> ;; Question section mismatch: got 120 | 121 | ... 11411511611711811 59 -> ;; Got bad packet: name too long, 269 bytes 122 | *** Error in `./dnsp': free(): invalid next size (normal): 0x0000000001c869b0 *** 123 | 124 | ///////////////////// LAST NETWORK RESPONSES, NO MORE FROM NOW ON 125 | 126 | ... 114115116117118119 60 -> segfault ! 127 | ... 1141151161171181191 61 -> segfault ! 128 | 129 | ... 1141151161171181191262 -> NOT ACCEPTED BY DIG !!! 130 | -------------------------------------------------------------------------------- /php-resolver/ns.php.noEtag: -------------------------------------------------------------------------------- 1 | get("foo"), $mc->get("bar") ); 4 | 5 | //Vary: Accept-Encoding, User-Agent 6 | // --- SET HEADERS AND DETECT CACHE CONTROL PRESENCE/EXPIRATION. 7 | session_cache_limiter('public'); //This stop php’s default no-cache 8 | session_cache_expire(14400); // Optional expiry time in minutes 9 | header("Connection: keep-alive"); 10 | header("Cache-control: public, max-age=14400, s-maxage=14400"); 11 | $host = rtrim($_GET["host"],'.'); 12 | 13 | //// USEFUL IF YOU NEED A PREMPTIVE HTTP CACHE 14 | //header("Location: http://" . $host); 15 | $lastModified=filemtime(__FILE__); 16 | //$etagFile = md5_file(__FILE__); 17 | 18 | //set last-modified header 19 | //header("Last-Modified: ". gmdate("D, d M Y H:i:s", $lastModified) ." GMT"); 20 | header("Last-Modified: ". gmdate("D, d M Y H:i:s", time()) ." GMT"); 21 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 22 | //set etag-header 23 | 24 | //header("Etag: $etagFile"); 25 | 26 | //get the HTTP_IF_MODIFIED_SINCE header when set 27 | $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); 28 | 29 | //get the HTTP_IF_NONE_MATCH header if set (Etag: unique file hash) 30 | $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); 31 | 32 | //check if page has changed. If not, send 304 and exit 33 | if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader==$etagFile ) 34 | { 35 | header("HTTP/1.1 304 Not Modified"); 36 | //exit; 37 | } 38 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 39 | //echo "Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"; 40 | 41 | if (isSet($_GET["host"]) && isSet($_GET["type"])) { 42 | $type = $_GET["type"]; 43 | //DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY. 44 | //print_r(checkdnsrr('8.8.8.8')); 45 | //$result = dns_get_record($host, DNS_ALL, $authns, $addtl); 46 | if ($_GET["type"] == "ALL"){ 47 | $result = dns_get_record($host, DNS_ALL, $authns, $addtl); 48 | print '

';
 49 |                 print_r($result);
 50 |                 print_r($authns);
 51 |                 print_r($addtl);
 52 |                 print '
'; 53 | } 54 | if ($_GET["type"] == "PTR"){ 55 | // $result = checkdnsrr($host); 56 | $result = dns_get_record($host, DNS_PTR, $authns, $addtl); 57 | //$result = checkdnsrr($host); 58 | print_r($result); 59 | print_r($authns); 60 | print_r($addtl); 61 | //$ccc = sizeof($result); 62 | //print $result[rand(0,$ccc-1)][mname]; 63 | } 64 | if ($_GET["type"] == "SOA"){ 65 | $result = dns_get_record($host, DNS_SOA, $authns, $addtl); 66 | $ccc = sizeof($result); 67 | print $result[rand(0,$ccc-1)][mname]; 68 | } 69 | if ($_GET["type"] == "SPF" || $_GET["type"] == "TXT"){ 70 | $res = dns_get_record($host, DNS_TXT, $authns, $addtl) or print '0.0.0.0'; 71 | 72 | $ccc = sizeof($res); 73 | $result = $res[rand(0,$ccc-1)][txt]; 74 | print $result . '
'; 75 | 76 | $ddd = sizeof($res[entries]); 77 | 78 | $rx = $res[rand(0,$ddd-1)][entries][0]; 79 | print_r($rx); 80 | print '
'; 81 | 82 | $rm = $res[rand(0,$ddd-1)][entries][1]; 83 | print_r($rm); 84 | print '
'; 85 | 86 | $rv = $res[rand(0,$ddd-1)][entries][2]; 87 | print_r($rv); 88 | print '
'; 89 | 90 | //print_r($result); 91 | //print_r($authns); 92 | //print_r($addtl); 93 | } 94 | if ($_GET["type"] == "AAAA"){ 95 | $res = dns_get_record($host, DNS_AAAA, $authns, $addtl) or print '0.0.0.0'; 96 | $ccc = sizeof($res); 97 | $result = $res[rand(0,$ccc-1)][ipv6]; 98 | print_r($result); 99 | } 100 | if ($_GET["type"] == "MX"){ 101 | $res = (dns_get_record($host, DNS_MX, $authns, $addtl)) or print '0.0.0.0'; 102 | $ccc = sizeof($res); 103 | $result = $res[rand(0,$ccc-1)][target]; 104 | print $result; 105 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 106 | //$ddd = sizeof($r2); 107 | //print $r2[rand(0,$ddd-1)][ip]; 108 | } 109 | if ($_GET["type"] == "NS"){ 110 | $result = dns_get_record($host, DNS_NS, $authns, $addtl); 111 | $ccc = sizeof($result); 112 | print $result[rand(0,$ccc-1)][target]; 113 | } 114 | if ($_GET["type"] == "A"){ 115 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 116 | $ccc = sizeof($result); 117 | print $result[rand(0,$ccc-1)][ip]; 118 | //print_r(array_keys($result[0])); 119 | } 120 | if ($_GET["type"] == "CNAME"){ 121 | $res = dns_get_record($host, DNS_CNAME, $authns, $addtl) or print '0.0.0.0'; 122 | $ccc = sizeof($res); 123 | $result = $res[rand(0,$ccc-1)][target]; 124 | print $result; 125 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 126 | //echo $result[0][class]; 127 | //echo $result[0][ttl]; 128 | } 129 | } else { 130 | if (isSet($_GET["host"])) { 131 | $host = rtrim($_GET["host"]); 132 | //$result = dns_get_record($host, DNS_NS, $authns, $addtl); 133 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 134 | $ccc = sizeof($result); 135 | print $result[rand(0,$ccc-1)][ip]; 136 | } else { 137 | print '0.0.0.0'; 138 | } 139 | } 140 | // if ($ip != $host) die ($ip); 141 | // $ip = gethostbyname($host); 142 | // $mx = getmxrr($host); 143 | 144 | ?> 145 | -------------------------------------------------------------------------------- /php-resolver/nslookup_googlecloud.php: -------------------------------------------------------------------------------- 1 | \n"; 19 | //set etag-header 20 | header("Etag: $etagFile"); 21 | 22 | //get the HTTP_IF_MODIFIED_SINCE header when set 23 | $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); 24 | 25 | //get the HTTP_IF_NONE_MATCH header if set (Etag: unique file hash) 26 | $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); 27 | 28 | //check if page has changed. If not, send 304 and exit 29 | if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader==$etagFile ) 30 | { 31 | header("HTTP/1.1 304 Not Modified"); 32 | //exit; 33 | } 34 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 35 | //echo "Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"; 36 | 37 | if (isSet($_GET["host"]) && isSet($_GET["type"])) { 38 | $type = $_GET["type"]; 39 | //DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY. 40 | //print_r(checkdnsrr('8.8.8.8')); 41 | //$result = dns_get_record($host, DNS_ALL, $authns, $addtl); 42 | if ($_GET["type"] == "ALL"){ 43 | $result = dns_get_record($host, DNS_ALL, $authns, $addtl); 44 | print '
';
 45 |                 print_r($result);
 46 |                 print_r($authns);
 47 |                 print_r($addtl);
 48 |                 print '
'; 49 | } 50 | if ($_GET["type"] == "PTR"){ 51 | // $result = checkdnsrr($host); 52 | $result = dns_get_record($host, DNS_PTR, $authns, $addtl); 53 | //$result = checkdnsrr($host); 54 | print_r($result); 55 | print_r($authns); 56 | print_r($addtl); 57 | //$ccc = sizeof($result); 58 | //print $result[rand(0,$ccc-1)]["mname"]; 59 | } 60 | if ($_GET["type"] == "SOA"){ 61 | $result = dns_get_record($host, DNS_SOA, $authns, $addtl); 62 | $ccc = sizeof($result); 63 | print $result[rand(0,$ccc-1)]["mname"]; 64 | } 65 | if ($_GET["type"] == "SPF" || $_GET["type"] == "TXT"){ 66 | $res = dns_get_record($host, DNS_TXT, $authns, $addtl) or print '0.0.0.0'; 67 | 68 | $ccc = sizeof($res); 69 | $result = $res[rand(0,$ccc-1)]["txt"]; 70 | print $result . '
'; 71 | 72 | $ddd = sizeof($res["entries"]); 73 | 74 | $rx = $res[rand(0,$ddd-1)]["entries"][0]; 75 | print_r($rx); 76 | print '
'; 77 | 78 | $rm = $res[rand(0,$ddd-1)]["entries"][1]; 79 | print_r($rm); 80 | print '
'; 81 | 82 | $rv = $res[rand(0,$ddd-1)]["entries"][2]; 83 | print_r($rv); 84 | print '
'; 85 | 86 | //print_r($result); 87 | //print_r($authns); 88 | //print_r($addtl); 89 | } 90 | if ($_GET["type"] == "AAAA"){ 91 | $res = dns_get_record($host, DNS_AAAA, $authns, $addtl) or print '0.0.0.0'; 92 | $ccc = sizeof($res); 93 | $result = $res[rand(0,$ccc-1)]["ipv6"]; 94 | print_r($result); 95 | } 96 | if ($_GET["type"] == "MX"){ 97 | $res = (dns_get_record($host, DNS_MX, $authns, $addtl)) or print '0.0.0.0'; 98 | $ccc = sizeof($res); 99 | $result = $res[rand(0,$ccc-1)]["target"]; 100 | print $result; 101 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 102 | //$ddd = sizeof($r2); 103 | //print $r2[rand(0,$ddd-1)][ip]; 104 | } 105 | if ($_GET["type"] == "NS"){ 106 | $res = dns_get_record($host, DNS_NS, $authns, $addtl); 107 | $ccc = sizeof($res); 108 | //print $res[rand(0,$ccc-1)][target]; 109 | //print_r($res[rand(0,$ccc-1)][target]); 110 | $result = $res[rand(0,$ccc-1)]["target"]; 111 | if ($result) { 112 | echo "$result\r\n\t" ; 113 | } else { 114 | echo "0.0.0.0\r\n\t"; 115 | } 116 | //print_r($result); 117 | } 118 | if ($_GET["type"] == "A"){ 119 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 120 | $ccc = sizeof($result); 121 | print $result[rand(0,$ccc-1)]["ip"]; 122 | //print $result[rand(0,$ccc-1)][ipv4]; 123 | //print_r(array_keys($result[0])); 124 | } 125 | if ($_GET["type"] == "CNAME"){ 126 | $res = dns_get_record($host, DNS_CNAME, $authns, $addtl) or print '0.0.0.0'; 127 | $ccc = sizeof($res); 128 | //print $res[rand(0,$ccc-1)][target]; 129 | //print_r($res[rand(0,$ccc-1)][target]); 130 | $result = $res[rand(0,$ccc-1)]["target"]; 131 | if ($result) { 132 | echo "$result\r\n\t" ; 133 | } else { 134 | echo "0.0.0.0\r\n\t"; 135 | } 136 | //echo nl2br(); 137 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 138 | //echo $result[0][class]; 139 | //echo $result[0][ttl]; 140 | } 141 | } else { 142 | if (isSet($_GET["host"])) { 143 | $host = rtrim($_GET["host"]); 144 | //$result = dns_get_record($host, DNS_NS, $authns, $addtl); 145 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 146 | $ccc = sizeof($result); 147 | print $result[rand(0,$ccc-1)]["ip"]; 148 | } else { 149 | print '0.0.0.0'; 150 | } 151 | } 152 | // if ($ip != $host) die ($ip); 153 | // $ip = gethostbyname($host); 154 | // $mx = getmxrr($host); 155 | ?> 156 | -------------------------------------------------------------------------------- /php-resolver/nslookup.php: -------------------------------------------------------------------------------- 1 | get("foo"), $mc->get("bar") ); 4 | 5 | //Vary: Accept-Encoding, User-Agent 6 | // --- SET HEADERS AND DETECT CACHE CONTROL PRESENCE/EXPIRATION. 7 | session_cache_limiter('public'); //This stop php’s default no-cache 8 | session_cache_expire(14400); // Optional expiry time in minutes 9 | header("Content-type: text/plain;charset=UTF-8"); 10 | header("Connection: keep-alive"); 11 | header("Cache-control: public, max-age=14400, s-maxage=14400"); 12 | $host = rtrim($_GET["host"],'.'); 13 | 14 | $lastModified=filemtime(__FILE__); 15 | $etagFile = md5_file(__FILE__); 16 | 17 | //set last-modified header 18 | //header("Last-Modified: ". gmdate("D, d M Y H:i:s", $lastModified) ." GMT"); 19 | header("Last-Modified: ". gmdate("D, d M Y H:i:s", time()) ." GMT"); 20 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 21 | //set etag-header 22 | header("Etag: $etagFile"); 23 | 24 | //get the HTTP_IF_MODIFIED_SINCE header when set 25 | $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); 26 | 27 | //get the HTTP_IF_NONE_MATCH header if set (Etag: unique file hash) 28 | $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); 29 | 30 | //check if page has changed. If not, send 304 and exit 31 | if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader==$etagFile ) 32 | { 33 | header("HTTP/1.1 304 Not Modified"); 34 | //exit; 35 | } 36 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 37 | //echo "Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"; 38 | 39 | // BEWARE, THE ANSWER SHALL CONTAIN \r\n or not, depending on PHP host version 55 vs. 7 (print function difference, minification etc) 40 | if (isSet($_GET["host"]) && isSet($_GET["type"])) { 41 | $type = $_GET["type"]; 42 | //DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY. 43 | //print_r(checkdnsrr('8.8.8.8')); 44 | //$result = dns_get_record($host, DNS_ALL, $authns, $addtl); 45 | if ($_GET["type"] == "ALL"){ 46 | $result = dns_get_record($host, DNS_ALL, $authns, $addtl); 47 | print '
';
 48 |                 print_r($result);
 49 |                 print_r($authns);
 50 |                 print_r($addtl);
 51 |                 print '
'; 52 | } 53 | if ($_GET["type"] == "PTR"){ 54 | // $result = checkdnsrr($host); 55 | $result = dns_get_record($host, DNS_PTR, $authns, $addtl); 56 | //$result = checkdnsrr($host); 57 | print_r($result); 58 | print_r($authns); 59 | print_r($addtl); 60 | //$ccc = sizeof($result); 61 | //print $result[rand(0,$ccc-1)][mname]; 62 | } 63 | if ($_GET["type"] == "SOA"){ 64 | $result = dns_get_record($host, DNS_SOA, $authns, $addtl); 65 | $ccc = sizeof($result); 66 | print $result[rand(0,$ccc-1)]["mname"]; 67 | } 68 | if ($_GET["type"] == "SPF" || $_GET["type"] == "TXT"){ 69 | $res = dns_get_record($host, DNS_TXT, $authns, $addtl) or print '0.0.0.0'; 70 | 71 | $ccc = sizeof($res); 72 | $result = $res[rand(0,$ccc-1)]["txt"]; 73 | print $result . '
'; 74 | 75 | $ddd = sizeof($res[entries]); 76 | 77 | $rx = $res[rand(0,$ddd-1)]["entries"][0]; 78 | print_r($rx); 79 | print '
'; 80 | 81 | $rm = $res[rand(0,$ddd-1)]["entries"][1]; 82 | print_r($rm); 83 | print '
'; 84 | 85 | $rv = $res[rand(0,$ddd-1)]["entries"][2]; 86 | print_r($rv); 87 | print '
'; 88 | 89 | //print_r($result); 90 | //print_r($authns); 91 | //print_r($addtl); 92 | } 93 | if ($_GET["type"] == "AAAA"){ 94 | $res = dns_get_record($host, DNS_AAAA, $authns, $addtl) or print '0.0.0.0'; 95 | $ccc = sizeof($res); 96 | $result = $res[rand(0,$ccc-1)]["ipv6"]; 97 | print_r($result); 98 | } 99 | if ($_GET["type"] == "MX"){ 100 | $res = (dns_get_record($host, DNS_MX, $authns, $addtl)) or print '0.0.0.0'; 101 | $ccc = sizeof($res); 102 | $result = $res[rand(0,$ccc-1)]["target"]; 103 | print $result; 104 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 105 | //$ddd = sizeof($r2); 106 | //print $r2[rand(0,$ddd-1)]["ip"]; 107 | } 108 | if ($_GET["type"] == "NS"){ 109 | $res = dns_get_record($host, DNS_NS, $authns, $addtl); 110 | $ccc = sizeof($res); 111 | print $res[rand(0,$ccc-1)]["target"]; 112 | //$result = $res[rand(0,$ccc-1)]["target"]; 113 | //echo "$result\r\n"; 114 | } 115 | if ($_GET["type"] == "A"){ 116 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 117 | $ccc = sizeof($result); 118 | print $result[rand(0,$ccc-1)]["ip"]; 119 | //print_r(array_keys($result[0])); 120 | /* 121 | // POOR-MAN PREMPTIVE HTTP CACHE. Implement only if needed to cache HTTP browser request (i.e. enterprise proxy makes sense, single user no sense) 122 | //this will force the CURL to follow location, as instructed into dnsp.c 123 | //as result, the page would then be in cache BEFORE the user can complete his first request (towards local proxy) 124 | header("Location: http://" . $host); 125 | */ 126 | } 127 | if ($_GET["type"] == "CNAME"){ 128 | $res = dns_get_record($host, DNS_CNAME, $authns, $addtl) or print '0.0.0.0'; 129 | $ccc = sizeof($res); 130 | $result = $res[rand(0,$ccc-1)]["target"]; 131 | print $result; 132 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 133 | //echo $result[0]["class"]; 134 | //echo $result[0]["ttl"]; 135 | } 136 | } else { 137 | if (isSet($_GET["host"])) { 138 | $host = rtrim($_GET["host"]); 139 | //$result = dns_get_record($host, DNS_NS, $authns, $addtl); 140 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 141 | $ccc = sizeof($result); 142 | print $result[rand(0,$ccc-1)]["ip"]; 143 | } else { 144 | print '0.0.0.0'; 145 | } 146 | } 147 | // if ($ip != $host) die ($ip); 148 | // $ip = gethostbyname($host); 149 | // $mx = getmxrr($host); 150 | 151 | print ("\r\n"); 152 | ?> 153 | -------------------------------------------------------------------------------- /php-resolver/nslookup-doh.php: -------------------------------------------------------------------------------- 1 | get("foo"), $mc->get("bar") ); 4 | 5 | //Vary: Accept-Encoding, User-Agent 6 | // --- SET HEADERS AND DETECT CACHE CONTROL PRESENCE/EXPIRATION. 7 | session_cache_limiter('public'); //This stop php’s default no-cache 8 | session_cache_expire(5); // Optional expiry time in minutes 9 | //header("Content-type: text/plain;charset=UTF-8"); 10 | header("content-type: application/dns-udpwireformat"); 11 | /* 12 | content-length = 64 13 | cache-control = max-age=128 14 | 15 | <64 bytes represented by the following hex encoding> 16 | 00 00 81 80 00 01 00 01 00 00 00 00 03 77 77 77 17 | 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 18 | 01 03 77 77 77 07 65 78 61 6d 70 6c 65 03 63 6f 19 | 6d 00 00 01 00 01 00 00 00 80 00 04 C0 00 02 01 20 | */ 21 | header("Connection: keep-alive"); 22 | //header("Cache-control: public, max-age=14400, s-maxage=14400"); 23 | $host = rtrim($_GET["host"],'.'); 24 | 25 | $lastModified=filemtime(__FILE__); 26 | $etagFile = md5_file(__FILE__); 27 | 28 | //set last-modified header 29 | //header("Last-Modified: ". gmdate("D, d M Y H:i:s", $lastModified) ." GMT"); 30 | header("Last-Modified: ". gmdate("D, d M Y H:i:s", time()) ." GMT"); 31 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 32 | //set etag-header 33 | header("Etag: $etagFile"); 34 | 35 | //get the HTTP_IF_MODIFIED_SINCE header when set 36 | $ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false); 37 | 38 | //get the HTTP_IF_NONE_MATCH header if set (Etag: unique file hash) 39 | $etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false); 40 | 41 | //check if page has changed. If not, send 304 and exit 42 | if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader==$etagFile ) 43 | { 44 | header("HTTP/1.1 304 Not Modified"); 45 | //exit; 46 | } 47 | //echo "This page was last modified: ".date("d.m.Y H:i:s",time())."
\n"; 48 | //echo "Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT"; 49 | 50 | // BEWARE, THE ANSWER SHALL CONTAIN \r\n or not, depending on PHP host version 55 vs. 7 (print function difference, minification etc) 51 | if (isSet($_GET["host"]) && isSet($_GET["type"])) { 52 | $type = $_GET["type"]; 53 | //DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY. 54 | //print_r(checkdnsrr('8.8.8.8')); 55 | //$result = dns_get_record($host, DNS_ALL, $authns, $addtl); 56 | if ($_GET["type"] == "ALL"){ 57 | $result = dns_get_record($host, DNS_ALL, $authns, $addtl); 58 | print '
';
 59 |                 print_r($result);
 60 |                 print_r($authns);
 61 |                 print_r($addtl);
 62 |                 print '
'; 63 | } 64 | if ($_GET["type"] == "PTR"){ 65 | // $result = checkdnsrr($host); 66 | $result = dns_get_record($host, DNS_PTR, $authns, $addtl); 67 | //$result = checkdnsrr($host); 68 | print_r($result); 69 | print_r($authns); 70 | print_r($addtl); 71 | //$ccc = sizeof($result); 72 | //print $result[rand(0,$ccc-1)][mname]; 73 | } 74 | if ($_GET["type"] == "SOA"){ 75 | $result = dns_get_record($host, DNS_SOA, $authns, $addtl); 76 | $ccc = sizeof($result); 77 | print $result[rand(0,$ccc-1)][mname]; 78 | } 79 | if ($_GET["type"] == "SPF" || $_GET["type"] == "TXT"){ 80 | $res = dns_get_record($host, DNS_TXT, $authns, $addtl) or print '0.0.0.0'; 81 | 82 | $ccc = sizeof($res); 83 | $result = $res[rand(0,$ccc-1)]["txt"]; 84 | print $result . '
'; 85 | 86 | $ddd = sizeof($res[entries]); 87 | 88 | $rx = $res[rand(0,$ddd-1)]["entries"][0]; 89 | print_r($rx); 90 | print '
'; 91 | 92 | $rm = $res[rand(0,$ddd-1)]["entries"][1]; 93 | print_r($rm); 94 | print '
'; 95 | 96 | $rv = $res[rand(0,$ddd-1)]["entries"][2]; 97 | print_r($rv); 98 | print '
'; 99 | 100 | //print_r($result); 101 | //print_r($authns); 102 | //print_r($addtl); 103 | } 104 | if ($_GET["type"] == "AAAA"){ 105 | $res = dns_get_record($host, DNS_AAAA, $authns, $addtl) or print '0.0.0.0'; 106 | $ccc = sizeof($res); 107 | $result = $res[rand(0,$ccc-1)]["ipv6"]; 108 | print_r($result); 109 | } 110 | if ($_GET["type"] == "MX"){ 111 | $res = (dns_get_record($host, DNS_MX, $authns, $addtl)) or print '0.0.0.0'; 112 | $ccc = sizeof($res); 113 | $result = $res[rand(0,$ccc-1)]["target"]; 114 | print $result; 115 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 116 | //$ddd = sizeof($r2); 117 | //print $r2[rand(0,$ddd-1)][ip]; 118 | } 119 | if ($_GET["type"] == "NS"){ 120 | $res = dns_get_record($host, DNS_NS, $authns, $addtl); 121 | $ccc = sizeof($res); 122 | print $res[rand(0,$ccc-1)]["target"]; 123 | //$result = $res[rand(0,$ccc-1)][target]; 124 | //echo "$result\r\n"; 125 | } 126 | if ($_GET["type"] == "A"){ 127 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 128 | $ccc = sizeof($result); 129 | $key = rand(0,$ccc-1); 130 | //header("Cache-control: public, max-age=".$result[rand(0,$ccc-1)][ttl].", s-maxage=14400"); 131 | header("Cache-control: public, max-age=".$result[$key][ttl].", s-maxage=".$result[$key][ttl]); 132 | print $result[$key]["ip"]; 133 | //$ccc = sizeof($result); 134 | //print $result[rand(0,$ccc-1)][ttl]; 135 | 136 | //print_r(array_keys($result[0])); 137 | /* 138 | // POOR-MAN PREMPTIVE HTTP CACHE. Implement only if needed to cache HTTP browser request (i.e. enterprise proxy makes sense, single user no sense) 139 | //this will force the CURL to follow location, as instructed into dnsp.c 140 | //as result, the page would then be in cache BEFORE the user can complete his first request (towards local proxy) 141 | header("Location: http://" . $host); 142 | */ 143 | } 144 | if ($_GET["type"] == "CNAME"){ 145 | $res = dns_get_record($host, DNS_CNAME, $authns, $addtl) or print '0.0.0.0'; 146 | $ccc = sizeof($res); 147 | $result = $res[rand(0,$ccc-1)]["target"]; 148 | print $result; 149 | //$r2 = dns_get_record($h2, DNS_A, $authns, $addtl); 150 | //echo $result[0][class]; 151 | //echo $result[0][ttl]; 152 | } 153 | } else { 154 | if (isSet($_GET["host"])) { 155 | $host = rtrim($_GET["host"]); 156 | //$result = dns_get_record($host, DNS_NS, $authns, $addtl); 157 | $result = (dns_get_record($host, DNS_A, $authns, $addtl)) or print '0.0.0.0'; 158 | $ccc = sizeof($result); 159 | $key = rand(0,$ccc-1); 160 | //header("Cache-control: public, max-age=".$result[rand(0,$ccc-1)][ttl].", s-maxage=14400"); 161 | header("Cache-control: public, max-age=".$result[$key][ttl].", s-maxage=".$result[$key][ttl]); 162 | 163 | print $result[$key]["ip"]; 164 | 165 | } else { 166 | print '0.0.0.0'; 167 | } 168 | } 169 | // if ($ip != $host) die ($ip); 170 | // $ip = gethostbyname($host); 171 | // $mx = getmxrr($host); 172 | 173 | print ("\r\n"); 174 | ?> 175 | -------------------------------------------------------------------------------- /CURL_OPTS: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | CURLINFO_ACTIVESOCKET.3 CURLINFO_APPCONNECT_TIME.3 CURLINFO_CERTINFO.3 CURLINFO_CONDITION_UNMET.3 4 | CURLINFO_CONNECT_TIME.3 CURLINFO_CONTENT_LENGTH_DOWNLOAD.3 CURLINFO_CONTENT_LENGTH_DOWNLOAD_T.3 5 | CURLINFO_CONTENT_LENGTH_UPLOAD.3 CURLINFO_CONTENT_LENGTH_UPLOAD_T.3 CURLINFO_CONTENT_TYPE.3 6 | CURLINFO_COOKIELIST.3 CURLINFO_EFFECTIVE_URL.3 CURLINFO_FILETIME.3 CURLINFO_FILETIME_T.3 7 | CURLINFO_FTP_ENTRY_PATH.3 CURLINFO_HEADER_SIZE.3 CURLINFO_HTTPAUTH_AVAIL.3 CURLINFO_HTTP_CONNECTCODE.3 8 | CURLINFO_HTTP_VERSION.3 CURLINFO_LASTSOCKET.3 CURLINFO_LOCAL_IP.3 CURLINFO_LOCAL_PORT.3 CURLINFO_NAMELOOKUP_TIME.3 CURLINFO_NUM_CONNECTS.3 CURLINFO_OS_ERRNO.3 CURLINFO_PRETRANSFER_TIME.3 CURLINFO_PRIMARY_IP.3 CURLINFO_PRIMARY_PORT.3 CURLINFO_PRIVATE.3 CURLINFO_PROTOCOL.3 CURLINFO_PROXYAUTH_AVAIL.3 CURLINFO_PROXY_SSL_VERIFYRESULT.3 CURLINFO_REDIRECT_COUNT.3 CURLINFO_REDIRECT_TIME.3 CURLINFO_REDIRECT_URL.3 CURLINFO_REQUEST_SIZE.3 CURLINFO_RESPONSE_CODE.3 CURLINFO_RTSP_CLIENT_CSEQ.3 CURLINFO_RTSP_CSEQ_RECV.3 CURLINFO_RTSP_SERVER_CSEQ.3 '/usr/local/share/man/man3' 9 | /usr/bin/install -c -m 644 CURLINFO_RTSP_SESSION_ID.3 CURLINFO_SCHEME.3 CURLINFO_SIZE_DOWNLOAD.3 CURLINFO_SIZE_DOWNLOAD_T.3 CURLINFO_SIZE_UPLOAD.3 CURLINFO_SIZE_UPLOAD_T.3 CURLINFO_SPEED_DOWNLOAD.3 CURLINFO_SPEED_DOWNLOAD_T.3 CURLINFO_SPEED_UPLOAD.3 CURLINFO_SPEED_UPLOAD_T.3 CURLINFO_SSL_ENGINES.3 CURLINFO_SSL_VERIFYRESULT.3 CURLINFO_STARTTRANSFER_TIME.3 CURLINFO_TLS_SESSION.3 CURLINFO_TLS_SSL_PTR.3 CURLINFO_TOTAL_TIME.3 CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE.3 CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE.3 CURLMOPT_MAXCONNECTS.3 CURLMOPT_MAX_HOST_CONNECTIONS.3 CURLMOPT_MAX_PIPELINE_LENGTH.3 CURLMOPT_MAX_TOTAL_CONNECTIONS.3 CURLMOPT_PIPELINING.3 CURLMOPT_PIPELINING_SERVER_BL.3 CURLMOPT_PIPELINING_SITE_BL.3 CURLMOPT_PUSHDATA.3 CURLMOPT_PUSHFUNCTION.3 CURLMOPT_SOCKETDATA.3 CURLMOPT_SOCKETFUNCTION.3 CURLMOPT_TIMERDATA.3 CURLMOPT_TIMERFUNCTION.3 CURLOPT_ABSTRACT_UNIX_SOCKET.3 CURLOPT_ACCEPTTIMEOUT_MS.3 CURLOPT_ACCEPT_ENCODING.3 CURLOPT_ADDRESS_SCOPE.3 CURLOPT_APPEND.3 CURLOPT_AUTOREFERER.3 CURLOPT_BUFFERSIZE.3 CURLOPT_CAINFO.3 CURLOPT_CAPATH.3 '/usr/local/share/man/man3' 10 | /usr/bin/install -c -m 644 CURLOPT_CERTINFO.3 CURLOPT_CHUNK_BGN_FUNCTION.3 CURLOPT_CHUNK_DATA.3 CURLOPT_CHUNK_END_FUNCTION.3 CURLOPT_CLOSESOCKETDATA.3 CURLOPT_CLOSESOCKETFUNCTION.3 CURLOPT_CONNECTTIMEOUT.3 CURLOPT_CONNECTTIMEOUT_MS.3 CURLOPT_CONNECT_ONLY.3 CURLOPT_CONNECT_TO.3 CURLOPT_CONV_FROM_NETWORK_FUNCTION.3 CURLOPT_CONV_FROM_UTF8_FUNCTION.3 CURLOPT_CONV_TO_NETWORK_FUNCTION.3 CURLOPT_COOKIE.3 CURLOPT_COOKIEFILE.3 CURLOPT_COOKIEJAR.3 CURLOPT_COOKIELIST.3 CURLOPT_COOKIESESSION.3 CURLOPT_COPYPOSTFIELDS.3 CURLOPT_CRLF.3 CURLOPT_CRLFILE.3 CURLOPT_CUSTOMREQUEST.3 CURLOPT_DEBUGDATA.3 CURLOPT_DEBUGFUNCTION.3 CURLOPT_DEFAULT_PROTOCOL.3 CURLOPT_DIRLISTONLY.3 CURLOPT_DNS_CACHE_TIMEOUT.3 CURLOPT_DNS_INTERFACE.3 CURLOPT_DNS_LOCAL_IP4.3 CURLOPT_DNS_LOCAL_IP6.3 CURLOPT_DNS_SERVERS.3 CURLOPT_DNS_USE_GLOBAL_CACHE.3 CURLOPT_EGDSOCKET.3 CURLOPT_ERRORBUFFER.3 CURLOPT_EXPECT_100_TIMEOUT_MS.3 CURLOPT_FAILONERROR.3 CURLOPT_FILETIME.3 CURLOPT_FNMATCH_DATA.3 CURLOPT_FNMATCH_FUNCTION.3 CURLOPT_FOLLOWLOCATION.3 '/usr/local/share/man/man3' 11 | /usr/bin/install -c -m 644 CURLOPT_FORBID_REUSE.3 CURLOPT_FRESH_CONNECT.3 CURLOPT_FTPPORT.3 CURLOPT_FTPSSLAUTH.3 CURLOPT_FTP_ACCOUNT.3 CURLOPT_FTP_ALTERNATIVE_TO_USER.3 CURLOPT_FTP_CREATE_MISSING_DIRS.3 CURLOPT_FTP_FILEMETHOD.3 CURLOPT_FTP_RESPONSE_TIMEOUT.3 CURLOPT_FTP_SKIP_PASV_IP.3 CURLOPT_FTP_SSL_CCC.3 CURLOPT_FTP_USE_EPRT.3 CURLOPT_FTP_USE_EPSV.3 CURLOPT_FTP_USE_PRET.3 CURLOPT_GSSAPI_DELEGATION.3 CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.3 CURLOPT_HEADER.3 CURLOPT_HEADERDATA.3 CURLOPT_HEADERFUNCTION.3 CURLOPT_HEADEROPT.3 CURLOPT_HTTP200ALIASES.3 CURLOPT_HTTPAUTH.3 CURLOPT_HTTPGET.3 CURLOPT_HTTPHEADER.3 CURLOPT_HTTPPOST.3 CURLOPT_HTTPPROXYTUNNEL.3 CURLOPT_HTTP_CONTENT_DECODING.3 CURLOPT_HTTP_TRANSFER_DECODING.3 CURLOPT_HTTP_VERSION.3 CURLOPT_IGNORE_CONTENT_LENGTH.3 CURLOPT_INFILESIZE.3 CURLOPT_INFILESIZE_LARGE.3 CURLOPT_INTERFACE.3 CURLOPT_INTERLEAVEDATA.3 CURLOPT_INTERLEAVEFUNCTION.3 CURLOPT_IOCTLDATA.3 CURLOPT_IOCTLFUNCTION.3 CURLOPT_IPRESOLVE.3 CURLOPT_ISSUERCERT.3 CURLOPT_KEEP_SENDING_ON_ERROR.3 '/usr/local/share/man/man3' 12 | /usr/bin/install -c -m 644 CURLOPT_KEYPASSWD.3 CURLOPT_KRBLEVEL.3 CURLOPT_LOCALPORT.3 CURLOPT_LOCALPORTRANGE.3 CURLOPT_LOGIN_OPTIONS.3 CURLOPT_LOW_SPEED_LIMIT.3 CURLOPT_LOW_SPEED_TIME.3 CURLOPT_MAIL_AUTH.3 CURLOPT_MAIL_FROM.3 CURLOPT_MAIL_RCPT.3 CURLOPT_MAXCONNECTS.3 CURLOPT_MAXFILESIZE.3 CURLOPT_MAXFILESIZE_LARGE.3 CURLOPT_MAXREDIRS.3 CURLOPT_MAX_RECV_SPEED_LARGE.3 CURLOPT_MAX_SEND_SPEED_LARGE.3 CURLOPT_MIMEPOST.3 CURLOPT_NETRC.3 CURLOPT_NETRC_FILE.3 CURLOPT_NEW_DIRECTORY_PERMS.3 CURLOPT_NEW_FILE_PERMS.3 CURLOPT_NOBODY.3 CURLOPT_NOPROGRESS.3 CURLOPT_NOPROXY.3 CURLOPT_NOSIGNAL.3 CURLOPT_OPENSOCKETDATA.3 CURLOPT_OPENSOCKETFUNCTION.3 CURLOPT_PASSWORD.3 CURLOPT_PATH_AS_IS.3 CURLOPT_PINNEDPUBLICKEY.3 CURLOPT_PIPEWAIT.3 CURLOPT_PORT.3 CURLOPT_POST.3 CURLOPT_POSTFIELDS.3 CURLOPT_POSTFIELDSIZE.3 CURLOPT_POSTFIELDSIZE_LARGE.3 CURLOPT_POSTQUOTE.3 CURLOPT_POSTREDIR.3 CURLOPT_PREQUOTE.3 CURLOPT_PRE_PROXY.3 '/usr/local/share/man/man3' 13 | /usr/bin/install -c -m 644 CURLOPT_PRIVATE.3 CURLOPT_PROGRESSDATA.3 CURLOPT_PROGRESSFUNCTION.3 CURLOPT_PROTOCOLS.3 CURLOPT_PROXY.3 CURLOPT_PROXYAUTH.3 CURLOPT_PROXYHEADER.3 CURLOPT_PROXYPASSWORD.3 CURLOPT_PROXYPORT.3 CURLOPT_PROXYTYPE.3 CURLOPT_PROXYUSERNAME.3 CURLOPT_PROXYUSERPWD.3 CURLOPT_PROXY_CAINFO.3 CURLOPT_PROXY_CAPATH.3 CURLOPT_PROXY_CRLFILE.3 CURLOPT_PROXY_KEYPASSWD.3 CURLOPT_PROXY_PINNEDPUBLICKEY.3 CURLOPT_PROXY_SERVICE_NAME.3 CURLOPT_PROXY_SSLCERT.3 CURLOPT_PROXY_SSLCERTTYPE.3 CURLOPT_PROXY_SSLKEY.3 CURLOPT_PROXY_SSLKEYTYPE.3 CURLOPT_PROXY_SSLVERSION.3 CURLOPT_PROXY_SSL_CIPHER_LIST.3 CURLOPT_PROXY_SSL_OPTIONS.3 CURLOPT_PROXY_SSL_VERIFYHOST.3 CURLOPT_PROXY_SSL_VERIFYPEER.3 CURLOPT_PROXY_TLSAUTH_PASSWORD.3 CURLOPT_PROXY_TLSAUTH_TYPE.3 CURLOPT_PROXY_TLSAUTH_USERNAME.3 CURLOPT_PROXY_TRANSFER_MODE.3 CURLOPT_PUT.3 CURLOPT_QUOTE.3 CURLOPT_RANDOM_FILE.3 CURLOPT_RANGE.3 CURLOPT_READDATA.3 CURLOPT_READFUNCTION.3 CURLOPT_REDIR_PROTOCOLS.3 CURLOPT_REFERER.3 CURLOPT_REQUEST_TARGET.3 '/usr/local/share/man/man3' 14 | /usr/bin/install -c -m 644 CURLOPT_RESOLVE.3 CURLOPT_RESOLVER_START_DATA.3 CURLOPT_RESOLVER_START_FUNCTION.3 CURLOPT_RESUME_FROM.3 CURLOPT_RESUME_FROM_LARGE.3 CURLOPT_RTSP_CLIENT_CSEQ.3 CURLOPT_RTSP_REQUEST.3 CURLOPT_RTSP_SERVER_CSEQ.3 CURLOPT_RTSP_SESSION_ID.3 CURLOPT_RTSP_STREAM_URI.3 CURLOPT_RTSP_TRANSPORT.3 CURLOPT_SASL_IR.3 CURLOPT_SEEKDATA.3 CURLOPT_SEEKFUNCTION.3 CURLOPT_SERVICE_NAME.3 CURLOPT_SHARE.3 CURLOPT_SOCKOPTDATA.3 CURLOPT_SOCKOPTFUNCTION.3 CURLOPT_SOCKS5_AUTH.3 CURLOPT_SOCKS5_GSSAPI_NEC.3 CURLOPT_SOCKS5_GSSAPI_SERVICE.3 CURLOPT_SSH_AUTH_TYPES.3 CURLOPT_SSH_COMPRESSION.3 CURLOPT_SSH_HOST_PUBLIC_KEY_MD5.3 CURLOPT_SSH_KEYDATA.3 CURLOPT_SSH_KEYFUNCTION.3 CURLOPT_SSH_KNOWNHOSTS.3 CURLOPT_SSH_PRIVATE_KEYFILE.3 CURLOPT_SSH_PUBLIC_KEYFILE.3 CURLOPT_SSLCERT.3 CURLOPT_SSLCERTTYPE.3 CURLOPT_SSLENGINE.3 CURLOPT_SSLENGINE_DEFAULT.3 CURLOPT_SSLKEY.3 CURLOPT_SSLKEYTYPE.3 CURLOPT_SSLVERSION.3 CURLOPT_SSL_CIPHER_LIST.3 CURLOPT_SSL_CTX_DATA.3 CURLOPT_SSL_CTX_FUNCTION.3 CURLOPT_SSL_ENABLE_ALPN.3 '/usr/local/share/man/man3' 15 | /usr/bin/install -c -m 644 CURLOPT_SSL_ENABLE_NPN.3 CURLOPT_SSL_FALSESTART.3 CURLOPT_SSL_OPTIONS.3 CURLOPT_SSL_SESSIONID_CACHE.3 CURLOPT_SSL_VERIFYHOST.3 CURLOPT_SSL_VERIFYPEER.3 CURLOPT_SSL_VERIFYSTATUS.3 CURLOPT_STDERR.3 CURLOPT_STREAM_DEPENDS.3 CURLOPT_STREAM_DEPENDS_E.3 CURLOPT_STREAM_WEIGHT.3 CURLOPT_SUPPRESS_CONNECT_HEADERS.3 CURLOPT_TCP_FASTOPEN.3 CURLOPT_TCP_KEEPALIVE.3 CURLOPT_TCP_KEEPIDLE.3 CURLOPT_TCP_KEEPINTVL.3 CURLOPT_TCP_NODELAY.3 CURLOPT_TELNETOPTIONS.3 CURLOPT_TFTP_BLKSIZE.3 CURLOPT_TFTP_NO_OPTIONS.3 CURLOPT_TIMECONDITION.3 CURLOPT_TIMEOUT.3 CURLOPT_TIMEOUT_MS.3 CURLOPT_TIMEVALUE.3 CURLOPT_TIMEVALUE_LARGE.3 CURLOPT_TLSAUTH_PASSWORD.3 CURLOPT_TLSAUTH_TYPE.3 CURLOPT_TLSAUTH_USERNAME.3 CURLOPT_TRANSFERTEXT.3 CURLOPT_TRANSFER_ENCODING.3 CURLOPT_UNIX_SOCKET_PATH.3 CURLOPT_UNRESTRICTED_AUTH.3 CURLOPT_UPLOAD.3 CURLOPT_URL.3 CURLOPT_USERAGENT.3 CURLOPT_USERNAME.3 CURLOPT_USERPWD.3 CURLOPT_USE_SSL.3 CURLOPT_VERBOSE.3 CURLOPT_WILDCARDMATCH.3 '/usr/local/share/man/man3' 16 | /usr/bin/install -c -m 644 CURLOPT_WRITEDATA.3 CURLOPT_WRITEFUNCTION.3 CURLOPT_XFERINFODATA.3 CURLOPT_XFERINFOFUNCTION.3 CURLOPT_XOAUTH2_BEARER.3 '/usr/local/share/man/man3' 17 | 18 | */ 19 | 20 | -------------------------------------------------------------------------------- /curl-multiplex-dld.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * _ _ ____ _ 3 | * Project ___| | | | _ \| | 4 | * / __| | | | |_) | | 5 | * | (__| |_| | _ <| |___ 6 | * \___|\___/|_| \_\_____| 7 | * 8 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 9 | * 10 | * This software is licensed as described in the file COPYING, which 11 | * you should have received as part of this distribution. The terms 12 | * are also available at https://curl.haxx.se/docs/copyright.html. 13 | * 14 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 | * copies of the Software, and permit persons to whom the Software is 16 | * furnished to do so, under the terms of the COPYING file. 17 | * 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 | * KIND, either express or implied. 20 | * 21 | ***************************************************************************/ 22 | /* 23 | * Multiplexed HTTP/2 downloads over a single connection 24 | * 25 | */ 26 | #include 27 | #include 28 | #include 29 | 30 | /* somewhat unix-specific */ 31 | #include 32 | #include 33 | 34 | /* curl stuff */ 35 | #include 36 | 37 | #ifndef CURLPIPE_MULTIPLEX 38 | /* This little trick will just make sure that we don't enable pipelining for 39 | libcurls old enough to not have this symbol. It is _not_ defined to zero in 40 | a recent libcurl header. */ 41 | #define CURLPIPE_MULTIPLEX 0 42 | #endif 43 | 44 | #define NUM_HANDLES 1000 45 | 46 | static void *curl_hnd[NUM_HANDLES]; 47 | static int num_transfers; 48 | 49 | /* a handle to number lookup, highly ineffective when we do many 50 | transfers... */ 51 | static int hnd2num(CURL *hnd) 52 | { 53 | int i; 54 | for(i = 0; i< num_transfers; i++) { 55 | if(curl_hnd[i] == hnd) 56 | return i; 57 | } 58 | return 0; /* weird, but just a fail-safe */ 59 | } 60 | 61 | static 62 | void dump(const char *text, int num, unsigned char *ptr, size_t size, 63 | char nohex) 64 | { 65 | size_t i; 66 | size_t c; 67 | 68 | unsigned int width = 0x10; 69 | 70 | if(nohex) 71 | /* without the hex output, we can fit more on screen */ 72 | width = 0x40; 73 | 74 | fprintf(stderr, "%d %s, %ld bytes (0x%lx)\n", 75 | num, text, (long)size, (long)size); 76 | 77 | for(i = 0; i= 0x20) && (ptr[i + c]<0x80)?ptr[i + c]:'.'); 99 | /* check again for 0D0A, to avoid an extra \n if it's at width */ 100 | if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D && 101 | ptr[i + c + 2] == 0x0A) { 102 | i += (c + 3 - width); 103 | break; 104 | } 105 | } 106 | fputc('\n', stderr); /* newline */ 107 | } 108 | } 109 | 110 | static 111 | int my_trace(CURL *handle, curl_infotype type, 112 | char *data, size_t size, 113 | void *userp) 114 | { 115 | const char *text; 116 | int num = hnd2num(handle); 117 | (void)handle; /* prevent compiler warning */ 118 | (void)userp; 119 | switch(type) { 120 | case CURLINFO_TEXT: 121 | fprintf(stderr, "== %d Info: %s", num, data); 122 | /* FALLTHROUGH */ 123 | default: /* in case a new one is introduced to shock us */ 124 | return 0; 125 | 126 | case CURLINFO_HEADER_OUT: 127 | text = "=> Send header"; 128 | break; 129 | case CURLINFO_DATA_OUT: 130 | text = "=> Send data"; 131 | break; 132 | case CURLINFO_SSL_DATA_OUT: 133 | text = "=> Send SSL data"; 134 | break; 135 | case CURLINFO_HEADER_IN: 136 | text = "<= Recv header"; 137 | break; 138 | case CURLINFO_DATA_IN: 139 | text = "<= Recv data"; 140 | break; 141 | case CURLINFO_SSL_DATA_IN: 142 | text = "<= Recv SSL data"; 143 | break; 144 | } 145 | 146 | dump(text, num, (unsigned char *)data, size, 1); 147 | return 0; 148 | } 149 | 150 | static void setup(CURL *hnd, int num) 151 | { 152 | FILE *out; 153 | char filename[128]; 154 | 155 | snprintf(filename, 128, "dl-%d", num); 156 | 157 | out = fopen(filename, "wb"); 158 | 159 | /* write to this file */ 160 | curl_easy_setopt(hnd, CURLOPT_WRITEDATA, out); 161 | 162 | /* set the same URL */ 163 | curl_easy_setopt(hnd, CURLOPT_URL, "https://nghttp2.org/"); 164 | 165 | /* please be verbose */ 166 | curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); 167 | curl_easy_setopt(hnd, CURLOPT_DEBUGFUNCTION, my_trace); 168 | 169 | /* HTTP/2 please */ 170 | curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); 171 | 172 | /* we use a self-signed test server, skip verification during debugging */ 173 | curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L); 174 | curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L); 175 | 176 | #if (CURLPIPE_MULTIPLEX > 0) 177 | /* wait for pipe connection to confirm */ 178 | curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L); 179 | #endif 180 | 181 | curl_hnd[num] = hnd; 182 | } 183 | 184 | /* 185 | * Simply download two files over HTTP/2, using the same physical connection! 186 | */ 187 | int main(int argc, char **argv) 188 | { 189 | CURL *easy[NUM_HANDLES]; 190 | CURLM *multi_handle; 191 | int i; 192 | int still_running; /* keep number of running handles */ 193 | 194 | if(argc > 1) 195 | /* if given a number, do that many transfers */ 196 | num_transfers = atoi(argv[1]); 197 | 198 | if(!num_transfers || (num_transfers > NUM_HANDLES)) 199 | num_transfers = 3; /* a suitable low default */ 200 | 201 | /* init a multi stack */ 202 | multi_handle = curl_multi_init(); 203 | 204 | for(i = 0; i= 0) { 240 | timeout.tv_sec = curl_timeo / 1000; 241 | if(timeout.tv_sec > 1) 242 | timeout.tv_sec = 1; 243 | else 244 | timeout.tv_usec = (curl_timeo % 1000) * 1000; 245 | } 246 | 247 | /* get file descriptors from the transfers */ 248 | mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); 249 | 250 | if(mc != CURLM_OK) { 251 | fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); 252 | break; 253 | } 254 | 255 | /* On success the value of maxfd is guaranteed to be >= -1. We call 256 | select(maxfd + 1, ...); specially in case of (maxfd == -1) there are 257 | no fds ready yet so we call select(0, ...) --or Sleep() on Windows-- 258 | to sleep 100ms, which is the minimum suggested value in the 259 | curl_multi_fdset() doc. */ 260 | 261 | if(maxfd == -1) { 262 | #ifdef _WIN32 263 | Sleep(100); 264 | rc = 0; 265 | #else 266 | /* Portable sleep for platforms other than Windows. */ 267 | struct timeval wait = { 0, 100 * 1000 }; /* 100ms */ 268 | rc = select(0, NULL, NULL, NULL, &wait); 269 | #endif 270 | } 271 | else { 272 | /* Note that on some platforms 'timeout' may be modified by select(). 273 | If you need access to the original value save a copy beforehand. */ 274 | rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 275 | } 276 | 277 | switch(rc) { 278 | case -1: 279 | /* select error */ 280 | break; 281 | case 0: 282 | default: 283 | /* timeout or readable/writable sockets */ 284 | curl_multi_perform(multi_handle, &still_running); 285 | break; 286 | } 287 | } while(still_running); 288 | 289 | curl_multi_cleanup(multi_handle); 290 | 291 | for(i = 0; i 4 | * CC-BY-4.0 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include "librb64u.h" 10 | 11 | 12 | static const char base64url_etab[64] = 13 | { 14 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 15 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 16 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 17 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 18 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 19 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 20 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 21 | '4', '5', '6', '7', '8', '9', '-', '_'}; 22 | 23 | 24 | static const char base64url_dtab[256] = { 25 | '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 26 | '\x01', '\x00', '\x00', '\x00', '\x5c', '\x08', '\x00', '\x00', '\xc0', '\x99', '\x76', '\xb7', '\xe0', '\x96', '\x76', '\xb7', 27 | '\x45', '\x82', '\x04', '\x08', '\x8c', '\x1a', '\x61', '\xb7', '\xc8', '\x81', '\x04', '\x08', '\x01', '\x3e', '\x00', '\x00', 28 | '\x34', '\x35', '\x36', '\x37', '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x78', '\xb7', '\xe0', '\xe3', '\xff', '\xbf', 29 | '\xcf', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', 30 | '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\xb7', '\x01', '\x00', '\x00', '\x3f', 31 | '\x00', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27', '\x28', 32 | '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f', '\x30', '\x31', '\x32', '\x33', '\x00', '\x00', '\x00', '\x00', '\x00', 33 | '\xd0', '\xe3', '\xff', '\xbf', '\xc4', '\xe3', '\xff', '\xbf', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 34 | '\x00', '\x00', '\x00', '\x00', '\x10', '\xe4', '\xff', '\xbf', '\x68', '\x66', '\x78', '\xb7', '\x45', '\x82', '\x04', '\x08', 35 | '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 36 | '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 37 | '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 38 | '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', 39 | '\x66', '\xf5', '\xff', '\xbf', '\x1e', '\x31', '\x67', '\xb7', '\x79', '\x0b', '\x72', '\xb7', '\xbc', '\x96', '\x04', '\x08', 40 | '\xb8', '\xe3', '\xff', '\xbf', '\xec', '\x82', '\x04', '\x08', '\xf4', '\xbf', '\x75', '\xb7', '\xbc', '\x96', '\x04', '\x08'}; 41 | 42 | 43 | 44 | int base64url_encode(char *dest, const size_t maxlen, const char *src, const size_t len, size_t *dlen) 45 | { 46 | int r; 47 | size_t i, 48 | lost = 0, 49 | dsz = 0; 50 | b64ue_t s; 51 | if (NULL != dlen) *dlen = 0; 52 | base64url_encode_reset(&s); 53 | for (i = 0; i < len; i++) 54 | { 55 | r = base64url_encode_ingest(&s, src[i]); 56 | if (r < 0) { 57 | if (NULL != dlen) *dlen = dsz; 58 | return -1; 59 | } 60 | if (r > 0) { 61 | if (maxlen > dsz) 62 | dest[dsz++] = base64url_encode_getc(&s); 63 | else 64 | lost++; 65 | } 66 | } 67 | for (;;) { 68 | r = base64url_encode_finish(&s); 69 | if (r < 0) return -1; 70 | if (r > 0) { 71 | if (maxlen > dsz) 72 | dest[dsz++] = base64url_encode_getc(&s); 73 | else 74 | lost++; 75 | } 76 | else 77 | break; 78 | } 79 | if (NULL != dlen) *dlen = dsz; 80 | if (lost > 0) { 81 | /*no support for %z in C90 and no need for output anyway */ 82 | /*fprintf(stderr, "base64url_encode: dropped %zu bytes to avoid output buffer overrun.", lost);*/ 83 | return -1; 84 | } 85 | return 0; 86 | } 87 | 88 | 89 | int base64url_decode(char *dest, const size_t maxlen, const char *src, const size_t len, size_t *dlen) 90 | { 91 | int r; 92 | size_t i, 93 | lost = 0, 94 | dsz = 0; 95 | b64ud_t s; 96 | if (NULL != dlen) *dlen = 0; 97 | base64url_decode_reset(&s); 98 | for (i = 0; i < len; i++) 99 | { 100 | r = base64url_decode_ingest(&s, src[i]); 101 | if (r < 0) { 102 | if (NULL != dlen) *dlen = dsz; 103 | return -1; 104 | } 105 | if (r > 0) { 106 | if (maxlen > dsz) 107 | dest[dsz++] = base64url_decode_getc(&s); 108 | else 109 | lost++; 110 | } 111 | } 112 | for (;;) { 113 | r = base64url_decode_finish(&s); 114 | if (r < 0) { 115 | if (NULL != dlen) *dlen = dsz; 116 | return -1; 117 | } 118 | if (r > 0) { 119 | if (maxlen > dsz) 120 | dest[dsz++] = base64url_decode_getc(&s); 121 | else 122 | lost++; 123 | } 124 | else 125 | break; 126 | } 127 | if (NULL != dlen) *dlen = dsz; 128 | if (lost > 0) { 129 | /*no support for %z in C90 and no need for output anyway */ 130 | /*fprintf(stderr, "base64url_decode: dropped %zu bytes to avoid output buffer overrun.", lost);*/ 131 | return -1; 132 | } 133 | return 0; 134 | } 135 | 136 | 137 | /* re-entrant methods *********************************************************/ 138 | 139 | 140 | void base64url_encode_reset(b64ue_t *state) 141 | { 142 | state->f = 1; /* unnamed state flag */ 143 | state->k = 4; /* triple shift */ 144 | state->t = 0; /* triple */ 145 | state->i = 0; /* write index */ 146 | state->j = 0; /* read index */ 147 | state->q = 0; /* total bytes read */ 148 | state->n = 0; /* bytes in buffer, b */ 149 | state->b[0] = 0; /* read buffer */ 150 | state->b[1] = 0; 151 | state->b[2] = 0; 152 | state->b[3] = 0; 153 | } 154 | 155 | 156 | int base64url_encode_getc(b64ue_t *state) 157 | { 158 | int r = state->r; 159 | state->r = 0; 160 | return r; 161 | } 162 | 163 | 164 | int base64url_encode_ingest(b64ue_t *state, char c) 165 | { 166 | size_t i, j, n; 167 | uint32_t t, k; 168 | 169 | i = state->i; 170 | state->b[i] = c; 171 | state->i = (i > RB64U_RXBUFSZ-2) ? 0 : i + 1; 172 | state->n++; 173 | state->q++; 174 | 175 | if (state->f > 0) { 176 | if (state->n < 3) 177 | return 0; 178 | state->f = 0; 179 | } 180 | 181 | t = state->t; 182 | k = state->k; 183 | if (k > 3) { 184 | k = 3; 185 | n = state->n; 186 | assert (n > 2); 187 | j = state->j; 188 | t = (state->b[j] << 0x10); 189 | state->b[j] = 0; 190 | j = (j > RB64U_RXBUFSZ-2) ? 0 : j + 1; 191 | t += (state->b[j] << 0x08); 192 | state->b[j] = 0; 193 | j = (j > RB64U_RXBUFSZ-2) ? 0 : j + 1; 194 | t += (state->b[j]); 195 | state->b[j] = 0; 196 | j = (j > RB64U_RXBUFSZ-2) ? 0 : j + 1; 197 | state->j = j; 198 | state->t = t; 199 | state->n = n - 3; 200 | } 201 | 202 | state->r = base64url_etab[(t >> k * 6) & 0x3f]; 203 | state->k = k - 1; 204 | return 1; 205 | } 206 | 207 | 208 | int base64url_encode_finish(b64ue_t *state) 209 | { 210 | size_t j, n; 211 | uint32_t t, k; 212 | uint8_t m; 213 | 214 | n = state->n; 215 | 216 | if (state->f > 0) { 217 | if (n < 1) 218 | return 0; 219 | state->f = 0; 220 | } 221 | 222 | t = state->t; 223 | k = state->k; 224 | if (k > 3) { 225 | if (n < 1) 226 | return 0; 227 | k = 3; 228 | j = state->j; 229 | t = (state->b[j] << 0x10); 230 | state->b[j] = 0; 231 | j = (j > RB64U_RXBUFSZ-2) ? 0 : j + 1; 232 | t += (state->b[j] << 0x08); 233 | state->b[j] = 0; 234 | j = (j > RB64U_RXBUFSZ-2) ? 0 : j + 1; 235 | t += (state->b[j]); 236 | state->b[j] = 0; 237 | j = (j > RB64U_RXBUFSZ-2) ? 0 : j + 1; 238 | state->j = j; 239 | state->t = t; 240 | state->n = 0; 241 | } 242 | 243 | if (state->n == 0) { 244 | m = state->q % 3; 245 | if (((m == 1) && (k <= 1)) || 246 | ((m == 2) && (k < 1))) 247 | return 0; 248 | } 249 | 250 | state->r = base64url_etab[(t >> k * 6) & 0x3f]; 251 | state->k = k - 1; 252 | return 1; 253 | } 254 | 255 | 256 | void base64url_decode_reset(b64ud_t *state) 257 | { 258 | state->f = 0; /* unnamed state flag */ 259 | state->s = 0; /* buffer state */ 260 | state->k = 3; /* output state */ 261 | state->q = 0; /* runoff quota */ 262 | state->r = 0; /* next return char */ 263 | state->a = 0; /* buffer */ 264 | state->b = 0; /* buffer */ 265 | state->c = 0; /* buffer */ 266 | } 267 | 268 | 269 | int base64url_decode_getc(b64ud_t *state) 270 | { 271 | int r = state->r; 272 | state->r = 0; 273 | return r; 274 | } 275 | 276 | 277 | int base64url_decode_ingest(b64ud_t *state, unsigned char c) 278 | { 279 | switch (state->s) 280 | { 281 | case 0: 282 | state->a = base64url_dtab[c]; 283 | state->r = (state->t >> 1 * 8) & 0xff; 284 | state->k = 0; 285 | state->q = 3; 286 | state->s = 1; 287 | return state->f; 288 | 289 | case 1: 290 | state->b = base64url_dtab[c]; 291 | state->r = (state->t >> 0 * 8) & 0xff; 292 | state->k = 2; 293 | state->q = 1; 294 | state->s = 2; 295 | return state->f; 296 | 297 | case 2: 298 | state->c = base64url_dtab[c]; 299 | state->q = 2; 300 | state->s = 3; 301 | return 0; 302 | 303 | case 3: 304 | state->f = 1; 305 | state->t = (state->a << 3 * 6) 306 | + (state->b << 2 * 6) 307 | + (state->c << 1 * 6) 308 | + (base64url_dtab[c] << 0 * 6); 309 | state->a = 0; 310 | state->b = 0; 311 | state->c = 0; 312 | state->r = (state->t >> 2 * 8) & 0xff; 313 | state->k = 1; 314 | state->q = 3; 315 | state->s = 0; 316 | return 1; 317 | } 318 | assert(0); 319 | } 320 | 321 | 322 | int base64url_decode_finish(b64ud_t *state) 323 | { 324 | uint8_t k; 325 | k = state->k; 326 | 327 | if (k > 2) 328 | return 0; 329 | 330 | if (k > 1) 331 | state->t = (state->a << 3 * 6) 332 | + (state->b << 2 * 6) 333 | + (state->c << 1 * 6); 334 | 335 | if (state->q-- == 0) 336 | return 0; 337 | 338 | state->r = (state->t >> k * 8) & 0xff; 339 | state->k = k - 1; 340 | return 1; 341 | } 342 | -------------------------------------------------------------------------------- /arduino/dnsp-arduino.ino: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright: (c) SAEKI Yoshiyasu, Massimiliano Fantuzzi HB3YOE 4 | Analog inputs attached to pins A0 through A5 (optional) 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */ 12 | #define DELAY 0 13 | #define MAXCONN 1 14 | #define UDP_DATAGRAM_SIZE 256 15 | #define DNSREWRITE 256 16 | #define HTTP_RESPONSE_SIZE 256 17 | #define URL_SIZE 256 18 | #define VERSION "1.5" 19 | #define DNS_MODE_ANSWER 1 20 | #define DNS_MODE_ERROR 2 21 | #define DEFAULT_LOCAL_PORT 53 22 | #define DEFAULT_WEB_PORT 80 23 | #define NUMT 4 24 | #define NUM_THREADS 4 25 | #define NUM_HANDLER_THREADS 1 26 | 27 | #define MISO 50 //num 10 on nano 28 | #define MOSI 51 //num 11 on nano 29 | #define SCLK 52 //num 12 on nano 30 | #define CLK 52 31 | 32 | //#define SS_PIN 53 //from MFRC522 33 | //#define SPI_SS 53 // from RFM12B 34 | //#define RST_LCD 53 35 | //#define CS 8 //6 36 | #define SS 53 37 | //#define SPI_SS_PIN 53 //from Robot_Control/SdCard.h 38 | 39 | /* last 2018 mod, test to see if working 40 | #define SD_CS 6 41 | #define SPI_SS 53 42 | #define SPI_CS 8 43 | */ 44 | 45 | //#define ETHERNET_SHIELD_SPI_CS 8; 46 | 47 | #define PACKET_MAX_SIZE 512 48 | 49 | byte macOne[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC }; 50 | byte macTwo[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 51 | 52 | //byte ip[] = {192, 168, 254, 100}; 53 | //byte resIp[] = {192, 168, 3, 241}; 54 | //byte resIp[] = {0x08,0x08,0x08,0x08}; 55 | byte resIp[4] = {94,130,94,9}; 56 | //byte resIp[4] = {8,8,8,8}; 57 | 58 | unsigned int listenPort = 53; 59 | byte remoteIp[4]; 60 | unsigned int remotePort; 61 | 62 | char requestBuffer[PACKET_MAX_SIZE]; 63 | char responseBuffer[PACKET_MAX_SIZE]; 64 | 65 | IPAddress ipOne(192,168,1,241); 66 | IPAddress ipTwo(192,168,3,241); 67 | IPAddress dnsOne(192,168,1,1); 68 | IPAddress dnsTwo(192,168,3,1); 69 | IPAddress gatewayOne(192, 168,1,1); 70 | IPAddress gatewayTwo(192, 168,3,1); 71 | IPAddress subnet(255,255,255,0); 72 | 73 | //IPAddress ip(192, 168, 1, 241); 74 | EthernetUDP Udp; 75 | EthernetUDP UdpOne; 76 | EthernetUDP UdpTwo; 77 | 78 | EthernetServer serverOne(80); 79 | EthernetServer serverTwo(80); 80 | //EthernetServer server(80); 81 | 82 | boolean currentLineIsBlank = true; 83 | char c; 84 | 85 | const uint8_t SD_CHIP_SELECT = 5; 86 | const int8_t DISABLE_CHIP_SELECT = 6; 87 | 88 | //#define ETH_CS_PIN 8 //from enc28j60_tutorial-master/_18_SDWebserver/_18_SDWebserver.ino 89 | //#define ethCSpin 8 90 | 91 | void setup() 92 | { 93 | //Serial.begin(9600); 94 | /* 95 | while (!Serial) { 96 | ; 97 | } 98 | */ 99 | 100 | /* 101 | if (DISABLE_CHIP_SELECT < 0) { 102 | //cout << F( 103 | // "\nAssuming the SD is the only SPI device.\n" 104 | // "Edit DISABLE_CHIP_SELECT to disable another device.\n"); 105 | } else { 106 | //cout << F("\nDisabling SPI device on pin "); 107 | //cout << int(DISABLE_CHIP_SELECT) << endl; 108 | pinMode(DISABLE_CHIP_SELECT, OUTPUT); 109 | digitalWrite(DISABLE_CHIP_SELECT, HIGH); 110 | } 111 | */ 112 | 113 | pinMode(8,OUTPUT); 114 | digitalWrite(8,HIGH); 115 | 116 | pinMode(7,OUTPUT); 117 | digitalWrite(7,HIGH); 118 | 119 | startOne(); 120 | delay(100); 121 | startTwo(); 122 | delay(100); 123 | 124 | //Serial.println(F("Ready")); 125 | } 126 | 127 | void loop() { 128 | 129 | checkServerOne(); 130 | checkServerTwo(); 131 | 132 | /* 133 | // listen for incoming clients 134 | EthernetClient client = server.available(); 135 | if (client) { 136 | Serial.println("new client"); 137 | // an http request ends with a blank line 138 | boolean currentLineIsBlank = true; 139 | while (client.connected()) { 140 | if (client.available()) { 141 | char c = client.read(); 142 | Serial.write(c); 143 | // if you've gotten to the end of the line (received a newline 144 | // character) and the line is blank, the http request has ended, 145 | // so you can send a reply 146 | if (c == '\n' && currentLineIsBlank) { 147 | // send a standard http response header 148 | client.println("HTTP/1.1 200 OK"); 149 | client.println("Content-Type: text/html"); 150 | client.println("Connection: close"); // the connection will be closed after completion of the response 151 | client.println("Refresh: 5"); // refresh the page automatically every 5 sec 152 | client.println(); 153 | client.println(""); 154 | client.println(""); 155 | // output the value of each analog input pin 156 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 157 | int sensorReading = analogRead(analogChannel); 158 | client.print("analog input "); 159 | client.print(analogChannel); 160 | client.print(" is "); 161 | client.print(sensorReading); 162 | client.println("
"); 163 | } 164 | client.println(""); 165 | break; 166 | } 167 | if (c == '\n') { 168 | // you're starting a new line 169 | currentLineIsBlank = true; 170 | } else if (c != '\r') { 171 | // you've gotten a character on the current line 172 | currentLineIsBlank = false; 173 | } 174 | } 175 | } 176 | // give the web browser time to receive the data 177 | delay(1); 178 | // close the connection: 179 | client.stop(); 180 | Serial.println("client disconnected"); 181 | } 182 | */ 183 | 184 | int requestSize = UdpTwo.parsePacket(); //int requestSize = Udp.available(); 185 | 186 | if(requestSize) { 187 | //Serial.print("Received packet of size "); 188 | //Serial.println(requestSize); 189 | //Serial.print("From "); 190 | 191 | IPAddress remote = UdpTwo.remoteIP(); 192 | 193 | /* 194 | for (int i = 0; i < 4; i++) { 195 | Serial.print(remote[i], DEC); 196 | if (i < 3) { 197 | Serial.print("."); 198 | } 199 | } 200 | Serial.print(", port "); 201 | Serial.println(UdpTwo.remotePort()); 202 | */ 203 | 204 | //Udp.readPacket(requestBuffer, PACKET_MAX_SIZE, remoteIp, remotePort); 205 | UdpTwo.read(requestBuffer, PACKET_MAX_SIZE); 206 | 207 | int type = (requestBuffer[2] >> 3) & 15; 208 | if(type == 0) { // nomal request 209 | int ini = 12; 210 | int lon = requestBuffer[ini]; 211 | char domain[64]; 212 | int i = 0; 213 | while(lon != 0) { 214 | for(int j = 0; j < lon; j++) { 215 | domain[i++] = requestBuffer[ini + j + 1]; 216 | } 217 | domain[i++] = '.'; 218 | ini += lon + 1; 219 | lon = requestBuffer[ini]; 220 | } 221 | domain[i] = '\0'; 222 | 223 | //Serial.println(domain); 224 | 225 | /* 226 | - ANSWER 227 | //response[0] = 0x81; 228 | response[0] = 0x85; 229 | response[1] = 0x80; 230 | response+=2; 231 | // Questions 1 232 | response[0] = 0x00; 233 | response[1] = 0x01; 234 | response+=2; 235 | //Answers 1 236 | response[0] = 0x00; 237 | response[1] = 0x01; 238 | response+=2; 239 | 240 | - ERROR 241 | response[0] = 0x81; 242 | response[1] = 0x82; 243 | response+=2; 244 | // Questions 1 245 | response[0] = 0x00; 246 | response[1] = 0x01; 247 | response+=2; 248 | // Answers 0 249 | response[0] = 0x00; 250 | response[1] = 0x00; 251 | response+=2; 252 | 253 | */ 254 | 255 | if(domain[0] != '\0') { // request exists 256 | int resIndex = 0; 257 | 258 | for(int k = 0; k < 2; k++) { // identification 259 | responseBuffer[resIndex++] = requestBuffer[k]; 260 | } 261 | 262 | responseBuffer[resIndex++] = '\x85'; // response //81 263 | // recursion desired 264 | responseBuffer[resIndex++] = '\x80'; // recursive 265 | // no error 266 | 267 | //for(int k = 4; k < 6; k++) { // question 268 | //responseBuffer[resIndex++] = requestBuffer[k]; 269 | responseBuffer[resIndex++] = '\x00'; 270 | responseBuffer[resIndex++] = '\x01'; 271 | //} 272 | 273 | for(int k = 4; k < 6; k++) { // answer 274 | responseBuffer[resIndex++] = requestBuffer[k]; 275 | //responseBuffer[resIndex++] = '\x00'; 276 | //responseBuffer[resIndex++] = '\x01'; 277 | } 278 | 279 | //for(int k = 0; k < 4; k++) { // authority, additional 280 | responseBuffer[resIndex++] = '\x00'; 281 | responseBuffer[resIndex++] = '\x00'; 282 | responseBuffer[resIndex++] = '\x00'; 283 | responseBuffer[resIndex++] = '\x00'; 284 | //} 285 | 286 | //for(int k = 12; k < requestSize -8; k++) { // question 287 | for(int k = 12; k < requestSize - 11; k++) { // question 288 | responseBuffer[resIndex++] = requestBuffer[k]; 289 | } 290 | 291 | /* 292 | // Type 293 | response[0] = (uint8_t)(dns_req->qtype >> 8); 294 | response[1] = (uint8_t)dns_req->qtype; 295 | response+=2; 296 | 297 | // Class 298 | response[0] = (uint8_t)(dns_req->qclass >> 8); 299 | response[1] = (uint8_t)dns_req->qclass; 300 | response+=2; 301 | */ 302 | 303 | responseBuffer[resIndex++] = '\xc0'; // pointer to answer 304 | responseBuffer[resIndex++] = '\x0c'; 305 | //responseBuffer[resIndex++] = '\x00'; // pointer to answer 306 | //responseBuffer[resIndex++] = '\x00'; 307 | 308 | /* TYPES */ 309 | 310 | /* 311 | if (dns_req->qtype == 0x0f) { //MX 312 | response[0] = 0x00; 313 | response[1] = 0x0f; 314 | response+=2; 315 | } else if (dns_req->qtype == 0xFF) { //ALL 316 | response[0] = 0x00; 317 | response[1] = 0xFF; 318 | response+=2; 319 | } else if (dns_req->qtype == 0x01) { //A 320 | *response++ = 0x00; 321 | *response++ = 0x01; 322 | } else if (dns_req->qtype == 0x05) { //CNAME 323 | response[0] = 0x00; 324 | response[1] = 0x05; 325 | response+=2; 326 | } else if (dns_req->qtype == 0x0c) { //PTR 327 | response[0] = 0x00; 328 | response[1] = 0x0c; 329 | response+=2; 330 | } else if (dns_req->qtype == 0x02) { //NS 331 | response[0] = 0x00; 332 | response[1] = 0x02; 333 | response+=2; 334 | } else { return; } 335 | */ 336 | 337 | responseBuffer[resIndex++] = '\x00'; // type A 338 | responseBuffer[resIndex++] = '\x01'; 339 | 340 | responseBuffer[resIndex++] = '\x00'; // class 341 | responseBuffer[resIndex++] = '\x01'; 342 | 343 | responseBuffer[resIndex++] = '\x00'; // ttl (orig 0x3c, now 4 hours) 344 | responseBuffer[resIndex++] = '\x00'; 345 | responseBuffer[resIndex++] = '\x38'; //3840 346 | responseBuffer[resIndex++] = '\x40'; 347 | 348 | responseBuffer[resIndex++] = '\x00'; // ip length for A record 349 | responseBuffer[resIndex++] = '\x04'; 350 | 351 | responseBuffer[resIndex++] = resIp[0]; // ip 352 | responseBuffer[resIndex++] = resIp[1]; 353 | responseBuffer[resIndex++] = resIp[2]; 354 | responseBuffer[resIndex++] = resIp[3]; 355 | 356 | responseBuffer[resIndex++] = '\x00'; // end 357 | 358 | //Serial.println("Contents:"); 359 | //Serial.println(requestBuffer); 360 | 361 | //Udp.sendPacket((uint8_t *)responseBuffer, (uint16_t)(resIndex - 1),remoteIp, remotePort); 362 | UdpTwo.beginPacket(UdpTwo.remoteIP(), UdpTwo.remotePort()); 363 | UdpTwo.write((uint8_t *)responseBuffer, (uint16_t)(resIndex - 1)); 364 | UdpTwo.endPacket(); 365 | } 366 | } 367 | } 368 | //delay(10); 369 | } 370 | 371 | void startOne() 372 | { 373 | Ethernet.select(8); 374 | Ethernet.begin(macOne, ipOne, dnsOne, gatewayOne, subnet); 375 | //Udp.begin(listenPort); 376 | UdpOne.begin(listenPort); 377 | serverOne.begin(); 378 | } 379 | 380 | void startTwo() 381 | { 382 | Ethernet.select(7); 383 | Ethernet.begin(macTwo, ipTwo, dnsTwo, gatewayTwo, subnet); 384 | //Udp.begin(listenPort); 385 | UdpTwo.begin(listenPort); 386 | serverTwo.begin(); 387 | } 388 | 389 | void checkServerOne() { 390 | // select ethernet one 391 | Ethernet.select(8); 392 | checkClient(1); 393 | } 394 | 395 | void checkServerTwo() { 396 | // select ethernet two 397 | Ethernet.select(7); 398 | checkClient(2); 399 | } 400 | 401 | void checkClient(int board) { 402 | 403 | /* 404 | switch (board) { 405 | case 1: 406 | EthernetClient clientOne = serverOne.available(); 407 | break; 408 | case 2: 409 | EthernetClient clientTwo = serverTwo.available(); 410 | break; 411 | default: 412 | //EthernetClient client; 413 | // statements 414 | Serial.println("aborting due to unexistent board value..."); 415 | return; 416 | } 417 | */ 418 | 419 | EthernetClient client; 420 | //if (board > 0 && board < 2) { 421 | EthernetClient clientOne = serverOne.available(); 422 | //} else if (board > 1 && board < 3) { 423 | EthernetClient clientTwo = serverTwo.available(); 424 | //} else { Serial.println("aborting due to unexistent board value..."); return; } 425 | 426 | currentLineIsBlank = true; 427 | 428 | if(clientOne || clientTwo) { 429 | //Serial.print("client coming in..."); 430 | //Serial.println(board); 431 | 432 | if (clientOne) { client = clientOne; } else { client = clientTwo; } 433 | 434 | while(client.connected()) { 435 | if(client.available()) { 436 | c = client.read(); 437 | if(c == '\n' && currentLineIsBlank) 438 | { 439 | client.println(F("HTTP/1.1 200 OK")); 440 | client.println(F("Content-Type: text/html")); 441 | client.println(F("Connection: close")); 442 | client.println(); 443 | client.println(F("")); 444 | client.println(F("")); 445 | client.println(F("")); 446 | client.print(F("Hello world from ")); 447 | client.print(board); 448 | client.print(F("")); 449 | client.println(F("")); 450 | break; 451 | } 452 | if(c == '\n') 453 | currentLineIsBlank = true; 454 | else if(c != '\r') 455 | currentLineIsBlank = false; 456 | } 457 | } 458 | client.stop(); 459 | } 460 | } 461 | -------------------------------------------------------------------------------- /varnish/etc-varnish-default-vcl: -------------------------------------------------------------------------------- 1 | #### Valid vcl_* methods are: 2 | #### vcl_backend_error 3 | #### vcl_backend_fetch 4 | #### vcl_backend_response 5 | #### vcl_deliver 6 | #### vcl_fini 7 | #### vcl_hash 8 | #### vcl_hit 9 | #### vcl_init 10 | #### vcl_miss 11 | #### vcl_pass 12 | #### vcl_pipe 13 | #### vcl_purge 14 | #### vcl_recv 15 | #### vcl_synth 16 | 17 | vcl 4.0; 18 | import directors; 19 | 20 | probe my_probe { 21 | .url = "/nslookup.php"; 22 | .interval = 20s; 23 | .expected_response=200; 24 | .timeout = 3s; 25 | .window = 3; 26 | .threshold = 2; 27 | .initial = 1; 28 | } 29 | 30 | backend default { 31 | .host = "127.0.0.1"; 32 | .port = "8080"; 33 | #.probe = my_probe; 34 | } 35 | 36 | backend fantuznet { 37 | .host = "fantuz.net"; 38 | .port = "80"; 39 | #.probe = my_probe; 40 | #.connect_timeout = 2s; 41 | #.first_byte_timeout = 5s; 42 | #.between_bytes_timeout = 2s; 43 | } 44 | 45 | backend f1 { 46 | .host = "104.27.132.199"; 47 | .port = "80"; 48 | .probe = my_probe; 49 | .connect_timeout = 2s; 50 | .first_byte_timeout = 5s; 51 | .between_bytes_timeout = 2s; 52 | } 53 | 54 | backend f2 { 55 | .host = "104.27.133.199"; 56 | .port = "80"; 57 | .probe = my_probe; 58 | .connect_timeout = 2s; 59 | .first_byte_timeout = 5s; 60 | .between_bytes_timeout = 2s; 61 | } 62 | 63 | #backend www { 64 | # #.host = "bonapp.world"; 65 | # .host = "vnc.fantuz.shop"; 66 | # .port = "http"; 67 | # .connect_timeout = 2s; 68 | # .first_byte_timeout = 5s; 69 | # .between_bytes_timeout = 2s; 70 | #} 71 | 72 | sub vcl_init { 73 | new radirector = directors.random(); 74 | radirector.add_backend(fantuznet, 1.0); 75 | radirector.add_backend(f1, 1.0); 76 | radirector.add_backend(f2, 1.0); 77 | radirector.add_backend(default, 1.0); 78 | 79 | # new vdir = directors.round_robin(); 80 | # vdir.add_backend(fantuznet); 81 | # vdir.add_backend(default); 82 | 83 | # new hash = directors.hash(); 84 | # hash.add_backend(fantuznet,1.0); 85 | # hash.add_backend(default,1.0); 86 | 87 | # new rr = directors.round_robin(); 88 | # rr.add_backend(hash.backend(fantuznet)); 89 | # rr.add_backend(hash.backend(default)); 90 | } 91 | 92 | acl purge { 93 | "localhost"; 94 | "192.168.3.0"/24; 95 | "192.168.1.0"/24; 96 | } 97 | 98 | ### # Happens before we check if we have this in cache already. 99 | ### # Typically you clean up the request here, removing cookies you don't need, 100 | ### # rewriting the request, etc. 101 | ## Legal returns are: "fail" "hash" "pass" "pipe" "purge" "synth" "vcl" 102 | sub vcl_recv { 103 | 104 | ## This information is mainly important if you are running earlier versions of Varnish. From 4.0 and on, the backend fetch will happen in the background as long as you haven't disabled grace explicitly. 105 | ## When using a script to refresh or warm the cache, it can be desirable to make sure it is your script that is stuck waiting for the backend fetch, and not the next client visiting your site. You can use the req.hash_always_miss control variable to make sure this request will result in a cache miss and fetch from the backend. 106 | ## Downside of this method is that it will leave multiple copies of the same object in cache. 107 | ## Command to refresh cached front page 108 | ## GET -H 'X-REFRESH: DOIT' http://my.site.com/ 109 | 110 | if (req.http.X-REFRESH) { 111 | # Force a cache miss 112 | set req.hash_always_miss = true; 113 | } 114 | 115 | #if ( req.http.host ~ "(intranet\.example\.com)$" && !(client.ip ~ offices) ) { 116 | # error 403 "Access denied"; 117 | #} 118 | set req.backend_hint = radirector.backend(); 119 | 120 | if (req.url ~ "^/nslookup-out/") { 121 | #set req.http.host = regsub(req.http.host, "^www\.",""); 122 | set req.http.host = "fantuz.net"; 123 | set req.url = regsub(req.url, "^/nslookup-out/","/"); 124 | set req.backend_hint = fantuznet; 125 | } 126 | #else { 127 | # set req.backend_hint = default; 128 | #} 129 | if (req.method == "PURGE") { 130 | set req.backend_hint = default; 131 | 132 | if (!client.ip ~ purge) { 133 | return(synth(405,"Not allowed.")); 134 | } else { 135 | #return(lookup); 136 | return(purge); 137 | } 138 | } 139 | 140 | ## The following example redirects clients accessing http://foo.example.com/foo/bar to http://www.example.net/foo/bar using a 302 redirect (temporarily relocated). 141 | ## For permanent domain or hostname changes a 301 moved permanently may be more appropriate. 142 | ## Please note that some clients send the complete URL (including http://foo.example.com/) as req.url. In such cases you may want to normalize req.url. 143 | if (req.http.host == "foo.example.com") { 144 | # req.url will be passed as an argument to the error subroutine 145 | return(synth(750,req.url)); 146 | } 147 | } 148 | 149 | ## Legal returns are: "deliver" "fail" "miss" "pass" "restart" "synth" 150 | sub vcl_hit { 151 | if (req.method == "PURGE") { 152 | #return(purge); 153 | return(synth(200,"Purged.")); 154 | } 155 | } 156 | 157 | sub vcl_miss { 158 | if (req.method == "PURGE") { 159 | #return(purge); 160 | return(synth(200,"Purged.")); 161 | } 162 | } 163 | 164 | sub vcl_synth { 165 | ## if (resp.status == 799) { 166 | ## set resp.status = 200; 167 | ## set resp.http.Content-Type = "text/plain; charset=utf-8"; 168 | ## synthetic("You are " + client.ip); 169 | ## return (deliver); 170 | ## } 171 | if (resp.status == 799) { 172 | set resp.status = 200; 173 | set resp.http.Content-Type = "text/plain; charset=utf-8"; 174 | synthetic("You are " + client.ip); 175 | return (deliver); 176 | } 177 | } 178 | 179 | ## Some clients (including curl and LWP) submit the full URI including protocol and hostname in the first line of the request. In Varnish 4.0 this will get dissected into req.http.host and req.url, so further handling of this is not needed. In Varnish 3.0 and earlier, it will however all get picked up by req.url. The following rewrite normalizes it. 180 | 181 | ## sub vcl_recv { 182 | ## ### clean out requests sent via curls -X mode and LWP 183 | ## if (req.url ~ "^http://") { 184 | ## set req.url = regsub(req.url, "http://[^/]*", ""); 185 | ## } 186 | ## 187 | ## ### remove double // in urls, 188 | ## ### /foo and /foo/ are the same url 189 | ## set req.url = regsuball( req.url, "//", "/" ); 190 | ## set req.url = regsub( req.url, "/([?])?$", "\1" ); 191 | ## } 192 | 193 | # 194 | #sub vcl_error { 195 | # if (obj.status == 750) { 196 | # # obj.response is the argument, originally req.url 197 | # set obj.http.Location = "http://www.example.net/" obj.response; 198 | # set obj.status = 302; 199 | # deliver; 200 | # } 201 | #} 202 | 203 | sub vcl_deliver { 204 | # Happens when we have all the pieces we need, and are about to send the 205 | # response to the client. 206 | # 207 | # You can do accounting or modifying the final object here. 208 | if (obj.hits > 0) { 209 | set resp.http.X-Cache = "HIT"; 210 | } else { 211 | set resp.http.X-Cache = "MISS"; 212 | } 213 | 214 | return(deliver); 215 | } 216 | 217 | #sub vcl_recv { 218 | # set req.http.host = "fantuz.net"; 219 | #} 220 | 221 | #This is an example from a brilliant book: https://www.varnish-software.com/static/book/ 222 | #Hiding js requests to external domainsIf we need to do some CORS (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) requests instead of our Javascript doing requests directly to external domain, we can do requests to our site, but with a specific URL. Then, on the Varnish level, we can redirect that request to external domain. In this case, Varnish will act like a proxy. This can be achieved with backend options. 223 | 224 | #backend google { 225 | # .host = "209.85.147.106"; 226 | # 227 | #.port = "80"; 228 | #} 229 | # 230 | #sub vcl_fetch { 231 | # if (req.url ~ "^/masq") { 232 | # set req.backend = google; 233 | # set req.http.host = "www.google.com"; 234 | # set req.url = regsub(req.url, "^/masq", ""); 235 | # remove req.http.Cookie; 236 | # return(deliver); 237 | # } 238 | #} 239 | 240 | # 241 | # Below is a commented-out copy of the default VCL logic. If you 242 | # redefine any of these subroutines, the built-in logic will be 243 | # appended to your code. 244 | # sub vcl_recv { 245 | # if (req.restarts == 0) { 246 | # if (req.http.x-forwarded-for) { 247 | # set req.http.X-Forwarded-For = 248 | # req.http.X-Forwarded-For + ", " + client.ip; 249 | # } else { 250 | # set req.http.X-Forwarded-For = client.ip; 251 | # } 252 | # } 253 | # if (req.request != "GET" && 254 | # req.request != "HEAD" && 255 | # req.request != "PUT" && 256 | # req.request != "POST" && 257 | # req.request != "TRACE" && 258 | # req.request != "OPTIONS" && 259 | # req.request != "DELETE") { 260 | # /* Non-RFC2616 or CONNECT which is weird. */ 261 | # return (pipe); 262 | # } 263 | # if (req.request != "GET" && req.request != "HEAD") { 264 | # /* We only deal with GET and HEAD by default */ 265 | # return (pass); 266 | # } 267 | # if (req.http.Authorization || req.http.Cookie) { 268 | # /* Not cacheable by default */ 269 | # return (pass); 270 | # } 271 | # return (lookup); 272 | # } 273 | # 274 | # sub vcl_pipe { 275 | # # Note that only the first request to the backend will have 276 | # # X-Forwarded-For set. If you use X-Forwarded-For and want to 277 | # # have it set for all requests, make sure to have: 278 | # # set bereq.http.connection = "close"; 279 | # # here. It is not set by default as it might break some broken web 280 | # # applications, like IIS with NTLM authentication. 281 | # return (pipe); 282 | # } 283 | # 284 | # sub vcl_pass { 285 | # return (pass); 286 | # } 287 | # 288 | # sub vcl_hash { 289 | # hash_data(req.url); 290 | # if (req.http.host) { 291 | # hash_data(req.http.host); 292 | # } else { 293 | # hash_data(server.ip); 294 | # } 295 | # return (hash); 296 | # } 297 | # 298 | # sub vcl_hit { 299 | # return (deliver); 300 | # } 301 | # 302 | # sub vcl_miss { 303 | # return (fetch); 304 | # } 305 | 306 | # sub vcl_fetch { 307 | # if (beresp.ttl <= 0s || 308 | # beresp.http.Set-Cookie || 309 | # beresp.http.Vary == "*") { 310 | # /* 311 | # * Mark as "Hit-For-Pass" for the next 2 minutes 312 | # */ 313 | # set beresp.ttl = 120 s; 314 | # return (hit_for_pass); 315 | # } 316 | # return (deliver); 317 | # } 318 | # 319 | # sub vcl_deliver { 320 | # return (deliver); 321 | # } 322 | # 323 | # sub vcl_error { 324 | # set obj.http.Content-Type = "text/html; charset=utf-8"; 325 | # set obj.http.Retry-After = "5"; 326 | # synthetic {" 327 | # 328 | # 330 | # 331 | # 332 | # "} + obj.status + " " + obj.response + {" 333 | # 334 | # 335 | #

Error "} + obj.status + " " + obj.response + {"

336 | #

"} + obj.response + {"

337 | #

Guru Meditation:

338 | #

XID: "} + req.xid + {"

339 | #
340 | #

Varnish cache server

341 | # 342 | # 343 | # "}; 344 | # return (deliver); 345 | # } 346 | # 347 | # sub vcl_init { 348 | # return (ok); 349 | # } 350 | # 351 | # sub vcl_fini { 352 | # return (ok); 353 | # } 354 | 355 | #director tsd client { 356 | # { .backend = foo; .weight = 100; } 357 | # { .backend = bar; .weight = 100; } 358 | #} 359 | 360 | #director b2 fallback/random/round-robin/hash { 361 | # 'acl', 'sub', 'backend', 'probe', 'import', or 'vcl' 362 | 363 | #director b2 client { 364 | # .retries = 5; 365 | # { .backend = fantuznet; .weight = 7;} 366 | # { .backend = default; .weight = 7;} 367 | #} 368 | 369 | # { 370 | # // Or define them inline 371 | # .backend = { 372 | # .host = "fs2"; 373 | # } 374 | # .weight = 3; 375 | # } 376 | 377 | # The `client' director will select a backend based on `client.identity'. 378 | # It's normally used to implement session stickiness but here we abuse it 379 | # to try to send pairs of requests to the same TSD, in order to achieve a 380 | # higher cache hit rate. The UI sends queries first with a "&json" at the 381 | # end, in order to get meta-data back about the results, and then it sends 382 | # the same query again with "&png". If the second query goes to a different 383 | # TSD, then that TSD will have to fetch the data from HBase again. Whereas 384 | # if it goes to the same TSD that served the "&json" query, it'll hit the 385 | # cache of that TSD and produce the PNG directly without using HBase. 386 | # 387 | # Note that we cannot use the `hash' director here, because otherwise Varnish 388 | # would hash both the "&json" and the "&png" requests identically, and it 389 | # would thus serve a cached JSON response to a "&png" request. 390 | 391 | ## director tsd client { 392 | ## { .backend = foo; .weight = 100; } 393 | ## { .backend = bar; .weight = 100; } 394 | ## } 395 | ## 396 | ## sub vcl_recv { 397 | ## set req.backend = tsd; 398 | ## # Make sure we hit the same backend based on the URL requested, 399 | ## # but ignore some parameters before hashing the URL. 400 | ## set client.identity = regsuball(req.url, "&(o|ignore|png|json|html|y2?range|y2?label|y2?log|key|nokey)\b(=[^&]*)?", ""); 401 | ## } 402 | ## 403 | ## sub vcl_hash { 404 | ## # Remove the `ignore' parameter from the URL we hash, so that two 405 | ## # identical requests modulo that parameter will hit Varnish's cache. 406 | ## hash_data(regsuball(req.url, "&ignore\b(=[^&]*)?", "")); 407 | ## if (req.http.host) { 408 | ## hash_data(req.http.host); 409 | ## } else { 410 | ## hash_data(server.ip); 411 | ## } 412 | ## return (hash); 413 | ## } 414 | 415 | #director directorname dns { 416 | # .list = { 417 | # .host_header = "fantuz.net"; 418 | # .port = "80"; 419 | # .connect_timeout = 2s; 420 | # "192.168.15.0"/24; 421 | # "192.168.16.128"/25; 422 | # } 423 | # .ttl = 5m; 424 | # .suffix = "internal.example.net"; 425 | #} 426 | 427 | #director b3 fallback { 428 | # { .backend = www1; } 429 | # { .backend = www2; } // will only be used if www1 is unhealthy. 430 | # { .backend = www3; } // will only be used if both www1 and www2 431 | #} 432 | 433 | # /* 434 | #probe my_probe { 435 | # .url = "/"; 436 | # .interval = 1s; 437 | # .timeout = 0.2 s; 438 | # .window = 3; 439 | # .threshold = 2; 440 | # .initial = 1; 441 | #} 442 | #backend default { 443 | # .host = 127.0.0.1; 444 | # .probe = my_probe; 445 | #} 446 | #backend server1 { 447 | # .host = 192.168.8.21; 448 | # .probe = my_probe; 449 | #} 450 | #backend server2 { 451 | # .host = 192.168.8.22; 452 | # .probe = my_probe; 453 | #} 454 | #backend server3 { 455 | # .host = 192.168.8.23; 456 | # .probe = my_probe; 457 | #} 458 | #director server_pool round-robin { 459 | # { .backend = server1; } 460 | # { .backend = server2; } 461 | # { .backend = server3; } 462 | #} 463 | # 464 | #sub vcl_recv { 465 | # if ( req.backend == default 466 | # && ! req.backend.healthy 467 | # ) { 468 | # set req.backend = server_pool; 469 | # } 470 | # /* Uncomment if you want to divert restarted requests to the server pool 471 | # * if (req.restarts > 0) { 472 | # * set req.backend = server_pool; 473 | # * } 474 | # */ 475 | #} 476 | # */ 477 | 478 | ## Some backends send headers that tell varnish not to cache elements. Header examples are: 479 | ## 480 | ## Cache-Control: no-cache, no-store, max-age=0, must-revalidate 481 | ## Pragma: no-cache 482 | ## To override these headers and still put the element into cache for 2 minutes, the following configuration may be used: 483 | ## 484 | ## sub vcl_fetch { 485 | ## if (beresp.ttl < 120s) { 486 | ## set beresp.ttl = 120s; 487 | ## } 488 | ## } 489 | 490 | # Happens after we have read the response headers from the backend. 491 | # Here you clean the response headers, removing silly Set-Cookie headers 492 | # and other mistakes your backend does. 493 | sub vcl_backend_response { 494 | ## Adding diagnostics on why there was a hit/miss 495 | ## You can use the snippet below to add extra diagnostic headers to your response indicating why something was a cache hit or miss. Of course, the conditions can vary based on your business logic, so extend and alter the below snippet to suit your needs. 496 | 497 | # Varnish determined the object was not cacheable 498 | if (beresp.ttl <= 0s) { 499 | set beresp.http.X-Cacheable = "NO:Not Cacheable"; 500 | # You don't wish to cache content for logged in users 501 | ## } elsif (req.http.Cookie ~ "(UserID|_session)") { 502 | ## set beresp.http.X-Cacheable = "NO:Got Session"; 503 | #return(hit_for_pass); 504 | # You are respecting the Cache-Control=private header from the backend 505 | } elsif (beresp.http.Cache-Control ~ "private") { 506 | set beresp.http.X-Cacheable = "NO:Cache-Control=private"; 507 | #return(hit_for_pass); 508 | # Varnish determined the object was cacheable 509 | } else { 510 | set beresp.http.X-Cacheable = "YES"; 511 | } 512 | 513 | if (beresp.ttl < 120s) { 514 | set beresp.ttl = 120s; 515 | unset beresp.http.Cache-Control; 516 | } 517 | } 518 | 519 | -------------------------------------------------------------------------------- /dnsp.c.fork.bak: -------------------------------------------------------------------------------- 1 | /* 2 | * DNS proxy 0.99 3 | * 4 | * Copyright (C) 2014 Massimiliano Fantuzzi 5 | * Copyright (C) 2009-2013 Andrea Fabrizi 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | //#include 41 | 42 | 43 | #ifndef SIGCLD 44 | # define SIGCLD SIGCHLD 45 | #endif 46 | 47 | #define DELAY 500 48 | #define MAXCONN 4096 49 | #define UDP_DATAGRAM_SIZE 255 50 | #define DNSREWRITE 255 51 | #define HTTP_RESPONSE_SIZE 255 52 | #define URL_SIZE 255 53 | #define VERSION "0.99" 54 | #define DNS_MODE_ANSWER 1 55 | #define DNS_MODE_ERROR 2 56 | #define DEFAULT_LOCAL_PORT 53 57 | #define DEFAULT_WEB_PORT 80 58 | //#define TYPEQ 2 59 | 60 | int DEBUG; 61 | 62 | struct dns_request 63 | { 64 | uint16_t transaction_id, 65 | questions_num, 66 | flags, 67 | qtype, 68 | qclass; 69 | char hostname[256], 70 | query[256]; 71 | size_t hostname_len; 72 | }; 73 | 74 | struct dns_reponse 75 | { 76 | size_t lenght; 77 | char *payload; 78 | }; 79 | 80 | /* * usage */ 81 | void usage(void) 82 | { 83 | fprintf(stderr, "\n dnsp %s\n" 84 | " usage: dnsp -l [local_host] -h [proxy_host] -r [proxy_port] -w [webport] -s [lookup_script]\n\n" 85 | " OPTIONS:\n" 86 | " -l\t\t Local server host\n" 87 | " -p\t\t Local server port\n" 88 | " -h\t\t Remote proxy host\n" 89 | " -r\t\t Remote proxy port\n" 90 | " -u\t\t Proxy username (optional)\n" 91 | " -k\t\t Proxy password (optional)\n" 92 | " -s\t\t Lookup script URL\n" 93 | " -w\t\t Webserver port (optional, default 80)\n" 94 | " -v\t\t Enable DEBUG mode\n" 95 | "\n" 96 | " Example: dnsp -p 53 -l 127.0.0.1 -h 127.0.0.1 -r 8118 -w 80 -s http://www.fantuz.net/nslookup.php\n\n" 97 | ,VERSION); 98 | exit(EXIT_FAILURE); 99 | } 100 | 101 | /* * Prints an error message and exit */ 102 | void error(const char *msg) 103 | { 104 | fprintf(stderr," *** %s: %s\n", msg, strerror(errno)); 105 | exit(EXIT_FAILURE); 106 | } 107 | 108 | /* * Prints debug messages */ 109 | void debug_msg(const char* fmt, ...) 110 | { 111 | va_list ap; 112 | 113 | if (DEBUG) { 114 | fprintf(stdout, " [%d]> ", getpid()); 115 | va_start(ap, fmt); 116 | vfprintf(stdout, fmt, ap); 117 | va_end(ap); 118 | } 119 | } 120 | 121 | /* * Return the length of the pointed buffer */ 122 | size_t memlen(const char *buff) 123 | { 124 | size_t len = 0; 125 | 126 | while (1) { 127 | if (buff[len] == 0) break; 128 | len ++; 129 | } 130 | 131 | return len; 132 | } 133 | 134 | /* * Parses the dns request and returns the pointer to dns_request struct Returns NULL on errors */ 135 | struct dns_request *parse_dns_request(const char *udp_request, size_t request_len) 136 | { 137 | struct dns_request *dns_req; 138 | 139 | dns_req = malloc(sizeof(struct dns_request)); 140 | 141 | /* Transaction ID */ 142 | dns_req->transaction_id = (uint8_t)udp_request[1] + (uint16_t)(udp_request[0] << 8); 143 | udp_request+=2; 144 | 145 | /* Flags */ 146 | dns_req->flags = (uint8_t)udp_request[1] + (uint16_t)(udp_request[0] << 8); 147 | udp_request+=2; 148 | 149 | /* Questions num */ 150 | dns_req->questions_num = (uint8_t)udp_request[1] + (uint16_t)(udp_request[0] << 8); 151 | udp_request+=2; 152 | 153 | /* Skipping 6 not interesting bytes 154 | uint16_t Answers number 155 | uint16_t Records number 156 | uint16_t Additionals records number 157 | */ 158 | udp_request+=6; 159 | 160 | /* Getting the dns query */ 161 | bzero(dns_req->query, sizeof(dns_req->query)); 162 | memcpy(dns_req->query, udp_request, sizeof(dns_req->query)-1); 163 | 164 | /* Hostname */ 165 | bzero(dns_req->hostname, sizeof(dns_req->hostname)); 166 | dns_req->hostname_len = 0; 167 | while (1) { 168 | uint8_t len = udp_request[0]; /* Length of the next label */ 169 | if (len == 0) { 170 | udp_request++; 171 | break; 172 | } 173 | udp_request++; 174 | if (dns_req->hostname_len + len >= sizeof(dns_req->hostname)) { 175 | free(dns_req); 176 | return NULL; 177 | } 178 | strncat(dns_req->hostname, udp_request, len); /* Append the current label to dns_req->hostname */ 179 | strncat(dns_req->hostname, ".", 1); /* Append a '.' */ 180 | dns_req->hostname_len+=len+1; 181 | udp_request+=len; 182 | } 183 | 184 | /* Qtype */ 185 | dns_req->qtype = (uint8_t)udp_request[1] + (uint16_t)(udp_request[0] << 8); 186 | udp_request+=2; 187 | 188 | /* Qclass */ 189 | dns_req->qclass = (uint8_t)udp_request[1] + (uint16_t)(udp_request[0] << 8); 190 | udp_request+=2; 191 | 192 | return dns_req; 193 | } 194 | 195 | /* * Builds and sends the dns response datagram */ 196 | void build_dns_reponse(int sd, struct sockaddr_in client, struct dns_request *dns_req, const char *ip, int mode) 197 | { 198 | char *response, 199 | *token, 200 | *pch, 201 | *maxim, 202 | //*ppch, 203 | //*typeq, 204 | *response_ptr; 205 | int i, ppch; 206 | ssize_t bytes_sent; 207 | 208 | response = malloc (UDP_DATAGRAM_SIZE); 209 | bzero(response, UDP_DATAGRAM_SIZE); 210 | 211 | maxim = malloc (DNSREWRITE); 212 | bzero(maxim, DNSREWRITE); 213 | 214 | response_ptr = response; 215 | //maxim_ptr = maxim; 216 | 217 | /* Transaction ID */ 218 | response[0] = (uint8_t)(dns_req->transaction_id >> 8); 219 | response[1] = (uint8_t)dns_req->transaction_id; 220 | response+=2; 221 | 222 | if (mode == DNS_MODE_ANSWER) { 223 | /* Default flags for a standard query (0x8580) */ 224 | /* authoritative answer... or not ? :) */ 225 | //response[0] = 0x81; 226 | response[0] = 0x85; 227 | response[1] = 0x80; 228 | response+=2; 229 | /* Questions 1 */ 230 | response[0] = 0x00; 231 | response[1] = 0x01; 232 | response+=2; 233 | /* Answers 1 */ 234 | response[0] = 0x00; 235 | response[1] = 0x01; 236 | response+=2; 237 | } 238 | /* DNS_MODE_ERROR should truncate message instead of building it up ... */ 239 | else { 240 | /* Server failure (0x8182), but what if we want NXDOMAIN (0x....) ???*/ 241 | /* 242 | * NOERROR (RCODE:0) : DNS Query completed successfully 243 | * FORMERR (RCODE:1) : DNS Query Format Error 244 | * SERVFAIL (RCODE:2) : Server failed to complete the DNS request 245 | * NXDOMAIN (RCODE:3) : Domain name does not exist 246 | * NOTIMP (RCODE:4) : Function not implemented 247 | * REFUSED (RCODE:5) : The server refused to answer for the query 248 | * YXDOMAIN (RCODE:6) : Name that should not exist, does exist 249 | * XRRSET (RCODE:7) : RRset that should not exist, does exist 250 | * NOTAUTH (RCODE:9) : Server not authoritative for the zone 251 | * NOTZONE (RCODE:10) : Name not in zone 252 | * 11-15 available for assignment 253 | * 16 BADVERS Bad OPT Version 254 | * 16 BADSIG TSIG Signature Failure 255 | * 17 BADKEY Key not recognized 256 | * 18 BADTIME Signature out of time window 257 | * 19 BADMODE Bad TKEY Mode 258 | * 20 BADNAME Duplicate key name 259 | * 21 BADALG Algorithm not supported 260 | * 22-3840 available for assignment 261 | * 0x0016-0x0F00 262 | * 3841-4095 Private Use 263 | * 0x0F01-0x0FFF 264 | * 4096-65535 available for assignment 265 | * 0x1000-0xFFFF 266 | * */ 267 | 268 | response[0] = 0x81; 269 | response[1] = 0x82; 270 | response+=2; 271 | /* Questions 1 */ 272 | response[0] = 0x00; 273 | response[1] = 0x01; 274 | response+=2; 275 | /* Answers 0 */ 276 | response[0] = 0x00; 277 | response[1] = 0x00; 278 | response+=2; 279 | } 280 | 281 | /* Authority RRs 0 */ 282 | response[0] = 0x00; 283 | response[1] = 0x00; 284 | response+=2; 285 | 286 | /* Additional RRs 0 */ 287 | response[0] = 0x00; 288 | response[1] = 0x00; 289 | response+=2; 290 | 291 | /* Query */ 292 | strncat(response, dns_req->query, dns_req->hostname_len); 293 | response+=dns_req->hostname_len+1; 294 | 295 | /* Type */ 296 | response[0] = (uint8_t)(dns_req->qtype >> 8); 297 | response[1] = (uint8_t)dns_req->qtype; 298 | response+=2; 299 | 300 | /* Class */ 301 | response[0] = (uint8_t)(dns_req->qclass >> 8); 302 | response[1] = (uint8_t)dns_req->qclass; 303 | response+=2; 304 | 305 | /* Answer */ 306 | if (mode == DNS_MODE_ANSWER) { 307 | /* Pointer to host name in query section */ 308 | response[0] = 0xc0; 309 | response[1] = 0x0c; 310 | response+=2; 311 | 312 | if (dns_req->qtype == 0x0f) { //MX 313 | response[0] = 0x00; 314 | response[1] = 0x0f; 315 | response+=2; 316 | } else if (dns_req->qtype == 0xFF) { //ALL 317 | response[0] = 0x00; 318 | response[1] = 0xFF; 319 | response+=2; 320 | } else if (dns_req->qtype == 0x01) { //A 321 | *response++ = 0x00; 322 | *response++ = 0x01; 323 | } else if (dns_req->qtype == 0x05) { //CNAME 324 | response[0] = 0x00; 325 | response[1] = 0x05; 326 | response+=2; 327 | } else if (dns_req->qtype == 0x0c) { //PTR 328 | response[0] = 0x00; 329 | response[1] = 0x0c; 330 | response+=2; 331 | } else if (dns_req->qtype == 0x02) { //NS 332 | response[0] = 0x00; 333 | response[1] = 0x02; 334 | response+=2; 335 | } else { return; } 336 | 337 | /* Class IN */ 338 | *response++ = 0x00; 339 | *response++ = 0x01; 340 | 341 | /* TTL (4 hours) */ 342 | *response++ = 0x00; 343 | *response++ = 0x00; 344 | *response++ = 0x38; 345 | *response++ = 0x40; 346 | 347 | //ptr,ns 348 | if (dns_req->qtype == 0x0c || dns_req->qtype == 0x02) { 349 | 350 | /* Data length (4 bytes)*/ 351 | response[0] = 0x00; 352 | response[1] = 0x04; 353 | response+=2; 354 | response[0] = 0xc0; 355 | response[1] = 0x0c; 356 | response+=2; 357 | 358 | } else if (dns_req->qtype == 0x05) { //CNAME RECORD 359 | 360 | /* Data length (4 bytes)*/ 361 | response[0] = 0x00; 362 | response[1] = (strlen(ip)+1); 363 | response+=2; 364 | 365 | pch = strtok((char *)ip,".\r\n\t"); 366 | while (pch != NULL) 367 | { 368 | ppch = strlen(pch); 369 | *response++ = strlen(pch); 370 | for (i = 0; i < strlen(pch); ++i) { 371 | *response++ = pch[i]; 372 | maxim[i] = pch[i]; 373 | } 374 | pch = strtok (NULL, "."); 375 | if (pch == NULL) { 376 | for (i = 0; i < ppch+1; ++i) { 377 | response--; 378 | } 379 | *response++ = ppch-1; 380 | for (i = 0; i < ppch-1; ++i) { 381 | *response++ = maxim[i]; 382 | } 383 | } 384 | } 385 | 386 | *response++ = 0x00; 387 | 388 | } else if (dns_req->qtype == 0x0f) { //MX RECORD 389 | /* Data length (4 bytes)*/ 390 | response[0] = 0x00; 391 | response[1] = (strlen(ip)+3); 392 | //response[1] = 0x00; 393 | response+=2; 394 | 395 | /* PRIO (4 bytes)*/ 396 | response[0] = 0x00; 397 | response[1] = 0x0a; 398 | response+=2; 399 | 400 | /* POINTER, IF YOU ARE SO BRAVE OR ABLE TO USE IT (4 bytes) -> do not use label then... so you should re-write the code to have super-duper minimal responses. That code would also need domain comparison, to see if suffix can be appended */ 401 | //response[0] = 0xc0; 402 | //response[1] = 0x0c; 403 | //response+=2; 404 | 405 | pch = strtok((char *)ip,".\r\n\t"); 406 | while (pch != NULL) 407 | { 408 | //maxim = NULL; 409 | ppch = strlen(pch); 410 | *response++ = strlen(pch); 411 | for (i = 0; i < strlen(pch); ++i) { 412 | *response++ = pch[i]; 413 | //maxim[0] += 0x00; 414 | maxim[i] = pch[i]; 415 | } 416 | //strcat(response, pch); 417 | //*response++ = *maxim; 418 | pch = strtok (NULL, "."); 419 | if (pch == NULL) { 420 | for (i = 0; i < ppch+1; ++i) { 421 | response--; 422 | } 423 | *response++ = ppch-1; 424 | for (i = 0; i < ppch-1; ++i) { 425 | *response++ = maxim[i]; 426 | } 427 | } 428 | } 429 | 430 | *response++ = 0x00; 431 | 432 | } else if (dns_req->qtype == 0x01) { // A RECORD 433 | 434 | /* Data length (4 bytes)*/ 435 | *response++ = 0x00; 436 | *response++ = 0x04; 437 | 438 | token = strtok((char *)ip,"."); 439 | if (token != NULL) response[0] = atoi(token); 440 | else return; 441 | 442 | token = strtok(NULL,"."); 443 | if (token != NULL) response[1] = atoi(token); 444 | else return; 445 | 446 | token = strtok(NULL,"."); 447 | if (token != NULL) response[2] = atoi(token); 448 | else return; 449 | 450 | token = strtok(NULL,"."); 451 | if (token != NULL) response[3] = atoi(token); 452 | else return; 453 | 454 | response+=4; 455 | 456 | } else { return;} 457 | // *response++=(unsigned char)(strlen(ip)+1); 458 | //memcpy(response,ip,strlen(ip)-1); 459 | //strncpy(response,ip,strlen(ip)-1); 460 | bytes_sent = sendto(sd,response_ptr,response - response_ptr,0,(struct sockaddr *)&client,sizeof(client)); 461 | //fdatasync(sd); 462 | close(sd); 463 | 464 | } else { 465 | 466 | /* Are we into "No such name" ?... just an NXDOMAIN ?? */ 467 | //if (mode == DNS_MODE_ERROR) 468 | bytes_sent = sendto(sd,response_ptr,response - response_ptr,0,(struct sockaddr *)&client,sizeof(client)); 469 | //fdatasync(sd); 470 | close(sd); 471 | } 472 | // DNS VOLUME CALCULATION 473 | //debug_msg("Dns response sent to client (DEC %d bytes)\n", bytes_sent); 474 | free(response_ptr); 475 | } 476 | 477 | /* * libCurl write data callback */ 478 | static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) 479 | { 480 | size_t stream_size; 481 | stream_size = size * nmemb + 1; 482 | bzero(stream, HTTP_RESPONSE_SIZE); 483 | memcpy(stream, ptr, stream_size); 484 | return 0; 485 | } 486 | 487 | /* * Hostname lookup * Return: * OK: Resolved IP * KO: Null */ 488 | char *lookup_host(const char *host, const char *proxy_host, unsigned int proxy_port, const char *proxy_user, const char *proxy_pass, const char *lookup_script, const char *typeq, unsigned int wport) 489 | { 490 | CURL *ch; 491 | CURLSH *curlsh; 492 | char *http_response, 493 | *script_url; 494 | int ret; 495 | struct curl_slist *hosting = NULL; 496 | hosting = curl_slist_append(NULL, "fantuz.net:80:127.0.0.1"); 497 | 498 | script_url = malloc(URL_SIZE); 499 | http_response = malloc(HTTP_RESPONSE_SIZE); 500 | bzero(script_url, URL_SIZE); 501 | 502 | //CALLBACK TO PHP, BEHIND WHICH SITS THE "REAL" RESOLVER 503 | snprintf(script_url, URL_SIZE-1, "%s?host=%s&type=%s", lookup_script, host, typeq); 504 | 505 | /* try to see.... */ 506 | hosting = curl_slist_append(NULL, "example.com:80:127.0.0.1"); 507 | /* curl setup */ 508 | ch = curl_easy_init(); 509 | curlsh = curl_share_init(); 510 | curl_easy_setopt(ch, CURLOPT_URL, script_url); 511 | curl_easy_setopt(ch, CURLOPT_PORT, wport); //80 512 | //curl_easy_setopt(ch, CURLINFO_HEADER_OUT, "" ); 513 | curl_easy_setopt(ch, CURLOPT_DNS_CACHE_TIMEOUT, 900); 514 | curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); /* No progress meter */ 515 | curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_data); /* Set write function */ 516 | curl_easy_setopt(ch, CURLOPT_WRITEDATA, http_response); 517 | curl_easy_setopt(ch, CURLOPT_PROXY, proxy_host); 518 | curl_easy_setopt(ch, CURLOPT_PROXYPORT, proxy_port); //8118 519 | curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); 520 | curl_easy_setopt(ch, CURLOPT_VERBOSE, 0); /* Verbose OFF */ 521 | 522 | //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0) 523 | curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 0L); 524 | curl_easy_setopt(ch, CURLOPT_SSL_VERIFYHOST, 0L);; 525 | 526 | curl_easy_setopt(ch, CURLOPT_DNS_USE_GLOBAL_CACHE, 1); /* DNS CACHE */ 527 | curl_easy_setopt(ch, CURLOPT_RESOLVE, hosting); 528 | curl_easy_setopt(ch, CURLOPT_MAXCONNECTS, 32); 529 | curl_easy_setopt(ch, CURLOPT_FRESH_CONNECT, 0); /* HOW DOES A NEW TCP INFLUENCE WEB CACHE ?? */ 530 | curl_easy_setopt(ch, CURLOPT_FORBID_REUSE, 0); 531 | //curl_setopt ($curl, CURLOPT_AUTOREFERER, 1); 532 | //curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1); 533 | 534 | //CURL_LOCK_DATA_SHARE 535 | // curl_share_setopt(curlsh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE); 536 | curl_share_setopt(curlsh, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS); 537 | curl_easy_setopt(ch, CURLOPT_SHARE, curlsh); 538 | 539 | /* PROXY AUTH REMOVED; just uncomment to enable !! */ 540 | /* option proxy username and password */ 541 | // if ((proxy_user != NULL) && (proxy_pass != NULL)) { 542 | // curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, proxy_user); 543 | // curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, proxy_pass); 544 | // } 545 | 546 | 547 | /* Problem in performing http request */ 548 | ret = curl_easy_perform(ch); 549 | if (ret < 0) { 550 | // curl_share_cleanup(curlsh); 551 | debug_msg ("Error performing HTTP request (Error %d) - spot on !!!\n"); 552 | curl_easy_cleanup(ch); 553 | free(script_url); 554 | free(http_response); 555 | return NULL; 556 | } 557 | 558 | /* Can't resolve host */ 559 | //if ((strlen(http_response) > 16) || (strncmp(http_response, "0.0.0.0", 7) == 0)) { 560 | if ((strlen(http_response) > 256) || (strncmp(http_response, "0.0.0.0", 7) == 0)) { 561 | /* insert error answers here, as NXDOMAIN, SERVFAIL etc */ 562 | debug_msg ("MALFORMED DNS, or SERVFAIL from origin... investigate !\n"); 563 | curl_easy_cleanup(ch); 564 | free(script_url); 565 | free(http_response); 566 | return NULL; 567 | } 568 | 569 | curl_easy_cleanup(ch); 570 | free(script_url); 571 | curl_slist_free_all(hosting); 572 | return http_response; 573 | } 574 | 575 | /* * main */ 576 | int main(int argc, char *argv[]) 577 | { 578 | int sockfd, 579 | port = DEFAULT_LOCAL_PORT, 580 | wport = DEFAULT_WEB_PORT, 581 | proxy_port = 0, 582 | c; 583 | struct sockaddr_in serv_addr; 584 | struct hostent *local_address; 585 | char *bind_address = NULL, 586 | *proxy_host = NULL, 587 | *proxy_user = NULL, 588 | *proxy_pass = NULL, 589 | *typeq = NULL, 590 | *lookup_script = NULL; 591 | 592 | opterr = 0; 593 | DEBUG = 0; 594 | 595 | /* Command line args */ 596 | while ((c = getopt (argc, argv, "s:p:l:r:h:w:u:k:v::")) != -1) 597 | switch (c) 598 | { 599 | case 'p': 600 | port = atoi(optarg); 601 | if (port <= 0) { 602 | fprintf(stdout," *** Invalid local port\n"); 603 | exit(EXIT_FAILURE); 604 | } 605 | break; 606 | 607 | case 'w': 608 | wport = atoi(optarg); 609 | if (wport <= 0) { 610 | fprintf(stdout," *** Invalid webserver port\n"); 611 | exit(EXIT_FAILURE); 612 | } 613 | break; 614 | 615 | case 'r': 616 | proxy_port = atoi(optarg); 617 | if (proxy_port <= 0) { 618 | fprintf(stdout," *** Invalid proxy port\n"); 619 | exit(EXIT_FAILURE); 620 | } 621 | break; 622 | 623 | case 'v': 624 | DEBUG = 1; 625 | break; 626 | 627 | case 'l': 628 | bind_address = (char *)optarg; 629 | break; 630 | 631 | case 'h': 632 | proxy_host = (char *)optarg; 633 | break; 634 | 635 | case 'u': 636 | proxy_user = (char *)optarg; 637 | break; 638 | 639 | case 'k': 640 | proxy_pass = (char *)optarg; 641 | break; 642 | 643 | case 's': 644 | lookup_script = (char *)optarg; 645 | break; 646 | 647 | case '?': 648 | if (optopt == 'p') 649 | fprintf(stderr," *** Invalid local port\n"); 650 | else 651 | if (optopt == 'w') 652 | fprintf(stderr," *** Invalid webserver port\n"); 653 | else 654 | if (optopt == 'r') 655 | fprintf(stderr," *** Invalid proxy port\n"); 656 | else 657 | if (optopt == 's') 658 | fprintf(stderr," *** Invalid lookup script URL\n"); 659 | else 660 | if (isprint(optopt)) 661 | fprintf(stderr," *** Invalid option -- '%c'\n", optopt); 662 | 663 | usage(); 664 | break; 665 | 666 | default: 667 | abort (); 668 | } 669 | 670 | if ((port == 0) || (proxy_port == 0) || (bind_address == NULL) || (proxy_host == NULL) || (lookup_script == NULL)) 671 | usage(); 672 | 673 | /* Prevent child process from becoming zombie process */ 674 | signal(SIGCLD, SIG_IGN); 675 | /* libCurl init */ 676 | curl_global_init(CURL_GLOBAL_ALL); 677 | /* socket() */ 678 | sockfd = socket(AF_INET, SOCK_DGRAM, 0); 679 | if (sockfd < 0) 680 | error("Error opening socket"); 681 | 682 | bzero((char *) &serv_addr, sizeof(serv_addr)); 683 | local_address = gethostbyname(bind_address); 684 | if (local_address == NULL) 685 | error("Error resolving local host"); 686 | 687 | serv_addr.sin_family = AF_INET; 688 | memcpy (&serv_addr.sin_addr.s_addr, local_address->h_addr,sizeof (struct in_addr)); 689 | serv_addr.sin_port = htons(port); 690 | 691 | /* bind() */ 692 | if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) 693 | error("Error opening socket (bind)"); 694 | 695 | while (1) { 696 | char request[UDP_DATAGRAM_SIZE + 1], 697 | *ip = NULL; 698 | unsigned int request_len, 699 | client_len; 700 | struct dns_request *dns_req; 701 | struct sockaddr_in client; 702 | 703 | client_len = sizeof(client); 704 | request_len = recvfrom(sockfd,request,UDP_DATAGRAM_SIZE,0,(struct sockaddr *)&client,&client_len); 705 | 706 | /* Child */ 707 | if (fork() == 0) 708 | { 709 | dns_req = parse_dns_request(request, request_len); 710 | if (dns_req == NULL) { 711 | //printf("BL: pid [%d] - name %s - host %s - size %d \r\n", getpid(), dns_req->hostname, ip, request_len); 712 | printf("FORK: tid: %x - name %s - size %d \r\n", dns_req->transaction_id, dns_req->hostname, request_len); 713 | exit(EXIT_FAILURE); 714 | } 715 | 716 | if (dns_req->qtype == 0x02) { 717 | typeq = "NS"; 718 | } else if (dns_req->qtype == 0x0c) { 719 | typeq = "PTR"; 720 | } else if (dns_req->qtype == 0x05) { 721 | typeq = "CNAME"; 722 | } else if (dns_req->qtype == 0x01) { 723 | typeq = "A"; 724 | } else if (dns_req->qtype == 0x0f) { 725 | typeq = "MX"; 726 | } //else { dns_req->qtype == 0xff;} 727 | // MAKE BETTER FILTER 728 | 729 | // CORE DNS LOOKUP, MADE ONCE (via HTTP) AND THEN CACHED INTO THE NETWORK 730 | // WITH DOMAIN BLACKLISTING 731 | 732 | //int buffsize = 2048; 733 | //setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &buffsize, sizeof(buffsize)); 734 | ip = lookup_host(dns_req->hostname, proxy_host, proxy_port, proxy_user, proxy_pass, lookup_script, typeq, wport); 735 | 736 | if (ip != NULL) { 737 | //if (ip != NULL && ip != "0.0.0.0") { 738 | //if (ip != NULL && ((strstr(dns_req->hostname, "bbc.com") == NULL ) || (strstr(dns_req->hostname, "skype.com") == NULL )) ) { 739 | build_dns_reponse(sockfd, client, dns_req, ip, DNS_MODE_ANSWER); 740 | free(ip); 741 | } else if (strstr(dns_req->hostname, "hamachi.cc") != NULL ) { 742 | printf("BALCKLIST: pid [%d] - name %s - host %s - size %d \r\n", getpid(), dns_req->hostname, ip, request_len); 743 | build_dns_reponse(sockfd, client, dns_req, ip, DNS_MODE_ANSWER); 744 | free(ip); 745 | } else { 746 | printf("ERROR: pid [%d] - name %s - host %s - size %d \r\n", getpid(), dns_req->hostname, ip, request_len); 747 | build_dns_reponse(sockfd, client, dns_req, ip, DNS_MODE_ERROR); 748 | free(ip); 749 | } 750 | 751 | free(dns_req); 752 | exit(EXIT_SUCCESS); 753 | } 754 | } 755 | --------------------------------------------------------------------------------