Paket-Anlegen begonnen
This commit is contained in:
parent
a71fd7fe67
commit
ea8c5d5924
BIN
hsarback/lib/commons-net2-2.0.jar
Normal file
BIN
hsarback/lib/commons-net2-2.0.jar
Normal file
Binary file not shown.
BIN
hsarback/lib/jpwgen-1.2.0.jar
Normal file
BIN
hsarback/lib/jpwgen-1.2.0.jar
Normal file
Binary file not shown.
@ -1,15 +1,11 @@
|
|||||||
package de.hsadmin.core.qserv;
|
package de.hsadmin.core.qserv;
|
||||||
|
|
||||||
import java.util.Properties;
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
|
import de.hsadmin.core.util.Config;
|
||||||
import javax.mail.MessagingException;
|
|
||||||
import javax.mail.Session;
|
|
||||||
import javax.mail.internet.InternetAddress;
|
|
||||||
import javax.mail.internet.MimeMessage;
|
|
||||||
|
|
||||||
public class MailerProcessor extends AbstractProcessor {
|
public class MailerProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = -8900943664576420041L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String aTo;
|
private String aTo;
|
||||||
private String aSubject;
|
private String aSubject;
|
||||||
@ -22,20 +18,14 @@ public class MailerProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object process() throws ProcessorException {
|
public Object process() throws ProcessorException {
|
||||||
Properties aProps = new Properties();
|
|
||||||
aProps.setProperty("mail.smtp.host", "localhost");
|
|
||||||
|
|
||||||
Session aSess = Session.getInstance(aProps);
|
|
||||||
MimeMessage aMsg = new MimeMessage(aSess);
|
|
||||||
try {
|
try {
|
||||||
aMsg.setFrom(new InternetAddress("robot@hostsharing.net"));
|
Config config = Config.getInstance();
|
||||||
aMsg.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(aTo));
|
String aFrom = config.getProperty("hsadmin.smtp.from", "unconfigured_from@example.com");
|
||||||
aMsg.setSubject(aSubject);
|
String aCC = config.getProperty("hsadmin.smtp.cc", "unconfigured_cc@example.com");
|
||||||
aMsg.setText(aBody);
|
SmtpHelper.send(aFrom, aTo, aCC, aSubject, aBody);
|
||||||
MailerShell.send(aMsg);
|
|
||||||
return null;
|
return null;
|
||||||
} catch (MessagingException aExc) {
|
} catch (HSAdminException e) {
|
||||||
throw new ProcessorException(aExc);
|
throw new ProcessorException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package de.hsadmin.core.qserv;
|
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
|
||||||
import javax.mail.internet.MimeMessage;
|
|
||||||
|
|
||||||
public class MailerShell {
|
|
||||||
|
|
||||||
private static boolean bExecute = true; // really execute or just store
|
|
||||||
// command and stdin?
|
|
||||||
private static MimeMessage aMessage; // stored message
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set mode of real mailer or just storing the messages for testing
|
|
||||||
* purposes.
|
|
||||||
*
|
|
||||||
* @param bExec
|
|
||||||
* specifies whether messages are really send (true) or just
|
|
||||||
* stored (false)
|
|
||||||
*/
|
|
||||||
public static void setExecute(boolean bExec) {
|
|
||||||
bExecute = bExec;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns and clears the last command which should have been executed.
|
|
||||||
*
|
|
||||||
* @return Last command, plus "<<EOF\n" + stdin + "EOF" if stdin was given.
|
|
||||||
*/
|
|
||||||
public static MimeMessage popLastMessage() {
|
|
||||||
MimeMessage aLastMessage = aMessage;
|
|
||||||
aMessage = null;
|
|
||||||
return aLastMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void send(MimeMessage aMsg) throws MessagingException {
|
|
||||||
if (bExecute)
|
|
||||||
javax.mail.Transport.send(aMsg);
|
|
||||||
aMessage = aMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
76
hsarback/src/de/hsadmin/core/qserv/SmtpHelper.java
Normal file
76
hsarback/src/de/hsadmin/core/qserv/SmtpHelper.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package de.hsadmin.core.qserv;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import org.apache.commons.net.smtp.SMTPClient;
|
||||||
|
import org.apache.commons.net.smtp.SMTPReply;
|
||||||
|
import org.apache.commons.net.smtp.SimpleSMTPHeader;
|
||||||
|
|
||||||
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
|
import de.hsadmin.core.util.Config;
|
||||||
|
|
||||||
|
public class SmtpHelper {
|
||||||
|
|
||||||
|
public static void send(String fromAddress, String toAddress, String subject, String text)
|
||||||
|
throws HSAdminException {
|
||||||
|
send(fromAddress, toAddress, null, subject, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void send(String fromAddress, String toAddress, String ccAddress, String subject, String text)
|
||||||
|
throws HSAdminException {
|
||||||
|
try {
|
||||||
|
SMTPClient client = new SMTPClient();
|
||||||
|
String canonicalHostName = InetAddress.getLocalHost().getHostName();
|
||||||
|
String smtpHost = Config.getInstance().getProperty("smtp.host");
|
||||||
|
if ("unittest".equals(smtpHost)) { // Nur fuer Unit-Tests
|
||||||
|
if (subject.toLowerCase().contains("error")) {
|
||||||
|
throw new HSAdminException("Konnte Mail nicht senden");
|
||||||
|
}
|
||||||
|
System.out.println("------------------------");
|
||||||
|
System.out.println("From: " + fromAddress);
|
||||||
|
System.out.println("To: " + toAddress);
|
||||||
|
System.out.println("Subject: " + subject);
|
||||||
|
System.out.println("\n" + text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
client.connect(smtpHost, 25);
|
||||||
|
int reply = client.getReplyCode();
|
||||||
|
if (!SMTPReply.isPositiveCompletion(reply)) {
|
||||||
|
throw new HSAdminException("Konnte Mail Server nicht erreichen");
|
||||||
|
}
|
||||||
|
client.login(canonicalHostName);
|
||||||
|
client.setSender(fromAddress.trim());
|
||||||
|
client.addRecipient(toAddress.trim());
|
||||||
|
if (ccAddress != null && ccAddress.trim().length() > 3) {
|
||||||
|
client.addRecipient(ccAddress.trim());
|
||||||
|
}
|
||||||
|
Writer sendMessageData = client.sendMessageData();
|
||||||
|
if (sendMessageData == null) {
|
||||||
|
throw new HSAdminException("Konnte Mail nicht senden (SMTP-Relay-Problem)");
|
||||||
|
}
|
||||||
|
PrintWriter wr = new PrintWriter(sendMessageData);
|
||||||
|
SimpleSMTPHeader header = new SimpleSMTPHeader(fromAddress, toAddress,
|
||||||
|
subject);
|
||||||
|
wr.write(header.toString());
|
||||||
|
wr.write(text);
|
||||||
|
wr.close();
|
||||||
|
if (!client.completePendingCommand()) {
|
||||||
|
throw new HSAdminException("Konnte Mail nicht senden");
|
||||||
|
}
|
||||||
|
client.logout();
|
||||||
|
client.disconnect();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (SocketException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -96,6 +96,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult();
|
Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult();
|
||||||
if (maxUid >= nUID) nUID = maxUid + 1;
|
if (maxUid >= nUID) nUID = maxUid + 1;
|
||||||
admin.setUserId(nUID);
|
admin.setUserId(nUID);
|
||||||
|
users.add(admin);
|
||||||
return super.add(newEntity);
|
return super.add(newEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
94
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
Normal file
94
hsarback/src/de/hsadmin/mods/pac/PacProcessorFactory.java
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package de.hsadmin.mods.pac;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import net.sf.jtpl.Template;
|
||||||
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
|
import de.hsadmin.core.qserv.CompoundProcessor;
|
||||||
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
|
import de.hsadmin.core.qserv.MailerProcessor;
|
||||||
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
import de.hsadmin.core.qserv.ProcessorException;
|
||||||
|
import de.hsadmin.core.qserv.ShellProcessor;
|
||||||
|
import de.hsadmin.core.qserv.TemplateProcessor;
|
||||||
|
import de.hsadmin.core.qserv.WaitingTasksProcessor;
|
||||||
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
import de.rrze.jpwgen.flags.PwGeneratorFlagBuilder;
|
||||||
|
import de.rrze.jpwgen.impl.PwGenerator;
|
||||||
|
|
||||||
|
public class PacProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
|
private static PwGeneratorFlagBuilder flagBuilder = new PwGeneratorFlagBuilder();
|
||||||
|
private static Random random = new Random();
|
||||||
|
|
||||||
|
static {
|
||||||
|
flagBuilder.setIncludeCapitals();
|
||||||
|
flagBuilder.setIncludeNumerals();
|
||||||
|
// flagBuilder.setIncludeReducedSymbols();
|
||||||
|
flagBuilder.setFilterAmbiguous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends AbstractEntity> Processor createCreateProcessor(
|
||||||
|
EntityManager em, T entity) throws ProcessorException {
|
||||||
|
Pac pac = (Pac) entity;
|
||||||
|
String inetAddr = pac.getCurINetAddr().getInetAddr();
|
||||||
|
String pacName = pac.getName();
|
||||||
|
String customerEMail = pac.getCustomer().getContractualContact().getEmail();
|
||||||
|
UnixUser unixUser = null;
|
||||||
|
Set<UnixUser> unixUserSet = pac.getUnixUser();
|
||||||
|
if (unixUserSet.size() == 1) {
|
||||||
|
unixUser = unixUserSet.iterator().next();
|
||||||
|
}
|
||||||
|
Processor hostsAppender = new ShellProcessor("echo '" + inetAddr + " " + pacName +".hostsharing.net " + pacName + "\n' >>/etc/hosts");
|
||||||
|
Processor interfacesAppender = new ShellProcessor("echo 'auto eth0:" + pacName + "\n" +
|
||||||
|
"iface eth0:" + pacName + " inet static\n" +
|
||||||
|
"\taddress " + inetAddr + "\n" +
|
||||||
|
"\tnetmask 255.255.255.0\n\n' >>/etc/network/interfaces");
|
||||||
|
Processor sudoersAppender = new ShellProcessor("echo '" + pacName + " ALL = (%" + pacName + ") NOPASSWD: ALL\n' >> /etc/sudoers");
|
||||||
|
String password = PwGenerator.generatePassword(7, flagBuilder.build(), 100, random);
|
||||||
|
Processor newUsersProc = new ShellProcessor(
|
||||||
|
"newusers", pacName + ":" + password + ":"
|
||||||
|
+ unixUser.getUserId() + ":" + unixUser.getPac().getName()
|
||||||
|
+ ":" + unixUser.getComment() + ":" + unixUser.getHomedir()
|
||||||
|
+ ":" + unixUser.getShell() + "\n");
|
||||||
|
try {
|
||||||
|
InputStream stream = TemplateProcessor.class.getClassLoader().getResourceAsStream("/de/hsadmin/mods/pac/email_new_pac_account.jtpl");
|
||||||
|
Template template = new Template(new InputStreamReader(stream));
|
||||||
|
template.assign("PAC", pacName);
|
||||||
|
template.assign("PASSWORD", password);
|
||||||
|
template.assign("CUST_EMAIL", customerEMail);
|
||||||
|
template.parse("main");
|
||||||
|
Processor emailPasswordProc = new WaitingTasksProcessor(
|
||||||
|
new MailerProcessor(
|
||||||
|
customerEMail,
|
||||||
|
"Zugangsdaten des neue Hostsharing Pakets " + pacName,
|
||||||
|
template.out())
|
||||||
|
);
|
||||||
|
return new CompoundProcessor(hostsAppender, interfacesAppender, sudoersAppender, newUsersProc, emailPasswordProc);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new ProcessorException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ProcessorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends AbstractEntity> Processor createUpdateProcessor(
|
||||||
|
EntityManager em, T newEntity) throws ProcessorException {
|
||||||
|
throw new ProcessorException("pac.update not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T extends AbstractEntity> Processor createDeleteProcessor(
|
||||||
|
EntityManager em, T entity) throws ProcessorException {
|
||||||
|
throw new ProcessorException("pac.delete not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
hsarback/src/de/hsadmin/mods/pac/email_new_pac_account.jtpl
Normal file
73
hsarback/src/de/hsadmin/mods/pac/email_new_pac_account.jtpl
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<!-- BEGIN: main -->Das neue Hostsharing Paket {PAC} ist eingerichtet. Zugangsdaten:
|
||||||
|
|
||||||
|
Hostname (HTTP, FTP, SSH, POP3, IMAP): {PAC}.hostsharing.net
|
||||||
|
Benutzernamen (Paket-Admin-Account): {PAC}
|
||||||
|
Passwort: {PASSWORD}
|
||||||
|
|
||||||
|
Wir bitten zu berücksichtigen, dass man mit diesem Passwort sehr viel
|
||||||
|
Macht über das Paket hat, so ist damit z.B. die Bestellung von Domains
|
||||||
|
möglich. Bitte daher die u.g. Sicherheitshinweise beachten und den
|
||||||
|
Paketadmin-Account {PAC} nicht mit unsicheren (unverschlüsselten)
|
||||||
|
Protokollen wie POP3 oder FTP ohne TLS verwenden!
|
||||||
|
|
||||||
|
E-Mail-Benachrichtigungen für den Paket-Admin gehen direkt an den
|
||||||
|
o.g. Account. Über den E-Mail-Alias {PAC} können diese E-Mails
|
||||||
|
an externe E-Mail-Adressen weitergeleitet werden. Initial ist
|
||||||
|
eine Weiterleitung an {CUST_EMAIL} eingetragen.
|
||||||
|
|
||||||
|
Wir empfehlen, Domains nicht unter dem Paketadmin {PAC} sondern z.B.
|
||||||
|
unter einem User "{PAC}-doms" anzulegen, um die Paket- und Domain-
|
||||||
|
Verwaltung zu trennen. Dies gilt insbesondere, wenn die Domain-Inhalte
|
||||||
|
per FTP gepflegt werden sollen.
|
||||||
|
|
||||||
|
Weitere Accounts (neben dem Paketadmin-Account {PAC}) können nach einem
|
||||||
|
Login per SSH mit dem Kommandozeilen-Programm hsadmin eingerichtet
|
||||||
|
werden (in Kürze auch per Web-Client). Dokumentation finden Sie unter:
|
||||||
|
|
||||||
|
<http://www.hostsharing.net/dokumentation.html>
|
||||||
|
|
||||||
|
Der Webspace des Paketes ist theoretisch ab sofort unter
|
||||||
|
<http://{PAC}.hostsharing.net/> erreichbar, allerdings kann es durch
|
||||||
|
DNS-Caches Verzögerungen geben. Das DocumentRoot ist ~{PAC}/web, wobei
|
||||||
|
~{PAC}/cgi als /cgi-bin in den Webspace eingeblendet wird. In SW Paketen
|
||||||
|
darf dieses CGI auch nur für administrative Zwecke verwendet werden.
|
||||||
|
|
||||||
|
Die vorgenannte Paket-Subdomain ist jedoch eher zum Testen und Ausprobieren
|
||||||
|
gedacht und hat mit dem folgenden Domain-Webspace nichts zu tun, der wird
|
||||||
|
unter ~{PAC}/doms/ angelegt, sobald eine Domain aufgeschaltet wird. Dort gibt
|
||||||
|
es dann für jede Domain ein separates Verzeichnis.
|
||||||
|
|
||||||
|
Das Verfahren zum Bestellen von Domains ist auf unserer Website unter
|
||||||
|
http://www.hostsharing.net/dokumentation/einstieg-bei-hostsharing/domain-bestellen.html
|
||||||
|
beschrieben. Ein Web-Interface hierfür ist in Entwicklung.
|
||||||
|
|
||||||
|
Bei evtl. auftretenden Problemen mit dem Server bitte zunächst auf
|
||||||
|
unserer Status-Website <http://status.hostsharing.net/> nachsehen,
|
||||||
|
insbesondere auch auf der dortigen Seite "Aktionen", ob die Hostmaster
|
||||||
|
bereits aktiv sind. Falls nicht, können die Hostmaster bei dringenden
|
||||||
|
Problemen über die Rufnummer +49 40 209331331 erreicht werden.
|
||||||
|
Bitte ggf. lange klingeln lassen, aber nicht mehr anrufen,
|
||||||
|
wenn die Hostmaster laut Status-Seite "Aktionen" bereits dabei sind,
|
||||||
|
das Problem zu beheben, da dies die Arbeiten dann nur verzögern würde.
|
||||||
|
Auch ist diese Rufnummer keine Support-Rufnummer, telefonische
|
||||||
|
Support-Anfragen können grundsätzlich nicht beantwortet werden.
|
||||||
|
|
||||||
|
Weitere Fragen beantworten wir gerne per E-Mail, am liebsten auf der
|
||||||
|
passenden öffentlichen Mailingliste (in den meisten Fällen wohl
|
||||||
|
support@). Einen Übeblick über unsere Mailinglisten bietet die Website:
|
||||||
|
http://www.hostsharing.net/forum/mailinglisten.html
|
||||||
|
|
||||||
|
Viel Erfolg mit dem neuen Paket bei Hostsharing!
|
||||||
|
|
||||||
|
die Hostsharing Hostmaster
|
||||||
|
|
||||||
|
P.S. Diese E-Mail wurde automatisch erstellt und ist daher allgemein
|
||||||
|
formuliert.
|
||||||
|
|
||||||
|
--
|
||||||
|
Hostsharing Service | http://www.hostsharing.net
|
||||||
|
Telefon: +49 40 209331311 | Fax: +49 40 209331312
|
||||||
|
Hostsharing eG | Glockengießerwall 17 | D-20095 Hamburg
|
||||||
|
Registergericht Hamburg, GnR 1007 | USt.-ID-Nr.: DE218602793
|
||||||
|
vertretungsberechtigter Vorstand: Michael Hierweck, Uwe Müller
|
||||||
|
<!-- END: main -->
|
Loading…
Reference in New Issue
Block a user