예제 #1
0
 function onAfterInsert()
 {
     global $app, $conf;
     // Create the group for the client
     $groupid = $app->db->datalogInsert('sys_group', "(name,description,client_id) VALUES ('" . $app->db->quote($this->dataRecord["username"]) . "',''," . $this->id . ")", 'groupid');
     $groups = $groupid;
     $username = $app->db->quote($this->dataRecord["username"]);
     $password = $app->db->quote($this->dataRecord["password"]);
     $modules = $conf['interface_modules_enabled'];
     if (isset($this->dataRecord["limit_client"]) && $this->dataRecord["limit_client"] > 0) {
         $modules .= ',client';
     }
     $startmodule = stristr($modules, 'dashboard') ? 'dashboard' : 'client';
     $usertheme = $app->db->quote($this->dataRecord["usertheme"]);
     $type = 'user';
     $active = 1;
     $language = $app->db->quote($this->dataRecord["language"]);
     $password = $app->auth->crypt_password($password);
     // Create the controlpaneluser for the client
     //Generate ssh-rsa-keys
     exec('ssh-keygen -t rsa -C ' . $username . '-rsa-key-' . time() . ' -f /tmp/id_rsa -N ""');
     $app->db->query("UPDATE client SET created_at = " . time() . ", id_rsa = '" . $app->db->quote(@file_get_contents('/tmp/id_rsa')) . "', ssh_rsa = '" . $app->db->quote(@file_get_contents('/tmp/id_rsa.pub')) . "' WHERE client_id = " . $this->id);
     exec('rm -f /tmp/id_rsa /tmp/id_rsa.pub');
     // Create the controlpaneluser for the client
     $sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)\n\t\tVALUES ('{$username}','{$password}','{$modules}','{$startmodule}','{$usertheme}','{$type}','{$active}','{$language}',{$groups},{$groupid}," . $this->id . ")";
     $app->db->query($sql);
     //* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
     //* to his groups, so he can administrate the records of this client.
     if ($_SESSION['s']['user']['typ'] == 'user') {
         $app->auth->add_group_to_user($_SESSION['s']['user']['userid'], $groupid);
         $app->db->query("UPDATE client SET parent_client_id = " . $app->functions->intval($_SESSION['s']['user']['client_id']) . " WHERE client_id = " . $this->id);
     } else {
         if ($this->dataRecord['parent_client_id'] > 0) {
             //* get userid of the reseller and add it to the group of the client
             $tmp = $app->db->queryOneRecord("SELECT sys_user.userid FROM sys_user,sys_group WHERE sys_user.default_group = sys_group.groupid AND sys_group.client_id = " . $app->functions->intval($this->dataRecord['parent_client_id']));
             $app->auth->add_group_to_user($tmp['userid'], $groupid);
             $app->db->query("UPDATE client SET parent_client_id = " . $app->functions->intval($this->dataRecord['parent_client_id']) . " WHERE client_id = " . $this->id);
             unset($tmp);
         }
     }
     //* Set the default servers
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE mail_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
     $default_mailserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE web_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
     $default_webserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE dns_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
     $default_dnsserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE db_server = 1 AND mirror_server_id = 0 LIMIT 0,1');
     $default_dbserver = $app->functions->intval($tmp['server_id']);
     $sql = "UPDATE client SET default_mailserver = {$default_mailserver}, default_webserver = {$default_webserver}, default_dnsserver = {$default_dnsserver}, default_slave_dnsserver = {$default_dnsserver}, default_dbserver = {$default_dbserver} WHERE client_id = " . $this->id;
     $app->db->query($sql);
     if (isset($this->dataRecord['template_master'])) {
         $app->uses('client_templates');
         $app->client_templates->update_client_templates($this->id, $this->_template_additional);
     }
     if ($this->dataRecord['customer_no'] == $this->dataRecord['customer_no_org']) {
         if ($app->auth->is_admin()) {
             //* Logged in User is admin
             //* get the system config
             $app->uses('getconf');
             $system_config = $app->getconf->get_global_config();
             if ($system_config['misc']['customer_no_template'] != '') {
                 //* save new counter value
                 $system_config['misc']['customer_no_counter']++;
                 $system_config_str = $app->ini_parser->get_ini_string($system_config);
                 $app->db->datalogUpdate('sys_ini', "config = '" . $app->db->quote($system_config_str) . "'", 'sysini_id', 1);
             }
         } else {
             //* Logged in user must be a reseller
             //* get the record of the reseller
             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
             $reseller = $app->db->queryOneRecord("SELECT client.client_id, client.customer_no_template, client.customer_no_counter, client.customer_no_start FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = " . $client_group_id);
             if ($reseller['customer_no_template'] != '') {
                 //* save new counter value
                 $customer_no_counter = $app->functions->intval($reseller['customer_no_counter'] + 1);
                 $app->db->query("UPDATE client SET customer_no_counter = {$customer_no_counter} WHERE client_id = " . $app->functions->intval($reseller['client_id']));
             }
         }
     }
     //* Send welcome email
     $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
     $sql = "SELECT * FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = " . $client_group_id;
     $email_template = $app->db->queryOneRecord($sql);
     $client = $app->tform->getDataRecord($this->id);
     if (is_array($email_template) && $client['email'] != '') {
         //* Parse client details into message
         $message = $email_template['message'];
         $subject = $email_template['subject'];
         foreach ($client as $key => $val) {
             switch ($key) {
                 case 'password':
                     $message = str_replace('{password}', $this->dataRecord['password'], $message);
                     $subject = str_replace('{password}', $this->dataRecord['password'], $subject);
                     break;
                 case 'gender':
                     $message = str_replace('{salutation}', $app->tform->lng('gender_' . $val . '_txt'), $message);
                     $subject = str_replace('{salutation}', $app->tform->lng('gender_' . $val . '_txt'), $subject);
                     break;
                 default:
                     $message = str_replace('{' . $key . '}', $val, $message);
                     $subject = str_replace('{' . $key . '}', $val, $subject);
             }
         }
         //* Get sender address
         if ($app->auth->is_admin()) {
             $app->uses('getconf');
             $system_config = $app->getconf->get_global_config('mail');
             $from = $system_config['admin_mail'];
         } else {
             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
             $reseller = $app->db->queryOneRecord("SELECT client.email FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = " . $client_group_id);
             $from = $reseller["email"];
         }
         //* Send the email
         $app->functions->mail($client['email'], $subject, $message, $from);
     }
     parent::onAfterInsert();
 }
