c8a0abc6c6e003a687dd8d29638ca504e18c105b

Author: Jonathan Bradley

Date: 2009-07-26 01:42:14 -0400

moved dreamhost back to a plugin, so that it can handle multiple apis, such as github, ohloh, basecamp, lighthouse and such keeping the datasource and settings autonomous from plugin though

diff --git a/app_controller.php b/app_controller.php index 7127c94..f27c788 100644 --- a/app_controller.php +++ b/app_controller.php @@ -1,7 +1,6 @@ <?php class AppController extends Controller { - //var $components = array('DebugKit.Toolbar'); var $helpers = array('Html', 'Form', 'Javascript'); @@ -10,11 +9,9 @@ class AppController extends Controller { } function settings() { - if (file_exists(TMP . 'installed.txt')) { - $settings = ClassRegistry::init('Setting')->settings(); - $this->Session->write('Settings', $settings); - } + $settings = ClassRegistry::init('Setting')->settings(); + $this->Session->write('Settings', $settings); + } - } ?> \ No newline at end of file diff --git a/controllers/components/dreamhost.php b/controllers/components/dreamhost.php deleted file mode 100644 index b8e2ea3..0000000 --- a/controllers/components/dreamhost.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php - -class DreamhostComponent extends Object { - - var $name = 'Dreamhost'; - var $params = array(); - var $components = array('Session'); - var $key = ''; - - function initialize(&$controller, $settings = array()) { - $this->Settings =& ClassRegistry::init('Setting'); - $this->Settings = $this->Settings->settings(); - $this->key = $this->Settings['key']; - } - - function startup() { - App::import('ConnectionManager'); - $this->dreamhost =& ConnectionManager::getDataSource('dreamhost'); - } - - function uuid($prefix = array()) { - $chars = md5(microtime()); - $uuid = substr($chars,0,8) . '-'; - $uuid .= substr($chars,8,4) . '-'; - $uuid .= substr($chars,12,4) . '-'; - $uuid .= substr($chars,16,4) . '-'; - $uuid .= substr($chars,20,12); - return $this->getString($prefix, 'string') . $uuid; - } - - function getString($array = array(), $type = 'query') { - $str = ''; - if ($type == 'query') { - foreach ($array as $key => $value) { - $str .= $key . '=' . $value . '&'; - } - } - if ($type == 'string') { - foreach ($array as $key => $value) { - $str .= $key . $value; - } - } - return $str; - } - - function save($params) { - $this->dreamhost->configs($this->key, $this->uuid()); - return $this->dreamhost->connect('mysql-add_hostname', $params); - } - - function delete($cmd, $params) { - $this->dreamhost->configs($this->key, $this->uuid()); - return $this->dreamhost->connect($cmd, $params); - } - - function find($command) { - $this->dreamhost->configs($this->key, $this->uuid()); - return $this->dreamhost->connect($command); - } - -} - -?> \ No newline at end of file diff --git a/controllers/components/empty b/controllers/components/empty deleted file mode 100644 index e69de29..0000000 diff --git a/controllers/crons_controller.php b/controllers/crons_controller.php deleted file mode 100644 index 618d0a8..0000000 --- a/controllers/crons_controller.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php - -class CronsController extends AppController { - - var $name = 'crons'; - var $uses = array('User', 'Domain', 'Registered', 'Hostname'); - var $components = array('Dreamhost'); - - function beforeFilter() { - parent::beforeFilter(); - } - - function setup() { - echo 'Pulling data from dreamhost'; - $this->users(0); - $this->domains(0); - $this->registered(0); - $this->hostnames(0); - $this->Session->setFlash('First Data Aggregation done'); - $this->redirect(array('controller' => 'domains')); - } - - function users($redirect = 1) { - $data = $this->Dreamhost->find('user-list_users'); - $this->User->truncate(); - foreach ($data as $key => $value) { - - $users['User'] = (array)$value; - if ($this->User->check($users) == 0) { - $this->User->create(); - $this->User->save($users); - $new++; - } - else { - $this->User->save($users['User']); - $old++; - } - } - if ($redirect == 1) { - $this->Session->setFlash('Database updated'); - $this->redirect(array('controller' => 'users', 'action' => 'index')); - } - } - - function domains($redirect = 1) { - $data = $this->Dreamhost->find('domain-list_domains'); - $this->Domain->truncate(); - foreach ($data as $key => $value) { - $domain['Domain'] = (array)$value; - if (isset($value->user) && $value->user != null) { - $domain['Domain']['user_id'] = $this->User->getUser($value->user); - } - - - if ($this->Domain->check($domain) == 0) { - $this->Domain->create(); - $this->Domain->save($domain); - } - else { - $this->Domain->save($domain['Domain']); - } - } - 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) { - $data = $this->Dreamhost->find('domain-list_registrations'); - $this->Registered->truncate(); - foreach ($data as $key => $value) { - $registered['Registered'] = (array)$value; - - if ($this->Registered->check($registered) == 0) { - $this->Registered->create(); - $this->Registered->save($registered); - } - else { - $this->Reserved->save($registered['Registered']); - } - } - if ($redirect == 1) { - $this->Session->setFlash('Database updated'); - $this->redirect(array('controller' => 'domains', 'action' => 'registered')); - } - - } -} -?> \ No newline at end of file diff --git a/controllers/databases_controller.php b/controllers/databases_controller.php deleted file mode 100644 index 6b084ab..0000000 --- a/controllers/databases_controller.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -class DatabasesController extends AppController { - - var $name = 'Databases'; - var $uses = array('Hostname', 'Domain'); - var $components = array('Dreamhost'); - - function beforeFilter() { - parent::beforeFilter(); - } - - function hostnames() { - $data = $this->Hostname->find('all'); - $this->set(compact('data')); - } - - function users() { - $data = $this->Database->find('mysql-list_users'); - $this->set(compact('data')); - } - - function delete_hostname($hostname, $id) { - $response = $this->Dreamhost->delete('mysql-remove_hostname', array('hostname' => $hostname)); - switch ($response) { - case 'hostname_removed': - case 'success': - $this->Session->setFlash('Hostname Deleted'); - break; - case 'no_hostname': - case 'invalid_hostname': - case 'internal_error_removing_hostname': - $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->Dreamhost->save(array('hostname' => $hostname)); - $response = str_replace('_', ' ', $response); - $response = ucwords($response); - $this->Session->setFlash($response); - $this->redirect(array('controller' => 'crons', 'action' => 'hostnames'), null, false); - } - $domain = $this->Dreamhost->hostnames(); - $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; - } - return $domain; - } -} -?> \ No newline at end of file diff --git a/controllers/domains_controller.php b/controllers/domains_controller.php deleted file mode 100644 index e1d831f..0000000 --- a/controllers/domains_controller.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -class DomainsController extends AppController { - - var $name = 'Domains'; - var $uses = array('Domain', 'Registered'); - - function index() { - $data = $this->Domain->getList(); - $this->set(compact('data')); - } - - function registered() { - $data = $this->Registered->find('all'); - $this->set(compact('data')); - } -} -?> \ No newline at end of file diff --git a/controllers/installer_controller.php b/controllers/installer_controller.php deleted file mode 100644 index d77de46..0000000 --- a/controllers/installer_controller.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -// app/controllers/ -uses('model' . DS . 'connection_manager'); - -class InstallerController extends AppController { - var $name = 'Installer'; - var $uses = array(); - var $helpers = array('Html'); - - function beforeFilter() { - if (!file_exists(TMP.'not_installed.txt')) { - echo('Application is already installed. Create app/config/not_installed.txt to reinstall the application.'); - exit(); - } - } - - function index() { - $this->__createTables(); - } - - - private function __createTables() { - $db = ConnectionManager::getDataSource('default'); - $this->__executeSQLScript($db, CONFIGS.'sql'.DS.'app.sql'); - unlink(TMP.'not_installed.txt'); - $this->redirect('/settings/config'); - } - - private function __executeSQLScript($db, $fileName) { - echo "__executeSQLScript()<br>"; - - $statements = file_get_contents($fileName); - $statements = explode(';', $statements); - - foreach ($statements as $statement) { - if (trim($statement) != '') { - $db->query($statement); - } - } - } -} -?> \ No newline at end of file diff --git a/controllers/settings_controller.php b/controllers/settings_controller.php index 93fca0c..47e46ae 100644 --- a/controllers/settings_controller.php +++ b/controllers/settings_controller.php @@ -3,6 +3,7 @@ class SettingsController extends AppController { var $name = 'Settings'; + var $uses = array('Setting'); function config() { if (!empty($this->data)) { diff --git a/controllers/users_controller.php b/controllers/users_controller.php deleted file mode 100644 index 172257d..0000000 --- a/controllers/users_controller.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -class UsersController extends AppController { - - var $name = 'Users'; - - function index() { - $data = $this->User->getList(); - $this->set(compact('data')); - } -} -?> \ No newline at end of file diff --git a/models/domain.php b/models/domain.php deleted file mode 100644 index e33881a..0000000 --- a/models/domain.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -class Domain extends AppModel { - - var $name = 'Domain'; - var $actAs = array('Containable'); - var $belongsTo = array( - 'User' => array( - 'className' => 'User', - 'foreignKey' => 'user_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 getDomain($domain) { - $domain = $this->find('first', array( - 'conditions' => array( - 'domain' => $domain - ), - 'fields' => array('Domain.id') - )); - return $domain['Domain']['id']; - } - - function check($data) { - return $this->find('count', array( - 'conditions' => array( - 'domain' => $data['Domain']['domain'] - ) - )); - } - - function truncate() { - $this->query('TRUNCATE TABLE ' . $this->useTable); - } -} -?> \ No newline at end of file diff --git a/models/hostname.php b/models/hostname.php deleted file mode 100644 index 92c46ad..0000000 --- a/models/hostname.php +++ /dev/null @@ -1,33 +0,0 @@ -<?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['Hostname']['domain'] - ) - )); - return $domain; - } - - function truncate() { - $this->query('TRUNCATE TABLE ' . $this->useTable); - } -} -?> \ No newline at end of file diff --git a/models/registered.php b/models/registered.php deleted file mode 100644 index 0e422c1..0000000 --- a/models/registered.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -class Registered extends AppModel { - - var $name = 'Registered'; - var $useTable = 'registered'; - - function check($data) { - return $this->find('count', array( - 'conditions' => array( - 'domain' => $data['Reserved']['domain'] - ) - )); - } - - function truncate() { - $this->query('TRUNCATE TABLE ' . $this->useTable); - } -} -?> \ No newline at end of file diff --git a/models/user.php b/models/user.php deleted file mode 100644 index 075e877..0000000 --- a/models/user.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -class User extends AppModel { - - var $name = 'User'; - - function getList() { - return $this->find('all', array( - 'fields' => array('User.username', 'User.home', 'User.password', 'User.shell', 'User.type') - )); - } - - function check($data) { - return $this->find('count', array( - 'conditions' => array( - 'username' => $data['User']['username'] - ) - )); - } - - function getUser($username) { - $user = $this->find('first', array( - 'conditions' => array( - 'username' => $username - ), - 'fields' => array('User.id') - )); - return $user['User']['id']; - } - - function truncate() { - $this->query('TRUNCATE TABLE ' . $this->useTable); - } -} -?> \ No newline at end of file diff --git a/plugins/dreamhost/controllers/components/dreamhost.php b/plugins/dreamhost/controllers/components/dreamhost.php new file mode 100644 index 0000000..b8e2ea3 --- /dev/null +++ b/plugins/dreamhost/controllers/components/dreamhost.php @@ -0,0 +1,63 @@ +<?php + +class DreamhostComponent extends Object { + + var $name = 'Dreamhost'; + var $params = array(); + var $components = array('Session'); + var $key = ''; + + function initialize(&$controller, $settings = array()) { + $this->Settings =& ClassRegistry::init('Setting'); + $this->Settings = $this->Settings->settings(); + $this->key = $this->Settings['key']; + } + + function startup() { + App::import('ConnectionManager'); + $this->dreamhost =& ConnectionManager::getDataSource('dreamhost'); + } + + function uuid($prefix = array()) { + $chars = md5(microtime()); + $uuid = substr($chars,0,8) . '-'; + $uuid .= substr($chars,8,4) . '-'; + $uuid .= substr($chars,12,4) . '-'; + $uuid .= substr($chars,16,4) . '-'; + $uuid .= substr($chars,20,12); + return $this->getString($prefix, 'string') . $uuid; + } + + function getString($array = array(), $type = 'query') { + $str = ''; + if ($type == 'query') { + foreach ($array as $key => $value) { + $str .= $key . '=' . $value . '&'; + } + } + if ($type == 'string') { + foreach ($array as $key => $value) { + $str .= $key . $value; + } + } + return $str; + } + + function save($params) { + $this->dreamhost->configs($this->key, $this->uuid()); + return $this->dreamhost->connect('mysql-add_hostname', $params); + } + + function delete($cmd, $params) { + $this->dreamhost->configs($this->key, $this->uuid()); + return $this->dreamhost->connect($cmd, $params); + } + + function find($command) { + $this->dreamhost->configs($this->key, $this->uuid()); + return $this->dreamhost->connect($command); + } + +} + +?> \ No newline at end of file diff --git a/plugins/dreamhost/controllers/components/empty b/plugins/dreamhost/controllers/components/empty new file mode 100644 index 0000000..e69de29 diff --git a/plugins/dreamhost/controllers/crons_controller.php b/plugins/dreamhost/controllers/crons_controller.php new file mode 100644 index 0000000..a72e925 --- /dev/null +++ b/plugins/dreamhost/controllers/crons_controller.php @@ -0,0 +1,113 @@ +<?php + +class CronsController extends DreamhostAppController { + + var $name = 'Crons'; + var $uses = array('Dreamhost.DreamhostUser', 'Dreamhost.DreamhostDomain', 'Dreamhost.DreamhostRegistered', 'Dreamhost.DreamhostHostname'); + var $components = array('Dreamhost.Dreamhost'); + + function beforeFilter() { + parent::beforeFilter(); + } + + function setup() { + echo 'Pulling data from dreamhost'; + $this->users(0); + $this->domains(0); + $this->registered(0); + $this->hostnames(0); + $this->Session->setFlash('First Data Aggregation done'); + $this->redirect(array('controller' => 'domains')); + } + + function users($redirect = 1) { + $data = $this->Dreamhost->find('user-list_users'); + $this->DreamhostUser->truncate(); + foreach ($data as $key => $value) { + + $users['DreamhostUser'] = (array)$value; + if ($this->DreamhostUser->check($users) == 0) { + $this->DreamhostUser->create(); + $this->DreamhostUser->save($users); + $new++; + } + else { + $this->DreamhostUser->save($users['User']); + $old++; + } + } + if ($redirect == 1) { + $this->Session->setFlash('Database updated'); + $this->redirect(array('controller' => 'users', 'action' => 'index')); + } + } + + function domains($redirect = 1) { + $data = $this->Dreamhost->find('domain-list_domains'); + $this->DreamhostDomain->truncate(); + foreach ($data as $key => $value) { + $domain['DreamhostDomain'] = (array)$value; + if (isset($value->user) && $value->user != null) { + $domain['DreamhostDomain']['user_id'] = $this->DreamhostUser->getUser($value->user); + } + + + if ($this->DreamhostDomain->check($domain) == 0) { + $this->DreamhostDomain->create(); + $this->DreamhostDomain->save($domain); + } + else { + $this->DreamhostDomain->save($domain['DreamhostDomain']); + } + } + 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->DreamhostHostname->truncate(); + foreach ($data as $key => $value) { + $hostname['DreamhostHostname'] = (array)$value; + $hostname['DreamhostHostname']['domain_id'] = $this->DreamhostDomain->getDomain($value->domain); + if ($this->DreamhostHostname->check($hostname) == 0) { + + $this->DreamhostHostname->create(); + $this->DreamhostHostname->save($hostname); + } + else { + $this->DreamhostHostname->save($hostname['DreamhostHostname']); + } + } + if ($redirect == 1) { + $this->Session->setFlash('Database updated'); + $this->redirect(array('controller' => 'databases', 'action' => 'hostnames')); + } + } + + function registered($redirect = 1) { + $data = $this->Dreamhost->find('domain-list_registrations'); + $this->DreamhostRegistered->truncate(); + foreach ($data as $key => $value) { + $registered['DreamhostRegistered'] = (array)$value; + + if ($this->DreamhostRegistered->check($registered) == 0) { + $this->DreamhostRegistered->create(); + $this->DreamhostRegistered->save($registered); + } + else { + $this->DreamhostReserved->save($registered['DreamhostRegistered']); + } + } + if ($redirect == 1) { + $this->Session->setFlash('Database updated'); + $this->redirect(array('controller' => 'domains', 'action' => 'registered')); + } + + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/controllers/databases_controller.php b/plugins/dreamhost/controllers/databases_controller.php new file mode 100644 index 0000000..0f80258 --- /dev/null +++ b/plugins/dreamhost/controllers/databases_controller.php @@ -0,0 +1,66 @@ +<?php + +class DatabasesController extends DreamhostAppController { + + var $name = 'Databases'; + var $uses = array('Dreamhost.DreamhostHostname'); + var $components = array('Dreamhost.Dreamhost'); + + function beforeFilter() { + parent::beforeFilter(); + } + + function index() { + $data = $this->DreamhostDomain->getList(); + $this->set(compact('data')); + } + + function hostnames() { + $data = $this->DreamhostHostname->find('all'); + $this->set(compact('data')); + } + + function users() { + $data = $this->DreamhostDatabase->find('mysql-list_users'); + $this->set(compact('data')); + } + + function delete_hostname($hostname, $id) { + $response = $this->DreamhostDreamhost->delete('mysql-remove_hostname', array('hostname' => $hostname)); + switch ($response) { + case 'hostname_removed': + case 'success': + $this->Session->setFlash('Hostname Deleted'); + break; + case 'no_hostname': + case 'invalid_hostname': + case 'internal_error_removing_hostname': + $this->Session->setFlash('Hostname Not Deleted'); + break; + } + $this->DreamhostHostname->del($id); + $this->redirect('hostnames', null, false); + } + + function add_host() { + if (!empty($this->data)) { + $hostname = implode('.', $this->data['DreamhostDatabase']); + $response = $this->DreamhostDreamhost->save(array('hostname' => $hostname)); + $response = str_replace('_', ' ', $response); + $response = ucwords($response); + $this->Session->setFlash($response); + $this->redirect(array('controller' => 'crons', 'action' => 'hostnames'), null, false); + } + $domain = $this->Dreamhost->hostnames(); + $this->set(compact('domain')); + } + + function domains() { + $domains = $this->DreamhostDomain->find('list', array('fields' => array('Domain.id', 'DreamhostDomain.domain'))); + foreach ($domains as $key => $value) { + $domain[$value] = $value; + } + return $domain; + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/controllers/domains_controller.php b/plugins/dreamhost/controllers/domains_controller.php new file mode 100644 index 0000000..534d5d0 --- /dev/null +++ b/plugins/dreamhost/controllers/domains_controller.php @@ -0,0 +1,18 @@ +<?php + +class DomainsController extends DreamhostAppController { + + var $name = 'Domains'; + var $uses = array('Dreamhost.DreamhostDomain', 'Dreamhost.DreamhostRegistered'); + + function index() { + $data = $this->DreamhostDomain->getList(); + $this->set(compact('data')); + } + + function registered() { + $data = $this->DreamhostRegistered->find('all'); + $this->set(compact('data')); + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/controllers/users_controller.php b/plugins/dreamhost/controllers/users_controller.php new file mode 100644 index 0000000..b94a682 --- /dev/null +++ b/plugins/dreamhost/controllers/users_controller.php @@ -0,0 +1,13 @@ +<?php + +class UsersController extends DreamhostAppController { + + var $name = 'Users'; + var $uses = array('Dreamhost.DreamhostUser'); + + function index() { + $data = $this->DreamhostUser->getList(); + $this->set(compact('data')); + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/dreamhost_app_controller.php b/plugins/dreamhost/dreamhost_app_controller.php new file mode 100644 index 0000000..14e8e94 --- /dev/null +++ b/plugins/dreamhost/dreamhost_app_controller.php @@ -0,0 +1,8 @@ +<?php + +class DreamhostAppController extends AppController { + + + +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/dreamhost_app_model.php b/plugins/dreamhost/dreamhost_app_model.php new file mode 100644 index 0000000..9724242 --- /dev/null +++ b/plugins/dreamhost/dreamhost_app_model.php @@ -0,0 +1,5 @@ +<?php + +class DreamhostAppModel extends AppModel { +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/models/dreamhost_database.php b/plugins/dreamhost/models/dreamhost_database.php new file mode 100644 index 0000000..e69de29 diff --git a/plugins/dreamhost/models/dreamhost_domain.php b/plugins/dreamhost/models/dreamhost_domain.php new file mode 100644 index 0000000..cb73b11 --- /dev/null +++ b/plugins/dreamhost/models/dreamhost_domain.php @@ -0,0 +1,55 @@ +<?php + +class DreamhostDomain extends DreamhostAppModel { + + var $name = 'DreamhostDomain'; + var $actAs = array('Containable'); + var $belongsTo = array( + 'DreamhostUser' => array( + 'className' => 'DreamhostUser', + 'foreignKey' => 'dreamhost_user_id' + ) + ); + + function getList() { + return $this->find('all', array( + 'conditions' => array( + 'DreamhostDomain.type !=' => 'mysqldns' + ), + 'fields' => array( + 'DreamhostDomain.domain', + 'DreamhostDomain.path', + 'DreamhostDomain.home', + 'DreamhostUser.username', + 'DreamhostUser.password', + 'DreamhostUser.shell', + 'DreamhostUser.type') + ) + ); + } + + function getDreamhostDomain($domain) { + $domains = $this->find('first', array( + 'conditions' => array( + 'DreamhostDomain' => $domain + ), + 'fields' => array( + 'DreamhostDomain.id' + ) + )); + return $domains['DreamhostDomain']['id']; + } + + function check($data) { + return $this->find('count', array( + 'conditions' => array( + 'domain' => $data['DreamhostDomain']['domain'] + ) + )); + } + + function truncate() { + $this->query('TRUNCATE TABLE ' . $this->useTable); + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/models/dreamhost_hostname.php b/plugins/dreamhost/models/dreamhost_hostname.php new file mode 100644 index 0000000..6883356 --- /dev/null +++ b/plugins/dreamhost/models/dreamhost_hostname.php @@ -0,0 +1,43 @@ +<?php + +class DreamhostHostname extends DreamhostAppModel { + + var $name = 'DreamhostHostname'; + var $belongsTo = array( + 'DreamhostDomain' => array( + 'className' => 'DreamhostDomain', + 'foreignKey' => 'dreamhost_domain_id' + ) + ); + + function getList() { + return $this->find('all', array( + 'conditions' => array( + 'DreamhostDomain.type !=' => 'mysqldns' + ), + 'fields' => array( + 'DreamhostDomain.domain', + 'DreamhostDomain.path', + 'DreamhostDomain.home', + 'DreamhostUser.username', + 'DreamhostUser.password', + 'DreamhostUser.shell', + 'DreamhostUser.type' + ) + )); + } + + function check($data) { + return $this->find('count', array( + 'conditions' => array( + 'domain' => $data['DreamhostHostname']['domain'] + ) + )); + return $domain; + } + + function truncate() { + $this->query('TRUNCATE TABLE ' . $this->useTable); + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/models/dreamhost_registered.php b/plugins/dreamhost/models/dreamhost_registered.php new file mode 100644 index 0000000..8217e7e --- /dev/null +++ b/plugins/dreamhost/models/dreamhost_registered.php @@ -0,0 +1,20 @@ +<?php + +class DreamhostRegistered extends DreamhostAppModel { + + var $name = 'DreamhostRegistered'; + var $useTable = 'dreamhost_registered'; + + function check($data) { + return $this->find('count', array( + 'conditions' => array( + 'domain' => $data['DreamhostRegistered']['domain'] + ) + )); + } + + function truncate() { + $this->query('TRUNCATE TABLE ' . $this->useTable); + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/models/dreamhost_user.php b/plugins/dreamhost/models/dreamhost_user.php new file mode 100644 index 0000000..75eabe5 --- /dev/null +++ b/plugins/dreamhost/models/dreamhost_user.php @@ -0,0 +1,35 @@ +<?php + +class DreamhostUser extends DreamhostAppModel { + + var $name = 'DreamhostUser'; + + function getList() { + return $this->find('all', array( + 'fields' => array('DreamhostUser.username', 'DreamhostUser.home', 'DreamhostUser.password', 'DreamhostUser.shell', 'DreamhostUser.type') + )); + } + + function check($data) { + return $this->find('count', array( + 'conditions' => array( + 'username' => $data['DreamhostUser']['username'] + ) + )); + } + + function getUser($username) { + $user = $this->find('first', array( + 'conditions' => array( + 'username' => $username + ), + 'fields' => array('DreamhostUser.id') + )); + return $user['DreamhostUser']['id']; + } + + function truncate() { + $this->query('TRUNCATE TABLE ' . $this->useTable); + } +} +?> \ No newline at end of file diff --git a/plugins/dreamhost/views/databases/add_host.ctp b/plugins/dreamhost/views/databases/add_host.ctp new file mode 100644 index 0000000..fd2075e --- /dev/null +++ b/plugins/dreamhost/views/databases/add_host.ctp @@ -0,0 +1,8 @@ +<h2>Add MySQL Hostname</h2> + +<?php +echo $form->create('DreamhostDatabase', array('action' => 'add_host')); +echo $form->input('prefix'); +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/plugins/dreamhost/views/databases/hostnames.ctp b/plugins/dreamhost/views/databases/hostnames.ctp new file mode 100644 index 0000000..fc2cbab --- /dev/null +++ b/plugins/dreamhost/views/databases/hostnames.ctp @@ -0,0 +1,21 @@ +<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> + <th>Domain</th> + <th>Server</th> + <th>Action</th> + </tr> + <?php foreach($data as $key => $value) { ?> + <tr> + <td><?php echo $value['DreamhostDomain']['domain']; ?></td> + <td><?php echo $value['DreamhostHostname']['home']; ?></td> + <td> + <?php + echo $html->link('Delete', array('action' =>'delete_hostname', $value['DreamhostDomain']['domain'], $value['DreamhostHostname']['id']), null, 'Are you sure?', false) + ?> + </td> + </tr> + <?php } ?> +</table> \ No newline at end of file diff --git a/plugins/dreamhost/views/databases/index.ctp b/plugins/dreamhost/views/databases/index.ctp new file mode 100644 index 0000000..727d9c2 --- /dev/null +++ b/plugins/dreamhost/views/databases/index.ctp @@ -0,0 +1,15 @@ +<h2>Current Databases</h2> +<table> + <tr> + <th>Name</th> + <th>Disk Usuage (MB)</th> + <th>Type</th> + </tr> + <?php foreach($data as $key => $value) { ?> + <tr> + <td><?php echo $value->db; ?></td> + <td><?php echo $value->disk_usage_mb; ?></td> + <td><?php echo $value->description; ?></td> + </tr> + <?php } ?> +</table> \ No newline at end of file diff --git a/plugins/dreamhost/views/databases/users.ctp b/plugins/dreamhost/views/databases/users.ctp new file mode 100644 index 0000000..edd3af5 --- /dev/null +++ b/plugins/dreamhost/views/databases/users.ctp @@ -0,0 +1,36 @@ +<h2>Current Databases Users</h2> +<table> + <tr> + <th>Username</th> + <th>Database</th> + <th>Hostname</th> + <th>Alter</th> + <th>Index</th> + <th>Create</th> + <th>Update</th> + <th>Select</th> + <th>Insert</th> + <th>Drop</th> + <th>Delete</th> + </tr> + <?php foreach($data as $key => $value) { ?> + <tr> + <td><?php echo $value->username; ?></td> + <td><?php echo $value->db; ?></td> + <td> + <?php + if ($value->host == '') echo 'localhost'; + else echo $value->host; + ?> + </td> + <td><?php echo $value->alter_priv; ?></td> + <td><?php echo $value->index_priv; ?></td> + <td><?php echo $value->create_priv; ?></td> + <td><?php echo $value->update_priv; ?></td> + <td><?php echo $value->select_priv; ?></td> + <td><?php echo $value->insert_priv; ?></td> + <td><?php echo $value->drop_priv; ?></td> + <td><?php echo $value->delete_priv; ?></td> + </tr> + <?php } ?> +</table> \ No newline at end of file diff --git a/plugins/dreamhost/views/domains/index.ctp b/plugins/dreamhost/views/domains/index.ctp new file mode 100644 index 0000000..3382c9b --- /dev/null +++ b/plugins/dreamhost/views/domains/index.ctp @@ -0,0 +1,23 @@ +<h2>Active Domains</h2> +<? echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'domains')); ?> +<table> + <tr> + <th>Name</th> + <th>Path</th> + <th>FTP Address</th> + <th>Username</th> + <th>Password</th> + <th>Access</th> + </tr> + <?php foreach($data as $key => $value) { ?> + <tr> + <td><?php echo $value['DreamhostDomain']['domain']; ?></td> + <td><?php echo $value['DreamhostDomain']['path']; ?></td> + <td><?php echo $value['DreamhostDomain']['home']; ?></td> + <td><?php echo $value['DreamhostUser']['username']; ?></td> + <td><?php echo $value['DreamhostUser']['password']; ?></td> + <td><?php echo $value['DreamhostUser']['shell'] . ' ' .$value['DreamhostUser']['type']; ?></td> + </tr> + <?php } ?> +</table> + diff --git a/plugins/dreamhost/views/domains/registered.ctp b/plugins/dreamhost/views/domains/registered.ctp new file mode 100644 index 0000000..44c155a --- /dev/null +++ b/plugins/dreamhost/views/domains/registered.ctp @@ -0,0 +1,24 @@ +<h2>Registered Domains</h2> +<? echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'registered')); ?> +<table> + <tr> + <th>Name</th> + <th>Created</th> + <th>Updated</th> + <th>Expires</th> + <th>DNS (Primary)</th> + <th>DNS (Secondary)</th> + <th>DNS (Tietary)</th> + </tr> + <?php foreach($data as $key => $value) { ?> + <tr> + <td><?php echo $value['DreamhostRegistered']['domain']; ?></td> + <td><?php echo $value['DreamhostRegistered']['modified']; ?></td> + <td><?php echo $value['DreamhostRegistered']['created']; ?></td> + <td><?php echo $value['DreamhostRegistered']['expires']; ?></td> + <td><?php echo $value['DreamhostRegistered']['ns1']; ?></td> + <td><?php echo $value['DreamhostRegistered']['ns2']; ?></td> + <td><?php echo $value['DreamhostRegistered']['ns3']; ?></td> + </tr> + <?php } ?> +</table> \ No newline at end of file diff --git a/plugins/dreamhost/views/users/index.ctp b/plugins/dreamhost/views/users/index.ctp new file mode 100644 index 0000000..932f0f6 --- /dev/null +++ b/plugins/dreamhost/views/users/index.ctp @@ -0,0 +1,21 @@ +<h2>Active Users</h2> +<? echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'users')); ?> +<table> + <tr> + <th>Username</th> + <th>Password</th> + <th>Server</th> + <th>Shell</th> + <th>Access</th> + </tr> + <?php foreach($data as $key => $value) { ?> + <tr> + <td><?php echo $value['DreamhostUser']['username']; ?></td> + <td><?php echo $value['DreamhostUser']['password']; ?></td> + <td><?php echo $value['DreamhostUser']['home']; ?></td> + <td><?php echo $value['DreamhostUser']['shell']; ?></td> + <td><?php echo $value['DreamhostUser']['type']; ?></td> + </tr> + <?php } ?> +</table> + diff --git a/tmp/logs/debug.log b/tmp/logs/debug.log index a7f62bc..d7f4298 100644 --- a/tmp/logs/debug.log +++ b/tmp/logs/debug.log @@ -100,3 +100,12 @@ 2009-07-24 02:21:48 Debug: Notice (8): Undefined index: Reserved in [APP\models\registered.php, line 11] 2009-07-24 02:22:49 Debug: Notice (8): Undefined variable: id in [APP\controllers\databases_controller.php, line 36] 2009-07-24 02:32:38 Debug: Notice (8): Undefined property: DatabasesController::$Database in [APP\controllers\databases_controller.php, line 19] +2009-07-24 02:49:40 Debug: Notice (8): Undefined index: Reserved in [APP\models\registered.php, line 11] +2009-07-26 01:36:12 Debug: Notice (8): Undefined variable: javascript in [APP\views\layouts\default.ctp, line 37] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 15] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 16] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 17] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 18] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 19] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 20] +2009-07-26 01:38:13 Debug: Notice (8): Undefined index: Registered in [APP\plugins\dreamhost\views\domains\registered.ctp, line 21] diff --git a/tmp/logs/error.log b/tmp/logs/error.log index 1b19fce..4faf7ef 100644 --- a/tmp/logs/error.log +++ b/tmp/logs/error.log @@ -64,3 +64,7 @@ 2009-07-24 02:24:19 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 48] 2009-07-24 02:24:49 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 48] 2009-07-24 02:25:07 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\crons_controller.php, line 74] +2009-07-26 01:37:21 Warning: Warning (512): <span style = "color:Red;text-align:left"><b>SQL Error:</b> 1054: Unknown column 'DreamhostDomain.dreamhost_user_id' in 'on clause'</span> in [CORE\cake\libs\model\datasources\dbo_source.php, line 525] +2009-07-26 01:37:22 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\plugins\dreamhost\views\domains\index.ctp, line 12] +2009-07-26 01:40:08 Warning: Warning (512): <span style = "color:Red;text-align:left"><b>SQL Error:</b> 1066: Not unique table/alias: 'DreamhostHostname'</span> in [CORE\cake\libs\model\datasources\dbo_source.php, line 525] +2009-07-26 01:40:08 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\plugins\dreamhost\views\databases\hostnames.ctp, line 10] diff --git a/views/databases/add_host.ctp b/views/databases/add_host.ctp deleted file mode 100644 index bcf4d2a..0000000 --- a/views/databases/add_host.ctp +++ /dev/null @@ -1,8 +0,0 @@ -<h2>Add MySQL Hostname</h2> - -<?php -echo $form->create('Database', array('action' => 'add_host')); -echo $form->input('prefix'); -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 deleted file mode 100644 index 7692d2e..0000000 --- a/views/databases/hostnames.ctp +++ /dev/null @@ -1,21 +0,0 @@ -<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> - <th>Domain</th> - <th>Server</th> - <th>Action</th> - </tr> - <?php foreach($data as $key => $value) { ?> - <tr> - <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']['domain'], $value['Hostname']['id']), null, 'Are you sure?', false) - ?> - </td> - </tr> - <?php } ?> -</table> \ No newline at end of file diff --git a/views/databases/index.ctp b/views/databases/index.ctp deleted file mode 100644 index 727d9c2..0000000 --- a/views/databases/index.ctp +++ /dev/null @@ -1,15 +0,0 @@ -<h2>Current Databases</h2> -<table> - <tr> - <th>Name</th> - <th>Disk Usuage (MB)</th> - <th>Type</th> - </tr> - <?php foreach($data as $key => $value) { ?> - <tr> - <td><?php echo $value->db; ?></td> - <td><?php echo $value->disk_usage_mb; ?></td> - <td><?php echo $value->description; ?></td> - </tr> - <?php } ?> -</table> \ No newline at end of file diff --git a/views/databases/users.ctp b/views/databases/users.ctp deleted file mode 100644 index edd3af5..0000000 --- a/views/databases/users.ctp +++ /dev/null @@ -1,36 +0,0 @@ -<h2>Current Databases Users</h2> -<table> - <tr> - <th>Username</th> - <th>Database</th> - <th>Hostname</th> - <th>Alter</th> - <th>Index</th> - <th>Create</th> - <th>Update</th> - <th>Select</th> - <th>Insert</th> - <th>Drop</th> - <th>Delete</th> - </tr> - <?php foreach($data as $key => $value) { ?> - <tr> - <td><?php echo $value->username; ?></td> - <td><?php echo $value->db; ?></td> - <td> - <?php - if ($value->host == '') echo 'localhost'; - else echo $value->host; - ?> - </td> - <td><?php echo $value->alter_priv; ?></td> - <td><?php echo $value->index_priv; ?></td> - <td><?php echo $value->create_priv; ?></td> - <td><?php echo $value->update_priv; ?></td> - <td><?php echo $value->select_priv; ?></td> - <td><?php echo $value->insert_priv; ?></td> - <td><?php echo $value->drop_priv; ?></td> - <td><?php echo $value->delete_priv; ?></td> - </tr> - <?php } ?> -</table> \ No newline at end of file diff --git a/views/domains/index.ctp b/views/domains/index.ctp deleted file mode 100644 index a619b16..0000000 --- a/views/domains/index.ctp +++ /dev/null @@ -1,23 +0,0 @@ -<h2>Active Domains</h2> -<? echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'domains')); ?> -<table> - <tr> - <th>Name</th> - <th>Path</th> - <th>FTP Address</th> - <th>Username</th> - <th>Password</th> - <th>Access</th> - </tr> - <?php foreach($data as $key => $value) { ?> - <tr> - <td><?php echo $value['Domain']['domain']; ?></td> - <td><?php echo $value['Domain']['path']; ?></td> - <td><?php echo $value['Domain']['home']; ?></td> - <td><?php echo $value['User']['username']; ?></td> - <td><?php echo $value['User']['password']; ?></td> - <td><?php echo $value['User']['shell'] . ' ' .$value['User']['type']; ?></td> - </tr> - <?php } ?> -</table> - diff --git a/views/domains/registered.ctp b/views/domains/registered.ctp deleted file mode 100644 index 35d3f40..0000000 --- a/views/domains/registered.ctp +++ /dev/null @@ -1,24 +0,0 @@ -<h2>Registered Domains</h2> -<? echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'registered')); ?> -<table> - <tr> - <th>Name</th> - <th>Created</th> - <th>Updated</th> - <th>Expires</th> - <th>DNS (Primary)</th> - <th>DNS (Secondary)</th> - <th>DNS (Tietary)</th> - </tr> - <?php foreach($data as $key => $value) { ?> - <tr> - <td><?php echo $value['Registered']['domain']; ?></td> - <td><?php echo $value['Registered']['modified']; ?></td> - <td><?php echo $value['Registered']['created']; ?></td> - <td><?php echo $value['Registered']['expires']; ?></td> - <td><?php echo $value['Registered']['ns1']; ?></td> - <td><?php echo $value['Registered']['ns2']; ?></td> - <td><?php echo $value['Registered']['ns3']; ?></td> - </tr> - <?php } ?> -</table> \ No newline at end of file diff --git a/views/elements/menu.ctp b/views/elements/menu.ctp index 4ddcdd8..46a01ce 100644 --- a/views/elements/menu.ctp +++ b/views/elements/menu.ctp @@ -1,27 +1,31 @@ <div id="menu"> <ul id="navmenu-h"> <li><a href="/">Home</a></li> - <li><?php echo $html->link('Domains &raquo;', array('controller' => 'domains', 'action' => 'index'), null, null, false); ?> - <ul> - <li><?php echo $html->link('Registered Domains', array('controller' => 'domains', 'action' => 'registered'), null, null, false); ?></li> - </ul> - </li> - <li><?php echo $html->link('Users', array('controller' => 'users', 'action' => 'index'), null, null, false); ?></li> - - <li><a href="#">MySQL &raquo;</a> - <ul> - <li><?php echo $html->link('Databases', array('controller' => 'databases', 'action' => 'index'), null, null, false); ?></li> - <li><?php echo $html->link('Hostnames &raquo;', array('controller' => 'databases', 'action' => 'hostnames'), null, null, false); ?> - <ul> - <li><?php echo $html->link('Add New Hostname', array('controller' => 'databases', 'action' => 'add_host'), null, null, false); ?></li> - </ul> - </li> - <li><?php echo $html->link('Users &raquo;', array('controller' => 'databases', 'action' => 'users'), null, null, false); ?> - <ul> - <li><?php echo $html->link('Add New User', array('controller' => 'databases', 'action' => 'add_user'), null, null, false); ?></li> - </ul> - </li> - </ul> - </li> + <li><a href="#">Dreamhost &raquo;</a> + <ul> + <li><?php echo $html->link('Domains &raquo;', array('controller' => 'domains', 'action' => 'index'), null, null, false); ?> + <ul> + <li><?php echo $html->link('Registered Domains', array('controller' => 'domains', 'action' => 'registered'), null, null, false); ?></li> + </ul> + </li> + <li><?php echo $html->link('Users', array('controller' => 'users', 'action' => 'index'), null, null, false); ?></li> + + <li><a href="#">MySQL &raquo;</a> + <ul> + <li><?php echo $html->link('Databases', array('controller' => 'databases', 'action' => 'index'), null, null, false); ?></li> + <li><?php echo $html->link('Hostnames &raquo;', array('controller' => 'databases', 'action' => 'hostnames'), null, null, false); ?> + <ul> + <li><?php echo $html->link('Add New Hostname', array('controller' => 'databases', 'action' => 'add_host'), null, null, false); ?></li> + </ul> + </li> + <li><?php echo $html->link('Users &raquo;', array('controller' => 'databases', 'action' => 'users'), null, null, false); ?> + <ul> + <li><?php echo $html->link('Add New User', array('controller' => 'databases', 'action' => 'add_user'), null, null, false); ?></li> + </ul> + </li> + </ul> + </li> + </ul> + </li> </ul> </div> \ No newline at end of file diff --git a/views/users/index.ctp b/views/users/index.ctp deleted file mode 100644 index 8c1ea92..0000000 --- a/views/users/index.ctp +++ /dev/null @@ -1,21 +0,0 @@ -<h2>Active Users</h2> -<? echo $html->link('Update From Dreamhost', array('controller' => 'crons', 'action' => 'users')); ?> -<table> - <tr> - <th>Username</th> - <th>Password</th> - <th>Server</th> - <th>Shell</th> - <th>Access</th> - </tr> - <?php foreach($data as $key => $value) { ?> - <tr> - <td><?php echo $value['User']['username']; ?></td> - <td><?php echo $value['User']['password']; ?></td> - <td><?php echo $value['User']['home']; ?></td> - <td><?php echo $value['User']['shell']; ?></td> - <td><?php echo $value['User']['type']; ?></td> - </tr> - <?php } ?> -</table> -