Commit graph

91 commits

Author SHA1 Message Date
Lukas Fleischer
86e4cd0731 aurjson: use APCu/memcached for rate limiting
There's no need to use permanent storage for rate limiting information;
try to keep it in memory if caching is enabled.

From experiments with our live setup, this reduces the number of
INSERT/DELETE operations per second from 15 to almost 0. Disk writes on
the server hosting the AUR are reduced by 90% (from ~3MB/s to ~300kB/s).

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-11-02 18:32:07 -04:00
Lukas Fleischer
734527370d Make package details cache TTL configurable
The TTL for package details can be much longer than for generic values
since they never change. Note that when an update is pushed via Git, all
packages belonging to that package base are deleted and new packages are
created.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-10-07 12:21:03 -04:00
Lukas Fleischer
6493d00db5 aurjson: cache extended fields
Cache the results of the extended fields computation if the global
caching mechanism is enabled.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2019-10-06 16:13:38 -04:00
Florian Pritz
042f3f2622
Quote MySql 8.0 reserved keywords
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
2019-01-14 14:45:37 -05:00
Baptiste Jonglez
1ff409874e RPC: Allow to search packages by "*depends" fields
It is now possible to search for packages that depend on a given package,
for instance:

    /rpc/?v=5&type=search&by=depends&arg=ocaml

It is similarly possible to match on "makedepends", "checkdepends" and
"optdepends".

Signed-off-by: Baptiste Jonglez <git@bitsofnetworks.org>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2018-02-24 14:57:31 +01:00
Florian Pritz
27654afadb Add rate limit support to API
This allows us to prevent users from hammering the API every few seconds
to check if any of their packages were updated. Real world users check
as often as every 5 or 10 seconds.

Signed-off-by: Florian Pritz <bluewind@xinu.at>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2018-02-24 14:57:31 +01:00
Lukas Fleischer
15501972bc Check return value of get_extended_fields()
Make sure that the get_extended_fields() invocation succeeded before
merging regular and extended fields in process_query().

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2017-04-18 08:45:02 +02:00
Michael Straube
f4176a8ce1 Make aurjson error messages consistent
All error messages in aurjson except two end with a period. Add the
missing periods to make the messages consistent.

Signed-off-by: Michael Straube <straubem@gmx.de>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2017-02-14 20:41:50 +01:00
Lukas Fleischer
42f5c405c0 aurjson: Remove stray GROUP BY clause
The IDs of packages are unique, so there is no need to group search
results by package ID.

Note that the GROUP BY statement in question was introduced in commit
3447dfc (Support versioned RPC queries, 2014-04-28) for no apparent
reason and could even lead to errors in various DBMS.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2016-03-01 18:30:48 +01:00
Lukas Fleischer
9d7d1be731 aurjson: Add package base keywords
Expose package base keywords through the RPC interface (version 5).

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2016-02-09 21:54:39 +01:00
Lukas Fleischer
1f179c9fbc aurjson: Do not search by ID when argument is numeric
When performing info or multiinfo queries, one can currently either pass
package names or package IDs as parameters. As a consequence, it is
impossible to search for packages with a numeric package name because
numeric arguments are always treated as IDs. Since package IDs are not
public anymore these days, simply remove the possibility to search by ID
in revision 5 of the RPC interface.

Fixes FS#47324.

Suggested-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-12-13 10:22:59 +01:00
Lukas Fleischer
a2cbc7f646 aurjson: Allow underscores in JSONP callback names
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-10-24 18:03:19 +02:00
Lukas Fleischer
1f6237ffa7 aurjson: Rename the search_by parameter to "by"
This parameter is only supported by the search command. We do not need
to repeat ourselves.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-10-09 17:35:51 +02:00
Lukas Fleischer
3c06716c72 aurjson: Merge info and multiinfo commands
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-10-04 11:40:38 +02:00
Lukas Fleischer
261c7f74dd aurjson: Add "maintainer" search type
Deprecate the msearch command and add a new search type to the search
command.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-10-04 11:40:37 +02:00
Lukas Fleischer
f5b4f7e996 Fix parameter processing in parse_multiinfo_args()
Fixes a regression introduced in 94aeead (aurjson: Pass http_data array
to all functions, 2015-06-28).

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-10-03 11:07:39 +02:00
Lukas Fleischer
c67e5a1cdf aurjson.class.php: Sync error message with front-end
Instead of introducing a new message "You do not have the right to edit
this comment." for the RPC interface, use "You are not allowed to edit
this comment." which we already show in the front-end.

