Issues (4)

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.

classes/condition.php (2 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
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 36 and the first side effect is on line 27.

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
 * Date condition.
19
 *
20
 * @package availability_maxviews
21
 * @copyright 2015 Daniel Neis Araujo
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
25
namespace availability_maxviews;
26
27
defined('MOODLE_INTERNAL') || die();
28
29
/**
30
 * maxviews condition.
31
 *
32
 * @package availability_maxviews
33
 * @copyright 2014 The Open University
34
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class condition extends \core_availability\condition {
37
38
    protected $viewslimit;
39
40
    /**
41
     * Constructor.
42
     *
43
     * @param \stdClass $structure Data structure from JSON decode
44
     * @throws \coding_exception If invalid data structure.
45
     */
46
    public function __construct($structure) {
47
        $this->viewslimit = $structure->viewslimit;
48
    }
49
50
    /**
51
     * Create object to be saved representing this condition.
52
     */
53
    public function save() {
54
        return (object)array('type' => 'maxviews', 'viewslimit' => $this->viewslimit);
55
    }
56
57
    /**
58
     * Returns a JSON object which corresponds to a condition of this type.
59
     *
60
     * Intended for unit testing, as normally the JSON values are constructed
61
     * by JavaScript code.
62
     *
63
     * @param int $viewslimit The limit of views for users
64
     * @return stdClass Object representing condition
65
     */
66
    public static function get_json($viewslimit = 5) {
67
        return (object)array('type' => 'maxviews', 'viewslimit' => (int)$viewslimit);
68
    }
69
70
    /**
71
     * Determines whether a particular item is currently available
72
     * according to this availability condition.
73
     *
74
     * @param bool $not Set true if we are inverting the condition
75
     * @param info $info Item we're checking
76
     * @param bool $grabthelot Performance hint: if true, caches information
77
     *   required for all course-modules, to make the front page and similar
78
     *   pages work more quickly (works only for current user)
79
     * @param int $userid User ID to check availability for
80
     * @return bool True if available
81
     */
82
    public function is_available($not, \core_availability\info $info, $grabthelot, $userid) {
83
        $logmanager = get_log_manager();
84
        if (!$readers = $logmanager->get_readers('core\log\sql_reader')) {
85
            // Should be using 2.8, use old class.
86
            $readers = $logmanager->get_readers('core\log\sql_select_reader');
87
        }
88
        $reader = array_pop($readers);
89
        $context = $info->get_context();
90
        $viewscount = $reader->get_events_select_count('contextid = :context AND userid = :userid AND crud = :crud',
91
                                                  array('context' => $context->id, 'userid' => $userid, 'crud' => 'r'));
92
        $allow = ($viewscount < $this->viewslimit);
93
        if ($not) {
94
            $allow = !$allow;
95
        }
96
        return $allow;
97
    }
98
99
    /**
100
     * Obtains a string describing this restriction (whether or not
101
     * it actually applies).
102
     *
103
     * @param bool $full Set true if this is the 'full information' view
104
     * @param bool $not Set true if we are inverting the condition
105
     * @param info $info Item we're checking
106
     * @return string Information string (for admin) about all restrictions on
107
     *   this item
108
     */
109
    public function get_description($full, $not, \core_availability\info $info) {
110
        global $USER;
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...
111
112
        $logmanager = get_log_manager();
113
        if (!$readers = $logmanager->get_readers('core\log\sql_reader')) {
114
            // Should be using 2.8, use old class.
115
            $readers = $logmanager->get_readers('core\log\sql_select_reader');
116
        }
117
        $reader = array_pop($readers);
118
        $context = $info->get_context();
119
        $viewscount = $reader->get_events_select_count('contextid = :context AND userid = :userid AND crud = :crud',
120
                                                  array('context' => $context->id, 'userid' => $USER->id, 'crud' => 'r'));
121
122
        $a = new \stdclass();
123
        $a->viewslimit = $this->viewslimit;
124
        $a->viewscount = $viewscount;
125
126
        if ($not) {
127
            return get_string('eithernotdescription', 'availability_maxviews', $a);
128
        } else {
129
            return get_string('eitherdescription', 'availability_maxviews', $a);
130
        }
131
    }
132
133
    /**
134
     * Obtains a representation of the options of this condition as a string,
135
     * for debugging.
136
     *
137
     * @return string Text representation of parameters
138
     */
139
    protected function get_debug_string() {
140
        return gmdate('Y-m-d H:i:s');
141
    }
142
}
143