0
0
mirror of https://github.com/urlgrey/hsmm-pi synced 2025-10-06 00:12:53 +02:00

Merge pull request #70 from argilo/master

Replace binary database with schema, fix deprecations
This commit is contained in:
Clayton Smith
2016-04-01 23:18:41 -04:00
7 changed files with 141 additions and 18 deletions

View File

@@ -111,7 +111,7 @@ sudo mkdir -p /var/data/hsmm-pi
sudo chown root.www-data /var/data/hsmm-pi
sudo chmod 775 /var/data/hsmm-pi
if [ ! -e /var/data/hsmm-pi/hsmm-pi.sqlite ]; then
sudo cp ${PROJECT_HOME}/src/var/data/hsmm-pi/hsmm-pi.sqlite /var/data/hsmm-pi/hsmm-pi.sqlite
sudo Console/cake schema create -y
sudo chown root.www-data /var/data/hsmm-pi/hsmm-pi.sqlite
sudo chmod 664 /var/data/hsmm-pi/hsmm-pi.sqlite
fi

Binary file not shown.

View File

@@ -0,0 +1,123 @@
<?php
class AppSchema extends CakeSchema {
public $connection = 'default';
public function before($event = array()) {
$db = ConnectionManager::getDataSource($this->connection);
$db->cacheSources = false;
return true;
}
public function after($event = array()) {
App::uses('ClassRegistry', 'Utility');
App::uses('AuthComponent', 'Controller/Component');
if (isset($event['create'])) {
switch ($event['create']) {
case 'location_settings':
$location_setting = ClassRegistry::init('LocationSetting');
$location_setting->create();
$location_setting->save();
break;
case 'network_settings':
$network_setting = ClassRegistry::init('NetworkSetting');
$network_setting->create();
$network_setting->save(
array(
'wan_mesh_gateway' => true,
'mesh_olsrd_secure_key' => 'FFFFFFFFFFFFFFFF'
)
);
break;
case 'users':
$user = ClassRegistry::init('User');
$user->create();
$user->save(
array('User' =>
array(
'username' => 'admin',
'password' => 'changeme',
'role' => 'admin'
)
), $validate = false
);
break;
}
}
}
public $location_settings = array(
'id' => array('type' => 'integer', 'null' => false, 'length' => 11, 'key' => 'primary'),
'transmit_location_enabled' => array('type' => 'boolean', 'null' => false, 'default' => false),
'location_source' => array('type' => 'string', 'null' => false, 'default' => 'fixed'),
'lat' => array('type' => 'float', 'null' => false, 'default' => '0.0'),
'lon' => array('type' => 'float', 'null' => false, 'default' => '0.0'),
'gps_device_name' => array('type' => 'string', 'null' => false, 'default' => 'gps0'),
'maps_api_key' => array('type' => 'string', 'null' => true),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array()
);
public $network_services = array(
'id' => array('type' => 'integer', 'null' => false, 'length' => 11, 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
'host' => array('type' => 'string', 'null' => false, 'default' => 'null'),
'port' => array('type' => 'integer', 'null' => false),
'protocol' => array('type' => 'string', 'null' => false, 'default' => 'tcp'),
'forwarding_port' => array('type' => 'integer', 'null' => false),
'service_protocol_name' => array('type' => 'string', 'null' => false, 'default' => 'http'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array()
);
public $network_settings = array(
'id' => array('type' => 'integer', 'null' => false, 'length' => 11, 'key' => 'primary'),
'wifi_protocol' => array('type' => 'string', 'null' => false, 'default' => 'Static'),
'wifi_ip_address' => array('type' => 'string', 'null' => true),
'wifi_netmask' => array('type' => 'string', 'null' => false, 'default' => '255.0.0.0'),
'wifi_ssid' => array('type' => 'string', 'null' => false, 'default' => 'HSMM-MESH'),
'wifi_mode' => array('type' => 'string', 'null' => false, 'default' => 'Ad-Hoc'),
'wifi_channel' => array('type' => 'integer', 'null' => false, 'default' => 1),
'wired_interface_mode' => array('type' => 'string', 'null' => false, 'default' => 'LAN'),
'lan_mode' => array('type' => 'string', 'null' => false, 'default' => 'NAT'),
'lan_ip_address' => array('type' => 'string', 'null' => false, 'default' => '172.27.2.1'),
'lan_netmask' => array('type' => 'string', 'null' => false, 'default' => '255.255.255.0'),
'lan_dhcp_server' => array('type' => 'boolean', 'null' => false, 'default' => true),
'lan_dhcp_start' => array('type' => 'integer', 'null' => false, 'default' => 5),
'lan_dhcp_end' => array('type' => 'integer', 'null' => false, 'default' => 25),
'wan_protocol' => array('type' => 'string', 'null' => false, 'default' => 'DHCP'),
'wan_dns1' => array('type' => 'string', 'null' => true, 'default' => '8.8.8.8'),
'wan_dns2' => array('type' => 'string', 'null' => true, 'default' => '8.8.4.4'),
'wan_mesh_gateway' => array('type' => 'boolean', 'null' => false, 'default' => false),
'mesh_olsrd_secure' => array('type' => 'boolean', 'null' => false, 'default' => false),
'mesh_olsrd_secure_key' => array('type' => 'string', 'null' => true),
'node_name' => array('type' => 'string', 'null' => false, 'default' => 'UNDEF-1'),
'wifi_adapter_name' => array('type' => 'string', 'null' => false, 'default' => 'wlan0'),
'wired_adapter_name' => array('type' => 'string', 'null' => false, 'default' => 'eth0'),
'callsign' => array('type' => 'string', 'null' => false, 'default' => 'UNDEF'),
'wan_fixed_connection' => array('type' => 'boolean', 'null' => false, 'default' => true),
'ntp_server' => array('type' => 'string', 'null' => false, 'default' => 'ntp.ubuntu.com'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array()
);
public $users = array(
'id' => array('type' => 'integer', 'null' => false, 'length' => 11, 'key' => 'primary'),
'username' => array('type' => 'string', 'null' => false, 'length' => 50),
'password' => array('type' => 'string', 'null' => false, 'length' => 50),
'role' => array('type' => 'string', 'null' => true, 'length' => 20),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array()
);
}

View File

@@ -109,4 +109,4 @@ CakeLog::config('error', array(
'file' => 'error',
));
Configure::write('App.version','0.6.2');
Configure::write('App.version','0.6.3');

View File

@@ -2,12 +2,12 @@
class NetworkService extends AppModel {
public $validate = array(
'name' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Service name is required')),
'service_protocol_name' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Service protocol is required')),
'name' => array('required' => array('rule' => array('notBlank'), 'message' => 'Service name is required')),
'service_protocol_name' => array('required' => array('rule' => array('notBlank'), 'message' => 'Service protocol is required')),
'host' => array('required' => array('rule' => '/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i', 'message' => 'A valid IP address is required')),
'port' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Port is required')),
'forwarding_port' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Forwarding port is required')),
'protocol' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Protocol is required')),
'port' => array('required' => array('rule' => array('notBlank'), 'message' => 'Port is required')),
'forwarding_port' => array('required' => array('rule' => array('notBlank'), 'message' => 'Forwarding port is required')),
'protocol' => array('required' => array('rule' => array('notBlank'), 'message' => 'Protocol is required')),
);
}

View File

@@ -2,24 +2,24 @@
class NetworkSetting extends AppModel {
public $validate = array(
'wifi_adapter_name' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A WIFI adapter name is required')),
'wifi_ssid' => array('required' => array('rule' => array('notEmpty'), 'message' => 'An SSID is required')),
'wifi_adapter_name' => array('required' => array('rule' => array('notBlank'), 'message' => 'A WIFI adapter name is required')),
'wifi_ssid' => array('required' => array('rule' => array('notBlank'), 'message' => 'An SSID is required')),
'wifi_netmask' => array('required' => array('rule' => '/^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$/i', 'message' => 'A valid netmask is required')),
'wifi_ip_address' => array('rule' => array('ip'), 'message' => 'Please supply a valid IP address.'),
'lan_ip_address' => array('rule' => array('ip'), 'message' => 'Please supply a valid IP address.'),
'lan_netmask' => array('required' => array('rule' => '/^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$/i', 'message' => 'A valid netmask is required')),
'lan_dhcp_start' => array('number' => array('rule' => array('range', 0, 254), 'message' => 'A DHCP address between 0 and 254 is required')),
'lan_dhcp_end' => array('number' => array('rule' => array('range', 0, 254), 'message' => 'A DHCP address between 0 and 254 is required')),
'wired_adapter_name' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A wired adapter name is required')),
'wired_adapter_name' => array('required' => array('rule' => array('notBlank'), 'message' => 'A wired adapter name is required')),
'wired_interface_mode' => array('required' => array('rule' => '/^(WAN|LAN)$/i', 'message' => 'The wired interface mode must be set to WAN or LAN.')),
'wan_protocol' => array('required' => array('rule' => '/^(DHCP)$/i', 'message' => 'DHCP is the only mode currently supported.')),
'wifi_channel' => array('required' => array('rule' => '/^(1|2|3|4|5|6|7|8|9|10|11)$/i', 'message' => 'Specify a valid channel-id.')),
'wan_dns1' => array('rule' => array('ip'), 'message' => 'Please supply a valid IP address.'),
'wan_dns2' => array('rule' => array('ip'), 'message' => 'Please supply a valid IP address.'),
'node_name' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A globally unique nodename with your callsign is required')),
'mesh_olsrd_secure_key' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A secure key value is required')),
'callsign' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A valid callsign is required'), array('rule' => array('between', 3, 9), 'message' => 'Callsign must be between 3 and 9 characters')),
'ntp_server' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A NTP server is required')),
'node_name' => array('required' => array('rule' => array('notBlank'), 'message' => 'A globally unique nodename with your callsign is required')),
'mesh_olsrd_secure_key' => array('required' => array('rule' => array('notBlank'), 'message' => 'A secure key value is required')),
'callsign' => array('required' => array('rule' => array('notBlank'), 'message' => 'A valid callsign is required'), array('rule' => array('lengthBetween', 3, 9), 'message' => 'Callsign must be between 3 and 9 characters')),
'ntp_server' => array('required' => array('rule' => array('notBlank'), 'message' => 'A NTP server is required')),
);
}

View File

@@ -3,10 +3,10 @@
// app/Model/User.php
class User extends AppModel {
public $validate = array(
'username' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A username is required')),
'current_password' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Current password is required')),
'password' => array('required' => array('rule' => array('notEmpty'), 'message' => 'A password is required'), array('rule' => array('between', 8, 20), 'message' => 'Password must be at least 8 characters long')),
'password_confirmation' => array('required' => array('rule' => array('notEmpty'), 'message' => 'Confirmation password is required')),
'username' => array('required' => array('rule' => array('notBlank'), 'message' => 'A username is required')),
'current_password' => array('required' => array('rule' => array('notBlank'), 'message' => 'Current password is required')),
'password' => array('required' => array('rule' => array('notBlank'), 'message' => 'A password is required'), array('rule' => array('lengthBetween', 8, 20), 'message' => 'Password must be at least 8 characters long')),
'password_confirmation' => array('required' => array('rule' => array('notBlank'), 'message' => 'Confirmation password is required')),
'role' => array('valid' => array('rule' => array('inList', array('admin', 'author')), 'message' => 'Please enter a valid role', 'allowEmpty' => false)));
public function beforeSave($options = array()) {