Reported-by: Christoph Seitz <seitz.christoph@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-09-26 07:43:10 +02:00
Lukas Fleischer
2f8e0dfa3a aurjson.class.php: Fix "Undefined index" notices
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-09-25 08:35:43 +02:00
Lukas Fleischer
209b0b6eda Mitigate JSONP callback vulnerabilities
The callback parameter of the RPC interface currently allows for
specifying a prefix of arbitrary length of the returned result. This can
be exploited by certain attacks.

As a countermeasure, this patch restricts the allowed character set for
the callback name to letters, digits, underscores, parenthesis and dots.
It also limits the length of the name to 128 characters. Furthermore,
the reflected callback name is now always prepended with "/**/", which
is a common workaround to protect against attacks such as Rosetta Flash.

Fixes FS#46259.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-09-12 10:20:03 +02:00
Johannes Löthberg
da1153857f rpc: msearch: Give orphans on empty maintainer argument
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-08-11 13:57:04 +02:00
Lukas Fleischer
080b6f3d12 aurjson.class.php: Add missing PHPDoc
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-08-08 12:59:24 +02:00
Marcel Korpel
8328223a5e aurjson.class.php: Add method get_comment_form()
This method will be used by the JavaScript comment editing and produces
a form containing the comment.

Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-08-08 12:59:24 +02:00
Johannes Löthberg
d8142abbbe Expose name-only search through the RPC interface
Fixes FS#37317.

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-08-08 12:59:23 +02:00
Johannes Löthberg
94aeead4ec aurjson: Pass http_data array to all functions
This is a preparatory patch that simplifies adding more arguments to
the parse functions

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-08-08 12:59:23 +02:00
Johannes Löthberg
838639056a Delete unused variable
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-08-08 12:59:23 +02:00
Johannes Löthberg
ea59f72778 RPC: Add decimal_fields array for floating-point fields
Fixes FS#45537.

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-07-04 13:02:37 +02:00
Lukas Fleischer
5a050552e8 Add the popularity field to the RPC interface
Implements FS#45422.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-06-27 13:04:03 +02:00
Lukas Fleischer
5fb7a74e23 Replace categories with keywords
Remove package base categories. Instead, users can now specify up to
twenty custom keywords that are taken into consideration when searching.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-06-14 17:58:55 +02:00
Lukas Fleischer
bd9af5f893 Reintroduce the URLPath field
In commit 74edb6f (Use Git repositories to store packages, 2014-06-06),
the URLPath field was dropped from RPC package results. Reintroduce the
field for backwards compatibility, even though it is no longer
recommended to use snapshot tarballs.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-06-11 13:44:53 +02:00
Lukas Fleischer
2be78f42ac aurjson.class.php: Exclude hidden package bases
Do not return packages belonging to hidden package bases in RPC results.

Fixes FS#45271.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2015-06-09 08:43:24 +02:00
Lukas Fleischer
74edb6fea9 Use Git repositories to store packages
* Remove package submission page from the web interface.
* Replace PKGBUILD and tarball links with links to cgit.
* Remove the "URLPath" field from RPC replies.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-12-27 12:42:12 +01:00
Lukas Fleischer
76343fb915 Use an INI-style configuration file
Replace web/lib/config.inc.php with an INI-style configuration file.
This allows us to get rid of several globals and makes it easier to use
the same configuration file in external scripts.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-10-24 10:03:54 +02:00
Lukas Fleischer
0a357a7d44 Add typeahead suggest to the merge request form
Add the typeahead implementation we already use for the package search
to the merge target text field. Instead of suggesting packages, suggest
package base names.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-07-23 17:53:30 +02:00
Lukas Fleischer
65129ce9c3 Make results consistent in RPC replies
Add RPC v3 which always returns a list of objects in RPC responses,
regardless of the request type. An empty list is returned when an error
occurs. The error message is moved to a separate "error" field.

