diff --git a/build/schema/mysql.demo.sql b/build/schema/mysql.demo.sql index 7fead5f..ddcd079 100644 --- a/build/schema/mysql.demo.sql +++ b/build/schema/mysql.demo.sql @@ -26,3 +26,44 @@ INSERT INTO `service` (`id`, `name`, `description`) VALUES (4, 'DNS', 'Hosted DNS services'), (5, 'LDAP', 'Hosted directory services'); +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`id`, `username`, `password`, `fullname`, `email`, `last_login`, `last_password_change`) VALUES +(2, 'guest', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'Guest', NULL, NULL, 1324211553); + +-- +-- Dumping data for table `group` +-- + +INSERT INTO `group` (`id`, `name`, `description`) VALUES +(2, 'readonly', 'Basic group with read only access to the status boards.'); + +-- +-- Dumping data for table `usergroup` +-- + +INSERT INTO `usergroup` (`id`, `user`, `group`, `added`) VALUES +(1, 1, 1, 1324211572), +(2, 2, 2, 1324211572); + +-- +-- Dumping data for table `permission` +-- + +INSERT INTO `permission` (`id`, `name`, `description`) VALUES +(2, 'Update Status Boards', 'Permission to add/edit/delete any service or site.'); +(3, 'Update Incidents', 'Permission to create and update the status of any incident.'), +(4, 'View Status Boards', 'Permission to view the status of all services and sites, and details of any incident.'), + +-- +-- Dumping data for table `grouppermissions` +-- + +INSERT INTO `grouppermissions` (`id`, `group`, `permission`, `added`) VALUES +(2, 1, 2, 1324211935), +(3, 1, 3, 1324211935), +(4, 1, 4, 1324211935), +(5, 2, 4, 1324211935); + diff --git a/build/schema/mysql.sql b/build/schema/mysql.sql index 8996345..950d814 100644 --- a/build/schema/mysql.sql +++ b/build/schema/mysql.sql @@ -34,6 +34,7 @@ CREATE TABLE IF NOT EXISTS `settings` ( INSERT INTO `settings` (`name`, `value`, `type`) VALUES ('debug.display_exceptions', '1', 'bool'), ('cache.base_dir', '/dev/shm/status-board/', 'string'), +('auth', 'Database', 'string'), ('logging.plugins', 'Database\nFlatFile', 'array(string)'), ('logging.Database', 'webui', 'array(string)'), ('logging.Database.webui.table', 'log', 'string'), @@ -171,3 +172,150 @@ CREATE VIEW `incident_open` AS ( WHERE `isc`.`status` IN (1,2,3,4) ); + +-- +-- Table structure for table `user` +-- + +DROP TABLE IF EXISTS `user`; +CREATE TABLE IF NOT EXISTS `user` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(255) NOT NULL, + `password` char(40) NOT NULL, + `fullname` varchar(255) NULL, + `email` varchar(255) NULL, + `last_login` int(10) NULL, + `last_password_change` int(10) NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; + +-- +-- Dumping data for table `user` +-- + +INSERT INTO `user` (`id`, `username`, `password`, `fullname`, `email`, `last_login`, `last_password_change`) VALUES +(1, 'admin', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 'Administrator', NULL, NULL, 1324211456); + +-- +-- Table structure for table `group` +-- + +DROP TABLE IF EXISTS `group`; +CREATE TABLE IF NOT EXISTS `group` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `description` text NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; + +-- +-- Dumping data for table `group` +-- + +INSERT INTO `group` (`id`, `name`, `description`) VALUES +(1, 'admins', 'Administrative users will full control over the status boards.'); + +-- +-- Table structure for table `usergroup` +-- + +DROP TABLE IF EXISTS `usergroup`; +CREATE TABLE IF NOT EXISTS `usergroup` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `user` int(10) unsigned NOT NULL, + `group` int(10) unsigned NOT NULL, + `added` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; + +-- +-- Dumping data for table `usergroup` +-- + +INSERT INTO `usergroup` (`id`, `user`, `group`, `added`) VALUES +(1, 1, 1, 1324211572); + +-- +-- Table structure for view `groups_by_user` +-- + +DROP VIEW IF EXISTS `groups_by_user`; +CREATE VIEW `groups_by_user` AS ( + SELECT + `u`.`id` AS `user`, + `g`.* + FROM + `usergroup` as `ug` + LEFT JOIN `user` AS `u` ON `ug`.`user`=`u`.`id` + LEFT JOIN `group` AS `g` ON `ug`.`group`=`g`.`id` +); + +-- +-- Table structure for table `permission` +-- + +DROP TABLE IF EXISTS `permission`; +CREATE TABLE IF NOT EXISTS `permission` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `description` text NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; + +-- +-- Dumping data for table `permission` +-- + +INSERT INTO `permission` (`id`, `name`, `description`) VALUES +(1, 'Administrator', 'Full administrative rights.'); + + +-- +-- Table structure for table `grouppermissions` +-- + +DROP TABLE IF EXISTS `grouppermission`; +CREATE TABLE IF NOT EXISTS `grouppermission` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `group` int(10) unsigned NOT NULL, + `permission` int(10) unsigned NOT NULL, + `added` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; + +-- +-- Dumping data for table `grouppermissions` +-- + +INSERT INTO `grouppermissions` (`id`, `group`, `permission`, `added`) VALUES +(1, 1, 1, 1324211935); + +-- +-- Table structure for view `permissions_by_group` +-- + +DROP VIEW IF EXISTS `permissions_by_group`; +CREATE VIEW `permissions_by_group` AS ( + SELECT + `g`.`id` AS `group`, + `p`.* + FROM + `grouppermission` as `gp` + LEFT JOIN `group` AS `g` ON `gp`.`group`=`g`.`id` + LEFT JOIN `permission` AS `p` on `gp`.`permission`=`p`.`id` +); + +-- +-- Table structure for view `permissions_by_user` +-- + +DROP VIEW IF EXISTS `permissions_by_user`; +CREATE VIEW `permissions_by_user` AS ( + SELECT + `u`.`id` AS `user`, + `p`.* + FROM + `usergroup` as `ug` + LEFT JOIN `user` AS `u` ON `ug`.`user`=`u`.`id` + LEFT JOIN `permissions_by_group` AS `p` on `ug`.`group`=`p`.`group` +); diff --git a/source/lib/StatusBoard/Incident.class.php b/source/lib/StatusBoard/Incident.class.php index ed800d8..5010116 100644 --- a/source/lib/StatusBoard/Incident.class.php +++ b/source/lib/StatusBoard/Incident.class.php @@ -1,87 +1,28 @@ id = $id; - $this->site = $site; - $this->reference = $reference; - $this->description = $description; - $this->start_time = $start_time; - $this->estimated_end_time = $estimated_end_time; - $this->actual_end_time = $actual_end_time; - } - - public static function fromDatabaseRow($row) { - return new self( - $row['id'], - $row['site'], - $row['reference'], - $row['description'], - $row['start_time'], - $row['estimated_end_time'], - $row['actual_end_time'] - ); - } - - /** - * Load an Incident object given its ID - * - * @param int $id - * @return StatusBoard_Incident - */ - public static function fromId($id) { - $database = StatusBoard_Main::instance()->database(); - - $incident = self::fromDatabaseRow( - $database->selectOne('SELECT * FROM `incident` WHERE id=:id', array( - array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) - ) - ) - ); - - return $incident; - } - - public static function all() { - $incidents = array(); - - $database = StatusBoard_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM `incident` WHERE `id` > 0 ORDER BY `id` DESC') as $row) { - $incidents[] = self::fromDatabaseRow($row); - } - - return $incidents; - } - public static function open_for_site(StatusBoard_Site $site) { - $incidents = array(); - - $database = StatusBoard_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM `incident_open` WHERE `site`=:site ORDER BY `id` DESC', array( - array('name' => 'site', 'value' => $site->id(), 'type' => PDO::PARAM_INT), - )) as $row) { - $incidents[] = self::fromDatabaseRow($row); - } - - return $incidents; + return static::all_for('site', $site->id, 'incident_open'); } public function currentStatus($ignore_cache = false) { if ($this->current_status === null || $ignore_cache) { $database = StatusBoard_Main::instance()->database(); $row = $database->selectOne('SELECT `status` FROM `incidentstatus_current` WHERE `incident`=:incident', array( - array('name' => 'incident', 'value' => $this->id(), 'type' => PDO::PARAM_INT), + array('name' => 'incident', 'value' => $this->id, 'type' => PDO::PARAM_INT), ) ); @@ -113,65 +54,6 @@ class StatusBoard_Incident { return $status; } - protected function create() { - $database = StatusBoard_Main::instance()->database(); - $database->insert( - 'INSERT INTO `service` - (`id`, `site`, `reference`, `description`, `start_time`, `estimated_end_time`, `actual_end_time`) - VALUES(NULL, :site, :reference, :description, :start_time, :estimated_end_time, :actual_end_time)', - array( - array('name' => 'site', 'value' => $this->site, 'type' => PDO::PARAM_INT), - array('name' => 'reference', 'value' => $this->reference, 'type' => PDO::PARAM_STR), - array('name' => 'description', 'value' => $this->description, 'type' => PDO::PARAM_STR), - array('name' => 'start_time', 'value' => $this->start_time, 'type' => PDO::PARAM_INT), - array('name' => 'estimated_end_time', 'value' => $this->estimated_end_time, 'type' => PDO::PARAM_INT), - array('name' => 'actual_end_time', 'value' => $this->actual_end_time, 'type' => PDO::PARAM_INT), - ) - ); - - $this->id = $database->lastInsertId(); - } - - public function delete() { - $database = StatusBoard_Main::instance()->database(); - $database->update( - 'DELETE FROM `incident` WHERE `id`=:id LIMIT 1', - array( - array('name' => 'id', 'value' => $this->id, 'type' => PDO::PARAM_INT), - ) - ); - - $this->id = null; - } - - public function id() { - return $this->id; - } - - public function site() { - return $this->site; - } - - public function reference() { - return $this->reference; - } - - public function description() { - return $this->description; - } - - public function start_time() { - return $this->start_time; - } - - public function estimated_end_time() { - return $this->estimated_end_time; - } - - public function actual_end_time() { - return $this->actual_end_time; - } - } -?> +?> \ No newline at end of file diff --git a/source/lib/StatusBoard/IncidentStatus.class.php b/source/lib/StatusBoard/IncidentStatus.class.php index 4639f6f..ba32a91 100644 --- a/source/lib/StatusBoard/IncidentStatus.class.php +++ b/source/lib/StatusBoard/IncidentStatus.class.php @@ -1,83 +1,14 @@ id = $id; - $this->incident = $incident; - $this->status = $status; - $this->ctime = $ctime; - } - - /** - * Load an Incident object given its ID - * - * @param int $id - * @return StatusBoard_Incident - */ - public static function fromId($id) { - $database = StatusBoard_Main::instance()->database(); - - $incident_status = self::fromDatabaseRow( - $database->selectOne('SELECT * FROM `incidentstatus` WHERE id=:id', array( - array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) - ) - ) - ); - - return $incident_status; - } - - protected function create() { - $database = StatusBoard_Main::instance()->database(); - $database->insert( - 'INSERT INTO `incidentstatus` - (`id`, `incident`, `status`, `ctime`) - VALUES(NULL, :incident, :status, :ctime)', - array( - array('name' => 'incident', 'value' => $this->incident, 'type' => PDO::PARAM_INT), - array('name' => 'status', 'value' => $this->status, 'type' => PDO::PARAM_STR), - array('name' => 'ctime', 'value' => $this->ctime, 'type' => PDO::PARAM_STR), - ) - ); - - $this->id = $database->lastInsertId(); - } - - public function delete() { - $database = StatusBoard_Main::instance()->database(); - $database->update( - 'DELETE FROM `incidentstatus` WHERE `id`=:id LIMIT 1', - array( - array('name' => 'id', 'value' => $this->id, 'type' => PDO::PARAM_INT), - ) - ); - - $this->id = null; - } - - public function id() { - return $this->id; - } - - public function incident() { - return $this->incident; - } - - public function status() { - return $this->status; - } - - public function ctime() { - return $this->ctime; - } - - + protected $_db_id; + protected $_db_incident; + protected $_db_status; + protected $_db_ctime; + } ?> \ No newline at end of file diff --git a/source/lib/StatusBoard/Service.class.php b/source/lib/StatusBoard/Service.class.php index ef003b4..64c1589 100644 --- a/source/lib/StatusBoard/Service.class.php +++ b/source/lib/StatusBoard/Service.class.php @@ -1,84 +1,15 @@ id = $id; - $this->name = $name; - $this->description = $description; - } - - public static function fromDatabaseRow($row) { - return new self( - $row['id'], - $row['name'], - $row['description'] - ); - } - - /** - * Load a Service object given its ID - * - * @param int $id - * @return StatusBoard_Service - */ - public static function fromId($id) { - $database = StatusBoard_Main::instance()->database(); - - $service = self::fromDatabaseRow( - $database->selectOne('SELECT * FROM `service` WHERE id=:id', array( - array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) - ) - ) - ); - - return $service; - } - - public static function all() { - $services = array(); - - $database = StatusBoard_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM `service` WHERE `id` > 0 ORDER BY `id` DESC') as $row) { - $services[] = self::fromDatabaseRow($row); - } - - return $services; - } - - protected function create() { - $database = StatusBoard_Main::instance()->database(); - $database->insert( - 'INSERT INTO `service` - (`id`, `name`, `description`) - VALUES(NULL, :name, :description)', - array( - array('name' => 'name', 'value' => $this->name, 'type' => PDO::PARAM_STR), - array('name' => 'description', 'value' => $this->description, 'type' => PDO::PARAM_STR), - ) - ); - - $this->id = $database->lastInsertId(); - } - - public function delete() { - $database = StatusBoard_Main::instance()->database(); - $database->update( - 'DELETE FROM `service` WHERE `id`=:id LIMIT 1', - array( - array('name' => 'id', 'value' => $this->id, 'type' => PDO::PARAM_INT), - ) - ); - - $this->id = null; - } + protected $_db_id; + protected $_db_name; + protected $_db_description; + protected $sites = null; + public function sites($ignore_cache = false) { if ($this->sites === null || $ignore_cache) { $this->sites = StatusBoard_Site::all_for_service($this); @@ -86,19 +17,7 @@ class StatusBoard_Service { return $this->sites; } - - public function id() { - return $this->id; - } - - public function name() { - return $this->name; - } - - public function description() { - return $this->description; - } - + } diff --git a/source/lib/StatusBoard/Site.class.php b/source/lib/StatusBoard/Site.class.php index 666e1cf..30ac219 100644 --- a/source/lib/StatusBoard/Site.class.php +++ b/source/lib/StatusBoard/Site.class.php @@ -1,101 +1,20 @@ id = $id; - $this->service = $service; - $this->name = $name; - $this->description = $description; - } - - public static function fromDatabaseRow($row) { - return new self( - $row['id'], - $row['service'], - $row['name'], - $row['description'] - ); - } - - /** - * Load a Site object given its ID - * - * @param int $id - * @return StatusBoard_Site - */ - public static function fromId($id) { - $database = StatusBoard_Main::instance()->database(); - - $site = self::fromDatabaseRow( - $database->selectOne('SELECT * FROM `site` WHERE id=:id', array( - array('name' => 'id', 'value' => $id, 'type' => PDO::PARAM_INT) - ) - ) - ); - - return $site; - } - - public static function all() { - $sites = array(); - - $database = StatusBoard_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM `site` WHERE `id` > 0 ORDER BY `id` DESC') as $row) { - $sites[] = self::fromDatabaseRow($row); - } - - return $sites; - } + protected $incidents = null; + protected $incidents_open = null; public static function all_for_service(StatusBoard_Service $service) { - $sites = array(); - - $database = StatusBoard_Main::instance()->database(); - foreach ($database->selectList('SELECT * FROM `site` WHERE `service`=:service ORDER BY `id` DESC', array( - array('name' => 'service', 'value' => $service->id(), 'type' => PDO::PARAM_INT), - )) as $row) { - $sites[] = self::fromDatabaseRow($row); - } - - return $sites; - } - - protected function create() { - $database = StatusBoard_Main::instance()->database(); - $database->insert( - 'INSERT INTO `service` - (`id`, `service`, `name`, `description`) - VALUES(NULL, :service, :name, :description)', - array( - array('name' => 'service', 'value' => $this->service, 'type' => PDO::PARAM_INT), - array('name' => 'name', 'value' => $this->name, 'type' => PDO::PARAM_STR), - array('name' => 'description', 'value' => $this->description, 'type' => PDO::PARAM_STR), - ) - ); - - $this->id = $database->lastInsertId(); - } - - public function delete() { - $database = StatusBoard_Main::instance()->database(); - $database->update( - 'DELETE FROM `site` WHERE `id`=:id LIMIT 1', - array( - array('name' => 'id', 'value' => $this->id, 'type' => PDO::PARAM_INT), - ) - ); - - $this->id = null; - } + return static::all_for('service', $service->id); + } public function openIncidents() { if ($this->incidents_open === null || $ignore_cache) { @@ -108,23 +27,6 @@ class StatusBoard_Site { public function status() { return StatusBoard_Incident::highestSeverityStatus($this->openIncidents()); } - - public function id() { - return $this->id; - } - - public function service() { - return $this->service; - } - - public function name() { - return $this->name; - } - - public function description() { - return $this->description; - } - }