Переглянути джерело

Major Update

tags/v0.0.28^0
Peter Vivell 6 роки тому
джерело
коміт
a13b264330

+ 2
- 2
CHANGELOG.md Переглянути файл

@@ -6,6 +6,6 @@ All notable changes to this project will be documented in this file.
6 6
 
7 7
 - Initial release.
8 8
 
9
-## 0.0.25
9
+## 0.0.28
10 10
 
11
-- Improved make system.
11
+- Cleanup and update of libs.

+ 2
- 2
Dockerfile Переглянути файл

@@ -2,11 +2,11 @@ FROM debian:stable-slim
2 2
 ARG MAINTAINER
3 3
 MAINTAINER ${MAINTAINER}
4 4
 
5
-RUN echo 'export http_proxy=$(ip route show default | cut -d' ' -f3):3142' >> /etc/profile
5
+RUN echo 'export http_proxy=$(ip route list exact 0.0.0.0/0 | head -1 | cut -d" " -f3):3142' >> /etc/profile
6 6
 
7 7
 ARG BUILDDEPS
8 8
 RUN apt-get update && \
9 9
     apt-get --yes upgrade && \
10 10
     apt-get --yes install ${BUILDDEPS}
11 11
 
12
-ENTRYPOINT ["/bin/bash", "-c", "#(noop)"]
12
+ENTRYPOINT ["/bin/sh", "-c", "#(noop)"]

+ 0
- 18
Dockerfile.heredoc Переглянути файл

@@ -1,18 +0,0 @@
1
-FROM debian:stable-slim
2
-MAINTAINER Drone CI/CD
3
-
4
-ARG HTTP_PROXY
5
-RUN echo '\
6
-      Acquire::http  { Proxy "'${HTTP_PROXY}'"; } \n\
7
-      Acquire::https { Proxy "https://"; }; \n\
8
-'   >> /etc/apt/apt.conf.d/01-proxy
9
-
10
-RUN ls -l /etc/apt/apt.conf.d/01-proxy
11
-RUN cat /etc/apt/apt.conf.d/01-proxy
12
-
13
-ARG BUILDDEPS
14
-RUN apt-get update && \
15
-    apt-get --yes upgrade && \
16
-    apt-get --yes install ${BUILDDEPS}
17
-
18
-ENTRYPOINT ["/bin/bash", "-c"]

+ 8
- 8
Makefile Переглянути файл

@@ -1,11 +1,11 @@
1
-TARGETS := all dist clean
1
+TARGETS := all
2 2
 
3 3
 #SUBDIRS := $(wildcard */.)
4 4
 SUBDIRS = src src/contrib
5 5
 
6 6
 SUBDIRGOALS := all
7 7
 
8
-SUBDIRSCLEAN=$(addsuffix clean,$(SUBDIRS))
8
+SUBDIRSCLEAN=$(addsuffix -clean,$(SUBDIRS))
9 9
 
10 10
 
11 11
 
@@ -14,7 +14,10 @@ all: $(SUBDIRS) dist
14 14
 $(TARGETS): $(SUBDIRS)
15 15
 
16 16
 $(SUBDIRS):
17
-	$(MAKE) -C $@
17
+	$(MAKE) -C $@ $(SUBDIRGOALS)
18
+
19
+%-clean: %
20
+	$(MAKE) -C $< clean
18 21
 
19 22
 dist:
20 23
 	mkdir -p dist/opt/radangel
@@ -30,13 +33,10 @@ dist:
30 33
 	mkdir -p dist/etc/nginx/sites-available
31 34
 	cp -p config/nginx*.conf dist/etc/nginx/sites-available/
32 35
 
33
-%clean: %
34
-	$(MAKE) -C $< clean
35
-
36
-cleanproj:
36
+dist-clean:
37 37
 	rm -rf dist
38 38
 
39
-clean: $(SUBDIRSCLEAN) cleanproj
39
+clean: $(SUBDIRSCLEAN) dist-clean
40 40
 
41 41
 .PHONY: $(TARGETS) $(SUBDIRS)
42 42
 

+ 0
- 31
config/nginx-datasrc-location.conf Переглянути файл

@@ -1,31 +0,0 @@
1
-    ## <DATASRC> ##
2
-
3
-    location /data/hist.tsv {
4
-        alias /tmp/stats.tsv;
5
-    }
6
-
7
-    location /data/stream.tsv { 
8
-        alias /tmp/event.tsv;
9
-    }
10
-
11
-    location /data/stream.ws {
12
-        proxy_http_version 1.1;
13
-        proxy_set_header Upgrade         $http_upgrade;
14
-        proxy_set_header Connection      "upgrade";
15
-
16
-        proxy_set_header Host            $host; # $http_host;
17
-        proxy_set_header X-Real-IP       $remote_addr;
18
-        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
-        proxy_set_header X-NginX-Proxy   true;
20
-
21
-        proxy_read_timeout 3600;
22
-        proxy_buffering off;
23
-        tcp_nodelay on;
24
-
25
-        error_page 502 = /data/stream.tsv; # serve http for non-ws clients
26
-
27
-        proxy_pass http://127.0.0.1:5800/websockify;
28
-    }
29
-
30
-    ## </DATASRC> ##
31
-

+ 123
- 0
config/nginx-default-datasrc-location.conf Переглянути файл

