Skip to content

Commit

Permalink
0.8.4 issue #27 + web minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jolav committed Feb 21, 2023
1 parent 7679ecd commit c8e1032
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 174 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

![Version](https://img.shields.io/badge/version-0.8.3-orange.svg)
![Version](https://img.shields.io/badge/version-0.8.4-orange.svg)
![Maintained YES](https://img.shields.io/badge/Maintained%3F-yes-green.svg)
![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)

# ![logo](https://github.com/jolav/codetabs/blob/master/www/_public/icons/ct/ct64r.png?raw=true) **ONLINE TOOLS ([codetabs.com](https://codetabs.com))**

**version 0.8.3**
**version 0.8.4**

1. [Count LOC (lines of code) online from github/gitlab repos or zipped uploaded folder](#count-loc-online)
2. [CORS proxy](#cors-proxy)
Expand Down
36 changes: 35 additions & 1 deletion _utils/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func AddHit(w http.ResponseWriter, r *http.Request, service, mode string,
}
}
}

askingFor := strings.Trim(fmt.Sprint(r.URL), string(r.URL.Path))

if mode == "production" {
Expand All @@ -38,6 +37,41 @@ func AddHit(w http.ResponseWriter, r *http.Request, service, mode string,
}
}

// AddBanned ...
func AddBanned(w http.ResponseWriter, r *http.Request, service, mode string,
hLog *log.Logger) {
ip := GetIP(r)
sv := strings.ToUpper(service)
host := r.Header.Get("Host")
if host == "" {
host = r.Header.Get("Origin")
if host == "" {
host = r.Header.Get("Referer")
if host == "" {
host = "???"
}
}
}
askingFor := strings.Trim(fmt.Sprint(r.URL), string(r.URL.Path))

if mode == "production" {
hLog.Println(ip, sv, host, askingFor)
} else {
log.Println(ip, sv, host, askingFor)
}
}

// CreateCustomBansLogFile ...
func NewBanFile(f string) *log.Logger {
infoLog, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("ERROR opening Ban log file %s\n", err)
}
bannedLog := log.New(infoLog, "BANNED: ", log.Ldate|log.Ltime)
//hitsLog := log.New(infoLog, "HIT :\t", log.Ldate|log.Ltime)
return bannedLog
}

// CreateCustomHitsLogFile ...
func NewHitsFile(f string) *log.Logger {
infoLog, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
Expand Down
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ import (
"github.com/jolav/codetabs/weather"
)

var version = "0.8.3"
var version = "0.8.4"
var when = "undefined"

type Conf struct {
Mode string
Port int
ErrorsLogFile string
HitsLogFile string
BannedLogFile string
DevHosts []string
Services []string
hitsLog *log.Logger
bannedLog *log.Logger
}

func main() {
Expand Down Expand Up @@ -68,6 +70,10 @@ func main() {
}
defer mylog.Close()

// Custom Ban Log File
c.BannedLogFile = usernow.HomeDir + c.BannedLogFile
c.bannedLog = u.NewBanFile(c.BannedLogFile)

// Custom Hits Log File
c.HitsLogFile = usernow.HomeDir + c.HitsLogFile
c.hitsLog = u.NewHitsFile(c.HitsLogFile)
Expand All @@ -86,6 +92,7 @@ func main() {
mux.HandleFunc("/v1/video2gif/", mw(video2gif.Router, "video2gif", c))
mux.HandleFunc("/v1/stars/", mw(stars.Router, "stars", c))
mux.HandleFunc("/v1/proxy/", mw(proxy.Router, "proxy", c))
mux.HandleFunc("/v1/tmp/", mw(proxy.Router, "proxy", c))
mux.HandleFunc("/v1/loc/", mw(loc.Router, "loc", c))

mux.HandleFunc("/", u.BadRequest)
Expand All @@ -104,14 +111,14 @@ func main() {

func mw(next http.HandlerFunc, service string, c Conf) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
go u.AddHit(w, r, service, c.Mode, c.hitsLog)
if service == "proxy" {
if isBanned(r) {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
go u.AddBanned(w, r, service, c.Mode, c.bannedLog)
return
}
}

go u.AddHit(w, r, service, c.Mode, c.hitsLog)
next.ServeHTTP(w, r)
})
}
Expand Down
5 changes: 5 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (p *proxy) doProxyRequest(w http.ResponseWriter, r *http.Request) {

if strings.Contains(contentType, "application/xml") {
u.SendXMLToClient(w, data, 200)
return
}

if strings.Contains(contentType, "text/") {
w.Header().Add("Content-type", "text/plain")
}

reader := bufio.NewReader(resp.Body)
Expand Down
4 changes: 2 additions & 2 deletions www/_error/404.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ a.link:hover {
/* TITLE */

.titleBox {
font-family: "Titillium Web", "arial", sans-serif;
font-family: "arial", sans-serif;
padding: 0px;
font-size: 2.5em;
text-align: center;
Expand All @@ -98,4 +98,4 @@ a.link:hover {
.titleBox img {
vertical-align: middle;
padding: 0px 15px 8px 0px;
}
}
8 changes: 1 addition & 7 deletions www/_error/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ <h1 class="titleBox">

</div>

<!-- google-analytics -->
<!--#include file="/_public/templates/analyticstracking.html" -->

<!-- Titillium Web -->
<link href="https://fonts.googleapis.com/css?family=Titillium+Web:400,700" rel="stylesheet">

</body>

</html>
</html>
8 changes: 1 addition & 7 deletions www/_error/429.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ <h1 class="titleBox">

</div>

<!-- google-analytics -->
<!--#include file="/_public/templates/analyticstracking.html" -->

<!-- Titillium Web -->
<link href="https://fonts.googleapis.com/css?family=Titillium+Web:400,700" rel="stylesheet">

</body>

</html>
</html>
Binary file added www/_public/fonts/TitilliumWeb.ttf
Binary file not shown.
Binary file added www/_public/fonts/Varela.ttf
Binary file not shown.
14 changes: 0 additions & 14 deletions www/_public/templates/analyticstracking.html

This file was deleted.

25 changes: 0 additions & 25 deletions www/_public/templates/cookieLaw.html

This file was deleted.

57 changes: 53 additions & 4 deletions www/_public/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
text-align: center;
}

@font-face {
font-family: 'Varela';
font-style: normal;
font-weight: 400;
src: url('_public/fonts/Varela.ttf');
}

@font-face {
font-family: 'Titillium';
font-style: normal;
font-weight: 400;
src: url('_public/fonts/TitilliumWeb.ttf');
}

</style>

<footer class="footer">
Expand All @@ -43,18 +57,53 @@
</a>
<br>
<span>You can submit your questions, feedbacks, and feature requests opening a issue on github or
<a href=mailto:[email protected]>
<strong>emailing us</strong>
</a>
<strong>
<a class="m" href="#">0f67664f6c606b6a7b6e6d7c216c6062Of989968bbc95bb968a888c9caf968080
</a>
</strong>
</span>
<br>
<img class="logo" style="max-height:32px; vertical-align:middle" alt="" src="/_public/icons/ct/jolav32.png">
Jolav
&copy; 2023 -
&copy; <span id="year"></span> -
<strong>
<a href="https://github.com/jolav/codetabs">View on GitHub</a>
</strong>
<hr>
</footer>
<br>
<!-- End -->

<script>
function getValue(oldValue) {
var value = "";
var keyInHex = oldValue.substr(0, 2);
var key = parseInt(keyInHex, 16);
for (var n = 2; n < oldValue.length; n += 2) {
var charInHex = oldValue.substr(n, 2)
var char = parseInt(charInHex, 16);
var output = char ^ key;
value += String.fromCharCode(output);
}
return value;
}

const ms = document.getElementsByClassName("m");

for (let i = 0; i < ms.length; i++) {
const el = ms[i]
const oldValue = el.innerHTML;
const aux = oldValue.split("O")[0]
const value = getValue(aux);
if (i === 0) {
el.textContent = "emailing us"
}
if (i === 1) {
el.textContent = value;
}
el.href = 'mailto:' + value;
}

const year = document.getElementById("year")
year.textContent = new Date().getFullYear()
</script>
58 changes: 54 additions & 4 deletions www/_public/templates/footerIP.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
text-align: center;
}*/

@font-face {
font-family: 'Varela';
font-style: normal;
font-weight: 400;
src: url('_public/fonts/Varela.ttf');
}

@font-face {
font-family: 'Titillium';
font-style: normal;
font-weight: 400;
src: url('_public/fonts/TitilliumWeb.ttf');
}

</style>


Expand All @@ -49,18 +63,54 @@
</span>
<br>
<span>You can submit your questions, feedbacks, and feature requests opening a issue on github or
<a href=mailto:[email protected]>
<strong>emailing us</strong>
</a>
<strong>
<a class="m" href="#">0f67664f6c606b6a7b6e6d7c216c6062Of989968bbc95bb968a888c9caf968080
</a>
</strong>
</span>
<br>
<img class="logo" style="max-height:32px; vertical-align:middle" alt="" src="/_public/icons/ct/jolav32.png">
Jolav
&copy; 2023 -
&copy; <span id="year"></span> -
<strong>
<a href="https://github.com/jolav/codetabs">View on GitHub</a>
</strong>
<hr>
</footer>
<br>
<!-- End -->


<script>
function getValue(oldValue) {
var value = "";
var keyInHex = oldValue.substr(0, 2);
var key = parseInt(keyInHex, 16);
for (var n = 2; n < oldValue.length; n += 2) {
var charInHex = oldValue.substr(n, 2)
var char = parseInt(charInHex, 16);
var output = char ^ key;
value += String.fromCharCode(output);
}
return value;
}

const ms = document.getElementsByClassName("m");

for (let i = 0; i < ms.length; i++) {
const el = ms[i]
const oldValue = el.innerHTML;
const aux = oldValue.split("O")[0]
const value = getValue(aux);
if (i === 0) {
el.textContent = "emailing us"
}
if (i === 1) {
el.textContent = value;
}
el.href = 'mailto:' + value;
}

const year = document.getElementById("year")
year.textContent = new Date().getFullYear()
</script>
Loading

0 comments on commit c8e1032

Please sign in to comment.