mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2025-04-19 07:16:57 +00:00
Compare commits
No commits in common. "master" and "v0.2" have entirely different histories.
@ -1,6 +1,6 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM golang:1.22
|
||||
FROM golang:latest
|
||||
|
||||
# Set destination for COPY
|
||||
WORKDIR /app
|
||||
|
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Minoplhy
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -31,7 +31,7 @@ func Check_API_Key(Basepath string, accessKey string) bool {
|
||||
return resp.StatusCode == http.StatusOK
|
||||
}
|
||||
|
||||
func UploadPost(BasePath string, headers map[string]string, PostData UploadPostMeta) ([]byte, error) {
|
||||
func UploadPost(BasePath string, accessKey string, PostData UploadPostMeta) ([]byte, error) {
|
||||
URL := BasePath + "/api/upload"
|
||||
// Convert PostData to JSON
|
||||
PostDataJson, err := json.Marshal(PostData)
|
||||
@ -39,6 +39,11 @@ func UploadPost(BasePath string, headers map[string]string, PostData UploadPostM
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"X-Api-Key": accessKey,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
POSTStruct := URLRequest{
|
||||
URL: URL,
|
||||
ContentType: PostData.ContentType,
|
||||
@ -53,12 +58,11 @@ func UploadPost(BasePath string, headers map[string]string, PostData UploadPostM
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
return BodyRead, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
@ -100,18 +104,17 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
return BodyRead, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func UploadProcessPost(BasePath string, headers map[string]string, PostData UploadProcessMeta) ([]byte, error) {
|
||||
func UploadProcessPost(BasePath string, accessKey string, PostData UploadProcessMeta) ([]byte, error) {
|
||||
URL := BasePath + "/api/upload/process"
|
||||
// Convert PostData to JSON
|
||||
PostDataJson, err := json.Marshal(PostData)
|
||||
@ -119,6 +122,11 @@ func UploadProcessPost(BasePath string, headers map[string]string, PostData Uplo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"X-Api-Key": accessKey,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
POSTStruct := URLRequest{
|
||||
URL: URL,
|
||||
Method: "POST",
|
||||
@ -129,15 +137,13 @@ func UploadProcessPost(BasePath string, headers map[string]string, PostData Uplo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
return BodyRead, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -75,5 +75,5 @@ func HTTPClientDo(Request *http.Request) (*http.Response, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
return response, err
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Check if request IP Address is in internal ranges
|
||||
func IsInternalIP(ip string) bool {
|
||||
parts := strings.Split(ip, ":")
|
||||
ip = parts[0]
|
||||
|
||||
// Parse the IP address
|
||||
ipAddress := net.ParseIP(ip)
|
||||
if ipAddress == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
internalRanges := []string{
|
||||
"10.0.0.0/8",
|
||||
"172.16.0.0/12",
|
||||
"192.168.0.0/16",
|
||||
}
|
||||
|
||||
for _, internalRange := range internalRanges {
|
||||
_, ipNet, err := net.ParseCIDR(internalRange)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if ipNet.Contains(ipAddress) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -2,28 +2,18 @@ package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func ResponseBuild(w http.ResponseWriter, ContentType string, ContentData []byte) {
|
||||
w.Header().Set("Content-Type", ContentType)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(ContentData)
|
||||
}
|
||||
|
||||
func ErrorResponseBuild(w http.ResponseWriter, StatusCode int64, Message string) {
|
||||
func ErrorResponseBuild(StatusCode int64, Message string) string {
|
||||
ErrorResponse := ErrorResponse{
|
||||
StatusCode: StatusCode,
|
||||
Message: Message,
|
||||
}
|
||||
Response, _ := json.Marshal(ErrorResponse)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(int(StatusCode))
|
||||
w.Write(Response)
|
||||
return string(Response)
|
||||
}
|
||||
|
||||
func InfoLogBuilder(headers []string, message string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user