Issues (519)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/Files/User/UserPdf.php (3 issues)

1
<?php namespace XoopsModules\Tdmcreate\Files\User;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tdmcreate module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: UserPdf.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class UserPdf.
30
 */
31
class UserPdf extends Files\CreateFile
32
{
33
    /**
34
     * @var mixed
35
     */
36
    private $uc = null;
37
38
    /**
39
     * @var string
40
     */
41
    private $xc = null;
42
43
    /**
44
     *  @public function constructor
45
     *  @param null
46
     */
47
    public function __construct()
48
    {
49
        parent::__construct();
50
        $this->xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Tdmcreate\F...oopsCode::getInstance() of type XoopsModules\Tdmcreate\Files\CreateXoopsCode is incompatible with the declared type string of property $xc.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
        $this->phpcode = Tdmcreate\Files\CreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like XoopsModules\Tdmcreate\F...ePhpCode::getInstance() of type XoopsModules\Tdmcreate\Files\CreatePhpCode is incompatible with the declared type string of property $phpcode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        $this->uc = UserXoopsCode::getInstance();
53
    }
54
55
    /**
56
     *  @static function getInstance
57
     *  @param null
58
     * @return UserPdf
59
     */
60
    public static function getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
67
        return $instance;
68
    }
69
70
    /**
71
     *  @public function write
72
     *  @param string $module
73
     *  @param mixed $table
74
     *  @param string $filename
75
     */
76
    public function write($module, $table, $filename)
77
    {
78
        $this->setModule($module);
79
        $this->setTable($table);
80
        $this->setFileName($filename);
81
    }
82
83
    /**
84
     * @private function getUserPagesHeader
85
     * @param $moduleDirname
86
     * @param $tableName
87
     * @param $fields
88
     * @param $language
89
     * @return string
90
     */
91
    private function getUserPdfHeader($moduleDirname, $tableName, $fields, $language)
92
    {
93
        $fieldId = $this->xc->getXcSaveFieldId($fields);
94
        $ccFieldId = $this->getCamelCase($fieldId, false, true);
95
        $ret = $this->getInclude();
96
        $fileExist = $this->phpcode->getPhpCodeFileExists("\$tcpdf = XOOPS_ROOT_PATH.'/Frameworks/tcpdf/tcpdf.php'");
97
        $requireOnce = $this->phpcode->getPhpCodeIncludeDir('$tcpdf', '', true, true, 'require', "\t");
98
        $ret .= $this->xc->getXcXoopsRequest($ccFieldId, $fieldId, '', 'Int');
99
        $redirectHeader = $this->xc->getXcRedirectHeader($tableName, '', $numb = '2', "{$language}NO_PDF_LIBRARY", true, "\t");
100
        $ret .= $this->phpcode->getPhpCodeConditions($fileExist, '', '', $requireOnce, $redirectHeader);
101
        $ret .= $this->phpcode->getPhpCodeCommentLine('Get Instance of Handler');
102
        $ret .= $this->xc->getXoopsHandlerLine($moduleDirname, $tableName);
103
        $ret .= $this->xc->getXcGetVar($tableName, 'this', $fieldId, false, '');
104
105
        return $ret;
106
    }
107
108
    /**
109
     *  @public function getAdminPagesList
110
     * @param $moduleDirname
111
     * @param $fields
112
     * @return string
113
     */
114
    public function getUserPdfTcpdf($moduleDirname, $fields)
