Skip to content

Commit b5a23a1

Browse files
committed
Added reseller capabilities to all modules.
Added a server module for clients and a mail plugin.
1 parent 8a6a58c commit b5a23a1

File tree

23 files changed

+510
-92
lines changed

23 files changed

+510
-92
lines changed

TODO.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ Administration module
4646
Clients module
4747
--------------------------------------
4848

49-
- Add the ability that Clients can add clients (Reseller functionality)
50-
Task assigned to: Till
51-
5249

5350
Sites (web) module
5451
--------------------------------------

install/sql/ispconfig3.sql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ CREATE TABLE `client` (
6060
`default_dnsserver` int(10) unsigned NOT NULL default '1',
6161
`limit_dns_zone` int(11) NOT NULL default '-1',
6262
`limit_dns_record` int(11) NOT NULL default '-1',
63+
`limit_client` int(11) NOT NULL default '0',
64+
`parent_client_id` int(10) unsigned NOT NULL default '0',
6365
`username` varchar(255) default NULL,
6466
`password` varchar(255) default NULL,
6567
`language` varchar(255) NOT NULL default 'en',
@@ -847,15 +849,15 @@ CREATE TABLE `web_domain` (
847849
`redirect_type` varchar(255) default NULL,
848850
`redirect_path` varchar(255) default NULL,
849851
`ssl` enum('n','y') NOT NULL default 'n',
850-
`ssl_state` varchar(255) NOT NULL,
851-
`ssl_locality` varchar(255) NOT NULL,
852-
`ssl_organisation` varchar(255) NOT NULL,
853-
`ssl_organisation_unit` varchar(255) NOT NULL,
854-
`ssl_country` varchar(255) NOT NULL,
855-
`ssl_request` mediumtext NOT NULL,
856-
`ssl_cert` mediumtext NOT NULL,
857-
`ssl_bundle` mediumtext NOT NULL,
858-
`ssl_action` varchar(10) NOT NULL,
852+
`ssl_state` varchar(255) NULL,
853+
`ssl_locality` varchar(255) NULL,
854+
`ssl_organisation` varchar(255) NULL,
855+
`ssl_organisation_unit` varchar(255) NULL,
856+
`ssl_country` varchar(255) NULL,
857+
`ssl_request` mediumtext NULL,
858+
`ssl_cert` mediumtext NULL,
859+
`ssl_bundle` mediumtext NULL,
860+
`ssl_action` varchar(10) NULL,
859861
`active` varchar(255) NOT NULL default 'y',
860862
PRIMARY KEY (`domain_id`)
861863
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

install/tpl/config.inc.php.master

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ define('ISPC_THEMES_PATH', ISPC_ROOT_PATH.'/web/themes');
5858
define('ISPC_TEMP_PATH', ISPC_ROOT_PATH.'/temp');
5959
define('ISPC_CACHE_PATH', ISPC_ROOT_PATH.'/cache');
6060

61+
//** Interface settings
62+
define('ISPC_INTERFACE_MODULES_ENABLED', 'mail,sites,dns');
63+
6164

6265
/*
6366
Server variables

interface/lib/app.inc.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function __construct()
6363
if(empty($_SESSION['s']['theme'])) $_SESSION['s']['theme'] = $conf['theme'];
6464
if(empty($_SESSION['s']['language'])) $_SESSION['s']['language'] = $conf['language'];
6565
}
66+
67+
$this->uses('auth');
6668
}
6769

6870
public function uses($classes)
@@ -176,6 +178,9 @@ public function tpl_defaults()
176178
if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') {
177179
$this->tpl->setVar('is_admin', 1);
178180
}
181+
if(isset($_SESSION['s']['user']) && $this->auth->has_clients($_SESSION['s']['user']['userid'])) {
182+
$this->tpl->setVar('is_reseller', 1);
183+
}
179184
}
180185

181186
} // end class

interface/lib/classes/auth.inc.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
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 auth {
32+
33+
public function has_clients($userid) {
34+
global $app, $conf;
35+
36+
$userid = intval($userid);
37+
$client = $app->db->queryOneRecord("SELECT client.limit_client FROM sys_user, client WHERE sys_user.userid = $userid AND sys_user.client_id = client.client_id");
38+
if($client['limit_client'] > 0) {
39+
return true;
40+
} else {
41+
return false;
42+
}
43+
}
44+
45+
//** This function adds a given group id to a given user.
46+
public function add_group_to_user($userid,$groupid) {
47+
global $app;
48+
49+
$userid = intval($userid);
50+
$groupid = intval($groupid);
51+
52+
if($userid > 0 && $groupid > 0) {
53+
$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE userid = $userid");
54+
$groups = explode(',',$user['groups']);
55+
if(!in_array($groupid,$groups)) $groups[] = $groupid;
56+
$groups_string = implode(',',$groups);
57+
$sql = "UPDATE sys_user SET groups = '$groups_string' WHERE userid = $userid";
58+
$app->db->query($sql);
59+
return true;
60+
} else {
61+
return false;
62+
}
63+
}
64+
65+
//** This function removes a given group id from a given user.
66+
public function remove_group_from_user($userid,$groupid) {
67+
global $app;
68+
69+
$userid = intval($userid);
70+
$groupid = intval($groupid);
71+
72+
if($userid > 0 && $groupid > 0) {
73+
$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE userid = $userid");
74+
$groups = explode(',',$user['groups']);
75+
$key = array_search($groupid,$groups);
76+
unset($groups[$key]);
77+
$groups_string = implode(',',$groups);
78+
$sql = "UPDATE sys_user SET groups = '$groups_string' WHERE userid = $userid";
79+
$app->db->query($sql);
80+
return true;
81+
} else {
82+
return false;
83+
}
84+
}
85+
}
86+
87+
?>

interface/lib/classes/tform.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ function getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $sql_ext_whe
718718
}
719719
} else {
720720
if($field['formtype'] == 'PASSWORD') {
721-
if($field['encryption'] == 'CRYPT') {
721+
if(isset($field['encryption']) && $field['encryption'] == 'CRYPT') {
722722
$salt="$1$";
723723
for ($n=0;$n<8;$n++) {
724724
$salt.=chr(mt_rand(64,126));
@@ -999,8 +999,8 @@ function checkPerm($record_id,$perm) {
999999
}
10001000
} else {
10011001
$result = false;
1002-
if($this->formDef["auth_preset"]["userid"] == $_SESSION["s"]["user"]["userid"] && stristr($perm,$this->formDef["auth_preset"]["perm_user"])) $result = true;
1003-
if($this->formDef["auth_preset"]["groupid"] == $_SESSION["s"]["user"]["groupid"] && stristr($perm,$this->formDef["auth_preset"]["perm_group"])) $result = true;
1002+
if(@$this->formDef["auth_preset"]["userid"] == $_SESSION["s"]["user"]["userid"] && stristr($perm,$this->formDef["auth_preset"]["perm_user"])) $result = true;
1003+
if(@$this->formDef["auth_preset"]["groupid"] == $_SESSION["s"]["user"]["groupid"] && stristr($perm,$this->formDef["auth_preset"]["perm_group"])) $result = true;
10041004
if(@stristr($this->formDef["auth_preset"]["perm_other"],$perm)) $result = true;
10051005

10061006
// if preset == 0, everyone can insert a record of this type

interface/lib/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
define('ISPC_TEMP_PATH', ISPC_ROOT_PATH.'/temp');
5252
define('ISPC_CACHE_PATH', ISPC_ROOT_PATH.'/cache');
5353

54+
define('ISPC_INTERFACE_MODULES_ENABLED', 'mail,sites,dns');
5455

5556
//********************************************************************************
5657
//** Future Code idea - pedro - rfc

interface/web/client/client_del.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,35 @@
4848
exit;
4949
}
5050

51-
$app->uses("tform_actions");
52-
$app->tform_actions->onDelete();
51+
$app->uses('tpl,tform');
52+
$app->load('tform_actions');
53+
54+
class page_action extends tform_actions {
55+
function onAfterDelete() {
56+
global $app, $conf;
57+
58+
$client_id = intval($this->dataRecord['client_id']);
59+
60+
if($client_id > 0) {
61+
// TODO: Delete all records (sub-clients, mail, web, etc....) of this client.
62+
63+
// remove the group of the client from the resellers group
64+
$parent_client_id = intval($this->dataRecord['parent_client_id']);
65+
$parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = $parent_client_id");
66+
$client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
67+
$app->auth->remove_group_from_user($parent_user['userid'],$client_group['groupid']);
68+
69+
// delete the group of the client
70+
$app->db->query("DELETE FROM sys_group WHERE client_id = $client_id");
71+
72+
// delete the sys user(s) of the client
73+
$app->db->query("DELETE FROM sys_user WHERE client_id = $client_id");
74+
}
75+
76+
}
77+
}
78+
79+
$page = new page_action;
80+
$page->onDelete()
5381

5482
?>

interface/web/client/client_edit.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ function onAfterInsert() {
6363
$sql = "INSERT INTO sys_group (name,description,client_id) VALUES ('".addslashes($this->dataRecord["username"])."','',".$this->id.")";
6464
$app->db->query($sql);
6565
$groupid = $app->db->insertID();
66+
$groups = $groupid;
6667

6768
$username = addslashes($this->dataRecord["username"]);
6869
$password = addslashes($this->dataRecord["password"]);
69-
$modules = 'mail,sites,dns';
70+
$modules = ISPC_INTERFACE_MODULES_ENABLED;
71+
if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
7072
$startmodule = 'mail';
7173
$usertheme = addslashes($this->dataRecord["usertheme"]);
7274
$type = 'user';
@@ -75,8 +77,17 @@ function onAfterInsert() {
7577

7678
// Create the controlpaneluser for the client
7779
$sql = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
78-
VALUES ('$username',md5('$password'),'$modules','$startmodule','$usertheme','$type','$active','$language',$groupid,$groupid,".$this->id.")";
80+
VALUES ('$username',md5('$password'),'$modules','$startmodule','$usertheme','$type','$active','$language',$groups,$groupid,".$this->id.")";
7981
$app->db->query($sql);
82+
83+
//* If the user who inserted the client is a reseller (not admin), we will have to add this new client group
84+
//* to his groups, so he can administrate the records of this client.
85+
if($_SESSION['s']['user']['typ'] == 'user') {
86+
$app->auth->add_group_to_user($_SESSION['s']['user']['userid'],$groupid);
87+
$app->db->query("UPDATE client SET parent_client_id = ".intval($_SESSION['s']['user']['client_id'])." WHERE client_id = ".$this->id);
88+
}
89+
90+
8091
}
8192

8293

@@ -105,8 +116,15 @@ function onAfterUpdate() {
105116
$app->db->query($sql);
106117
}
107118

108-
109-
119+
// reseller status changed
120+
if(isset($this->dataRecord["limit_client"])) {
121+
$modules = ISPC_INTERFACE_MODULES_ENABLED;
122+
if($this->dataRecord["limit_client"] > 0) $modules .= ',client';
123+
$modules = addslashes($modules);
124+
$client_id = $this->id;
125+
$sql = "UPDATE sys_user SET modules = '$modules' WHERE client_id = $client_id";
126+
$app->db->query($sql);
127+
}
110128
}
111129

112130

interface/web/client/form/client.tform.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
'password' => array (
105105
'datatype' => 'VARCHAR',
106106
'formtype' => 'PASSWORD',
107+
'encryption'=> 'MD5',
107108
'default' => '',
108109
'value' => '',
109110
'separator' => '',
@@ -579,6 +580,20 @@
579580
'rows' => '',
580581
'cols' => ''
581582
),
583+
'limit_client' => array (
584+
'datatype' => 'INTEGER',
585+
'formtype' => 'TEXT',
586+
'validators' => array ( 0 => array ( 'type' => 'ISINT',
587+
'errmsg'=> 'limit_client_error_notint'),
588+
),
589+
'default' => '0',
590+
'value' => '',
591+
'separator' => '',
592+
'width' => '10',
593+
'maxlength' => '10',
594+
'rows' => '',
595+
'cols' => ''
596+
),
582597
##################################
583598
# END Datatable fields
584599
##################################

0 commit comments

Comments
 (0)