@@ -0,0 +1,123 @@
1
+##
2
+# You should look at the following URL's in order to grasp a solid understanding
3
+# of Nginx configuration files in order to fully unleash the power of Nginx.
4
+# https://www.nginx.com/resources/wiki/start/
5
+# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
6
+# https://wiki.debian.org/Nginx/DirectoryStructure
7
+#
8
+# In most cases, administrators will remove this file from sites-enabled/ and
9
+# leave it as reference inside of sites-available where it will continue to be
10
+# updated by the nginx packaging team.
11
+#
12
+# This file will automatically load configuration files provided by other
13
+# applications, such as Drupal or Wordpress. These applications will be made
14
+# available underneath a path with that package name, such as /drupal8.
15
+#
16
+# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
17
+##
18
+
19
+# Default server configuration
20
+#
21
+server {
22
+	listen 80 default_server;
23
+	listen [::]:80 default_server;
24
+
25
+	# SSL configuration
26
+	#
27
+	# listen 443 ssl default_server;
28
+	# listen [::]:443 ssl default_server;
29
+	#
30
+	# Note: You should disable gzip for SSL traffic.
31
+	# See: https://bugs.debian.org/773332
32
+	#
33
+	# Read up on ssl_ciphers to ensure a secure configuration.
34
+	# See: https://bugs.debian.org/765782
35
+	#
36
+	# Self signed certs generated by the ssl-cert package
37
+	# Don't use them in a production server!
38
+	#
39
+	# include snippets/snakeoil.conf;
40
+
41
+	root /var/www/html;
42
+
43
+	# Add index.php to the list if you are using PHP
44
+	index index.html index.htm index.nginx-debian.html;
45
+
46
+	server_name _;
47
+
48
+	location / {
49
+		# First attempt to serve request as file, then
50
+		# as directory, then fall back to displaying a 404.
51
+		try_files $uri $uri/ =404;
52
+	}
53
+
54
+	# pass PHP scripts to FastCGI server
55
+	#
56
+	#location ~ \.php$ {
57
+	#	include snippets/fastcgi-php.conf;
58
+	#
59
+	#	# With php-fpm (or other unix sockets):
60
+	#	fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
61
+	#	# With php-cgi (or other tcp sockets):
62
+	#	fastcgi_pass 127.0.0.1:9000;
63
+	#}
64
+
65
+	# deny access to .htaccess files, if Apache's document root
66
+	# concurs with nginx's one
67
+	#
68
+	#location ~ /\.ht {
69
+	#	deny all;
70
+	#}
71
+
72
+    ## <DATASRC> ##
73
+
74
+    location /data/hist.tsv {
75
+        alias /tmp/stats.tsv;
76
+    }
77
+
78
+    location /data/stream.tsv { 
79
+        alias /tmp/event.tsv;
80
+    }
81
+
82
+    location /data/stream.ws {
83
+        proxy_http_version 1.1;
84
+        proxy_set_header Upgrade         $http_upgrade;
85
+        proxy_set_header Connection      "upgrade";
86
+
87
+        proxy_set_header Host            $host; # $http_host;
88
+        proxy_set_header X-Real-IP       $remote_addr;
89
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
90
+        proxy_set_header X-NginX-Proxy   true;
91
+
92
+        proxy_read_timeout 3600;
93
+        proxy_buffering off;
94
+        tcp_nodelay on;
95
+
96
+        error_page 502 = /data/stream.tsv; # serve http for non-ws clients
97
+
98
+        proxy_pass http://127.0.0.1:5800/websockify;
99
+    }
100
+
101
+    ## </DATASRC> ##
102
+
103
+}
104
+
105
+
106
+# Virtual Host configuration for example.com
107
+#
108
+# You can move that to a different file under sites-available/ and symlink that
109
+# to sites-enabled/ to enable it.
110
+#
111
+#server {
112
+#	listen 80;
113
+#	listen [::]:80;
114
+#
115
+#	server_name example.com;
116
+#
117
+#	root /var/www/example.com;
118
+#	index index.html;
119
+#
120
+#	location / {
121
+#		try_files $uri $uri/ =404;
122
+#	}
123
+#}

+ 0
- 61
draft.drone.yml Переглянути файл

@@ -1,61 +0,0 @@
1
-kind: pipeline
2
-name: default
3
-
4
-platform:
5
-  os: linux
6
-  arch: amd64
7
-
8
-steps:
9
-- name: build
10
-  image: debian:stable-slim
11
-  privileged: false
12
-  environment:
13
-    BUILDDEPS: build-essential libc6-dev libhidapi-dev libssl-dev   
14
-    MAKEFLAGS: -j 4
15
-    MAKEDIRS: src          src/contrib
16
-    BINARIES: src/radangel src/contrib/websockify
17
-  commands:
18
-    - | 
19
-      cat >> /etc/apt/apt.conf.d/01-proxy <<-EOF
20
-        Acquire::http  { Proxy "http://172.17.0.1:3142"; }
21
-        Acquire::https { Proxy "https://"; };
22
-      EOF
23
-    - apt-get update && apt-get --yes upgrade
24
-    - apt-get --yes install $BUILDDEPS
25
-    - export MAKEFLAGS
26
-    - for DIR in $MAKEDIRS; do make -C $DIR ; done
27
-    - ls -l  $BINARIES && md5sum $BINARIES
28
-  when:
29
-    branch:
30
-    - master
31
-    event:
32
-    - push
33
-    - tag
34
-
35
-- name: release
36
-  image: plugins/gitea-release
37
-  depends_on: 
38
-    - build
39
-  settings:
40
-    api_key:
41
-      from_secret: gitea-release
42
-    base_url: https://git.unino.de
43
-    files:
44
-      - src/radangel
45
-      - src/contrib/websockify
46
-    file_exists: overwrite
47
-    checksum:
48
-      - md5
49
-      - sha1
50
-      - sha256
51
-      - sha512
52
-      - adler32
53
-      - crc32
54
-    draft: true
55
-    prerelease: true
56
-    note: CHANGELOG.md
57
-    title: Release
58
-    insecure: false
59
-  when:
60
-    branch: master
61
-    event: tag

+ 5
- 11
drone.yml Переглянути файл

@@ -15,8 +15,6 @@ clone:
15 15
 steps:
16 16
 
17 17
 
18
-
19
-
20 18
 #http://plugins.drone.io/drone-plugins/drone-docker/
21 19
 #https://github.com/drone-plugins/drone-docker
22 20
 - name: prepare
@@ -32,19 +30,16 @@ steps:
32 30
       from_secret: reg-user
33 31
     password:
34 32
       from_secret: reg-pass
35
-    repo: reg.unino.de/library/debian-devel
33
+    repo: reg.unino.de/develop/debian-${DRONE_REPO_NAME}:stable-slim
36 34
     #mirror: registry.hub.docker.com/library/busybox
37
-
38
-    bip: 172.17.0.1/24
35
+    #bip: 172.17.0.1/24
39 36
     context: /drone
40 37
     #custom_dns: 127.0.0.11
41 38
     storage_driver: overlay2 # aufs, overlay or vfs
42
-
43 39
     #debug: true
44 40
     #launch_debug: true
