Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend support command to dump log #446 #450

Merged
merged 43 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cd8a138
Removing the login command, fixes #444
shech2 Dec 21, 2023
5d7a362
Removing login command , #444
shech2 Dec 21, 2023
c1804c9
Restoring to default
shech2 Dec 21, 2023
28ca86b
Extending support command to dump log - added email and log #446
shech2 Dec 21, 2023
b005f51
Fixing some typos and making the code prettier
shech2 Dec 21, 2023
3851f18
Adding another fix i missed
shech2 Dec 21, 2023
88047a6
Merge branch 'master' into Extend_support_command_to_dump_log
shech2 Dec 21, 2023
b18eb77
Updating aatp to match our previous changes (replaced login with subs…
shech2 Dec 23, 2023
8e3084b
Fixing a typo
shech2 Dec 23, 2023
05fbe88
Adding netlify settings for cache
shech2 Dec 25, 2023
fe6c606
Making email shorter and clearer and now its asking for email if its …
shech2 Dec 25, 2023
98a0102
Adding Better feedback
shech2 Dec 25, 2023
cd66ee6
Fixing a typo
shech2 Dec 25, 2023
bd04d08
Changing email to let
shech2 Dec 25, 2023
02f2939
Updating index.html to match other PR's
shech2 Dec 25, 2023
7767f78
Modifing netlify to match all htmls
shech2 Dec 25, 2023
15e91fd
Refactoring dumpLog()
shech2 Dec 25, 2023
abc0d84
Adding a finer menu for support including copy to clipboard and sendi…
shech2 Dec 25, 2023
8aa38f0
Fixing bugs
shech2 Dec 25, 2023
90ceaa3
Fixing issues
shech2 Dec 25, 2023
ab6fe69
Deleting module script
shech2 Dec 25, 2023
577b5df
Restored main.ts
shech2 Dec 25, 2023
a5088d5
Changing writeln to notify
shech2 Dec 25, 2023
20c22ed
Adding Cancel chosise and changed to switch case
shech2 Dec 25, 2023
da10a86
Adding capacitor FileSystem plugin
shech2 Dec 27, 2023
6c4fead
Adding premissions for android
shech2 Dec 27, 2023
32457d3
Changing supportCMD function to check if Platform is native or not
shech2 Dec 28, 2023
cac3390
Adding support tests
shech2 Dec 28, 2023
12a0780
Coderabbit suggestions
shech2 Dec 28, 2023
b0dd275
Fixing all rejects
shech2 Dec 31, 2023
4b8696c
Merge branch 'master' into Extend_support_command_to_dump_log
shech2 Dec 31, 2023
812ef5b
Fixing a space
shech2 Dec 31, 2023
28749d3
Added suggested change
shech2 Dec 31, 2023
7f11b9b
Fixing a typo in support cmd
shech2 Jan 3, 2024
744653c
Deleting get-docker
shech2 Jan 3, 2024
e322124
Adding the required changes
shech2 Jan 3, 2024
539142e
Fixing the structure
shech2 Jan 3, 2024
1586aab
Changing "" with ''
shech2 Jan 3, 2024
723610f
Applying suggestions
shech2 Jan 3, 2024
0c826fe
Applying suggestions
shech2 Jan 3, 2024
faa462c
Fixing new line reject
shech2 Jan 10, 2024
baa13a2
Fixed the issue
shech2 Jan 15, 2024
a85358e
Improving tests stability
daonb Jan 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aatp/infra/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM redis:alpine
RUN echo "appendonly no" >> /etc/redis.conf
RUN echo 'appendonly no' > /etc/redis.conf
RUN echo 'save ""' >> /etc/redis.conf
CMD [ "redis-server", "/etc/redis.conf" ]
32 changes: 32 additions & 0 deletions aatp/peerbook_webrtc/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,36 @@ test.describe('peerbook administration', () => {
const twr = await getTWRBuffer(page)
expect(twr).toMatch(/Logged in/)
})
test('test the support command', async ({request}) => {
await sleep(100)
await page.keyboard.type('support')
await page.keyboard.press('Enter')
await sleep(100)
let twr = await getTWRBuffer(page)
expect(twr).toMatch(/address:$/)
await page.keyboard.type('[email protected]')
await page.keyboard.press('Enter')
await sleep(100)
await page.keyboard.press('ArrowDown')
await page.evaluate(() => { terminal7.log('log line')})
await page.keyboard.press('Enter')
await sleep(100)
twr = await getTWRBuffer(page)
expect(twr).toMatch(/issue:$/)
await page.keyboard.type('test issue')
await page.keyboard.press('Enter')

let count = 0
let msg
while (count < 2) {
await sleep(100)
const res = await request.get('http://smtp:8025/api/v2/messages')
msg = await res.json()
count = msg.count
}
expect(msg.count).toBe(2)
const body = msg.items[0].Content.Body
expect(body).toMatch(/test issue/)
expect(body).toMatch(/log line/)
})
Comment on lines +353 to +384
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test for the "support" command is well-structured and covers the expected behavior. However, consider adding assertions to verify that the email address ([email protected]) and the log line (log line) are included in the email body sent by the support command to ensure the complete log dump is captured.

+ expect(body).toMatch(/[email protected]/)
+ expect(body).toMatch(/log line/)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
test('test the support command', async ({request}) => {
await sleep(100)
await page.keyboard.type('support')
await page.keyboard.press('Enter')
await sleep(100)
let twr = await getTWRBuffer(page)
expect(twr).toMatch(/address:$/)
await page.keyboard.type('[email protected]')
await page.keyboard.press('Enter')
await sleep(100)
await page.keyboard.press('ArrowDown')
await page.evaluate(() => { terminal7.log('log line')})
await page.keyboard.press('Enter')
await sleep(100)
twr = await getTWRBuffer(page)
expect(twr).toMatch(/issue:$/)
await page.keyboard.type('test issue')
await page.keyboard.press('Enter')
let count = 0
let msg
while (count < 2) {
await sleep(100)
const res = await request.get('http://smtp:8025/api/v2/messages')
msg = await res.json()
count = msg.count
}
expect(msg.count).toBe(2)
const body = msg.items[0].Content.Body
expect(body).toMatch(/test issue/)
expect(body).toMatch(/log line/)
})
test('test the support command', async ({request}) => {
await sleep(100)
await page.keyboard.type('support')
await page.keyboard.press('Enter')
await sleep(100)
let twr = await getTWRBuffer(page)
expect(twr).toMatch(/address:$/)
await page.keyboard.type('[email protected]')
await page.keyboard.press('Enter')
await sleep(100)
await page.keyboard.press('ArrowDown')
await page.evaluate(() => { terminal7.log('log line')})
await page.keyboard.press('Enter')
await sleep(100)
twr = await getTWRBuffer(page)
expect(twr).toMatch(/issue:$/)
await page.keyboard.type('test issue')
await page.keyboard.press('Enter')
let count = 0
let msg
while (count < 2) {
await sleep(100)
const res = await request.get('http://smtp:8025/api/v2/messages')
msg = await res.json()
count = msg.count
}
expect(msg.count).toBe(2)
const body = msg.items[0].Content.Body
expect(body).toMatch(/test issue/)
expect(body).toMatch(/log line/)
expect(body).toMatch(/test@gmail.com/)
expect(body).toMatch(/log line/)
})

})
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation project(':capacitor-camera')
implementation project(':capacitor-clipboard')
implementation project(':capacitor-device')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-network')
implementation project(':capacitor-preferences')
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/assets/capacitor.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"pkg": "@capacitor/device",
"classpath": "com.capacitorjs.plugins.device.DevicePlugin"
},
{
"pkg": "@capacitor/filesystem",
"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"
},
{
"pkg": "@capacitor/keyboard",
"classpath": "com.capacitorjs.plugins.keyboard.KeyboardPlugin"
Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ project(':capacitor-clipboard').projectDir = new File('../node_modules/@capacito
include ':capacitor-device'
project(':capacitor-device').projectDir = new File('../node_modules/@capacitor/device/android')

include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')

include ':capacitor-keyboard'
project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android')

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<meta name="apple-touch-fullscreen" content="yes" />
<meta name="apple-mobile-web-app-title" content="Terminal7" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<script type="module" src="/main.ts"></script>
<script type="module" src="/main.ts" defer></script>

</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def capacitor_pods
pod 'CapacitorCamera', :path => '../../node_modules/@capacitor/camera'
pod 'CapacitorClipboard', :path => '../../node_modules/@capacitor/clipboard'
pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network'
pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@capacitor/clipboard": "^5.0.0",
"@capacitor/core": "^5.0.0",
"@capacitor/device": "^5.0.0",
"@capacitor/filesystem": "^5.2.0",
"@capacitor/ios": "^5.0.0",
"@capacitor/keyboard": "^5.0.0",
"@capacitor/network": "^5.0.0",
Expand Down Expand Up @@ -53,14 +54,14 @@
},
"devDependencies": {
"@capacitor/assets": "^2.0.4",
"native-run": "^1.7.4",
"@playwright/test": "^1.20.1",
"@types/hammerjs": "^2.0.42",
"@types/xterm": "^3.0.0",
"@typescript-eslint/eslint-plugin": "<6",
"@typescript-eslint/parser": "<6",
"eslint": "<9",
"jsdom": "^19.0.0",
"native-run": "^1.7.4",
"typescript": "<5",
"vi-canvas-mock": "^1.0.0",
"vite": "^4.5.1",
Expand Down
80 changes: 75 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SSHSession, SSHChannel } from './ssh_session'
import { Failure } from './session'
import { NativeBiometric } from 'capacitor-native-biometric'
import { Capacitor } from "@capacitor/core"
import { Filesystem, Directory , Encoding} from '@capacitor/filesystem'
shech2 marked this conversation as resolved.
Show resolved Hide resolved

export type Command = {
name: string
Expand Down Expand Up @@ -712,7 +713,7 @@ async function subscribeCMD(shell: Shell) {
}
if (!terminal7.pb.isOpen()) {
if (!Capacitor.isNativePlatform()) {
loginCMD(shell);
await loginCMD(shell);
shech2 marked this conversation as resolved.
Show resolved Hide resolved
return
}
terminal7.pb.startSpinner()
Expand Down Expand Up @@ -981,10 +982,79 @@ async function configCMD(shell: Shell) {
await shell.openConfig()
}
async function supportCMD(shell: Shell) {
shell.t.write("Sorry things are not working well. Please ")
shell.t.writeln("\x1B]8;;https://github.com/tuzig/terminal7/issues/new?template=bug_report.md\x07report a bug\x1B]8;;\x07")
shell.t.writeln("or talk to us on our \x1B]8;;https://discord.gg/Puu2afdUtr\x07discord server\x1B]8;;\x07")
}
shell.t.write("Apologies. Have you tried resetting the App?\n")
shell.t.writeln("If that doesn't work, please send us a log of the error.")
const insecure = terminal7.conf.peerbook.insecure,
schema = insecure?"http":"https"

// ask for email address + check validity
let email = terminal7.conf.peerbook.email || (await shell.askValue("Enter your email address"))
while (!email.match(/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)) {
shell.t.writeln("Invalid email address")
email = await shell.askValue("Enter your email address")
}
shech2 marked this conversation as resolved.
Show resolved Hide resolved

// Menu to ask user if they want to send the log or Post it to mail
const fieldsNative = [
{prompt: "Copy log to clipboard"},
{prompt: "Send log to support"},
{prompt: "Save log to file"},
{prompt: "Cancel"}
]

// Ask user for choice
!Capacitor.isNativePlatform() ? fieldsNative.splice(2,1) : fieldsNative
const choice = await shell.runForm(fieldsNative,"menu" , "Choose an option")
shech2 marked this conversation as resolved.
Show resolved Hide resolved
// Switch case to handle user choice
switch (choice) {
case "Copy log to clipboard":
// Saving the log to the clipboard
const log = terminal7.dumpLog()
await Clipboard.write({string: (await log).toString()})
terminal7.notify("Log copied to clipboard.")
shell.t.writeln("Please paste into discord support channel.")
break
case "Send log to support":
const description = await shell.askValue("please describe the issue")
shell.t.writeln("Sending log to support...")
const res = await fetch(`${schema}://${terminal7.conf.net.peerbook}/support`, {
method: "POST",
body: JSON.stringify({
email,
log: await terminal7.dumpLog(),
description
}),
})
if (res.ok) {
shell.t.writeln("Log sent to support.")
} else {
shell.t.writeln("Failed to send log to support.")
shell.t.writeln("Please send us a message in discord support channel.")
}
break
case "Save log to file":
shell.t.writeln("Saving log to file...")
const log2 = terminal7.dumpLog()
// Works only on ios and android
if(Capacitor.isNativePlatform()) {
try{
await Filesystem.requestPermissions()
await Filesystem.checkPermissions()
await Filesystem.writeFile({
path: "log-" + Date.now().toString() +".txt",
data: (await log2).toString(),
directory: Directory.Documents,
encoding: Encoding.UTF8
})
} catch(e) {
terminal7.log(e)
}
}
break
case "Cancel":
break
shech2 marked this conversation as resolved.
Show resolved Hide resolved
}
}
shech2 marked this conversation as resolved.
Show resolved Hide resolved
async function loginCMD(shell: Shell) {
if (terminal7.pb.isOpen()) {
shell.t.writeln("You are already logged in")
Expand Down
16 changes: 1 addition & 15 deletions src/terminal7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { randomBytes } from 'ed25519-keygen/utils'

import { Capacitor } from '@capacitor/core'
import { App } from '@capacitor/app'
import { Clipboard } from '@capacitor/clipboard'
import { Network } from '@capacitor/network'
import { Preferences } from '@capacitor/preferences'
import { Device } from '@capacitor/device'
Expand Down Expand Up @@ -916,20 +915,7 @@ export class Terminal7 {
while (this.logBuffer.length > 0) {
data += this.logBuffer.shift() + "\n"
}
await Clipboard.write({string: data})
this.notify("Log copied to clipboard")
/* TODO: wwould be nice to store log to file, problme is
* Preferences pluging failes
try {
await Filesystem.writeFile({
path: path,
data: data,
directory: FilesystemDirectory.Documents
})i
} catch(e) {
terminal7.log(e)
}
*/
return data
}
onPointerCancel() {
this.pointer0 = null
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,11 @@
resolved "https://registry.yarnpkg.com/@capacitor/device/-/device-5.0.6.tgz#11322a9c737196f2df8f82abbe6d1a5b32e35fb7"
integrity sha512-tmjK0H8IKbDLMcmzZzJPbV+9yLkKJ76QOdz4A7fZAOYx2GnFHsFngxldq/wKotGAJuDX/ih3ZzHNrzVguzlv2g==

"@capacitor/filesystem@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@capacitor/filesystem/-/filesystem-5.2.0.tgz#6e4529eb059c85869ecc68643f25123dbe38768f"
integrity sha512-fyv+yWVFfglobPPveIRm4+ryMGI8vW27vjX63HDwB7K5fscSYajid+ie3qfwl2wkbPhlX8KTPes7IPij0lCmQg==

"@capacitor/ios@^5.0.0":
version "5.5.1"
resolved "https://registry.yarnpkg.com/@capacitor/ios/-/ios-5.5.1.tgz#e07d0752b8934215a9defc2d22a537060f2dd7f7"
Expand Down