Skip to content

Instantly share code, notes, and snippets.

@genneko
Last active June 23, 2019 07:02
Show Gist options
  • Save genneko/85c8fa260e588f9d70a69f615bf18f4d to your computer and use it in GitHub Desktop.
Save genneko/85c8fa260e588f9d70a69f615bf18f4d to your computer and use it in GitHub Desktop.
A quick note on how to install Joplin CLI client on FreeBSD.

Testing on VNET Jails

Host

/etc/jail.conf

exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;

host.hostname = $name;
path = "/vm/$name";
exec.consolelog = "/var/log/jail_${name}_console.log";
exec.prestart = "cp /etc/resolv.conf $path/etc";
exec.poststop = "rm $path/etc/resolv.conf";

devfs_ruleset = 10;

proxy {
        $net = "vi0";
        $gwv4 = "172.31.0.1";
        $ipv4 = "172.31.0.2";
        $plen = 24;

        vnet;
        vnet.interface = "${net}_$name";
        exec.prestart += "vnet add -4 $gwv4/$plen $net ${net}_$name";
        exec.start += "ifconfig ${net}_$name $ipv4/$plen";
        exec.start += "route add default $gwv4";
        exec.poststop += "vnet delete $net ${net}_$name";
}

webdav {
        $net = "vi0";
        $gwv4 = "172.31.0.1";
        $ipv4 = "172.31.0.3";
        $plen = 24;

        vnet;
        vnet.interface = "${net}_$name";
        exec.prestart += "vnet add -4 $gwv4/$plen $net ${net}_$name";
        exec.start += "ifconfig ${net}_$name $ipv4/$plen";
        exec.start += "route add default $gwv4";
        exec.poststop += "vnet delete $net ${net}_$name";
}

/etc/devfs.rules

[devfsrules_bpfjail=10]
add include $devfsrules_jail
add path 'bpf*' unhide

[devfsrules_tunjail=11]
add include $devfsrules_jail
add path 'tun*' unhide

/etc/pf.conf

nat on em0 inet from 172.31.0.0/24 to any -> (em0)

/etc/rc.conf (excerpts)

gateway_enable="YES"
pf_enable="YES"
pflog_enable="YES"
jail_enable="YES"

Jail proxy

/usr/local/etc/privoxy/config (excerpts)

debug 1
debug 1024
listen-address 172.31.0.2:8118

/etc/rc.conf (excerpts)

privoxy_enable="YES"

Jail webdav

/usr/local/etc/apache24/httpd.conf (excerpts)

LoadModule socache_shmcb_module libexec/apache24/mod_socache_shmcb.so
LoadModule ssl_module libexec/apache24/mod_ssl.so
LoadModule dav_module libexec/apache24/mod_dav.so
LoadModule dav_fs_module libexec/apache24/mod_dav_fs.so
LoadModule dav_lock_module libexec/apache24/mod_dav_lock.so
ServerName 172.31.0.3:80
Include etc/apache24/extra/httpd-dav.conf
Include etc/apache24/extra/httpd-ssl.conf

/usr/local/etc/apache24/extra/httpd-dav.conf (excerpts)

DavLockDB "/usr/local/var/DavLock/DavLock"
Alias /dav "/usr/local/www/dav"
<Directory "/usr/local/www/dav">
    SSLRequireSSL
    AuthType Basic
    AuthName DAV
    AuthUserFile "/usr/local/etc/davuser.passwd"

/usr/local/etc/apache24/extra/httpd-ssl.conf (excerpts)

ServerName 172.31.0.3:443

/etc/rc.conf (excerpts)

apache24_enable="YES"
#!/usr/bin/env perl
use strict;
use utf8;
use Encode;
use open qw(:std :utf8);
use FindBin;
use lib $FindBin::Bin;
use Joplin;
my $API_URL = "http://localhost:41184";
my $API_TOKEN = "PUT_YOUR_TOKEN_HERE";
my $root = Joplin->connect(
server => $API_URL,
apikey => $API_TOKEN,
);
my @folders = $root->find_folders();
if(@folders < 1){
print STDERR "No folder available.\n";
exit 1;
}
printf("Available Folders: %s\n", join(", ", map { "[" . $_->{title} . "]" } @folders));
sub index_folders_by_id{
my(@folders) = @_;
my(%folder_by_id);
for my $folder (@folders){
$folder_by_id{$folder->{id}} = $folder;
}
return \%folder_by_id;
}
sub index_folders_by_title{
my(@folders) = @_;
my(%folder_by_title);
for my $folder (@folders){
$folder_by_title{$folder->{title}} = $folder;
}
return \%folder_by_title;
}
my $folder_by_id = index_folders_by_id(@folders);
my $folder_by_title = index_folders_by_title(@folders);
if(@ARGV >= 2){
map { $_ = Encode::decode('utf8', $_) } @ARGV;
my($title, $body, $notebook, @tags) = @ARGV;
my($folder, $note);
if($notebook){
$folder = $folder_by_title->{$notebook};
}
if(!$folder){
$folder = $folders[0];
}
$note = $folder->create_note($title, $body);
if($note && @tags){
for my $tag (@tags){
$note->add_tag($tag) if $tag;
}
}
}
for my $folder (@folders){
my(@notes) = $folder->find_notes();
for my $note (@notes){
my @tags;
#@tags = $note->find_tags();
printf("%s [%s] %s\n", $note->{title}, $folder_by_id->{$note->{parent_id}}, join(", ", @tags));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment