Merge pull request #44 from bagheriali2001/master
Added support of curl protocol, added click to copy to curl commands, updated readme
This commit is contained in:
commit
771a958a3e
72
README.md
72
README.md
|
@ -1,11 +1,83 @@
|
|||
|
||||
# ifconfig.io
|
||||
|
||||
[![Build Status](https://drone.io/github.com/georgyo/ifconfig.io/status.png)](https://drone.io/github.com/georgyo/ifconfig.io/latest)
|
||||
|
||||
Inspired by ifconfig.me, but designed for pure speed. A single server can do 18,000 requests per seconds while only consuming 50megs of ram.
|
||||
|
||||
# Contents
|
||||
|
||||
- [Short Summery](#short-summery)
|
||||
- [Deployment](#deployment)
|
||||
- [Docker Compose](#docker-compose)
|
||||
- [ENVs](#envs)
|
||||
|
||||
# Short Summery
|
||||
|
||||
I used the gin framework as it does several things to ensure that there are no memory allocations on each request, keeping the GC happy and preventing unnessary allocations.
|
||||
|
||||
Tested to handle 10,000 clients doing 90,000 requests persecond on modest hardware with an average response time of 42ms. Easily servicing over 5 million requests in a minute. (Updated June, 2022)
|
||||
|
||||
[![LoadTest](http://i.imgur.com/0vJYumD.png)](https://loader.io/reports/f1e9a7dd516ac0472351e5e0c83b0787/results/a055e51ff317cdf8a688b25e9c0e4147#response_details)
|
||||
|
||||
# Deployment
|
||||
|
||||
You can use the source code directly to deploy your own server. You can also you can use Docker and Docker Compose.
|
||||
|
||||
## Docker-Compose
|
||||
|
||||
Here is a sample docker-compose file:
|
||||
|
||||
``` bash
|
||||
version: "3.4"
|
||||
|
||||
services:
|
||||
ifconfig:
|
||||
image: ifconfig.io:latest
|
||||
ports:
|
||||
- 8080:8080
|
||||
```
|
||||
|
||||
Some other compose files:
|
||||
|
||||
``` bash
|
||||
version: "3.4"
|
||||
|
||||
services:
|
||||
ifconfig:
|
||||
image: ifconfig.io:latest
|
||||
ports:
|
||||
- 8080:8080
|
||||
environment:
|
||||
HOSTNAME: "ifconfig.io"
|
||||
```
|
||||
|
||||
``` bash
|
||||
version: "3.4"
|
||||
|
||||
services:
|
||||
ifconfig:
|
||||
image: ifconfig.io:latest
|
||||
ports:
|
||||
- 8080:8080
|
||||
env_file:
|
||||
- ./.env
|
||||
```
|
||||
|
||||
## ENVs
|
||||
|
||||
This project offers you some customizability over what you show to user and ect. Here is list of all possible environment variable that you can pass to your instance, with their default values.
|
||||
|
||||
``` bash
|
||||
HOSTNAME="ifconfig.io" # Text address shown to user at header
|
||||
CMD_PROTOCOL="" # Request protocol for curl commands
|
||||
HOST=""
|
||||
PORT="8080"
|
||||
PROXY_PROTOCOL_ADDR=""
|
||||
FORWARD_IP_HEADER="CF-Connecting-IP" # Request header to get IP from
|
||||
COUNTRY_CODE_HEADER="CF-IPCountry" # Request header to get country code from
|
||||
TLS="0"
|
||||
TLSPORT="8443"
|
||||
TLSCERT="/opt/ifconfig/.cf/ifconfig.io.crt"
|
||||
TLSKEY="/opt/ifconfig/.cf/ifconfig.io.key"
|
||||
```
|
||||
|
|
6
main.go
6
main.go
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
type Configuration struct {
|
||||
hostname string // Displayed Hostname
|
||||
cmd_hostname string // Displayed Hostname for CMD section
|
||||
host string // Listened Host
|
||||
port string // HTTP Port
|
||||
proxy_listener string // Proxy Protocol Listener
|
||||
|
@ -31,6 +32,9 @@ var configuration = Configuration{}
|
|||
|
||||
func init() {
|
||||
hostname := getEnvWithDefault("HOSTNAME", "ifconfig.io")
|
||||
protocol := getEnvWithDefault("CMD_PROTOCOL", "")
|
||||
|
||||
cmd_hostname := protocol + hostname
|
||||
|
||||
host := getEnvWithDefault("HOST", "")
|
||||
port := getEnvWithDefault("PORT", "8080")
|
||||
|
@ -48,6 +52,7 @@ func init() {
|
|||
|
||||
configuration = Configuration{
|
||||
hostname: hostname,
|
||||
cmd_hostname: cmd_hostname,
|
||||
host: host,
|
||||
port: port,
|
||||
proxy_listener: proxy_listener,
|
||||
|
@ -110,6 +115,7 @@ func mainHandler(c *gin.Context) {
|
|||
//}
|
||||
|
||||
c.Set("ifconfig_hostname", configuration.hostname)
|
||||
c.Set("ifconfig_cmd_hostname", configuration.cmd_hostname)
|
||||
|
||||
ua := c.Request.UserAgent()
|
||||
|
||||
|
|
|
@ -16,11 +16,29 @@
|
|||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
color: #555555
|
||||
}
|
||||
|
||||
.popup {
|
||||
display: none;
|
||||
position: fixed;
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
color: #fff;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
z-index: 9999;
|
||||
width: 70px;
|
||||
height: 34px;
|
||||
}
|
||||
</style>
|
||||
<title>{{ .ifconfig_hostname }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="popup" id="popup">
|
||||
<p>Copied !</p>
|
||||
</div>
|
||||
<header class="page-header container">
|
||||
<a href="/" class="h1">
|
||||
What is my ip address? - <small>{{ .ifconfig_hostname }}</small>
|
||||
|
@ -74,46 +92,46 @@
|
|||
</div>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}</div><div class="col-sm-8">{{ .ip }}</div>
|
||||
<div class="col-sm-4" id="direct_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}</span></div><div class="col-sm-8">{{ .ip }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/ip</div><div class="col-sm-8">{{ .ip }}</div>
|
||||
<div class="col-sm-4" id="ip_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/ip</span></div><div class="col-sm-8">{{ .ip }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/host</div><div class="col-sm-8">{{ .host }}</div>
|
||||
<div class="col-sm-4" id="host_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/host</span></div><div class="col-sm-8">{{ .host }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/country_code</div><div class="col-sm-8">{{ .country_code }}</div>
|
||||
<div class="col-sm-4" id="country_code_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/country_code</span></div><div class="col-sm-8">{{ .country_code }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/ua</div><div class="col-sm-8">{{ .ua }}</div>
|
||||
<div class="col-sm-4" id="ua_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/ua</span></div><div class="col-sm-8">{{ .ua }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/port</div><div class="col-sm-8">{{ .port }}</div>
|
||||
<div class="col-sm-4" id="port_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/port</span></div><div class="col-sm-8">{{ .port }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/lang</div><div class="col-sm-8">{{ .lang }}</div>
|
||||
<div class="col-sm-4" id="lang_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/lang</span></div><div class="col-sm-8">{{ .lang }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/encoding</div><div class="col-sm-8">{{ .encoding }}</div>
|
||||
<div class="col-sm-4" id="encoding_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/encoding</span></div><div class="col-sm-8">{{ .encoding }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/mime</div><div class="col-sm-8">{{ .mime }}</div>
|
||||
<div class="col-sm-4" id="mime_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/mime</span></div><div class="col-sm-8">{{ .mime }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/forwarded</div><div class="col-sm-8">{{ .forwarded }}</div>
|
||||
<div class="col-sm-4" id="forwarded_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/forwarded</span></div><div class="col-sm-8">{{ .forwarded }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/all</div><div class="col-sm-8">{{ .hash_as_yaml }}</div>
|
||||
<div class="col-sm-4" id="all_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/all</span></div><div class="col-sm-8">{{ .hash_as_yaml }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/all.xml</div><div class="col-sm-8">{{ .hash_as_xml }}</div>
|
||||
<div class="col-sm-4" id="all.xml_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/all.xml</span></div><div class="col-sm-8">{{ .hash_as_xml }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/all.json</div><div class="col-sm-8">{{ .hash_as_json }}</div>
|
||||
<div class="col-sm-4" id="all.json_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/all.json</span></div><div class="col-sm-8">{{ .hash_as_json }}</div>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="col-sm-4"><span class="unselectable">$ </span>curl {{ .ifconfig_hostname }}/all.js</div><div class="col-sm-8">{{ .hash_as_js }}</div>
|
||||
<div class="col-sm-4" id="all.js_curl"><span class="unselectable">$ </span><span class="copy_text">curl {{ .ifconfig_cmd_hostname }}/all.js</span></div><div class="col-sm-8">{{ .hash_as_js }}</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -121,6 +139,21 @@
|
|||
<footer class="container text-center">
|
||||
<p>© 2014 - 2022 ifconfig.io</p>
|
||||
</footer>
|
||||
<script>
|
||||
function copyText(event) {
|
||||
let popup = document.getElementById("popup");
|
||||
popup.style.display = 'block';
|
||||
popup.style.left = `${event.x-35}px`;
|
||||
popup.style.top = `${event.y-17-30}px`;
|
||||
|
||||
setTimeout(function() {
|
||||
popup.style.display = 'none';
|
||||
}, 2000);
|
||||
|
||||
navigator.clipboard.writeText(event.srcElement.textContent);
|
||||
}
|
||||
Array.prototype.forEach.call(document.getElementsByClassName("copy_text") , (element) => {element.addEventListener("click", function(event) {copyText(event);event.preventDefault();});});
|
||||
</script>
|
||||
<!-- Hello World -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue