Compare commits

...
21 Commits
Author SHA1 Message Date
whoswhip ae3b96d7e0 Update README.md
no longer using react & vite, switching back to pure html
2025-01-16 17:36:51 -05:00
whoswhip 6e95ae595a Update README.md 2025-01-15 23:20:41 -05:00
whoswhip 517a82d058 Enhance password security and simplify configuration
Turns out I should've looked into the bcrypt hashing algorithm a bit more, turns out you can have a unique salt per hash and can just use a verify method

- Remove `salt` and `smallerSalt` fields from `Program` class.
- Replace `Password` with `PasswordHash` in `Paste` and `PrivatePaste` classes.
- Generate a new salt for each password hash.
- Use `BCrypt.Net.BCrypt.Verify` for password verification.
- Remove `salt` and `smallerSalt` logic from `config.json`.
- Ensure consistent use of `PasswordHash` for storing and verifying passwords.
2024-10-29 17:11:43 -04:00
whoswhip 46615aba5b Refactor endpoints and update HTML for new API
Simplified /archive endpoint to return static HTML without dynamic content or database queries. Refactored CreatePaste method to accept a Paste object and conditionally write compressed or uncompressed content based on size. Added new /api/pastes/get endpoint for fetching paginated pastes in JSON format.

Updated archives.html to remove dynamic placeholders, using JavaScript for fetching and displaying pastes, and handling user authentication and pagination. Improved index.html with new font family and font weight for buttons. Updated paste.html to truncate long paste titles for display.

Removed unused using directive in Turnstile.cs. Updated Program.cs to include new API endpoint and refactored CreatePaste method.
2024-10-25 16:40:26 -04:00
whoswhip 59c609e7c1 Merge branch 'master' of https://github.com/whoswhip/Sharpbin 2024-10-19 15:21:56 -04:00
whoswhip ada51d5c56 Move install script 2024-10-19 15:21:52 -04:00
whoswhip c158cde86d Update README.md 2024-10-19 15:19:33 -04:00
whoswhip 38d25d785e Merge branch 'master' of https://github.com/whoswhip/Sharpbin 2024-10-19 15:19:14 -04:00
whoswhip 410172f922 Update rate limiters, endpoints, and UI styles
Added a new "fixed-xl" rate limiter policy with a permit limit of 16 and applied it to several endpoints. Replaced "fixed-bigger" with "fixed-xl" on some endpoints. Introduced a new POST endpoint `/api/pastes/admin/change-id` for changing paste IDs, including authorization checks and error handling. Enhanced logging for paste edits to include paste ID and user info. Adjusted rate limiting policies for various endpoints to use "fixed-bigger" instead of "fixed".

Modified UI styles: changed `.nav-div` margin-top in `index.html` from 10px to 1.5px, increased `backdrop-filter` blur in `paste.html` and `privatepaste.html` from 2.5px to 5px, added a border to `.input-wrapper-container` in `paste.html` and `privatepaste.html`, removed the title attribute from `<h1>` in `privatepaste.html`, simplified JSON parsing in `fetchInfo` function, removed redundant localization code, and updated `.user-a` class to use `:any-link` pseudo-class.

Various minor adjustments to improve code readability and maintainability.
2024-10-19 15:19:09 -04:00
whoswhip b872de29d2 Update README.md 2024-10-19 00:56:34 -04:00
whoswhip c90bd84ad7 Update README.md 2024-10-19 00:56:02 -04:00
whoswhip eb542342c9 Hot fixes, changed every single writeasjsonasync to writeasync cause it would bug some other stuff,fixed the authentication api which for some reason redirected to lost paste???? 2024-10-19 00:46:19 -04:00
whoswhip 92f1ef1dbf Update install.sh 2024-10-19 00:14:23 -04:00
whoswhip 553b1a12db Update install.sh 2024-10-19 00:12:01 -04:00
whoswhip bdcc3a1dc6 Refactor for async operations and add new features
Updated Compression.cs to support asynchronous operations, including new methods for decompressing byte arrays and checking compression status.
Enhanced Logging.cs with asynchronous logging methods.
Refactored Program.cs to replace synchronous calls with asynchronous ones, added a new endpoint for editing pastes, and implemented rate limiting.
Removed outdated logging configuration.
2024-10-19 00:05:59 -04:00
whoswhip c28b9b92b1 merge 2024-10-18 20:45:31 -04:00
whoswhip 0d5fd3bc5d Extra checks and delete confirmation for pastes
## Copilot Generated Commit Details Below