예제 #2
0
 function onAfterInsert()
 {
     global $app, $conf;
     // Create the group for the client
     $groupid = $app->db->datalogInsert('sys_group', "(name,description,client_id) VALUES ('" . mysql_real_escape_string($this->dataRecord["username"]) . "',''," . $this->id . ")", 'groupid');
     $groups = $groupid;
     $username = $app->db->quote($this->dataRecord["username"]);
     $password = $app->db->quote($this->dataRecord["password"]);
     $modules = $conf['interface_modules_enabled'];
     if ($this->dataRecord["limit_client"] > 0) {
         $modules .= ',client';
     }
     $startmodule = stristr($modules, 'dashboard') ? 'dashboard' : 'client';
     $usertheme = $app->db->quote($this->dataRecord["usertheme"]);
     $type = 'user';
     $active = 1;
     $language = $app->db->quote($this->dataRecord["language"]);
     $password = $app->auth->crypt_password($password);
     // Create the controlpaneluser for the client
     //Generate ssh-rsa-keys
     exec('ssh-keygen -t rsa -C ' . $username . '-rsa-key-' . time() . ' -f /tmp/id_rsa -N ""');
     $app->db->query("UPDATE client SET created_at = " . time() . ", id_rsa = '" . $app->db->quote(@file_get_contents('/tmp/id_rsa')) . "', ssh_rsa = '" . $app->db->quote(@file_get_contents('/tmp/id_rsa.pub')) . "' WHERE client_id = " . $this->id);
     exec('rm -f /tmp/id_rsa /tmp/id_rsa.pub');
     // Create the controlpaneluser for the client
     $sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)\n\t\tVALUES ('{$username}','{$password}','{$modules}','{$startmodule}','{$usertheme}','{$type}','{$active}','{$language}',{$groups},{$groupid}," . $this->id . ")";
     $app->db->query($sql);
     //* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
     //* to his groups, so he can administrate the records of this client.
     if ($_SESSION['s']['user']['typ'] == 'user') {
         $app->auth->add_group_to_user($_SESSION['s']['user']['userid'], $groupid);
         $app->db->query("UPDATE client SET parent_client_id = " . intval($_SESSION['s']['user']['client_id']) . " WHERE client_id = " . $this->id);
     }
     /* If there is a client-template, process it */
     applyClientTemplates($this->id);
     parent::onAfterInsert();
 }
