d499ab85a1f16ceffbc6067b09b38aeabe2676a6
Author: Jonathan Bradley
Date: 2009-07-24 01:24:13 -0400
diff --git a/config/routes.php b/config/routes.php
index e020d4a..b5ad15f 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -34,9 +34,9 @@
if (file_exists(TMP.'not_installed.txt')) {
Router::connect('/:action', array('controller' => 'installer'));
} else {
- Router::connect('/', array('controller' => 'users', 'action' => 'login'));
+ Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
}
- Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
+
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
diff --git a/controllers/crons_controller.php b/controllers/crons_controller.php
index 983d647..f7e03ed 100644
--- a/controllers/crons_controller.php
+++ b/controllers/crons_controller.php
@@ -3,7 +3,7 @@
class CronsController extends AppController {
var $name = 'crons';
- var $uses = array('User', 'Domain', 'Registered');
+ var $uses = array('User', 'Domain', 'Registered', 'Hostname');
var $components = array('Dreamhost');
function beforeFilter() {
@@ -15,6 +15,7 @@ class CronsController extends AppController {
$this->users(0);
$this->domains(0);
$this->registered(0);
+ $this->hostnames(0);
$this->Session->setFlash('First Data Aggregation done');
$this->redirect(array('controller' => 'domains'));
}
@@ -42,6 +43,7 @@ class CronsController extends AppController {
function domains($redirect = 1) {
$data = $this->Dreamhost->find('domain-list_domains');
+ echo '<pre>'; print_r($data); die;
$this->Domain->truncate();
foreach ($data as $key => $value) {
$domain['Domain'] = (array)$value;
@@ -49,6 +51,8 @@ class CronsController extends AppController {
$domain['Domain']['user_id'] = $this->User->getUser($value->user);
}
+ echo '<pre>'; print_r($domain); die;
+
if ($this->Domain->check($domain) == 0) {
$this->Domain->create();
$this->Domain->save($domain);
@@ -60,8 +64,30 @@ class CronsController extends AppController {
if ($redirect == 1) {
$this->Session->setFlash('Database updated');
$this->redirect(array('controller' => 'domains', 'action' => 'index'));
+ }
+ }
+
+
+ function hostnames($redirect = 1) {
+ $this->domains(0);
+ $data = $this->Dreamhost->find('mysql-list_hostnames');
+ $this->Hostname->truncate();
+ foreach ($data as $key => $value) {
+ $hostname['Hostname'] = (array)$value;
+ $hostname['Hostname']['domain_id'] = $this->Domain->getDomain($value->domain);
+
+ if ($this->Hostname->check($hostname) == 0) {
+ $this->Hostname->create();
+ $this->Hostname->save($hostname);
+ }
+ else {
+ $this->Hostname->save($hostname['Hostname']);
+ }
}
-
+ if ($redirect == 1) {
+ $this->Session->setFlash('Database updated');
+ $this->redirect(array('controller' => 'databases', 'action' => 'hostnames'));
+ }
}
function registered($redirect = 1) {
diff --git a/controllers/databases_controller.php b/controllers/databases_controller.php
index b096cd4..6a87837 100644
--- a/controllers/databases_controller.php
+++ b/controllers/databases_controller.php
@@ -1,21 +1,17 @@
<?php
-class DatabasesController extends DreamhostAppController {
+class DatabasesController extends AppController {
var $name = 'Databases';
- var $uses = array('Dreamhost.Database', 'Dreamhost.Domain');
+ var $uses = array('Hostname', 'Domain');
+ var $components = array('Dreamhost');
function beforeFilter() {
parent::beforeFilter();
}
- function index() {
- $data = $this->Database->find('mysql-list_dbs');
- $this->set(compact('data'));
- }
-
function hostnames() {
- $data = $this->Domain->find('mysql-list_hostnames');
+ $data = $this->Hostname->find('all');
$this->set(compact('data'));
}
@@ -24,8 +20,8 @@ class DatabasesController extends DreamhostAppController {
$this->set(compact('data'));
}
- function delete_hostname($hostname) {
- $response = $this->Database->delete('mysql-remove_hostname', array('hostname' => $hostname));
+ function delete_hostname($hostname, $id) {
+ $response = $this->Dreamhost->delete('mysql-remove_hostname', array('hostname' => $hostname));
switch ($response) {
case 'hostname_removed':
case 'success':
@@ -37,22 +33,29 @@ class DatabasesController extends DreamhostAppController {
$this->Session->setFlash('Hostname Not Deleted');
break;
}
+ $this->Hostname->del($id);
$this->redirect('hostnames', null, false);
}
function add_host() {
if (!empty($this->data)) {
$hostname = implode('.', $this->data['Database']);
- $response = $this->Database->save(array('hostname' => $hostname));
-
-
+ $response = $this->Dreamhost->save(array('hostname' => $hostname));
$response = str_replace('_', ' ', $response);
$response = ucwords($response);
$this->Session->setFlash($response);
- $this->redirect('hostnames', null, false);
+ $this->redirect(array('controller' => 'crons', 'action' => 'hostnames'), null, false);
+ }
+ $domain = $this->domains();
+ $this->set(compact('domain'));
+ }
+
+ function domains() {
+ $domains = $this->Domain->find('list', array('fields' => array('Domain.id', 'Domain.domain')));
+ foreach ($domains as $key => $value) {
+ $domain[$value] = $value;
}
- $domains = $this->Database->domains();
- $this->set(compact('domains'));
+ return $domain;
}
}
?>
\ No newline at end of file
diff --git a/models/domain.php b/models/domain.php
index 4477067..e33881a 100644
--- a/models/domain.php
+++ b/models/domain.php
@@ -16,6 +16,16 @@ class Domain extends AppModel {
'conditions' => array('Domain.type !=' => 'mysqldns'),
'fields' => array('Domain.domain', 'Domain.path', 'Domain.home', 'User.username', 'User.password', 'User.shell', 'User.type')
));
+ }
+
+ function getDomain($domain) {
+ $domain = $this->find('first', array(
+ 'conditions' => array(
+ 'domain' => $domain
+ ),
+ 'fields' => array('Domain.id')
+ ));
+ return $domain['Domain']['id'];
}
function check($data) {
diff --git a/models/hostname.php b/models/hostname.php
new file mode 100644
index 0000000..960179a
--- /dev/null
+++ b/models/hostname.php
@@ -0,0 +1,33 @@
+<?php
+
+class Hostname extends AppModel {
+
+ var $name = 'Hostname';
+ var $belongsTo = array(
+ 'Domain' => array(
+ 'className' => 'Domain',
+ 'foreignKey' => 'domain_id'
+ )
+ );
+
+ function getList() {
+ return $this->find('all', array(
+ 'conditions' => array('Domain.type !=' => 'mysqldns'),
+ 'fields' => array('Domain.domain', 'Domain.path', 'Domain.home', 'User.username', 'User.password', 'User.shell', 'User.type')
+ ));
+ }
+
+ function check($data) {
+ return $this->find('count', array(
+ 'conditions' => array(
+ 'domain' => $data['Domain']['domain']
+ )
+ ));
+ return $domain;
+ }
+
+ function truncate() {
+ $this->query('TRUNCATE TABLE ' . $this->useTable);
+ }
+}
+?>
\ No newline at end of file
diff --git a/tmp/logs/debug.log b/tmp/logs/debug.log
index 1932bf7..f882d99 100644
--- a/tmp/logs/debug.log
+++ b/tmp/logs/debug.log
@@ -67,3 +67,22 @@
2009-07-23 00:05:03 Debug: Notice (8): Undefined variable: form in [APP\views\settings\config.ctp, line 3]
2009-07-23 00:06:22 Debug: Notice (8): Undefined variable: new in [APP\controllers\crons_controller.php, line 30]
2009-07-23 00:08:42 Debug: Notice (8): Undefined index: Reserved in [APP\models\registered.php, line 11]
+2009-07-23 00:33:51 Debug: Notice (8): Undefined variable: old in [APP\controllers\crons_controller.php, line 34]
+2009-07-23 00:41:20 Debug: Notice (8): Undefined property: stdClass::$id in [APP\controllers\crons_controller.php, line 72]
+2009-07-23 00:43:42 Debug: Notice (8): Undefined index: Domain in [APP\models\hostname.php, line 23]
+2009-07-23 00:44:59 Debug: Notice (8): Trying to get property of non-object in [APP\views\databases\hostnames.ctp, line 11]
+2009-07-23 00:44:59 Debug: Notice (8): Trying to get property of non-object in [APP\views\databases\hostnames.ctp, line 12]
+2009-07-23 00:44:59 Debug: Notice (8): Trying to get property of non-object in [APP\views\databases\hostnames.ctp, line 15]
+2009-07-23 00:48:16 Debug: Notice (8): Undefined property: DatabasesController::$Dreamohost in [APP\controllers\databases_controller.php, line 24]
+2009-07-23 00:49:27 Debug: Notice (8): Undefined property: DatabasesController::$Database in [APP\controllers\databases_controller.php, line 51]
+2009-07-23 00:50:09 Debug: Notice (8): Undefined property: DatabasesController::$Domain in [APP\controllers\databases_controller.php, line 51]
+2009-07-23 00:52:01 Debug: Notice (8): Undefined variable: domains in [APP\views\databases\add_host.ctp, line 6]
+2009-07-23 00:52:44 Debug: Notice (8): Undefined index: Domain in [APP\models\hostname.php, line 23]
+2009-07-23 00:56:24 Debug: Notice (8): Undefined index: Domain in [APP\models\hostname.php, line 23]
+2009-07-23 00:56:49 Debug: Notice (8): Undefined index: Domain in [APP\models\hostname.php, line 23]
+2009-07-23 00:57:39 Debug: Notice (8): Trying to get property of non-object in [APP\controllers\components\dreamhost.php, line 46]
+2009-07-23 00:57:54 Debug: Notice (8): Trying to get property of non-object in [APP\controllers\components\dreamhost.php, line 46]
+2009-07-23 00:58:22 Debug: Notice (8): Trying to get property of non-object in [APP\controllers\components\dreamhost.php, line 46]
+2009-07-23 00:58:31 Debug: Notice (8): Trying to get property of non-object in [APP\controllers\components\dreamhost.php, line 46]
+2009-07-23 00:58:49 Debug: Notice (8): Trying to get property of non-object in [APP\controllers\components\dreamhost.php, line 46]
+2009-07-23 00:59:28 Debug: Notice (8): Trying to get property of non-object in [APP\controllers\components\dreamhost.php, line 46]
diff --git a/tmp/logs/error.log b/tmp/logs/error.log
index 27bf40d..057a84a 100644
--- a/tmp/logs/error.log
+++ b/tmp/logs/error.log
@@ -41,3 +41,15 @@
2009-07-23 00:06:29 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 73]
2009-07-23 00:06:30 Warning: Warning (512): <span style = "color:Red;text-align:left"><b>SQL Error:</b> 1054: Unknown column 'Domain.user_id' in 'on clause'</span> in [CORE\cake\libs\model\datasources\dbo_source.php, line 525]
2009-07-23 00:06:30 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\views\domains\index.ctp, line 12]
+2009-07-23 00:41:20 Warning: Warning (512): <span style = "color:Red;text-align:left"><b>SQL Error:</b> 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getDomain' at line 1</span> in [CORE\cake\libs\model\datasources\dbo_source.php, line 525]
+2009-07-23 00:41:44 Warning: Warning (512): <span style = "color:Red;text-align:left"><b>SQL Error:</b> 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getDomain' at line 1</span> in [CORE\cake\libs\model\datasources\dbo_source.php, line 525]
+2009-07-23 00:57:39 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 47]
+2009-07-23 00:57:39 Warning: Warning (2): session_regenerate_id() [<a href='http://php.net/function.session-regenerate-id'>function.session-regenerate-id</a>]: Session object destruction failed in [CORE\cake\libs\session.php, line 599]
+2009-07-23 00:57:39 Warning: Warning (2): session_regenerate_id() [<a href='http://php.net/function.session-regenerate-id'>function.session-regenerate-id</a>]: Session object destruction failed in [CORE\cake\libs\session.php, line 599]
+2009-07-23 00:57:39 Warning: Warning (2): session_regenerate_id() [<a href='http://php.net/function.session-regenerate-id'>function.session-regenerate-id</a>]: Session object destruction failed in [CORE\cake\libs\session.php, line 599]
+2009-07-23 00:57:39 Warning: Warning (2): session_regenerate_id() [<a href='http://php.net/function.session-regenerate-id'>function.session-regenerate-id</a>]: Session object destruction failed in [CORE\cake\libs\session.php, line 599]
+2009-07-23 00:57:54 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 47]
+2009-07-23 00:57:59 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 72]
+2009-07-23 00:58:22 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 47]
+2009-07-23 00:58:23 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 74]
+2009-07-23 00:58:31 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 47]
diff --git a/tmp/not_installed.txt b/tmp/not_installed.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/vendors/shells/dreamhost.php b/vendors/shells/dreamhost.php
new file mode 100644
index 0000000..eaab263
--- /dev/null
+++ b/vendors/shells/dreamhost.php
@@ -0,0 +1,13 @@
+<?php
+class DreamhostShell extends Shell {
+ var $uses = array('User', 'Domain', 'Registered', 'Hostname');
+ var $components = array('Dreamhost');
+
+ function main() {
+ $this->users(0);
+ $this->domains(0);
+ $this->registered(0);
+ $this->hostnames(0);
+ }
+}
+?>
diff --git a/views/databases/add_host.ctp b/views/databases/add_host.ctp
index f6837bf..bcf4d2a 100644
--- a/views/databases/add_host.ctp
+++ b/views/databases/add_host.ctp
@@ -3,6 +3,6 @@
<?php
echo $form->create('Database', array('action' => 'add_host'));
echo $form->input('prefix');
-echo $form->input('domain', array('type' => 'select', 'empty' => 'Select Domain', 'options' => $domains));
+echo $form->input('domain', array('type' => 'select', 'empty' => 'Select Domain', 'options' => $domain));
echo $form->end('Add Hostname');
?>
\ No newline at end of file
diff --git a/views/databases/hostnames.ctp b/views/databases/hostnames.ctp
index 98bd073..7692d2e 100644
--- a/views/databases/hostnames.ctp
+++ b/views/databases/hostnames.ctp
@@ -1,4 +1,5 @@
<h2>Current Hostnames</h2>
+<?php echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'hostnames')); ?> |
<?php echo $html->link('Add Hostname', array('action' =>'add_host'), null, null, false) ?>
<table>
<tr>
@@ -8,11 +9,11 @@
</tr>
<?php foreach($data as $key => $value) { ?>
<tr>
- <td><?php echo $value->domain; ?></td>
- <td><?php echo $value->home; ?></td>
+ <td><?php echo $value['Domain']['domain']; ?></td>
+ <td><?php echo $value['Hostname']['home']; ?></td>
<td>
<?php
- echo $html->link('Delete', array('action' =>'delete_hostname', $value->domain), null, 'Are you sure?', false)
+ echo $html->link('Delete', array('action' =>'delete_hostname', $value['Domain']['domain'], $value['Hostname']['id']), null, 'Are you sure?', false)
?>
</td>
</tr>
diff --git a/views/elements/menu.ctp b/views/elements/menu.ctp
index faf3ac2..4ddcdd8 100644
--- a/views/elements/menu.ctp
+++ b/views/elements/menu.ctp
@@ -7,7 +7,7 @@
</ul>
</li>
<li><?php echo $html->link('Users', array('controller' => 'users', 'action' => 'index'), null, null, false); ?></li>
- <!--
+
<li><a href="#">MySQL »</a>
<ul>
<li><?php echo $html->link('Databases', array('controller' => 'databases', 'action' => 'index'), null, null, false); ?></li>
@@ -23,6 +23,5 @@
</li>
</ul>
</li>
- -->
</ul>
</div>
\ No newline at end of file
