From 6b033580c9fb06457a38c4b36f55aabe7364abc0 Mon Sep 17 00:00:00 2001 From: alban Date: Tue, 16 Sep 2014 18:40:50 +0200 Subject: [PATCH 01/34] [fix] chmod action requiring a SQL change + lost action global reference in m_bro --- bureau/class/m_bro.php | 2 +- install/upgrades/3.3.1.sql | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 install/upgrades/3.3.1.sql diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index a90e961b..ca0c576e 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -556,7 +556,7 @@ class m_bro { * @return boolean TRUE Si les fichiers ont t renomms, FALSE si une erreur s'est produite. */ function ChangePermissions($R,$d,$perm,$verbose=false) { - global $err; + global $err, $action; $absolute=$this->convertabsolute($R,false); if (!$absolute) { $err->raise("bro",_("File or folder name is incorrect")); diff --git a/install/upgrades/3.3.1.sql b/install/upgrades/3.3.1.sql new file mode 100644 index 00000000..f0a82698 --- /dev/null +++ b/install/upgrades/3.3.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE `actions` CHANGE `type` `type` ENUM('CREATE_FILE','FIX_USER','CREATE_DIR','DELETE','MOVE','FIX_DIR','FIX_FILE','CHMOD') DEFAULT NULL ; + From d278474358b021ced58448425d516ee6745cd154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Wed, 24 Sep 2014 22:05:47 +0000 Subject: [PATCH 02/34] rewrite the account deactivation code to make sure it works with mailboxes and restores properly --- bureau/admin/adm_deactivate.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/bureau/admin/adm_deactivate.php b/bureau/admin/adm_deactivate.php index ab71ed3e..7ebfbbf8 100644 --- a/bureau/admin/adm_deactivate.php +++ b/bureau/admin/adm_deactivate.php @@ -126,11 +126,11 @@ foreach ($domains as $key => $domain) { } else { # 2.1 keep a copy of where it was, in an SQL request - $backup .= "UPDATE `sub_domaines` SET `type`='$type', valeur='$dest',web_action='UPDATE' WHERE `domaine`='$domain' AND sub='$sub';\n"; + $backup .= "UPDATE `sub_domaines` SET `type`='$type', valeur='$dest',web_action='UPDATE' WHERE id=" . $r['sub'][$k]['id'] . ";\n"; # 2.2 change the subdomain to redirect to http://spam.koumbit.org/ $dom->lock(); - if (!$dom->set_sub_domain($domain, $sub, $dom->type_url, $redirect)) { + if (! $db->query("UPDATE `sub_domaines` SET `type`='" . $dom->type_url . "', valeur='$redirect',web_action='UPDATE' WHERE id=" . $r['sub'][$k]['id'] . ";\n") ) { print "-- error in $sub.$domain: " . $err->errstr() . "\n"; } $dom->unlock(); @@ -141,6 +141,35 @@ foreach ($domains as $key => $domain) { if (!$confirmed) print ''; } +$mail_dom = $mail->enum_domains(); + +if ($confirmed) { + print "
";
+  printf(_("-- disabling all the mail passwords\n"));
+}
+if (!$confirmed) print "\n
  • mailboxes
      \n"; +reset($mail_dom); +# 1.3 foreach mail domain, we list the email hashes +foreach ($mail_dom as $key => $domain) { + if (!$confirmed) print '' . $domain['domaine'] . '
        '; + $mails = $mail->enum_domain_mails($domain['id']); + foreach ($mails as $key => $mail) { + if ($mail['islocal']) { + if (!$confirmed) print '
      • ' . $mail['address'] . '@' . $domain['domaine']; + $pass = $mail['password']; + $id = $mail['id']; + $backup .= $b = "update address set password='$pass' where id=$id"; + if (!$confirmed) print "
      • \n"; + if ($confirmed) { + $db->query("update `address` set password='!$pass' where id=$id"); + } + } + } +} + + +if (!$confirmed) print "
    \n"; + # 3. wrap up (?) if ($confirmed) { print "-- The following is a serie of SQL request you can run, as root, to revert the user's domains to their previous state.\n"; From b2949424c34bb9b15181d6a5c7f27a95f26c193c Mon Sep 17 00:00:00 2001 From: Squidly Date: Thu, 31 Jul 2014 10:57:49 +0200 Subject: [PATCH 03/34] Updating error message to give a usefull information --- bureau/class/m_dom.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 1c2e533d..04ba764d 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -734,7 +734,7 @@ class m_dom { return false; } if ($dns && $v == -3) { - $err->raise("dom", _("The domain cannot be found in the whois database")); + $err->raise("dom", _("The name servers referenced by this domain do not match those referenced by this AlternC instance")); return false; } From b906850eb50456a6d1dc899d7644936026f6ee25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Mon, 6 Oct 2014 15:15:55 +0000 Subject: [PATCH 04/34] more reasonable permissions on config files this way the webserver don't own the files (so can't change perms) yet can still read --- debian/alternc-roundcube.postinst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debian/alternc-roundcube.postinst b/debian/alternc-roundcube.postinst index 6dfe23c9..afe52a18 100644 --- a/debian/alternc-roundcube.postinst +++ b/debian/alternc-roundcube.postinst @@ -24,13 +24,13 @@ case "$1" in dpkg-statoverride --list /etc/roundcube/debian-db.php >/dev/null && dpkg-statoverride --remove /etc/roundcube/debian-db.php - chown -R www-data:root /etc/roundcube/debian-db.php - chmod -R 460 /etc/roundcube/debian-db.php + chown root:www-data /etc/roundcube/debian-db.php + chmod 640 /etc/roundcube/debian-db.php dpkg-statoverride --list /etc/roundcube/main.inc.php >/dev/null && dpkg-statoverride --remove /etc/roundcube/main.inc.php - chown -R www-data:root /etc/roundcube/main.inc.php - chmod -R 460 /etc/roundcube/main.inc.php + chown root:www-data /etc/roundcube/main.inc.php + chmod 640 /etc/roundcube/main.inc.php dpkg-statoverride --list /var/log/roundcube >/dev/null && dpkg-statoverride --remove /var/log/roundcube From 7eba1bb1f62a62d47df768722fd1ae9e807ff1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Mon, 13 Oct 2014 23:02:13 +0000 Subject: [PATCH 05/34] fix email deactivation --- bureau/admin/adm_deactivate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bureau/admin/adm_deactivate.php b/bureau/admin/adm_deactivate.php index 7ebfbbf8..cee28f99 100644 --- a/bureau/admin/adm_deactivate.php +++ b/bureau/admin/adm_deactivate.php @@ -141,7 +141,7 @@ foreach ($domains as $key => $domain) { if (!$confirmed) print ''; } -$mail_dom = $mail->enum_domains(); +$mail_dom = $dom->enum_domains(); if ($confirmed) { print "
    ";
    @@ -152,7 +152,7 @@ reset($mail_dom);
     # 1.3 foreach mail domain, we list the email hashes
     foreach ($mail_dom as $key => $domain) {
       if (!$confirmed) print '' . $domain['domaine'] . '
      '; - $mails = $mail->enum_domain_mails($domain['id']); + $mails = $dom->enum_domain_mails($domain['id']); foreach ($mails as $key => $mail) { if ($mail['islocal']) { if (!$confirmed) print '
    • ' . $mail['address'] . '@' . $domain['domaine']; From 71647e7fd799003dc1e63ecff7cdcbc05264a4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Mon, 13 Oct 2014 23:08:32 +0000 Subject: [PATCH 06/34] revert previous fix and fix properly --- bureau/admin/adm_deactivate.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bureau/admin/adm_deactivate.php b/bureau/admin/adm_deactivate.php index cee28f99..686d582f 100644 --- a/bureau/admin/adm_deactivate.php +++ b/bureau/admin/adm_deactivate.php @@ -141,7 +141,7 @@ foreach ($domains as $key => $domain) { if (!$confirmed) print '
    '; } -$mail_dom = $dom->enum_domains(); +$mail_dom = $mail->enum_domains(); if ($confirmed) { print "
    ";
    @@ -152,12 +152,12 @@ reset($mail_dom);
     # 1.3 foreach mail domain, we list the email hashes
     foreach ($mail_dom as $key => $domain) {
       if (!$confirmed) print '' . $domain['domaine'] . '
      '; - $mails = $dom->enum_domain_mails($domain['id']); - foreach ($mails as $key => $mail) { - if ($mail['islocal']) { - if (!$confirmed) print '
    • ' . $mail['address'] . '@' . $domain['domaine']; - $pass = $mail['password']; - $id = $mail['id']; + $mails = $mail->enum_domain_mails($domain['id']); + foreach ($mails as $key => $add) { + if ($add['islocal']) { + if (!$confirmed) print '
    • ' . $add['address'] . '@' . $domain['domaine']; + $pass = $add['password']; + $id = $add['id']; $backup .= $b = "update address set password='$pass' where id=$id"; if (!$confirmed) print "
    • \n"; if ($confirmed) { @@ -165,6 +165,7 @@ foreach ($mail_dom as $key => $domain) { } } } + if (!$confirmed) print "
    "; } From 0a697d140120c4e9a9e3235d2e6b3941fda5fdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Mon, 13 Oct 2014 23:10:00 +0000 Subject: [PATCH 07/34] properly output restore code --- bureau/admin/adm_deactivate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bureau/admin/adm_deactivate.php b/bureau/admin/adm_deactivate.php index 686d582f..a1563d5c 100644 --- a/bureau/admin/adm_deactivate.php +++ b/bureau/admin/adm_deactivate.php @@ -158,10 +158,10 @@ foreach ($mail_dom as $key => $domain) { if (!$confirmed) print '
  • ' . $add['address'] . '@' . $domain['domaine']; $pass = $add['password']; $id = $add['id']; - $backup .= $b = "update address set password='$pass' where id=$id"; + $backup .= $b = "update address set password='$pass' where id=$id;\n"; if (!$confirmed) print "
  • \n"; if ($confirmed) { - $db->query("update `address` set password='!$pass' where id=$id"); + $db->query("update `address` set password='!$pass' where id=$id;\n"); } } } From fa5bfd574c79c4ad3b8e54f693432c1308673bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 14 Oct 2014 21:40:55 +0000 Subject: [PATCH 08/34] mailx doesn't support -r, use -a --- src/cron_users_doit.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cron_users_doit.sh b/src/cron_users_doit.sh index 2998a136..0585e2e0 100755 --- a/src/cron_users_doit.sh +++ b/src/cron_users_doit.sh @@ -23,8 +23,6 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done -from="noreply@$FQDN" - if [ "x$url" == "x" ] ; then echo Missing arguments exit 0 @@ -62,7 +60,7 @@ echo -e "\n---------- END ----------" # If there is an email specified, mail it if [ ! "x$email" == "x" -a ! "$email" == "null" ] ; then date=$(date +%x\ %X) - cat "$tmpfile" | mailx -s "AlternC Cron #$id - Report $date" -r "$from" "$(urldecode $email)" + cat "$tmpfile" | mailx -s "AlternC Cron #$id - Report $date" -a "From: noreply@$FQDN" "$(urldecode $email)" fi rm -f "$tmpfile" From 2ac05cfb6fbd870463a38e356f0b2ad91c1ce402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 14 Oct 2014 21:41:23 +0000 Subject: [PATCH 09/34] spare one more little cat --- src/cron_users_doit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cron_users_doit.sh b/src/cron_users_doit.sh index 0585e2e0..005be7c8 100755 --- a/src/cron_users_doit.sh +++ b/src/cron_users_doit.sh @@ -60,7 +60,7 @@ echo -e "\n---------- END ----------" # If there is an email specified, mail it if [ ! "x$email" == "x" -a ! "$email" == "null" ] ; then date=$(date +%x\ %X) - cat "$tmpfile" | mailx -s "AlternC Cron #$id - Report $date" -a "From: noreply@$FQDN" "$(urldecode $email)" + mailx -s "AlternC Cron #$id - Report $date" -a "From: noreply@$FQDN" "$(urldecode $email)" < "$tmpfile" fi rm -f "$tmpfile" From 281edf671da1998a93bbc09f5bc162a90d7b3bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 14 Oct 2014 21:47:20 +0000 Subject: [PATCH 10/34] fix systematic failure message: output was never set so this was always setting an error also do not use the macho 'dude', operator genitalia having very little relevance here --- src/do_actions.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/do_actions.php b/src/do_actions.php index dc01d302..8ce1c3f0 100644 --- a/src/do_actions.php +++ b/src/do_actions.php @@ -264,14 +264,9 @@ while ($rr=$action->get_action()){ } break; default : - $output=array("Fail: Sorry dude, i do not know this type of action"); + $errorsList[]=array("Fail: Sorry, i do not know this type of action: ". $r['type']); break; } - // Get the error (if exists). - if(isset($output[0])){ - $return=$output[0]; - $errorsList[]="\nAction n°".$r["id"]." '".$r["type"]."' failed! With user: ".$r["user"]."\nHere is the complete output:\n".print_r($output); - } // We finished the action, notify the DB. d("Finishing... return value is : $return\n"); if(!$action->finish($r["id"],addslashes($return))){ @@ -290,4 +285,4 @@ if(count($errorsList)) { unlink(ALTERNC_DO_ACTION_LOCK); // Exit this script -exit(0); \ No newline at end of file +exit(0); From 923dd0989c135e2580fee3a72e8354b7186cddc7 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Tue, 28 Oct 2014 08:08:07 +0000 Subject: [PATCH 11/34] Pb de variable quand on ajoute un domaine en .eu --- bureau/class/m_dom.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/class/m_dom.php b/bureau/class/m_dom.php index 04ba764d..3afe4e18 100644 --- a/bureau/class/m_dom.php +++ b/bureau/class/m_dom.php @@ -996,7 +996,7 @@ class m_dom { $ligne = preg_replace("/^ *([^ ]*) \(.*\)$/", "\\1", trim($ligne)); if ($found) $tmp = trim($ligne); - if ($tmp) + if (isset($tmp) && $tmp) $serveurList[] = $tmp; if ($ligne == "Nameservers:") { $state = 1; From 4c4cd25bce19392b8a0168cfe2b2c5634ec8030b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 28 Oct 2014 17:48:45 +0000 Subject: [PATCH 12/34] fix error handling in do_actions.php --- src/do_actions.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/do_actions.php b/src/do_actions.php index 8ce1c3f0..c574a869 100644 --- a/src/do_actions.php +++ b/src/do_actions.php @@ -85,12 +85,8 @@ function d($mess){ */ function mail_it(){ global $errorsList,$L_FQDN; - // Forces array - if( !is_array($errorsList)){ - $errorsList = array($errorsList); - } // Builds message from array - $msg = implode("\n", $errorsList); + $msg = var_export($errorsList, TRUE); // Attempts to send email // @todo log if fails mail("alterncpanel@$L_FQDN",'Script do_actions.php issues',"\n Errors reporting mail:\n\n$msg"); From c9c381f406d54198f7db41bff263c3dba04bcf72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Wed, 5 Nov 2014 21:52:36 +0000 Subject: [PATCH 13/34] do not use mysql_pconnect mysql_pconnect leaves stray mysql connexions lying around and we do our own connexion management anyways --- bureau/class/db_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/class/db_mysql.php b/bureau/class/db_mysql.php index 81992ba2..bc780b81 100644 --- a/bureau/class/db_mysql.php +++ b/bureau/class/db_mysql.php @@ -91,7 +91,7 @@ class DB_Sql { /* establish connection, select database */ if ( 0 == $this->Link_ID ) { - $this->Link_ID=mysql_pconnect($Host, $User, $Password); + $this->Link_ID=mysql_connect($Host, $User, $Password); if (!$this->Link_ID) { $this->halt("pconnect($Host, $User, \$Password) failed."); return 0; From afd2746bccbf01fc32d47a97d1697b8632c9af0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Thu, 20 Nov 2014 16:47:29 +0000 Subject: [PATCH 14/34] make mail_add dry by default to avoid potential catastrophe --- src/mail_add.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mail_add.php b/src/mail_add.php index 47ff2b9f..e33b59b0 100644 --- a/src/mail_add.php +++ b/src/mail_add.php @@ -19,7 +19,7 @@ global $cuid; // those will be tried in order, the first one to return more than 7 // chars will win $generators = array('pwqgen', 'pwgen'); -$dryrun = false; +$dryrun = true; // 1GB default quota $default_quotas = 1024; // in MB because using bytes would be too // precise (try to guess AlternC, just you try) From a9ebd1488272755151e4114fff7c7649c81e3ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:16:53 +0000 Subject: [PATCH 15/34] do not allow gid write access by default, the gid user can still write for now, see #1629 --- src/fixperms.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fixperms.sh b/src/fixperms.sh index 6ae6e505..91912bbe 100755 --- a/src/fixperms.sh +++ b/src/fixperms.sh @@ -126,15 +126,15 @@ doone() { # Set the file readable only for the AlternC User mkdir -p "$REP" chown -R $GID:$GID "$REP" - chmod 2770 -R "$REP" + chmod 2750 -R "$REP" # # Delete existings ACL # # Set the defaults acl on all the files # setfacl -b -k -n -R -m d:g:alterncpanel:rwx -m d:u::rwx -m d:g::rwx -m d:u:$GID:rwx -m d:g:$GID:rwx -m d:o::--- -m d:mask:rwx\ # -Rm g:alterncpanel:rwx -m u:$GID:rwx -m g:$GID:rwx -m mask:rwx\ # "$REP" - setfacl -bknR -m d:u:alterncpanel:rwx -m d:g:alterncpanel:rwx -m u:alterncpanel:rwx -m g:alterncpanel:rwx -m d:o::--- -m o::---\ - -m d:u:$GID:rwx -m d:g:$GID:rwx -m u:$GID:rwx -m g:$GID:rwx -m d:mask:rwx -m mask:rwx "$REP" + setfacl -bknR -m d:u:alterncpanel:rwx -m d:g:alterncpanel:r-x -m u:alterncpanel:rwx -m g:alterncpanel:r-x -m d:o::--- -m o::---\ + -m d:u:$GID:rwx -m d:g:$GID:r-x -m u:$GID:rwx -m g:$GID:r-x -m d:mask:rwx -m mask:rwx "$REP" fixtmp $GID read GID LOGIN || true From e68544637a4c16be041535f302a616310fec6757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:18:25 +0000 Subject: [PATCH 16/34] make sure we address the VHOST_DIR directory, it may be a symlink --- src/update_domains.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/update_domains.sh b/src/update_domains.sh index 89df3bc6..8d46a132 100755 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -132,7 +132,7 @@ if [ ! -z "$(cat "$RELOAD_WEB")" ] ; then else echo "Include \"$LOGFORMAT_FILE\"" fi - find "$VHOST_DIR" -mindepth 2 -type f -iname "*.conf" -print0 | xargs -0 cat + find "$VHOST_DIR/" -mindepth 2 -type f -iname "*.conf" -print0 | xargs -0 cat echo "###END OF ALTERNC AUTO-GENERATED FILE - DO NOT EDIT MANUALLY###" ) > "$tempo" From 0afe53f8a6d3537586400c83a5151c66c6c08278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:20:25 +0000 Subject: [PATCH 17/34] add 'force' argument to update_domains to allow admins to regen everything easil --- src/update_domains.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/update_domains.sh b/src/update_domains.sh index 8d46a132..7961bc56 100755 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -114,7 +114,7 @@ do mysql_query "delete from sub_domaines where domaine='$dom'; delete from domaines where domaine='$dom';" done -if [ ! -z "$(cat "$RELOAD_WEB")" ] ; then +if [ ! -z "$(cat "$RELOAD_WEB")" ] || [ "$1" = "force" ]; then # Just to encourage user to use THIS directory and not another one test -d "$VHOST_MANUALCONF" || mkdir -p "$VHOST_MANUALCONF" From 4ccc9c6a91a647a8ded75afecde2de443d1e20cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:26:16 +0000 Subject: [PATCH 18/34] abort alternc.install on failures so we can handle them better --- install/alternc.install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install/alternc.install b/install/alternc.install index 8f2d84ba..84f3ad0f 100644 --- a/install/alternc.install +++ b/install/alternc.install @@ -22,6 +22,8 @@ # Purpose of file: Main install script, launch it anytime ;) # ---------------------------------------------------------------------- +set -e + # Somes check before start operations if [ `id -u` -ne 0 ]; then echo "must be launched as root" From 7885d2e39b636f94e6fe1f7b9ae01e0744309027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:33:18 +0000 Subject: [PATCH 19/34] add variable to disable https warning - it's up to the admin after all to configure their stuff --- bureau/admin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/admin/index.php b/bureau/admin/index.php index d3ca1d8a..97f95c82 100644 --- a/bureau/admin/index.php +++ b/bureau/admin/index.php @@ -74,7 +74,7 @@ if ( empty($logo) || ! $logo ) {
    ' . sprintf(_('WARNING: you are trying to access the control panel insecurely, click here to go to secure mode'), $_SERVER["HTTP_HOST"]) . ''; } ?> From d5f5e49b2acdef02e5510c4120652522767c550c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:33:33 +0000 Subject: [PATCH 20/34] disable php warning --- bureau/admin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/admin/index.php b/bureau/admin/index.php index 97f95c82..6ed1193b 100644 --- a/bureau/admin/index.php +++ b/bureau/admin/index.php @@ -36,7 +36,7 @@ $H=getenv("HTTP_HOST"); if (!isset($restrictip)) { $restrictip=1; } -if (!isset($charset) || ! $charset) $charset="UTF-8"; +if (!$charset) $charset="UTF-8"; @header("Content-Type: text/html; charset=$charset"); ?> From 2695b09f6abad9a87d73203fe867202e86edc731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:37:05 +0000 Subject: [PATCH 21/34] revert last commit, i read my diff backwards --- bureau/admin/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/admin/index.php b/bureau/admin/index.php index 6ed1193b..97f95c82 100644 --- a/bureau/admin/index.php +++ b/bureau/admin/index.php @@ -36,7 +36,7 @@ $H=getenv("HTTP_HOST"); if (!isset($restrictip)) { $restrictip=1; } -if (!$charset) $charset="UTF-8"; +if (!isset($charset) || ! $charset) $charset="UTF-8"; @header("Content-Type: text/html; charset=$charset"); ?> From 8d6ad399132e66d2d720aa973e392245a73aec8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:40:07 +0000 Subject: [PATCH 22/34] make a new session before bouncing to PMA to avoid leaking our session, also direct to the right server --- bureau/admin/sql_pma_sso.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bureau/admin/sql_pma_sso.php b/bureau/admin/sql_pma_sso.php index 0326447c..4fa77891 100644 --- a/bureau/admin/sql_pma_sso.php +++ b/bureau/admin/sql_pma_sso.php @@ -32,13 +32,18 @@ require_once("../class/config.php"); if (!$r=$mysql->php_myadmin_connect()) { $error=$err->errstr(); } else { + session_write_close(); // SSO of PhpMyAdmin + session_set_cookie_params(0, '/', '', 0); + session_name('AlternC_Panel'); + session_start(); $_SESSION['PMA_single_signon_user'] = $r["login"]; $_SESSION['PMA_single_signon_password'] = $r["pass"]; $_SESSION['PMA_single_signon_host'] = $r["host"]; // pma >= 2.11 + session_write_close(); // finally redirect to phpMyAdmin : - header("Location: /alternc-sql/"); + header("Location: /alternc-sql/index.php?server=1"); exit(); } From 335b5beebed05bfa92f791a6db850ad1f5257892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:41:13 +0000 Subject: [PATCH 23/34] fix typo --- bureau/class/db_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/class/db_mysql.php b/bureau/class/db_mysql.php index bc780b81..39f29fa5 100644 --- a/bureau/class/db_mysql.php +++ b/bureau/class/db_mysql.php @@ -93,7 +93,7 @@ class DB_Sql { $this->Link_ID=mysql_connect($Host, $User, $Password); if (!$this->Link_ID) { - $this->halt("pconnect($Host, $User, \$Password) failed."); + $this->halt("connect($Host, $User, \$Password) failed."); return 0; } From 9b90e39ec90f3db868495842b378d8e13ec4e623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:47:36 +0000 Subject: [PATCH 24/34] relacher le lock sur le bureau quand on cree les archives, sinon ca gele pour tout le monde --- bureau/class/m_bro.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index ca0c576e..6f4b2561 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -1025,6 +1025,9 @@ class m_bro { header("Content-Transfer-Encoding: binary"); $d=escapeshellarg(".".$this->convertabsolute($dir,true)); set_time_limit(0); + // relacher le lock global sinon ce download va geler alternc pour + // tout le monde + alternc_shutdown(); passthru("/bin/tar -cZ -C ".getuserpath()."/".$mem->user["login"]."/ $d"); } @@ -1043,6 +1046,9 @@ class m_bro { header("Content-Transfer-Encoding: binary"); $d=escapeshellarg(".".$this->convertabsolute($dir,true)); set_time_limit(0); + // relacher le lock global sinon ce download va geler alternc pour + // tout le monde + alternc_shutdown(); passthru("/bin/tar -cz -C ".getuserpath()."/ $d"); } @@ -1061,6 +1067,9 @@ class m_bro { header("Content-Transfer-Encoding: binary"); $d=escapeshellarg(".".$this->convertabsolute($dir,true)); set_time_limit(0); + // relacher le lock global sinon ce download va geler alternc pour + // tout le monde + alternc_shutdown(); passthru("/bin/tar -cj -C ".getuserpath()."/ $d"); } @@ -1172,6 +1181,9 @@ class m_bro { } $timestamp=date("H:i:s"); + // relacher le lock global sinon ce download va geler alternc pour + // tout le monde + alternc_shutdown(); if(exec("/bin/tar cvf - ".getuserpath()."/ | gzip -9c > ".$dir."/".$mem->user['login']."_html_".$timestamp.".tar.gz")){ $err->log("bro","export_data_succes"); }else{ From d8fe94d24be71a5abc54e348783558dfaf07c4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 21 Nov 2014 17:49:59 +0000 Subject: [PATCH 25/34] transmit the piwik api error message back to the user --- bureau/class/m_piwik.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bureau/class/m_piwik.php b/bureau/class/m_piwik.php index 47c996ca..0d3ec976 100644 --- a/bureau/class/m_piwik.php +++ b/bureau/class/m_piwik.php @@ -112,6 +112,10 @@ class m_piwik { $user_creation_date = $user->date_registered; return $db->query("INSERT INTO piwik_users (uid, login, created_date) VALUES ('$cuid', '$user_login', '$user_creation_date')"); } + else { + $err->raise('piwik', $api_data->message); + return FALSE; + } } else { // api_data = false -> error is already filled return FALSE; } From 511653d32710f90805941e81c04671fcc7b144f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Thu, 27 Nov 2014 16:54:49 +0000 Subject: [PATCH 26/34] cleanup postlogin hooks in dovecot so they are uniform and always post-login, closes #1632 --- .../templates/dovecot/conf.d/95_alternc.conf | 18 ++++++++++++++++-- wheezy/95_alternc.conf | 19 ++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/etc/alternc/templates/dovecot/conf.d/95_alternc.conf b/etc/alternc/templates/dovecot/conf.d/95_alternc.conf index 5dcf7708..5c6839fc 100644 --- a/etc/alternc/templates/dovecot/conf.d/95_alternc.conf +++ b/etc/alternc/templates/dovecot/conf.d/95_alternc.conf @@ -192,7 +192,20 @@ protocol imap { } service imap { - executable = /usr/lib/alternc/popimap-log-login.sh /usr/lib/dovecot/imap + # tell imap to do post-login lookup using a socket called "imap-postlogin" + executable = imap postlogin +} + +# The service name below doesn't actually matter. +service postlogin { + # all post-login scripts are executed via script-login binary + executable = script-login /usr/lib/alternc/popimap-log-login.sh + + # the script process runs as the user specified here (v2.0.14+): + #user = $default_internal_user + # this UNIX socket listener must use the same name as given to imap executable + unix_listener postlogin { + } } @@ -247,7 +260,8 @@ protocol pop3 { } service pop3 { - executable = /usr/lib/alternc/popimap-log-login.sh /usr/lib/dovecot/pop3 + # tell imap to do post-login lookup using a socket called "imap-postlogin" + executable = pop3 postlogin } # ---------------------------------------------------------------------------- diff --git a/wheezy/95_alternc.conf b/wheezy/95_alternc.conf index c4d66687..e14ae4f6 100644 --- a/wheezy/95_alternc.conf +++ b/wheezy/95_alternc.conf @@ -195,18 +195,22 @@ protocol imap { } service imap { - executable = imap imap-postlogin + # tell imap to do post-login lookup using a socket called "postlogin" + executable = imap postlogin vsz_limit = 512M } -service imap-postlogin { - executable = script-login /usr/lib/alternc/popimap-log-login.sh +# The service name below doesn't actually matter. +service postlogin { + # all post-login scripts are executed via script-login binary + executable = script-login /usr/lib/alternc/popimap-log-login.sh + # the script process runs as the user specified here (v2.0.14+): -# user = $default_internal_user + #user = $default_internal_user # this UNIX socket listener must use the same name as given to imap executable - unix_listener imap-postlogin { + unix_listener postlogin { } -} + } # ---------------------------------------------------------------------------- # 20-managesieve.conf @@ -259,7 +263,8 @@ protocol pop3 { } service pop3 { - executable = /usr/lib/alternc/popimap-log-login.sh /usr/lib/dovecot/pop3 + # tell imap to do post-login lookup using a socket called "postlogin" + executable = pop3 postlogin } # ---------------------------------------------------------------------------- From 542c0f59b264177f1fe9f6e97dceb1507adae2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Thu, 27 Nov 2014 18:54:44 +0000 Subject: [PATCH 27/34] improve lastlogin performance by using indexes, closes #1633, patch by lelutin --- src/popimap-log-login.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/popimap-log-login.sh b/src/popimap-log-login.sh index 62d0e998..f1679254 100755 --- a/src/popimap-log-login.sh +++ b/src/popimap-log-login.sh @@ -15,7 +15,10 @@ if [ ! -r "$ALTERNC_CONFIG_FILE" ]; then fi . "$ALTERNC_CONFIG_FILE" -mysql_query "update address a, domaines d, mailbox m set m.lastlogin=now() where a.domain_id=d.id and m.address_id=a.id and concat_ws('@',a.address,d.domaine) = '$USER';" +addr=$(echo $USER | sed 's/@.*//') +dom=$(echo $USER | sed 's/^.*@//') + +mysql_query "update address a, domaines d, mailbox m set m.lastlogin=now() where a.domain_id=d.id and m.address_id=a.id and a.address='$addr' and d.domaine='$dom';" # Now launch the expected binary server exec "$@" From eedb851a50ae3641a61f631aad69d02b600c374b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 28 Nov 2014 21:54:10 +0000 Subject: [PATCH 28/34] fix weird case where user root is not found --- bureau/class/m_bro.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bureau/class/m_bro.php b/bureau/class/m_bro.php index 6f4b2561..81c71ffa 100644 --- a/bureau/class/m_bro.php +++ b/bureau/class/m_bro.php @@ -111,6 +111,11 @@ class m_bro { $root_alternc=$root ; // Passage du root en chemin rel (diffrent avec un lien) $root=realpath($root) ; + if (! $root=realpath($root)) { + // Guillaume: it needed to work.. if file doesn't exist it need to crash + // gently + $root=$root_alternc; + } // separer le chemin entre le repertoire et le fichier $file=basename($dir); $dir=dirname($dir); From 8cb0e3d1a8f09cc83cb208a010da926d90540b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Fri, 28 Nov 2014 21:58:42 +0000 Subject: [PATCH 29/34] don't check disk quotas if they're disabled --- bureau/class/m_quota.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bureau/class/m_quota.php b/bureau/class/m_quota.php index ac7ab96d..2b5f38f0 100644 --- a/bureau/class/m_quota.php +++ b/bureau/class/m_quota.php @@ -172,7 +172,7 @@ class m_quota { } reset($this->disk); - if (!empty ($this->disk)) { // Check if there are some disk quota to check + if ($this->disk_quota_enable && !empty ($this->disk)) { // Check if there are some disk quota to check // Look if there are some cached value $disk_cached = $mem->session_tempo_params_get('quota_cache_disk'); From 61f6406c53756556698c880dec54aa325c3d1c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 2 Dec 2014 19:10:48 +0000 Subject: [PATCH 30/34] add changes from wheezy, commented out --- etc/alternc/templates/postfix/master.cf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/etc/alternc/templates/postfix/master.cf b/etc/alternc/templates/postfix/master.cf index a7016407..2e974ba7 100644 --- a/etc/alternc/templates/postfix/master.cf +++ b/etc/alternc/templates/postfix/master.cf @@ -114,5 +114,7 @@ mailman unix - n n - - pipe #dovecot LDA, as explained here: http://wiki.dovecot.org/LDA/Postfix dovecot unix - n n - 0 pipe flags=DRhu user=vmail:vmail argv=/usr/bin/sudo /usr/lib/dovecot/deliver -f ${sender} -a ${recipient} -d ${user}@${nexthop} - - +#smtp inet n - n - 1 postscreen +#smtpd pass - - n - - smtpd +#dnsblog unix - - n - 0 dnsblog +#tlsproxy unix - - n - 0 tlsproxy From 47b246105cbae354135f58106a65a1df1b261da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 2 Dec 2014 20:17:46 +0000 Subject: [PATCH 31/34] ensure we follow symlinks on /var/lib/alternc/apache-vhost because some clever admins may have moved it to ALTERNC_HTML --- src/functions_hosting.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_hosting.sh b/src/functions_hosting.sh index 7c163fb5..409de6e1 100644 --- a/src/functions_hosting.sh +++ b/src/functions_hosting.sh @@ -6,7 +6,7 @@ TEMPLATE_DIR="/etc/alternc/templates/apache2" HOSTING_DIR="/etc/alternc/functions_hosting" HTML_HOME="$ALTERNC_HTML" -VHOST_DIR="/var/lib/alternc/apache-vhost" +VHOST_DIR="/var/lib/alternc/apache-vhost/" launch_hooks() { local ACTION=$1 From da25f15da1cd7dc19499bdb01321d690dcc7c4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 2 Dec 2014 21:29:02 +0000 Subject: [PATCH 32/34] allow panel to enter $ALTERNC_HTML/ --- install/alternc.install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/alternc.install b/install/alternc.install index 84f3ad0f..22f2715a 100644 --- a/install/alternc.install +++ b/install/alternc.install @@ -530,7 +530,7 @@ tar -zcf "$INSTALLED_CONFIG_TAR" -C / $CONFIG_FILES # Last touches # -find $ALTERNC_HTML -maxdepth 1 -type d -exec setfacl -b -k -m d:g:alterncpanel:rw- -m d:u:alterncpanel:rw- -m u:alterncpanel:rw- -m g:alterncpanel:rw- {} \; +find $ALTERNC_HTML -maxdepth 1 -type d -exec setfacl -b -k -m d:g:alterncpanel:rwx -m d:u:alterncpanel:rwx -m u:alterncpanel:rwx -m g:alterncpanel:rwx {} \; #creating log file if [ ! -e "/var/log/alternc/bureau.log" ]; then From 9076d745669d8e5f67d5931fc544829f9b13fb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=EF=BF=BD=EF=BF=BD?= Date: Tue, 2 Dec 2014 21:54:33 +0000 Subject: [PATCH 33/34] allow for redirecting users to https --- bureau/admin/index.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bureau/admin/index.php b/bureau/admin/index.php index 97f95c82..af67e474 100644 --- a/bureau/admin/index.php +++ b/bureau/admin/index.php @@ -32,6 +32,10 @@ if (!$mem->del_session()) { } $H=getenv("HTTP_HOST"); +if (variable_get('https_redirect', false, 'switch users to HTTPS') && !isset($_SERVER['HTTPS'])) { + header("Location: https://$H/"); + exit(); +} if (!isset($restrictip)) { $restrictip=1; From f204ceeb71bcfeee6daaea9c3c4c119fe501174d Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 11 Dec 2014 21:18:51 +0100 Subject: [PATCH 34/34] [enh] diagnostic near alpha --- lib/Alternc/Diagnostic/Data.php | 43 ++++- lib/Alternc/Diagnostic/Diff.php | 93 +++++++-- lib/Alternc/Diagnostic/Directory.php | 43 ++++- lib/Alternc/Diagnostic/Format/Abstract.php | 34 ++++ lib/Alternc/Diagnostic/Format/Interface.php | 17 +- lib/Alternc/Diagnostic/Format/Json.php | 20 +- lib/Alternc/Diagnostic/Format/Txt.php | 61 ++++++ lib/Alternc/Diagnostic/Manager.php | 97 ++++++++-- src/diagnostic.php | 200 +++++--------------- 9 files changed, 395 insertions(+), 213 deletions(-) create mode 100644 lib/Alternc/Diagnostic/Format/Txt.php diff --git a/lib/Alternc/Diagnostic/Data.php b/lib/Alternc/Diagnostic/Data.php index 1ee1e819..1e9078d0 100644 --- a/lib/Alternc/Diagnostic/Data.php +++ b/lib/Alternc/Diagnostic/Data.php @@ -24,7 +24,46 @@ class Alternc_Diagnostic_Data { } } - + + // recursive rebuild + function buildFromArray( $content ){ + + if( ! $this->isValidArrayData( $content ) ) { + return $content; + } + $type = $content["type"]; + $newInstance = new Alternc_Diagnostic_Data( $type ); + $newInstance->index = $content["index"]; + $newInstance->metadata = $content["metadata"]; + $data = $content["data"]; + // The content is raw + if( $type === self::TYPE_SECTION){ + $newInstance->data = $data; + } + // The content is made of services or sections + else foreach( $content["data"] as $section_name => $sectionData ){ + $sectionContent = $this->buildFromArray( $sectionData ); + $newInstance->addData( $section_name, $sectionContent ); + } + return $newInstance; + + } + + // Make sure we have a valid format result + function isValidArrayData( $content ){ + if( + !is_array($content) + || !array_key_exists( "type", $content ) + || !array_key_exists("metadata",$content) + || !array_key_exists("index",$content) + || !array_key_exists("data",$content) + || ! in_array( $content["type"], array(self::TYPE_ROOT,self::TYPE_DOMAIN,self::TYPE_SECTION) ) ){ + + return false; + + } + return true; + } /** * Sets @@ -115,4 +154,4 @@ class Alternc_Diagnostic_Data { } -} \ No newline at end of file +} diff --git a/lib/Alternc/Diagnostic/Diff.php b/lib/Alternc/Diagnostic/Diff.php index 788c2edd..f79b77ef 100644 --- a/lib/Alternc/Diagnostic/Diff.php +++ b/lib/Alternc/Diagnostic/Diff.php @@ -1,28 +1,83 @@ -getIndex(); + $targetIndex = $target->getIndex(); + // Check diagnostics are same level + $source_type = $source->getType(); + $target_type = $target->getType(); + if( $source_type != $target_type){ + throw new \Exception("Invalid type comparison requested: $source_type vs $target_type"); + } + $diffInstance = new Alternc_Diagnostic_Data( $source_type ); + +#echo "type $source_type\n"; + // Compare general data + if( $source->getMetadata() != $target->getMetadata() ){ + $diffInstance->setMetadata( array_diff( $source->getMetadata(), $target->getMetadata() ) ); + } + + if( $source->getIndex() != $target->getIndex() ){ + $diffInstance->setIndex( array_diff( $source->getIndex(), $target->getIndex() ) ); + } + + // If section content ie. no subsections + if( $source_type == Alternc_Diagnostic_Data::TYPE_SECTION ){ +#echo "Real section\n"; + if( is_array( $source->getData() ) && is_array( $target->getData() ) ){ + + $diff = array_diff( $source->getData(), $target->getData() ) ; + if( $diff ){ + $diffInstance->setData( array_diff( $source->getData(), $target->getData()) ); + } + }else{ + if( $source->getData() != $target->getData() ){ + $diffInstance->setData( array("source" => $source->getData(),"target" => $target->getData() ) ); + } + } + }else{ + + $sourceData = $source->getData(); + $targetData = $target->getData(); + $seenSections = array(); + foreach( $sourceData as $section_name => $sectionData ){ + +#echo "section_name $section_name\n"; + $section_data_type = $sectionData->getType(); + if( ! isset( $targetData[$section_name] ) ) { +#echo "section_name not in target\n"; + $tempDataInstance = new Alternc_Diagnostic_Data($section_data_type); + $tempDataInstance->setMetadata( array("Not in target") ); + }else{ +#echo "section_name for diff\n"; + $tempDataInstance = $this->compare($sectionData, $targetData[$section_name] ); + } + if( ! is_null( $tempDataInstance ) ){ + $diffInstance->addData( $section_name, $tempDataInstance); + } + + + } + + } + if( count( $diffInstance->getData() ) + || count( $diffInstance->getIndex() ) + || count( $diffInstance->getMetadata() ) + ){ + return $diffInstance; + } + + return null; + } - /** - * Finds a file by reference or name - * - * @param string $file_reference - * @return Alternc_Diagnostic_Data Resulting data - */ - function resolve( $file_reference){ - - } } diff --git a/lib/Alternc/Diagnostic/Directory.php b/lib/Alternc/Diagnostic/Directory.php index c89c7e84..7b6048a0 100644 --- a/lib/Alternc/Diagnostic/Directory.php +++ b/lib/Alternc/Diagnostic/Directory.php @@ -25,7 +25,17 @@ class Alternc_Diagnostic_Directory { function getList( $max = null){ $dir = new DirectoryIterator($this->file_path); - + $fileList = array(); + while($dir->valid()) { + if( $dir->isDot() ){ + $dir->next(); + continue; + } + $file_name = $dir->getFilename(); + $fileList[] = $file_name; + $dir->next(); + } + return $fileList; } /** @@ -36,6 +46,35 @@ class Alternc_Diagnostic_Directory { return $this; } + + // @todo Confirm usefulness + public function getFileContent( $id ) { + $fileList = $this->getList(); + if( array_key_exists( $id, $fileList ) ){ + return file_get_contents( $this->file_path."/".$fileList[$id]); + } + if( in_array($id, $fileList)){ + $key = array_search( $id, $fileList ); + return file_get_contents( $this->file_path."/".$fileList[$key]); + } + throw new \Exception("Could not find diagnostic for id : $id"); + } + + function getFileInfo($id){ + + $fileList = $this->getList(); + + if( array_key_exists( $id, $fileList ) ){ + $file_path = $this->file_path."/".$fileList[$id]; + } + if( in_array($id, $fileList)){ + $key = array_search( $id, $fileList ); + $file_path = $this->file_path."/".$fileList[$key]; + } + $fileInfos = pathinfo( $file_path ); + return ($fileInfos); + } + /** * @return string */ @@ -47,4 +86,4 @@ class Alternc_Diagnostic_Directory { } -} \ No newline at end of file +} diff --git a/lib/Alternc/Diagnostic/Format/Abstract.php b/lib/Alternc/Diagnostic/Format/Abstract.php index 58001499..2557409e 100644 --- a/lib/Alternc/Diagnostic/Format/Abstract.php +++ b/lib/Alternc/Diagnostic/Format/Abstract.php @@ -83,6 +83,40 @@ class Alternc_Diagnostic_Format_Abstract { return $this->directory; } + + /** + * Writes a Data object to file + * + * @return boolean + */ + public function write( Alternc_Diagnostic_Data $data = null ){ + if( null == $data ){ + if( ! $this->data ){ + throw new \Exception( "A format cannot be written without a Data"); + } + $data = $this->data; + } + $content = $this->dataToContent( $data ); + $filename = $this->getFilename(); + if( ! file_put_contents($filename, $content) ){ + throw new \Exception("Failed to write in json format to file $filename" ); + } + return true; + + } + + /** + * + * @param string file_name + * @return Alternc_Diagnostic_Data A diagnostic structure + */ + function read( $file_name ){ + + $content = $this->directory->getFileContent( $file_name ); + return $this->contentToData( $content ); + + } + } diff --git a/lib/Alternc/Diagnostic/Format/Interface.php b/lib/Alternc/Diagnostic/Format/Interface.php index 662bcb15..77231a46 100644 --- a/lib/Alternc/Diagnostic/Format/Interface.php +++ b/lib/Alternc/Diagnostic/Format/Interface.php @@ -2,20 +2,9 @@ interface Alternc_Diagnostic_Format_Interface{ - /** - * - * @param mixed $file_reference - * Either a number or a string refering to the file - * @return Alternc_Diagnostic_Data A diagnostic file - */ - function read( $file_reference ); + function contentToData( $content ); - /** - * Writes a Data object to file - * - * @return boolean - */ - function write(); + function dataToContent(); -} \ No newline at end of file +} diff --git a/lib/Alternc/Diagnostic/Format/Json.php b/lib/Alternc/Diagnostic/Format/Json.php index ccd77039..cca03791 100644 --- a/lib/Alternc/Diagnostic/Format/Json.php +++ b/lib/Alternc/Diagnostic/Format/Json.php @@ -19,29 +19,31 @@ class Alternc_Diagnostic_Format_Json /** * @inherit */ - function read( $file_reference ){ - + function contentToData( $content ){ + + $arrayData = json_decode( $content , true); + $dataInstance = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_ROOT); + $this->data = $dataInstance->buildFromArray( $arrayData ); + return $this->data; + } /** * @inherit */ - function write(Alternc_Diagnostic_Data $data = null ){ + function dataToContent(Alternc_Diagnostic_Data $data = null ){ if( $data ){ $this->setData($data); } - $file_content = json_encode($this->getData()); + $content = json_encode($this->getData()); $filename = $this->getFilename(); if(json_last_error()){ throw new \Exception("Json conversion failed with error #".json_last_error()."for data".serialize($this->getData())); } - if( ! file_put_contents($filename, $file_content) ){ - throw new \Exception("Failed to write in json format to file $filename for data".serialize($this->getData())); - } - return true; + return $content; } -} \ No newline at end of file +} diff --git a/lib/Alternc/Diagnostic/Format/Txt.php b/lib/Alternc/Diagnostic/Format/Txt.php new file mode 100644 index 00000000..407f633b --- /dev/null +++ b/lib/Alternc/Diagnostic/Format/Txt.php @@ -0,0 +1,61 @@ +setExtension("txt"); + } + + /** + * @inherit + */ + function contentToData( $content ){ + + // @todo or skip ? Quite a fragile storage + + } + + + /** + * @inherit + */ + function dataToContent(Alternc_Diagnostic_Data $data = null, $depth = 0 ){ + $d = $this->space_depth($depth); + echo $d."Type: ".$data->type."\n"; + $d .= " "; + if( $data->type == Alternc_Diagnostic_Data::TYPE_SECTION ){ + foreach( $data->data as $key => $value ){ + if( is_int( $key) ){ + echo $d.json_encode( $value, true )."\n"; + }else{ + echo $d.$key." => ".json_encode( $value, true )."\n"; + } + } + return; + } + foreach( $data->data as $section_name => $sectionData ){ + echo $d."Section: $section_name\n"; + $this->dataToContent( $sectionData, $depth+1); + } + } + + function space_depth( $depth){ + $buf = ""; + for( $i=0; $i < $depth; $i++){ + $buf .= " "; + } + return $buf; + } + + +} diff --git a/lib/Alternc/Diagnostic/Manager.php b/lib/Alternc/Diagnostic/Manager.php index e75c03d8..4a41c94d 100644 --- a/lib/Alternc/Diagnostic/Manager.php +++ b/lib/Alternc/Diagnostic/Manager.php @@ -55,32 +55,101 @@ class Alternc_Diagnostic_Manager{ * @param Console_CommandLine_Result $options * @throws \Exception */ - function create(Console_CommandLine_Result $options){ + function c_create(Console_CommandLine_Result $options){ $args = $options->args; $options = $options->options; - $diagnosticData = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_ROOT); + $diagnosticdata = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_ROOT); - $serviceList = explode(',',$options["services"]); - foreach ($serviceList as $service) { + $servicelist = explode(',',$options["services"]); + foreach ($servicelist as $service) { $class_name = "Alternc_Diagnostic_Service_".trim(ucfirst($service)); if(!class_exists($class_name)){ - throw new \Exception("Invalid service $service"); + throw new \exception("invalid service $service"); } - /** @var Alternc_Diagnostic_Service_Interface */ - $serviceAgent = new $class_name( array("service" => $this) ); + /** @var alternc_diagnostic_service_interface */ + $serviceagent = new $class_name( array("service" => $this) ); - // Runs the service agent and store the results - $diagnosticData->addData($serviceAgent->name, $serviceAgent->run()); + // runs the service agent and store the results + $diagnosticdata->addData($serviceagent->name, $serviceagent->run()); } - $this->formatInstance->setData($diagnosticData)->write(); + $this->formatInstance->setData($diagnosticdata)->write(); } - function compare( $options ){} - function index( $options ){} - function show( $options ){} - function delete( $options ){} + function c_diff( $options ){ + $args = $options->args; + $options = $options->options; + $source = $options["source"]; + $target = $options["target"]; + $format = $options['format']; + $sourceDiagnostic = $this->getDiagnosticFromId($source); + $targetDiagnostic = $this->getDiagnosticFromId($target); + $diff = new Alternc_Diagnostic_Diff(); + $diffData = $diff->compare($sourceDiagnostic,$targetDiagnostic); + $formatInstance = $this->getFormatInstance( $format ); + echo $formatInstance->dataToContent( $diffData); + } + + function c_list( $options ){ + + $args = $options->args; + $options = $options->options; + $fileList = $this->directoryInstance->getList(); + foreach( $fileList as $number => $file ){ + echo "$number\t$file\n"; + } + + + + } + function c_show( $options ){ + + + $args = $options->args; + $options = $options->options; + $id = $options['id']; + $format = $options['format']; + $data = $this->getDiagnosticFromId( $id); + $formatInstance = $this->getFormatInstance( $format ); + echo $formatInstance->dataToContent( $data ); + + + } + function c_delete( $options ){} + + /** + * Finds a file by reference or name + * + * @param string $file_reference + * @return Alternc_Diagnostic_Data Resulting data + * @todo add the ability to resolve by filename + */ + protected function getDiagnosticFromId ( $id ) { + + $fileInfo = $this->directoryInstance->getFileInfo( $id ) ; + $extension = $fileInfo["extension"]; + $formatInstance = $this->getFormatInstance( $extension); + $formatInstance->read( $fileInfo["basename"] ); + $data = $formatInstance->getData(); + return $data; + + } + + protected function getFormatInstance ( $format ){ + switch( $format ){ + case "json": + $instance = new Alternc_Diagnostic_Format_Json( $this->directoryInstance ); + break; + case "txt": + $instance = new Alternc_Diagnostic_Format_Txt( $this->directoryInstance ); + break; + default: + throw new \Exception("Invalid format : $format"); + break; + } + return $instance; + } } diff --git a/src/diagnostic.php b/src/diagnostic.php index 69ea41f9..00936055 100644 --- a/src/diagnostic.php +++ b/src/diagnostic.php @@ -126,7 +126,7 @@ if(is_file("/usr/share/alternc/panel/class/config_nochk.php")){ -$directoryInstance = new Alternc_Diagnostic_Directory("/tmp/diagnostic"); +$directoryInstance = new Alternc_Diagnostic_Directory("/var/log/alternc/diagnostic"); // instanciation of the diagnosticManager service @@ -168,9 +168,49 @@ $createCommmand->addOption('format', array( 'help_name' => 'format' )); -$indexCommmand = $consoleParser->addCommand('index', array('multiple'=>false,"alias"=>"i","description" => "Shows all available diagnostics")); -$compareCommmand = $consoleParser->addCommand('compare', array('multiple'=>false,"alias"=>"x","description" => "Removes one or more diagnotics")); -$compareCommmand = $consoleParser->addCommand('show', array('multiple'=>false,"alias"=>"s","description" => "Prints a diagnotic content")); +$listCommmand = $consoleParser->addCommand('list', array('multiple'=>false,"alias"=>"i","description" => "Shows all available diagnostics")); +$diffCommmand = $consoleParser->addCommand('diff', array('multiple'=>false,"alias"=>"x","description" => "Removes one or more diagnotics")); +$diffCommmand->addOption('source', array( + 'short_name' => '-s', + 'long_name' => '--source', + 'action' => 'StoreString', + 'default' => '0', + 'description' => 'First file to diff, id or basename. Default: 0', + 'help_name' => 'source' + )); +$diffCommmand->addOption('target', array( + 'short_name' => '-t', + 'long_name' => '--target', + 'action' => 'StoreString', + 'default' => '1', + 'description' => 'First file to diff, id or basename. Default: 1', + 'help_name' => 'target' + )); +$diffCommmand->addOption('format', array( + 'short_name' => '-f', + 'long_name' => '--format', + 'action' => 'StoreString', + 'default' => 'txt', + 'description' => 'Sets the format of the diagnostic diff. default: txt', + 'help_name' => 'format' + )); +$showCommand = $consoleParser->addCommand('show', array('multiple'=>false,"alias"=>"s","description" => "Prints a diagnotic content")); +$showCommand->addOption('id', array( + 'short_name' => '-i', + 'long_name' => '--id', + 'action' => 'StoreString', + 'default' => '0', + 'description' => 'Provides the id or name of a diagnostic to show. Default: 0', + 'help_name' => 'id' + )); +$showCommand->addOption('format', array( + 'short_name' => '-f', + 'long_name' => '--format', + 'action' => 'StoreString', + 'default' => 'txt', + 'description' => 'Sets the format of the output. Default: txt. Other choices : array', + 'help_name' => 'format' + )); $deleteCommmand = $consoleParser->addCommand('delete', array('multiple'=>false,"alias"=>"d","description" => "Deletes diagnostic files")); @@ -179,161 +219,15 @@ $deleteCommmand = $consoleParser->addCommand('delete', a try { $result = $consoleParser->parse(); if ($result->command_name){ - $command_name = $result->command_name; + $command_name = "c_".$result->command_name; $command = $result->command; }else{ - throw new \Exception("Command missing, use -h to learn about available commands."); + throw new \Exception("Welcome to AlternC Diagnostics! Use -h to learn about available commands."); } if( !method_exists($diagnosticManager, $command_name)){ throw new \Exception("Invalid command : $command"); } - $diagnosticManager->$command_name($command); + $result = $diagnosticManager->$command_name($command); } catch (\Exception $exc) { $consoleParser->displayError($exc->getMessage()); } -/* -// Put this var to 1 if you want to enable debug prints - - -$admin->stop_if_jobs_locked(); - -$LOCK_FIL E= '/var/run/alternc/do_actions_cron.lock'; -$SCRIP T= '/usr/bin/php do_actions.php'; -$MY_PI D= getmypid(); -$FIXPER M= '/usr/lib/alternc/fixperms.sh'; - -// Check if script isn't already running -if (file_exists($LOCK_FILE) !== false){ - d("Lock file already exists. "); - // Check if file is in process list - $PI D= file_get_contents($LOCK_FILE); - d("My PID is $MY_PID, PID in the lock file is $PID"); - if ($PID == exec("pidof $SCRIPT | tr ' ' '\n' | grep -v $MY_PID")){ - // Previous cron is not finished yet, just exit - d("Previous cron is already running, we just exit and let it finish :-)"); - exit(0); - }else{ - // Previous cron failed! - $error_raise .= "Lock file already exists. No process with PID $PID found! Previous cron failed...\n"; - d("Removing lock file and trying to process the failed action..."); - // Delete the lock and continue to the next action - unlink($LOCK_FILE); - - // Lock with the current script's PID - if (file_put_contents($LOCK_FILE,$MY_PID) === false){ - $error_raise .= "Cannot open/write $LOCK_FILE\n"; - mail_it(); - exit(1); - } - - // Get the action(s) that was processing when previous script failed - // (Normally, there will be at most 1 job pending... but who know?) - while($cc=$action->get_job()){ - $ c= $cc[0]; - $param s= unserialize($c["parameters"]); - // We can resume these types of action, so we reset the job to process it later - d("Previous job was the n°".$c["id"]." : '".$c["type"]."'"); - if($c["type"] == "CREATE_FILE" && is_dir(dirname($params["file"])) || $c["type"] == "CREATE_DIR" || $c["type"] == "DELETE" || $c["type"] == "FIXDIR" || $c["type"] == "FIXFILE"){ - d("Reset of the job! So it will be resumed..."); - $action->reset_job($c["id"]); - }else{ - // We can't resume the others types, notify the fail and finish this action - $error_raise .= "Can't resume the job n°".$c["id"]." action '".$c["type"]."', finishing it with a fail status.\n"; - if(!$action->finish($c["id"],"Fail: Previous script crashed while processing this action, cannot resume it.")){ - $error_raise .= "Cannot finish the action! Error while inserting the error value in the DB for action n°".$c["id"]." : action '".$c["type"]."'\n"; - break; // Else we go into an infinite loop... AAAAHHHHHH - } - } - } - } -}else{ - // Lock with the current script's PID - if (file_put_contents($LOCK_FILE,$MY_PID) === false){ - $error_raise .= "Cannot open/write $LOCK_FILE\n"; - mail_it(); - exit(1); - } -} - -//We get the next action to do -while ($rr=$action->get_action()){ - $ r= $rr[0]; - $retur n= "OK"; - // Do we have to do this action with a specific user? - if($r["user"] != "root") - $S U= "su ".$r["user"]." 2>&1 ;"; - else - $S U= ""; - unset($output); - // We lock the action - d("-----------\nBeginning action n°".$r["id"]); - $action->begin($r["id"]); - // We process it - $param s= @unserialize($r["parameters"]); - // We exec with the specified user - d("Executing action '".$r["type"]."' with user '".$r["user"]."'"); - switch ($r["type"]){ - case "FIX_USER" : - // Create the directory and make parent directories as needed - @exec("$FIXPERM -u ".$params["uid"]." 2>&1", $trash, $code); - break; - case "CREATE_FILE" : - if(!file_exists($params["file"])) - @exec("$SU touch ".$params["file"]." 2>&1 ; echo '".$params["content"]."' > '".$params["file"]."' 2>&1", $output); - else - $outpu t= array("Fail: file already exists"); - break; - case "CREATE_DIR" : - // Create the directory and make parent directories as needed - @exec("$SU mkdir -p ".$params["dir"]." 2>&1",$output); - break; - case "DELETE" : - // Delete file/directory and its contents recursively - @exec("$SU rm -rf ".$params["dir"]." 2>&1", $output); - break; - case "MOVE" : - // If destination dir does not exists, create it - if(!is_dir($params["dst"])) - @exec("$SU mkdir -p ".$params["dst"]." 2>&1",$output); - if(!isset($output[0])) - @exec("$SU mv -f ".$params["src"]." ".$params["dst"]." 2>&1", $output); - break; - case "FIXDIR" : - @exec("$FIXPERM -d ".$params["dir"]." 2>&1", $trash, $code); - if($code!=0) - $output[0]="Fixperms.sh failed, returned error code : $code"; - break; - case "FIXFILE" : - @exec("$FIXPERM -f ".$params["file"]." 2>&1", $trash, $code); - if($code!=0) - $output[0]="Fixperms.sh failed, returned error code : $code"; - break; - default : - $outpu t= array("Fail: Sorry dude, i do not know this type of action"); - break; - } - // Get the error (if exists). - if(isset($output[0])){ - $retur n= $output[0]; - $error_raise .= "Action n°".$r["id"]." '".$r["type"]."' failed! With user: ".$r["user"]."\nHere is the complete output:\n".print_r($output); - } - // We finished the action, notify the DB. - d("Finishing... return value is : $return\n"); - if(!$action->finish($r["id"],addslashes($return))){ - $error_raise .= "Cannot finish the action! Error while inserting the error value in the DB for action n°".$c["id"]." : action '".$c["type"]."'\nReturn value: ".addslashes($return)."\n"; - break; // Else we go into an infinite loop... AAAAHHHHHH - } -} - -// If something have failed, notify it to the admin -if($error_raise !== '') - mail_it(); - -// Unlock the script -unlink($LOCK_FILE); - -// Exit this script -exit(0); -?> - -*/