This commit is contained in:
commit
95a533c876
451 changed files with 18255 additions and 0 deletions
77
pkgs/pass2bw/convert_csvs.py
Normal file
77
pkgs/pass2bw/convert_csvs.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import csv
|
||||
import re
|
||||
import sys
|
||||
|
||||
def process_csv(input_file, output_file):
|
||||
column_mapping = {
|
||||
'Group(/)': 'folder',
|
||||
'Title': 'name',
|
||||
'Password': 'login_password',
|
||||
'Notes': 'notes'
|
||||
}
|
||||
|
||||
default_values = {
|
||||
'favorite': '',
|
||||
'type': 'login',
|
||||
'fields': '',
|
||||
'reprompt': '0',
|
||||
'login_uri': '',
|
||||
'login_username': '',
|
||||
'login_totp': ''
|
||||
}
|
||||
|
||||
target_columns = [
|
||||
'folder', 'favorite', 'type', 'name', 'notes', 'fields',
|
||||
'reprompt', 'login_uri', 'login_username', 'login_password', 'login_totp'
|
||||
]
|
||||
|
||||
with open(input_file, 'r', newline='', encoding='utf-8') as infile, \
|
||||
open(output_file, 'w', newline='', encoding='utf-8') as outfile:
|
||||
|
||||
reader = csv.DictReader(infile)
|
||||
writer = csv.DictWriter(outfile, fieldnames=target_columns)
|
||||
|
||||
writer.writeheader()
|
||||
|
||||
for row in reader:
|
||||
new_row = {}
|
||||
|
||||
for old_col, new_col in column_mapping.items():
|
||||
new_row[new_col] = row.get(old_col, '')
|
||||
|
||||
for col, default_val in default_values.items():
|
||||
if col not in new_row:
|
||||
new_row[col] = default_val
|
||||
|
||||
if new_row['notes']:
|
||||
new_row['notes'] = new_row['notes'].replace('\n', ' ').replace('\r', ' ')
|
||||
new_row['notes'] = re.sub(r'\s+', ' ', new_row['notes']).strip()
|
||||
|
||||
notes = new_row['notes']
|
||||
if notes:
|
||||
# Look for pattern: "login: USERNAME"
|
||||
match = re.search(r'login:\s*(\S+)', notes, re.IGNORECASE)
|
||||
if match:
|
||||
username = match.group(1)
|
||||
new_row['login_username'] = username
|
||||
new_row['notes'] = re.sub(r'login:\s*\S+', '', notes, flags=re.IGNORECASE).strip()
|
||||
new_row['notes'] = re.sub(r'\s+', ' ', new_row['notes']).strip()
|
||||
new_row['notes'] = new_row['notes'].strip(': ').strip()
|
||||
|
||||
for key in new_row:
|
||||
if new_row[key]:
|
||||
new_row[key] = str(new_row[key]).replace('\n', ' ').replace('\r', ' ')
|
||||
new_row[key] = re.sub(r'\s+', ' ', new_row[key]).strip()
|
||||
|
||||
writer.writerow(new_row)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python script.py <input_file.csv> <output_file.csv>")
|
||||
sys.exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
|
||||
process_csv(input_file, output_file)
|
||||
print(f"Processing complete. Output saved to {output_file}")
|
||||
32
pkgs/pass2bw/default.nix
Normal file
32
pkgs/pass2bw/default.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
stdenv,
|
||||
lib,
|
||||
makeWrapper,
|
||||
python3,
|
||||
...
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "pass2bw";
|
||||
version = "0.1";
|
||||
|
||||
src = ./.;
|
||||
|
||||
dontBuild = true;
|
||||
doCheck = false;
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
|
||||
sed -e "s|python ./convert_csvs.py|python $out/bin/convert_csvs.py|" \
|
||||
${src}/${pname}.sh > $out/bin/${pname}
|
||||
chmod +x $out/bin/${pname}
|
||||
|
||||
cp ${src}/convert_csvs.py $out/bin/
|
||||
|
||||
wrapProgram $out/bin/${pname} \
|
||||
--prefix PATH : ${lib.makeBinPath [ python3 ]}
|
||||
'';
|
||||
}
|
||||
8
pkgs/pass2bw/pass2bw.sh
Normal file
8
pkgs/pass2bw/pass2bw.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <pass_storepath> <output_csv>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pass2csv "$1" /tmp/pass.csv
|
||||
python ./convert_csvs.py /tmp/pass.csv "$2"
|
||||
rm /tmp/pass.csv
|
||||
Loading…
Add table
Add a link
Reference in a new issue