Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
WikiDru committed Sep 19, 2018
1 parent 4b32d55 commit 59dbf10
Show file tree
Hide file tree
Showing 21 changed files with 1,965 additions and 20 deletions.
33 changes: 15 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# Compiled class file
*.class
# Virtual machine crash logs
hs_err_pid*

# Log file
*.log
# Gradle build files
.gradle/

# BlueJ files
*.ctxt
# IDEA files
.idea/

# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Vertx
.vertx

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# Build
build/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Log
log/

# Config
config/
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: java

os:
- linux

jdk:
- openjdk8

sudo: false

script: gradle test
180 changes: 178 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,178 @@
# zeroproxy
Multi purpose http proxy server
# ZeroProxy is a multi purpose http proxy.
* Support http(https) proxy
* Support websocket proxy (Not yet)
* Support multiple targets


# Supported protocol
* http / https
* ws / wss (Not yet)


# Configuration

## app_config.yml
It's application configuration file.
```yaml
# Server port
port:
main_http: 55550
main_ws: 55551
api_http: 55552
```
## proxy_config.yml
It's proxy configuration file.
```yaml
# Example-1
- location: /zeroproxy_example
type: round-robin
connect_timeout: 3000
idle_timeout: 3000
targets:
- http://1.1.1.1:3000

# Example-2
- location: /zeroproxy/example
type: random
connect_timeout: 3000
idle_timeout: 3000
targets:
- http://1.1.1.1:3000
- http://1.1.1.1:3001

# Example-3
- location: /zeroproxy/example/1
type: all
connect_timeout: 3000
idle_timeout: 3000
targets:
- http://1.1.1.1:3000
- http://1.1.1.1:3001
- http://1.1.1.1:3002

# Example-4
- location: /
type: round-robin
connect_timeout: 3000
idle_timeout: 3000
targets:
- http://1.1.1.1:3000
```
## logback.xml
It's Logback configuration file that is famous logging library.
* You can send error log to Telegram.
1. Uncomment *Telegram* configuration.
2. Set value of `<botToken>` and `<chatId>`.
```xml
<appender name="TELEGRAM" class="com.github.paolodenti.telegram.logback.TelegramAppender">
<botToken></botToken>
<chatId></chatId>
...
</appender>
```
3. Insert `<appender-ref ref="TELEGRAM"/>` into `<root>`
```xml
<root level="WARN">
<appender-ref ref="FILE"/>
<appender-ref ref="TELEGRAM"/>
</root>
```
* You can send error log to Slack.
1. Uncomment *Slack* configuration.
2. Set value of `<webhookUri>`.
```xml
<appender name="SLACK_SYNC" class="com.github.maricn.logback.SlackAppender">
<webhookUri></webhookUri>
...
</appender>
```
3. Insert `<appender-ref ref="SLACK"/>` into `<root>`
```xml
<root level="WARN">
<appender-ref ref="FILE"/>
<appender-ref ref="SLACK"/>
</root>
```
* You can reload configuration but need not to restart application.


# Server
ZeroProxy has three servers.
One is a http proxy server, another is a websocket proxy server, and the other is a restful API server.
Restful API server provide application information and additional functions.

## Main HTTP Server
### Usage
```html
http://example.com:{port}/{location}/{path}
ws://example.com:{port}/{location}/{path}
```
* port
* Server port
* It's *main_http* and *main_ws* in app_config.yml.
* location
* Location
* It's *location* in proxy_config.yml
* path
* Target path

### Example
```html
http://example.com:55550/zeroproxy/example/test.png
```

## API HTTP Server
### Usage
```html
http://example.com:{port}/{domain}/{method}
```

### Example
```html
http://example.com:57911/app/status
http://example.com:57911/app/hello
http://example.com:57911/app/ping
```

### API
#### GET /app/status
* Get application status and environment.
##### Response
```json
{
"data":{
"applicationVersion":"0.1.0-alpha.1",
"cpuUsage":2.56,
"threadInfo":{...},
"vmMemoryFree":"190M",
"javaVersion":"1.8.0_25",
"vmMemoryMax":"3,641M",
"currentDate":"2018-09-18T18:48:58.795+09:00",
"threadCount":15,
"startedDate":"2018-09-18T18:48:40.901+09:00",
"javaVendor":"",
"runningTimeHour":0,
"osName":"Mac OS X",
"cpuProcessorCount":4,
"vmMemoryTotalFree":"3,585M",
"hostname":"",
"osVersion":"10.11.6",
"jarFile":"code13k-zeroproxy-0.1.0-alpha.1.jar",
"vmMemoryAllocated":"245M",
}
}
```
#### GET /app/hello
* Hello, World
##### Response
```json
{"data":"world"}
```

#### GET /app/ping
* Ping-Pong
##### Response
```json
{"data":"pong"}
99 changes: 99 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
plugins {
id 'java'
id 'application'
}

/**
* Project
*/
group 'org.code13k'
version '0.1.0-alpha.1'
repositories {
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'

// Log
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'ch.qos.logback', name: 'logback-access', version: '1.2.3'

// Log for telegram
compile group: 'com.github.paolodenti', name: 'telegram-logback', version: '1.2.0'

// Log for slack
compile group: 'com.github.maricn', name: 'logback-slack-appender', version: '1.4.0'

// Java Compiler (For Logback)
compile group: 'org.codehaus.janino', name: 'janino', version: '3.0.8'

// SnakeYAML (YAML Library)
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'

// Gson (Json Library)
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'

// Vert.x (Http Library)
compile group: 'io.vertx', name: 'vertx-core', version: '3.5.3'
compile group: 'io.vertx', name: 'vertx-web', version: '3.5.3'
compile group: 'io.vertx', name: 'vertx-web-client', version: '3.5.3'
compile group: 'io.vertx', name: 'vertx-codegen', version: '3.5.3'

// Util
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'com.google.guava', name: 'guava', version: '26.0-jre'
}

/**
* Java Plugin
*/
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
baseName = 'code13k-zeroproxy'
manifest {
attributes(
'Implementation-Title': 'Code13k ZeroProxy',
'Implementation-Version': version,
'Main-Class': 'org.code13k.zeroproxy.Main'
)
}
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:deprecation"
}
compileTestJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:deprecation"
}

/**
* Application Plugin
*/
mainClassName = 'org.code13k.zeroproxy.Main'

/**
* Custom
*/
task runJar(dependsOn: jar) {
doLast {
javaexec {
main = "-jar"
args = [jar.archivePath]
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Sep 18 00:39:54 KST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
Loading

0 comments on commit 59dbf10

Please sign in to comment.