diff --git a/.gitignore b/.gitignore index 8c3053d..64f4f1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ pkg/server/assets.go +*~ # Binaries for programs and plugins *.exe *.exe~ diff --git a/pkg/server/server.go b/pkg/server/server.go index d0dc203..e60ce8a 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -4,6 +4,7 @@ import ( "fmt" "html/template" "math/rand" + "io/ioutil" "net/http" "path/filepath" "strings" @@ -77,7 +78,7 @@ Disallow: /`)) return } else if strings.HasPrefix(r.URL.Path, "/static") { var b []byte - b, err = Asset(r.URL.Path[1:]) + b, err = ioutil.ReadFile()(r.URL.Path[1:]) if err != nil { http.Error(w, "file not found", 404) return @@ -98,7 +99,7 @@ Disallow: /`)) return } else if r.URL.Path == "/" { var t *template.Template - b, _ := Asset("templates/view.html") + b, _ := ioutil.ReadFile("templates/view.html") t, err = template.New("view").Parse(string(b)) if err != nil { log.Error(err) diff --git a/static/banner.jpg b/static/banner.jpg new file mode 100644 index 0000000..33ad37e Binary files /dev/null and b/static/banner.jpg differ diff --git a/static/main.js b/static/main.js new file mode 100644 index 0000000..42132b1 --- /dev/null +++ b/static/main.js @@ -0,0 +1,185 @@ +var files = []; +var isConnected = false; +var relativeDirectory = ""; + +function consoleLog(s) { + console.log(s); + if (typeof s === 'object') { + s = JSON.stringify(s); + } + + if (!(s.startsWith("[debug]"))) { + document.getElementById("consoleText").value = document.getElementById("consoleText").value + s + "\n"; + document.getElementById("consoleText").scrollTop = document.getElementById("consoleText").scrollHeight; + } +} + +function humanFileSize(bytes, si) { + var thresh = si ? 1000 : 1024; + if (Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + var units = si ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', + 'EiB', 'ZiB', 'YiB' + ]; + var u = -1; + do { + bytes /= thresh; + ++u; + } while (Math.abs(bytes) >= thresh && u < units.length - 1); + return bytes.toFixed(1) + ' ' + units[u]; +} + +var Name = ""; +var filesize = 0; + +(function(Dropzone) { + Dropzone.autoDiscover = false; + + let drop = new Dropzone('div#filesBox', { + maxFiles: 1000, + url: '/', + method: 'post', + createImageThumbnails: false, + previewTemplate: "
", + autoProcessQueue: false, + }); + + + drop.on('addedfile', function(file) { + // console.log(file); + var domain = document.getElementById("inputDomain").value + files.push(file); + if (files.length == 1) { + relativeDirectory = file.webkitRelativePath.split("/")[0]; + } else if (file.webkitRelativePath.split("/")[0] != relativeDirectory) { + relativeDirectory = ""; + } + + if (!(isConnected)) { + isConnected = true; + socketSend({ + type: "domain", + message: domain, + key: document.getElementById("inputKey").value, + }) + } + + var filesString = "files are"; + var domainName = `${window.publicURL}/${domain}/`; + if (files.length == 1) { + filesString = "file is" + domainName += `${file.name}` + } + + document.getElementById("consoleHeader").innerHTML = + `

Your ${filesString} available at:

${domainName}

`; + html = ``; + document.getElementById("fileList").innerHTML = html; + document.getElementById("filesBox").classList.add("hide"); + document.getElementById("console").classList.remove("hide"); + document.getElementById("inputKey").readOnly = "true"; + document.getElementById("inputDomain").readOnly = "true"; + }) + +})(Dropzone); + +var socket; // websocket + + +/* websockets */ +function socketSend(data) { + if (socket == null) { + return + } + if (socket.readyState != 1) { + return + } + jsonData = JSON.stringify(data); + socket.send(jsonData); + if (jsonData.length > 100) { + consoleLog("[debug] ws-> " + jsonData.substring(0, 99)) + } else { + consoleLog("[debug] ws-> " + jsonData) + } +} + +const socketMessageListener = (event) => { + var data = JSON.parse(event.data); + if (!('type' in data && 'message' in data)) { + consoleLog(`[warn] got bad data ${event.data}`); + return + } + console.log(data) + consoleLog(`[debug] ${data.message}`) + if (data.type == "get") { + var foundFile = false + var iToSend = 0 + for (i = 0; i < files.length; i++) { + if (files[i].webkitRelativePath == data.message || files[i].name == data.message || files[i] + .webkitRelativePath == relativeDirectory + "/" + data.message) { + iToSend = i; + var reader = new FileReader(); + reader.onload = function(theFile) { + socketSend({ + type: "get", + message: reader.result, + success: true, + key: document.getElementById("inputKey").value, + }) + consoleLog( + `${data.ip} [${(new Date()).toUTCString()}] /${data.message} 200 ${files[i].size}` + ); + }; + reader.readAsDataURL(files[i]); + foundFile = true + break + } + } + if (foundFile == false) { + socketSend({ + type: "get", + message: "not found", + success: false, + key: document.getElementById("inputKey").value, + }) + consoleLog(`${data.ip} [${(new Date()).toUTCString()}] /${data.message} 404`); + } + } else if (data.type == "domain") { + console.log(`[info] ${data.message}`); + } else if (data.type == "message") { + console.log(`[info] ${data.message}`); + } else { + consoleLog(`[debug] unknown`); + } +}; +const socketOpenListener = (event) => { + consoleLog('[info] connected'); +}; + +const socketCloseListener = (event) => { + if (socket) { + consoleLog('[info] disconnected'); + } + var url = window.origin.replace("http", "ws") + '/ws'; + try { + socket = new WebSocket(url); + socket.addEventListener('open', socketOpenListener); + socket.addEventListener('message', socketMessageListener); + socket.addEventListener('close', socketCloseListener); + } catch (err) { + consoleLog("[info] no connection available") + } +}; + + +socketCloseListener(); \ No newline at end of file diff --git a/static/style.css b/static/style.css index 60826b7..684eee8 100644 --- a/static/style.css +++ b/static/style.css @@ -329,3 +329,67 @@ However, delay the fade out process for 2.5 seconds */ opacity: 0; } } + + + +.main { + padding-top: 20px; +} + +.list { + display: flex; + flex-wrap: wrap; +} + +.list>div { + padding: 0.4em; +} + +body { + text-decoration-skip: ink; +} + +.hide { + display: none; +} + +textarea { + width: 100%; + border: none; + resize: none; + height: 20em; + border: 1px solid #ccc; + background-color: #f5f5f5; + padding: 1em; + font-size: 0.9em; +} + +details>p>code { + background-color: inherit; +} + +.editer { + margin: 0.2em; + padding: 0.5em; + background-color: #f5f5f5; + display: inline; + border: none; + font-weight: bold; + font-family: var(--sans-font); + font-size: 1em; +} + +.banner { + padding-top: 3em; +} + +.p05 { + padding-top: 0.5em; + padding-bottom: 0.5em; +} + +.flexcol { + display: flex; + flex-direction: row; + align-content: center; +} \ No newline at end of file diff --git a/templates/view.html b/templates/view.html index 04871e6..2c02477 100644 --- a/templates/view.html +++ b/templates/view.html @@ -2,70 +2,46 @@ - - - - - + + host yo self + + + + + + + + + + + + + + + + + + + + + + + + + + + - hostyoself -
- +

-

Your files will be relayed at {{.PublicURL}}/. Multiple hosts can be used with this key: .

+

Need a web host? Host yo self! Use this page to host a website or a file directly from your computer / phone / smartwatch / toaster!

Click here for FAQ.

FAQ

@@ -163,10 +139,78 @@

Privacy policy

- Privacy policy +

Effective date: July 11, 2019

+

Host Yo Self ("us", "we", or "our") operates the https://hostyoself.com website (the "Service").

+

This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data.

+

We use your data to provide and improve the Service. By using the Service, you agree to the collection and use of information in accordance with this policy. Unless otherwise defined in this Privacy Policy, terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, accessible from https://hostyoself.com

+

Information Collection And Use

+

We collect several different types of information for various purposes to provide and improve our Service to you.

+

Types of Data Collected

+

Personal Data

+

While using our Service, we may ask you to provide us with certain personally identifiable information that can be used to contact or identify you ("Personal Data"). Personally identifiable information may include, but is not limited to:

+ +

Usage Data

+

We may also collect information how the Service is accessed and used ("Usage Data"). This Usage Data may include information such as your computer's Internet Protocol address (e.g. IP address), browser type, browser version, the pages of our Service that you visit, the time and date of your visit, the time spent on those pages, unique device identifiers and other diagnostic data.

+

Use of Data

+

Host Yo Self uses the collected data for various purposes:

+ +

Transfer Of Data

+

Your information, including Personal Data, may be transferred to — and maintained on — computers located outside of your state, province, country or other governmental jurisdiction where the data protection laws may differ than those from your jurisdiction.

+

If you are located outside United States and choose to provide information to us, please note that we transfer the data, including Personal Data, to United States and process it there.

+

Your consent to this Privacy Policy followed by your submission of such information represents your agreement to that transfer.

+

Host Yo Self will take all steps reasonably necessary to ensure that your data is treated securely and in accordance with this Privacy Policy and no transfer of your Personal Data will take place to an organization or a country unless there are adequate controls in place including the security of your data and other personal information.

+

Disclosure Of Data

+

Legal Requirements

+

Host Yo Self may disclose your Personal Data in the good faith belief that such action is necessary to:

+ +

Security Of Data

+

The security of your data is important to us, but remember that no method of transmission over the Internet, or method of electronic storage is 100% secure. While we strive to use commercially acceptable means to protect your Personal Data, we cannot guarantee its absolute security.

+

Service Providers

+

We may employ third party companies and individuals to facilitate our Service ("Service Providers"), to provide the Service on our behalf, to perform Service-related services or to assist us in analyzing how our Service is used.

+

These third parties have access to your Personal Data only to perform these tasks on our behalf and are obligated not to disclose or use it for any other purpose.

+

Links To Other Sites

+

Our Service may contain links to other sites that are not operated by us. If you click on a third party link, you will be directed to that third party's site. We strongly advise you to review the Privacy Policy of every site you visit.

+

We have no control over and assume no responsibility for the content, privacy policies or practices of any third party sites or services.

+

Children's Privacy

+

Our Service does not address anyone under the age of 18 ("Children").

+

We do not knowingly collect personally identifiable information from anyone under the age of 18. If you are a parent or guardian and you are aware that your Children has provided us with Personal Data, please contact us. If we become aware that we have collected Personal Data from children without verification of parental consent, we take steps to remove that information from our servers.

+

Changes To This Privacy Policy

+

We may update our Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on this page.

+

We will let you know via email and/or a prominent notice on our Service, prior to the change becoming effective and update the "effective date" at the top of this Privacy Policy.

+

You are advised to review this Privacy Policy periodically for any changes. Changes to this Privacy Policy are effective when they are posted on this page.

+

Contact Us

+

If you have any questions about this Privacy Policy, please contact us:

+

+
+ + +
+
+ + +   (You can spawn multiple hosts with this key). +
Drag and drop a folder or click to share a file.
@@ -191,194 +235,11 @@

Made by schollz, source available on Github.

- + + \ No newline at end of file