forked from grodzik/uzbl-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eFormFiller.sh
executable file
·167 lines (150 loc) · 5.62 KB
/
eFormFiller.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/sh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Based on script from Uzbl examples (anonymous author)
# Copyright (c) 2009 by Paweł Tomak <satherot (at) gmail (dot) com>
#
#
# Enhanced html form (eg for logins) filler (and manager) for uzbl.
#
# uses settings files like: $keydir/<domain>
# files contain lines like: !profile=<profile_name>
# <fieldname>(fieldtype): <value>
# profile_name should be replaced with a name that will tell sth about that profile
# fieldtype can be text or password - only for information pupropse (auto-generated) - don't change that
#
# user arg 1:
# edit: force editing the file (falls back to new if not found)
# new: start with a new file.
# load: try to load from file into form
# add: try to add another profile to an existing file
#
# something else (or empty): if file not available: new, otherwise load.
# config dmenu colors and prompt
NB="#0f0f0f"
NF="#4e7093"
SB="#003d7c"
SF="#3a9bff"
PROMPT="Choose profile"
keydir=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/dforms
[ -d "`dirname $keydir`" ] || exit 1
[ -d "$keydir" ] || mkdir "$keydir"
editor=${VISUAL}
if [[ -z ${editor} ]]; then
editor="urxvt -e ${EDITOR}"
fi
if [[ -z ${editor} ]]; then
editor='xterm -e vim'
fi
config=$1; shift
pid=$1; shift
xid=$1; shift
fifo=$1; shift
socket=$1; shift
url=$1; shift
title=$1; shift
action=$1
[ -d $keydir ] || mkdir $keydir || exit 1
if [ "$action" != 'edit' -a "$action" != 'new' -a "$action" != 'load' -a "$action" != 'add' ]
then
action=new
[[ -e $keydir/$domain ]] && action=load
elif [ "$action" == 'edit' ] && [[ ! -e $keydir/$domain ]]
then
action=new
fi
domain=$(echo $url | sed 's#\(http\|https\)://\([^/]\+\)/.*#\2#')
passhashdomain=$(echo $domain | sed 's#^\(.*\.\)\?\([^\.]\+\.[^\.]\+\)$#\2#')
echo "Using domain $domain"
echo "Passhash domain $passhashdomain"
get_password_export_value()
{
# $1 - type (site-tag, master-key, options)
# $2 - domain
grep "$1-$2" ~/password-export-* | sed -e 's/^.*password="//' -e 's/".*$//'
}
get_password_site_tag()
{
# $1 - domain
get_password_export_value site-tag $1
}
get_password_master_key()
{
# $1 - domain
get_password_export_value master-key $1
}
get_password_length()
{
# $1 - domain
get_password_export_value options $1 | sed 's/[^0-9]*//'
}
get_passhash_password()
{
# $1 - domain
js ~/.config/uzbl/scripts/eFormFiller/passhash.js "$(get_password_site_tag $1)" "$(get_password_master_key $1)" "$(get_password_length $1)"
}
echo "Passhash site tag: $(get_password_site_tag $passhashdomain)"
echo "Passhash master key: $(get_password_master_key $passhashdomain)"
echo "Passhash password length: $(get_password_length $passhashdomain)"
echo "Passhash password: $(get_passhash_password $passhashdomain)"
if [[ "$action" == 'load' ]]
then
[[ -e $keydir/$domain ]] || exit 2
if [[ `cat $keydir/$domain|grep "!profile"|wc -l` -gt 1 ]]
then
menu=`cat $keydir/$domain| \
sed -n 's/^!profile=\([^[:blank:]]\+\)/\1/p'`
optiown=`echo -e -n "$menu"| dmenu -nb "${NB}" -nf "${NF}" -sb "${SB}" -sf "${SF}" -p "${PROMPT}"`
fi
cat $keydir/$domain | \
sed -n -e "/^!profile=${option}/,/^!profile=/p" | \
sed -n -e 's/\([^(]\+\)([^)]\+):[ ]*\([^[:blank:]]\+\)/js document.getElementsByName("\1")[0].value="\2";/p' | \
sed -e 's/@/\\@/p' | \
sed -e "s#\\\\@@PASSHASH@@#$(get_passhash_password $passhashdomain)#" >> $fifo
else
if [[ "$action" == 'new' || "$action" == 'add' ]]
then
if [ "$action" == 'new' ]
then
echo "!profile=NAME_THIS_PROFILE$RANDOM" > $keydir/$domain
else
echo "!profile=NAME_THIS_PROFILE$RANDOM" >> $keydir/$domain
fi
#
# 2. and 3. line (tr -d and sed) are because, on gmail login for example,
# <input > tag is splited into lines
# ex:
# <input name="Email"
# type="text"
# value="">
# So, tr removes all new lines, and sed inserts new line after each >
# Next sed selects only <input> tags and only with type == "text" or == "password"
# If type is first and name is second, then another sed will change their order
# so the last sed will make output
# text_from_the_name_attr(text or password):
#
# login(text):
# passwd(password):
#
curl -L "$url" | \
tr -d '\n' | \
sed 's/>/>\n/g' | \
sed -n 's/.*\(<input[^>]\+>\).*/\1/;/type="\(password\|text\)"/Ip' | \
sed 's/\(.*\)\(type="[^"]\+"\)\(.*\)\(name="[^"]\+"\)\(.*\)/\1\4\3\2\5/I' | \
sed 's/.*name="\([^"]\+\)".*type="\([^"]\+\)".*/\1(\2): /I' >> $keydir/$domain
fi
[[ -e $keydir/$domain ]] || exit 3 #this should never happen, but you never know.
$editor $keydir/$domain #TODO: if user aborts save in editor, the file is already overwritten
fi
# vim:fileencoding=utf-8:sw=4