My code works great so far, except for one part which I need to bypass somehow because this is going to be an autosys job. That one part is logging in to lotus notes (when I'm logged in and the app is still running); every time my script runs it requires the user to input his password. I've tried code to log in to my account but it still didn't work for me, so I was wondering what am I missing? Any help would be greatly appreciated! My code is below. It is very close to being finished. The popup is the only issue I have; the code below is compilable and runs just fine so far.
import java.io.IOException;
import java.util.*;
import javax.mail.*;
import javax.mail.Session;
import javax.mail.internet.*;
import javax.swing.JOptionPane;
import javax.activation.*;
import lotus.domino.*;
import lotus.notes.addins.util.DominoAddressBook;
public class SendEmail extends NotesThread {
#SuppressWarnings("deprecation")
public static void main(String [] args) throws AddressException, MessagingException {
// runs the program, mainly runNotes()
SendEmail e = new SendEmail();
e.start();
//e.sendMail();
}
public void runNotes() {
try {
// TODO: pop's up dialog box for user password to be input if password is in line 32 else its line 59
// might be because I'm creating a new session each time the program is run?
// this lets you retype the password as many times as you want until you got it correct (no password in argument, line 32)
lotus.domino.Session s = NotesFactory.createSessionWithFullAccess();
// configures so the password entered in the dialog box matches the password here (security check user)
// lotus.domino.Session s = NotesFactory.createSession((String)null, "userID", "pass!");
String p = s.getPlatform();
System.out.println("Platform: " + p);
System.out.println("Username: " + s.getUserName());
System.out.println("Server name: " + s.getServerName());
// self explantory, set's up the email with the message, attachment, etc
Database db = s.getDatabase(null, "C:\\Program Files (x86)\\IBM\\Lotus\\Notes\\Data\\names.nsf");
Document doc = db.createDocument();
doc.setSaveMessageOnSend(true);
RichTextItem attachedFile = doc.createRichTextItem("Attachment");
attachedFile.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "G-Man", "C:\\Users\\F400318\\Desktop\\testDB2.xlsx", "testDB");
StringBuilder body = new StringBuilder();
body.append("This email is a test!");
doc.appendItemValue("\n\n");
doc.appendItemValue("Body", body.toString());
doc.appendItemValue("Subject", "Test E-Mail");
doc.appendItemValue("Sent", "user#emailcompany.com");
doc.send("user#emailcompany.com");
System.out.println("Check email... it should have been sent");
} catch (Exception e) {
e.printStackTrace();
}
}
Where is your code running? On a Domino server, from a Notes client, or outside of Notes/Domino entirely?
The createSessionWithFullAccess() method assumes the code is running on the server and it will prompt for the password when needed unless you pass the password as an argument createSessionWithFullAccess("password").
http://www-12.lotus.com/ldd/doc/domino_notes/rnext/help6_designer.nsf/b3266a3c17f9bb7085256b870069c0a9/5a8f8afb89d617f785256c54004d9eb4?OpenDocument
* Edit *
From the looks of your code, you're trying to create a Swing application with JOptionPane, so using createSessionWithFullAccess() isn't necessary from the Notes client. You could just use NotesFactory.createSession() and it will use the users's Notes ID for credentials. Another option you could consider is if you're calling your code from a Notes agent, then you could pass the Session created by the agent to your code instead of creating a new one.
Related
Hey I want to send a welcome message to new people.
This is my Code. Im very new at Java please help me to get this feature working:
package de.backxtar.listener;
import java.time.OffsetDateTime;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class JoinListener extends ListenerAdapter {
#Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
Member member = event.getMember();
if((event.getGuild().getDefaultChannel()) != null) {
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(0xf22613);
builder.setThumbnail("http://image.png");
builder.setTitle("Willkommen auf Da Hood!");
builder.setFooter("Powered by Backxtar.");
builder.setTimestamp(OffsetDateTime.now());
builder.setDescription("Herzlich willkommen" + member.getAsMention() + "auf **Da Hood**!\n"
+ "[**Da Hood - The Best Gaming-Discord!**](https://xyz.gg)");
member.getUser().openPrivateChannel().queue((ch) -> {
ch.sendMessage(builder.build()).queue();
});
}
}
}
How does this funktion to be? if((event.getGuild().getDefaultChannel()) != null) {
Thanks!!
first of all, event.getGuild().getDefaultChannel() returns you the channel set for "System Messages Channel" in the server settings, or if none is set there, the first text channel on the Discord Server.
Secondly, unfortunately I cannot tell you why your code does not work because it works perfectly for me, maybe it could be because your Discord server does not have TextChannel if that is the case try if your code works when you create a TextChannel on your Discord server.
For example i block my site for Pakistan.Then how do i automate from Pakistan end,to check whether my site is blocked or not .
We used TOR for this case via silvertunnel lib https://mvnrepository.com/artifact/org.silvertunnel-ng.
import java.io.IOException;
import java.net.Socket;
import net.freehaven.tor.control.TorControlConnection;
public class Main {
public static void main(String[] args) throws IOException {
//Connecting to TOR's control port
//TOR must be running and following line must be added to the torrc:
//ControlPort 9100
Socket s = new Socket("127.0.0.1", 9100);
TorControlConnection conn = TorControlConnection.getConnection(s);
//no authentification at the moment
conn.authenticate(new byte[0]);
//write some changes to torrc (like setting exit node)
//ExitNodes {US}
//StrictExitNodes 1
//send "RELOAD" signal - reloading torrc from disk
conn.signal("RELOAD");
}
}
And these files: https://github.com/guardianproject/jtorctl
It was long time ago so I have no more code but here are a couple of links for reference:
http://www.yasith.me/2017/01/selenium-webdriver-with-tor-network.html
https://tor.stackexchange.com/questions/652/how-to-call-tor-browser-using-selenium-using-java
I followed several different tutorials for his but everytime more or less nothing happens. Since I had problems with "ClassNotFoundException" I used the mongodb driver jar file suggested in this question:
Stackoverflow Topic
I have a very simple Java Project with a Class Test running the main method to connect to my database "local" and to the collection "Countries" according to several tutorials, the data should be inserted as defined in the code. But when I check the collection in command line or Studio 3T it is still empty. There are some unused imports due to several tests before.
import org.bson.Document;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
MongoClient connection = new MongoClient("localhost", 27017);
DB db = connection.getDB("local");
DBCollection coll = db.getCollection("Countries");
BasicDBObject doc = new BasicDBObject("title", "MongoDB").
append("name","Germany" ).
append("population", "82 000 000");
coll.insert(doc);
System.out.print("Test");
}
catch(Exception e) {
System.out.print(e);
System.out.print("Test");
}
}
}
The output is the following:
Usage : [--bucket bucketname] action
where action is one of:
list : lists all files in the store
put filename : puts the file filename into the store
get filename1 filename2 : gets filename1 from store and sends to filename2
md5 filename : does an md5 hash on a file in the db (for testing)
I dont get why the insert is not working and in addition why the System.out.print methods are not showing up. The getDB method is also cancelled in eclipse saying "The method getDB(String) from the type Mongo is deprecated" that i do not really understand. I hope someone can help me to get the code working. Mongod.exe is running in the background.
I am using ssh factory to automate the logins. I have to automate logins till 4 gateways and send commands and get output's of it. I have successfully automated till 3 gateways. Now i have to fire command "telnet remote_ip" to get into the 4th gateway. Where i am using telnet sessions for this 4th gateway alone since i need to fire "telnet ip", since it is using telnet protocol over here. But for the previous 3 gateway's i've used ssh sessions. But it is not firing this "telnet ip" command. Can some1 help me regarding this?.
Below is the code, where i am trying to automate it.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import com.jscape.inet.ssh.Ssh;
import com.jscape.inet.ssh.SshAdapter;
import com.jscape.inet.ssh.SshConnectedEvent;
import com.jscape.inet.ssh.SshDataReceivedEvent;
import com.jscape.inet.ssh.SshDisconnectedEvent;
import com.jscape.inet.ssh.SshException;
import com.jscape.inet.ssh.SshScript;
import com.jscape.inet.ssh.SshSession;
import com.jscape.inet.ssh.SshTask;
import com.jscape.inet.ssh.connection.channels.SessionClient;
import com.jscape.inet.ssh.connection.channels.SessionRequests;
import com.jscape.inet.ssh.util.SshParameters;
import com.jscape.inet.telnet.Telnet;
import com.jscape.inet.telnet.TelnetException;
import com.jscape.inet.telnet.TelnetListener;
import com.jscape.inet.telnet.TelnetScript;
import com.jscape.inet.telnet.TelnetSession;
import com.jscape.inet.telnet.TelnetTask;
public class SshScriptTutorial extends SshAdapter {
public SshScriptTutorial() {}
public void executeSshScript(String hostname, String username, String password)
throws SshException, IOException, InterruptedException, TelnetException
{
// assumes that SSH shell prompt is ">" .. this MUST match exactly
String shellPrompt = ">";
String shellPrompt1 = ":";
// initialize and create new Ssh instance
SshParameters sshParams = new SshParameters(hostname,username,password);
Ssh ssh = new Ssh(sshParams);
// register this class to receive Ssh events
ssh.addSshListener(this);
// create new script object and bind to the given ssh object
SshScript script = new SshScript(ssh);
// add tasks to script object
script.addTask(new SshTask(shellPrompt, "show host", shellPrompt));
script.addTask(new SshTask(shellPrompt, "ssh ssgpun", shellPrompt1)); // 2nd g/w
script.addTask(new SshTask(shellPrompt1, "password", shellPrompt));
script.addTask(new SshTask(shellPrompt, "net ip", shellPrompt1)); // 3rd gateway
script.addTask(new SshTask(shellPrompt1, "username", shellPrompt1));
script.addTask(new SshTask(shellPrompt1, "password", shellPrompt));
// till this it is working
// connect to SSH server and execute script
ssh.connect();
// wait until last task is complete
while(!script.isComplete()) {
try {
Thread.sleep(500);
} catch(Exception e) {
System.err.println(e.getMessage());
}
}
// disconnect from server
// ssh.disconnect();
//**
Here i am trying to get into the last remote server using command "telnet ip" using telnet session since it is involving telnet protocol. But it is not firing this command itself. So, can anybody help me regarding this. How to do?... I have even tried using ssh sessions for this "telnet ip" and for username and pass. If i use ssh session for this 4th gateway, i am able to automate only "telnet ip" and it is asking for login name, and login name is not automated. So, i have tried both ssh sessions and telnet sessions. I dont know what is the prob or how to solve it.
Kindly help...
//**
// create new Telnet instance
Telnet telnet = new Telnet("10.228.128.33");
// create new TelnetScript instance and bind to Telnet instance
TelnetScript script_t = new TelnetScript(telnet);
// create a task that waits for login prompt and submits username
TelnetTask username_t = new TelnetTask(shellPrompt1,"switchind", shellPrompt1);
// create task that waits for password prompt and submits password
TelnetTask password_t = new TelnetTask(shellPrompt1, "Indore123", shellPrompt);
// add tasks to script
script_t.addTask(username_t);
script_t.addTask(password_t);
// connect to telnet server … script is executed automatically
telnet.connect();
}
public void connected(SshConnectedEvent event) {
System.out.println("Connected to host: " + event.getHost());
}
public void disconnected(SshDisconnectedEvent event) {
System.out.println("Disconnected from host: " + event.getHost());
}
public void dataReceived(SshDataReceivedEvent event) {
System.out.print(event.getData());
}
public static void main(String[] args)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String hostname = "host_ip";
String username = "username";
System.out.print("Enter password: ");
String password = reader.readLine();
SshScriptTutorial tutorial = new SshScriptTutorial();
tutorial.executeSshScript(hostname, username, password);
} catch(Exception e) {
e.printStackTrace();
}
}
}
I would like to pre-fill and periodically put data to the Google Appengine database.
I would like to write a program in java and python that connect to my GAE service and upload data to my database.
How can I do that?
Thanks
Please use RemoteAPI for doing this programmatically.
In python, you can first configure the appengine_console.py as described here
Once you have that, you can launch and write the following commands in the python shell:
$ python appengine_console.py yourapp
>>> import yourdbmodelclassnamehere
>>> m = yourmodelclassnamehere(x='',y='')
>>> m.put()
And here is code from the java version which is self explanatory (directly borrowed from the remote api page on gae docs):
package remoteapiexample;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;
import java.io.IOException;
public class RemoteApiExample {
public static void main(String[] args) throws IOException {
String username = System.console().readLine("username: ");
String password =
new String(System.console().readPassword("password: "));
RemoteApiOptions options = new RemoteApiOptions()
.server("<your app>.appspot.com", 443)
.credentials(username, password);
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
System.out.println("Key of new entity is " +
ds.put(new Entity("Hello Remote API!")));
} finally {
installer.uninstall();
}
}
}