commit | author | age
|
0b0dc9
|
1 |
<?php |
M |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
Modified 2009, Marius Cramer, pixcept KG |
|
6 |
All rights reserved. |
|
7 |
|
|
8 |
Redistribution and use in source and binary forms, with or without modification, |
|
9 |
are permitted provided that the following conditions are met: |
|
10 |
|
|
11 |
* Redistributions of source code must retain the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer. |
|
13 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
this list of conditions and the following disclaimer in the documentation |
|
15 |
and/or other materials provided with the distribution. |
|
16 |
* Neither the name of ISPConfig nor the names of its contributors |
|
17 |
may be used to endorse or promote products derived from this software without |
|
18 |
specific prior written permission. |
|
19 |
|
|
20 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
21 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
22 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
23 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
24 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
25 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
26 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
27 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
28 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
29 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
*/ |
|
31 |
|
|
32 |
/****************************************** |
|
33 |
* Begin Form configuration |
|
34 |
******************************************/ |
|
35 |
|
|
36 |
$tform_def_file = "form/cron.tform.php"; |
|
37 |
|
|
38 |
/****************************************** |
|
39 |
* End Form configuration |
|
40 |
******************************************/ |
|
41 |
|
7fe908
|
42 |
require_once '../../lib/config.inc.php'; |
MC |
43 |
require_once '../../lib/app.inc.php'; |
0b0dc9
|
44 |
|
M |
45 |
//* Check permissions for module |
|
46 |
$app->auth->check_module_permissions('sites'); |
|
47 |
|
|
48 |
// Loading classes |
|
49 |
$app->uses('tpl,tform,tform_actions,validate_cron'); |
|
50 |
$app->load('tform_actions'); |
|
51 |
|
|
52 |
class page_action extends tform_actions { |
7fe908
|
53 |
|
0b0dc9
|
54 |
function onShowNew() { |
M |
55 |
global $app, $conf; |
7fe908
|
56 |
|
0b0dc9
|
57 |
// we will check only users, not admins |
M |
58 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
3cebc3
|
59 |
if(!$app->tform->checkClientLimit('limit_cron')) { |
T |
60 |
$app->error($app->tform->wordbook["limit_cron_txt"]); |
|
61 |
} |
|
62 |
if(!$app->tform->checkResellerLimit('limit_cron')) { |
|
63 |
$app->error('Reseller: '.$app->tform->wordbook["limit_cron_txt"]); |
0b0dc9
|
64 |
} |
M |
65 |
} |
7fe908
|
66 |
|
0b0dc9
|
67 |
parent::onShowNew(); |
M |
68 |
} |
7fe908
|
69 |
|
0b0dc9
|
70 |
function onShowEnd() { |
M |
71 |
global $app, $conf; |
7fe908
|
72 |
|
MC |
73 |
if($this->id > 0) { |
|
74 |
//* we are editing a existing record |
|
75 |
$app->tpl->setVar("edit_disabled", 1); |
|
76 |
$app->tpl->setVar("parent_domain_id_value", $this->dataRecord["parent_domain_id"]); |
|
77 |
} else { |
|
78 |
$app->tpl->setVar("edit_disabled", 0); |
|
79 |
} |
|
80 |
|
0b0dc9
|
81 |
parent::onShowEnd(); |
M |
82 |
} |
7fe908
|
83 |
|
0b0dc9
|
84 |
function onSubmit() { |
M |
85 |
global $app, $conf; |
7fe908
|
86 |
|
0b0dc9
|
87 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
M |
88 |
// Get the limits of the client |
604c0c
|
89 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
9d9833
|
90 |
$client = $app->db->queryOneRecord("SELECT limit_cron, limit_cron_type FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
7fe908
|
91 |
|
0b0dc9
|
92 |
// When the record is updated |
M |
93 |
if($this->id > 0) { |
7fe908
|
94 |
// When the record is inserted |
0b0dc9
|
95 |
} else { |
M |
96 |
// Check if the user may add another cron job. |
|
97 |
if($client["limit_cron"] >= 0) { |
9d9833
|
98 |
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM cron WHERE sys_groupid = ?", $client_group_id); |
0b0dc9
|
99 |
if($tmp["number"] >= $client["limit_cron"]) { |
M |
100 |
$app->error($app->tform->wordbook["limit_cron_txt"]); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
|
7fe908
|
106 |
// Get the record of the parent domain |
cc7a82
|
107 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]); |
7fe908
|
108 |
if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); |
MC |
109 |
|
|
110 |
// Set fixed values |
|
111 |
$this->dataRecord["server_id"] = $parent_domain["server_id"]; |
|
112 |
|
|
113 |
//* get type of command |
|
114 |
$command = $this->dataRecord["command"]; |
|
115 |
if(preg_match("'^http(s)?:\/\/'i", $command)) { |
|
116 |
$this->dataRecord["type"] = 'url'; |
|
117 |
} else { |
cc7a82
|
118 |
$domain_owner = $app->db->queryOneRecord("SELECT limit_cron_type FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $parent_domain["sys_groupid"]); |
7fe908
|
119 |
//* True when the site is assigned to a client |
615a0a
|
120 |
if(isset($domain_owner["limit_cron_type"])) { |
T |
121 |
if($domain_owner["limit_cron_type"] == 'full') { |
|
122 |
$this->dataRecord["type"] = 'full'; |
|
123 |
} else { |
|
124 |
$this->dataRecord["type"] = 'chrooted'; |
|
125 |
} |
|
126 |
} else { |
|
127 |
//* True when the site is assigned to the admin |
|
128 |
$this->dataRecord["type"] = 'full'; |
|
129 |
} |
7fe908
|
130 |
} |
MC |
131 |
|
|
132 |
parent::onSubmit(); |
0b0dc9
|
133 |
} |
7fe908
|
134 |
|
MC |
135 |
function onUpdateSave($sql) { |
|
136 |
global $app; |
|
137 |
|
|
138 |
$has_error = false; |
|
139 |
//* last chance to stop this, so check frequency limit! |
|
140 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
141 |
// Get the limits of the client |
604c0c
|
142 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
143 |
$client = $app->db->queryOneRecord("SELECT limit_cron_frequency, limit_cron_type FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
7fe908
|
144 |
|
MC |
145 |
if($client["limit_cron_frequency"] > 1) { |
|
146 |
if($app->tform->cron_min_freq < $client["limit_cron_frequency"]) { |
|
147 |
$app->error($app->tform->wordbook["limit_cron_frequency_txt"]); |
|
148 |
$has_error = true; |
|
149 |
} |
4b5da4
|
150 |
} |
TB |
151 |
|
|
152 |
if($client["limit_cron_type"] == 'url' && $this->dataRecord["type"] != 'url') { |
|
153 |
$app->error($app->tform->wordbook["limit_cron_url_txt"]); |
|
154 |
$has_error = true; |
7fe908
|
155 |
} |
MC |
156 |
} |
|
157 |
|
|
158 |
if($has_error == true) { |
|
159 |
parent::onError(); |
|
160 |
exit; |
|
161 |
} |
|
162 |
else parent::onUpdateSave($sql); |
|
163 |
} |
|
164 |
|
|
165 |
function onInsertSave($sql) { |
|
166 |
global $app; |
|
167 |
|
|
168 |
$has_error = false; |
|
169 |
//* last chance to stop this, so check frequency limit! |
|
170 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
171 |
// Get the limits of the client |
604c0c
|
172 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
173 |
$client = $app->db->queryOneRecord("SELECT limit_cron_frequency, limit_cron_type FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
7fe908
|
174 |
|
MC |
175 |
if($client["limit_cron_frequency"] > 1) { |
|
176 |
if($app->tform->cron_min_freq < $client["limit_cron_frequency"]) { |
|
177 |
$app->error($app->tform->wordbook["limit_cron_frequency_txt"]); |
|
178 |
$has_error = true; |
|
179 |
} |
|
180 |
} |
4b5da4
|
181 |
|
TB |
182 |
if($client["limit_cron_type"] == 'url' && $this->dataRecord["type"] != 'url') { |
|
183 |
$app->error($app->tform->wordbook["limit_cron_url_txt"]); |
|
184 |
$has_error = true; |
|
185 |
} |
7fe908
|
186 |
} |
MC |
187 |
|
|
188 |
if($has_error == true) { |
|
189 |
parent::onError(); |
|
190 |
exit; |
|
191 |
} else { |
52bc49
|
192 |
return parent::onInsertSave($sql); |
T |
193 |
} |
7fe908
|
194 |
} |
MC |
195 |
|
0b0dc9
|
196 |
function onAfterInsert() { |
M |
197 |
global $app, $conf; |
7fe908
|
198 |
|
cc7a82
|
199 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]); |
7fe908
|
200 |
$server_id = $web["server_id"]; |
MC |
201 |
|
|
202 |
// The cron shall be owned by the same group then the website |
604c0c
|
203 |
$sys_groupid = $app->functions->intval($web['sys_groupid']); |
7fe908
|
204 |
|
cc7a82
|
205 |
$sql = "UPDATE cron SET server_id = ?, sys_groupid = ? WHERE id = ?"; |
MC |
206 |
$app->db->query($sql, $server_id, $sys_groupid, $this->id); |
0b0dc9
|
207 |
} |
7fe908
|
208 |
|
0b0dc9
|
209 |
function onAfterUpdate() { |
M |
210 |
global $app, $conf; |
7fe908
|
211 |
|
MC |
212 |
|
0b0dc9
|
213 |
} |
7fe908
|
214 |
|
0b0dc9
|
215 |
} |
M |
216 |
|
|
217 |
$page = new page_action; |
|
218 |
$page->onLoad(); |
|
219 |
|
7fe908
|
220 |
?> |