How to replace JS file with mitmproxy/mitmdump - mitmproxy

I am trying to use mitmdump to replace a JS file being requested by the server with my own JS file. I am not able to find anything in the docs regarding this, especially for the version that I'm using, i.e., 4.0.4.
What I tried was - mitmdump --listen-port 8888 --replacements :~q:https://static.examimg.com/repojs/jpAllJsFuncs_v128.js:/home/akshansh/Projects/repo/web/js/jpAllJsFuncs_v129.js
(Here I wanted to replace https://static.examimg.com/repojs/jpAllJsFuncs_v128.js file with /home/akshansh/Projects/repo/web/js/jpAllJsFuncs_v129.js which is present on my local machine.)
The above didn't seem to work. Also, the separator according to documents is : and I have : in the part I want to replace as well, how will I go around it? I wasn't able to find much in the docs. --replace-from-file is another option, which is now deprecated in the newer versions, for which I was not able to find the docs.
Thanks.

I use script that is launched together with mitmproxy:
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
if flow.request.url == 'https://static.examimg.com/repojs/jpAllJsFuncs_v128.js':
flow.request.url = '/home/akshansh/Projects/repo/web/js/jpAllJsFuncs_v129.js'

Related

IBM Aspera get size of file before download

I am using Aspera Connect on mac to download files from a server. It works fine in terminal, but i was wondering if before i download a file, i could read its size first and then decide if i want to download it or not. I found the flag
'--precalculate-job-size'
but it's only doing that right before download and there's no way to stop the download.
The current command i use is this:
/Applications/Aspera\ Connect.app/Contents/Resources/./ascp -QT -l 200M -P33001 -i "/Applications/Aspera Connect.app/Contents/Resources/asperaweb_id_dsa.openssh" emp_ext3#fasp.ebi.ac.uk:/{asp_path} {local_path}
The resources for the flags are here:
https://download.asperasoft.com/download/docs/ascp/2.7/html/index.html
To answer your question, without going too much in the details:
If you want to display the size of an elements on an Aspera server for which you have access, you can use the command line "Amelia", see:
https://www.rubydoc.info/gems/asperalm
mlia server --url=ssh://fasp.ebi.ac.uk:33001 --username=emp_ext3 --ssh-keys=~/.aspera/mlia/aspera_bypass_dsa.pem br /10002/data/100_movie_gc.mrcs
there are plenty of options, like : --format=csv --fields=size
Note that this displays individual file sizes, but not recursive folder size.
a few other things:
You are not exactly using "Connect", but rather the "ascp" command line. Connect refers rather to the browser extension and lightweight app. while ascp is the implementation of Aspera FASP transfer protocol, found basically in all Aspera products.
the latest ascp documentation can be found here: https://www.ibm.com/support/knowledgecenter/SSL85S_3.9.6/hsts_admin_linux/dita/hsts_admin_linux_ascp_usage.html
did you know you can also use the free client:
https://downloads.asperasoft.com/en/downloads/2
it includes also ascp, but also a graphical user interface

Error 403 with Ckan 2.6.2 - Datapush

I have, in order to process some big data, to set up ckan on a local machine. I've set up the whole system following this guide : http://docs.ckan.org/en/latest/maintaining/installing/install-from-source.html
I wanted to display a preview of a locally loaded file, so the user can actually see it before downloading it. And it doesn't work, because it only works for online files. For instance, it DOES work with this online file but NOT with my own file I upload.
So, I've been interested about Datastore and Datapusher. I've followed every part of the guide, and it appears on my ckan. However, I have an error. Specifically this one :
Upload error: An Error occurred while sending the job: 403 Client Error: Forbidden for url: http://127.0.0.1:8800/job
Here's my most important parts about my production.ini file (copying the whole would be very long) :
ckan.site_url = http://localhost
ckan.plugins = datastore datapusher stats text_view image_view
recline_view recline_graph_view recline_map_view webpage_view
ckan.datapusher.formats = csv xls xlsx tsv application/csv
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
ckan.datapusher.url = http://127.0.0.1:8800/
I truly have no idea about what my problem could be, I tried to change the datapusher.url to 0.0.0.0 as the guide suggested, but it doesn't work either.
If the data to be added to CKAN is in a file on your computer, select “Upload a file” option. CKAN will give you a file browser to select it. You should use link to a file option just for publicly available resources.
Have you installed datapusher also? Its a separate process running on port 8800. CKAN uses datastore to be able to have a grid view of tabular data. Data needs to be pushed through datapusher to be used by datastore.
Yes, you need to set up the Datapusher.It's not activated by default.
Pull the datapusher code, install the dependencies and run it using:
python datapusher/main.py deployment/settings.py
The instructions to configure the settings are on the repository.
Here's the datapusher manual: http://docs.ckan.org/projects/datapusher/en/latest/
Here's the repository: https://github.com/ckan/datapusher
Had the exact same error message.
This post solved my issue though.
short: insert/check the following in your virtualhost in /etc/apache2/sites-enabled/datapusher.conf
<Directory /etc/ckan>
Options All
AllowOverride All
Require all granted
</Directory>

How does one access the configuration from inside a IPython 3.x / Jupyter Notebook?

In particular I would like to know the base_url of the Notebook Server that the code is running in.
In IPython Notebooks version 2.x I used to do the following:
config = get_ipython().config
print config['NotebookApp']['base_url']
However this no longer works in IPython Notebook 3.x / Jupyter Notebooks.
EDIT: Some more detail on what I am trying to achieve.
I run various IPython Servers in separate Docker containers on the same host which are accessed through different base_urls. I would like to use the quantopian/qgrid package to display Pandas DataFrames inside the Notebook. Initially qgrid did not handle custom base_url prefixes for serving up a local copy of the Javascript dependencies but the code above allowed me to find the base_url in IPython 2 and to inject the relevant base_url into the Javascript template.
I would also like to use the mpld3 library in the Notebook and when browsing their documentation I found that they also mention that in "IPython 2.0+, local=True may fail if a url prefix is added (e.g. by setting NotebookApp.base_url)" so it seems that this is not an isolated problem and a good solution would be worthwhile.
Given #matt's comment below and thinking more about kernel vs frontend split, it makes sense that the NotebookApp config isn't accessible from the kernel. It's really the JS code that's generated that needs to know what the base_url is, so if someone can point me to where I can access this in the Notebook JS API, that should solve it.
From the frontend side, if you publish javasscript, and assuming you are in a notebook (keep in mind that being in JS does not necessary mean notebook, you could be Atom-Hydrogen, or Jupyter-Sidecar) you can use a snipet like:
require(['base/js/utils'], function(utils){
var base_url = utils.get_body_data('base-url')
})
The data-base-url attribute is set on the <body> tag of the notebook.
It is though not guarantied to stay this way. Usually, extension should be installed in the nbextensions folder, which should automatically resolve correctly:
require.config({
...
paths: {
nbextensions : '<base url>/nbextensions',
kernelspecs : '<base url>/kernelspecs',
...
})
Nbextension is a search path, so if set correctly on the server, you shouldn't (most of the time) have to serve things yourself at custom URLs, nor to handle base_url yourself on frontend side.
After quite a lot of digging into IPython internals I found something that works for me:
from IPython.config.loader import load_pyconfig_files
config = get_ipython().config
profiledir = config['ProfileDir']['location']
nbconfig = load_pyconfig_files(['ipython_notebook_config.py'], profiledir)
print nbconfig['NotebookApp']['base_url']
EDIT: This works on my installation but I understand now that the kernel is not really the right place to get this info. I'll probably delete this answer once some better answers are up.

Write a simple mod_perl handler

I want to write a simple mod_perl handler which returns the local time like described on this page (http://perl.apache.org/docs/2.0/user/handlers/intro.html), but where have I to locate this file to access it.
I'm using Ubuntu but don't have a directory called MyApache2. So where to locate this file to try the functionality?
This is just an example. You need to create the files yourself. (You'll see your example refers to "file:MyApache2/CurrentTime.pm").
mkdir -p example-lib/MyApache2
touch example-lib/MyApache2/CurrentTime.pm
Then paste the contents from the example into the file you just created.
In order for this to run under mod_perl, you'll also have to let the server know where your MyApache2 is located. You should be able to add something like this to your Apache config:
PerlSwitches -I/path/to/example-lib
Don't forget to restart Apache before you test this out.

Setting moodle online

Good day everyone, I have been trying to put my moodle online so pcs from internet can access it, but until now, no luck at all. (Im using moodle 2.3.2 on Windows Server 2008 and IIS 7).
I tried to configure the moodle file config.php, setting the directive $CFG -> wwwroot = "my-public-ip/moodle". Then, when I access to moodel from the server, I can access it by "http://my-public-ip/moodle", when I try to access via localhost, it sends an error which it is OK.
But the funny part comes when I try to access the server from an outside pc. When I type "http://my-public-ip/moodle" it simply cant "see" the configuration I made to the config.php file (it says: This server cna only be accessed via localhost/moodle) it looks like the outside pcs are either ignoring it, or searching for another configuration file. I dont know what the hell is happening, this is very odd.
Any ideas?? tnx!!!
Change the following file:
lib-->setuplib.php
Redirect ($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
for
Redirect ($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 0);
I realise this is an old question, but it's also worth pointing out you may need to also run the database search and replace script, at:
http://my-public-ip/moodle/admin/tool/replace/index.php
as referenced in Method 2 here.
This is required if you change the name of the site once you have installed it. If you were already using Moodle under "localhost", then there will be a number of references to the old localhost address stored in the database that need to be updated to the new IP-based address.
It might be because the http:// part is missing?
$CFG->wwwroot = "my-public-ip/moodle"
should be
$CFG->wwwroot = "http://my-public-ip/moodle"