115
    {
116
        $fieldId = $this->xc->getXcSaveFieldId($fields);
0 ignored issues
show
The assignment to $fieldId is dead and can be removed.
Loading history...
117
        $stuModuleDirname = mb_strtoupper($moduleDirname);
118
        $ret = '';
119
        foreach (array_keys($fields) as $f) {
120
            $fieldName = $fields[$f]->getVar('field_name');
121
            $fieldDefault = $fields[$f]->getVar('field_default');
122
            $fieldElement = $fields[$f]->getVar('field_element');
123
            $getVar = $this->xc->getXcGetVar('', 'pdfContent', $fieldName, true);
124
            switch ($fieldElement) {
125
                case 2:
126
                    if (false !== mb_strpos($fieldName, 'title') || false !== mb_strpos($fieldName, 'name') && '' == $fieldDefault) {
127
                        $ret .= $this->phpcode->getPhpCodeStripTags("pdfData['title']", $getVar);
128
                    }
129
                break;
130
                case 3:
131
                case 4:
132
                    $ret .= $this->phpcode->getPhpCodeStripTags("pdfData['content']", $getVar);
133
                break;
134
                case 8:
135
                    $ret .= $this->xc->getXcUnameFromId("pdfData['author']", $getVar);
136
                break;
137
                case 15:
138
                    $ret .= $this->xc->getXcFormatTimeStamp("pdfData['date']", $getVar);
139
                break;
140
            }
141
        }
142
        $ret .= $this->phpcode->getPhpCodeCommentLine('Get Config');
143
        $ret .= $this->xc->getXcEqualsOperator("\$pdfData['creator'] ", "\$GLOBALS['xoopsConfig']['xoops_sitename']");
144
        $ret .= $this->xc->getXcEqualsOperator("\$pdfData['subject'] ", "\$GLOBALS['xoopsConfig']['slogan']");
145
        $ret .= $this->xc->getXcEqualsOperator("\$pdfData['keywords'] ", "\$GLOBALS['xoopsConfig']['keywords']");
146
        $ret .= $this->phpcode->getPhpCodeCommentLine('Defines');
147
        $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_CREATOR", "\$pdfData['creator']");
148
        $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_AUTHOR", "\$pdfData['author']");
149
        $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_TITLE", "\$pdfData['title']");
150
        $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_STRING", "\$pdfData['subject']");
151
        $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_LOGO", "'logo.gif'");
152
        $ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_IMAGES_PATH", "XOOPS_ROOT_PATH.'/images/'");
153
        $ret .= $this->xc->getXcEqualsOperator('$myts', 'MyTextSanitizer::getInstance()', null, true);
154
        $ret .= $this->xc->getXcEqualsOperator('$content', "''");
155
        $ret .= $this->xc->getXcEqualsOperator('$content', "\$myts->undoHtmlSpecialChars(\$pdfData['content'])", '.');
156
        $ret .= $this->xc->getXcEqualsOperator('$content', '$myts->displayTarea($content)');
157
        $ret .= $this->xc->getXcEqualsOperator('$pdf', 'new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false)');
158
        $ret .= $this->xc->getXcEqualsOperator('$title', "\$myts->undoHtmlSpecialChars(\$pdfData['title'])");
159
        $ret .= $this->xc->getXcEqualsOperator('$keywords', "\$myts->undoHtmlSpecialChars(\$pdfData['keywords'])");
160
        $ret .= $this->xc->getXcEqualsOperator("\$pdfData['fontsize']", '12');
161
        $ret .= $this->phpcode->getPhpCodeCommentLine('For schinese');
162
        $ifLang = $this->getSimpleString("\$pdf->SetFont('gbsn00lp', '', \$pdfData['fontsize']);", "\t");
163
        $elseLang = $this->getSimpleString("\$pdf->SetFont(\$pdfData['fontname'], '', \$pdfData['fontsize']);", "\t");
164
        $ret .= $this->phpcode->getPhpCodeConditions('_LANGCODE', ' == ', "'cn'", $ifLang, $elseLang);
165
        $ret .= $this->phpcode->getPhpCodeCommentLine('Set document information');
166
        $ret .= $this->getSimpleString("\$pdf->SetCreator(\$pdfData['creator']);");
167
        $ret .= $this->getSimpleString("\$pdf->SetAuthor(\$pdfData['author']);");
168
        $ret .= $this->getSimpleString('$pdf->SetTitle($title);');
169
        $ret .= $this->getSimpleString('$pdf->SetKeywords($keywords);');
170
        $ret .= $this->phpcode->getPhpCodeCommentLine('Set default header data');
171
        $ret .= $this->getSimpleString("\$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, {$stuModuleDirname}_HEADER_TITLE, {$stuModuleDirname}_HEADER_STRING);");
172
        $ret .= $this->phpcode->getPhpCodeCommentLine('Set margins');
173
        $ret .= $this->getSimpleString('$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 10, PDF_MARGIN_RIGHT);');
174
        $ret .= $this->phpcode->getPhpCodeCommentLine('Set auto page breaks');
175
        $ret .= $this->getSimpleString('$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);');
176
        $ret .= $this->getSimpleString('$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);');
177
        $ret .= $this->getSimpleString('$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);');
178
        $ret .= $this->getSimpleString('$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor');
179
        $ifLang = $this->getSimpleString("\$pdf->setHeaderFont(array('gbsn00lp', '', \$pdfData['fontsize']));", "\t");
180
        $ifLang .= $this->getSimpleString("\$pdf->setFooterFont(array('gbsn00lp', '', \$pdfData['fontsize']));", "\t");
181
        $elseLang = $this->getSimpleString("\$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));", "\t");
182
        $elseLang .= $this->getSimpleString("\$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));", "\t");
183
        $ret .= $this->phpcode->getPhpCodeConditions('_LANGCODE', ' == ', "'cn'", $ifLang, $elseLang);
184
        $ret .= $this->phpcode->getPhpCodeCommentLine('Set some language-dependent strings (optional)');
185
        $fileExist = $this->phpcode->getPhpCodeFileExists("\$lang = XOOPS_ROOT_PATH.'/Frameworks/tcpdf/lang/eng.php'");
186
        $contIf = $this->phpcode->getPhpCodeIncludeDir('$lang', '', true, false, 'require', "\t");
187
        $contIf .= $this->getSimpleString('$pdf->setLanguageArray($l);', "\t");
188
        $ret .= $this->phpcode->getPhpCodeConditions("@{$fileExist}", '', '', $contIf);
189
190
        return $ret;
191
    }
