Ensuring if excel worksheet contains any user defined function [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
My application contains an upload option from which the user can upload files(any file).
I know that users have the ability to write code/scripts in excel worksheet.So how can i prevent that from happening as it can lead to security breach.
Or what check can i apply to know that the uploaded worksheet contains any function?

I assume from the Java tag that your appliction to which the sheet gets uploaded is a Java application.
Using Apache POI, you can use a POIFSReader (see this doc) to read the file on a lower level.
There is an example by RĂ©al Gagnon which shows how you can check the content by looking at the name.
I had to modify the listener (added another comparision)
class MacroListener implements POIFSReaderListener {
[...]
#Override
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
System.out.println(" Event: Name " + event.getName() + ", path "
+ event.getPath());
if (event.getPath().toString().startsWith("\\Macros")
|| event.getPath().toString().startsWith("\\_VBA")
|| event.getPath().toString().contains("_VBA_")) {
this.macroDetected = true;
}
}
}
so that it worked for some test files. You might have to tune/extend the checks.

Related

how can I get the member mentioned and displayed in the embed [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
if(msg.equalsIgnoreCase("hi")){
Member member = event.getMessage().getMentions().getMembers().get(0);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.cyan);
embedBuilder.setDescription("Hello, " + member.getUser().getName() + "!");
embedBuilder.build();
event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
message: hi #mentioned
expected answer: hello #mention or name
Get the user's ID and put it in between of <# and >. Example: <#355314189117554689>.
if (msg.equalsIgnoreCase("hi")) {
Member member = event.getMessage()
.getMentions()
.getMembers()
.get(0);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.cyan);
// simply put the users snowflake ID between <# and >
embedBuilder.setDescription("Hello, <#" + member.getUser().getId() + ">!");
embedBuilder.build();
event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
}
To get a mention of a member you can use member.getAsMention(), in your case if you would like to actually mention someone, you would need to do it in the actual message (not the embed itself) as embeds do not support mentions and so it will be formatted in a weird way.
Alternatively you can just get the users name using member.getEffectiveName() and prepend it with '#' so it would look like a mention, but won't actually mention anyone

Assert the URL or Navigate to it appropriately [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have one question - how to write a cucumber hook that asserts the web URL.
Example -
Let's say I am testing - https://www.usatoday.com/tech/
My Given is as follows -
Given I am on the "/tech/" page
I would like a method to add the base url (www.usatoday.com) + "/tech" and assert whether it is currently on that page
(driver.getURL() ==www.usatoday/tech/)
otherwise navigate to that page if I am not there.
Any Java pros that can help me with this? Many thanks my friends.
#Given("^I am on the \"([^\"]*)\" page$")
public void i_am_on_the_page(String arg) throws throwable{
String newBaseURL = getBaseURL() + arg;
String currentURL = driver.getCurrentURL();
try{
Assert.assertEquals(newBaseURL, currentURL);
}
catch(Exception e){
driver.get(newBaseURL);
}
}
I am assuming that you have a function - getBaseURL() that will provide you the base url.

Using IF commands to Check if a button exists in Selenium Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a java selenium program that automatically presses on a button in a website. The code i am using looks like this :
driver.findElement(By.id("button")).click();
I want the program to use if statements if possible.
Thanks for your help.
Use can use findelements by along with if to achieve this. Below code might give you some idea.
if(driver.findElements(by.xpath("//*[#id=253]")).size>0)
{
//element exists with id = 253
// do the stuff
} else
{
//element do not exist with id = 253.
// do the stuff
}
Hope this helps. Thanks.
You may try this:
public void ClickButton () throws InterruptedException
{
WebElement button = driver.findElement(By.id("button"));
String Source = driver.getPageSource();
if (Source.contains(button))
{
button.click();
Thread.sleep(3000);
}
else
{
driver.quit;
}
}
Hope this can be helpful. Let me know if you are still facing problem.

Sending mail from Third party sites Programmatically [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I send mail from sites other than gmail, hotmail, rediffmail. Without any API provided. Is there provision to make this happen in any of programming languages. I think the domain I'm going to use does not have any captcha checks.
I also would like to attach a folder within.
If you are asking about other domain names, like your own domain then you can use below method:
Add using System.Net.Mail;
then below in some event
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("mail.yoursite.com");
mail.From = new MailAddress("testing#yoursite.com");
mail.To.Add("youremail#address.com");
mail.Subject = "New Email";
mail.Body = "add text here from controls";
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("testing#yoursite.com", "passhere");
SmtpServer.EnableSsl = false;
SmtpServer.Send(mail);
MessageBox.Show("All Done");

How to start an OpenOffice extension? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to write an extension for OpenOffice.
This extension would be written in java (compiled, I don't want people to see the code).
It should do actions when I start openOffice writer, when I click on a button and when I print.
I've already added the button but I can't find how to link it with the code of what it should do.
I've read the wiki and the DevGuide but I don't find it very clear.
Could you please help me to start understanding how to create an extension (where should I put my code, how to link it with the GUI etc...)?
As an example, follow instructions at https://wiki.openoffice.org/wiki/OpenOffice_NetBeans_Integration#Configuration. Install the Apache OpenOffice API Plugin by going to Tools -> Plugins.
Click on the link that says OpenOffice.org Add-On Project Type to get more instructions. If you haven't yet, download AOO 4.1.2 and the AOO 4.1.2 SDK. (The plugin did not work for me using LibreOffice, but the resulting extension did work in LibreOffice).
After the code is generated according to the instructions, then add this code to the dispatch method of TestAddOn.java:
if ( aURL.Path.compareTo("HelloWorld") == 0 )
{
// add your own code here
com.sun.star.frame.XController xController = m_xFrame.getController();
if (xController != null) {
XModel xModel = (com.sun.star.frame.XModel) xController.getModel();
XTextDocument xTextDocument = (com.sun.star.text.XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xModel);
XText xText = xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString( "Hello World (in Java)" );
return;
}
}
Now compile and deploy the extension. When the "Hello World" toolbar button is clicked, it should put "Hello World (in Java)" in the document.
The code was adapted from https://forum.openoffice.org/en/forum/viewtopic.php?f=47&t=72459.
In order to handle events like when the document is opened, I also tried calling a method of the extension from Basic code like this:
Sub CallJavaMacro
MSPF = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
scriptPro = MSPF.createScriptProvider("")
xScript = scriptPro.getScript("vnd.sun.star.script:" & _
"com.example.testaddon.TestAddOn.PutHello?" & _
"language=Java&location=user:uno_packages/TestAddOn.oxt")
Thing = xScript.Invoke()
End Sub
However the Basic routine said it could not find the method. Maybe I did not declare the method properly or something.

Categories