Merge lp:~vierbergenlars/remotecp-panel/offline-db-access into lp:~vierbergenlars/remotecp-panel/trunk

Proposed by Lars Vierbergen
Status: Merged
Approved by: Lars Vierbergen
Approved revision: 207
Merged at revision: 208
Proposed branch: lp:~vierbergenlars/remotecp-panel/offline-db-access
Merge into: lp:~vierbergenlars/remotecp-panel/trunk
Diff against target: 287 lines (+179/-7)
10 files modified
inc/controllers.php (+3/-1)
inc/exceptions/database.php (+143/-0)
inc/exceptions/exceptions.php (+6/-0)
inc/exceptions/handler.php (+11/-0)
inc/rdb/auth.php (+0/-3)
inc/rdb/db_info.php (+1/-0)
inc/rdb/rdb.php (+2/-1)
remote_panel.php (+11/-0)
system_remote/database.php (+1/-1)
system_remote/desktop.php (+1/-1)
To merge this branch: bzr merge lp:~vierbergenlars/remotecp-panel/offline-db-access
Reviewer Review Type Date Requested Status
Lars Vierbergen Approve
Review via email: mp+79880@code.launchpad.net

Description of the change

Add remote database offline access to admin area (offline-db-access blueprint)

To post a comment you must log in.
207. By Lars Vierbergen

Started implementation of blueprint offline-db-access.
Add exceptions

