Issues (37)

Security Analysis    no request data  

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.

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 35 and the first side effect is on line 28.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * pagseguro enrolment plugin.
19
 *
20
 * This plugin allows you to set up paid courses.
21
 *
22
 * @package    enrol
23
 * @subpackage pagseguro
24
 * @copyright  2010 Eugene Venter
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
28
defined('MOODLE_INTERNAL') || die();
29
30
/**
31
 * pagseguro enrolment plugin implementation.
32
 * @author  Eugene Venter - based on code by Martin Dougiamas and others
33
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class enrol_pagseguro_plugin extends enrol_plugin {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
36
37
    /**
38
     * Returns optional enrolment information icons.
39
     *
40
     * This is used in course list for quick overview of enrolment options.
41
     *
42
     * We are not using single instance parameter because sometimes
43
     * we might want to prevent icon repetition when multiple instances
44
     * of one type exist. One instance may also produce several icons.
45
     *
46
     * @param array $instances all enrol instances of this type in one course
47
     * @return array of pix_icon
48
     */
49
    public function get_info_icons(array $instances) {
50
        return array(new pix_icon('icon', get_string('pluginname', 'enrol_pagseguro'), 'enrol_pagseguro'));
51
    }
52
53
    public function roles_protected() {
54
        return false;
55
    }
56
57
    public function allow_unenrol(stdClass $instance) {
58
        return true;
59
    }
60
61
    public function allow_manage(stdClass $instance) {
62
        return true;
63
    }
64
65
    public function show_enrolme_link(stdClass $instance) {
66
        return ($instance->status == ENROL_INSTANCE_ENABLED);
67
    }
68
69
    /**
70
     * Sets up navigation entries.
71
     *
72
     * @param object $instance
73
     * @return void
74
     */
75
    public function add_course_navigation($instancesnode, stdClass $instance) {
76
        if ($instance->enrol !== 'pagseguro') {
77
             throw new coding_exception('Invalid enrol instance type!');
78
        }
79
80
        $context = context_course::instance($instance->courseid);
81
        if (has_capability('enrol/pagseguro:config', $context)) {
82
            $managelink = new moodle_url('/enrol/pagseguro/edit.php', array('courseid' => $instance->courseid, 'id' => $instance->id));
83
            $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
84
        }
85
    }
86
87
    /**
88
     * Returns edit icons for the page with list of instances
89
     * @param stdClass $instance
90
     * @return array
91
     */
92
    public function get_action_icons(stdClass $instance) {
93
        global $OUTPUT;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
94
95
        if ($instance->enrol !== 'pagseguro') {
96
            throw new coding_exception('invalid enrol instance!');
97
        }
98
        $context = context_course::instance($instance->courseid);
99
100
        $icons = array();
101
102
        if (has_capability('enrol/pagseguro:config', $context)) {
103
            $editlink = new moodle_url("/enrol/pagseguro/edit.php", array('courseid' => $instance->courseid, 'id' => $instance->id));
104
            $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'icon')));
105
        }
106
107
        return $icons;
108
    }
109
110
    /**
111
     * Returns link to page which may be used to add new instance of enrolment plugin in course.
112
     * @param int $courseid
113
     * @return moodle_url page url
114
     */
115
    public function get_newinstance_link($courseid) {
116
        $context = context_course::instance($courseid);
117
118
        if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/pagseguro:config', $context)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
119
            return null;
120
        }
121
122
        return new moodle_url('/enrol/pagseguro/edit.php', array('courseid' => $courseid));
123
    }
124
125
    /**
126
     * Creates course enrol form, checks if form submitted
127
     * and enrols user if necessary. It can also redirect.
128
     *
129
     * @param stdClass $instance
130
     * @return string html text, usually a form in a text box
131
     */
132
    public function enrol_page_hook(stdClass $instance) {
133
        global $CFG, $USER, $OUTPUT, $PAGE, $DB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
134
135
        ob_start();
136
137
        if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
138
            return ob_get_clean();
139
        }
140
141
        if ($instance->enrolstartdate != 0 && $instance->enrolstartdate > time()) {
142
            return ob_get_clean();
143
        }
