Compare commits

7 Commits

Author SHA1 Message Date
tilman 718a55cb76 eclipse test 2 2012-09-11 10:32:35 +02:00
tilman 233cd3614e test eclipse 2012-09-11 10:23:21 +02:00
tilman 5322961234 Merge branch 'master' of file:////home/tilman/hidrive/Tilman/Privat/Computerarbeit/Repositories/CallerIdClient 2012-09-11 08:20:24 +02:00
tilman 38a3f3f402 Umbau auf Gmail 2012-07-30 23:20:00 +02:00
tilman 2dd6525e22 mc 2012-07-30 22:38:48 +02:00
tilman b20c563b93 mc cmd line 2012-07-30 22:25:53 +02:00
tilman e9252aa18a renamed package 2012-07-30 22:12:58 +02:00
5 changed files with 16 additions and 30 deletions
+2
View File
@@ -1,3 +1,5 @@
eclipse II
https://speedport.ip/index/login.cgi https://speedport.ip/index/login.cgi
POST /index/login.cgi HTTP/1.1 POST /index/login.cgi HTTP/1.1
@@ -1,4 +1,4 @@
package de.tilman.callerId; package de.tilman.callerid;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -30,7 +30,6 @@ import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactEntry; import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed; import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.data.extensions.PhoneNumber; import com.google.gdata.data.extensions.PhoneNumber;
import com.martiansoftware.jsap.FlaggedOption;
import com.martiansoftware.jsap.JSAP; import com.martiansoftware.jsap.JSAP;
import com.martiansoftware.jsap.JSAPException; import com.martiansoftware.jsap.JSAPException;
import com.martiansoftware.jsap.JSAPResult; import com.martiansoftware.jsap.JSAPResult;
@@ -75,10 +74,10 @@ public class CallerIdClient {
if (calls.size() > 0) { if (calls.size() > 0) {
List<ContactEntry> contacts = null; List<ContactEntry> contacts = null;
if (config.getString("google username") != null) { if (config.getBoolean("check contacts")) {
log.info("retrieving Google contacts"); log.info("retrieving Google contacts");
ContactsService service = new ContactsService("<var>SpeedportCallerIdClient</var>"); ContactsService service = new ContactsService("<var>SpeedportCallerIdClient</var>");
service.setUserCredentials(config.getString("google username"), config.getString("google password")); service.setUserCredentials(config.getString("e-mail adress"), config.getString("e-mail password"));
URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full"); URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
Query myQuery = new Query(feedUrl); Query myQuery = new Query(feedUrl);
myQuery.setMaxResults(1000); myQuery.setMaxResults(1000);
@@ -187,9 +186,6 @@ public class CallerIdClient {
if (cookie != null) { if (cookie != null) {
connection.setRequestProperty("Cookie", "SessionID_R3=" + cookie); connection.setRequestProperty("Cookie", "SessionID_R3=" + cookie);
} }
// connection.setRequestProperty("Referer",
// "https://speedport.ip/auth/hcti_status_telanrl.php?cookie=SessionID_R3,"
// + cookie);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
if (payload.length() > 0) { if (payload.length() > 0) {
@@ -235,17 +231,15 @@ public class CallerIdClient {
} }
private void sendNotification(String time, String caller) throws Exception { private void sendNotification(String time, String caller) throws Exception {
String host = config.getString("SMTP server address"); String host = "smtp.gmail.com";
String from = config.getString("e-mail adress"); String from = config.getString("e-mail adress");
String pass = config.getString("e-mail password"); String pass = config.getString("e-mail password");
Properties props = System.getProperties(); Properties props = System.getProperties();
props.put("mail.smtp.ssl.enable", "true"); props.put("mail.smtp.starttls.enable", "true");
// props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host); props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from); props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass); props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "465"); props.put("mail.smtp.port", "587");
// props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true"); props.put("mail.smtp.auth", "true");
String[] to = config.getStringArray("recipient"); String[] to = config.getStringArray("recipient");
@@ -275,9 +269,10 @@ public class CallerIdClient {
transport.close(); transport.close();
} }
@SuppressWarnings("rawtypes")
public static void main(String[] args) { public static void main(String[] args) {
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n"))); BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d{ISO8601} - %m%n")));
log.info("Starting CallerIdClient version 1.0.2"); log.info("Starting CallerIdClient version 1.1.2");
JSAP jsap = new JSAP(); JSAP jsap = new JSAP();
@@ -292,19 +287,14 @@ public class CallerIdClient {
updateInterval.setHelp("the interval beetween runs in minutes"); updateInterval.setHelp("the interval beetween runs in minutes");
jsap.registerParameter(updateInterval); jsap.registerParameter(updateInterval);
UnflaggedOption smtpServer = new UnflaggedOption("SMTP server address").setStringParser(JSAP.STRING_PARSER)
.setRequired(true);
smtpServer.setHelp("the SMTP server to send notifications with");
jsap.registerParameter(smtpServer);
UnflaggedOption fromAddress = new UnflaggedOption("e-mail adress").setStringParser(JSAP.STRING_PARSER).setRequired( UnflaggedOption fromAddress = new UnflaggedOption("e-mail adress").setStringParser(JSAP.STRING_PARSER).setRequired(
true); true);
fromAddress.setHelp("e-mail address to send from"); fromAddress.setHelp("Google mail address to send from");
jsap.registerParameter(fromAddress); jsap.registerParameter(fromAddress);
UnflaggedOption emailPassword = new UnflaggedOption("e-mail password").setStringParser(JSAP.STRING_PARSER) UnflaggedOption emailPassword = new UnflaggedOption("e-mail password").setStringParser(JSAP.STRING_PARSER)
.setRequired(true); .setRequired(true);
emailPassword.setHelp("the login password for the e-mail account"); emailPassword.setHelp("the login password for the Google account");
jsap.registerParameter(emailPassword); jsap.registerParameter(emailPassword);
UnflaggedOption recipients = new UnflaggedOption("recipient").setStringParser(JSAP.STRING_PARSER).setRequired(true) UnflaggedOption recipients = new UnflaggedOption("recipient").setStringParser(JSAP.STRING_PARSER).setRequired(true)
@@ -312,15 +302,9 @@ public class CallerIdClient {
recipients.setHelp("e-mail addresses to send notifications to"); recipients.setHelp("e-mail addresses to send notifications to");
jsap.registerParameter(recipients); jsap.registerParameter(recipients);
FlaggedOption googleUsername = new FlaggedOption("google username").setStringParser(JSAP.STRING_PARSER).setShortFlag( Switch contactsSwitch = new Switch("check contacts").setLongFlag("contacts");
'u'); contactsSwitch.setHelp("retrieve contacts from Google account and resolve caller names");
googleUsername.setHelp("the Google username for contact name resolution"); jsap.registerParameter(contactsSwitch);
jsap.registerParameter(googleUsername);
FlaggedOption googlePassword = new FlaggedOption("google password").setStringParser(JSAP.STRING_PARSER).setShortFlag(
'p');
googleUsername.setHelp("the Google password for contact name resolution");
jsap.registerParameter(googlePassword);
Switch debugSwitch = new Switch("debug").setLongFlag("debug"); Switch debugSwitch = new Switch("debug").setLongFlag("debug");
debugSwitch.setHelp("print debug messages"); debugSwitch.setHelp("print debug messages");
@@ -1,4 +1,4 @@
package de.tilman.callerId; package de.tilman.callerid;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;