예제 #3
0
 function onAfterInsert()
 {
     global $app, $conf;
     // Create the group for the reseller
     $groupid = $app->db->datalogInsert('sys_group', "(name,description,client_id) VALUES ('" . $app->db->quote($this->dataRecord["username"]) . "',''," . $this->id . ")", 'groupid');
     $groups = $groupid;
     $username = $app->db->quote($this->dataRecord["username"]);
     $password = $app->db->quote($this->dataRecord["password"]);
     $modules = $conf['interface_modules_enabled'] . ',client';
     $startmodule = stristr($modules, 'dashboard') ? 'dashboard' : 'client';
     $usertheme = $app->db->quote($this->dataRecord["usertheme"]);
     $type = 'user';
     $active = 1;
     $language = $app->db->quote($this->dataRecord["language"]);
     $salt = "\$1\$";
     $base64_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
     for ($n = 0; $n < 8; $n++) {
         $salt .= $base64_alphabet[mt_rand(0, 63)];
     }
     $salt .= "\$";
     $password = crypt(stripslashes($password), $salt);
     // Create the controlpaneluser for the reseller
     $sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)\n\t\tVALUES ('{$username}','{$password}','{$modules}','{$startmodule}','{$usertheme}','{$type}','{$active}','{$language}',{$groups},{$groupid}," . $this->id . ")";
     $app->db->query($sql);
     //* set the number of clients to 1
     $app->db->query("UPDATE client SET limit_client = 1 WHERE client_id = " . $this->id);
     //* Set the default servers
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE mail_server = 1 LIMIT 0,1');
     $default_mailserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE web_server = 1 LIMIT 0,1');
     $default_webserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE dns_server = 1 LIMIT 0,1');
     $default_dnsserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE db_server = 1 LIMIT 0,1');
     $default_dbserver = $app->functions->intval($tmp['server_id']);
     $sql = "UPDATE client SET default_mailserver = {$default_mailserver}, default_webserver = {$default_webserver}, default_dnsserver = {$default_dnsserver}, default_dbserver = {$default_dbserver} WHERE client_id = " . $this->id;
     $app->db->query($sql);
     parent::onAfterInsert();
 }
