Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved PDF export and made LDAP compatible to anonymous bind #140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions find.load.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,21 @@ function(event, ui) {
}
}
});

function focusFind() {
var x = $("input[type=\'text\']")[1];
if (typeof x === "undefined") {
setTimeout('focusFind()',100);
return;
}

if ($(x).is(":focus") === false) {
console.log("hat keinen fokus, setze fokus");
x.focus();
}
}

$(document).ready(function() {
focusFind();
});
</script>
6 changes: 5 additions & 1 deletion home.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,18 @@
</div>
</div>';

//Print out the items
// Data Export (PDF/CSV)
echo '
<div>
<div id="div_print_out" style="display:none;padding:4px;">
<div style="height:20px;text-align:center;margin:2px;" id="print_out_error" class=""></div>

<label for="selected_folders" class="form_label">'.$txt['select_folders'].' :</label>
<select id="selected_folders" multiple size="7" class="text ui-widget-content ui-corner-all" style="padding:10px;"></select>
<br />
<br />
<label for="pdf_password" class="form_label">'.$txt['pdf_password'].' :</label>
<input type="password" id="pdf_password" name="pdf_password" />

<div class="div_radio" stle="text-align:center;">
<input type="radio" id="export_format_radio1" name="export_format" value="pdf" /><label for="export_format_radio1">'.$txt['pdf'].'</label>
Expand Down
5 changes: 4 additions & 1 deletion includes/language/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@
$txt['pdf_del_date'] = "PDF generated the";
$txt['pdf_del_title'] = "Passwords renewal follow-up";
$txt['pdf_download'] = "Download file";
$txt['pdf_export'] = "PDF exports";
$txt['pdf_password'] = "PDF encryption key";
$txt['pdf_password_warning'] = "You must provide an encryption key!";
$txt['personal_folder'] = "Personal folder";
$txt['personal_saltkey_change_button'] = "Change it!";
$txt['personal_salt_key'] = "Your personal salt key";
Expand All @@ -437,7 +440,7 @@
$txt['print'] = "Print";
$txt['print_out_menu_title'] = "Print out a listing of your items";
$txt['print_out_pdf_title'] = "TeamPass - List of exported Items";
$txt['print_out_warning'] = "All passwords and all confidential data will be written in this file without any encryption! By writing the file containing unencrypted items/passwords, you are accepting the full responsibility for further protection of this list!";
$txt['print_out_warning'] = "By writing the file containing unencrypted items/passwords, you are accepting the full responsibility for further protection of this list! Your PDF export will be logged.";
$txt['pw'] = "Password";
$txt['pw_change'] = "Change the account's password";
$txt['pw_changed'] = "Password changed!";
Expand Down
Binary file not shown.
23 changes: 23 additions & 0 deletions includes/libraries/tfpdf/font/liberationmono.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
$type = 'TrueType';
$name = 'LiberationMono';
$desc = array('Ascent'=>613,'Descent'=>-188,'CapHeight'=>659,'Flags'=>33,'FontBBox'=>'[-24 -300 609 833]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>600);
$up = -233;
$ut = 41;
$cw = array(
chr(0)=>600,chr(1)=>600,chr(2)=>600,chr(3)=>600,chr(4)=>600,chr(5)=>600,chr(6)=>600,chr(7)=>600,chr(8)=>600,chr(9)=>600,chr(10)=>600,chr(11)=>600,chr(12)=>600,chr(13)=>600,chr(14)=>600,chr(15)=>600,chr(16)=>600,chr(17)=>600,chr(18)=>600,chr(19)=>600,chr(20)=>600,chr(21)=>600,
chr(22)=>600,chr(23)=>600,chr(24)=>600,chr(25)=>600,chr(26)=>600,chr(27)=>600,chr(28)=>600,chr(29)=>600,chr(30)=>600,chr(31)=>600,' '=>600,'!'=>600,'"'=>600,'#'=>600,'$'=>600,'%'=>600,'&'=>600,'\''=>600,'('=>600,')'=>600,'*'=>600,'+'=>600,
','=>600,'-'=>600,'.'=>600,'/'=>600,'0'=>600,'1'=>600,'2'=>600,'3'=>600,'4'=>600,'5'=>600,'6'=>600,'7'=>600,'8'=>600,'9'=>600,':'=>600,';'=>600,'<'=>600,'='=>600,'>'=>600,'?'=>600,'@'=>600,'A'=>600,
'B'=>600,'C'=>600,'D'=>600,'E'=>600,'F'=>600,'G'=>600,'H'=>600,'I'=>600,'J'=>600,'K'=>600,'L'=>600,'M'=>600,'N'=>600,'O'=>600,'P'=>600,'Q'=>600,'R'=>600,'S'=>600,'T'=>600,'U'=>600,'V'=>600,'W'=>600,
'X'=>600,'Y'=>600,'Z'=>600,'['=>600,'\\'=>600,']'=>600,'^'=>600,'_'=>600,'`'=>600,'a'=>600,'b'=>600,'c'=>600,'d'=>600,'e'=>600,'f'=>600,'g'=>600,'h'=>600,'i'=>600,'j'=>600,'k'=>600,'l'=>600,'m'=>600,
'n'=>600,'o'=>600,'p'=>600,'q'=>600,'r'=>600,'s'=>600,'t'=>600,'u'=>600,'v'=>600,'w'=>600,'x'=>600,'y'=>600,'z'=>600,'{'=>600,'|'=>600,'}'=>600,'~'=>600,chr(127)=>600,chr(128)=>600,chr(129)=>600,chr(130)=>600,chr(131)=>600,
chr(132)=>600,chr(133)=>600,chr(134)=>600,chr(135)=>600,chr(136)=>600,chr(137)=>600,chr(138)=>600,chr(139)=>600,chr(140)=>600,chr(141)=>600,chr(142)=>600,chr(143)=>600,chr(144)=>600,chr(145)=>600,chr(146)=>600,chr(147)=>600,chr(148)=>600,chr(149)=>600,chr(150)=>600,chr(151)=>600,chr(152)=>600,chr(153)=>600,
chr(154)=>600,chr(155)=>600,chr(156)=>600,chr(157)=>600,chr(158)=>600,chr(159)=>600,chr(160)=>600,chr(161)=>600,chr(162)=>600,chr(163)=>600,chr(164)=>600,chr(165)=>600,chr(166)=>600,chr(167)=>600,chr(168)=>600,chr(169)=>600,chr(170)=>600,chr(171)=>600,chr(172)=>600,chr(173)=>600,chr(174)=>600,chr(175)=>600,
chr(176)=>600,chr(177)=>600,chr(178)=>600,chr(179)=>600,chr(180)=>600,chr(181)=>600,chr(182)=>600,chr(183)=>600,chr(184)=>600,chr(185)=>600,chr(186)=>600,chr(187)=>600,chr(188)=>600,chr(189)=>600,chr(190)=>600,chr(191)=>600,chr(192)=>600,chr(193)=>600,chr(194)=>600,chr(195)=>600,chr(196)=>600,chr(197)=>600,
chr(198)=>600,chr(199)=>600,chr(200)=>600,chr(201)=>600,chr(202)=>600,chr(203)=>600,chr(204)=>600,chr(205)=>600,chr(206)=>600,chr(207)=>600,chr(208)=>600,chr(209)=>600,chr(210)=>600,chr(211)=>600,chr(212)=>600,chr(213)=>600,chr(214)=>600,chr(215)=>600,chr(216)=>600,chr(217)=>600,chr(218)=>600,chr(219)=>600,
chr(220)=>600,chr(221)=>600,chr(222)=>600,chr(223)=>600,chr(224)=>600,chr(225)=>600,chr(226)=>600,chr(227)=>600,chr(228)=>600,chr(229)=>600,chr(230)=>600,chr(231)=>600,chr(232)=>600,chr(233)=>600,chr(234)=>600,chr(235)=>600,chr(236)=>600,chr(237)=>600,chr(238)=>600,chr(239)=>600,chr(240)=>600,chr(241)=>600,
chr(242)=>600,chr(243)=>600,chr(244)=>600,chr(245)=>600,chr(246)=>600,chr(247)=>600,chr(248)=>600,chr(249)=>600,chr(250)=>600,chr(251)=>600,chr(252)=>600,chr(253)=>600,chr(254)=>600,chr(255)=>600);
$enc = 'cp1252';
$file = 'LiberationMono-Regular.z';
$originalsize = 108168;
?>
Binary file added includes/libraries/tfpdf/font/liberationmono.ttf
Binary file not shown.
206 changes: 206 additions & 0 deletions includes/libraries/tfpdf/fpdf_protection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php
/****************************************************************************
* Software: FPDF_Protection *
* Version: 1.03 *
* Date: 2009-11-29 *
* Author: Klemen VODOPIVEC *
* License: FPDF *
* *
* Thanks: Cpdf (http://www.ros.co.nz/pdf) was my working sample of how to *
* implement protection in pdf. *
****************************************************************************/

require('tfpdf.php');

if(function_exists('mcrypt_encrypt'))
{
function RC4($key, $data)
{
return mcrypt_encrypt(MCRYPT_ARCFOUR, $key, $data, MCRYPT_MODE_STREAM, '');
}
}
else
{
function RC4($key, $data)
{
static $last_key, $last_state;

if($key != $last_key)
{
$k = str_repeat($key, 256/strlen($key)+1);
$state = range(0, 255);
$j = 0;
for ($i=0; $i<256; $i++){
$t = $state[$i];
$j = ($j + $t + ord($k[$i])) % 256;
$state[$i] = $state[$j];
$state[$j] = $t;
}
$last_key = $key;
$last_state = $state;
}
else
$state = $last_state;

$len = strlen($data);
$a = 0;
$b = 0;
$out = '';
for ($i=0; $i<$len; $i++){
$a = ($a+1) % 256;
$t = $state[$a];
$b = ($b+$t) % 256;
$state[$a] = $state[$b];
$state[$b] = $t;
$k = $state[($state[$a]+$state[$b]) % 256];
$out .= chr(ord($data[$i]) ^ $k);
}
return $out;
}
}

class FPDF_Protection extends tFPDF
{
var $encrypted = false; //whether document is protected
var $Uvalue; //U entry in pdf document
var $Ovalue; //O entry in pdf document
var $Pvalue; //P entry in pdf document
var $enc_obj_id; //encryption object id

/**
* Function to set permissions as well as user and owner passwords
*
* - permissions is an array with values taken from the following list:
* copy, print, modify, annot-forms
* If a value is present it means that the permission is granted
* - If a user password is set, user will be prompted before document is opened
* - If an owner password is set, document can be opened in privilege mode with no
* restriction if that password is entered
*/
function SetProtection($permissions=array(), $user_pass='', $owner_pass=null)
{
$options = array('print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 );
$protection = 192;
foreach($permissions as $permission)
{
if (!isset($options[$permission]))
$this->Error('Incorrect permission: '.$permission);
$protection += $options[$permission];
}
if ($owner_pass === null)
$owner_pass = uniqid(rand());
$this->encrypted = true;
$this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08".
"\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A";
$this->_generateencryptionkey($user_pass, $owner_pass, $protection);
}

/****************************************************************************
* *
* Private methods *
* *
****************************************************************************/

function _putstream($s)
{
if ($this->encrypted) {
$s = RC4($this->_objectkey($this->n), $s);
}
parent::_putstream($s);
}

function _textstring($s)
{
if ($this->encrypted) {
$s = RC4($this->_objectkey($this->n), $s);
}
return parent::_textstring($s);
}

/**
* Compute key depending on object number where the encrypted data is stored
*/
function _objectkey($n)
{
return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,10);
}

function _putresources()
{
parent::_putresources();
if ($this->encrypted) {
$this->_newobj();
$this->enc_obj_id = $this->n;
$this->_out('<<');
$this->_putencryption();
$this->_out('>>');
$this->_out('endobj');
}
}

function _putencryption()
{
$this->_out('/Filter /Standard');
$this->_out('/V 1');
$this->_out('/R 2');
$this->_out('/O ('.$this->_escape($this->Ovalue).')');
$this->_out('/U ('.$this->_escape($this->Uvalue).')');
$this->_out('/P '.$this->Pvalue);
}

function _puttrailer()
{
parent::_puttrailer();
if ($this->encrypted) {
$this->_out('/Encrypt '.$this->enc_obj_id.' 0 R');
$this->_out('/ID [()()]');
}
}

/**
* Get MD5 as binary string
*/
function _md5_16($string)
{
return pack('H*',md5($string));
}

/**
* Compute O value
*/
function _Ovalue($user_pass, $owner_pass)
{
$tmp = $this->_md5_16($owner_pass);
$owner_RC4_key = substr($tmp,0,5);
return RC4($owner_RC4_key, $user_pass);
}

/**
* Compute U value
*/
function _Uvalue()
{
return RC4($this->encryption_key, $this->padding);
}

/**
* Compute encryption key
*/
function _generateencryptionkey($user_pass, $owner_pass, $protection)
{
// Pad passwords
$user_pass = substr($user_pass.$this->padding,0,32);
$owner_pass = substr($owner_pass.$this->padding,0,32);
// Compute O value
$this->Ovalue = $this->_Ovalue($user_pass,$owner_pass);
// Compute encyption key
$tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF");
$this->encryption_key = substr($tmp,0,5);
// Compute U value
$this->Uvalue = $this->_Uvalue();
// Compute P value
$this->Pvalue = -(($protection^255)+1);
}
}

?>
12 changes: 10 additions & 2 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,21 @@ function(data){
});
$("#div_loading").show();

// Get PDF encryption password and make sure it is set
pdf_password = $("#pdf_password").val();
if ((pdf_password == "") && ($("input[name=\"export_format\"]:checked").val() == "pdf")) {
alert("'.$txt['pdf_password_warning'].'");
return;
}

//Send query
$.post(
"sources/export.queries.php",
{
type : $("input[name=\"export_format\"]:checked").val() == "pdf" ? "export_to_pdf_format" : "export_to_csv_format",
ids : ids
},
ids : ids,
pdf_password : pdf_password
},
function(data){
$("#download_link").html(data[0].text);
$("#div_loading").hide();
Expand Down
Loading