Issues (789)

Security Analysis    not enabled

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

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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.

app/services/Emailer.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Services;
4
5
use App\Models\SettingsModel;
6
use Nette\Mail\IMailer;
7
use Nette\Mail\Message;
8
use Tracy\Debugger;
9
10
/**
11
 * Emailer
12
 *
13
 * Class for hadling and sending e-mails
14
 *
15
 * @created 2011-09-16
16
 * @author Tomas Litera <[email protected]>
17
 */
18 1
class Emailer
19
{
20
	/** @var SmtpMailer */
21
	private $mailer;
22
23
	/** @var SettingsModel */
24
	private $settings;
25
26
	/* Constructor */
27
	public function __construct(SettingsModel $settings, IMailer $mailer)
28
	{
29 1
		$this->mailer = $mailer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mailer of type object<Nette\Mail\IMailer> is incompatible with the declared type object<App\Services\SmtpMailer> of property $mailer.

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...
30 1
		$this->settings = $settings;
31 1
	}
32
33
	/**
34
	 * Send an e-mail to recipient
35
	 *
36
	 * @param	array	recipient e-mail and name
37
	 * @param	string	subject
38
	 * @param	string	message
39
	 * @param	array	bcc
40
	 * @return	bool	true | false (log the exception)
41
	 */
42
	public function sendMail($recipients, $subject, $body, array $bccMail = NULL)
43
	{
44 1
		$message = new Message;
45 1
		$message->setFrom('[email protected]', 'Srazy VS');
46
47 1
		foreach($recipients as $recipient) {
48 1
			$message->addTo(
49 1
			    $recipient->email,
50 1
                trim($recipient->name . ' ' . $recipient->surname)
51
            );
52
		}
53
		// add bcc
54 1
		if(!empty($bccMail)) {
55 1
			foreach ($bccMail as $bccMail => $bccName) {
0 ignored issues
show
The expression $bccMail of type integer|string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
56 1
				$message->addBcc($bccMail, $bccName);
57
			}
58
		}
59
		// create subject
60 1
		$message->subject = $subject;
61
		// create HTML body
62 1
		$message->htmlBody = $body;
63
		// create alternative message without HTML tags
64 1
		$message->body = strip_tags($body);
65
		// sending e-mail or error status
66
		try {
67 1
			$this->mailer->send($message);
68 1
			return true;
69
		} catch(Exception $e) {
0 ignored issues
show
The class App\Services\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
70
			Debugger::log($e, 'error');
71
			return false;
72
		}
73
	}
74
75
	/**
76
	 * Get e-mail template from settings
77
	 *
78
	 * @param	string	type of template
79
	 * @return	array	subject and message
80
	 */
81
	public function getTemplate($type)
82
	{
83 1
		$json = $this->settings->getMailJSON($type);
84
85 1
		$subject = html_entity_decode($json->subject);
86 1
		$message = html_entity_decode($json->message);
87
88
		return array(
89 1
			'subject' => $subject,
90 1
			'message' => $message,
91
		);
92
	}
93
94
	/**
95
	 * Sends an e-mail to lecture master
96
	 *
97
	 * @param	array	recipient mail and name
98
	 * @param	string	guid
99
	 * @param	string	program | block
100
	 * @return	mixed	true | error information
101
	 */
102
	public function tutor($recipients, $guid, $type)
103
	{
104 1
		$lang['block']['cs'] = "bloku";
0 ignored issues
show
Coding Style Comprehensibility introduced by
$lang was never initialized. Although not strictly required by PHP, it is generally a good practice to add $lang = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
105 1
		$lang['program']['cs'] = "programu";
106
107 1
		$tutorFormUrl = PRJ_DIR . "annotation/edit/{$type}/{$guid}";
108
109
		// e-mail templates
110 1
		$template = $this->getTemplate('tutor');
111 1
		$subject = $template['subject'];
112 1
		$message = $template['message'];
113
114
		// replacing text variables
115 1
		$subject = preg_replace('/%%\[typ-anotace\]%%/', $lang[$type]['cs'], $subject);
116 1
		$message = preg_replace('/%%\[typ-anotace\]%%/', $lang[$type]['cs'], $message);
117 1
		$message = preg_replace('/%%\[url-formulare\]%%/', $tutorFormUrl, $message);
118
119
		// send it
120 1
		return $this->sendMail($recipients, $subject, $message);
121
	}
122
123
	/**
124
	 * Sends an after registration summary e-mail to visitor
125
	 *
126
	 * @param	array	recipient mail
127
	 * @param	int		check hash code
128
	 * @param	string	code for recognition of bank transaction
129
	 * @return	mixed	true | error information
130
	 */
131
	public function sendRegistrationSummary(array $recipientMail, $hash, $code4bank)
132
	{
133
		// e-mail templates
134 1
		$template = $this->getTemplate('post_reg');
135 1
		$subject = $template['subject'];
136 1
		$message = $template['message'];
137
138
		// replacing text variables
139 1
		$message = preg_replace('/%%\[kontrolni-hash\]%%/', $hash, $message);
140 1
		$message = preg_replace('/%%\[variabilni-symbol\]%%/', $code4bank, $message);
141
142
		// send it
143 1
		return $this->sendMail($recipientMail, $subject, $message);
144
	}
145
146
	/**
147
	 * Get e-mail templates from settings
148
	 *
149
	 * @param	mixed	id numbers in row
150
	 * @param	string	type of template
151
	 * @return	array	subject and message
152
	 */
153
	public function sendPaymentInfo($recipients, $type)
154
	{
155
		// e-mail templates
156 1
		$template = $this->getTemplate($type);
157 1
		$subject = $template['subject'];
158 1
		$message = $template['message'];
159
160 1
		return $this->sendMail($recipients, $subject, $message);
161
	}
162
}
163