Enhance auth and UI with notifications and delete confirmation

Enhanced authentication in Program.cs by adding checks for the
logged-in user and ensuring proper response handling. Improved
UI in paste.html and privatepaste.html by adding a confirmation
dialog for deletions and a notification system to inform users
of actions and errors. Added CSS styles to support these new
features with appropriate styling and animations.
2024-10-18 20:44:19 -04:00
whoswhip ab04010c30 Didnt mean to merge this! 2024-10-18 20:15:00 -04:00
whoswhip 49f8911be2 Merge files 2024-10-18 20:13:47 -04:00
whoswhip eb21e6d662 Pretty big update, this adds file compression on the server side to preserve space on the disk.
Switched the paste info displaying from server side to client side, which also added a new api to fetch the info.
A new api to check if the user is authorized, (/api/accounts/authenticated)

## Commit Message Details Below Generated by Copilot
Add compression, and install script

Added EncryptByteArray and DecryptByteArray methods to the Encryption class for handling byte array encryption and decryption.
Removed unused namespaces from Program.cs.
Replaced direct file content reading and HTML manipulation with database queries and JSON responses for better error handling and response consistency.
Added JSON error responses for various error conditions.
Implemented content compression and decompression using GZip in Compression.cs to reduce file size and improve performance.
Updated paste creation and retrieval logic to handle compressed and encrypted content.
Added new API endpoints for fetching paste information and checking user authentication status.
Modified HTML templates to dynamically fetch and display paste information and user authentication status using JavaScript.
Added Paste UID property to the Paste class to store unique identifiers for pastes.
Created a new Compression class to handle string compression and decompression using GZip.
Updated the InitializeAsync method to create the pastes.sqlite file if it does not exist.
Enhanced the user interface to show or hide elements based on user authentication status and paste ownership (client side).
Improved error handling and user feedback in the JavaScript code.
Added logic to handle compressed and encrypted content in various parts of the application.
Added a new Bash script (install.sh) to install Sharpbin on a Linux system, which includes fetching the latest release, extracting it, and configuring Cloudflare keys.
2024-10-18 20:12:48 -04:00
whoswhip 233b338f9b Fix Deletion Button Not Appearing
There was an extra space in the html for some reason around the area where its usually supposed to replace it with a variable server side. This commit fixes that issue.
2024-10-08 17:29:19 -04:00
15 changed files with 1335 additions and 352 deletions
+62
View File
@@ -0,0 +1,62 @@
using System.IO.Compression;
using System.Text;
using System.Threading.Tasks;
namespace Sharpbin
{
public class Compression
{
public static async Task<byte[]> CompressString(string text)
{
byte[] compressedBytes;
using (var ms = new MemoryStream())
{
using (var cs = new GZipStream(ms, CompressionMode.Compress))
{
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
await cs.WriteAsync(inputBytes, 0, inputBytes.Length);
}
compressedBytes = ms.ToArray();
}
return compressedBytes;
}
public static async Task<string> DecompressByteArrayToString(byte[] compressedBytes)
{
string decompressedText;
using (var ms = new MemoryStream(compressedBytes))
{
using (var cs = new GZipStream(ms, CompressionMode.Decompress))
{
using (var sr = new StreamReader(cs))
{
decompressedText = await sr.ReadToEndAsync();
}
}
}
return decompressedText;
}
public static async Task<byte[]> DecompressByteArray(byte[] compressedBytes)
{
byte[] decompressedBytes;
using (var ms = new MemoryStream(compressedBytes))
{
using (var cs = new GZipStream(ms, CompressionMode.Decompress))
{
using (var msDecompressed = new MemoryStream())
{
await cs.CopyToAsync(msDecompressed);
decompressedBytes = msDecompressed.ToArray();
}
}
}
return decompressedBytes;
}
public static bool IsCompressed(byte[] data)
{
return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
}
}
}
+49
View File
@@ -31,6 +31,31 @@ namespace Sharpbin
return Convert.ToBase64String(encryptedBytes);
}
public static string EncryptByteArray(byte[] bytes, string password)
{
byte[] encryptedBytes;
using (Aes aes = Aes.Create())
{
aes.KeySize = 256;
aes.Key = Encoding.UTF8.GetBytes(password.PadRight(32, ' '));
aes.IV = new byte[16];
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
using (var ms = new MemoryStream())
{
using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
{
cs.Write(bytes, 0, bytes.Length);
}
encryptedBytes = ms.ToArray();
}
}
return Convert.ToBase64String(encryptedBytes);
}
public static string DecryptString(string input, string password)
{
@@ -59,5 +84,29 @@ namespace Sharpbin
return decryptedText;
}
public static byte[] DecryptByteArray(byte[] input, string password)
{
byte[] decryptedBytes;
using (Aes aes = Aes.Create())
{
aes.KeySize = 256;
aes.Key = Encoding.UTF8.GetBytes(password.PadRight(32, ' '));
aes.IV = new byte[16];
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
using (var ms = new MemoryStream(input))
{
using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
{
decryptedBytes = new byte[ms.Length];
cs.Read(decryptedBytes, 0, decryptedBytes.Length);
}
}
}
return decryptedBytes;
}
}
}
+26 -2
View File
@@ -1,8 +1,9 @@
namespace Sharpbin
using Org.BouncyCastle.Asn1.Cms;
namespace Sharpbin
{
public class Logging
{
public static string Api_CreateMessage = "";
public static async Task<Log> LogRequestAsync(HttpContext context)
{
Log log = new Log();
@@ -14,6 +15,29 @@
log.IP = context.Request.Headers["X-Forwarded-For"].ToString() ?? context.Connection.RemoteIpAddress.ToString();
return log;
}
public static async Task LogError(string message)
{
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[ERROR - {DateTime.Now}] {message}");
await File.AppendAllTextAsync("logs.log", $"[ERROR - {DateTime.Now}] {message}\n");
Console.ResetColor();
}
public static async Task LogInfo(string message)
{
Console.WriteLine($"[INFO - {DateTime.Now}] {message}");
await File.AppendAllTextAsync("logs.log", $"[INFO - {DateTime.Now}] {message}\n");
Console.ResetColor();
}
public static async Task LogWarning(string message)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine($"[WARNING - {DateTime.Now}] {message}");
await File.AppendAllTextAsync("logs.log", $"[WARNING - {DateTime.Now}] {message}\n");
Console.ResetColor();
}
}
public class Log
{
+595 -288
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -49,7 +49,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="pastes.sqlite">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
@@ -90,7 +90,7 @@
<ItemGroup>
<Content Update="config.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
-2
View File
@@ -1,6 +1,4 @@
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Text;
namespace Sharpbin
+3 -3
View File
@@ -153,7 +153,7 @@
}).then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`${result.message} for ${reason}`);
} else {
@@ -174,7 +174,7 @@
}).then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`${result.message} for ${reason}`);
} else {
@@ -199,7 +199,7 @@
}).then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`${result.message} to ${result.password}`);
navigator.clipboard.writeText(result.password);
+69 -7
View File
@@ -13,10 +13,13 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
<div class="nav-hamburger-menu">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
<path fill-rule="evenodd"
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
</svg>
@@ -24,7 +27,9 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
</div>
<div class="container-wrapper">
@@ -32,18 +37,73 @@
<h1>paste archive</h1>
<input type="text" placeholder="search" class="text-input" oninput="search()">
<div class="pastes-wrapper">
{pastes}
Loading...
</div>
<div class="buttons-wrapper">
<a class="arrow-button" href="/archive?page={backpagenum}">&lt;</a>
<p>{currentpagenum}/{totalpages}</p>
<a class="arrow-button" href="/archive?page={pagenum}">></a>
<a class="arrow-button" id="back-page">&lt;</a>
<p id="page-count"></p>
<a class="arrow-button" id="next-page">></a>
</div>
</div>
</div>
</body>
<script>
let searchTimeout;
let pagenum = 1;
function authenticate() {
fetch('/api/accounts/authenticate')
.then(response => response.json())
.then(data => {
if (data.message == "Authenticated") {
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'none';
});
document.getElementById('dash-btn').style.display = 'block';
}else{
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'block';
});
}
});
}
function getPastes() {
fetch(`/api/pastes/get`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
page: pagenum
})
})
.then(response => response.json())
.then(data => {
const pastesWrapper = document.querySelector('.pastes-wrapper');
const pageCount = document.getElementById('page-count');
pastesWrapper.innerHTML = '';
pageCount.innerHTML = `${pagenum}/${data.pages}`;
if (data.pastes.length === 0) {
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
return;
}
data.pastes.forEach(paste => {
title = paste.title.length > 30 ? paste.title.substring(0, 30) + '...' : paste.title;
pastesWrapper.innerHTML += `<a href="/${paste.id}" title="${paste.title}"><li>${title} ${paste.date} ${paste.size}</li></a>`;
});
});
}
document.getElementById('back-page').addEventListener('click', function () {
if (pagenum > 1) {
pagenum--;
getPastes();
}
});
document.getElementById('next-page').addEventListener('click', function () {
pagenum++;
getPastes();
});
document.addEventListener('DOMContentLoaded', () => {
var mobile = window.mobileCheck();
@@ -51,6 +111,8 @@
document.querySelector('.nav-div').style.display = 'none';
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
}
authenticate();
getPastes();
});
document.getElementById("hamburger-button").addEventListener("click", function () {
+7 -6
View File
@@ -84,11 +84,10 @@
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
if (result.pasteId != null) {
window.location.href = `/${result.pasteId}`;
} else if (result.error != null) {
notification(result.error);
if (obj.pasteId != null) {
window.location.href = `/${obj.pasteId}`;
} else if (obj.error != null) {
notification(obj.error);
}
})
});
@@ -309,6 +308,8 @@
border: #2a2a2a00 2px solid;
cursor: pointer;
font-size: 1.2em;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
}
.button:hover {
@@ -319,7 +320,7 @@
.nav-div {
top: 0;
margin-top: 10px;
margin-top: 1.5px;
position: absolute;
display: flex;
flex-direction: row;
+1 -1
View File
@@ -63,7 +63,7 @@
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
isLoggingIn = true;
if (result.message != null) {
window.location.href = "/";
+281 -9
View File
@@ -4,7 +4,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{pastetitle}</title>
</head>
<body>
@@ -12,7 +11,9 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
<div class="nav-hamburger-menu">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
@@ -24,13 +25,16 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
</div>
<div class="container-wrapper">
<div class="paste-container">
<h1 id="paste-title" title="{pastetitleattribute}">{pastetitle}</h1>
<h3 class="uploader-text">{username} <a id="creationdate">{creationdate}</a> {pastesize}</h3>
<h1 id="paste-title"></h1>
<h3 class="uploader-text"><a id="uploader-username" class="user-a"></a> <a id="creationdate"></a> <a id="paste-size"></a>
</h3>
<div class="paste-wrapper">
<p id="text"></p>
</div>
@@ -40,22 +44,93 @@
</a>
<button id="copy-button" class="button">copy</button>
<button id="download-button" class="button">download</button>
{deletebutton}
<button id="delete-button" class="button" style="display: none;">delete</button>
<button id="edit-button" class="button" style="display: none;">edit</button>
</div>
</div>
</div>
<div class="notifcations-wrapper" id="notifications"></div>
<div class="input-wrapper" id="input-wrapper">
<div class="input-wrapper-container">
<h2 id="input-message"></h2>
<div>
<button id="yes-button" class="button">Yes</button>
<button id="no-button" class="button">No</button>
</div>
</div>
</div>
</body>
<script>
info = "";
editing = false;
function localizeDateTime(unixTimestamp) {
const date = new Date(unixTimestamp * 1000);
return date.toLocaleString();
}
function authenticate() {
fetch('/api/accounts/authenticate')
.then(response => response.json())
.then(data => {
if (data.message == "Authenticated") {
if (info.uploader == data.username || data.type == "Admin") {
document.getElementById('delete-button').style.display = 'block';
document.getElementById('edit-button').style.display = 'block';
}
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'none';
});
document.getElementById('dash-btn').style.display = 'block';
}else{
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'block';
});
}
});
}
function fetchInfo() {
fetch('/api/pastes/info?id={pasteid}')
.then(response => response.json())
.then(json => {
info = json;
title = json.title.length > 40 ? json.title.substring(0, 40) + '...' : json.title;
document.getElementById('uploader-username').innerText = json.uploader || 'Anonymous';
document.getElementById('creationdate').innerText = localizeDateTime(json.date);
document.getElementById('paste-size').innerText = json.size;
document.getElementById('paste-size').title = `Compressed Size: ${json.compressedSize}`;
document.getElementById('paste-title').innerText = title;
document.getElementById('paste-title').title = json.title;
if (json.title == "") {
document.getElementById('paste-title').innerText = `Untitled ${json.uid}`;
document.title = `Untitled ${json.uid}`;
}
if (json.uploader && json.uploader.startsWith("Anonymous") && json.uploader.length == 46) {
document.getElementById('uploader-username').innerText = 'Anonymous';
} else if (json.uploader) {
document.getElementById('uploader-username').href = `/u/${json.uploader}`;
}
})
.catch(error => console.error('Error fetching paste info:', error));
}
document.getElementById("edit-button").addEventListener("click", function () {
if (editing) {
createInput('Are you sure you want to save this edit?');
document.getElementById('yes-button').addEventListener("click", finalizeEdit);
} else {
editing = true;
var editButton = document.getElementById('edit-button');
editButton.innerText = 'save';
var text = document.getElementById('text');
var innertext = text.innerText;
text.innerHTML = `<textarea class="textarea" id="edit-textarea" style="width: 100%; height: ${text.clientHeight}px;">${innertext}</textarea>`;
}
});
document.addEventListener("DOMContentLoaded", function () {
fetchInfo();
authenticate();
const creationdateElement = document.getElementById('creationdate');
const creationdateText = creationdateElement.innerText.trim();
const textElement = document.getElementById('text');
creationdateElement.innerText = localizeDateTime(parseInt(creationdateText));
textElement.innerText = "Loading...";
fetch(`/raw/{pasteid}`)
@@ -109,8 +184,106 @@
element.click();
document.body.removeChild(element);
});
{ deletescript }
document.getElementById("delete-button").addEventListener("click", function () {
createInput('Are you sure you want to delete this paste?');
document.getElementById("yes-button").addEventListener("click", function () {
fetch(`/api/pastes/delete?id={pasteid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: '{pasteid}'
})
})
.then(response => response.json())
.then(obj => {
const result = obj;
if (result.message != null) {
createNotification(`Success: ${result.message}`);
setTimeout(() => {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
window.location.href = '/';
}, 2000);
} else {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
createNotification(`Error: ${result.error}`);
}
});
});
});
document.getElementById("no-button").addEventListener("click", function () {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
});
function createNotification(message) {
const notificationWrapper = document.getElementById('notifications');
const notificationDiv = document.createElement('div');
notificationDiv.classList.add('notification-div');
notificationDiv.id = 'notification';
const notificationText = document.createElement('h2');
notificationText.id = 'notification-text';
notificationText.innerText = message;
notificationDiv.appendChild(notificationText);
notificationWrapper.appendChild(notificationDiv);
notificationDiv.style.animation = 'none';
notificationDiv.style.display = 'none';
notificationDiv.style.display = 'flex';
notificationDiv.style.animation = 'hoverup 1s';
setTimeout(() => {
notificationDiv.style.animation = 'hoverdown 1s';
}, 4000);
setTimeout(() => {
notificationDiv.remove();
}, 4900);
}
function createInput(message) {
const inputWrapper = document.getElementById('input-wrapper');
const inputMessage = document.getElementById('input-message');
inputMessage.innerText = message;
inputWrapper.style.display = 'flex';
}
function finalizeEdit() {
var textarea = document.getElementById('edit-textarea');
var text = textarea.value;
fetch(`/api/pastes/edit`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: '{pasteid}',
text: text
})
})
.then(response => response.json())
.then(obj => {
const result = obj;
if (result.message != null) {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
document.getElementById('edit-button').innerText = "edit";
createNotification(`Success: ${result.message}`);
document.getElementById('text').innerText = text;
document.getElementById('edit-textarea').remove();
editing = false;
} else {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
document.getElementById('edit-button').innerText = "edit";
createNotification(`Error: ${result.error}`);
}
});
}
</script>
@@ -118,6 +291,44 @@
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap');
.textarea{
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: 500;
max-width: 100%;
min-width: 100%;
background-color: #1d1d1d;
color: white;
border: none;
}
.textarea:focus{
outline: none;
}
.input-wrapper{
z-index: 100;
display: none;
position: absolute;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: white;
backdrop-filter: blur(5px);
}
.input-wrapper-container{
z-index: 101;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 50%;
border-radius: 5px;
padding: 20px;
background-color: #181818;
border: #222222 2px solid;
}
body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
@@ -210,12 +421,13 @@
font-weight: 600;
}
.user-a {
.user-a:any-link {
color: rgb(190, 190, 190);
text-decoration: none;
text-decoration: underline;
}
.nav-div {
top: 0;
margin-top: 10px;
@@ -233,6 +445,7 @@
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
z-index: 999999;
}
.nav-hamburger-menu {
@@ -314,4 +527,63 @@
}
}
@keyframes hoverup {
0% {
opacity: 0;
transform: translateY(100%);
}
25% {
opacity: 1;
}
50% {
transform: translateY(-10px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
@keyframes hoverdown {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-10px);
}
100% {
transform: translateY(200%);
}
}
.notification-div {
display: flex;
right: 0;
bottom: 0;
width: fit-content;
height: fit-content;
color: white;
background-color: #181818;
border-radius: 5px;
border: #222222 2px solid;
padding-left: 10px;
padding-right: 10px;
margin-right: 10px;
margin-bottom: 10px;
justify-content: center;
align-items: center;
z-index: 102;
position: absolute;
}
.notifcations-wrapper{
z-index: 101;
}
</style>
+207 -29
View File
@@ -12,10 +12,13 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
<div class="nav-hamburger-menu">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
<path fill-rule="evenodd"
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
</svg>
@@ -23,13 +26,16 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
</div>
<div class="container-wrapper">
<div class="paste-container">
<h1 id="paste-title" title="{pastetitleattribute}">{pastetitle}</h1>
<h3 class="uploader-text">{username} <a id="creationdate">{creationdate}</a> {pastesize}</h3>
<h1 id="paste-title"></h1>
<h3 class="uploader-text"><a id="uploader-username" class="user-a"></a> <a id="creationdate"></a> <a id="paste-size"></a>
</h3>
<div class="paste-wrapper">
<p id="text"></p>
</div>
@@ -39,13 +45,15 @@
</a>
<button id="copy-button" class="button">copy</button>
<button id="download-button" class="button">download</button>
{deletebutton}
<button id="delete-button" class="button" style="display: none;">delete</button>
<button id="edit-button" class="button" style="display: none;">edit</button>
</div>
</div>
<div class="passwordDiv">
<div class="inputDiv">
<h1>This paste is password protected</h1>
<input type="password" id="password" class="textinput" name="password" maxlength="500" placeholder="password">
<input type="password" id="password" class="textinput" name="password" maxlength="500"
placeholder="password">
<button id="submitPassword" class="button-input">Submit</button>
</div>
</div>
@@ -53,8 +61,76 @@
<div class="notification-div" id="notification">
<h2 id="notification-text"></h2>
</div>
<div class="input-wrapper" id="input-wrapper">
<div class="input-wrapper-container">
<h2 id="input-message"></h2>
<div>
<button id="yes-button" class="button">Yes</button>
<button id="no-button" class="button">No</button>
</div>
</div>
</div>
</body>
<script>
info = "";
editing = false;
function authenticate() {
fetch('/api/accounts/authenticate')
.then(response => response.json())
.then(data => {
if (data.message == "Authenticated") {
if (info.uploader == data.username || data.type == "Admin") {
document.getElementById('delete-button').style.display = 'block';
//document.getElementById('edit-button').style.display = 'block';
}
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'none';
});
document.getElementById('dash-btn').style.display = 'block';
}else{
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'block';
});
}
});
}
function fetchInfo() {
fetch('/api/pastes/info?id={pasteid}')
.then(response => response.json())
.then(json => {
info = json;
document.getElementById('uploader-username').innerText = json.uploader;
document.getElementById('creationdate').innerText = localizeDateTime(json.date);
document.getElementById('paste-size').innerText = json.size;
document.getElementById('paste-size').title = `Compressed Size: ${json.compressedSize}`;
document.getElementById('paste-title').innerText = json.title;
document.getElementById('paste-title').title = json.title;
if (json.title == "") {
document.getElementById('paste-title').innerText = `Untitled ${json.uid}`;
document.title = `Untitled ${json.uid}`;
}
if (json.uploader.startsWith("Anonymous") && json.uploader.length == 46) {
document.getElementById('uploader-username').innerText = 'Anonymous';
} else {
document.getElementById('uploader-username').href = `/u/${json.uploader}`;
}
});
}
document.getElementById("edit-button").addEventListener("click", function () {
if (editing) {
createInput('Are you sure you want to save this edit?');
document.getElementById('yes-button').removeEventListener("click", deletePaste);
document.getElementById('yes-button').addEventListener("click", finalizeEdit);
document.getElementById('yes-button').removeEventListener("click", finalizeEdit);
} else {
editing = true;
var editButton = document.getElementById('edit-button');
editButton.innerText = 'save';
var text = document.getElementById('text');
var innertext = text.innerText;
text.innerHTML = `<textarea class="textarea" id="edit-textarea" style="width: 100%; height: ${text.clientHeight}px;">${innertext}</textarea>`;
}
});
document.getElementById("submitPassword").addEventListener("click", function () {
var password = document.getElementById("password").value;
fetch(`/api/pastes/password/{pasteid}`, {
@@ -66,31 +142,28 @@
password: password
})
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
if (result.content != null){
const textElement = document.getElementById('text');
textElement.innerText = result.content;
document.querySelector(".passwordDiv").style.display = "none";
const viewRawButton = document.getElementById('view-raw-a');
viewRawButton.href = `/raw/{pasteid}?password=${password}`;
}
else {
notification(`Error: ${result.error}`);
}
});
.then(response => response.json())
.then(result => {
if (result.content != null) {
const textElement = document.getElementById('text');
textElement.innerText = result.content;
document.querySelector(".passwordDiv").style.display = "none";
const viewRawButton = document.getElementById('view-raw-a');
viewRawButton.href = `/raw/{pasteid}?password=` + password;
}
else {
notification(`Error: ${result.error}`);
}
});
});
function localizeDateTime(unixTimestamp) {
const date = new Date(unixTimestamp * 1000);
return date.toLocaleString();
}
document.addEventListener("DOMContentLoaded", function() {
const creationdateElement = document.getElementById('creationdate');
const creationdateText = creationdateElement.innerText.trim();
creationdateElement.innerText = localizeDateTime(parseInt(creationdateText));
document.addEventListener("DOMContentLoaded", function () {
fetchInfo();
authenticated();
var mobile = window.mobileCheck();
if (mobile) {
document.querySelector('.nav-div').style.display = 'none';
@@ -122,7 +195,66 @@
element.click();
document.body.removeChild(element);
});
{deletescript}
document.getElementById("delete-button").addEventListener("click", function () {
createInput('Are you sure you want to delete this paste?');
document.getElementById('yes-button').removeEventListener("click", finalizeEdit);
document.getElementById('yes-button').addEventListener("click", deletePaste);
document.getElementById('yes-button').removeEventListener("click", deletePaste);
});
function deletePaste() {
fetch(`/api/pastes/delete?id={pasteid}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: '{pasteid}'
})
})
.then(response => response.json())
.then(result => {
if (result.message != null) {
createNotification(`Success: ${result.message}`);
setTimeout(() => {
window.location.href = '/';
}, 2000);
} else {
createNotification(`Error: ${result.error}`);
}
});
}
function finalizeEdit() {
var textarea = document.getElementById('edit-textarea');
var text = textarea.value;
fetch(`/api/pastes/edit`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: '{pasteid}',
text: text
})
})
.then(response => response.json())
.then(result => {
if (result.message != null) {
createNotification(`Success: ${result.message}`);
document.getElementById('text').innerText = text;
document.getElementById('edit-textarea').remove();
editing = false;
} else {
createNotification(`Error: ${result.error}`);
}
});
}
document.getElementById("no-button").addEventListener("click", function () {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
document.getElementById('yes-button').removeEventListener("click", finalizeEdit);
document.getElementById('yes-button').removeEventListener("click", deletePaste);
});
function notification(message) {
const notification = document.getElementById('notification');
const notificationText = document.getElementById('notification-text');
@@ -140,13 +272,19 @@
}, 4900);
}
function createInput(message) {
const inputWrapper = document.getElementById('input-wrapper');
const inputMessage = document.getElementById('input-message');
inputMessage.innerText = message;
inputWrapper.style.display = 'flex';
}
</script>
</html>
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap');
body {
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
@@ -157,6 +295,32 @@
background-color: #0d0d0d;
}
.input-wrapper {
z-index: 100;
display: none;
position: absolute;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: white;
backdrop-filter: blur(5px);
}
.input-wrapper-container {
z-index: 101;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 50%;
border-radius: 5px;
padding: 20px;
background-color: #181818;
border: #222222 2px solid;
}
.container-wrapper {
display: flex;
flex-direction: column;
@@ -165,6 +329,7 @@
width: 100%;
height: 98.7vh;
}
.button-input {
transition: 300ms;
background-color: #222222;
@@ -182,11 +347,13 @@
font-weight: 625;
box-sizing: content-box;
}
.button-input:hover {
transition: 300ms;
background-color: #333333;
border: 2px solid #3a3a3a;
}
.passwordDiv {
z-index: 100;
position: absolute;
@@ -199,6 +366,7 @@
justify-content: center;
align-items: center;
}
.inputDiv {
display: flex;
flex-direction: column;
@@ -207,6 +375,7 @@
width: fit-content;
color: white;
}
.textinput {
width: 100%;
height: 50px;
@@ -219,6 +388,7 @@
font-weight: 625;
color: white;
}
.textinput:focus {
outline: none;
border: 2px solid #333333;
@@ -297,7 +467,7 @@
font-weight: 600;
}
.user-a {
.user-a:any-link {
color: rgb(190, 190, 190);
text-decoration: none;
text-decoration: underline;
@@ -321,6 +491,7 @@
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
z-index: 999999;
}
.nav-hamburger-menu {
@@ -383,6 +554,7 @@
background-color: #333333;
border: #3a3a3a 2px solid;
}
@media screen and (max-width: 800px) {
.nav-div {
display: none;
@@ -401,6 +573,7 @@
}
}
@keyframes hoverup {
0% {
opacity: 0;
@@ -436,6 +609,7 @@
}
}
.notification-div {
position: fixed;
display: none;
@@ -453,6 +627,10 @@
margin-bottom: 10px;
justify-content: center;
align-items: center;
z-index: 102;
position: absolute;
}
.notifcations-wrapper{
z-index: 101;
}
</style>
+1 -1
View File
@@ -65,7 +65,7 @@
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
window.location.href = "/";
isLoggingIn = false;
+7
View File
@@ -1,3 +1,5 @@
# Sharpbin is currently being re-written.
Quite frankly the current code base is quite messy, I also am just bored and would like to improve this since it's a pretty fun thing to make.
# Sharpbin
Sharpbin is a Pastebin type website completely in C#, except for the frontend, being pure HTML & CSS.
Sharpbin can be used for sharing large amounts of text.
@@ -13,8 +15,13 @@ Sharpbin can be used for sharing large amounts of text.
- Private encrypted pastes, sadly the encryption is server side, although client side may be soon!
- Mobile Support
- Captchas for logins and sign ups
- Editable pastes
... And more to come!
# TODO
- ~~Fix css on the confirmations~~
- ~~Update file size when an edit is made in the database~~
# Demo Website & Screenshots
You can find the test website at https://bin.whoswhip.top , there is no removed functionality and is the exact same code in this repo.
<div>
+23
View File
@@ -0,0 +1,23 @@
#!/bin/bash
############################################
#### Sharpbin Linux installer ####
############################################
##
## This is a semi completed script to install Sharpbin on Linux, however it does not set it as a system daemon/service, cause idk how to do that lol
##
mkdir sharpbin
cd sharpbin
curl -s "https://api.github.com/repos/whoswhip/Sharpbin/releases/latest" | jq -r '.assets[] | select(.name | test("sharpbin-linux-.*\\.tar$")) | .browser_download_url' | xargs -I {} curl -L -o sharpbin-linux.tar {}
tar -xvf sharpbin-linux.tar
chmod +x Sharpbin
echo "Enter your cloudflare sitekey: "
read sitekey
echo "Enter your cloudflare secretkey: "
read secretkey
echo "{ \"CF_TurnstileSiteKey\": \"$sitekey\", \"CF_TurnstileSecret\": \"$secretkey\" }" > config.json