6387d24846
Admin-scoped users (answers: who can create a 'user' account, only super or also an admin within their own scope?): - New owner_admin_id column on users (migration 004). NULL means created by super (company-wide, previous behavior); otherwise scoped to that admin's own codes. - Users::addUser/editUser/deleteUser now allow an 'admin' session, but force type='user' and owner_admin_id to their own id regardless of submitted input. user.php/users.php open up to admins with a restricted UI (no type picker, listing limited to their own created users). - New qr_compute_scope_owner_id()/qr_apply_owner_scope()/qr_has_full_visibility() helpers in includes/security.php, replacing the ad-hoc type==='admin' checks in index.php, dynamic_qrcodes.php, static_qrcodes.php and bulk_action.php. A 'user' account created by an admin is now scoped to that admin's codes instead of seeing everything company-wide. Qr code storage hardening: images were served as plain static files under the document root with no auth check at all. Storage now lives outside the web root; qrcode_image.php and qrcode_zip_download.php gate access with the same permission model as the list pages, and the bulk zip download is bound to the session that generated it. PHP 8.4 + chillerlan/php-qrcode 6.0.1: bumped since this is a dockerized app, so the PHP version shipped doesn't matter to end users. Note: the 6.0.1 tag itself only requires PHP 8.2 - the earlier "needs 8.4" read was from an unpinned clone of master, which has since moved past the tag. Fixed along the way, surfaced by testing on 8.4: - The hardcoded Imagick build (an old pinned master commit, workaround for 3.7.0 being broken on PHP 8.3+) no longer compiles on 8.4. Imagick 3.8.1 is now a normal stable release, so the workaround is gone. - config.php had display_errors=On + error_reporting(E_ALL), so PHP 8.4's new deprecation notices got dumped straight into the response before session_start() could run, breaking login outright. Also an info-disclosure risk on its own. Now logged instead of displayed. - MysqliDb::insertMulti() had an implicit nullable parameter, now explicit. - includes/auth_validate.php redirected unauthenticated requests but never called exit(), so the rest of the script kept running. - Dockerfile.fpm was missing both git (needed to clone chillerlan/php-qrcode) and the imagick extension entirely. Also removes the unused sample qr code images that shipped in the original repo; storage now lives outside the document root so they were never going to be served again.
95 lines
3.9 KiB
SQL
95 lines
3.9 KiB
SQL
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
|
|
SET time_zone = "+00:00";
|
|
|
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
|
/*!40101 SET NAMES utf8 */;
|
|
|
|
CREATE TABLE IF NOT EXISTS `users` (
|
|
`id` int(25) NOT NULL AUTO_INCREMENT,
|
|
`username` varchar(50) NOT NULL,
|
|
`password` varchar(255) NOT NULL,
|
|
`series_id` varchar(60) DEFAULT NULL,
|
|
`remember_token` varchar(255) DEFAULT NULL,
|
|
`expires` datetime DEFAULT NULL,
|
|
`type` varchar(10) NOT NULL,
|
|
`must_change_password` tinyint(1) NOT NULL DEFAULT 0,
|
|
`password_changed_at` datetime DEFAULT NULL,
|
|
`can_view_static` tinyint(1) NOT NULL DEFAULT 0,
|
|
`can_view_dynamic` tinyint(1) NOT NULL DEFAULT 0,
|
|
`owner_admin_id` int(25) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `username` (`username`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
|
|
|
|
-- Default super admin account. Credentials: superadmin / superadmin
|
|
-- must_change_password=1 forces a password change on first login (see Fase 1 hardening).
|
|
INSERT INTO `users` (`id`, `username`, `password`, `series_id`, `remember_token`, `expires`, `type`, `must_change_password`, `password_changed_at`) VALUES
|
|
(1, 'superadmin', '$2y$10$xpZc5KC.aU2XHkcqhuZGFuAnqmtL4Unt8MysOyylceq.19XIyoZpG', NULL, NULL, NULL, 'super', 1, NULL);
|
|
|
|
CREATE TABLE IF NOT EXISTS `dynamic_qrcodes` (
|
|
`id` int(10) NOT NULL AUTO_INCREMENT,
|
|
`id_owner` int(25) NULL DEFAULT NULL,
|
|
`filename` varchar(45) NOT NULL,
|
|
`format` varchar(45) DEFAULT NULL,
|
|
`identifier` longtext,
|
|
`link` varchar(500) DEFAULT NULL,
|
|
`qrcode` varchar(60) DEFAULT NULL,
|
|
`scan` int(11) NOT NULL DEFAULT '0',
|
|
`state` varchar(20) NOT NULL DEFAULT 'enable',
|
|
`created_by` int(10) unsigned NOT NULL DEFAULT '0',
|
|
`created_at` timestamp NULL DEFAULT NULL,
|
|
`updated_by` int(10) unsigned NOT NULL DEFAULT '0',
|
|
`updated_at` timestamp NULL DEFAULT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
|
|
|
|
CREATE TABLE IF NOT EXISTS `static_qrcodes` (
|
|
`id` int(10) NOT NULL AUTO_INCREMENT,
|
|
`id_owner` int(25) NULL DEFAULT NULL,
|
|
`filename` varchar(45) CHARACTER SET utf8 NOT NULL,
|
|
`format` varchar(45) DEFAULT NULL,
|
|
`type` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
|
|
`content` mediumtext CHARACTER SET utf8,
|
|
`qrcode` varchar(60) CHARACTER SET utf8 DEFAULT NULL,
|
|
`state` varchar(20) CHARACTER SET utf8 NOT NULL DEFAULT 'enable',
|
|
`created_by` int(10) unsigned NOT NULL DEFAULT '0',
|
|
`created_at` timestamp NULL DEFAULT NULL,
|
|
`updated_by` int(10) unsigned NOT NULL DEFAULT '0',
|
|
`updated_at` timestamp NULL DEFAULT NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
|
|
|
|
-- Security hardening (Fase 1): rate limiting on login attempts
|
|
CREATE TABLE IF NOT EXISTS `login_attempts` (
|
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
`username` varchar(50) NOT NULL,
|
|
`ip_address` varchar(45) NOT NULL,
|
|
`success` tinyint(1) NOT NULL DEFAULT 0,
|
|
`attempted_at` datetime NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `username_attempted_at` (`username`, `attempted_at`),
|
|
KEY `ip_attempted_at` (`ip_address`, `attempted_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
-- Security hardening (Fase 1): audit log of sensitive actions
|
|
CREATE TABLE IF NOT EXISTS `audit_log` (
|
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
|
`user_id` int(25) DEFAULT NULL,
|
|
`username` varchar(50) DEFAULT NULL,
|
|
`action` varchar(50) NOT NULL,
|
|
`target_type` varchar(30) DEFAULT NULL,
|
|
`target_id` varchar(50) DEFAULT NULL,
|
|
`ip_address` varchar(45) DEFAULT NULL,
|
|
`user_agent` varchar(255) DEFAULT NULL,
|
|
`created_at` datetime NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `created_at` (`created_at`),
|
|
KEY `user_id` (`user_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
|
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|