45 41
     #target: production # build target from dockerfile, e.g. production, debug
46 42
     dockerfile: Dockerfile
47
-
48 43
     auto_tag: false
49 44
     auto_tag_suffix: linux-amd64
50 45
     force_tag: true
@@ -55,11 +50,8 @@ steps:
55 50
       - BUILDDEPS=build-essential libc6-dev libhidapi-dev libssl-dev zip
56 51
 
57 52
 
58
-
59
-
60
-
61 53
 - name: build
62
-  image: reg.unino.de/library/debian-devel:latest
54
+  image: reg.unino.de/develop/debian-${DRONE_REPO_NAME}:stable-slim
63 55
   when:
64 56
     event: [ push, tag ]
65 57
   depends_on: [ prepare ]
@@ -84,6 +76,7 @@ steps:
84 76
       find release -type f -exec md5sum '{}' \;
85 77
     - printf '\n\n\n======= BUILD FINISHED. =======\n\n\n'
86 78
 
79
+
87 80
 # http://plugins.drone.io/drone-plugins/drone-gpgsign/
88 81
 # https://github.com/drone-plugins/drone-gpgsign
89 82
 - name: sign
@@ -103,6 +96,7 @@ steps:
103 96
     excludes:
104 97
       - release/*.asc
105 98
 
99
+
106 100
 # http://plugins.drone.io/drone-plugins/drone-gitea-release/
107 101
 # https://github.com/drone-plugins/drone-gitea-release
108 102
 - name: release

+ 3048
- 2589
html/js/chroma.js
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 57
- 32
html/js/chroma.min.js
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 1
- 1
html/js/get.sh Переглянути файл

@@ -22,4 +22,4 @@ wget 'https://github.com/gka/chroma.js/raw/master/chroma.min.js'
22 22
 #wget 'https://tonejs.github.io/build/Tone.min.js'
23 23
 
24 24
 # nginx gzip_static on;
25
-for F in *.js ; do cat $F | gzip -9 > $F.gz ; done
25
+#for F in *.js ; do cat $F | gzip -9 > $F.gz ; done

+ 9559
- 6251
html/js/plotly-cartesian-latest.js
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 3
- 3
html/js/plotly-cartesian-latest.min.js
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 1
- 2
src/contrib/Makefile Переглянути файл

@@ -3,12 +3,11 @@ CFLAGS += -fPIC
3 3
 
4 4
 all: $(TARGETS)
5 5
 
6
-websockify: websockify.o websocket.o base64.o
6
+websockify: websockify.o websocket.o
7 7
 	$(CC) $(LDFLAGS) $^ -lssl -lcrypto -o $@
8 8
 
9 9
 websocket.o: websocket.c websocket.h
10 10
 websockify.o: websockify.c websocket.h
11
-base64.o: base64.c
12 11
 
13 12
 clean:
14 13
 	rm -f websockify *.o

+ 0
- 313
src/contrib/base64.c Переглянути файл

@@ -1,313 +0,0 @@
1
-/*
2
- * Copyright (c) 1996-1999 by Internet Software Consortium.
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15
- * SOFTWARE.
16
- */
17
-
18
-/*
19
- * Portions Copyright (c) 1995 by International Business Machines, Inc.
20
- *
21
- * International Business Machines, Inc. (hereinafter called IBM) grants
22
- * permission under its copyrights to use, copy, modify, and distribute this
23
- * Software with or without fee, provided that the above copyright notice and
24
- * all paragraphs of this notice appear in all copies, and that the name of IBM
25
- * not be used in connection with the marketing of any product incorporating
26
- * the Software or modifications thereof, without specific, written prior
27
- * permission.
28
- *
29
- * To the extent it has a right to do so, IBM grants an immunity from suit
30
- * under its patents, if any, for the use, sale or manufacture of products to
31
- * the extent that such products are used for performing Domain Name System
32
- * dynamic updates in TCP/IP networks by means of the Software.  No immunity is
33
- * granted for any product per se or for any other function of any product.
34
- *
35
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
36
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37
- * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
38
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
39
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
40
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
41
- */
42
-
43
-#if !defined(LINT) && !defined(CODECENTER)
44
-static const char rcsid[] = "$BINDId: base64.c,v 8.7 1999/10/13 16:39:33 vixie Exp $";
45
-#endif /* not lint */
46
-
47
-#include <sys/types.h>
48
-#include <sys/param.h>
49
-#include <sys/socket.h>
50
-
51
-#include <netinet/in.h>
52
-#include <arpa/inet.h>
53
-#include <arpa/nameser.h>
54
-
55
-#include <ctype.h>
56
-#include <resolv.h>
57
-#include <stdio.h>
58
-#include <stdlib.h>
59
-#include <string.h>
60
-
61
-#define Assert(Cond) if (!(Cond)) abort()
62
-
63
-static const char Base64[] =
64
-	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
65
-static const char Pad64 = '=';
66
-
67
-/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
68
-   The following encoding technique is taken from RFC 1521 by Borenstein
69
-   and Freed.  It is reproduced here in a slightly edited form for
70
-   convenience.
71
-
72
-   A 65-character subset of US-ASCII is used, enabling 6 bits to be
73
-   represented per printable character. (The extra 65th character, "=",
74
-   is used to signify a special processing function.)
75
-
76
-   The encoding process represents 24-bit groups of input bits as output
77
-   strings of 4 encoded characters. Proceeding from left to right, a
78
-   24-bit input group is formed by concatenating 3 8-bit input groups.
79
-   These 24 bits are then treated as 4 concatenated 6-bit groups, each
80
-   of which is translated into a single digit in the base64 alphabet.
81
-
82
-   Each 6-bit group is used as an index into an array of 64 printable
83
-   characters. The character referenced by the index is placed in the
84
-   output string.
85
-
86
-                         Table 1: The Base64 Alphabet
87
-
88
-      Value Encoding  Value Encoding  Value Encoding  Value Encoding
89
-          0 A            17 R            34 i            51 z
90
-          1 B            18 S            35 j            52 0
91
-          2 C            19 T            36 k            53 1
92
-          3 D            20 U            37 l            54 2
93
-          4 E            21 V            38 m            55 3
94
-          5 F            22 W            39 n            56 4
95
-          6 G            23 X            40 o            57 5
96
-          7 H            24 Y            41 p            58 6
97
-          8 I            25 Z            42 q            59 7
98
-          9 J            26 a            43 r            60 8
99
-         10 K            27 b            44 s            61 9
100
-         11 L            28 c            45 t            62 +
101
-         12 M            29 d            46 u            63 /
102
-         13 N            30 e            47 v
103
-         14 O            31 f            48 w         (pad) =
104
-         15 P            32 g            49 x
105
-         16 Q            33 h            50 y
106
-
107
-   Special processing is performed if fewer than 24 bits are available
108
-   at the end of the data being encoded.  A full encoding quantum is
109
-   always completed at the end of a quantity.  When fewer than 24 input
110
-   bits are available in an input group, zero bits are added (on the
111
-   right) to form an integral number of 6-bit groups.  Padding at the
112
-   end of the data is performed using the '=' character.
113
-
114
-   Since all base64 input is an integral number of octets, only the
115
-         -------------------------------------------------
116
-   following cases can arise:
117
-
118
-       (1) the final quantum of encoding input is an integral
119
-           multiple of 24 bits; here, the final unit of encoded
120
-	   output will be an integral multiple of 4 characters
121
-	   with no "=" padding,
122
-       (2) the final quantum of encoding input is exactly 8 bits;
123
-           here, the final unit of encoded output will be two
124
-	   characters followed by two "=" padding characters, or
125
-       (3) the final quantum of encoding input is exactly 16 bits;
126
-           here, the final unit of encoded output will be three
127
-	   characters followed by one "=" padding character.
128
-   */
129
-
130
-int
131
-ws_b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
132
-	size_t datalength = 0;
133
-	u_char input[3];
134
-	u_char output[4];
135
-	size_t i;
136
-
137
-	while (2 < srclength) {
138
-		input[0] = *src++;
139
-		input[1] = *src++;
140
-		input[2] = *src++;
141
-		srclength -= 3;
142
-
143
-		output[0] = input[0] >> 2;
144
-		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
145
-		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
146
-		output[3] = input[2] & 0x3f;
147
-		Assert(output[0] < 64);
148
-		Assert(output[1] < 64);
149
-		Assert(output[2] < 64);
150
-		Assert(output[3] < 64);
151
-
152
-		if (datalength + 4 > targsize)
153
-			return (-1);
154
-		target[datalength++] = Base64[output[0]];
155
-		target[datalength++] = Base64[output[1]];
156
-		target[datalength++] = Base64[output[2]];
157
-		target[datalength++] = Base64[output[3]];
158
-	}
159
-
160
-	/* Now we worry about padding. */
161
-	if (0 != srclength) {
162
-		/* Get what's left. */
163
-		input[0] = input[1] = input[2] = '\0';
164
-		for (i = 0; i < srclength; i++)
165
-			input[i] = *src++;
166
-
167
-		output[0] = input[0] >> 2;
168
-		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
169
-		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
170
-		Assert(output[0] < 64);
171
-		Assert(output[1] < 64);
172
-		Assert(output[2] < 64);
173
-
174
-		if (datalength + 4 > targsize)
175
-			return (-1);
176
-		target[datalength++] = Base64[output[0]];
177
-		target[datalength++] = Base64[output[1]];
178
-		if (srclength == 1)
179
-			target[datalength++] = Pad64;
180
-		else
181
-			target[datalength++] = Base64[output[2]];
182
-		target[datalength++] = Pad64;
183
-	}
184
-	if (datalength >= targsize)
185
-		return (-1);
186
-	target[datalength] = '\0';	/* Returned value doesn't count \0. */
187
-	return (datalength);
188
-}
189
-//libresolv_hidden_def (b64_ntop)
190
-
191
-/* skips all whitespace anywhere.
192
-   converts characters, four at a time, starting at (or after)
193
-   src from base - 64 numbers into three 8 bit bytes in the target area.
194
-   it returns the number of data bytes stored at the target, or -1 on error.
195
- */
196
-
197
-int
198
-ws_b64_pton(char const *src, u_char *target, size_t targsize) {
199
-	int tarindex, state, ch;
200
-	char *pos;
201
-
202
-	state = 0;
203
-	tarindex = 0;
204
-
205
-	while ((ch = *src++) != '\0') {
206
-		if (isspace(ch))	/* Skip whitespace anywhere. */
207
-			continue;
208
-
209
-		if (ch == Pad64)
210
-			break;
211
-
212
-		pos = strchr(Base64, ch);
213
-		if (pos == 0) 		/* A non-base64 character. */
214
-			return (-1);
215
-
216
-		switch (state) {
217
-		case 0:
218
-			if (target) {
219
-				if ((size_t)tarindex >= targsize)
220
-					return (-1);
221
-				target[tarindex] = (pos - Base64) << 2;
222
-			}
223
-			state = 1;
224
-			break;
225
-		case 1:
226
-			if (target) {
227
-				if ((size_t)tarindex + 1 >= targsize)
228
-					return (-1);
229
-				target[tarindex]   |=  (pos - Base64) >> 4;
230
-				target[tarindex+1]  = ((pos - Base64) & 0x0f)
231
-							<< 4 ;
232
-			}
233
-			tarindex++;
234
-			state = 2;
235
-			break;
236
-		case 2:
237
-			if (target) {
238
-				if ((size_t)tarindex + 1 >= targsize)
239
-					return (-1);
240
-				target[tarindex]   |=  (pos - Base64) >> 2;
241
-				target[tarindex+1]  = ((pos - Base64) & 0x03)
242
-							<< 6;
243
-			}
244
-			tarindex++;
245
-			state = 3;
246
-			break;
247
-		case 3:
248
-			if (target) {
249
-				if ((size_t)tarindex >= targsize)
250
-					return (-1);
251
-				target[tarindex] |= (pos - Base64);
252
-			}
253
-			tarindex++;
254
-			state = 0;
255
-			break;
256
-		default:
257
-			abort();
258
-		}
259
-	}
260
-
261
-	/*
262
-	 * We are done decoding Base-64 chars.  Let's see if we ended
263
-	 * on a byte boundary, and/or with erroneous trailing characters.
264
-	 */
265
-
266
-	if (ch == Pad64) {		/* We got a pad char. */
267
-		ch = *src++;		/* Skip it, get next. */
268
-		switch (state) {
269
-		case 0:		/* Invalid = in first position */
270
-		case 1:		/* Invalid = in second position */
271
-			return (-1);
272
-
273
-		case 2:		/* Valid, means one byte of info */
274
-			/* Skip any number of spaces. */
275
-			for ((void)NULL; ch != '\0'; ch = *src++)
276
-				if (!isspace(ch))
277
-					break;
278
-			/* Make sure there is another trailing = sign. */
279
-			if (ch != Pad64)
280
-				return (-1);
281
-			ch = *src++;		/* Skip the = */
282
-			/* Fall through to "single trailing =" case. */
283
-			/* FALLTHROUGH */
284
-
285
-		case 3:		/* Valid, means two bytes of info */
286
-			/*
287
-			 * We know this char is an =.  Is there anything but
288
-			 * whitespace after it?
289
-			 */
290
-			for ((void)NULL; ch != '\0'; ch = *src++)
291
-				if (!isspace(ch))
292
-					return (-1);
293
-
294
-			/*
295
-			 * Now make sure for cases 2 and 3 that the "extra"
296
-			 * bits that slopped past the last full byte were
297
-			 * zeros.  If we don't check them, they become a
298
-			 * subliminal channel.
299
-			 */
300
-			if (target && target[tarindex] != 0)
301
-				return (-1);
302
-		}
303
-	} else {
304
-		/*
305
-		 * We ended by seeing the end of the string.  Make sure we
306
-		 * have no partial bytes lying around.
307
-		 */
308
-		if (state != 0)
309
-			return (-1);
310
-	}
311
-
312
-	return (tarindex);
313
-}

