saas enhancements

This commit is contained in:
SJ
2013-07-23 22:44:34 +02:00
parent 90eef6b43d
commit 920f4208ba
31 changed files with 970 additions and 463 deletions

View File

@ -3,6 +3,76 @@
class ModelSaasCustomer extends Model
{
public function get($id = -1) {
if($id > 0) {
$query = $this->db->query("SELECT * FROM " . TABLE_CUSTOMER_SETTINGS . " WHERE id=?", array($id));
if($query->num_rows > 0) { return $query->row; }
}
$query = $this->db->query("SELECT * FROM " . TABLE_CUSTOMER_SETTINGS . " ORDER BY domain ASC");
if($query->num_rows > 0) { return $query->rows; }
return array();
}
public function delete($id = 0, $description = '') {
if($id == 0) { return 0; }
$query = $this->db->query("DELETE FROM " . TABLE_CUSTOMER_SETTINGS . " WHERE id=?", array($id));
$rc = $this->db->countAffected();
LOGGER("remove ldap entry: #$id, $description (rc=$rc)");
return $rc;
}
public function add($arr = array()) {
$branding_logo = '';
if(!isset($arr['domain']) || !isset($arr['branding_text'])) { return 0; }
if(isset($_FILES['branding_logo']['name'])) {
$branding_logo = $_FILES['branding_logo']['name'];
move_uploaded_file($_FILES['branding_logo']['tmp_name'], DIR_BASE . "/images/" . $_FILES['branding_logo']['name']);
}
$query = $this->db->query("INSERT INTO " . TABLE_CUSTOMER_SETTINGS . " (domain, branding_text, branding_url, branding_logo, support_link, colour) VALUES (?,?,?,?,?,?)", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $branding_logo, $arr['support_link'], $arr['colour']));
$rc = $this->db->countAffected();
LOGGER("add ldap entry: " . $arr['domain'] . " / " . $arr['branding_text'] . " / " . $arr['branding_url'] . " / " . $arr['support_link'] . " (rc=$rc)");
if($rc == 1){ return 1; }
return 0;
}
public function update($arr = array()) {
$branding_logo = '';
if(!isset($arr['id']) || !isset($arr['domain']) || !isset($arr['branding_text'])) { return 0; }
if(isset($_FILES['branding_logo']['name'])) {
$branding_logo = $_FILES['branding_logo']['name'];
move_uploaded_file($_FILES['branding_logo']['tmp_name'], DIR_BASE . "/images/" . $_FILES['branding_logo']['name']);
$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET domain=?, branding_text=?, branding_url=?, branding_logo=?, support_link=?, colour=? WHERE id=?", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $branding_logo, $arr['support_link'], $arr['colour'], $arr['id']));
}
else {
$query = $this->db->query("UPDATE " . TABLE_CUSTOMER_SETTINGS . " SET domain=?, branding_text=?, branding_url=?, support_link=?, colour=? WHERE id=?", array($arr['domain'], $arr['branding_text'], $arr['branding_url'], $arr['support_link'], $arr['colour'], $arr['id']));
}
return $this->db->countAffected();
}
public function get_customer_settings_by_email() {
$data = array(
'branding_text' => BRANDING_TEXT,
@ -17,6 +87,13 @@ class ModelSaasCustomer extends Model
list ($user, $domain) = explode("@", $_SESSION['email']);
if(MEMCACHED_ENABLED) {
$cache_key = sha1("customer_settings:" . $domain);
$memcache = Registry::get('memcache');
$m = $memcache->get($cache_key);
if(isset($m['data'])) { return unserialize($m['data']); }
}
$query = $this->db->query("SELECT * FROM " . TABLE_CUSTOMER_SETTINGS . " WHERE domain=(SELECT mapped FROM " . TABLE_DOMAIN . " WHERE domain=?)", array($domain));
if($query->num_rows > 0) {
@ -27,6 +104,10 @@ class ModelSaasCustomer extends Model
if($query->row['colour']) { $data['colour'] = $query->row['colour']; }
}
if(MEMCACHED_ENABLED && $cache_key) {
$memcache->add($cache_key, array('data' => serialize($data)), 0, MEMCACHED_TTL);
}
return $data;
}

View File

@ -3,9 +3,14 @@
class ModelSaasLdap extends Model
{
public function get() {
public function get($id = -1) {
$query = $this->db->query("SELECT id, description, ldap_type, ldap_host, ldap_base_dn, ldap_bind_dn FROM " . TABLE_LDAP . " ORDER BY description ASC");
if($id >= 0) {
$query = $this->db->query("SELECT id, description, ldap_type, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw, ldap_auditor_member_dn FROM " . TABLE_LDAP . " WHERE id=?", array($id));
if($query->num_rows > 0) { return $query->row; }
}
$query = $this->db->query("SELECT id, description, ldap_type, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_auditor_member_dn FROM " . TABLE_LDAP . " ORDER BY description ASC");
if($query->num_rows > 0) { return $query->rows; }
@ -29,7 +34,7 @@ class ModelSaasLdap extends Model
public function add($arr = array()) {
if(!isset($arr['description']) || !isset($arr['ldap_host'])) { return 0; }
$query = $this->db->query("INSERT INTO " . TABLE_LDAP . " (description, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw, ldap_type) VALUES (?,?,?,?,?,?)", array($arr['description'], $arr['ldap_host'], $arr['ldap_base_dn'], $arr['ldap_bind_dn'], $arr['ldap_bind_pw'], $arr['ldap_type']));
$query = $this->db->query("INSERT INTO " . TABLE_LDAP . " (description, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw, ldap_type, ldap_auditor_member_dn) VALUES (?,?,?,?,?,?,?)", array($arr['description'], $arr['ldap_host'], $arr['ldap_base_dn'], $arr['ldap_bind_dn'], $arr['ldap_bind_pw'], $arr['ldap_type'], $arr['ldap_auditor_member_dn']));
$rc = $this->db->countAffected();
@ -41,6 +46,15 @@ class ModelSaasLdap extends Model
}
public function update($arr = array()) {
if(!isset($arr['id']) || !isset($arr['description']) || !isset($arr['ldap_host'])) { return 0; }
$query = $this->db->query("UPDATE " . TABLE_LDAP . " SET description=?, ldap_host=?, ldap_base_dn=?, ldap_bind_dn=?, ldap_bind_pw=?, ldap_type=?, ldap_auditor_member_dn=? WHERE id=?", array($arr['description'], $arr['ldap_host'], $arr['ldap_base_dn'], $arr['ldap_bind_dn'], $arr['ldap_bind_pw'], $arr['ldap_type'], $arr['ldap_auditor_member_dn'], $arr['id']));
return $this->db->countAffected();
}
public function get_ldap_params_by_email($email = '') {
$domain = '';
@ -48,9 +62,9 @@ class ModelSaasLdap extends Model
list($l,$d) = explode("@", $email);
$query = $this->db->query("SELECT ldap_type, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw from " . TABLE_DOMAIN . " as d, " . TABLE_LDAP . " as l where d.ldap_id=l.id and d.domain=?", array($d));
$query = $this->db->query("SELECT ldap_type, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw, ldap_auditor_member_dn FROM " . TABLE_DOMAIN . " as d, " . TABLE_LDAP . " as l where d.ldap_id=l.id and d.domain=?", array($d));
if($query->num_rows > 0) { return array($query->row['ldap_type'], $query->row['ldap_host'], $query->row['ldap_base_dn'], $query->row['ldap_bind_dn'], $query->row['ldap_bind_pw']); }
if($query->num_rows > 0) { return array($query->row['ldap_type'], $query->row['ldap_host'], $query->row['ldap_base_dn'], $query->row['ldap_bind_dn'], $query->row['ldap_bind_pw'], $query->row['ldap_auditor_member_dn']); }
return array();
}