Angular: hide JSON data from user - javascript

My Angular application loads JSON files as search material using $http
$http.get('my.json').success(function(data){ ... };
Unfortunately, this method loads the JSON file in to the browser and allows the user to see it's content.
Screenshot from Safari
I'd like to hide that file from the user.
To refine my question. I know that I won't be able to totally hide that data from the user.
A user can easily write a script to scrape the data off my site.
I just don't want to hand those files to the user so easily, to just let them sit there for him to just copy and paste.

Everything you sent to client is anyhow visible by client. There is no way to absolutely hide it from him.
All you can do is .zip or encode data on server and unzip or decode it on client. But even in this case all decoding mechanisms will be available to user and if he wishes and has some skills, he can decode it and access all data you send him.
UPD:
Ok, you want to uglify your data so client couldn't see it simple way.
You need to somehow encode data on server, send it encoded to the client, and decode on client so you could use it.
Checkout lz-string - it's js library that can archive / unarchive json strings, converting them to binary format, so data becomes unreadable. And it's pretty fast (I haven't noticed any delays encoding/decoding 2Mb strings - I use it to compress data and store it in localStorage).
It's as easy as LZString.compress(JSON.stringify(data)) to compress json and JSON.parse(LZString.decompress(data)) to decompress.
Only thing you need in addition - to find a server-side library that uses exactly this format. If you use NodeJS at your server, you can take lz-string itself. Otherwise, quick googling gave me solution for php - I think it's pretty possible to find solutions for other languages..

If you want the user to see only parts of the document, you should filter it on the server.
Create some kind of service/Api-function/etc. which loads the document and pass it the user information via ajax request. Now filter it depending on this user information and return the filtered data.

Related

How to send data from backend to front end securely

So I am trying to find a way to send data from the back end to the front end securely.
My application is about posting images, and each post has a name, id, comments, etc..
The problem is that I want to prerender all my posts using pug, but also send all the data of those posts securely to the front end. I know that you can send data using the dataset attributes, but I don't want a client to see this data - I want it to be secure.
I just want to know if this is even possible, and if there is a secure way to implement this
E.g. Server sends data of 50 posts. Those 50 posts can be accessed in a front end js file, but cannot be accessed through the console in inspect element, or any other way.
Once the data hits the browser (e.g. front-end) it is available to the user. You can see the data in the Network tab of the dev tools in Chrome. I am not to sure what you mean by securing it in the front-end. It seems like you are trying to override browser functionality which is not possible. You can use javascript to a certain extend to stop people from getting the context menu on images etc, however, if a users looks hard enough it is easy to get the data that has been loaded.

Difficulty figuring out an app/webpage to webpage interaction

Context:
The page I'm making should take in graph data from a JSON format from an outside application/webpage. Queries to Parse.com will gather the initial data, so I can avoid setting up the graph page with a connection to the Parse database.
A webpage OR android application currently submits a request to the Parse system and get back a response formatted in JSON, then it must send that information to a webpage with graphing JavaScript for it to read and build the graph from.
I've explored the possibility of sessions or cookies, but it doesn't seem compatible with the android application end (unless webview can do something?). GET looked like a good alternative originally but the size of some URI query strings would easily be too large. POST, upon review, is impossible for me to use in this case.
Question:
Is there still another way to send this information without AJAX, PHP or some other server-side code? Or would i need to scrap the idea as it stands, and just implement it all on the graph page anyway?

How to gather information from a URL and decode it in another application

I'm looking to create a web based tool that will allow me to pull information from a website via URL and decode this content in a more usable fashion.
Here is the situation: The company I work for has log files any time there is an error in the code. The error's are then searchable in a back end application but contain raw data and is fairly time consuming to find the useful information. Those logs are then accessible with a static link.
I'm pretty sure I can figure out the decoding process, however I am struggling with how to get the content I need to decode.
The content I am looking to decode is not on the same domain but are within my companies network.
Any help would be greatly appreciated
If it's not on your domaine you can't request the link using javascript, so you need to do it in the backend with curl or other HTTP clients.

I need to generate a JSON file in browser using (currently) javascript

I have a website that allows users to select a date range from a data set. At least, that's the goal.
What I would like to have happen: the user selects a date range, presses the submit button, and a script generates a JSON file which MATLAB reads to generate the graphs.
Any thoughts on resources to help accomplish this?
You'll need the script that fires off to be server side. JavaScript is client side and can not, in any way, access, modify, or otherwise create files on the client. You'll have to use a language like PHP to create the file.
Example using PHP:
Once the file is created, force a request on the client side to fire asking for the file. Set the PHP header to Content-Disposition: attachment; filename="< Place file name here>".
This will prompt the browser to launch a download prompt allowing the user to download the file.
Hope this helps.
You can use Downloadify, a small Flash component with a Javascript interface that allows you to create files on the client that a user can download. That's what I used in a similar situation.
You could also try and use Data URI but they are a quite limited and browser specific so some issues may arise.
These may be alternative solutions to the previous answer that suggested using server side code to generate the file.

MS Word Object Model via Javascript: Mail Merge

I am building a website application for a local charity, it is going well, I seem to overcome most challenges, but this is a huge problem I have, and I don't even know if it is possible.
I want the user to be able to click a button and output a Microsoft Word file by mail merging a text file and a prebuilt template (dotx) file, both on the server side.
The text file will only contain one record that has been taken from an mySQL database and generated via PHP.
I know about using XSLT to modify the document file inside the document zip, but I do not have access to the php.ini on the charities server, and anyway it seems a little bit too much considering how simple it is to use create a Macro to Mail Merge.
So I am now thinking of using the Word Object Model, it would have to be via Javascript, but most of the users use either Firefox or Chrome, so would for eg. var oApplication = new ActiveXObject("Application.Word"); work with those browsers, or could I use simply = new Object("Application.Word");?
Also can I confirm that the object in Javascript would then have the same function names and parameters as those in VBA, I have never tried using Word via Javascript, but if it's the same as VBA, then I should be fine.
I am using my localhost for development and the file structure is:
template\conformation.docx
template\data.txt
Where data.txt is the PHP generated CSV of the data taken from the database.
ActiveX/COM automation (which is required to access word.application) is supported in IE only, no other browser supports it in any way.
If it were supported you would still not be able to easily interact with the Word files on the server from within the client.
You could generate the file on the server ( Generating word documents with PHP ) although to access functionality that's actually built into Word itself (like a mail merge) you would need to programmatically interact with a real instance of Word that's been installed on the server (using PHP/COM/word.application) to control it, to avoid this, you would do whatever the mail merge does, manually.
Another alternative would be to have a Word document that contained VBA code that interacted with a PHP web service to generate the output document.
Is a web-service an option for your application? If so, have a look at Docmosis - you can upload doc templates then send requests with data to do the mail merge outputting the result with various options including MS word.

Categories