Skip to content

Commit

Permalink
auto install certifiacate
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslopezj committed Aug 7, 2023
1 parent a25eedd commit 844a77e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 13 deletions.
Binary file modified .DS_Store
Binary file not shown.
59 changes: 59 additions & 0 deletions app/App/qztray/digital-certificate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export const digitalCertificate = `-----BEGIN CERTIFICATE-----
MIIExzCCAq+gAwIBAgIQNzkyMDIzMDgwNzE1NTMxMDANBgkqhkiG9w0BAQsFADCB
mDELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAk5ZMRswGQYDVQQKDBJRWiBJbmR1c3Ry
aWVzLCBMTEMxGzAZBgNVBAsMElFaIEluZHVzdHJpZXMsIExMQzEZMBcGA1UEAwwQ
cXppbmR1c3RyaWVzLmNvbTEnMCUGCSqGSIb3DQEJARYYc3VwcG9ydEBxemluZHVz
dHJpZXMuY29tMB4XDTIzMDgwNzE1NTMxMFoXDTI0MDgwNzE0NDA0N1owgYAxCzAJ
BgNVBAYMAkNMMQswCQYDVQQIDAJSTTERMA8GA1UEBwwIU2FudGlhZ28xDjAMBgNV
BAoMBUp1c3RvMQ4wDAYDVQQLDAVKdXN0bzEOMAwGA1UEAwwFSnVzdG8xITAfBgkq
hkiG9w0BCQEMEmFkbWluQGdldGp1c3RvLmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBAKr0D8QiKYyiMTnOcAcozIRIAfO3+uaE/ecQaDMQ6XC/ERxT
3FMocPfsz9g/xJXzGZ10rQ+YIU/CuFwPcwf8BQGwfCiVNFjMC/PlGnZs5LX/jD9U
dEADdnEyI9QWyoh3uYeAGFrrHWqcbJPoSuBfB9JRHjS58d9ujXTLejToqFWMx3mp
wfrIFcacHDZNt3AqJZC2IaX7a0hwhTDUcC6hhN6oXaG0fsPT3sFEK/m7eUDp2NVk
/YKZgByfZceIYrhDQIoB/VULVRpek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LrxmvGy5XFVG+8fF/xaVfo5TW5AgMBAAGjUDBOMB0GA1UdDgQWBBSQ
plC3hNS56l/yBYQTeEXoqXVUXDAfBgNVHSMEGDAWgBQDRcZNwPqOqQvagw9BpW0S
BkOpXjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAJIO8SiNr9jpLQ
eUsFUmbueoxyI5L+P5eV92ceVOJ2tAlBA13vzF1NWlpSlrMmQcVUE/K4D01qtr0k
gDs6LUHvj2XXLpyEogitbBgipkQpwCTJVfC9bWYBwEotC7Y8mVjjEV7uXAT71GKT
x8XlB9maf+BTZGgyoulA5pTYJ++7s/xX9gzSWCa+eXGcjguBtYYXaAjjAqFGRAvu
pz1yrDWcA6H94HeErJKUXBakS0Jm/V33JDuVXY+aZ8EQi2kV82aZbNdXll/R6iGw
2ur4rDErnHsiphBgZB71C5FD4cdfSONTsYxmPmyUb5T+KLUouxZ9B0Wh28ucc1Lp
rbO7BnjW
-----END CERTIFICATE-----`
30 changes: 19 additions & 11 deletions app/App/qztray/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import sudo from 'sudo-prompt'
import {digitalCertificate} from './digital-certificate'
import {sudoPromise} from './sudoPromise'
import fs from 'fs'
import os from 'os'

const isMac = process.platform === 'darwin'

Expand All @@ -9,16 +12,8 @@ export async function installQZTray(): Promise<{success: boolean; message: strin
win: `powershell -Command "irm pwsh.sh | iex"`
}[isMac ? 'mac' : 'win']

await new Promise<void>((resolve, reject) => {
sudo.exec(script, {name: 'Crisp'}, function (error, stdout, stderr) {
if (error) {
console.error(`Error installing qztray: ${error}`, stdout, stderr)
reject(`Error: ${error.message}`)
} else {
resolve()
}
})
})
await sudoPromise(script)
await installCertificate()

return {
success: true,
Expand All @@ -31,3 +26,16 @@ export async function installQZTray(): Promise<{success: boolean; message: strin
}
}
}

async function installCertificate() {
// write the file to a temp folder
const path = os.tmpdir() + '/digital-certificate.txt'
fs.writeFileSync(path, digitalCertificate)

const script = {
mac: `"/Applications/QZ Tray.app/Contents/MacOS/QZ Tray" --whitelist "${path}"`,
win: `"%PROGRAMFILES%\\QZ Tray\\qz-tray-console.exe" --whitelist "${path}"`
}[isMac ? 'mac' : 'win']

await sudoPromise(script)
}
2 changes: 1 addition & 1 deletion app/App/qztray/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// NO se usa, se hace desde la web
import {digitalCertificate} from './keys/digital-certificate'
import {digitalCertificate} from './digital-certificate'
import {privateKey} from './keys/private-key'
import crypto from 'crypto'

Expand Down
18 changes: 18 additions & 0 deletions app/App/qztray/sudoPromise.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sudo from 'sudo-prompt'

export async function sudoPromise(script: string) {
await new Promise<string>((resolve, reject) => {
console.log(`Will run sudo promise: ${script}`)
sudo.exec(script, {name: 'Crisp'}, function (error, stdout, stderr) {
if (error) {
console.log(`Error in sudo promise: ${error}`, stdout, stderr)
reject(`Error: ${error.message}`)
} else {
console.log('Sudo promise success', {
stdout
})
resolve(stdout.toString())
}
})
})
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "justo-crisp",
"version": "0.7.0",
"version": "0.7.3",
"license": "MIT",
"description": "Crisp POS",
"author": "nicolaslopezj",
Expand Down

0 comments on commit 844a77e

Please sign in to comment.