192
193
    /**
194
     * @private function getUserPdfFooter
195
     *
196
     * @param $moduleDirname
197
     * @param $tableName
198
     *
199
     * @return string
200
     */
201
    private function getUserPdfFooter($moduleDirname, $tableName)
202
    {
203
        $ret = $this->phpcode->getPhpCodeCommentLine('Initialize document');
204
        $ret .= $this->getSimpleString('$pdf->AliasNbPages();');
205
        $ret .= $this->phpcode->getPhpCodeCommentLine('Add Page document');
206
        $ret .= $this->getSimpleString('$pdf->AddPage();');
207
        $ret .= $this->getSimpleString("\$pdf->writeHTMLCell(\$w=0, \$h=0, \$x='', \$y='', \$content, \$border=0, \$ln=1, \$fill=0, \$reseth=true, \$align='', \$autopadding=true);");
208
        $ret .= $this->phpcode->getPhpCodeCommentLine('Pdf Filename');
209
        $ret .= $this->phpcode->getPhpCodeCommentLine('Output');
210
        $ret .= $this->xc->getXcTplAssign('pdfoutput', "\$pdf->Output('{$tableName}.pdf', 'I')");
211
        $ret .= $this->xc->getXcTplDisplay($moduleDirname . '_pdf.tpl', '', false);
212
213
        return $ret;
214
    }
215
216
    /**
217
     *  @public function render
218
     *  @param null
219
     * @return bool|string
220
     */
221
    public function render()
222
    {
223
        $module = $this->getModule();
224
        $table = $this->getTable();
225
        $filename = $this->getFileName();
226
        $moduleDirname = $module->getVar('mod_dirname');
227
        $tableId = $table->getVar('table_id');
228
        $tableMid = $table->getVar('table_mid');
229
        $tableName = $table->getVar('table_name');
230
        $fields = $this->getTableFields($tableMid, $tableId);
231
        $language = $this->getLanguage($moduleDirname, 'MA');
232
        $content = $this->getHeaderFilesComments($module, $filename);
233
        $content .= $this->getUserPdfHeader($moduleDirname, $tableName, $fields, $language);
234
        $content .= $this->getUserPdfTcpdf($moduleDirname, $fields);
235
        $content .= $this->getUserPdfFooter($moduleDirname, $tableName);
236
237
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
238
239
        return $this->renderFile();
240
    }
241
}
242