Skip to content

Commit

Permalink
Merge pull request #38 from passwall/main
Browse files Browse the repository at this point in the history
Update version to 1.0.12
  • Loading branch information
yakuter authored Oct 15, 2021
2 parents 23a180f + 71acb61 commit ebea314
Show file tree
Hide file tree
Showing 26 changed files with 1,120 additions and 652 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module.exports = {
node: true,
webextensions: true,
},
extends: ["plugin:vue/essential"],
extends: ['plugin:vue/essential'],
parserOptions: {
parser: "babel-eslint",
parser: 'babel-eslint',
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
},
};
}
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"@/*": ["src/*"],
"@p/*": ["src/popup/*"]
}
}
},
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passwall-extension",
"version": "1.0.11",
"version": "1.0.12",
"private": true,
"scripts": {
"serve": "vue-cli-service build --mode development --watch",
Expand Down
38 changes: 24 additions & 14 deletions public/css/content-script.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
/* Passwall ////////////////////////////////////////////////////////////////////////////////////*/
/*//////////////////////////////////////////////////////////////////////////////////////////////*/

#passwall-dialog{
border:10px solig blue;
position:fixed;
z-index:999999;
top:20px;
right:20px;
#passwall-dialog {
border: 10px solig blue;
position: fixed;
z-index: 999999;
top: 20px;
right: 20px;
}

#passwall-dialog iframe{
display:block;
width:350px;
height: 360px;
background: #0A0F17;
border-style:none;
border-radius: 16px;
}
#passwall-dialog iframe {
display: block;
width: 350px;
height: auto;
background: #0a0f17;
border-style: none;
border-radius: 16px;
}

#passwall-input-icon {
position: absolute;
cursor: pointer;
}

#passwall-input-dialog {
position: absolute;
z-index: 999999;
}
8 changes: 2 additions & 6 deletions public/js/jquery.js

Large diffs are not rendered by default.

120 changes: 112 additions & 8 deletions src/background-scripts/background-script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,110 @@
const browser = require('webextension-polyfill')
import browser from 'webextension-polyfill'
import { EVENT_TYPES } from '@/utils/constants'
import LoginsService from '@/api/services/Logins'
import Storage from '@/utils/storage'
import HTTPClient from '@/api/HTTPClient'
import CryptoUtils from '@/utils/crypto'
import { RequestError } from '@/utils/helpers'

const EncryptedFields = ['username', 'password', 'extra']

class Agent {
isAuthenticated = false
constructor() {
console.log('Background initalize')
this.init()
}

async init() {
await this.fetchTokens()
browser.runtime.onMessage.addListener(this.handleMessage.bind(this)) // for content-scirpt/popup events events

browser.tabs.onUpdated.addListener((tabId, changeInfo, tabInfo) => {
browser.tabs.sendMessage(tabId, { type: EVENT_TYPES.TAB_UPDATE, payload: {} })
})
}

async fetchTokens() {
const token = await Storage.getItem('access_token')
if (!token) {
console.warn('Login first!!')
this.isAuthenticated = false
return
}
HTTPClient.setHeader('Authorization', `Bearer ${token}`)

CryptoUtils.encryptKey = await Storage.getItem('master_hash')
CryptoUtils.transmissionKey = await Storage.getItem('transmission_key')
this.isAuthenticated = true
}

/**
*
* @param {import('@/content-scripts/content-script').RuntimeRequest} request
*/
async handleMessage(request, sender, sendResponse) {
if (request.who === 'popup') {
// popup
switch (request.type) {
case 'REFRESH_TOKENS':
this.fetchTokens()
break
}
}
if (request.who === 'content-script') {
// content-script
switch (request.type) {
case 'REQUEST_LOGINS':
try {
const logins = await this.requestLogins(request.payload)
return Promise.resolve(logins)
} catch (error) {
console.error(error)
return Promise.reject(error)
}
}
}
}

/**
*
* @param {string} domain
* @returns {Promise<Array>}
*/
async requestLogins(domain) {
if (!this.isAuthenticated) throw new RequestError('No token found!', 'NO_AUTH')
const { data } = await LoginsService.FetchAll()
const itemList = JSON.parse(CryptoUtils.aesDecrypt(data.data))
itemList.forEach(element => {
CryptoUtils.decryptFields(element, EncryptedFields)
})

const filteredItems = itemList.filter(item =>
Object.values(item).some(value =>
(value || '')
.toString()
.toLowerCase()
.includes(domain.toLowerCase())
)
)
if (filteredItems.length === 0) throw new RequestError('No logins found', 'NO_LOGINS')
return filteredItems
}

async sendResponseToContentScirpt(data = {}) {
// find the current tab and send a message to "content-script.js" and all the iframes
browser.tabs.query({ active: true, lastFocusedWindow: true }).then(tabs => {
if (!tabs[0]) return
browser.tabs.sendMessage(tabs[0].id, data)
})
}
}

window.addEventListener('load', () => {
new Agent()
})

