Commit Graph
45 Commits
Author SHA1 Message Date
Adam Daley 435944defa Refactor pagination and API with strict types and validation (#3391)
* Add strict types; refactor pagination, tools & API

* Replace `Box_Paginator` with FOSSBilling `Paginator`

* Clarify paginator comment wording

* Validate JSON response and include HTTP code

* Cast language params to bool and add JSON preview
2026-04-06 22:06:13 +01:00
Adam Daley 0f5ff8847f Improve code robustness and reliability (#3248)
* Harden code against null/undefined values

* Update dependency lockfiles

* Sanitize ticket input and use IDs in email list
2026-02-16 23:48:06 +00:00
Belle Aerni 0a156f4161 Fix CS automation (#3209)
* Restore needed gitignore

* Ran the fixes since they are far behind

* Fix for rector causing a problem. Re-ran.

* Update ServiceTest.php
2026-01-26 11:18:35 -08:00
Adam DaleyandCopilot 0c44c7f624 Replace PDO usage with Doctrine DBAL (#2964)
* Refactor database connection to use `DriverManagerFactory`

* Add Doctrine DBAL connection to DI container

Revert "Add Doctrine DBAL connection to DI container"

This reverts commit bc2f9f4901d8baee4b12cd2795b0ef76156849cf.

Reapply "Add Doctrine DBAL connection to DI container"

This reverts commit 48debb74bbfa6c8cebf27ee20c222c911d508ccb.

* Refactor database access to use Doctrine DBAL

* Refactor DB config to use 'driver' instead of 'type'

* Refactor database connection to use `DriverManagerFactory`

* Add Doctrine DBAL connection to DI container

Revert "Add Doctrine DBAL connection to DI container"

This reverts commit bc2f9f4901d8baee4b12cd2795b0ef76156849cf.

Reapply "Add Doctrine DBAL connection to DI container"

This reverts commit 48debb74bbfa6c8cebf27ee20c222c911d508ccb.

* Refactor database access to use Doctrine DBAL

* Refactor DB config to use 'driver' instead of 'type'

* Refactor tests to use `dbal` mocks

* Replace `getQueryBuilder` with `createQueryBuilder

* Fix handling of empty query results and cleanup exception comment

* Update Composer lock file

* Refactor PDO initialization in DI container

Updated the DI definition for 'pdo' to directly use the PDO instance returned by Doctrine's DriverManagerFactory, removing unnecessary object casting. Also added missing import for DriverManagerFactory. Updated PHPStan config to remove a redundant ctype_alnum rule.

* Refactor query execution and result fetching logic

Updated database query handling in Extension and System Service classes to separate query building from execution and fetching. This improves code clarity and ensures consistent use of fetchOne for single-value results.

* Fix SQL where clause syntax in Service.php

Corrects the syntax of the where clause in several queries by changing 'where('param', ':param')' to 'where('param = :param')' for proper parameter binding and query execution.

* Refactor Stats module to use Doctrine DBAL

* Refactor Custompages Service to use dbal instead of pdo

Replaced all direct PDO usage with dbal methods for database operations in the Custompages Service. This improves consistency, leverages dbal's abstraction, and prepares the codebase for better maintainability and future enhancements.

* Refactor DBAL usage and update test mocks

Refactored DBAL service definitions and query builder usage to improve clarity and consistency. Updated tests to use anonymous classes for DBAL and query builder mocks instead of PHPUnit mock objects, simplifying test setup and improving maintainability.

Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor DB queries to use executeQuery and executeStatement

Replaced manual PDO prepare/execute calls with Doctrine DBAL's executeQuery and executeStatement methods in UpdatePatcher and ApiRequestTable. This improves code consistency and leverages DBAL features for query execution and result fetching.

* Add input validation for DB charset, table, and column names

Introduces strict validation for supported database charsets in DriverManagerFactory, allowed column names in Custompages Service, and allowed table names in Stats Service to prevent invalid or unsafe input. Also updates UpdatePatcher with default values for new config keys and adjusts a Stats Service test to use a valid table name.

* Add 'CHARSETS' to cspell custom words list

* Refactor query execution in patcher and product domain

Updated query builder usage in UpdatePatcher and ProductDomainTable to separate query building from execution, aligning with best practices. Removed unused fetchOne stubs from ServiceTest to reflect these changes.

Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor `getProductSummary` to use Doctrine DBAL

* Fix parameter binding for category and hash in UpdatePatcher

Updated the insert statement in UpdatePatcher to bind the 'category' and 'hash' parameters explicitly, ensuring correct handling of null values during database insertion.

* Update MySQL charset handling in PDO setup

Removes redundant charset initialization statements for MySQL connections, relying on DBAL to handle connection charset via DSN. Now only sets the server default charset and session timeouts.

* Set default DB driver to `pdo_mysql` in `UpdatePatcher`

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-25 13:02:23 +00:00
Adam Daley 37deea9d38 Add parentheses to SQL WHERE clauses for correct logic (#3156)
Wrapped `OR` conditions in SQL `WHERE` clauses with parentheses across multiple service classes to ensure correct logical grouping and prevent operator precedence issues during search queries.
2026-01-14 14:46:13 +00:00
af521f1794 Improved audit logs and removed the ability to delete them using the admin panel (#3026)
* Removed API routes that allowed activity logs to be deleted

* Dropped `updated_at` columns from activity tables

* Rename the label from "Event history" to "System activity"

* Rename the label from "Event history" to "System activity"

* Dropped `updated_at` columns from activity tables

* chore(deps): update dependency rector/rector to v2.2.8
chore(deps): update dependency pimple/pimple to v3.6.0 (#3025)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Removed API routes that allowed activity logs to be deleted

Dropped `updated_at` columns from activity tables

Rename the label from "Event history" to "System activity"

Rename the label from "Event history" to "System activity"

Merge branch 'security/activity-logs' of https://github.com/fossbilling/fossbilling into security/activity-logs

Dropped `updated_at` columns from activity tables

Merge branch 'security/activity-logs' of https://github.com/fossbilling/fossbilling into security/activity-logs

* Rename the label from "Event history" to "System activity"
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch security/activity-logs
# Your branch is behind 'origin/security/activity-logs' by 9 commits, and can be fast-forwarded.
#   (use "git pull" to update your local branch)
#
# Changes to be committed:
#	modified:   src/install/sql/content.sql
#	modified:   src/install/sql/structure.sql
#	modified:   src/library/FOSSBilling/UpdatePatcher.php
#	modified:   src/modules/Activity/Api/Admin.php
#	modified:   src/modules/Activity/Controller/Admin.php
#	modified:   src/modules/Activity/Service.php
#	modified:   src/modules/Activity/html_admin/mod_activity_index.html.twig
#	modified:   src/modules/Client/Api/Admin.php
#	modified:   src/modules/Client/html_admin/mod_client_login_history.html.twig
#	modified:   src/modules/Staff/Api/Admin.php
#	modified:   src/modules/Staff/Service.php
#	modified:   src/modules/Staff/html_admin/mod_staff_login_history.html.twig
#	modified:   tests-legacy/modules/Activity/Api/AdminTest.php
#	modified:   tests-legacy/modules/Client/Api/AdminTest.php
#	modified:   tests-legacy/modules/Staff/Api/AdminTest.php
#	modified:   tests-legacy/modules/Staff/ServiceTest.php
#

* Colspan

* Fixed TomSelect. It now works with more than one instance in a page.

* Added get_pairs endpoint to the Staff module to make TomSelect work

* Implemented filters for the system activity logs

* Added date range filter and "Show all activity from this admin"

* Added filtering by priority

* Separate filtering by IP address

* Filtering options for getPairs

* Fix priority filter conflict when both exact and minimum priority are specified (#3028)

* Initial plan

* Make priority filter take precedence over min_priority to avoid conflicts

Co-authored-by: yagiz-dev <35808275+yagiz-dev@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yagiz-dev <35808275+yagiz-dev@users.noreply.github.com>

* Make the "filter" button in searchbox preserve other request parameters

* Make the debug message for events more descriptive

* Show the time passed since event as a title for the element

* Fixed tests

* Disable min_priority select when exact priority is selected

* Display the client name correctly

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2025-11-19 01:07:06 +03:00
Adam Daley a9b903c222 Codebase modernisation, configuration cleanup, and improved type safety (#2957)
* Refactor tests to replace depreciated functions

* Update Rector config and dependencies

* Rector: Add explicit string casting for stricter type safety

* Rector: Add return type hints to methods across codebase

* Rector: Increase dead code level and refactor invoice item logic

* Remove unnecessary `willReturn` from test mocks

Eliminate redundant `willReturn(null)` and similar calls from PHPUnit mock setups in legacy module tests, leaving only method expectations. Also update some test values to use floats for consistency.

* Refactor API controller and email adapter return values

* Update formatting and guidelines in `AGENTS.md`
2025-10-11 23:39:44 +01:00
Belle Aerni 996ff15a3e Partial revert of added strict types (#2881) 2025-08-29 15:06:49 -07:00
Adam DaleyandCopilot 315f9f3944 Refactor Filesystem and Path handling (#2836)
* Removed legacy files

* Refactor Filesystem and Path handling

* Removed `FOSSBilling\Tools` legacy functions

* Update live-tests to include file check for `php_error.log`

* Update Extension module tables to fix wrapping issue

* Apply suggestions from @Copilot

Co-Authored-By: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Extension module icon URL handling

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-08-09 21:50:11 +01:00
Belle AerniandAdam Daley fa57b285e8 Fix permission & navigation bugs (#2786)
* Prevent duplicate nav registration

* Fix the security module not being accessible

Corrects the security permissions accidentally being hidden and fixes flawed logic which caused hiding the permissions for a module to then report no permission being given (which is why the security module was being hidden)

* Greatly simplified some of the permissions logic

---------

Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
2025-06-12 09:04:36 +01:00
Yağızhan f2bb4179d2 Reworked the Pagination class (#2759)
* Introduce the new Paginator class

* Rename it back to Pagination

* Move #2756 here

* Use HttpFoundation\Request

* Restore Box_Paginator

* Tests

* Replace the deprecated methods wherever used

* No need

* Tests

* Tests again

* tests

* Tests hopefully for the last time

* Use a subquery instead

* Found a faulty query

`m.*` already includes `client_id`. was getting a duplicated column error.

* New pagination logic in Huraga & a couple of improvements

* Type safety

* Accessibility and other improvements

* Fixed tests

* Make aria tags translatable

* Update partial_pagination.html.twig

* Dot operator and little docblock improvement

---------
2025-06-04 15:21:09 +03:00
Belle Aerni 368f8cd6ad Bump the year (#2581) 2025-01-23 15:11:53 -08:00
Belle Aerni 3449537c92 Fixed CS / Rector workflow and ran both (#2580) 2025-01-20 16:19:45 -08:00
Belle Aerni 6df392ffa7 Fully prevent the cron account from ever being logged into (#2502)
* Fully prevent the cron account from ever being logged into

* Update the tests
2024-11-22 00:08:48 -08:00
Belle Aerni 45db4910a7 PHP 8.4 prep (#2464)
* Update CI for PHP 8.4

* Update composer deps for PHP 8.4

* Updates

* This is the default mode and this constant causes test failutes

* Explicily install the PDO extensions

* Temporarily downgrade the live tests to PHP 8.3

It would seem that there is some kind of problem with PHP 8.4 in regards to these tests. I believe it is outside of our control however as it installs fine for me with PHP 8.4 under DirectAdmin

* Update to address deprecations

* Make that nullable

* Fixed my typo

* Bump PHPunit to v11

* Also take care of two minor things

* Formatting fix
2024-11-21 23:16:29 -08:00
Belle AerniandJaap Marcus 7fcaaae8bb Add delays to prevent email enumeration (#2487)
* Add delays to prevent email enumeration

* Wording tweak

* This should fix the tests

Also ran PHP-CS-Fixer and Rector

* Update ServiceTest.php

---------

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
2024-11-14 00:38:58 -08:00
Belle Aerni 303f4cfa2d Code styling & rector config improvements (#2254)
* Bumped the Rector deadcode level

* Added the instanceof setlist

* Increasded type coverage and updated tests config too

* Bumped type coverage & ran PHP-cs-fixer
2024-04-23 10:38:18 -07:00
FOSSBilling BotandFOSSBilling Bot 6d1649da6b Apply PHP Code Styling & Quality Changes (#2173)
Co-authored-by: FOSSBilling Bot <fossbilling-bot>
2024-03-04 14:05:09 -08:00
Belle AerniandJohn @ S4 037acce702 Bulk fix of many grammar / phraseology mistakes (#2166)
* Bulk fix of many grammar / phraseology mistakes

* Small fixes after self-review

* Corrections

* Update mod_currency_settings.html.twig

* Update mod_currency_settings.html.twig

* Update mod_formbuilder_field.html.twig

---------

Co-authored-by: John @ S4 <64874788+John-S4@users.noreply.github.com>
2024-02-27 03:01:07 -08:00
Belle Aerni d771457efc Bump the year (#2167)
* Bump the year

* And fix the spelling
2024-02-25 02:45:38 -08:00
FOSSBilling BotandFOSSBilling Bot f136352b31 Apply PHP Code Styling & Quality Changes (#1865)
Co-authored-by: FOSSBilling Bot <fossbilling-bot>
2023-11-25 02:55:31 +00:00
Belle Aerni 5bd3ff7751 Begin reworking permission management (#1545)
* Begin reworking permission management

* Tests

* This.. tested functionality that didn't exist in the app

* Fixes

* Added permission checks for the system module

* Implemented extension settings permission

The "extension" settings page will now check for permission before allowing a staff member to even visit the settings page for a client.

FOSSBilling will also check for permission before saving a new config so the API can't be used to bypass this limitation.

I also removed a test as it was checking a function which only ever had one possible return value, no point in updating it to work with this PR

* This should fix the test

* I got a little mixed up with that, but this should work

* Fixed the tests

* Implemented give all & revoke all buttons

* Implemented more, enhancements, & bugfix

* Rename function

* Fix tests

* Optimize, address comment

* Now let's make the tests happy again

* Deduplicate code, cleanup a bit

* Bugfix

* Added selectbox support to the front-end

* Quick bugfix

* Fix issue PHPStan detected

* Bug fix

* Improved page layout & styling

* Implemented more checks

* Fix the tests

* Update error.html.twig

* Cleanup

* Fix the tests

* Updated the design to be more space efficient

* Don't list module access when always given

* Updated the exception type

* setMethod -> onlyMethods

* I donno how that got goofed up

* Fix the test, email module should always be accessible

* Removed the broken test

It's.. not really checking anything anyways. Just that the `extension` module is in a hardcoded array.
2023-11-21 16:18:53 -08:00
Belle Aerni 602b537996 Opt-in error reporting via Sentry.io (#1732)
* Began implementing Sentry.io support

* Added to the installer

* Added the ID to the bug report template and UI

* Hook it into our error handler, added the ability to filter by error code

* Attempting to add the DSN via GH actions

* Spelling and making PHPstan happy

* Skip exceptions for various incomplete configurations

Also brings in some of the category suggestions made by @Anuril in #195

* Update tests to account for changes

* Added & renamed exception classes

* Fix tests

* Change a bunch of items to be InformationExceptions

* Use a lighter HTTP client, fixed API error reporting

* I guess that's not needed now?

Arighty then

* Improvements, additional info added

* Update SentryHelper.php

* Improved error logging, added instance ID to error page

Also made it so that errors are correctly sent to Sentry rather than exclusively exceptions

* Make the tests happy

* Added the link, improved wording

Also removed the "performance" part of the reporting as it needs to be added to the front-end and I'm not currently implementing that

* Began implementing UI alerts and info

* Added the ability to toggle, fixed tests, use path constants

* Added some useful info & links to the page

* These should be InformationException

* Fix the automated Sentry DSN entry

* Fix the install number text

* Minor cleanup, converted more to InformationException

* Replaced some direct config references with constants

We have the BB_DEBUG constant to indicate if we have debug mode enabled or not, so we shouldn't be directly referencing it in the config file unless we actually need to do so.

Using the constant means there's less locations to update the reference if the config structure is changed

* Bugfix

* Consistency & fixed a PHPDoc

* Corrections

* We actually do want exceptions thrown here

* Change how we get the instance ID

* Stability improvements

Having support for translatable error pages was proving to be problematic, so I had to remove it.

I also had to update the exception class to handle cases where the trans function wasn't setup yet (needed for the /run-patcher page if an error occurs)

* Missed this change on git

* Also fix the variable names...

* Re-added new deps after rebase

* This should also accept "Error" types

* Added more info to the bug report and removed a dug line

* This wasn't supposed to get renamed

* Updated some missed references to Box_Exception
2023-10-28 18:40:39 -07:00
fefbcd21b0 Apply PHP Code Styling & Quality Changes (#1498)
* Apply PHP Code Styling & Quality Changes

* Delete these

* Update .gitignore

* Fixes for PHPStan

* Ignore spelling in the gitnore

* Allow null for that type

Honestly doing so makes ZERO sense, but it matches the current behavior.

---------

Co-authored-by: FOSSBilling Bot <fossbilling-bot>
Co-authored-by: Belle Aerni <belleaerni@gmail.com>
2023-07-30 08:57:44 -07:00
Yağızhanandfossbilling-bot fd872ac941 Implement PHP-CS-Fixer as an automated workflow (#1240)
* Implement PHP-CS-Fixer as an automated workflow

* Apply PHP-CS-Fixer changes

---------

Co-authored-by: fossbilling-bot <121974958+fossbilling-bot@users.noreply.github.com>
2023-07-30 06:49:11 -07:00
7a99f78ef1 Remove incorrect login info from onEventAdminLoginFailed (#1495)
* Small security fix that removes the cleartext password from log files and the "onEventAdminLoginFailed" event

* Do it better and less wrong

---------

Co-authored-by: Anuril <ta@TAPC01.localdomain>
Co-authored-by: Belle Aerni <belleaerni@gmail.com>
2023-07-30 05:47:30 -07:00
Belle Aerni dfcabdd80b Remove the "remember me" checkbox (#1471)
The functionality for this isn't actually implemented and it doesn't work
2023-07-26 08:14:28 -07:00
Belle Aerni 20c23b051e Invalidate existing sessions during PW reset (#1435) 2023-07-20 13:23:44 +01:00
Belle Aerni 325155bccd Fix minor errors (#1443) 2023-07-20 13:12:54 +01:00
Belle Aerni b9c35a1747 Replace Box_Session and improve session handling (#1332)
* Replace Box_Session and improve session handling

* Improve weights, capitalize class name correctly

* Make the tests pass, update the SQL structure

* Tweak to the fingerprint class, fix more tests

* Regenerate session IDs when logging in

* Improve readability

* Update ServiceTest.php

* Tweak weights and added Huntr badge to the readme

* Improve readability, add PHPDocs, and updated weight

* Update SECURITY.md
2023-06-19 04:14:29 -07:00
Yağızhan d909d77f7e -Unnecessary whitespace in the class headers (#1219) 2023-05-07 13:24:29 -07:00
Yağızhan 412e4a9fbd Standardized the class headers (#1212) 2023-05-06 13:06:17 +01:00
Adam Daley e54569d2cd Introduce namespaces and strict typing for FOSSBilling library classes (#1206) 2023-05-04 01:02:06 +01:00
Yağızhan 950e4dccef Type hinting the DI methods and variables (#1201) 2023-05-01 21:01:35 +03:00
Adam Daley 053f22a8bb Remove Box DI class in favour of native dependencies (#1193) 2023-04-30 08:47:52 +01:00
Belle Aerni 9faa981c58 Replace usage of array_get (#989)
* Replace usage of array_get

* Fixes

* And a few more

* Remove remaining references

* Update Service.php

* Few more fixes

* Fix.. I think?

* Fix Client / Invoice updates

* Fix stats

* Fix issues noticed during code review

* More fixes

* And some more fixes :)
2023-03-27 23:44:30 -07:00
Jaap Marcus a41e406703 Improvements to password reset function (#802)
* Add settings in staff module to disable password reset

* Allow admin to select password instead send by mail
2023-02-10 02:06:57 -08:00
Jaap Marcus 774127bdc5 Fix #727 Unable to save staff permissions (#728) 2023-01-21 16:20:41 +01:00
Wynton Franklin a68d3edc20 Merge remote-tracking branch 'upstream/main' into admin-password-reset 2023-01-15 17:30:12 -04:00
Wynton Franklin 6bd52065d8 add send email to one staff account. 2023-01-15 11:44:24 -04:00
Belle Aerni 774f0d5c95 Use Rector to modernize code for PHP 8.0 2023-01-12 00:40:54 -08:00
Wynton Franklin 990e21fcc2 Add admin password reset db 2023-01-07 12:27:12 -04:00
Wynton Franklin eb9bc25a44 added password reset for admin accounts 2023-01-01 11:25:34 -04:00
evrifaessa f463f875d0 Fixed some typos 2022-12-03 19:13:22 +03:00
Belle Aerni edd6f72634 Drop the "BB" prefix 2022-11-28 17:22:50 +03:00