Fixes FS#40963.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-06-25 12:10:15 +02:00
Lukas Fleischer
d909ffcb17 aurjson: Add a PackageBaseID field
This is useful to tools that automatically generate requests to orphan,
delete or merge packages.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-05-31 11:45:00 +02:00
Lukas Fleischer
cf6470803e aurjson: Fix multiinfo when using package IDs
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-05-18 12:19:29 +02:00
Lukas Fleischer
c90faa44a1 Use RPC API version 1 by default
Most AUR helpers don't support the new format yet. Use version 1 of the
API by default. In order to use the new format, "v=2" can be appended to
the list of GET parameters.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-04-28 18:54:26 +02:00
Lukas Fleischer
3447dfcbff Support versioned RPC queries
This adds a backwards compatibility mode for the old RPC API. The old
format can be requested by explicitly adding "v=1" to the list of GET
parameters. Note that due to internal changes, the old format only
returns the first license that belongs to a package.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-04-28 18:54:26 +02:00
Lukas Fleischer
11a565936e aurjson.class.php: Style fixes
* Fix braces, indentation and comment style.
* Remove some superfluous comments.
* Reword some comments.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-04-28 18:44:41 +02:00
Lukas Fleischer
e50f352643 Add a version tag to RPC replies
This is needed for clients to quickly differentiate between different
versions of the RPC API. The version number should be bumped whenever
there is a change that breaks backwards compatibility.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-04-28 00:10:42 +02:00
Lukas Fleischer
eb6cf1fad0 Add more fields to RPC info replies
This patch adds the following fields to info and multiinfo replies:

* Depends
* MakeDepends
* CheckDepends
* OptDepends
* Conflicts
* Provides
* Replaces
* Groups
* License

Each of these fields is an array.

Note that since collecting all these fields is CPU-intensive, they are
not included in replies to search queries.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-04-28 00:10:42 +02:00
Lukas Fleischer
b384f32fec Fix the RPC interface
* Fix the SQL query to conform to the new database layout.

* Remove the license field from replies. The license field is now stored
  in a separate table and no longer returned on search queries.

* Add a "PackageBase" field that contains the name of the package base
  of every package in the result.

* Fix the source tarball URL. The URL is now built based on the package
  base name instead of the package name.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2014-04-27 23:30:33 +02:00
Chris Down
35c5a5a3a9 Specify charset in Content-Type header when returning JSON data from API.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2013-09-02 00:29:58 +02:00
canyonknight
8e03e68d68 Add database wrapper class and new connection method
Uses the Singleton pattern to ensure all queries use the same
database connection that is released upon script completion.

All database connections should now be called with DB::connect() and
not db_connect().

Signed-off-by: canyonknight <canyonknight@gmail.com>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2013-02-10 12:10:37 +01:00
Marcel Korpel
b004333ead Implemented typeahead suggest
Use Twitter Bootstrap JavaScript framework for typeahead support.

Add a new "suggest" JSON method, which returns the first 20
packages that match the beginning characters of a query.

canyonknight: Link format change, commit message
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2013-01-19 12:17:55 +01:00
canyonknight
43a69e7127 aurjson.class.php: Limit number of RPC results
With no limit to the number of results, memory_limit set to 32M
can easily be exceeded for searches that have a large number of
results. This results in an HTTP error 500 for those queries.

Limit results to an amount set within config.inc.php to avoid
exceeding memory_limit. Introduce new JSON error code for when
the result limit is hit.

Fixes FS#31849

Signed-off-by: canyonknight <canyonknight@gmail.com>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2012-10-22 12:33:13 +02:00
canyonknight
e171f6f34e Migrate all DB code to use PDO
All DB code currently uses the quickly aging mysql_* functions. These
functions are strongly discouraged and may eventually be deprecated.

Transition all code to utilize the PDO data access abstraction layer. PDO
allows for consistent query code across multiple databases. This could
potentially allow for someone to use a database other than MySQL with
minimal code changes.

All functions and behaviors are reproduced as faithfully as possible with
PDO equivalents and some changes in code.

Signed-off-by: canyonknight <canyonknight@gmail.com>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2012-09-18 00:58:46 +02:00
Lukas Fleischer
0557f7705a RPC: Do not return an error on 0 results
Return an empty array and set the result count to zero instead.

Before:

    $ curl 'http://localhost/rpc.php?type=search&arg=raboof'
    {"type":"error","resultcount":0,"results":"No results found"}

After:

    $ curl 'http://localhost/rpc.php?type=search&arg=raboof'
    {"type":"search","resultcount":0,"results":[]}

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2011-11-03 08:48:20 +01:00
Dave Reisner
168a51431b aurjson: add result count to JSON result
We already ask for the result count, but only use it as a basis for testing
query success or failure. Add the value to the JSON reply.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2011-11-02 21:21:23 +01:00
Lukas Fleischer
47c5167acb Escape wildcards in "LIKE" patterns
Percent signs ("%") and underscores ("_") are not escaped by
mysql_real_escape_string() and are interpreted as wildcards if combined
with "LIKE". Write a wrapper function db_escape_like() and use it where
appropriate.

Note that we already fixed this for the RPC interface in commit
da2ebb667b but missed the other places.
This patch should fix all remaining flaws reported in FS#26527.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-24 17:57:54 +02:00