Changeset 24 in code for trunk


Ignore:
Timestamp:
May 14, 2025, 2:23:43 AM (4 weeks ago)
Author:
yakumo.izuru
Message:

Make TOTP support built-in, simplify code a bit, add colored errors and warnings via printf

Location:
trunk
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/COPYING

    r17 r24  
    22 * ----------------------------------------------------------------------------
    33 * "THE BEER-WARE LICENSE" (Revision 42.1):
    4  * <yakumo.izuru@chaotic.ninja> wrote this file. As long as you retain this notice you
     4 * <eternal-servant@yakumo.dev> wrote this file. As long as you retain this notice you
    55 * can do whatever you want with this stuff. If we meet some day, and you think
    66 * this stuff is worth it, you can buy me a bottle of sake in return Izuru Yakumo
  • trunk/README.md

    r22 r24  
    99
    1010## Dependencies
    11 * Any of the above, depending how you configured it
    12 * `tree(1)` for printing a list
    13 * `mandoc(1)` for documentation
    14 * `rm(1)` with the `-i` and `-I` switches
    15 * `strings(1)`, `dd(1)` and `tr(1)` for generating passwords
     11* [dd(1)](https://man.netbsd.org/dd.1)
     12* [oathtool(1)](https://www.nongnu.org/oath-toolkit/)
     13* [rm(1)](https://man.netbsd.org/rm.1)
     14* [strings(1)](https://man.netbsd.org/strings.1)
     15* [tr(1)](https://man.netbsd.org/tr.1)
     16* [tree(1)](https://github.com/Old-Man-Programmer/tree)
    1617
    1718## Add-ons
     
    2021quick graphical front-end for kanako, works with either of `dmenu(1)`
    2122or `bemenu(1)`, useful for copying passwords to clipboard.
    22 
    23 ### kanako-totp
    24 time-based one time password addon for kanako, requires `oathtool(1)`
    25 from oath-toolkit.
    2623
    2724## License
  • trunk/kanako

    r23 r24  
    11#!/bin/sh
    2 # $TheSupernovaDuo: kanako,v 2.1 2023/10/25 01:50:28 yakumo_izuru Exp $
     2# $YakumoLabs: kanako,v 2.2 2025/05/14 02:07:06 yakumo_izuru Exp $
    33
    4 readonly kanako_conf_dir="${kanako_conf_dir:-$HOME/.config/kanako}"
    5 readonly kanako_key_dir="${kanako_key_dir:-$HOME/.kanako}"
    6 readonly kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}"
     4kanako_conf_dir="${kanako_conf_dir:-$HOME/.config/kanako}"
     5kanako_key_dir="${kanako_key_dir:-$HOME/.kanako}"
     6kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}"
    77
    8 if test -d "${kanako_store_dir}"; then
    9         cd "${kanako_store_dir}"
    10 else
    11         printf "Password store not found!\n"
    12         printf "Create it with mkdir -p %s\n" "$kanako_store_dir"
    13         exit 1
    14 fi
     8_die() {
     9    printf "\033[1;31m%s\033[0m\n" "$*" >&2
     10    exit 1
     11}
     12_warn() {
     13    printf "\033[1;35m%s\033[0m\n" "$*"
     14}
    1515
    16 if test -f "${kanako_conf_dir}/kanako.conf"; then
    17         . "${kanako_conf_dir}/kanako.conf"
    18 else
    19         printf "Configuration file has not been found!\n"
    20         printf "Copy kanako.conf from the examples directory,\n"
    21         printf "and edit accordingly.\n"
    22         exit 1
    23 fi
     16[ -d "${kanako_store_dir}" ] && cd "${kanako_store_dir}" || _die "Password store not found"
     17[ -f "${kanako_conf_dir}/kanako.conf" ] && . "${kanako_conf_dir}/kanako.conf" || _die "Configuration file not found"
    2418
    2519copy() {
     
    2721}
    2822edit() {
    29         if [ -f ${1%%.enc}.enc ]; then
    30                 ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
    31                 "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
    32                 ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
    33                 rm "${1%%.enc}"
    34         else
    35                 printf "%s does not exist, maybe there was a typo on your end?\n" "${1%%.enc}.enc"
    36         fi
     23    if [ -f ${1%%.enc}.enc ]; then
     24        ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
     25        "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
     26        ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
     27        rm "${1%%.enc}"
     28    else
     29        _warn "%s does not exist, maybe there was a typo on your end?\n" "${1%%.enc}.enc"
     30    fi
    3731}
    3832gen() {
    39         printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
     33    printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
    4034}
    4135list() {
    42         if [ -z "$1" ]; then
    43                 $(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g'
    44         else
    45                 $(which tree) "${1:-.}" | sed 's/\.enc//g'
    46         fi
     36    if [ -z "$(command -v tree)" ]; then
     37        _die "Required dependency 'tree' not found"
     38
     39    fi
     40    if [ -z "$1" ]; then
     41        tree "${kanako_store_dir}/" | sed 's/\.enc//g'
     42    else
     43        tree "${1:-.}" | sed 's/\.enc//g'
     44    fi
    4745}
    4846new() {
    49         test -d "$1" && usage
     47    [ -d "$1" ] && usage
     48    tmpfile="$(mktemp)"
     49    "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
     50    mkdir -p "$(dirname "$1")"
     51    ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
     52    rm ${tmpfile}
     53}
     54otp() {
     55    if [ -z "$(command -v oathtool)" ]; then
     56        _die "Required dependency 'oathtool' not found"
    5057
    51         tmpfile="$(mktemp)"
    52         "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
    53 
    54         mkdir -p "$(dirname "$1")"
    55         ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
    56         rm ${tmpfile}
     58    fi
     59    totp_seed=$(view "$1" | grep 'totp: ' | head -n1 | cut -d' ' -f2)
     60    if ! [ -z ${totp_seed} ]; then
     61        oathtool --totp -b ${totp_seed}
     62    fi
    5763}
    5864delete_directory() {
    59         rm -r -I "$1"
     65    rm -r -i "$1"
    6066}
    6167delete_file() {
    62         rm -i "${1}${2}".enc
     68    rm -i "${1}${2}".enc
    6369}
    6470usage() {
    65         printf "Usage: %s [-c|-e|-g|-l|-n|-R|-r|-v [file or directory]]\n" "$0"
    66         printf "The arguments for all switches are relative to \${kanako_store_dir}\n"
    67         printf "which is located at %s\n" "${kanako_store_dir}"
    68         exit 1
     71    printf "Usage: %s [-c|-e|-g|-l|-n|-R|-r|-v [file or directory]]\n" "$0"
     72    printf "The arguments for all switches are relative to \${kanako_store_dir}\n"
     73    printf "which is located at %s\n" "${kanako_store_dir}"
     74    exit
    6975}
    7076view() {
    71         if [ -f "${1%%.enc}".enc ]; then
    72                 ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
    73         elif [ -d "${1:-.}" ]; then
    74                 list "${1:-.}"
    75         else
    76                 usage
    77         fi
     77    if [ -f "${1%%.enc}".enc ]; then
     78        ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
     79    elif [ -d "${1:-.}" ]; then
     80        list "${1:-.}"
     81    else
     82        usage
     83    fi
    7884}
    7985
    8086case $1 in
    81 -c) copy $2 ;;
    82 -e) edit $2 ;;
    83 -g) gen $2 ;;
    84 -l) list $2 ;;
    85 -n) new $2 ;;
    86 -R) delete_directory $2 ;;
    87 -r) delete_file $2 ;;
    88 -v) view $2 ;;
    89 *) usage ;;
     87    -c) copy $2 ;;
     88    -e) edit $2 ;;
     89    -g) gen $2 ;;
     90    -l) list $2 ;;
     91    -n) new $2 ;;
     92    -o) otp $2 ;;
     93    -R) delete_directory $2 ;;
     94    -r) delete_file $2 ;;
     95    -v) view $2 ;;
     96    *) usage ;;
    9097esac
  • trunk/kanako.conf.mdoc

    r18 r24  
    1 .Dd $Mdocdate$
     1.Dd May 14, 2025
    22.Dt KANAKO.CONF 5
    33.Os
    44.Sh NAME
    55.Nm kanako.conf
    6 .Nd configuration file for
    7 .Xr kanako 1
    8 .Sh FIELDS
     6.Nd configuration file for kanako
     7.Sh CONFIGURATION FIELDS
    98.Bl -tag -width 11n -compact
    109.It kanako_clip_cmd
     
    2726.Xr kanako 1
    2827.Sh AUTHORS
    29 .An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
    30  
     28.An Izuru Yakumo Aq Mt eternal-servant@yakumo.dev
  • trunk/kanako.mdoc

    r23 r24  
    1 .Dd $Mdocdate$
     1.Dd May 14, 2025
    22.Dt KANAKO 1
    33.Os
     
    77.Sh SYNOPSIS
    88.Nm
    9 .Op Fl ceglnrRv
     9.Op Fl ceglnorRv
    1010.Op Ar args
    1111.Sh DESCRIPTION
     
    1414supporting multiple backends
    1515and having more add-ons for
    16 use with it. However, it
    17 may be pretty unstable compared
    18 to said tool, but should work
    19 well for its purpose.
     16use with it.
     17However, it may be pretty unstable compared
     18to said tool, but should work well for its purpose.
    2019.Sh USAGE
    2120.Bl -tag -width 11n -compact
     
    3029.It -l
    3130List all entries
     31.It -o
     32Obtain a one time password
    3233.It -r
    3334Remove single entries,
     
    3839.It -v
    3940View an entry
    40 .Bl
    4141.El
    4242.Sh SEE ALSO
    43 .Xr age 1
    44 .Xr cream 1
    45 .Xr gpg 1
     43.Xr age 1 ,
     44.Xr cream 1 ,
     45.Xr gpg 1 ,
     46.Xr oathtool 1 ,
     47.Xr pwgen 1 ,
     48.Xr salty 1 ,
    4649.Xr kanako.conf 5
    47 .Xr pwgen 1
    48 .Xr salty 1
    4950.Rs
    5051.%A Rob Pike
     
    5455.Re
    5556.Sh AUTHORS
    56 .An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
    57 .Sh BUGS
    58 Under the Wayland display protocol,
    59 the clipboard subcommand won't work,
    60 due to 'Permission denied'. On X11
    61 it works just fine.
     57.An Izuru Yakumo Aq Mt eternal-servant@yakumo.dev
Note: See TracChangeset for help on using the changeset viewer.