+ 85
- 39
src/contrib/websocket.c Переглянути файл

@@ -11,7 +11,7 @@
11 11
 #include <stdio.h>
12 12
 #include <stdlib.h>
13 13
 #include <errno.h>
14
-#include <strings.h>
14
+#include <string.h>
15 15
 #include <sys/types.h> 
16 16
 #include <sys/socket.h>
17 17
 #include <sys/stat.h>
@@ -22,13 +22,11 @@
22 22
 #include <fcntl.h>  // daemonizing
23 23
 #include <openssl/err.h>
24 24
 #include <openssl/ssl.h>
25
+#include <openssl/bio.h> /* base64 encode/decode */
25 26
 #include <openssl/md5.h> /* md5 hash */
26 27
 #include <openssl/sha.h> /* sha1 hash */
27 28
 #include "websocket.h"
28 29
 
29
-int ws_b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize);
30
-int ws_b64_pton(char const *src, u_char *target, size_t targsize);
31
-
32 30
 /*
33 31
  * Global state
34 32
  *
@@ -159,7 +157,8 @@ ws_ctx_t *ws_socket_ssl(ws_ctx_t *ctx, int socket, char * certfile, char * keyfi
159 157
 
160 158
     }
161 159
 
162
-    ctx->ssl_ctx = SSL_CTX_new(TLSv1_server_method());
160
+    //ctx->ssl_ctx = SSL_CTX_new(TLSv1_server_method());
161
+    ctx->ssl_ctx = SSL_CTX_new(TLS_server_method());
163 162
     if (ctx->ssl_ctx == NULL) {
164 163
         ERR_print_errors_fp(stderr);
165 164
         fatal("Failed to configure SSL context");
@@ -171,8 +170,7 @@ ws_ctx_t *ws_socket_ssl(ws_ctx_t *ctx, int socket, char * certfile, char * keyfi
171 170
         fatal(msg);
172 171
     }
173 172
 
174
-    if (SSL_CTX_use_certificate_file(ctx->ssl_ctx, certfile,
175
-                                     SSL_FILETYPE_PEM) <= 0) {
173
+    if (SSL_CTX_use_certificate_chain_file(ctx->ssl_ctx, certfile) <= 0) {
176 174
         sprintf(msg, "Unable to load certificate file %s\n", certfile);
177 175
         fatal(msg);
178 176
     }
@@ -211,6 +209,72 @@ void ws_socket_free(ws_ctx_t *ctx) {
211 209
     }
212 210
 }
213 211
 
212
+int ws_b64_ntop(const unsigned char const * src, size_t srclen, char * dst, size_t dstlen) {
213
+    int len = 0;
214
+    int total_len = 0;
215
+
216
+    BIO *buff, *b64f;
217
+    BUF_MEM *ptr;
218
+
219
+    b64f = BIO_new(BIO_f_base64());
220
+    buff = BIO_new(BIO_s_mem());
221
+    buff = BIO_push(b64f, buff);
222
+
223
+    BIO_set_flags(buff, BIO_FLAGS_BASE64_NO_NL);
224
+    BIO_set_close(buff, BIO_CLOSE);
225
+    do {
226
+        len = BIO_write(buff, src + total_len, srclen - total_len);
227
+        if (len > 0)
228
+            total_len += len;
229
+    } while (len && BIO_should_retry(buff));
230
+
231
+    BIO_flush(buff);
232
+
233
+    BIO_get_mem_ptr(buff, &ptr);
234
+    len = ptr->length;
235
+
236
+    memcpy(dst, ptr->data, dstlen < len ? dstlen : len);
237
+    dst[dstlen < len ? dstlen : len] = '\0';
238
+
239
+    BIO_free_all(buff);
240
+
241
+    if (dstlen < len)
242
+        return -1;
243
+
244
+    return len;
245
+}
246
+
247
+int ws_b64_pton(const char const * src, unsigned char * dst, size_t dstlen) {
248
+    int len = 0;
249
+    int total_len = 0;
250
+    int pending = 0;
251
+
252
+    BIO *buff, *b64f;
253
+
254
+    b64f = BIO_new(BIO_f_base64());
255
+    buff = BIO_new_mem_buf(src, -1);
256
+    buff = BIO_push(b64f, buff);
257
+
258
+    BIO_set_flags(buff, BIO_FLAGS_BASE64_NO_NL);
259
+    BIO_set_close(buff, BIO_CLOSE);
260
+    do {
261
+        len = BIO_read(buff, dst + total_len, dstlen - total_len);
262
+        if (len > 0)
263
+            total_len += len;
264
+    } while (len && BIO_should_retry(buff));
265
+
266
+    dst[total_len] = '\0';
267
+
268
+    pending = BIO_ctrl_pending(buff);
269
+
270
+    BIO_free_all(buff);
271
+
272
+    if (pending)
273
+        return -1;
274
+
275
+    return len;
276
+}
277
+
214 278
 /* ------------------------------------------------------- */
