This file is indexed.

/usr/bin/credential-sheets is in credential-sheets 0.0.3-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/perl -T

# Copyright (C) 2012-2016 by Debian Edu project, http://wiki.debian.org/DebianEdu
#       Mike Gabriel <mike.gabriel@das-netzwerkteam.de>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

use strict;
use warnings;
use Cwd;
use File::Basename;
use File::Spec;
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
use Text::CSV;
use Getopt::Long;

$ENV{PATH} = '/usr/bin:/bin';

my $cmd = basename($0);

my $usage = '';
my $do_zip = '';
my $do_debug = '';
my $template = 'students';
my $zipfile_name = basename(&Cwd::cwd())."-TEMPLATE.zip";
my $rows = '7';
my $cols = '3';
GetOptions ('help' => \$usage,
            'template=s' => \$template,
            'zip' => \$do_zip,
            'zipfilename=s' => \$zipfile_name,
            'rows=s' => \$rows,
            'cols=s' => \$cols, 
            'debug' => \$do_debug,
);

$zipfile_name =~ s/TEMPLATE/$template/;

sub get_file_content {

	my $filename = "@_ ";
	$filename =~ s/^\s+|\s+$//g ;

	my $fullpath;

	if ( -f $ENV{"HOME"}.'/.'.$cmd.'/'.$filename ) {
		$fullpath = $ENV{"HOME"}.'/.'.$cmd.'/'.$filename;
	}
	elsif ( -f File::Spec->rel2abs("$filename") ) {
		$fullpath = File::Spec->rel2abs("$filename");
	}
	elsif ( -f '/etc/'.$cmd.'/'.$filename ) {
		$fullpath = '~/.'.$cmd.'/'.$filename;
	}
	elsif ( -f '/usr/local/share/'.$cmd.'/'.$filename ) {
		$fullpath = '/usr/local/share/'.$cmd.'/'.$filename;
	}
	elsif ( -f '/usr/share/'.$cmd.'/'.$filename ) {
		$fullpath = '/usr/share/'.$cmd.'/'.$filename;
	}
	else
	{
		return ();
	}

	open FH, $fullpath;
	print "Using: ".$fullpath."\n";
	my @content = <FH>;
	close FH;
	return @content;

}

sub finalize_texheader {

    my $line = "@_ ";

    $line =~ s/@@@\_ROWS_@@@/$rows/g;
    $line =~ s/@@@\_COLS_@@@/$cols/g;

    return $line;
}

sub usage {

	print <<"EOF";
usage: $cmd [options] <CSV-file-1> [<CSV-file-2> [...]]

Options:
    --help                        -- show this help output.
    --template=<tpl-name>         -- name of the template to use.
    --cols=<x>                    -- render <x> columns per sheet
    --rows=<y>                    -- render <y> rows per sheet
    --zip                         -- do create a ZIP file at the end
    --zipfilename=<zip-file-name> -- alternative ZIP file name (default: name of parent folder)
    --debug                       -- don\'t remove temporary files

CSV File Column Arrangement
---------------------------

The $cmd tool can handle any sort of column arrangement in given CSV file(s).
It expects the CSV file(s) to have column names in their first line.

The given column names have to map to the \"VAR-<column-name>\" placeholders in $cmd\'s
LaTeX templates.

The shipped-with templates \"students\" and \"teachers\" can handle these column names:

	login:		The user account\'s login id (uid)
	lastName:	The user\'s last name(s)
	firstName:	The user\'s first name(s)
	password:	The user\'s password
	form:		The form name/ID (student template only)
	subjects:	Subjects taught by a teacher (teachers template only)

The shipped-with template \"wifivouchers\" can handle these column names:

	essid:		The WiFi network's ESSID (network name)
	login:		The voucher\'s login id (if any)
	code:		The voucher\'s login code
	duration:	The duration period that the vouchers grants WiFi access

If you create your own templates, you can be very flexible in using your own column names and template.
names. Only make sure that the column names provided in the CSV file(s) match the variables used in the
customized LaTeX template.

The shipped-with $cmd templates can be found in /usr/share/$cmd/.
When customizing templates, simply place them into ~/.$cmd/ or /etc/$cmd.
EOF

	exit 0;
}

if ( $usage ) { usage() };

if ( (scalar @ARGV) == 0 ) {
	print STDERR "ERROR: No CSV file(s) name given. Aborting...\n\n";
	usage();
};

my $zip;
if ( $do_zip ) {
	print "preparing ZIP archive file: $zipfile_name\n";
	$zip = Archive::Zip->new();
}

my @template = get_file_content($template."-template.tex") or die $!;
my @tex_header = get_file_content("header.tex") or die $!;
my @tex_footer = get_file_content("footer.tex") or die $!;

my $csv_file;
my $csv_filehandle;
my $tex_file;
my $pdf_file;
my $log_file;
my $aux_file;
my $csv_table;

my $this_template;

while ( @ARGV )
{
	$csv_file = shift;
	$csv_file =~ s/^\s+|\s+$//g ;

	if ( $csv_file =~ /^(.*)$/ && -f $csv_file ) {

		$tex_file = $1;
		$tex_file =~ s/.csv/.tex/;

		print "Processing: ".File::Spec->rel2abs($csv_file)."\n";

		$pdf_file = $csv_file;
		$pdf_file =~ s/.csv/.pdf/;

		$log_file = $csv_file;
		$log_file =~ s/.csv/.log/;

		$aux_file = $csv_file;
		$aux_file =~ s/.csv/.aux/;

		$csv_table = Text::CSV->new({
		    decode_utf8=>0,
		    binary => 1,
		    auto_diag => 1,
		});
		open $csv_filehandle, "<$csv_file";

		open TEXFILE, ">$tex_file";
		foreach (@tex_header) {
			print TEXFILE finalize_texheader($_)."\n";
		}

		$csv_table->column_names($csv_table->getline ($csv_filehandle)); # use header
		while (my $row = $csv_table->getline_hr($csv_filehandle)) {
			$this_template = join("", @template);
			while (my ($key, $value) = each %$row) {
				$key =~ s/^\s+|\s+$//g ;
				if (!$key) {
					next;
				}
				$value =~ s/^\s+|\s+$//g ;
				$this_template =~ s/VAR-$key/$value/;
			}
			print TEXFILE "$this_template";
		}

		close $csv_filehandle;

		foreach (@tex_footer) {
			print TEXFILE "$_\n";
		}

		close TEXFILE;

		print "Created temporary file: ".File::Spec->rel2abs($tex_file)."\n";
		if ( system("/usr/bin/xelatex --halt-on-error $tex_file 2>&1 1>/dev/null") == 0 ) {
			print "Rendered: ".File::Spec->rel2abs($pdf_file)."\n";
			if ( ! $do_debug ) {
				if ( -e $tex_file && $tex_file =~ /^(.*)$/ ) { print "Removing temporary file: ".$1."\n"; unlink($1); }
				if ( -e $log_file && $log_file =~ /^(.*)$/ ) { print "Removing temporary file: ".$1."\n"; unlink($1); }
				if ( -e $aux_file && $aux_file =~ /^(.*)$/ ) { print "Removing temporary file: ".$1."\n"; unlink($1); }
			}
		}
		else
		{
			print STDERR "Rendering FAILED: ".File::Spec->rel2abs($pdf_file).", see .log and .aux file for details.\n";
		}

		if ( $do_zip ) {
			print "writing CSV sheet to ZIP archive\n";
			$zip->addFile( $csv_file ) or warn "Can't add file $csv_file\n";
			print "writing PDF file to ZIP archive\n";
			$zip->addFile( $pdf_file ) or warn "Can't add file $pdf_file\n";
		}

	}
	else
	{
		print "NO SUCH FILE: ".$csv_file."\n";
	}
}

if ( $do_zip ) {
	my $status = $zip->writeToFileNamed($zipfile_name);
	print "ZIP archive $zipfile_name closed\n";
	exit $status;
}