Skip to content

Commit 4f68a7f

Browse files
committed
- Fixed login attempts bug
- Fixed bug were the interface is enabled after an update on a server were interface = no selected during install - Fixed a replication problem and made replication more fault tolerant.
1 parent a672b1e commit 4f68a7f

File tree

7 files changed

+75
-67
lines changed

7 files changed

+75
-67
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public function install_ispconfig()
670670

671671
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
672672
//* and create the symlink
673-
if($this->install_ispconfig_interface == true) {
673+
if($this->install_ispconfig_interface == true && $this->is_update == false) {
674674
if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
675675
if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
676676
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");

install/dist/lib/opensuse.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ public function install_ispconfig()
688688

689689
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
690690
//* and create the symlink
691-
if($this->install_ispconfig_interface == true) {
691+
if($this->install_ispconfig_interface == true && $this->is_update == false) {
692692
if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
693693
if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
694694
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");

install/lib/installer_base.lib.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class installer_base {
3535
var $db;
3636
public $conf;
3737
public $install_ispconfig_interface = true;
38-
38+
public $is_update = false; // true if it is an update, falsi if it is a new install
3939

4040

4141
public function __construct()
@@ -938,13 +938,11 @@ public function install_ispconfig()
938938
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
939939

940940
//* Copy the ISPConfig vhost for the controlpanel
941-
// TODO: These are missing! should they be "vhost_dist_*_dir" ?
942941
$vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
943942
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
944943

945944

946945
// Dont just copy over the virtualhost template but add some custom settings
947-
948946
$content = rf("tpl/apache_ispconfig.vhost.master");
949947
$content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
950948

@@ -959,7 +957,7 @@ public function install_ispconfig()
959957

960958
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
961959
//* and create the symlink
962-
if($this->install_ispconfig_interface == true) {
960+
if($this->install_ispconfig_interface == true && $this->is_update == false) {
963961
if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
964962
if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
965963
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");

install/update.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
$conf['ispconfig_log_priority'] = $conf_old["log_priority"];
102102

103103
$inst = new installer();
104+
$inst->is_update = true;
104105

105106
//** Detect the installed applications
106107
$inst->find_installed_apps();

interface/web/login/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public function render() {
9292
}
9393

9494
//* Check if there already wrong logins
95-
$sql = "SELECT * FROM `attempts_login` WHERE `ip`= '{$ip}' AND `login_time` < NOW() + INTERVAL 15 MINUTE LIMIT 1";
95+
$sql = "SELECT * FROM `attempts_login` WHERE `ip`= '{$ip}' AND `login_time` > (NOW() - INTERVAL 1 MINUTE) LIMIT 1";
96+
echo $sql;
9697
$alreadyfailed = $app->db->queryOneRecord($sql);
9798
//* login to much wrong
9899
if($alreadyfailed['times'] > 5) {

interface/web/sites/ajax_get_ip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$sql = "SELECT ip_address FROM server_ip WHERE server_id = $server_id";
4242
$ips = $app->db->queryAllRecords($sql);
4343
// $ip_select = "<option value=''></option>";
44-
$ip_select = "";
44+
$ip_select = "<option value='*'>*</option>\r\n";
4545
if(is_array($ips)) {
4646
foreach( $ips as $ip) {
4747
//$selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';

server/lib/classes/modules.inc.php

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -88,74 +88,80 @@ function processDatalog() {
8888
$records = $app->dbmaster->queryAllRecords($sql);
8989
foreach($records as $d) {
9090

91-
$data = unserialize(stripslashes($d["data"]));
91+
if(!$data = unserialize(stripslashes($d["data"]))) {
92+
$data = unserialize($d["data"]);
93+
}
9294
$replication_error = false;
9395

9496
$this->current_datalog_id = $d["datalog_id"];
9597

96-
if($d["action"] == 'i') {
97-
$idx = explode(":",$d["dbidx"]);
98-
$tmp_sql1 = '';
99-
$tmp_sql2 = '';
100-
foreach($data['new'] as $fieldname => $val) {
101-
$tmp_sql1 .= "`$fieldname`,";
102-
$tmp_sql2 .= "'$val',";
103-
}
104-
$tmp_sql1 = substr($tmp_sql1,0,-1);
105-
$tmp_sql2 = substr($tmp_sql2,0,-1);
106-
//$tmp_sql1 .= "$idx[0]";
107-
//$tmp_sql2 .= "$idx[1]";
108-
$sql = "REPLACE INTO $d[dbtable] ($tmp_sql1) VALUES ($tmp_sql2)";
109-
$app->db->query($sql);
110-
if($app->db->errorNumber > 0) {
111-
$replication_error = true;
112-
$app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
113-
}
114-
$app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
115-
}
116-
117-
if($d["action"] == 'u') {
118-
$sql = "UPDATE $d[dbtable] SET ";
119-
foreach($data['new'] as $fieldname => $val) {
120-
$sql .= "`$fieldname` = '$val',";
98+
if(count($data['new']) > 0) {
99+
if($d["action"] == 'i' || $d["action"] == 'u') {
100+
$idx = explode(":",$d["dbidx"]);
101+
$tmp_sql1 = '';
102+
$tmp_sql2 = '';
103+
foreach($data['new'] as $fieldname => $val) {
104+
$tmp_sql1 .= "`$fieldname`,";
105+
$tmp_sql2 .= "'$val',";
106+
}
107+
$tmp_sql1 = substr($tmp_sql1,0,-1);
108+
$tmp_sql2 = substr($tmp_sql2,0,-1);
109+
//$tmp_sql1 .= "$idx[0]";
110+
//$tmp_sql2 .= "$idx[1]";
111+
$sql = "REPLACE INTO $d[dbtable] ($tmp_sql1) VALUES ($tmp_sql2)";
112+
$app->db->query($sql);
113+
if($app->db->errorNumber > 0) {
114+
$replication_error = true;
115+
$app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
116+
}
117+
$app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
121118
}
122-
$sql = substr($sql,0,-1);
123-
$idx = explode(":",$d["dbidx"]);
124-
$sql .= " WHERE $idx[0] = $idx[1]";
125-
$app->db->query($sql);
126-
if($app->db->errorNumber > 0) {
127-
$replication_error = true;
128-
$app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
119+
/*
120+
if($d["action"] == 'u') {
121+
$sql = "UPDATE $d[dbtable] SET ";
122+
foreach($data['new'] as $fieldname => $val) {
123+
$sql .= "`$fieldname` = '$val',";
124+
}
125+
$sql = substr($sql,0,-1);
126+
$idx = explode(":",$d["dbidx"]);
127+
$sql .= " WHERE $idx[0] = $idx[1]";
128+
$app->db->query($sql);
129+
if($app->db->errorNumber > 0) {
130+
$replication_error = true;
131+
$app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
132+
}
133+
$app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
129134
}
130-
$app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
131-
}
132-
133-
if($d["action"] == 'd') {
134-
$idx = explode(":",$d["dbidx"]);
135-
$sql = "DELETE FROM $d[dbtable] ";
136-
$sql .= " WHERE $idx[0] = $idx[1]";
137-
$app->db->query($sql);
138-
if($app->db->errorNumber > 0) {
139-
$replication_error = true;
140-
$app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
135+
*/
136+
if($d["action"] == 'd') {
137+
$idx = explode(":",$d["dbidx"]);
138+
$sql = "DELETE FROM $d[dbtable] ";
139+
$sql .= " WHERE $idx[0] = $idx[1]";
140+
$app->db->query($sql);
141+
if($app->db->errorNumber > 0) {
142+
$replication_error = true;
143+
$app->log("Replication failed. Error: (" . $d[dbtable] . ") " . $app->db->errorMessage . " # SQL: " . $sql,LOGLEVEL_ERROR);
144+
}
145+
$app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
141146
}
142-
$app->log("Replicated from master: ".$sql,LOGLEVEL_DEBUG);
143-
}
144147

145148

146-
if($replication_error == false) {
147-
$this->raiseTableHook($d["dbtable"],$d["action"],$data);
148-
//$app->dbmaster->query("DELETE FROM sys_datalog WHERE datalog_id = ".$d["datalog_id"]);
149-
//$app->log("Deleting sys_datalog ID ".$d["datalog_id"],LOGLEVEL_DEBUG);
150-
$app->dbmaster->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
151-
$app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
149+
if($replication_error == false) {
150+
$this->raiseTableHook($d["dbtable"],$d["action"],$data);
151+
//$app->dbmaster->query("DELETE FROM sys_datalog WHERE datalog_id = ".$d["datalog_id"]);
152+
//$app->log("Deleting sys_datalog ID ".$d["datalog_id"],LOGLEVEL_DEBUG);
153+
$app->dbmaster->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
154+
$app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
155+
} else {
156+
$app->log("Error in Replication, changes were not processed.",LOGLEVEL_ERROR);
157+
/*
158+
* If there is any error in processing the datalog we can't continue, because
159+
* we do not know if the newer actions require this (old) one.
160+
*/
161+
return;
162+
}
152163
} else {
153-
$app->log("Error in Replication, changes were not processed.",LOGLEVEL_ERROR);
154-
/*
155-
* If there is any error in processing the datalog we can't continue, because
156-
* we do not know if the newer actions require this (old) one.
157-
*/
158-
return;
164+
$app->log("Datalog does not conatin any changes for this record ".$d["datalog_id"],LOGLEVEL_DEBUG);
159165
}
160166
}
161167

@@ -164,7 +170,9 @@ function processDatalog() {
164170
$sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
165171
$records = $app->db->queryAllRecords($sql);
166172
foreach($records as $d) {
167-
$data = unserialize(stripslashes($d["data"]));
173+
if(!$data = unserialize(stripslashes($d["data"]))) {
174+
$data = unserialize($d["data"]);
175+
}
168176
$this->current_datalog_id = $d["datalog_id"];
169177
$this->raiseTableHook($d["dbtable"],$d["action"],$data);
170178
//$app->db->query("DELETE FROM sys_datalog WHERE datalog_id = ".$rec["datalog_id"]);

0 commit comments

Comments
 (0)