how to hide unnecessary html tags in perl cgi when running from command line? - perl

I'm using perl version 5.18. I don't have a provision to upgrade perl to a newer version. When I pass the CGI query parameters from the command line, the script runs and works perfectly but it shows unnecessary HTML tags and other things (<!DOCTYPE html PUBLIC...), which I want to hide from terminals. Those are necessary to execute the script from a browser. So, without affecting the functionality of cgi when it runs from the browser, is there any easy way to get only necessary outputs when running from command line/ terminal?

The best approach here is to separate the data extraction from the presentation of the extracted data.
I would move the data extraction code into a module. You can then call that module from your CGI program and then wrap it in the appropriate layer of HTML.
You can then write a command-line version of your program that uses the same module to extract the correct data but which then wraps it in whatever text you want to use to display the data on the console.
Adding unwanted presentation layers (like your current HTML) is never a good idea. Best to rewrite from scratch to give what you want.
(If you're in a real rush though, there's one other approach that I might consider. Write a screen-scraper that scrapes your HTML page and extracts the data from that.)

Related

Powershell import encoded module

I am writing a script with a lot of modules but I don't really want the user to see my source code so I figured to encode everything in base64 since the user won't be able to decode it even if it is that basic.
I tried to somehow add an encoded module but no luck.
So my question is -
Is it possible to import a base64 encoded module to the main script file?
If you have any better solutions to hide source code please share, I would be more than happy to try them out.
P.S. I tried to find some info on making a .dll files but found out I would have to rewrite the script in C#. (if I didn't missed anything)
Also I tried to put all modules into one encoded file, but then the file gets too big and Powershell is not able to process it anymore.
You've got two options, which can be combined if you would like to be extremely sure that no one will be able to access your code, making your code into an exe was already mentioned, there are several projects to do this but This one is nice as it is wholly contained within PS. The other, imo better, method is to use an obfuscator, which will take your code and replace variable names with nonsense strings and make other changes to make your code very difficult to read, it's still possible to work out your code but generally not worth the effort, you can find a working one Here. But I do have to add that obfuscating your code really goes against the powershell ethos and I recommend against doing it unless you have some sort of requirement too being passed down from management. And please note that this NOT an acceptable method of obscuring code that includes passwords, api keys, or any other information that needs to be secured as all of those are quite easy to extract from code that has been obfuscated this way.
You could change your ps1 to an exe file by using
https://ps2exe.codeplex.com/
You'd still be able to get at the code if you tried, but it would prevent a casual look.
Why do you want to hide the modules?

How to include CGI script inside HTML document?

I have to include my CGI script login.pl inside an HTML document index.html. I googled for answers and was surprised to find out that it was hard to get a definitive answer to this question. Some suggest using server side includes, but as far as I understand those are used for putting HTML inside of CGI, which is not what I want. I know that in JSP and PHP one can use tags like <% %> and php tags to include code inside of HTML document. Is there a similar construct for CGI? P.S. I am using CGI.pm framework and want to run output of login.pl inside of index.html.
What you are looking for is HTML::Template or Template::Toolkit. Either of these will allow you to put tags in your HTML file and your CGI script can populate the data.
Note that you will be posting to or getting from the CGI script which will read the HTML file, populate it and then send built HTML file to the client. The client's browser would not be accessing the HTML file directly.
In your case, the client's browser will post to login.pl and then, on the server, the perl script will run and build the HTML file and serve it to the client.
It's not possible. CGI is a method for invoking scripts or programs on the server.
See https://en.wikipedia.org/wiki/Common_Gateway_Interface
PHP, ASP and JSP as special documents which are parsed by an interpreter on the server side which then executes the included code. HTML documents cannot be executed, thus, it's not possible.
However, you could make use of Server Side Includes (SSI, https://en.wikipedia.org/wiki/Server_Side_Includes) and include/call CGI programs from there - it's however, less powerful than PHP, JSP and ASP).

Building an automated script to copy a page of text, translate it in Google Translator and paste it in Word

So, as the title says, I would like to make an automated script that is going to take all the text from one PDF page, copy it, paste it into Google Translate and then copy the translated text into another Microsoft Word document.
Since that PDF has a lot of pages (150+), I thought it may be easier to make an automated script to do that.
What language would I have to use, would it be complicated for me to do it and in the end, will I actually save time by using this script (implying that I have to learn it first, but I have some programming experience (I know C++, Javascript, PHP), but I do not have a strong grasp of algorithms (like Flood Fill, ...))?
Thanks in advance!
EDIT : I found that I could use AutoIt for scripting... but I don't know would I be better off using AutoIt or Powershell... I also want to learn something that would be enable me to create other scripts (for example to automate some processes I do in Camtasia Studio)... So, AutoIt or Powershell?
As an AutoIt user I would say AutoIt.
Copying text out of PDFs is not quite as simple as you might imagine. Mileage will vary on how the PDF was created, and there are several methods you can use:
Most PDFs will have most of the text in the file itself, allowing you to get the text using a simple method like this
This method uses zlib to do something to the pdf. Not sure what as I've never tried it.
There are a variety of examples of using third party programs to do this, which may be better. There is one using Debenu and another using XPDF
Automating other programs such as acrobat should be possible, in acrobats case they have an api that can be used, though I'm not aware of this already being wrapped in AutoIt.
As to the rest of the requirements, there is a UDF to translate with google translate here, and the word UDF is a standard one that comes with the AutoIt installation.

store files to filepicker.io from the command line?

I have a bunch of files, I'd like to push them all to filepicker and use various convert options to manipulate them.
How do I automate this process? Is there a way to do this outside of javascript with a traditional scripting language I can run from the command line?
The way to do this is as a POST to /api/store/S3 with the contents of the file. For instance
curl -F fileUpload=#test.html 'https://www.filepicker.io/api/store/S3?key={{apikey}}&filename=myCoolFile.html'
There are other tools that perform similar actions, such as https://github.com/uams/geturl, but the mechanism they use (posting to /api/path/storage) is out of date.
Overall, you can use this functionality, but the urls may change. We're fairly happy with the /api/store/[provider] syntax, but may change before release

Launching a GWT module when clicking on an XML

Greetings,
I'm looking for a way to launch a GWT module when a user clicks on an XML file and have the module consume the xml data. Ideally I would like to render the XML in a rich manner and would prefer to use GWT controls instead of having to lay it out by hand via xslt + javascript.
I'm supposing one way would be to point the xml to a well known xslt that creates a simple html page that forces a redirect to the gwt module but how would I transfer the xml data to said module to allow for enhanced formatting?
Another way would be to have the process that produces the xml also include the bootstrap gwt module but it would be creating multiple bootstrap instances over time and pollute the user's directory.
The use case is that a user would run this app on their local machine which outputs an XML file. If they try and view the xml file in a browser, I'd like to have the GWT module take over and present the data accordingly. I would rather they not have to go to a page and upload the data manually.
Appreciate any ideas on the matter.
TIA
If it's something that runs on the user's machine, I would recommend to ship an executable, or generate a parallel HTML file to present the data. JavaScript run from file:/// will not be able to acces the filesystem.