144
145
        if ($instance->enrolenddate != 0 && $instance->enrolenddate < time()) {
146
            return ob_get_clean();
147
        }
148
149
        $course = $DB->get_record('course', array('id' => $instance->courseid));
150
        $context = context_course::instance($instance->courseid);
151
152
        $shortname = format_string($course->shortname, true, array('context' => $context));
153
        $strloginto = get_string("loginto", "", $shortname);
0 ignored issues
show
$strloginto is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
154
        $strcourses = get_string("courses");
0 ignored issues
show
$strcourses is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
155
156
        // Pass $view=true to filter hidden caps if the user cannot see them.
157 View Code Duplication
        if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC',
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
                                             '', '', '', '', false, true)) {
159
            $users = sort_by_roleassignment_authority($users, $context);
160
            $teacher = array_shift($users);
0 ignored issues
show
$teacher is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
161
        } else {
162
            $teacher = false;
0 ignored issues
show
$teacher is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
163
        }
164
165
        if ( (float) $instance->cost <= 0 ) {
166
            $cost = (float) $this->get_config('cost');
167
        } else {
168
            $cost = (float) $instance->cost;
169
        }
170
171
        if (abs($cost) < 0.01) { // No cost, other enrolment methods (instances) should be used.
172
            echo '<p>'.get_string('nocost', 'enrol_pagseguro').'</p>';
173
        } else {
174
175
            if (isguestuser()) { // Force login only for guest user, not real users with guest role.
176
                if (empty($CFG->loginhttps)) {
177
                    $wwwroot = $CFG->wwwroot;
178
                } else {
179
                    // This actually is not so secure ;-), 'cause we're in unencrypted connection...
180
                    $wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
181
                }
182
                echo '<div class="mdl-align"><p>'.get_string('paymentrequired').'</p>';
183
                echo '<p><b>'.get_string('cost').": $instance->currency $cost".'</b></p>';
184
                echo '<p><a href="'.$wwwroot.'/login/">'.get_string('loginsite').'</a></p>';
185
                echo '</div>';
186
            } else {
187
                require_once("$CFG->dirroot/enrol/pagseguro/locallib.php");
188
                // Sanitise some fields before building the pagseguro form.
189
                $coursefullname  = format_string($course->fullname, true, array('context' => $context));
0 ignored issues
show
$coursefullname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
                $courseshortname = $shortname;
0 ignored issues
show
$courseshortname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
191
                $userfullname    = fullname($USER);
0 ignored issues
show
$userfullname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
192
                $userfirstname   = $USER->firstname;
0 ignored issues
show
$userfirstname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
193
                $userlastname    = $USER->lastname;
0 ignored issues
show
$userlastname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
194
                $useraddress     = $USER->address;
0 ignored issues
show
$useraddress is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
195
                $usercity        = $USER->city;
0 ignored issues
show
$usercity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
196
                $instancename    = $this->get_instance_name($instance);
0 ignored issues
show
$instancename is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
197
198
                $form = new enrol_pagseguro_enrol_form($CFG->wwwroot.'/enrol/pagseguro/process.php', $instance);
199
200
                ob_start();
201
                $form->display();
202
                $output = ob_get_clean();
203
                return $OUTPUT->box($output);
204
            }
205
206
        }
207
208
        return $OUTPUT->box(ob_get_clean());
209
    }
210
211
    /**
212
     * Is it possible to delete enrol instance via standard UI?
213
     *
214
     * @param stdClass $instance
215
     * @return bool
216
     */
217
    public function can_delete_instance($instance) {
218
        $context = context_course::instance($instance->courseid);
219
        return has_capability('enrol/self:config', $context);
220
    }
221
222
    /**
223
     * Is it possible to hide/show enrol instance via standard UI?
224
     *
225
     * @param stdClass $instance
226
     * @return bool
227
     */
228
    public function can_hide_show_instance($instance) {
229
        $context = context_course::instance($instance->courseid);
230
        return has_capability('enrol/pagseguro:config', $context);
231
    }
232
233
}
234