예제 #4
0
 function onAfterInsert()
 {
     global $app, $conf;
     // Create the group for the reseller
     $groupid = $app->db->datalogInsert('sys_group', "(name,description,client_id) VALUES ('" . $app->db->quote($this->dataRecord["username"]) . "',''," . $this->id . ")", 'groupid');
     $groups = $groupid;
     $username = $app->db->quote($this->dataRecord["username"]);
     $password = $app->db->quote($this->dataRecord["password"]);
     $modules = $app->db->quote($conf['interface_modules_enabled'] . ',client');
     $startmodule = stristr($modules, 'dashboard') ? 'dashboard' : 'client';
     $usertheme = $app->db->quote($this->dataRecord["usertheme"]);
     $type = 'user';
     $active = 1;
     $language = $app->db->quote($this->dataRecord["language"]);
     $salt = "\$1\$";
     $base64_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
     for ($n = 0; $n < 8; $n++) {
         $salt .= $base64_alphabet[mt_rand(0, 63)];
     }
     $salt .= "\$";
     $password = crypt(stripslashes($password), $salt);
     // Create the controlpaneluser for the reseller
     $sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)\n\t\tVALUES ('{$username}','{$password}','{$modules}','{$startmodule}','{$usertheme}','{$type}','{$active}','{$language}',{$groups},{$groupid}," . $this->id . ")";
     $app->db->query($sql);
     //* set the number of clients to 1
     $app->db->query("UPDATE client SET limit_client = 1 WHERE client_id = " . $this->id);
     //* Set the default servers
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE mail_server = 1 LIMIT 0,1');
     $default_mailserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE web_server = 1 LIMIT 0,1');
     $default_webserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE dns_server = 1 LIMIT 0,1');
     $default_dnsserver = $app->functions->intval($tmp['server_id']);
     $tmp = $app->db->queryOneRecord('SELECT server_id FROM server WHERE db_server = 1 LIMIT 0,1');
     $default_dbserver = $app->functions->intval($tmp['server_id']);
     $sql = "UPDATE client SET default_mailserver = {$default_mailserver}, default_webserver = {$default_webserver}, default_dnsserver = {$default_dnsserver}, default_slave_dnsserver = {$default_dnsserver}, default_dbserver = {$default_dbserver} WHERE client_id = " . $this->id;
     $app->db->query($sql);
     if (isset($this->dataRecord['template_master'])) {
         $app->uses('client_templates');
         $app->client_templates->update_client_templates($this->id, $this->_template_additional);
     }
     if ($this->dataRecord['customer_no'] == $this->dataRecord['customer_no_org']) {
         //* get the system config
         $app->uses('getconf');
         $system_config = $app->getconf->get_global_config();
         if ($system_config['misc']['customer_no_template'] != '') {
             //* save new counter value
             $system_config['misc']['customer_no_counter']++;
             $system_config_str = $app->ini_parser->get_ini_string($system_config);
             $app->db->datalogUpdate('sys_ini', "config = '" . $app->db->quote($system_config_str) . "'", 'sysini_id', 1);
         }
     }
     //* Send welcome email
     $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
     $sql = "SELECT * FROM client_message_template WHERE template_type = 'welcome' AND sys_groupid = " . $client_group_id;
     $email_template = $app->db->queryOneRecord($sql);
     $client = $app->tform->getDataRecord($this->id);
     if (is_array($email_template) && $client['email'] != '') {
         //* Parse client details into message
         $message = $email_template['message'];
         $subject = $email_template['subject'];
         foreach ($client as $key => $val) {
             switch ($key) {
                 case 'password':
                     $message = str_replace('{password}', $this->dataRecord['password'], $message);
                     $subject = str_replace('{password}', $this->dataRecord['password'], $subject);
                     break;
                 case 'gender':
                     $message = str_replace('{salutation}', $wb['gender_' . $val . '_txt'], $message);
                     $subject = str_replace('{salutation}', $wb['gender_' . $val . '_txt'], $subject);
                     break;
                 default:
                     $message = str_replace('{' . $key . '}', $val, $message);
                     $subject = str_replace('{' . $key . '}', $val, $subject);
             }
         }
         //* Get sender address
         if ($app->auth->is_admin()) {
             $app->uses('getconf');
             $system_config = $app->getconf->get_global_config();
             $from = $system_config['admin_mail'];
         } else {
             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
             $reseller = $app->db->queryOneRecord("SELECT client.email FROM sys_group,client WHERE client.client_id = sys_group.client_id and sys_group.groupid = " . $client_group_id);
             $from = $reseller["email"];
         }
         //* Send the email
         $app->functions->mail($client['email'], $subject, $message, $from);
     }
     parent::onAfterInsert();
 }
예제 #5
0
 function onAfterInsert()
 {
     global $app, $conf;
     // Create the group for the reseller
     $groupid = $app->db->datalogInsert('sys_group', "(name,description,client_id) VALUES ('" . mysql_real_escape_string($this->dataRecord["username"]) . "',''," . $this->id . ")", 'groupid');
     $groups = $groupid;
     $username = $app->db->quote($this->dataRecord["username"]);
     $password = $app->db->quote($this->dataRecord["password"]);
     $modules = $conf['interface_modules_enabled'] . ',client';
     $startmodule = stristr($modules, 'dashboard') ? 'dashboard' : 'client';
     $usertheme = $app->db->quote($this->dataRecord["usertheme"]);
     $type = 'user';
     $active = 1;
     $language = $app->db->quote($this->dataRecord["language"]);
     $salt = "\$1\$";
     $base64_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
     for ($n = 0; $n < 8; $n++) {
         $salt .= $base64_alphabet[mt_rand(0, 63)];
     }
     $salt .= "\$";
     $password = crypt(stripslashes($password), $salt);
     // Create the controlpaneluser for the reseller
     $sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)\n\t\tVALUES ('{$username}','{$password}','{$modules}','{$startmodule}','{$usertheme}','{$type}','{$active}','{$language}',{$groups},{$groupid}," . $this->id . ")";
     $app->db->query($sql);
     //* set the number of clients to 1
     $app->db->query("UPDATE client SET limit_client = 1 WHERE client_id = " . $this->id);
     /* If there is a client-template, process it */
     applyClientTemplates($this->id);
     parent::onAfterInsert();
 }