Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
commit | author | age
aa1500 1 <?php
T 2
3 /*
4 Copyright (c) 2008, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 class custom_datasource {
b1a6a5 32
aa1500 33     function master_templates($field, $record) {
T 34         global $app, $conf;
94c961 35         $records = $app->db->queryAllRecords("SELECT template_id,template_name FROM client_template WHERE template_type ='m' and ".$app->tform->getAuthSQL('r'));
aa1500 36         $records_new[0] = $app->lng('Custom');
T 37         foreach($records as $rec) {
38             $key = $rec['template_id'];
39             $records_new[$key] = $rec['template_name'];
40         }
41         return $records_new;
42     }
b1a6a5 43
376812 44     function dns_servers($field, $record) {
T 45         global $app, $conf;
b1a6a5 46
376812 47         if($_SESSION["s"]["user"]["typ"] == 'user') {
T 48             // Get the limits of the client
604c0c 49             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
9d9833 50             $client = $app->db->queryOneRecord("SELECT default_dnsserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
cc7a82 51             $sql = "SELECT server_id,server_name FROM server WHERE server_id = ?";
376812 52         } else {
aff9ac 53             $sql = "SELECT server_id,server_name FROM server WHERE dns_server = 1 ORDER BY server_name AND mirror_server_id = 0";
376812 54         }
cc7a82 55         $records = $app->db->queryAllRecords($sql, $client['default_dnsserver']);
376812 56         $records_new = array();
T 57         if(is_array($records)) {
58             foreach($records as $rec) {
59                 $key = $rec['server_id'];
60                 $records_new[$key] = $rec['server_name'];
61             }
62         }
63         return $records_new;
64     }
b1a6a5 65
1fef4a 66     function slave_dns_servers($field, $record) {
FT 67         global $app, $conf;
b1a6a5 68
1fef4a 69         if($_SESSION["s"]["user"]["typ"] == 'user') {
FT 70             // Get the limits of the client
604c0c 71             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
9d9833 72             $client = $app->db->queryOneRecord("SELECT default_slave_dnsserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
a6e3ae 73             $sql = "SELECT server_id,server_name FROM server WHERE server_id = ?";
1fef4a 74         } else {
aff9ac 75             $sql = "SELECT server_id,server_name FROM server WHERE dns_server = 1 ORDER BY server_name AND mirror_server_id = 0";
1fef4a 76         }
cc7a82 77         $records = $app->db->queryAllRecords($sql, $client['default_slave_dnsserver']);
1fef4a 78         $records_new = array();
FT 79         if(is_array($records)) {
80             foreach($records as $rec) {
81                 $key = $rec['server_id'];
82                 $records_new[$key] = $rec['server_name'];
83             }
84         }
85         return $records_new;
86     }
b1a6a5 87
8ab3cd 88     function webdav_domains($field, $record) {
T 89         global $app, $conf;
b1a6a5 90
8ab3cd 91         $servers = $app->db->queryAllRecords("SELECT * FROM server WHERE active = 1 AND mirror_server_id = 0");
T 92         $server_ids = array();
93         $app->uses('getconf');
94         if(is_array($servers) && !empty($servers)){
95             foreach($servers as $server){
96                 $web_config = $app->getconf->get_server_config($server['server_id'], 'web');
97                 if($web_config['server_type'] != 'nginx') $server_ids[] = $server['server_id'];
98             }
99         }
248bc3 100         if(count($server_ids) == 0) return array();
8ab3cd 101         $server_ids = implode(',', $server_ids);
aff9ac 102         $records = $app->db->queryAllRecords("SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id IN (?) AND web_domain.server_id = server.server_id AND ".$app->tform->getAuthSQL('r', 'web_domain')." ORDER BY web_domain.domain", $server_ids);
b1a6a5 103
8ab3cd 104         $records_new = array();
T 105         if(is_array($records)) {
106             foreach($records as $rec) {
107                 $key = $rec['domain_id'];
d5473b 108                 $records_new[$key] = $rec['parent_domain'];
8ab3cd 109             }
T 110         }
111         return $records_new;
112     }
b1a6a5 113
MC 114
be7d7f 115     function client_servers($field, $record) {
T 116         global $app, $conf;
b1a6a5 117
be7d7f 118         $server_type = $field['name'];
b1a6a5 119
f3f32d 120         switch($server_type) {
b1a6a5 121         case 'default_mailserver':
MC 122             $field = 'mail_server';
f3f32d 123             break;
b1a6a5 124         case 'default_webserver':
MC 125             $field = 'web_server';
f3f32d 126             break;
b1a6a5 127         case 'default_dnsserver':
MC 128             $field = 'dns_server';
f3f32d 129             break;
b1a6a5 130         case 'default_slave_dnsserver':
MC 131             $field = 'dns_server';
992797 132             break;
b1a6a5 133         case 'default_fileserver':
MC 134             $field = 'file_server';
f3f32d 135             break;
b1a6a5 136         case 'default_dbserver':
MC 137             $field = 'db_server';
f3f32d 138             break;
b1a6a5 139         case 'default_vserverserver':
MC 140             $field = 'vserver_server';
f3f32d 141             break;
015dff 142         case 'mail_servers':
MC 143             $field = 'mail_server';
bd6659 144             break;
015dff 145         case 'web_servers':
MC 146             $field = 'web_server';
bd6659 147             break;
015dff 148         case 'dns_servers':
MC 149             $field = 'dns_server';
bd6659 150             break;
015dff 151         case 'db_servers':
MC 152             $field = 'db_server';
bd6659 153             break;
b1a6a5 154         default:
MC 155             $field = 'web_server';
f3f32d 156             break;
T 157         }
b1a6a5 158
be7d7f 159         if($_SESSION["s"]["user"]["typ"] == 'user') {
T 160             // Get the limits of the client
604c0c 161             $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
cc7a82 162             $sql = "SELECT $server_type as server_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?";
MC 163             $client = $app->db->queryOneRecord($sql, $client_group_id);
f3f32d 164             if($client['server_id'] > 0) {
T 165                 //* Select the default server for the client
cc7a82 166                 $sql = "SELECT server_id,server_name FROM server WHERE server_id = ?";
MC 167                 $records = $app->db->queryAllRecords($sql, $client['server_id']);
f3f32d 168             } else {
T 169                 //* Not able to find the clients defaults, use this as fallback and add a warning message to the log
b1a6a5 170                 $app->log('Unable to find default server for client in custom_datasource.inc.php', 1);
aff9ac 171                 $sql = "SELECT server_id,server_name FROM server WHERE ?? = 1 AND mirror_server_id = 0 ORDER BY server_name";
cc7a82 172                 $records = $app->db->queryAllRecords($sql, $field);
f3f32d 173             }
be7d7f 174         } else {
f3f32d 175             //* The logged in user is admin, so we show him all available servers of a specific type.
aff9ac 176             $sql = "SELECT server_id,server_name FROM server WHERE ?? = 1 AND mirror_server_id = 0 ORDER BY server_name";
cc7a82 177             $records = $app->db->queryAllRecords($sql, $field);
be7d7f 178         }
b1a6a5 179
cc7a82 180         
be7d7f 181         $records_new = array();
T 182         if(is_array($records)) {
183             foreach($records as $rec) {
184                 $key = $rec['server_id'];
185                 $records_new[$key] = $rec['server_name'];
186             }
187         }
188         return $records_new;
189     }
b1a6a5 190
MC 191
aa1500 192
T 193 }
194
b1a6a5 195 ?>