python mechanicalsoup redirection issue - redirect

guys, actually I have a problem in my code and the redirection feature in my router, after I wrote the code which able to find the form and login into the router I faced a problem that after the login using the login.cgi the router redirects the link into something like http://192.168.1.2/index.asp;session_id=2dfa2490ad2e26a3d073edfdae7d0f45
what I could understand that it shows the session id in the link and I need help to make my code understands and gets the link I tried many times using
browser.get_url() but it shows http://192.168.1.2/login.cgi
thank you guys
def wifi_pass_changer():
username = 'admin'
password = 'admin'
url = "http://192.168.1.2/"
browser = mechanicalsoup.StatefulBrowser()
browser.open(url)
browser.select_form('form[action="login.cgi"]')
browser["http_username"] = username
browser["http_passwd"] = password
response = browser.submit_selected()

Related

Password URL link getting truncated

I send out Password reset links that are of the following format
https://example.com/login?email=123#456.com&tmpPas=qwertyuiopasdfghjkl
Some small percent of users are reporting that when they click the link the email and password parameters are not carried over to the website.
So far they have reported this issue on IE11 and Safari on Ipad. What could be causing this and what are the possible solutions to reduce the occurence.
I have been able to reproduce this on an Ipad mini each time. Even if i paste the URL in the browser it does trigger the reset flow. While from any other device it does work.
in the console logs i see this
SCRIPT5009: 'URLSearchParams' is not defined
Here is the relevant code
let url = new URL(window.location.href);
let searchParams = new URLSearchParams(url.search);
let emailAddress = (searchParams.get('email'));
let tempPass = (searchParams.get('tmpPass'));
Found that the URLSearchParams is not supported on all browsers. Found this code in this answer that did it https://stackoverflow.com/a/20097994

EWS from WebSite using user credentials and windows authentication for intranet

I am trying to understand how I should configure a web site (ASP.Net) that need to pass the user credential and get some mail things
I get different kind of errors depending on the app pool configure,
What is the complete way to do it? I mean code + Configuration ;o)
I don't want to write the user and password but get them through the windows authentication
Thanks
code:
Service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
Url =
new Uri(
"https://xxx/yyy.asmx"),
//UseDefaultCredentials = true doesnt help
};
var view = new ItemView(1820);
// Find the first email message in the Inbox that has attachments. This results
FindItemsResults<Item> results = Service.FindItems(folderName, view);
//Here I get the error 401
Take a look at Get started with EWS Managed API client applications, it covers the basics to get you up and rolling. Note that when you use UseDefaultCredentials, you have to be on a domain joined machine, with the user logged in, and you must be targeting an on-prem server. We tested that scenario out and the following code works in that scenario.
using System;
using Microsoft.Exchange.WebServices.Data;
namespace HelloWorld
{
class Program
{
static void Main()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.UseDefaultCredentials = true;
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
//Replace the URL below with your own, but using AutoDiscover is recommended instead
service.Url = new Uri("https://computer.domain.contoso.com/EWS/Exchange.asmx");
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox,
new ItemView(1));
}
}
}
If that doesn't work for you, then you might want to try using impersonation. See this thread, where I think they've got a similar situation . More information about impersonation is on MSDN: Impersonation and EWS in Exchange.

how can I test my facebook page tab app from localhost

