Skip to content

Commit

Permalink
Merge branch 'main' into add_to_launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxTheGeeek authored Dec 10, 2024
2 parents 448c21f + a670175 commit d07853a
Show file tree
Hide file tree
Showing 38 changed files with 264 additions and 44 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions launcher/public/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@
}

/*
! tailwindcss v3.4.16 | MIT License | https://tailwindcss.com
*/

/*
Expand Down Expand Up @@ -631,7 +633,7 @@ video {

/* Make elements with the HTML hidden attribute stay hidden by default */

[hidden]:where(:not([hidden="until-found"])) {
[hidden] {
display: none;
}

Expand Down Expand Up @@ -4324,7 +4326,9 @@ video {

.bg-zinc-700{
--tw-bg-opacity: 1;
background-color: rgb(63 63 70 / var(--tw-bg-opacity, 1));

background-color: rgb(63 63 70 / var(--tw-bg-opacity));

}

.bg-opacity-80{
Expand Down
34 changes: 27 additions & 7 deletions launcher/src/backend/SSHService.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,34 @@ export class SSHService {
log.error("Forwarding error: ", err);
return;
}
// Track data size for el rpc
connection.on("data", (data) => {
stream.write(data);
this.handleReceivedData(data.length, forwardOptions.srcPort);
});

// Pipe the connection to the stream and vice versa
connection.pipe(stream).pipe(connection);
connection.on("end", () => {
stream.end();
});
stream.on("end", () => {
connection.end();
});

// Listen for data on the stream
stream.on("data", (data) => {
// Call the handleReceivedData method to handle the received data
this.handleReceivedData(data.length, forwardOptions.srcPort);
connection.on("error", (error) => {
log.error("Connection error: ", error);
stream.end();
});

stream.on("error", (error) => {
log.error("Stream error: ", error);
connection.end();
});

connection.on("close", () => {
stream.destroy();
});
stream.on("close", () => {
connection.destroy();
});
}
);
Expand All @@ -330,7 +350,7 @@ export class SSHService {
/**
* Handles the received data by storing it in the rpcReceivedDatas array.
* @param {number} dataLength - The length of the received data (byte).
* @param {number} dstPort - The destination port.
* @param {number} srcPort - The source port.
*/
async handleReceivedData(dataLength, srcPort) {
try {
Expand Down
30 changes: 29 additions & 1 deletion launcher/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { TekuGasLimitConfig } from "./backend/TekuGasLimitConfig.js";
import { SSHService } from "./backend/SSHService.js";
import { ProtocolHandler } from "./backend/CustomUrlProtocol.js";
import path from "path";
import { readFileSync } from "fs";
import { readFileSync, existsSync, mkdirSync, renameSync, readdir, rmSync } from "fs";
import url from "url";
import checkSigningKeys from "./backend/web3/CSM.js";
const isDevelopment = process.env.NODE_ENV !== "production";
Expand All @@ -39,6 +39,34 @@ const protocolHandler = new ProtocolHandler(storageService);
stereumUpdater.initUpdater();
log.transports.console.level = process.env.LOG_LEVEL || "info";
log.transports.file.level = "debug";
log.transports.file.archiveLogFn = async (file) => {
file = file.toString();
const info = path.parse(file);
let backupPath = info.dir + "/backups/";
if (!existsSync(backupPath)) {
mkdirSync(backupPath);
}

renameSync(file, `${backupPath}main-${Date.now()}.log`);

let backupLogs = [];

const storedConfig = await storageService.readConfig();

readdir(backupPath, (err, files) => {
files.forEach((file) => {
backupLogs.push(file);
});
if (backupLogs.length > storedConfig.logBackups.value) {
backupLogs.reverse();
for (let i = storedConfig.logBackups.value; i < backupLogs.length; i++) {
rmSync(backupPath + backupLogs[i], { force: true }, (err) => {
if (err) throw err;
});
}
}
});
};

let remoteHost = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@mouseenter="setCursorLocation(`${service.name} toggle`)"
@mouseleave="clearCursorLocation"
>
{{ isActive ? "open" : "close" }}
{{ isActive ? "open" : "closed" }}
</div>
<div
class="service-icon w-6 h-full flex justify-center items-center p-[0.10rem]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const sshError = ref("");
const devices = ref([]);
const removeHovered = ref(false);
const addHovered = ref(false);
const isFormValid = ref(false);
const useSSHKey = ref(false);
const usePassword = ref(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>

<div
class="w-full h-full max-h-[300px] col-start-1 col-span-full row-start-2 row-end-11 overflow-x-hidden overflow-y-auto flex flex-col justify-start items-center p-3 bg-black rounded-md space-y-2"
class="w-full h-full max-h-[300px] col-start-1 col-span-full row-start-2 row-end-11 overflow-x-hidden overflow-y-auto flex flex-col justify-start items-center p-1 bg-black rounded-md space-y-2"
>
<ServerRow
v-for="(server, index) in filteredServers"
Expand All @@ -48,7 +48,27 @@
</div>
<div class="col-start-1 col-span-full row-start-11 row-span-2 self-end grid grid-cols-12 gap-x-2">
<button
class="w-full h-[50px] self-end col-start-6 col-span-full row-start-11 row-span-2 bg-gray-200 rounded-md px-4 py-2 flex justify-start items-center shadow-lg shadow-black active:shadow-none active:scale-95 cursor-pointer space-x-4 transition-all duration-200 ease-in-out hover:bg-[#336666] text-gray-800 hover:text-gray-100"
class="w-full h-[50px] self-end col-start-1 col-span-3 row-start-11 row-span-2 bg-gray-200 rounded-md px-1 flex justify-start items-center shadow-lg shadow-black active:shadow-none active:scale-95 cursor-pointer transition-all duration-200 pr-2 ease-in-out hover:bg-[#336666] text-gray-800 hover:text-gray-100"
@click="openFileInput"
@mouseenter="footerStore.cursorLocation = 'click to import server list'"
@mouseleave="footerStore.cursorLocation = ''"
>
<img class="w-16 h-7" src="/img/icon/server-management-icons/import-config.png" alt="Add Icon" />
<span class="text-sm text-left uppercase font-bold">import</span>
</button>
<input ref="fileInput" type="file" class="hidden" accept=".zip" @change="importConnections" />

<button
class="w-full h-[50px] self-end col-start-4 col-span-3 row-start-11 row-span-2 bg-gray-200 rounded-md px-1 pr-2 flex justify-start items-center shadow-lg shadow-black active:shadow-none active:scale-95 cursor-pointer transition-all duration-200 ease-in-out hover:bg-[#336666] text-gray-800 hover:text-gray-100"
@click="exportConnections"
@mouseenter="footerStore.cursorLocation = `click to export server list`"
@mouseleave="footerStore.cursorLocation = ''"
>
<img class="w-16 h-7" src="/img/icon/server-management-icons/export-config.png" alt="Add Icon" />
<span class="text-sm text-left uppercase font-bold">export</span>
</button>
<button
class="w-full h-[50px] self-end col-start-10 col-span-full row-start-11 row-span-2 bg-gray-200 rounded-md px-4 py-2 flex justify-start items-center shadow-lg shadow-black active:shadow-none active:scale-95 cursor-pointer space-x-4 transition-all duration-200 ease-in-out hover:bg-[#336666] text-gray-800 hover:text-gray-100"
@click="serverLogin"
@mouseenter="footerStore.cursorLocation = `${t('serverList.addServer')}`"
@mouseleave="footerStore.cursorLocation = ''"
Expand All @@ -58,15 +78,14 @@
src="/img/icon/server-management-icons/plus.png"
alt="Add Icon"
/>
<span class="text-sm text-left uppercase font-bold">{{ $t("multiServer.addServer") }}</span>
<span class="text-sm text-left uppercase font-bold">new</span>
</button>

<div
class="w-full h-[50px] self-end col-start-1 col-end-6 row-start-11 row-span-2 flex justify-center items-center bg-[#093A4C] rounded-md px-4 py-2 cursor-pointer space-x-2 transition-all duration-200 ease-in-out hover:bg-[#336666] shadow-lg shadow-black active:shadow-none"
class="w-full h-[50px] self-end col-start-7 col-end-10 row-start-11 row-span-2 flex justify-center items-center bg-[#093A4C] rounded-md px-2 py-1 cursor-pointer space-x-2 transition-all duration-200 ease-in-out hover:bg-[#336666] shadow-lg shadow-black active:shadow-none"
@click="getToStereumPlusLogin"
>
<span class="text-xs text-gray-200 font-normal font-sans"> GET SERVER </span>
<img class="w-auto h-6 border rounded-[4px]" src="/img/stereumPlus/logo.png" alt="Server Icon" />
<img class="w-full" src="/img/stereumPlus/logo.png" alt="Server Icon" />
</div>
</div>
</div>
Expand All @@ -79,6 +98,8 @@ import { useControlStore } from "@/store/theControl";
import { useFooter } from "@/store/theFooter";
import { onMounted, ref, watch } from "vue";
import ServerRow from "./ServerRow.vue";
import JSZip from "jszip";
import { saveAs } from "file-saver";
const t = i18n.global.t;
Expand All @@ -95,10 +116,10 @@ const getFilteredServers = () => {
if (!searchQuery.value) {
return serverStore.savedServers?.savedConnections;
}
return serverStore.savedServers.savedConnections.filter((server) => server.name.toLowerCase().includes(searchQuery.value.toLowerCase()));
};
// Watch for changes in both searchQuery and serverStore.refreshServers
watch(
[searchQuery, () => serverStore.refreshServers],
async ([, refreshTrigger], [, oldRefreshTrigger]) => {
Expand Down Expand Up @@ -126,6 +147,73 @@ onMounted(async () => {
//Methods
const exportConnections = async () => {
const zip = new JSZip();
const connectionsJSON = JSON.stringify(serverStore.connections, null, 2);
zip.file("connections.json", connectionsJSON);
const blob = await zip.generateAsync({ type: "blob" });
saveAs(blob, "connections.zip");
};
const fileInput = ref(null);
const openFileInput = () => {
if (fileInput.value) {
fileInput.value.click();
}
};
const importConnections = async (event) => {
const file = event.target.files[0];
if (!file) {
return;
}
const zip = new JSZip();
try {
const connect = await file.arrayBuffer();
const zipContent = await zip.loadAsync(connect);
const connectionsFile = zipContent.file("connections.json");
if (!connectionsFile) {
alert("No connections.json file found in the zip.");
return;
}
const jsonData = await connectionsFile.async("string");
const newConnections = JSON.parse(jsonData);
if (Array.isArray(newConnections) && newConnections.length > 0) {
const existingConnections = serverStore.savedServers.savedConnections;
const uniqueConnections = newConnections.filter(
(newConnection) =>
!existingConnections.some((existingConnection) => JSON.stringify(existingConnection) === JSON.stringify(newConnection))
);
existingConnections.push(...uniqueConnections);
const prevConf = await ControlService.readConfig();
const conf = {
...prevConf,
savedConnections: JSON.parse(JSON.stringify(existingConnections)),
};
await ControlService.writeConfig(conf);
} else {
console.error("Invalid or empty connections data.");
}
await loadStoredConnections(serverStore.savedServers);
} catch (error) {
console.error("An error occurred:", error);
}
};
const getToStereumPlusLogin = () => {
window.open("https://stereumplus.com/", "_blank");
};
Expand Down
2 changes: 2 additions & 0 deletions launcher/src/components/UI/setting-page/SettingScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import OutputOptions from "./components/OutputOptions.vue";
import LanguageBtn from "./components/LanguageBtn.vue";
import CreditButtons from "./section/CreditButtons.vue";
import IdleTimer from "./components/IdleTimer.vue";
import LogBackups from "./components/LogBackups.vue";
import IdleTimerTime from "./components/IdleTimerTime.vue";
import { ref, computed, onMounted } from "vue";
import CreditBtn from "./components/CreditBtn.vue";
Expand Down Expand Up @@ -105,6 +106,7 @@ const itemConfigurations = computed(() => {
{ title: "Credits", component: CreditButtons },
{ title: "Idle Timeout", component: IdleTimer },
{ title: "Idle Timeout Time (in minutes)", component: IdleTimerTime },
{ title: "Stereum Log Backups", component: LogBackups },
];
} else if (mainBox.value === "audio") {
items = [
Expand Down
75 changes: 75 additions & 0 deletions launcher/src/components/UI/setting-page/components/LogBackups.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<div class="LogBacksups-parent w-full h-full justify-center items-center flex">
<input
type="number"
:value="footerStore.logBackups"
class="lang-btn-parent w-full h-full bg-[#33393E] rounded-md flex justify-center items-center cursor-pointer border border-[#33393E] uppercase pl-3 pr-3 text-gray-200 text-base"
@change="onChange($event)"
/>
</div>
</template>

<script setup>
import { onMounted } from "vue";
import ControlService from "@/store/ControlService";
import { useFooter } from "@/store/theFooter";
const footerStore = useFooter();
const checkSettings = async () => {
try {
const savedConfig = await ControlService.readConfig();
if (typeof savedConfig.logBackups.value !== "undefined") {
footerStore.logBackups = savedConfig.logBackups.value;
} else {
updateSettings(5);
}
} catch (error) {
console.error("Failed to load saved settings:", error);
}
};
const updateSettings = async (logBackup) => {
try {
const prevConf = await ControlService.readConfig();
const conf = {
...prevConf,
logBackups: { value: logBackup },
};
await ControlService.writeConfig(conf);
useFooter.logBackups = logBackup;
checkSettings();
} catch (error) {
console.error("Failed to update settings:", error);
}
};
const onChange = async (event) => {
if (event.target.value == "" || event.target.value < 3) {
event.target.value = 3;
}
updateSettings(event.target.value);
};
onMounted(() => {
checkSettings();
});
</script>

<style scoped>
input[type="number"] {
text-align: center;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
.LogBacksups-parent {
display: flex;
align-items: center;
justify-content: center;
}
</style>
2 changes: 1 addition & 1 deletion launcher/src/languages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@
"has2fa": "This server has 2fa enabled Please enter the One Time Password generated by your authenticator",
"copy": "click to copy the secret key to clipboard",
"copyBtn": "copy",
"copied": "copied!"
"copied": "Copied!"
},
"updateServer": {
"opSysUpdate": "OPERATING SYSTEM UPDATES",
Expand Down
Loading

0 comments on commit d07853a

Please sign in to comment.