var Background = (function (){
/* var Background = (function (){
// variables ----------------------------------------------------------------
var _this = {},
_websites = [];
Expand Down Expand Up @@ -30,10 +134,10 @@ var Background = (function (){
if (!request.message) return;
// if it has a "view", it resends the message to all the frames in the current tab
// if (request.data.view){
// _this.tell(request.message, request.data);
// return;
// }
if (request.data.view){
_this.tell(request.message, request.data);
return;
}
processMessage(request);
};
Expand Down Expand Up @@ -187,7 +291,7 @@ var Background = (function (){
return _this;
}());
window.addEventListener("load", function() { Background.init(); }, false);
window.addEventListener("load", function() { Background.init(); }, false); */

/*
Expand Down Expand Up @@ -288,4 +392,4 @@ function handleTabURLUpdated(tabId, changeInfo, tabInfo) {
// }
}
*/
*/
4 changes: 2 additions & 2 deletions src/components/CompanyLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img
v-if="logoAvailable && check"
class="logo"
:src="`http://logo.clearbit.com/${domain}?size=40?format=png`"
:src="`https://logo.clearbit.com/${domain}?size=40?format=png`"
alt="logo"
height="40"
width="40"
Expand Down Expand Up @@ -45,7 +45,7 @@ export default {
domain() {
return this.domainFromUrl(this.url)
}
}
},
}
</script>

Expand Down
21 changes: 18 additions & 3 deletions src/components/TheIcons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
/>
</symbol>
<symbol id="check" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
<path
fill="currentColor"
fill-rule="evenodd"
fill-rule="evenodd"
d="M5.5204 2.14599C6.29231 2.08436 7.0251 1.78075 7.6144 1.27839C8.28 0.711503 9.12571 0.400162 10 0.400162C10.8743 0.400162 11.72 0.711503 12.3856 1.27839C12.9749 1.78075 13.7077 2.08436 14.4796 2.14599C15.3513 2.21566 16.1697 2.59355 16.7881 3.21191C17.4064 3.83027 17.7843 4.64868 17.854 5.52039C17.9152 6.29199 18.2188 7.02519 18.7216 7.61439C19.2885 8.27999 19.5998 9.1257 19.5998 9.99999C19.5998 10.8743 19.2885 11.72 18.7216 12.3856C18.2192 12.9749 17.9156 13.7077 17.854 14.4796C17.7843 15.3513 17.4064 16.1697 16.7881 16.7881C16.1697 17.4064 15.3513 17.7843 14.4796 17.854C13.7077 17.9156 12.9749 18.2192 12.3856 18.7216C11.72 19.2885 10.8743 19.5998 10 19.5998C9.12571 19.5998 8.28 19.2885 7.6144 18.7216C7.0251 18.2192 6.29231 17.9156 5.5204 17.854C4.64868 17.7843 3.83028 17.4064 3.21192 16.7881C2.59356 16.1697 2.21567 15.3513 2.146 14.4796C2.08437 13.7077 1.78076 12.9749 1.2784 12.3856C0.71151 11.72 0.400169 10.8743 0.400169 9.99999C0.400169 9.1257 0.71151 8.27999 1.2784 7.61439C1.78076 7.02509 2.08437 6.2923 2.146 5.52039C2.21567 4.64868 2.59356 3.83027 3.21192 3.21191C3.83028 2.59355 4.64868 2.21566 5.5204 2.14599ZM14.4484 8.44839C14.667 8.22207 14.7879 7.91895 14.7852 7.60431C14.7825 7.28968 14.6563 6.9887 14.4338 6.76621C14.2113 6.54372 13.9103 6.41752 13.5957 6.41478C13.281 6.41205 12.9779 6.533 12.7516 6.75159L8.8 10.7032L7.2484 9.15159C7.02208 8.933 6.71895 8.81205 6.40432 8.81478C6.08968 8.81752 5.78871 8.94372 5.56622 9.16621C5.34373 9.3887 5.21753 9.68968 5.21479 10.0043C5.21206 10.3189 5.33301 10.6221 5.5516 10.8484L7.9516 13.2484C8.17663 13.4734 8.4818 13.5997 8.8 13.5997C9.1182 13.5997 9.42337 13.4734 9.6484 13.2484L14.4484 8.44839Z"
clip-rule="evenodd"
/>
Expand Down Expand Up @@ -475,7 +475,22 @@
fill-rule="evenodd"
clip-rule="evenodd"
d="M5.15164 5.1515C5.37667 4.92654 5.68184 4.80016 6.00004 4.80016C6.31823 4.80016 6.6234 4.92654 6.84844 5.1515L12 10.3031L17.1516 5.1515C17.2623 5.03689 17.3947 4.94547 17.5412 4.88258C17.6876 4.81969 17.845 4.78659 18.0044 4.7852C18.1637 4.78382 18.3217 4.81418 18.4692 4.87452C18.6167 4.93485 18.7506 5.02396 18.8633 5.13663C18.976 5.2493 19.0651 5.38328 19.1254 5.53076C19.1858 5.67823 19.2161 5.83625 19.2147 5.99558C19.2134 6.15492 19.1803 6.31238 19.1174 6.45879C19.0545 6.60519 18.963 6.73761 18.8484 6.8483L13.6968 11.9999L18.8484 17.1515C19.067 17.3778 19.188 17.6809 19.1852 17.9956C19.1825 18.3102 19.0563 18.6112 18.8338 18.8337C18.6113 19.0562 18.3104 19.1824 17.9957 19.1851C17.6811 19.1878 17.378 19.0669 17.1516 18.8483L12 13.6967L6.84844 18.8483C6.62211 19.0669 6.31899 19.1878 6.00436 19.1851C5.68972 19.1824 5.38874 19.0562 5.16625 18.8337C4.94376 18.6112 4.81756 18.3102 4.81483 17.9956C4.81209 17.6809 4.93305 17.3778 5.15164 17.1515L10.3032 11.9999L5.15164 6.8483C4.92667 6.62327 4.80029 6.3181 4.80029 5.9999C4.80029 5.68171 4.92667 5.37654 5.15164 5.1515Z"
fill="white"
fill="currentColor"
/>
</symbol>
<symbol
id="down-arrow"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M6.35159 8.7516C6.57662 8.52663 6.88179 8.40026 7.19999 8.40026C7.51819 8.40026 7.82335 8.52663 8.04839 8.7516L12 12.7032L15.9516 8.7516C16.0623 8.63699 16.1947 8.54557 16.3411 8.48268C16.4875 8.41979 16.645 8.38668 16.8043 8.3853C16.9636 8.38391 17.1217 8.41428 17.2691 8.47461C17.4166 8.53495 17.5506 8.62405 17.6633 8.73673C17.7759 8.8494 17.865 8.98338 17.9254 9.13085C17.9857 9.27833 18.0161 9.43635 18.0147 9.59568C18.0133 9.75502 17.9802 9.91248 17.9173 10.0589C17.8544 10.2053 17.763 10.3377 17.6484 10.4484L12.8484 15.2484C12.6234 15.4734 12.3182 15.5997 12 15.5997C11.6818 15.5997 11.3766 15.4734 11.1516 15.2484L6.35159 10.4484C6.12662 10.2234 6.00024 9.9182 6.00024 9.6C6.00024 9.2818 6.12662 8.97663 6.35159 8.7516Z"
fill="currentColor"
/>
</symbol>
</defs>
Expand Down
116 changes: 116 additions & 0 deletions src/content-scripts/LoginAsPopup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { getOffset, sendPayload } from '@/utils/helpers'