I'm developing a facebook page tab app. When I set page tab URL in app settings to something like localhost/fbapp, it doesn't work since the page tab is not simply iframe. Is there any workaround to resolve this?
EDIT
I'm building facebook page tab with ASP.NET MVC-3.0 with fb C# SDK.
What I've tried so far is to modify hosts file to point the URL I have on app settings to localhost(127.0.0.1). I've been testing facebook app in this way always but it doesn't work in facebook page tab.
In Application setting in page tab url set
http://localhost/yourpagetabdir/
I am using this setting for my page application test frmlocalhost its works fine from my ASP.Net Development server if you are using IIS server make sure your IIS server allow page in iframe.
after this if u want to get page-signed request
Facebook.FacebookConfigurationSection s = new FacebookConfigurationSection();
s.AppId = "AppID";
s.AppSecret = "Secret";
FacebookWebContext wc = new FacebookWebContext(s);
dynamic da = wc.SignedRequest.Data;
dynamic page = da.page;
string curpageid = page.id;
bool isLiked = page.liked;
bool isAdmin = page.admin;
Try editing your hosts file so that when you go to http://example.com it links to your http://localhost/yourapp
Here's how to do it:
Windows: http://www.trailheadinteractive.com/creating_multiple_virtual_sites_a_single_apache_install_windows_xp (your localhost URL should have a valid website format: 127.0.0.1 dummydomainname.tld)
MacOS: http://danilo.ariadoss.com/how-to-setup-virtual-hosts-mamp-environment/ (again, make sure you have a valid website format)
Linux: You probably know how to do this already :)
This should work as then the iframe would point to a valid URL, which on your local machine would point to your content. Note that this won't work if you access the tab from other computers since for them the URL would point to something else (or nothing, depending on what domain name you choose).
Using FB PHP SDK for example, you can post the signed_request and parse it with a few lines:-
require_once ("facebook.php"); // this file comes from the SDK
$config = array();
$config['appId'] = 'get_appID_from_app_menu';
$config['secret'] = 'get_secret_below_appID';
$facebook = new Facebook($config);
$signed_request = $facebook->getSignedRequest();
print_r($signed_request);
Avoid that lenghty example given in FB's blog. Good luck coding :)
I figured out the issue with facebook page tab. It seems that they don't accept http on page tab even I have sandbox mode enabled. All I have to do is set up IIS to work with https and run the app over the ssl. It is now working perfectly. Thank you guys for all help

Zend: Redirect to page after log in with a URL from email

I am using Zend and I have an email sent to all members which contains a link to a Post. Only members logged in can comment but all guest can see it. Of course whoever is clicking on the link in the email should be able to comment straight away.
For this reason what I would like to find out is a way to check if a member clicking on the link is logged in or not:-
if already logged in the URL in the email should take the member to the Post directly.
if not logged in forward the member to the log in page and then to the proper URL containined in the link.
I hope I explained myself. Please ask me if not. Could someone please advise the best way to do it?
Thank you. F.
Create a plugin and save the requested Uri in the session using:
$this->_session->lastUrl = $this->getRequest()->getRequestUri();
Then, after the user enters his credentials, redirect him to this saved URL.
Another option would be to save the url and add it as parameter to the next requests, like Google, Yahoo and SO do.
public function emailAction()
{
$loggedIn = Zend_Auth::getInstance()->getIdentity();
if($loggedIn)
{
$this->_helper->_forward('post);
}else {
$this->_helper->_forward('login');
}
}
public function loginAction()
{
$success = new Zend_Session_Namespace('success');
if(!isset($success->url))
{
$success->url = $this->view->serverUrl(true);
}
$form = new Login_Form();
if($this->getRequest()->isPost() && $form->isValid($_POST))
{
$this->_redirect($success->url);
}
}

agsXMPP OnAuthError on different id

hi i am connecting to facebook using the following code it work fine for my two account one is gmail and another one is yahoo but it is only working on that accounts not log in on the other accounts of the gmail,yahoo,hotmail i check every acccount that i have every time onautherror come why ? what i am doing wrong is my code is wrong can any one tell me plz
Jid jidUser = new Jid(txtBoxUserName.Text);
xmppCon.ConnectServer = jidUser.Server;
xmppCon.Username = jidUser.User;
xmppCon.Server = "chat.facebook.com";
xmppCon.Port = 5222;
xmppCon.Password = txtBoxPassword.Text;
xmppCon.AutoResolveConnectServer = true;
xmppCon.Open();
Facebook doesn't allow the username/password XMPP authentication anymore.
You can only login using the X_FACEBOOK_PLATFORM SASL mechanism.
See:
http://developers.facebook.com/blog/post/2011/09/09/platform-updates--operation-developer-love/
So for Facebook use X_FACEBOOK_PLATFORM SASL auth in agsXMPP and it will work fine.