Skip to content

Commit

Permalink
improved search hints
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Jun 23, 2024
1 parent da946f2 commit 005d087
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
2 changes: 1 addition & 1 deletion website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 46 additions & 13 deletions website/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, html, render} from 'htm/preact';
import {DeviceExploitAvailabilities, DeviceModel, DeviceModelName} from "@webosbrew/caniroot";
import {DeviceExploitAvailabilities, DeviceExploitType, DeviceModel, DeviceModelName} from "@webosbrew/caniroot";
import debounce from 'lodash-es/debounce';
import {RenderableProps} from "preact";
import {ExploitCard} from "./exploit";
Expand All @@ -13,6 +13,7 @@ interface AppProps {
interface AppState {
term?: SearchTerm;
model?: DeviceModel;
similar?: boolean;
availability?: DeviceExploitAvailabilities;
}

Expand All @@ -32,27 +33,44 @@ function parseSearchTerm(q?: string): SearchTerm | undefined {

export declare interface ExploitMethod {
name: string;
key: keyof DeviceExploitAvailabilities;
key: DeviceExploitType;
url: string;
expert?: boolean;
}

class App extends Component<AppProps, AppState> {

readonly exploits: ExploitMethod[] = [
{name: 'DejaVuln', key: 'dejavuln', url: 'https://github.com/throwaway96/dejavuln-autoroot'},
{name: 'ASM', key: 'asm', url: 'https://github.com/illixion/root-my-webos-tv'},
{name: 'crashd', key: 'crashd', url: 'https://gist.github.com/throwaway96/e811b0f7cc2a705a5a476a8dfa45e09f'},
{name: 'WTA', key: 'wta', url: 'https://gist.github.com/throwaway96/b171240ef59d7f5fd6fb48fc6dfd2941'},
{name: 'RootMy.TV', key: 'rootmytv', url: 'https://rootmy.tv/'},
{
name: 'DejaVuln',
key: DeviceExploitType.DejaVuln,
url: 'https://github.com/throwaway96/dejavuln-autoroot'
},
{
name: 'ASM',
key: DeviceExploitType.ASM,
url: 'https://github.com/illixion/root-my-webos-tv'
},
{
name: 'crashd',
key: DeviceExploitType.crashd,
url: 'https://gist.github.com/throwaway96/e811b0f7cc2a705a5a476a8dfa45e09f'
},
{
name: 'WTA',
key: DeviceExploitType.WTA,
url: 'https://gist.github.com/throwaway96/b171240ef59d7f5fd6fb48fc6dfd2941'
},
{
name: 'RootMy.TV',
key: DeviceExploitType.RootMyTV,
url: 'https://rootmy.tv/'
},
];

constructor(props: AppProps) {
super(props);
const term = parseSearchTerm(props.q);
let model = term?.model && DeviceModel.find(term.model.series + (term.model.tdd || ''));
let availability = model && DeviceExploitAvailabilities.byOTAID(model.otaId);
this.state = {term, model, availability};
this.state = this.createState(props.q)
}

/**
Expand Down Expand Up @@ -97,10 +115,17 @@ class App extends Component<AppProps, AppState> {
onInput=${(e: Event) => this.searchChanged((e.currentTarget as HTMLInputElement).value)}/>
${SearchHint(state.term, model)}
${state.similar && html`
<div class="alert alert-warning mt-3">
<i class="bi bi-exclamation-triangle-fill me-2"></i>
We found a similar model (<code>${state.availability?.otaId}</code>) but not an exact match
(<code>${model?.otaId}</code>).
</div>
`}
${this.exploits.map(exploit => {
const avail = state.availability?.[exploit.key];
return avail && ExploitCard(exploit, avail, state.term?.firmware ?? avail.patched?.version);
return avail && ExploitCard(exploit, avail, state.term?.firmware);
})}
${unrootable && html`
Expand Down Expand Up @@ -148,10 +173,18 @@ class App extends Component<AppProps, AppState> {
}

private searchImmediate(q: string): void {
this.setState(this.createState(q));
}

private createState(q?: string): AppState {
const term = parseSearchTerm(q);
let model = term?.model && DeviceModel.find(term.model.series + (term.model.tdd || ''));
let availability = model && DeviceExploitAvailabilities.byOTAID(model.otaId);
this.setState({term, model, availability});
let similar = false;
if (model && availability && availability.otaId !== model.otaId) {
similar = true;
}
return {term, model, similar, availability};
}
}

Expand Down
11 changes: 5 additions & 6 deletions website/src/exploit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import {ExploitMethod} from "./app";
import {ExploitAvailability} from "../../src/library";

export function ExploitCard(exploit: ExploitMethod, avail: ExploitAvailability, firmware?: string) {
const patched = (avail.patched && firmware && firmware >= avail.patched.version) || false;
const mayPatched = !patched && (avail.latest && firmware && firmware > avail.latest.version) || false;
const patched = (avail.patched && (!firmware || firmware >= avail.patched.version)) || false;
const mayPatched = !patched && (!avail.latest || firmware && firmware > avail.latest.version) || false;
const bgClass = patched ? 'bg-secondary-subtle opacity-75' : mayPatched ? 'bg-warning-subtle' : 'bg-primary-subtle';
const iconClass = patched ? 'bi-exclamation-octagon-fill' : mayPatched ?
'bi-question-octagon-fill' : 'bi-hand-thumbs-up-fill';
return (html`
return html`
<div class=${`card p-3 mt-3 ${bgClass}`}>
<h3>
<i class="bi ${iconClass} me-2"/>
<a class="stretched-link text-decoration-none text-light" href=${exploit.url}
target="_blank">${exploit.name}</a>
${patched && html` (Patched)`}
${patched ? html` (Patched)`: mayPatched && html` (Possibly patched)`}
</h3>
${avail.latest && html`
<div>
Expand All @@ -33,6 +33,5 @@ export function ExploitCard(exploit: ExploitMethod, avail: ExploitAvailability,
</div>
`}
</div>
`
);
`;
}
3 changes: 2 additions & 1 deletion website/src/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function SearchHint(term?: SearchTerm, model?: DeviceModel) {
}
if (model) {
return html`
<div class="alert alert-info mt-3" role="alert">Found <code>${model.model}</code>
<div class="alert alert-info mt-3" role="alert">
<i class="bi bi-search me-2"/>Found <code>${model.model}</code>
, running <code>${osVersionMap[model.codename]}</code>
, machine <code>${model.machine}</code>
, otaId <code>${model.otaId}</code>
Expand Down

0 comments on commit 005d087

Please sign in to comment.