Skip to content

Commit

Permalink
Replace process name, path, and id, and activity
Browse files Browse the repository at this point in the history
  • Loading branch information
SRichner committed Mar 4, 2024
1 parent 2464633 commit 33f9617
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 24 deletions.
61 changes: 50 additions & 11 deletions src/electron/electron/main/services/DataExportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,73 @@ export class DataExportService {
db.pragma(`rekey='PersonalAnalytics_${settings.subjectId}'`);

if (windowActivityExportType === DataExportType.Obfuscate || obfuscationTerms?.length > 0) {
const items: { windowTitle: string; url: string; id: string }[] =
await WindowActivityEntity.getRepository()
.createQueryBuilder('window_activity')
.select('id, windowTitle, url')
.getRawMany();
const items: {
windowTitle: string;
processName: string;
processPath: string;
processId: string;
activity: string;
url: string;
id: string;
}[] = await WindowActivityEntity.getRepository()
.createQueryBuilder('window_activity')
.select('id, windowTitle, url, processName, processPath, processId, activity')
.getRawMany();
for (const item of items) {
if (windowActivityExportType === DataExportType.Obfuscate) {
const randomizeWindowTitle = this.windowActivityTrackerService.randomizeWindowTitle(
const randomizeWindowTitle = this.windowActivityTrackerService.randomizeString(
item.windowTitle
);
const randomizeUrl = this.windowActivityTrackerService.randomizeUrl(item.url);
const randomizeProcessName = this.windowActivityTrackerService.randomizeString(
item.processName
);
const randomizeProcessPath = this.windowActivityTrackerService.randomizeString(
item.processPath
);
const randomizeProcessId = undefined;
const obfuscateWindowActivities = db.prepare(
'UPDATE window_activity SET windowTitle = ?, url = ? WHERE id = ?'
'UPDATE window_activity SET windowTitle = ?, url = ?, processName = ?, processPath = ?, processId = ?, activity = ? WHERE id = ?'
);
obfuscateWindowActivities.run(
randomizeWindowTitle,
randomizeUrl,
randomizeProcessName,
randomizeProcessPath,
randomizeProcessId,
item.id
);
obfuscateWindowActivities.run(randomizeWindowTitle, randomizeUrl, item.id);
} else if (obfuscationTerms.length > 0) {
const lowerCaseObfuscationTerms: string[] = obfuscationTerms.map((term: string) =>
term.toLowerCase()
);
lowerCaseObfuscationTerms.forEach((term: string) => {
if (
item.windowTitle?.toLowerCase().includes(term) ||
item.url?.toLowerCase().includes(term)
item.url?.toLowerCase().includes(term) ||
item.processName?.toLowerCase().includes(term) ||
item.processPath?.toLowerCase().includes(term) ||
item.activity?.toLowerCase().includes(term)
) {
const obfuscateWindowActivities = db.prepare(
'UPDATE window_activity SET windowTitle = ?, url = ? WHERE id = ?'
'UPDATE window_activity SET windowTitle = ?, url = ?, processName = ?, processPath = ?, processId = ?, activity = ? WHERE id = ?'
);
const windowTitle = item.windowTitle ? '[anonymized]' : undefined;
const url = item.url ? '[anonymized]' : undefined;
const processName = item.processName ? '[anonymized]' : undefined;
const processPath = item.processPath ? '[anonymized]' : undefined;
const processId = undefined;
const activity = item.activity ? '[anonymized]' : undefined;

obfuscateWindowActivities.run(
windowTitle,
url,
processName,
processPath,
processId,
activity,
item.id
);
obfuscateWindowActivities.run('[anonymized]', '[anonymized]', item.id);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export class WindowActivityTrackerService {
})
).map((activity) => {
return {
windowTitle: this.randomizeWindowTitle(activity.windowTitle),
processName: activity.processName,
processPath: activity.processPath,
processId: activity.processId,
windowTitle: this.randomizeString(activity.windowTitle),
processName: this.randomizeString(activity.processName),
processPath: this.randomizeString(activity.processPath),
processId: undefined,
url: this.randomizeUrl(activity.url),
activity: activity.activity,
activity: this.randomizeString(activity.activity),
ts: activity.ts,
id: activity.id,
createdAt: activity.createdAt,
Expand Down Expand Up @@ -92,7 +92,7 @@ export class WindowActivityTrackerService {
return out;
}

public randomizeWindowTitle(title: string): string {
public randomizeString(title: string): string {
return this.randomizeOrKeepEmpty(title);
}

Expand Down
25 changes: 18 additions & 7 deletions src/electron/src/views/DataExportView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,30 @@ async function handleObfuscateSampleData() {
obfuscationTermsInput?.value?.length > 0 &&
mostRecentWindowActivities.value
) {
mostRecentWindowActivities.value = mostRecentWindowActivities.value?.map((activity) => {
let windowTitle = activity.windowTitle;
let url = activity.url;
mostRecentWindowActivities.value = mostRecentWindowActivities.value?.map((item) => {
let windowTitle = item.windowTitle;
let url = item.url;
let processName = item.processName;
let processPath = item.processPath;
let processId = item.processId;
let activity = item.activity;
obfuscationTermsInput.value?.forEach((term) => {
if (
windowTitle?.toLowerCase().includes(term.toLowerCase()) ||
url?.toLowerCase().includes(term.toLowerCase())
url?.toLowerCase().includes(term.toLowerCase()) ||
processName?.toLowerCase().includes(term.toLowerCase()) ||
processPath?.toLowerCase().includes(term.toLowerCase()) ||
activity?.toLowerCase().includes(term.toLowerCase())
) {
windowTitle = '[anonymized]';
url = '[anonymized]';
windowTitle = windowTitle ? '[anonymized]' : windowTitle;
url = url ? '[anonymized]' : url;
processName = processName ? '[anonymized]' : processName;
processPath = processPath ? '[anonymized]' : processPath;
processId = processId ? null : processId;
activity = activity ? '[anonymized]' : activity;
}
});
return { ...activity, windowTitle, url };
return { ...item, windowTitle, url, activity, processPath, processName, processId };
});
} else {
mostRecentWindowActivities.value = await typedIpcRenderer.invoke(
Expand Down

0 comments on commit 33f9617

Please sign in to comment.