-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
763 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
DeskThing/src/components/icons/icon/Icons/AIconTemplate.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Icon } from '..' | ||
|
||
function IconCoffee(props): JSX.Element { | ||
const strokeWidth = props.strokeWidth || 1 | ||
|
||
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${strokeWidth}" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-coffee"><path d="M10 2v2"/><path d="M14 2v2"/><path d="M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"/><path d="M6 2v2"/></svg>` | ||
return <Icon {...props} dangerouslySetInnerHTML={{ __html: svgContent }} /> | ||
} | ||
|
||
export default IconCoffee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { exec } from 'child_process' | ||
import os from 'os' | ||
import dataListener, { MESSAGE_TYPES } from '../utils/events' | ||
import fs from 'fs' | ||
import { join } from 'path' | ||
import { app } from 'electron' | ||
|
||
// Function to execute shell commands | ||
function runCommand(command: string): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(`Error: ${error.message}`) | ||
return | ||
} | ||
if (stderr) { | ||
reject(`Stderr: ${stderr}`) | ||
return | ||
} | ||
resolve(stdout) | ||
}) | ||
}) | ||
} | ||
|
||
async function checkFirewallRuleExists(port: number): Promise<boolean> { | ||
const platform = os.platform() | ||
let checkCommand: string | ||
|
||
try { | ||
if (platform === 'win32') { | ||
// PowerShell command for Windows | ||
checkCommand = `"Get-NetFirewallRule -DisplayName 'Deskthing Server Inbound'"` | ||
const result = await runCommand(`powershell -Command ${checkCommand}`) | ||
|
||
return result.trim() !== '' | ||
} else if (platform === 'linux') { | ||
// Bash command for iptables on Linux | ||
checkCommand = `sudo iptables -C INPUT -p tcp --dport ${port} -j ACCEPT 2>/dev/null && echo "true" || echo "false"` | ||
const result = await runCommand(checkCommand) | ||
return result.trim() === 'true' | ||
} else if (platform === 'darwin') { | ||
// Bash command for pfctl on macOS | ||
checkCommand = `sudo pfctl -sr | grep -q "rdr pass on lo0 inet proto tcp from any to any port ${port} -> 127.0.0.1 port ${port}" && echo "true" || echo "false"` | ||
const result = await runCommand(checkCommand) | ||
return result.trim() === 'true' | ||
} else { | ||
dataListener.emit(MESSAGE_TYPES.ERROR, `FIREWALL: Unsupported OS!`) | ||
console.error('Unsupported OS') | ||
return false | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
return false | ||
} | ||
} | ||
|
||
// Firewall setup function | ||
async function setupFirewall(port: number): Promise<void> { | ||
const platform = os.platform() | ||
const inboundRuleName = 'Deskthing Server Inbound' | ||
const outboundRuleName = 'Deskthing Server Outbound' | ||
|
||
try { | ||
const ruleExists = await checkFirewallRuleExists(port) | ||
if (ruleExists) { | ||
dataListener.emit( | ||
MESSAGE_TYPES.LOGGING, | ||
`FIREWALL: Firewall rule for port ${port} verified successfully` | ||
) | ||
console.log(`Firewall rule for port ${port} verified successfully`) | ||
return | ||
} else { | ||
dataListener.emit( | ||
MESSAGE_TYPES.ERROR, | ||
`FIREWALL: Failed to verify firewall rule for port ${port}!` | ||
) | ||
console.error(`Failed to verify firewall rule for port ${port}`) | ||
} | ||
|
||
if (platform === 'win32') { | ||
// PowerShell script for Windows | ||
const script = ` | ||
$inboundRuleName = "${inboundRuleName}" | ||
$outboundRuleName = "${outboundRuleName}" | ||
$port = ${port} | ||
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | ||
{ | ||
$arguments = "& '" +$myinvocation.mycommand.definition + "'" | ||
Start-Process powershell -Verb runAs -ArgumentList $arguments | ||
Break | ||
} | ||
if (-not (Get-NetFirewallRule -DisplayName $inboundRuleName -ErrorAction SilentlyContinue)) { | ||
New-NetFirewallRule -DisplayName $inboundRuleName -Direction Inbound -Action Allow -Protocol TCP -LocalPort $port | ||
} | ||
if (-not (Get-NetFirewallRule -DisplayName $outboundRuleName -ErrorAction SilentlyContinue)) { | ||
New-NetFirewallRule -DisplayName $outboundRuleName -Direction Outbound -Action Allow -Protocol TCP -LocalPort $port | ||
} | ||
` | ||
|
||
const tempScriptPath = join(app.getPath('temp'), 'setup-firewall.ps1') | ||
fs.writeFileSync(tempScriptPath, script) | ||
|
||
await runCommand(`powershell -ExecutionPolicy Bypass -File "${tempScriptPath}"`) | ||
|
||
//fs.unlinkSync(tempScriptPath) | ||
|
||
dataListener.emit( | ||
MESSAGE_TYPES.LOGGING, | ||
`FIREWALL: Firewall rules set up successfully on Windows` | ||
) | ||
console.log('Firewall rules set up successfully on Windows') | ||
} else if (platform === 'linux') { | ||
// Bash script for iptables on Linux | ||
const script = ` | ||
#!/bin/bash | ||
port=${port} | ||
if ! sudo iptables -C INPUT -p tcp --dport $port -j ACCEPT 2>/dev/null; then | ||
sudo iptables -A INPUT -p tcp --dport $port -j ACCEPT | ||
fi | ||
if ! sudo iptables -C OUTPUT -p tcp --dport $port -j ACCEPT 2>/dev/null; then | ||
sudo iptables -A OUTPUT -p tcp --dport $port -j ACCEPT | ||
fi | ||
` | ||
|
||
await runCommand(`echo "${script}" | bash`) | ||
dataListener.emit( | ||
MESSAGE_TYPES.LOGGING, | ||
`FIREWALL: Firewall rules set up successfully on Linux` | ||
) | ||
console.log('Firewall rules set up successfully on Linux') | ||
} else if (platform === 'darwin') { | ||
// Bash script for pfctl on macOS | ||
const script = ` | ||
#!/bin/bash | ||
port=${port} | ||
anchorName="myAppAnchor" | ||
if ! sudo pfctl -s all | grep -q "rdr pass on lo0 inet proto tcp from any to any port $port -> 127.0.0.1 port $port"; then | ||
echo "rdr pass on lo0 inet proto tcp from any to any port $port -> 127.0.0.1 port $port" | sudo pfctl -a $anchorName -f - | ||
sudo pfctl -e | ||
fi | ||
` | ||
|
||
await runCommand(`echo "${script}" | bash`) | ||
dataListener.emit( | ||
MESSAGE_TYPES.LOGGING, | ||
`FIREWALL: Firewall rules set up successfully on macOS` | ||
) | ||
console.log('Firewall rules set up successfully on macOS') | ||
} else { | ||
console.error('Unsupported OS') | ||
} | ||
} catch (error) { | ||
dataListener.emit( | ||
MESSAGE_TYPES.ERROR, | ||
`FIREWALL: Error encountered trying to setup firewall for ${port}! Run administrator and try again` | ||
) | ||
console.error(error) | ||
} | ||
} | ||
|
||
export { setupFirewall } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.