Revision history for this message
Lars Vierbergen (vierbergenlars) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'inc/controllers.php'
--- inc/controllers.php 2011-09-02 16:38:47 +0000
+++ inc/controllers.php 2011-10-19 19:44:25 +0000
@@ -1,7 +1,9 @@
1<?php //@./inc/controllers.php ?><?php1<?php //@./inc/controllers.php ?><?php
2require_once 'inc/exceptions/exceptions.php';
2require_once 'inc/errorhandler.php';3require_once 'inc/errorhandler.php';
3require_once 'inc/utils/magic_quotes.php';4require_once 'inc/utils/magic_quotes.php';
4ob_start('ob_gzhandler');5//ob_start('ob_gzhandler');
6ob_start();
5header('Cache-Control: private');7header('Cache-Control: private');
6require_once 'inc/sitemgmt/constants.php';8require_once 'inc/sitemgmt/constants.php';
7require_once 'inc/JavaScript_errorhandler.php';9require_once 'inc/JavaScript_errorhandler.php';
810
=== added directory 'inc/exceptions'
=== added file 'inc/exceptions/database.php'
--- inc/exceptions/database.php 1970-01-01 00:00:00 +0000
+++ inc/exceptions/database.php 2011-10-19 19:44:25 +0000
@@ -0,0 +1,143 @@
1<?php
2/**
3 * Handles exceptions related to the database
4 * @author Lars Vierbergen
5 * @package exceptions
6 */
7class DatabaseException extends RuntimeException {
8 /**
9 * Unknown error
10 * @var int
11 */
12 const unknown=0;
13 /**
14 * Connection error
15 * @var int
16 */
17 const connect=1;
18 /**
19 * Query error
20 * @var int
21 */
22 const query=2;
23 /**
24 * Error on a row operation
25 * @var int
26 */
27 const row=4;
28 /**
29 * Error on a SELECT statement
30 * @var int
31 */
32 const select=8;
33 /**
34 * Error on an UPDATE statement
35 * @var int
36 */
37 const update=16;
38 /**
39 * Error on an INSERT statement
40 * @var int
41 */
42 const insert=32;
43 /**
44 * Error on a DELETE statement
45 * @var int
46 */
47 const delete=64;
48 /**
49 * Error on a table operation
50 * @var int
51 */
52 const table=128;
53 /**
54 * Error on a SHOW statement
55 * @var int
56 */
57 const show=156;
58 /**
59 * Error on an ALTER statement
60 * @var int
61 */
62 const alter=512;
63 /**
64 * Error on a CREATE statement
65 * @var int
66 */
67 const create=1024;
68 /**
69 * Error on a DROP statement
70 * @var int
71 */
72 const drop=2048;
73 /**
74 * The table on which the error occurs
75 * @var string
76 */
77 protected $table='';
78 /**
79 * Throw a database-related error
80 * @param string $table The table on which the error occured
81 * @param int $code Explanation of the error by using class constants
82 * @param Exception $previous The previous exception
83 */
84 function __construct($table='' ,$code=0, Exception $previous=NULL) {
85 $this->table=$table;
86 $this->code=$code;
87 parent::__construct('Database failed on '.$this->table,$code,$previous);
88 }
89 /**
90 * Get the table on which the exception occured
91 * @return string Table name
92 */
93 final function getTable() {
94 return $this->table;
95 }
96 /**
97 * Get the type of the failure, the error codes are converted to a single string
98 * @return string String representation of the exact exception that occured
99 */
100 final function getFailureType() {
101 $errors='';
102 if($this->code==self::unknown) {
103 return 'UNKNOWN';
104 }
105 if($this->code&self::connect) {
106 $errors.='connect>';
107 }
108 if($this->code&self::query) {
109 $errors.='query>';
110 }
111 if($this->code&self::row) {
112 $errors.='row:';
113 }
114 if($this->code&self::select) {
115 $errors.='select,';
116 }
117 if($this->code&self::update) {
118 $errors.='update,';
119 }
120 if($this->code&self::insert) {
121 $errors.='insert,';
122 }
123 if($this->code&self::delete) {
124 $errors.='delete,';
125 }
126 if($this->code&self::table) {
127 $errors.='table:';
128 }
129 if($this->code&self::show) {
130 $errors.='show,';
131 }
132 if($this->code&self::alter) {
133 $errors.='alter,';
134 }
135 if($this->code&self::create) {
136 $errors.='create,';
137 }
138 if($this->code&self::drop) {
139 $errors.='drop,';
140 }
141 return substr($errors,0,-1);
142 }
143}
0\ No newline at end of file144\ No newline at end of file
1145
=== added file 'inc/exceptions/exceptions.php'
--- inc/exceptions/exceptions.php 1970-01-01 00:00:00 +0000
+++ inc/exceptions/exceptions.php 2011-10-19 19:44:25 +0000
@@ -0,0 +1,6 @@
1<?php
2/**
3 * A list of exceptions used by RemoteCP
4 * @package exceptions
5 */
6require 'database.php';
07
=== added file 'inc/exceptions/handler.php'
--- inc/exceptions/handler.php 1970-01-01 00:00:00 +0000
+++ inc/exceptions/handler.php 2011-10-19 19:44:25 +0000
@@ -0,0 +1,11 @@
1<?php
2function default_exception_handler($e,$type) {
3 header('HTTP/1.1 500 Internal Server Error');
4 $es=$type.': <i>'.get_class($e).'</i>: <b>'.$e->getMessage().'</b> in <b>'.$e->getFile().'</b> on </b>'.$e->getLine().'</b>';
5 if(defined('__DEBUG__')&&__DEBUG__) {
6 $es.='<hr>Trace:<br><pre>';
7 $es.=$e->getTraceAsString();
8 $es.='</pre>';
9 }
10 echo '<h1>Internal Server Error</h1>'.$es;
11}
0\ No newline at end of file12\ No newline at end of file
113
=== modified file 'inc/rdb/auth.php'
--- inc/rdb/auth.php 2011-09-02 16:38:47 +0000
+++ inc/rdb/auth.php 2011-10-19 19:44:25 +0000
@@ -39,9 +39,6 @@
39 else {39 else {
40 $remote_connection=@new MySQLi($rdbauth['host'],$rdbauth['user'],$rdbauth['password'],$rdbauth['database']);40 $remote_connection=@new MySQLi($rdbauth['host'],$rdbauth['user'],$rdbauth['password'],$rdbauth['database']);
41 }41 }
42 if(!@$remote_connection->ping()) {
43 trigger_error('Could not connect to the remote database',E_USER_ERROR);
44 }
45 return $remote_connection;42 return $remote_connection;
46 }43 }
47}44}
4845
=== modified file 'inc/rdb/db_info.php'
--- inc/rdb/db_info.php 2011-09-26 17:38:10 +0000
+++ inc/rdb/db_info.php 2011-10-19 19:44:25 +0000
@@ -3,6 +3,7 @@
3 static private $info=array();3 static private $info=array();
4 static function init() {4 static function init() {
5 global $remote_connection;5 global $remote_connection;
6 if(!@$remote_connection->ping()) throw new DatabaseException('Remote database is down',DatabaseException::connect);
6 $q=$remote_connection->query('SELECT * FROM `_system_`');7 $q=$remote_connection->query('SELECT * FROM `_system_`');
7 while($r=$q->fetch_array()) {8 while($r=$q->fetch_array()) {
8 self::$info[$r[0]]=$r[1];9 self::$info[$r[0]]=$r[1];
910
=== modified file 'inc/rdb/rdb.php'
--- inc/rdb/rdb.php 2011-09-26 16:13:19 +0000
+++ inc/rdb/rdb.php 2011-10-19 19:44:25 +0000
@@ -5,10 +5,11 @@
5*/5*/
6require_once('inc/rdb/auth.php');6require_once('inc/rdb/auth.php');
7if(!rdb_auth::$exists) {7if(!rdb_auth::$exists) {
8 trigger_error('Remote database does not exist',E_USER_ERROR);8 throw new DatabaseException('Remote database does not exist',DatabaseException::connect);
9}9}
10else {10else {
11 $remote_connection=rdb_auth::connect();11 $remote_connection=rdb_auth::connect();
12 if(!@$remote_connection->ping()) throw new DatabaseException('Remote database is not accessible',DatabaseException::connect);
12}13}
13require_once 'inc/rdb/db_info.php';14require_once 'inc/rdb/db_info.php';
14?>15?>
15\ No newline at end of file16\ No newline at end of file
1617
=== modified file 'remote_panel.php'
--- remote_panel.php 2011-10-18 18:14:57 +0000
+++ remote_panel.php 2011-10-19 19:44:25 +0000
@@ -6,9 +6,20 @@
6 * This file is called from the webbrowser when using RemoteCP to connect to a remote database.6 * This file is called from the webbrowser when using RemoteCP to connect to a remote database.
7 */ 7 */
8require('inc/controllers.php');8require('inc/controllers.php');
9try {
9require_once('inc/rdb/rdb.php');10require_once('inc/rdb/rdb.php');
10require_once('inc/groups/groups.php');11require_once('inc/groups/groups.php');
11require_once('inc/accountlevels.php');12require_once('inc/accountlevels.php');
13}
14catch(DatabaseException $e) {
15 if($e->getCode()==DatabaseException::connect) {
16 define('REMOTEDB_DOWN',true);
17 }
18 else {
19 default_exception_handler($e, 'DatabaseException');
20 exit;
21 }
22}
12$t->addFile(__FILE__);23$t->addFile(__FILE__);
13//Basic HTML start24//Basic HTML start
14?>25?>
1526
=== modified file 'system_remote/database.php'
--- system_remote/database.php 2011-09-26 16:13:19 +0000
+++ system_remote/database.php 2011-10-19 19:44:25 +0000
@@ -54,7 +54,7 @@
54 </fieldset>54 </fieldset>
55 <fieldset>55 <fieldset>
56 <legend><?php echo $t->_('Information')?></legend>56 <legend><?php echo $t->_('Information')?></legend>
57 <?php echo $t->_('Filesystem'); ?>: <?php echo rdb_info::getInfo('fs'); ?>57 <?php echo $t->_('Filesystem'); ?>: <?php if(defined('REMOTEDB_DOWN')&&REMOTEDB_DOWN) echo $t->_('Remote database is down'); else echo rdb_info::getInfo('fs'); ?>
58 </fieldset>58 </fieldset>
59 <fieldset>59 <fieldset>
60 <legend><?php echo $t->_('Delete database'); ?></legend>60 <legend><?php echo $t->_('Delete database'); ?></legend>
6161
=== modified file 'system_remote/desktop.php'
--- system_remote/desktop.php 2011-06-28 16:13:01 +0000
+++ system_remote/desktop.php 2011-10-19 19:44:25 +0000
@@ -4,7 +4,7 @@
4<AJAX_SCRIPTEVAL>NULL</AJAX_SCRIPTEVAL>4<AJAX_SCRIPTEVAL>NULL</AJAX_SCRIPTEVAL>
5< HEADERS -->5< HEADERS -->
6<?php if(rdb_auth::$level==9) {6<?php if(rdb_auth::$level==9) {
7 ?>| <a onclick="openLoc('<?php echo $t->_('Administration'); ?>','?control=admin','admin');"><?php echo $t->_('Administration'); ?></a> |<?php } ?>| <a onclick="openLoc('<?php echo $t->_('Groups'); ?>','?control=groups','groups');"><?php echo $t->_('Groups'); ?></a> |7 ?>| <a onclick="openLoc('<?php echo $t->_('Administration'); ?>','?control=admin','admin');"><?php echo $t->_('Administration'); ?></a> |<?php } if(defined('REMOTEDB_DOWN')&&REMOTEDB_DOWN) {die('<hr>'.$t->_('Remote database is not available'));} ?>| <a onclick="openLoc('<?php echo $t->_('Groups'); ?>','?control=groups','groups');"><?php echo $t->_('Groups'); ?></a> |
8<hr><?php8<hr><?php
9 $q=$remote_connection->query('SELECT * FROM `sites` WHERE `user`="'.session::$guid.'"');9 $q=$remote_connection->query('SELECT * FROM `sites` WHERE `user`="'.session::$guid.'"');
10 while($sites=$q->fetch_assoc()) { ?>| <a onclick="openLoc('<?php echo getSiteInfo($sites['ref'],'SITE_TITLE'); ?>','?control=addons&site=<?php echo $sites['ref']; ?>','<?php echo $sites['ref']; ?>_ctrls_main');"><?php echo getSiteInfo($sites['ref'],'SITE_TITLE'); ?></a> |<?php }10 while($sites=$q->fetch_assoc()) { ?>| <a onclick="openLoc('<?php echo getSiteInfo($sites['ref'],'SITE_TITLE'); ?>','?control=addons&site=<?php echo $sites['ref']; ?>','<?php echo $sites['ref']; ?>_ctrls_main');"><?php echo getSiteInfo($sites['ref'],'SITE_TITLE'); ?></a> |<?php }

Subscribers

People subscribed via source and target branches

to all changes: