Added support for configuration files

master
Thomas Hooge 3 years ago
parent f1648dade6
commit 76d8f5f147
  1. 3
      INSTALL
  2. 2
      lib/GUI.pm
  3. 27
      lib/HELPERS.pm
  4. 8
      tinyca.cnf.example
  5. 23
      tinyca2

@ -2,6 +2,9 @@
2. Configure the following paths for your setup. These variables
are located in the file tinyca itself.
As of version 0.7.6 these settings should be configured in
/etc/tinyca/tinyca.cnf. So there is no more need to modify
the code itself. See tinyca.cnf.example.
@INC (location of the directory lib)
$init->{'opensslbin'} (location of your openssl binary)

@ -119,7 +119,7 @@ sub new {
$self->{'cursor'} = Gtk2::Gdk::Cursor->new('left-ptr');
$self->{'rootwin'} = Gtk2::Gdk->get_default_root_window();
# split window to add menu, toolbar and notebook
# split window horizontal to add menu, toolbar and notebook
$self->{'mvb'} = Gtk2::VBox->new();
$self->{'mw'}->add($self->{'mvb'});

@ -21,11 +21,38 @@ use strict;
package HELPERS;
use POSIX;
use Config::Tiny;
my $version = "0.1";
my $true = 1;
my $false = undef;
#
# read global configuration file
#
sub read_global_cfg {
my $cfg = Config::Tiny->read("/etc/tinyca/tinyca.cnf", 'utf8');
return ($cfg);
}
#
# read a per CA configuration
#
sub read_cfg {
my $base = shift;
my $cfg = Config::Tiny->read($base."/tinyca.cnf", 'utf8');
return ($cfg);
}
#
# read per user configuration
# e.g. last used ca, last window position
#
sub read_user_cfg {
my $cfg = Config::Tiny->read($ENV{HOME}."/.tinycarc", 'utf8');
return ($cfg);
}
#
# generate filename from Subject-DN
#

@ -0,0 +1,8 @@
[paths]
basedir = /var/lib/tinyca
exportdir = /tmp
templatedir = /usr/share/tinyaca/templates
opensslbin = /usr/bin/openssl
zipbin = /usr/bin/zip
tarbin = /bin/tar

@ -52,49 +52,50 @@ textdomain("tinyca2");
# https://bugs.gentoo.org/show_bug.cgi?id=78576
$ENV{XLIB_SKIP_ARGB_VISUALS}= '1';
my $cfg = HELPERS::read_global_cfg();
my $init = {};
# location of openssl
$init->{'opensslbin'} = "/usr/bin/openssl";
$init->{'zipbin'} = "/usr/bin/zip";
$init->{'tarbin'} = "/bin/tar";
$init->{'opensslbin'} = $cfg->{paths}{opensslbin} // "/usr/bin/openssl";
$init->{'zipbin'} = $cfg->{paths}{zipbin} // "/usr/bin/zip";
$init->{'tarbin'} = $cfg->{paths}{tarbin} // "/bin/tar";
if(not -x $init->{'opensslbin'}) {
printf(gettext("Can't execute %s.\n"), $init->{'opensslbin'});
print gettext("Configure correct path to openssl in tinyca.\n");
print gettext("Configure correct path to openssl.\n");
exit(1);
}
if(not -x $init->{'zipbin'}) {
print gettext("zip command not found, support disabled.\n");
print gettext("Configure correct path to zip in tinyca.\n");
print gettext("Configure correct path to zip.\n");
}
if(not -x $init->{'tarbin'}) {
print gettext("tar command not found, support disabled.\n");
print gettext("Configure correct path to tar in tinyca.\n");
print gettext("Configure correct path to tar.\n");
}
# directory with the templates
$init->{'templatedir'} = "./templates";
$init->{'templatedir'} = $cfg->{paths}{templatedir} // "./templates";
if(not -d $init->{'templatedir'}) {
print gettext("Can't find templatedir.\n");
print gettext("Please configure correct path with templates in tinyca.\n");
print gettext("Please configure correct path with templates.\n");
exit(1);
}
# location for CA files
if( exists $ENV{'TINYCA_BASEDIR'}) {
$init->{'basedir'} = $ENV{'TINYCA_BASEDIR'}
$init->{'basedir'} = $ENV{'TINYCA_BASEDIR'}
} else {
$init->{'basedir'} = $ENV{HOME}."/.TinyCA";
$init->{'basedir'} = $cfg->{paths}{basedir} // $ENV{HOME}."/.TinyCA";
}
if( exists $ENV{'TINYCA_EXPORTDIR'}) {
$init->{'exportdir'} = $ENV{'TINYCA_EXPORTDIR'};
} else {
$init->{'exportdir'} = $ENV{HOME};
$init->{'exportdir'} = $cfg->{paths}{exportdir} // $ENV{HOME};
}
umask(0077);