Issues (982)

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.

lib/Page.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
 * COPS (Calibre OPDS PHP Server) class file
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Sébastien Lucas <[email protected]>
7
 */
8
9
class Page
10
{
11
    public $title;
12
    public $subtitle = "";
13
    public $authorName = "";
14
    public $authorUri = "";
15
    public $authorEmail = "";
16
    public $idPage;
17
    public $idGet;
18
    public $query;
19
    public $favicon;
20
    public $n;
21
    public $book;
22
    public $totalNumber = -1;
23
24
    /* @var Entry[] */
25
    public $entryArray = array();
26
27 102
    public static function getPage ($pageId, $id, $query, $n)
28
    {
29
        switch ($pageId) {
30 102
            case Base::PAGE_ALL_AUTHORS :
31 3
                return new PageAllAuthors ($id, $query, $n);
32 99
            case Base::PAGE_AUTHORS_FIRST_LETTER :
33 1
                return new PageAllAuthorsLetter ($id, $query, $n);
34 98
            case Base::PAGE_AUTHOR_DETAIL :
35 7
                return new PageAuthorDetail ($id, $query, $n);
36 91
            case Base::PAGE_ALL_TAGS :
37 2
                return new PageAllTags ($id, $query, $n);
38 89
            case Base::PAGE_TAG_DETAIL :
39 1
                return new PageTagDetail ($id, $query, $n);
40 88
            case Base::PAGE_ALL_LANGUAGES :
41 2
                return new PageAllLanguages ($id, $query, $n);
42 86
            case Base::PAGE_LANGUAGE_DETAIL :
43 1
                return new PageLanguageDetail ($id, $query, $n);
44 85
            case Base::PAGE_ALL_CUSTOMS :
45 12
                return new PageAllCustoms ($id, $query, $n);
46 73
            case Base::PAGE_CUSTOM_DETAIL :
47 4
                return new PageCustomDetail ($id, $query, $n);
48 69
            case Base::PAGE_ALL_RATINGS :
49 1
                return new PageAllRating ($id, $query, $n);
50 68
            case Base::PAGE_RATING_DETAIL :
51 1
                return new PageRatingDetail ($id, $query, $n);
52 67
            case Base::PAGE_ALL_SERIES :
53 2
                return new PageAllSeries ($id, $query, $n);
54 65
            case Base::PAGE_ALL_BOOKS :
55 3
                return new PageAllBooks ($id, $query, $n);
56 62
            case Base::PAGE_ALL_BOOKS_LETTER:
57 1
                return new PageAllBooksLetter ($id, $query, $n);
58 61
            case Base::PAGE_ALL_RECENT_BOOKS :
59 4
                return new PageRecentBooks ($id, $query, $n);
60 57
            case Base::PAGE_SERIE_DETAIL :
61 1
                return new PageSerieDetail ($id, $query, $n);
62 56
            case Base::PAGE_OPENSEARCH_QUERY :
63 31
                return new PageQueryResult ($id, $query, $n);
64 25
            case Base::PAGE_BOOK_DETAIL :
65 1
                return new PageBookDetail ($id, $query, $n);
66 24
            case Base::PAGE_ALL_PUBLISHERS:
67 2
                return new PageAllPublishers ($id, $query, $n);
68 22
            case Base::PAGE_PUBLISHER_DETAIL :
69 1
                return new PagePublisherDetail ($id, $query, $n);
70 21
            case Base::PAGE_ABOUT :
71
                return new PageAbout ($id, $query, $n);
72 21
            case Base::PAGE_CUSTOMIZE :
73
                return new PageCustomize ($id, $query, $n);
74 21
            default:
75 21
                $page = new Page ($id, $query, $n);
76 21
                $page->idPage = "cops:catalog";
77 21
                return $page;
78 21
        }
79
    }
80
81 102
    public function __construct($pid, $pquery, $pn) {
82 102
        global $config;
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...
83
84 102
        $this->idGet = $pid;
85 102
        $this->query = $pquery;
86 102
        $this->n = $pn;
87 102
        $this->favicon = $config['cops_icon'];
88 102
        $this->authorName = empty($config['cops_author_name']) ? utf8_encode('Sébastien Lucas') : $config['cops_author_name'];
89 102
        $this->authorUri = empty($config['cops_author_uri']) ? 'http://blog.slucas.fr' : $config['cops_author_uri'];
90 102
        $this->authorEmail = empty($config['cops_author_email']) ? '[email protected]' : $config['cops_author_email'];
91 102
    }
92
93 21
    public function InitializeContent ()
94
    {
95 21
        global $config;
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...
96 21
        $this->title = $config['cops_title_default'];
97 21
        $this->subtitle = $config['cops_subtitle_default'];
98 21
        if (Base::noDatabaseSelected ()) {
99 2
            $i = 0;
100 2
            foreach (Base::getDbNameList () as $key) {
101 2
                $nBooks = Book::getBookCount ($i);
102 2
                array_push ($this->entryArray, new Entry ($key, "cops:{$i}:catalog",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $i instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
103 2
                                        str_format (localize ("bookword", $nBooks), $nBooks), "text",
104 2
                                        array ( new LinkNavigation ("?" . DB . "={$i}")), "", $nBooks));
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $i instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
105 2
                $i++;
106 2
                Base::clearDb ();
107 2
            }
108 2
        } else {
109 19
            if (!in_array (PageQueryResult::SCOPE_AUTHOR, getCurrentOption ('ignored_categories'))) {
110 18
                array_push ($this->entryArray, Author::getCount());
111 18
            }
112 19 View Code Duplication
            if (!in_array (PageQueryResult::SCOPE_SERIES, getCurrentOption ('ignored_categories'))) {
113 18
                $series = Serie::getCount();
114 18
                if (!is_null ($series)) array_push ($this->entryArray, $series);
115 18
            }
116 19 View Code Duplication
            if (!in_array (PageQueryResult::SCOPE_PUBLISHER, getCurrentOption ('ignored_categories'))) {
117 18
                $publisher = Publisher::getCount();
118 18
                if (!is_null ($publisher)) array_push ($this->entryArray, $publisher);
119 18
            }
120 19 View Code Duplication
            if (!in_array (PageQueryResult::SCOPE_TAG, getCurrentOption ('ignored_categories'))) {
121 18
                $tags = Tag::getCount();
122 18
                if (!is_null ($tags)) array_push ($this->entryArray, $tags);
123 18
            }
124 19 View Code Duplication
            if (!in_array (PageQueryResult::SCOPE_RATING, getCurrentOption ('ignored_categories'))) {
125 19
                $rating = Rating::getCount();
126 19
                if (!is_null ($rating)) array_push ($this->entryArray, $rating);
127 19
            }
128 19 View Code Duplication
            if (!in_array ("language", getCurrentOption ('ignored_categories'))) {
129 18
                $languages = Language::getCount();
130 18
                if (!is_null ($languages)) array_push ($this->entryArray, $languages);
131 18
            }
132 19
            foreach ($config['cops_calibre_custom_column'] as $lookup) {
133 15
                $customColumn = CustomColumnType::createByLookup($lookup);
134 15
                if (!is_null ($customColumn) && $customColumn->isSearchable()) {
135 14
                    array_push ($this->entryArray, $customColumn->getCount());
136 14
                }
137 19
            }
138 19
            $this->entryArray = array_merge ($this->entryArray, Book::getCount());
139
140 19
            if (Base::isMultipleDatabaseEnabled ()) $this->title =  Base::getDbName ();
141
        }
142 21
    }
143
144 17
    public function isPaginated ()
145
    {
146 17
        return (getCurrentOption ("max_item_per_page") != -1 &&
147 17
                $this->totalNumber != -1 &&
148 17
                $this->totalNumber > getCurrentOption ("max_item_per_page"));
149
    }
150
151 2 View Code Duplication
    public function getNextLink ()
152
    {
153 2
        $currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . getQueryString ());
154 2
        if (($this->n) * getCurrentOption ("max_item_per_page") < $this->totalNumber) {
155 1
            return new LinkNavigation ($currentUrl . "&n=" . ($this->n + 1), "next", localize ("paging.next.alternate"));
156
        }
157 1
        return NULL;
158
    }
159
160 2 View Code Duplication
    public function getPrevLink ()
161
    {
162 2
        $currentUrl = preg_replace ("/\&n=.*?$/", "", "?" . getQueryString ());
163 2
        if ($this->n > 1) {
164 1
            return new LinkNavigation ($currentUrl . "&n=" . ($this->n - 1), "previous", localize ("paging.previous.alternate"));
165
        }
166 2
        return NULL;
167
    }
168
169 2
    public function getMaxPage ()
170
    {
171 2
        return ceil ($this->totalNumber / getCurrentOption ("max_item_per_page"));
172
    }
173
174 70
    public function containsBook ()
175
    {
176 70
        if (count ($this->entryArray) == 0) return false;
177 68
        if (get_class ($this->entryArray [0]) == "EntryBook") return true;
178 46
        return false;
179
    }
180
}
181