215 279
 
216 280
 
@@ -272,7 +336,7 @@ int decode_hixie(char *src, size_t srclength,
272 336
 int encode_hybi(u_char const *src, size_t srclength,
273 337
                 char *target, size_t targsize, unsigned int opcode)
274 338
 {
275
-    unsigned long long b64_sz, len_offset = 1, payload_offset = 2;
339
+    unsigned long long payload_offset = 2;
276 340
     int len = 0;
277 341
 
278 342
     if (opcode != OPCODE_TEXT && opcode != OPCODE_BINARY) {
@@ -666,22 +730,20 @@ ws_ctx_t *do_handshake(int sock) {
666 730
 
667 731
     headers = ws_ctx->headers;
668 732
 
669
-    if (strstr(headers->protocols, "binary")) {
670
-      ws_ctx->opcode = OPCODE_BINARY;
671
-      response_protocol = "binary";
672
-    } else if (strstr(headers->protocols, "base64")) {
733
+    response_protocol = strtok(headers->protocols, ",");
734
+    if (!response_protocol || !strlen(response_protocol)) {
735
+        ws_ctx->opcode = OPCODE_BINARY;
736
+        response_protocol = "null";
737
+    } else if (!strcmp(response_protocol, "base64")) {
673 738
       ws_ctx->opcode = OPCODE_TEXT;
674
-      response_protocol = "base64";
675 739
     } else {
676
-      handler_emsg("Invalid protocol '%s', expecting 'binary' or 'base64'\n",
677
-          headers->protocols);
678
-      return NULL;
740
+        ws_ctx->opcode = OPCODE_BINARY;
679 741
     }
680 742
 
681 743
     if (ws_ctx->hybi > 0) {
682 744
         handler_msg("using protocol HyBi/IETF 6455 %d\n", ws_ctx->hybi);
683 745
         gen_sha1(headers, sha1);
684
-        sprintf(response, SERVER_HANDSHAKE_HYBI, sha1, response_protocol);
746
+        snprintf(response, sizeof(response), SERVER_HANDSHAKE_HYBI, sha1, response_protocol);
685 747
     } else {
686 748
         if (ws_ctx->hixie == 76) {
687 749
             handler_msg("using protocol Hixie 76\n");
@@ -692,8 +754,8 @@ ws_ctx_t *do_handshake(int sock) {
692 754
             trailer[0] = '\0';
693 755
             pre = "";
694 756
         }
695
-        sprintf(response, SERVER_HANDSHAKE_HIXIE, pre, headers->origin, pre, scheme,
696
-                headers->host, headers->path, pre, "base64", trailer);
757
+        snprintf(response, sizeof(response), SERVER_HANDSHAKE_HIXIE, pre, headers->origin,
758
+                 pre, scheme, headers->host, headers->path, pre, "base64", trailer);
697 759
     }
698 760
     
699 761
     //handler_msg("response: %s\n", response);
@@ -704,16 +766,9 @@ ws_ctx_t *do_handshake(int sock) {
704 766
 
705 767
 void signal_handler(int sig) {
706 768
     switch (sig) {
707
-        case SIGHUP:
708
-            if (settings.whitelist != NULL) {
709
-              load_whitelist();
710
-            }
711
-            break;
769
+        case SIGHUP: break; // ignore for now
712 770
         case SIGPIPE: pipe_error = 1; break; // handle inline
713
-        case SIGTERM:
714
-            remove(settings.pid);
715
-            exit(0);
716
-            break;
771
+        case SIGTERM: exit(0); break;
717 772
     }
718 773
 }
719 774
 
@@ -732,17 +787,7 @@ void daemonize(int keepfd) {
732 787
     setsid();                // Obtain new process group
733 788
     pid = fork();
734 789
     if (pid<0) { fatal("fork error"); }
735
-    if (pid>0) {
736
-      // parent exits
737
-      FILE *pidf = fopen(settings.pid, "w");
738
-      if (pidf) {
739
-        fprintf(pidf, "%d", pid);
740
-        fclose(pidf);
741
-      } else {
742
-        fprintf(stderr, "Could not write daemon PID file '%s': %s\n", settings.pid, strerror(errno));
743
-      }
744
-      exit(0);
745
-    }
790
+    if (pid>0) { exit(0); }  // parent exits
746 791
 
747 792
     /* Signal handling */
748 793
     signal(SIGHUP, signal_handler);   // catch HUP
@@ -847,6 +892,7 @@ void start_server() {
847 892
             break;   // Child process exits
848 893
         } else {         // parent process
849 894
             settings.handler_id += 1;
895
+            close(csock);
850 896
         }
851 897
     }
852 898
     if (pid == 0) {

+ 9
- 14
src/contrib/websocket.h Переглянути файл

@@ -66,12 +66,11 @@ typedef struct {
66 66
     int ssl_only;
67 67
     int daemon;
68 68
     int run_once;
69
-    char *whitelist;
70
-    char *pattern;
71
-    char *pid;
72 69
 } settings_t;
73 70
 
74 71
 
72
+int resolve_host(struct in_addr *sin_addr, const char *hostname);
73
+
75 74
 ssize_t ws_recv(ws_ctx_t *ctx, void *buf, size_t len);
76 75
 
77 76
 ssize_t ws_send(ws_ctx_t *ctx, const void *buf, size_t len);
@@ -89,21 +88,17 @@ ssize_t ws_send(ws_ctx_t *ctx, const void *buf, size_t len);
89 88
 #define handler_msg(...) gen_handler_msg(stdout, __VA_ARGS__);
90 89
 #define handler_emsg(...) gen_handler_msg(stderr, __VA_ARGS__);
91 90
 
92
-/* forward declarations */
93 91
 void traffic(const char * token);
94
-int encode_hybi(u_char const *src, size_t srclength,
95
-                char *target, size_t targsize, unsigned int opcode);
92
+
96 93
 int encode_hixie(u_char const *src, size_t srclength,
97 94
                  char *target, size_t targsize);
98
-int decode_hybi(unsigned char *src, size_t srclength,
99
-                u_char *target, size_t targsize,
100
-                unsigned int *opcode, unsigned int *left);
101 95
 int decode_hixie(char *src, size_t srclength,
102 96
                  u_char *target, size_t targsize,
103 97
                  unsigned int *opcode, unsigned int *left);
104
-int resolve_host(struct in_addr *sin_addr, const char *hostname);
105
-void start_server();
106
-
107
-
108
-int load_whitelist();
98
+int encode_hybi(u_char const *src, size_t srclength,
99
+                char *target, size_t targsize, unsigned int opcode);
100
+int decode_hybi(unsigned char *src, size_t srclength,
101
+                u_char *target, size_t targsize,
102
+                unsigned int *opcode, unsigned int *left);
109 103
 
104
+void start_server();

+ 32
- 143
src/contrib/websockify.c Переглянути файл

@@ -11,6 +11,7 @@
11 11
 #include <errno.h>
12 12
 #include <limits.h>
13 13
 #include <getopt.h>
14
+#include <string.h>
14 15
 #include <sys/socket.h>
15 16
 #include <netinet/in.h>
16 17
 #include <netdb.h>
@@ -18,15 +19,8 @@
18 19
 #include <fcntl.h>
19 20
 #include <unistd.h>
20 21
 #include <sys/stat.h>
21
-#include <signal.h>
22 22
 #include "websocket.h"
23 23
 
24
-
25
-
26
-
27
-
28
-
29
-
30 24
 char traffic_legend[] = "\n\
31 25
 Traffic Legend:\n\
32 26
     }  - Client receive\n\
@@ -40,30 +34,22 @@ Traffic Legend:\n\
40 34
 ";
41 35
 
42 36
 char USAGE[] = "Usage: [options] " \
43
-               "[source_addr:]source_port target_addr{:target_port}\n\n" \
44
-               "  --verbose|-v         verbose messages and per frame traffic\n" \
45
-               "  --daemon|-D          become a daemon (background process)\n" \
46
-               "  --run-once           handle a single WebSocket connection and exit\n" \
47
-               "  --cert CERT          SSL certificate file\n" \
48
-               "  --key KEY            SSL key file (if separate from cert)\n" \
49
-               "  --ssl-only           disallow non-encrypted connections\n" \
50
-               "  --whitelist|-w LIST  new-line separated target port whitelist file\n" \
51
-               "                       (target_port is not required only with this option)\n" \
52
-               "  --pattern|-P         target port request pattern. Default: '/%d'\n" \
53
-               "  --pid|-p             desired path of pid file. Default: '/var/run/websockify.pid'";
37
+               "[source_addr:]source_port target_addr:target_port\n\n" \
38
+               "  --verbose|-v       verbose messages and per frame traffic\n" \
39
+               "  --daemon|-D        become a daemon (background process)\n" \
40
+               "  --run-once         handle a single WebSocket connection and exit\n" \
41
+               "  --cert CERT        SSL certificate file\n" \
42
+               "  --key KEY          SSL key file (if separate from cert)\n" \
43
+               "  --ssl-only         disallow non-encrypted connections";
54 44
 
55 45
 #define usage(fmt, args...) \
56
-    do { \
57
-        fprintf(stderr, "%s\n\n", USAGE); \
58
-        fprintf(stderr, fmt , ## args); \
59
-        exit(1); \
60
-    } while(0)
46
+    fprintf(stderr, "%s\n\n", USAGE); \
47
+    fprintf(stderr, fmt , ## args); \
48
+    exit(1);
61 49
 
62 50
 char target_host[256];
63 51
 int target_port;
64
-int *target_ports;
65 52
 
66
-//extern pipe_error;
67 53
 extern int pipe_error;
68 54
 extern settings_t settings;
69 55
 
@@ -253,27 +239,6 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
253 239
     int tsock = 0;
254 240
     struct sockaddr_in taddr;
255 241
 
256
-    if (target_ports != NULL) {
257
-        if (sscanf(ws_ctx->headers->path, settings.pattern, &target_port) != 1) {
258
-        handler_emsg("Could not match pattern '%s' to request path '%s'\n",
259
-                     settings.pattern, ws_ctx->headers->path);
260
-        return;
261
-        }
262
-        int *p;
263
-        int found = 0;
264
-        for (p = target_ports; *p; p++) {
265
-            if (*p == target_port) {
266
-                found = 1;
267
-                break;
268
-            }
269
-        }
270
-        if (!found) {
271
-            handler_emsg("Rejecting connection to non-whitelisted port: '%d'\n",
272
-                         target_port);
273
-            return;
274
-        }
275
-    }
276
-
277 242
     handler_msg("connecting to: %s:%d\n", target_host, target_port);
278 243
 
279 244
     tsock = socket(AF_INET, SOCK_STREAM, 0);
@@ -309,77 +274,19 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
309 274
     close(tsock);
310 275
 }
311 276
 
312
-int load_whitelist() {
313
-  printf("loading port whitelist '%s'\n", settings.whitelist);
314
-  FILE *whitelist = fopen(settings.whitelist, "r");
315
-  if (whitelist == NULL) {
316
-    fprintf(stderr, "Error opening whitelist file '%s':\n\t%s\n",
317
-          settings.whitelist, strerror(errno));
318
-    return -1;
319
-  }
320
-
321
-  const int tplen_grow = 512;
322
-  int tplen = tplen_grow, tpcount = 0;
323
-  target_ports = (int*)malloc(tplen*sizeof(int));
324
-  if (target_ports == NULL) {
325
-    fprintf(stderr, "Whitelist port malloc error");
326
-    return -2;
327
-  }
328
-
329
-  char *line = NULL;
330
-  ssize_t n = 0, nread = 0;
331
-  while ((nread = getline(&line, &n, whitelist)) > 0) {
332
-      if (line[0] == '\n') continue;
333
-      line[nread-1] = '\x00';
334
-      long int port = strtol(line, NULL, 10);
335
-      if (port < 1 || port > 65535) {
336
-          fprintf(stderr,
337
-            "Whitelist port '%s' is not between valid range 1 and 65535", line);
338
-          return -3;
339
-      }
340
-      tpcount++;
341
-      if (tpcount >= tplen) {
342
-          tplen += tplen_grow;
343
-          target_ports = (int*)realloc(target_ports, tplen*sizeof(int));
344
-          if (target_ports == NULL) {
345
-              fprintf(stderr, "Whitelist port realloc error");
346
-              return -2;
347
-          }
348
-      }
349
-      target_ports[tpcount-1] = port;
350
-  }
351
-  if (line != NULL) free(line);
352
-
353
-  if (tpcount == 0) {
354
-      fprintf(stderr, "0 ports read from whitelist file '%s'\n",
355
-                      settings.whitelist);
356
-      return -4;
357
-  }
358
-
359
-  target_ports = (int*)realloc(target_ports, (tpcount + 1)*sizeof(int));
360
-  if (target_ports == NULL) {
361
-      fprintf(stderr, "Whitelist port realloc error");
362
-      return -2;
363
-  }
364
-  target_ports[tpcount] = 0;
365
-  return 0;
366
-}
367
-
368 277
 int main(int argc, char *argv[])
369 278
 {
370 279
     int fd, c, option_index = 0;
280
+    static int ssl_only = 0, daemon = 0, run_once = 0, verbose = 0;
371 281
     char *found;
372 282
     static struct option long_options[] = {
373
-        {"verbose",   no_argument,       0,                 'v'},
374
-        {"ssl-only",  no_argument,       &settings.ssl_only, 1 },
375
-        {"daemon",    no_argument,       0,                 'D'},
283
+        {"verbose",    no_argument,       &verbose,    'v'},
284
+        {"ssl-only",   no_argument,       &ssl_only,    1 },
285
+        {"daemon",     no_argument,       &daemon,     'D'},
376 286
         /* ---- */
377
-        {"run-once",  no_argument,       0,                 'r'},
378
-        {"cert",      required_argument, 0,                 'c'},
379
-        {"key",       required_argument, 0,                 'k'},
380
-        {"whitelist", required_argument, 0,                 'w'},
381
-        {"pattern",   required_argument, 0,                 'P'},
382
-        {"pid",       required_argument, 0,                 'p'},
287
+        {"run-once",   no_argument,       0,           'r'},
288
+        {"cert",       required_argument, 0,           'c'},
289
+        {"key",        required_argument, 0,           'k'},
383 290
         {0, 0, 0, 0}
384 291
     };
385 292
 
@@ -389,15 +296,13 @@ int main(int argc, char *argv[])
389 296
         settings.cert = "self.pem";
390 297
     }
391 298
     settings.key = "";
392
-    settings.pattern = "/%d";
393
-    settings.pid = "/var/run/websockify.pid";
394 299
 
395 300
     while (1) {
396
-        c = getopt_long (argc, argv, "vDrc:k:w:p:P:",
301
+        c = getopt_long (argc, argv, "vDrc:k:",
397 302
                          long_options, &option_index);
398 303
 
399 304
         /* Detect the end */
400
-        if (c == -1) break;
305
+        if (c == -1) { break; }
401 306
 
402 307
         switch (c) {
403 308
             case 0:
@@ -405,13 +310,13 @@ int main(int argc, char *argv[])
405 310
             case 1:
406 311
                 break; // ignore
407 312
             case 'v':
408
-                settings.verbose = 1;
313
+                verbose = 1;
409 314
                 break;
410 315
             case 'D':
411
-                settings.daemon = 1;
316
+                daemon = 1;
412 317
                 break;
413 318
             case 'r':
414
-                settings.run_once = 1;
319
+                run_once = 1;
415 320
                 break;
416 321
             case 'c':
417 322
                 settings.cert = realpath(optarg, NULL);
@@ -425,22 +330,14 @@ int main(int argc, char *argv[])
425 330
                     usage("No key file at %s\n", optarg);
426 331
                 }
427 332
                 break;
428
-            case 'w':
429
-                settings.whitelist = realpath(optarg, NULL);
430
-                if (! settings.whitelist) {
431
-                    usage("No whitelist file at %s\n", optarg);
432
-                }
433
-                break;
434
-            case 'P':
435
-                settings.pattern = optarg;
436
-                break;
437
-            case 'p':
438
-                settings.pid = optarg;
439
-                break;
440 333
             default:
441
-                usage(" ");
334
+                usage("\n");
442 335
         }
443 336
     }
337
+    settings.verbose      = verbose;
338
+    settings.ssl_only     = ssl_only;
339
+    settings.daemon       = daemon;
340
+    settings.run_once     = run_once;
444 341
 
445 342
     if ((argc-optind) != 2) {
446 343
         usage("Invalid number of arguments\n");
@@ -460,25 +357,17 @@ int main(int argc, char *argv[])
460 357
     }
461 358
 
462 359
     found = strstr(argv[optind], ":");
463
-    if (found && settings.whitelist == NULL) {
360
+    if (found) {
464 361
         memcpy(target_host, argv[optind], found-argv[optind]);
465 362
         target_port = strtol(found+1, NULL, 10);
466
-        target_ports = NULL;
467
-    } else if (!found && settings.whitelist != NULL) {
468
-        if (load_whitelist()) {
469
-          usage("Whitelist error.");
470
-        }
471
-        memcpy(target_host, argv[optind], strlen(argv[optind]));
472
-        target_port = -1;
473
-
474 363
     } else {
475
-        usage("Target argument must be host:port or provide host and a port whitelist\n");
364
+        usage("Target argument must be host:port\n");
476 365
     }
477 366
     if (target_port == 0) {
478 367
         usage("Could not parse target port\n");
479 368
     }
480 369
 
481
-    if (settings.ssl_only) {
370
+    if (ssl_only) {
482 371
         if (access(settings.cert, R_OK) != 0) {
483 372
             usage("SSL only and cert file '%s' not found\n", settings.cert);
484 373
         }
@@ -493,7 +382,7 @@ int main(int argc, char *argv[])
493 382
     //printf("  cert: %s\n",      settings.cert);
494 383
     //printf("  key: %s\n",       settings.key);
495 384
 
496
-    settings.handler = proxy_handler;
385
+    settings.handler = proxy_handler; 
497 386
     start_server();
498 387
 
499 388
 }

Завантаження…
Відмінити
Зберегти