Added support for configuration files
This commit is contained in:
parent
f1648dade6
commit
76d8f5f147
3
INSTALL
3
INSTALL
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
2. Configure the following paths for your setup. These variables
|
2. Configure the following paths for your setup. These variables
|
||||||
are located in the file tinyca itself.
|
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)
|
@INC (location of the directory lib)
|
||||||
$init->{'opensslbin'} (location of your openssl binary)
|
$init->{'opensslbin'} (location of your openssl binary)
|
||||||
|
|
|
@ -119,7 +119,7 @@ sub new {
|
||||||
$self->{'cursor'} = Gtk2::Gdk::Cursor->new('left-ptr');
|
$self->{'cursor'} = Gtk2::Gdk::Cursor->new('left-ptr');
|
||||||
$self->{'rootwin'} = Gtk2::Gdk->get_default_root_window();
|
$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->{'mvb'} = Gtk2::VBox->new();
|
||||||
$self->{'mw'}->add($self->{'mvb'});
|
$self->{'mw'}->add($self->{'mvb'});
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,38 @@ use strict;
|
||||||
package HELPERS;
|
package HELPERS;
|
||||||
|
|
||||||
use POSIX;
|
use POSIX;
|
||||||
|
use Config::Tiny;
|
||||||
|
|
||||||
my $version = "0.1";
|
my $version = "0.1";
|
||||||
my $true = 1;
|
my $true = 1;
|
||||||
my $false = undef;
|
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
|
# 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
|
23
tinyca2
23
tinyca2
|
@ -52,49 +52,50 @@ textdomain("tinyca2");
|
||||||
# https://bugs.gentoo.org/show_bug.cgi?id=78576
|
# https://bugs.gentoo.org/show_bug.cgi?id=78576
|
||||||
$ENV{XLIB_SKIP_ARGB_VISUALS}= '1';
|
$ENV{XLIB_SKIP_ARGB_VISUALS}= '1';
|
||||||
|
|
||||||
|
my $cfg = HELPERS::read_global_cfg();
|
||||||
my $init = {};
|
my $init = {};
|
||||||
|
|
||||||
# location of openssl
|
# location of openssl
|
||||||
$init->{'opensslbin'} = "/usr/bin/openssl";
|
$init->{'opensslbin'} = $cfg->{paths}{opensslbin} // "/usr/bin/openssl";
|
||||||
$init->{'zipbin'} = "/usr/bin/zip";
|
$init->{'zipbin'} = $cfg->{paths}{zipbin} // "/usr/bin/zip";
|
||||||
$init->{'tarbin'} = "/bin/tar";
|
$init->{'tarbin'} = $cfg->{paths}{tarbin} // "/bin/tar";
|
||||||
|
|
||||||
if(not -x $init->{'opensslbin'}) {
|
if(not -x $init->{'opensslbin'}) {
|
||||||
printf(gettext("Can't execute %s.\n"), $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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(not -x $init->{'zipbin'}) {
|
if(not -x $init->{'zipbin'}) {
|
||||||
print gettext("zip command not found, support disabled.\n");
|
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'}) {
|
if(not -x $init->{'tarbin'}) {
|
||||||
print gettext("tar command not found, support disabled.\n");
|
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
|
# directory with the templates
|
||||||
$init->{'templatedir'} = "./templates";
|
$init->{'templatedir'} = $cfg->{paths}{templatedir} // "./templates";
|
||||||
|
|
||||||
if(not -d $init->{'templatedir'}) {
|
if(not -d $init->{'templatedir'}) {
|
||||||
print gettext("Can't find templatedir.\n");
|
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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
# location for CA files
|
# location for CA files
|
||||||
if( exists $ENV{'TINYCA_BASEDIR'}) {
|
if( exists $ENV{'TINYCA_BASEDIR'}) {
|
||||||
$init->{'basedir'} = $ENV{'TINYCA_BASEDIR'}
|
$init->{'basedir'} = $ENV{'TINYCA_BASEDIR'}
|
||||||
} else {
|
} else {
|
||||||
$init->{'basedir'} = $ENV{HOME}."/.TinyCA";
|
$init->{'basedir'} = $cfg->{paths}{basedir} // $ENV{HOME}."/.TinyCA";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( exists $ENV{'TINYCA_EXPORTDIR'}) {
|
if( exists $ENV{'TINYCA_EXPORTDIR'}) {
|
||||||
$init->{'exportdir'} = $ENV{'TINYCA_EXPORTDIR'};
|
$init->{'exportdir'} = $ENV{'TINYCA_EXPORTDIR'};
|
||||||
} else {
|
} else {
|
||||||
$init->{'exportdir'} = $ENV{HOME};
|
$init->{'exportdir'} = $cfg->{paths}{exportdir} // $ENV{HOME};
|
||||||
}
|
}
|
||||||
|
|
||||||
umask(0077);
|
umask(0077);
|
||||||
|
|
Loading…
Reference in New Issue