export class LoginAsPopup {
/**
* @type {HTMLElement} iframe
*/
iframe

/**
* @type {boolean} canDestroy
*/
canDestroy = false

/**
*
* @param {HTMLElement} target
* @param {Array<unknown>} logins
* @param {import('./content-script').PForm} forms
*/
constructor(target, logins, forms) {
this.target = target
this.logins = logins
this.forms = forms
this.WIDTH = 350
this.height = 206 // this will change
this.className = `passwall-login-as-popup-${Math.floor(Math.random() * 9999)}`
}

/**
*
* @param {import('./content-script').RuntimeRequest} request
* @param {*} sender
* @param {*} sendResponse
*/
async messageHandler(request, sender, sendResponse) {
let parsedRequest
try {
parsedRequest = JSON.parse(request)
} catch (error) {
return
}

switch (parsedRequest.type) {
case 'LOGIN_AS_POPUP_RESIZE':
this.height = parsedRequest.payload.height // resize dynamic height
this.update()
this.canDestroy = true
break
case 'LOGIN_AS_POPUP_FETCH':
sendPayload({ type: 'LOGIN_AS_POPUP_FETCH', payload: this.logins }) // send logins to popup
break
case 'LOGIN_AS_POPUP_FILL_FORM':
this.fillForm(parsedRequest.payload)
break
case 'LOGIN_AS_POPUP_CLOSE':
this.destroy()
break
}
}

/**
*
* @param {string} username
* @param {string} password
*/
fillForm({ username, password }) {
this.forms[0].inputs.forEach(input => {
input.focus()
if (input.type === 'password') input.value = password
if (['text', 'email'].includes(input.type)) input.value = username
})
this.destroy()
}

onClickOutside(e) {
if (!e.target.className.includes(this.className)) {
if (this.canDestroy) this.destroy()
}
}

create() {
this.iframe = document.createElement('iframe')
this.iframe.setAttribute('id', 'passwall-input-dialog')
this.iframe.setAttribute('src', browser.runtime.getURL('popup.html#/Inject/loginAsPopup'))
this.iframe.setAttribute('scrolling', 'no')
this.iframe.setAttribute('class', this.className)

document.body.appendChild(this.iframe)
window.addEventListener('click', this.onClickOutside.bind(this), true)
}

update() {
const { top, left, height } = getOffset(this.target)
this.iframe.setAttribute(
'style',
`
top: ${top + height + 1}px;
left: ${left}px;
width: ${this.WIDTH}px;
height: ${this.height}px;
border: 1px solid #8b93a1;
border-radius: 16px;
`
)
}

render() {
this.create()
this.update()
}

destroy() {
this.iframe.remove()
window.removeEventListener('click', this.onClickOutside.bind(this), true)
}
}
Loading

0 comments on commit ebea314

Please sign in to comment.