Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
update web interface w/ create & delete features
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexLynd committed May 11, 2022
1 parent a4baafb commit b5f9296
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 21 deletions.
37 changes: 33 additions & 4 deletions RubberNugget/RubberNugget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern SH1106Wire display;
extern String rubberCss;
extern String rubberHtml;
extern String rubberJs;
extern String createHtml;

extern String payloadPath;
bool webstuffhappening = false;
Expand Down Expand Up @@ -51,15 +52,44 @@ void stylesheet() {
server.send(200, "text/css", runCss);
}

void create() {
server.send(200, "text/html", createHtml);
}

void javascript() {
server.send(200, "text/javascript", runJs);
}

void delpayload() {
String path = (server.arg("path"));
char tab2[100];
strcpy(tab2, path.c_str());
f_unlink(tab2);
server.send(200);
}

void websave() {
String path = (server.arg("path"));
String content = (server.arg("content"));
content.replace(" ", "/");

FRESULT fr;
FIL file;
uint16_t size;
UINT bytesRead;


FILINFO fno;
char tab1[100];
strcpy(tab1, path.substring(0,path.lastIndexOf("/")).c_str());

fr = f_stat(tab1, &fno);

if (fr!=FR_OK) {
Serial.println((char*) tab1);
f_mkdir(tab1);
}

char tab2[100];
strcpy(tab2, path.c_str());

Expand All @@ -69,10 +99,7 @@ void websave() {
uint8_t raw[BASE64::decodeLength(tab3)];
BASE64::decode(tab3, raw);

FRESULT fr;
FIL file;
uint16_t size;
UINT bytesRead;


fr = f_open(&file, tab2, FA_WRITE | FA_CREATE_ALWAYS);
if (fr == FR_OK) {
Expand Down Expand Up @@ -181,9 +208,11 @@ void setup() {
server.on("/style.css", stylesheet);

server.on("/savepayload.php", HTTP_POST, websave);
server.on("/deletepayload.php", HTTP_POST, delpayload);
server.on("/runlive.php", HTTP_POST, webrunlive);
server.on("/getpayload.php", HTTP_GET, webget);
server.on("/runpayload.php", HTTP_GET, webrun);
server.on("/create.html", create);

server.begin();

Expand Down
8 changes: 5 additions & 3 deletions RubberNugget/Webserver.h

Large diffs are not rendered by default.

Binary file removed v1.0.3-beta-RubberNugget.bin
Binary file not shown.
25 changes: 19 additions & 6 deletions web/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,37 @@
<div class="payloadTable">
<h2>Create a payload</h2>
<div>
<input type="text" id="fname" name="fname" placeholder="Payload Name">
<input type="text" id="lname" name="lname" placeholder="Payload Category">
<input type="text" id="pnamec" name="fname" placeholder="Payload Name">
<input type="text" id="pcatc" name="lname" placeholder="Payload Category">
<div style="margin-bottom:20px;">
<label for="os">OS:</label>
<select name="os" id="osc">
<option value="Linux">Linux</option>
<option value="Mac">Mac</option>
<option value="Windows">Windows</option>
<option value="Starred">Starred</option>
</select>
</div>
</div>
<!-- <input type="submit" value="Submit"> -->

<textarea id="w3review" name="w3review" rows="10" placeholder="Start writing payload here!"></textarea>
<textarea id="textarea1" name="w3review" rows="10" placeholder="Start writing payload here!"></textarea>

<p id="statusText"></p>

<span>
<button class="edit">Save</button>
<button class="run">Run Live</button>
<button class="edit" onclick="saveNew()">Save</button>
<button class="run" onclick="runLive()">Run Live</button>
</span>
</div>


<div style="text-align: center; margin-top: 10em">
<p><b>Copyright 2022, HakCat Hardware</b></p>
<p>Beta v1.0</p>
<p>Beta v1.0.4</p>
</div>
</div>
<script src="run.js"></script>
</body>

</html>
Empty file added web/create.js
Empty file.
4 changes: 2 additions & 2 deletions web/run.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script src="run.js">
</script>

<div class="status"></div>
<div class="statusText"></div>

<nav>
<div class="container">
Expand Down Expand Up @@ -68,7 +68,7 @@ <h2>Windows</h2>

<div style="text-align: center; margin-top: 10em">
<p><b>Copyright 2022, HakCat Hardware</b></p>
<p>Beta v1.0</p>
<p>Beta v1.0.4</p>
</div>
</div>
</body>
Expand Down
32 changes: 30 additions & 2 deletions web/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ function loadPayloadTables() {
console.log("Loading payloads...");

const xhttp = new XMLHttpRequest();
xhttp.open("GET", "http://localhost/data.json?rand=" + Date.now(), false); // prove endpoint to return json
xhttp.open("GET", "/data.json?rand=" + Date.now(), false); // prove endpoint to return json
xhttp.send(null);

var json = xhttp.responseText;
const obj = JSON.parse(json);
const pTables = ["tableStarred", "tableLinux", "tableMac", "tableWindows"];
const pTypes = ["Starred", "Linux", "Mac", "Windows"];
const pEditOs = ["editStarred", "editLinux", "editMac", "editWindows"]
const pEditOs = ["editStarred", "editLinux", "editMac", "editWindows"];

// append to each table
for (let i = 0; i < 4; i++) {
Expand Down Expand Up @@ -64,6 +64,7 @@ function editPayload(payloadPath, payloadEdit) {
<button class=\"run\" onclick=\"runLive(\'"+payloadEdit+"\')\">Run Live</button> \
<button class=\"edit\" onclick=\"savePayload('"+payloadEdit+"','"+payloadPath+"')\">Save</button> \
<button class=\"close\" onclick=\"closeEdit()\">Close</button> \
<button class=\"run\" onclick=\"deletePayload('"+payloadPath+"')\">Delete</button> \
</div> \
";
}
Expand Down Expand Up @@ -98,4 +99,31 @@ function savePayload(payloadEdit, payloadPath) {
xmlHttp.open("POST", "savepayload.php");
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("path="+payloadPath+"&content="+btoa(textarea1.value));
}

function deletePayload(payloadPath) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "deletepayload.php");
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.send("path="+payloadPath);

setTimeout( function () { location.reload(); }, 2000 );

}

function saveNew() {
var payloadname = document.getElementById("pnamec").value;
var payloadcat = document.getElementById("pcatc").value;
var payloados = document.getElementById("osc").value;

if (payloadname != "" && payloadcat != "") {
var newpath = "/"+payloados+"/"+payloadcat+"/"+payloadname;
document.getElementById("statusText").innerHTML="<p>Saved: <b>"+newpath+"</b></p>";
}
else {
document.getElementById("statusText").innerHTML="<p>Can't save payload! Please check the name & category fields.</p>";
}

savePayload("lolz", newpath);

}
12 changes: 8 additions & 4 deletions web/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ nav {
background-color: #263238;
}

table, textarea {
table, textarea, input, select {
border-radius: 5px;
background-color: #263238;
border: 1px solid #25282c;
color: white;
}

nav a {
Expand Down Expand Up @@ -120,9 +121,12 @@ body {
}

input {
width: 50%;
width: 100%;
box-sizing: border-box;
padding: 0;
margin: 0;
padding: 10px;
margin-bottom: 20px;
}

select {
padding: 10px;
}

0 comments on commit b5f9296

Please sign in to comment.