Lighttpd Mod_Redirect and Mod_Proxy to NAS - webserver

I've setup in my lighttpd config the following:
$HTTP["url"] =~ "^/nas" {
proxy.server = ( "" => ( ( "host" => "192.168.1.10", "port" => "5000" ) ) )
proxy.header = ( "upgrade" => "enable" )
#url.rewrite-once = ("^/nas" => "/")
}
This works as I expect it to, when I go to [webserver]/nas it redirects me to my nas, however the problem is that it keeps the word "nas" in the URL thus causing a 404 since it won't find the login page.
If I uncomment the url.rewrite-once it no longer works because it doesn't have the nas in the url thus not triggering the redirect. Does anyone have any ideas or is this so simple I am missing something silly.

I ended up using subdomains. Worked for me
https://www.cyberciti.biz/faq/linux-unix-setup-adding-subdomain-with-lighttpd-webserver/
Well this didn't actually fix my issue, now it won't work externally since the NAS logs on at port 5000 not 80.

You can use
proxy.header = ("map-urlpath" => ("/nas/" => "/"), "upgrade" => "enable")
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModProxy

Related

laravel4 hybridauth facebook Authentication failed! Facebook returned an invalid user id

OK, I'm trying to use Hybridauth with laravel 4. However I seem to be getting the very common when trying to log in with facebook:
Authentication failed! Facebook returned an invalid user id.
I have read all the other posts, and have had no luck, so just hoping someone may be able to help me.
I followed this tutorial: http://www.mrcasual.com/on/coding/laravel4-package-management-with-composer/
And have tried several other configurations to no success.
Here is my config/hybridauth.php
<?php
return array(
"base_url" => "http://myapp.dev/social/auth/",
"providers" => array (
"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => "****", "secret" => "****" ),
),
),
);
And here is my route:
Route::get('social/{action?}', array("as" => "hybridauth", function($action = "")
{
// check URL segment
if ($action == "auth") {
// process authentication
try {
Hybrid_Endpoint::process();
}
catch (Exception $e) {
// redirect back to http://URL/social/
return Redirect::route('hybridauth');
}
return;
}
try {
// create a HybridAuth object
$socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
// authenticate with Facebook
$provider = $socialAuth->authenticate("Facebook");
// fetch user profile
$userProfile = $provider->getUserProfile();
}
catch(Exception $e) {
// exception codes can be found on HybBridAuth's web site
return $e->getMessage();
}
// access user profile data
echo "Connected with: <b>{$provider->id}</b><br />";
echo "As: <b>{$userProfile->displayName}</b><br />";
echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";
// logout
$provider->logout();
}));
So, when I access "myapp.dev/social" I'm brought to the facebook sign up page everthing seems to work fine, asks me to allow permissions to myadd.dev. After I click OK I am brought to the following URL: http://myapp.ie/social#_=_ where the error is displayed.
Not sure if this is relevant:
Just from observing other sites that in-cooperate a facebook login.. the redirect URL looks something like http://somesite.dev/subdomain/#_=_ . In other words they have a slash before the #=. Is this my problem, how do I fix it?? Very new to hybridauth so any help greatly appreciated thanks.
Oh I do realize that this post is very similar to other posts but I have yet to find a solution.
UPDATE: the exact error: Authentification failed. The user has canceled the authentication or the provider refused the connection.
In base_facebook.php do following
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 50,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.2',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
);
protected $trustForwarded = true;
protected $allowSignedRequest = false;
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
at modules/hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php:128
solved!
For anyone else this is what worked for me: I reset app secret and now works great. No idea why my first app secret key did not work. Spent a ridiculous amount of time trying to fix this error.
Had this error in the past. Solved by modyfying Hybridauth's code myself.
In thirdparty/Facebook/base_facebook.php make sure $CURL_OPTS array uses:
CURLOPT_SSL_VERIFYPEER => false
In my case I was closing session files for performance improvements so I added:
session_start()
inside Storage.php wherever HA::STORE session var is being updated/unset.
Let me know if it helps.
CURLOPT_SSL_VERIFYPEER => false & resetting my app secret key didn't work for me. I was getting this error because of some conflict with privileges I had previously setup. Removing the app from my facebook account did the trick (under privacy settings -> apps).
REMOVE THE TRAILING SLASH !!! (in config/hybridauth.php)
"base_url" => "http://myapp.dev/social/auth/",
should be
"base_url" => "http://myapp.dev/social/auth",
My case was a little bit more specific, but just in case: Be carefull with redirects!
I had an SSL Certificate installed and a redirect to force the user over https, but when I first configured HybridAuth I didn't took this into account. The facebook request was being redirected over to https causing the $_REQUEST data to be lost in the process.
For me the change was, in Hybrid/config.php:
"base_url" => "http://my-site.com/"
to
"base_url" => "https://my-site.com/"
I was having the same issue (although using HybridAuth on Yii) and turns out my app on Facebook was still in Sandbox mode. No source code changes needed on HybridAuth, just needed to turn off Sandbox Mode for the app and suddenly everything worked. Hope this helps.
This happened to me because my SSL is terminated in AWS's load balancer
Just update the config file in your app/config to include the trustForwarded setting
<?php
return array(
'base_url' => 'http://website.com/oauth/auth',
'providers' => array (
'Facebook' => array (
'enabled' => true,
'keys' => array ( 'id' => 'redacted', 'secret' => 'redacted' ),
'trustForwarded' => true,
),
),
);
I had the exact same error message on a wordpress installation using Hybridauth. To find the problem I set up an isolated test with the Facebook PHP SDK (which Hybridauth uses) just to find out that curl_exec was not enabled on my host. Happily, an easy fix.
If you are on apache open you php.ini and delete curl_exec from this line:
disable_functions = curl_exec
Reload your apache configuration and voila :)
Hope this will help somebody.

Can't get rewrite to work correctly for lighttpd + webpy (through fastcgi)

I can't seem to get rewrite to work for lighttpd + fastcgi. I'm running a webpy app which is located at /var/www/training/trainapp.py
/var/www is lighttpd's docroot
My fastcgi config looks as follows:
# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#m$
server.modules += ( "mod_fastcgi" )
server.modules += ( "mod_rewrite" )
fastcgi.server = ( "/trainapp.py" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/var/www/training/trainapp.py",
"max-procs" => 1,
"bin-environment" => (
"REAL_SCRIPT_NAME" => ""
),
"check-local" => "disable"
))
)
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/trainapp.py",
)
When I use the config file above everything works as expected, when I go to http://ipaddress/ the webpy app is opened. However, when I change rewrite line of the config file to:
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/flip/(.*)$" => "/trainapp.py",
)
and go to http://ipaddress/flip/ I get an error that says "not found". It is different from a regular 404 error; lighttpd usually responds with "404 - Not Found" for the http://ipaddress/flip/ I only see a non-formatted "not found" message.
The following pastebin shows the lighttpd log for the two scenarios. I can't find the source of the error from this, it seems as if they are handled both in the same way, however one ends in a 404.
http://pastebin.com/E3qzEAzD
Anyone any idea of what I'm missing here? Thanks.

Using Zend Mail with SMTP Authentication gives an error

I'm trying to create a form that sends an email using SMTP authentication, but I keep receiving an error. I've read a bunch of posts online and this is the code I've come up with so far. Does anyone see anything wrong with the code below? Any help would be greatly appreciated.
Thanks
Bob
$configSMTP = array(
'port' => 587,
'auth' => 'login',
'username' => '***',
'password' => '***'
);
$transport = new Zend_Mail_Transport_Smtp('mail.server.com', $configSMTP);
$mail = new Zend_Mail();
$mail->setReplyTo($config['replyto']);
$mail->setBodyText($message);
$mail->setFrom($params[$config['emailID']], $params[$config['nameID']]);
$mail->addTo($config['sendto']);
$mail->setSubject($config['subject']);
try {
$mail->send($transport);
} catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('There was an error submitting your request.');
}
Mandril's SMTP uses TLS.
http://help.mandrill.com/entries/21738477-What-SMTP-ports-can-I-use-
Enable it in your config array.
$configSMTP = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => '***',
'password' => '***'
);
Would direct you maybe to section on resource plugins form Zend Mail. Give a better list of the options and shows how to assign them through your app.ini file.
That said, assuming your arguments are valid that looks fine.
What exception are you catching? You must be getting an error message. Can you telnet from this machine to your mail server? Want to eliminate network/auth issues.
It's hard to say without knowing what exception you're getting.
There might be several reasons, can you connect to the SMTP-server.. Is the port 587 really open? Do you have a firewall, and if so, might it be blocking the connection to that port? Are you really sure those credentials are valid? Have you tried manually connecting to the SMTP-server?
If not, see how you can do it with Telnet: How to test an SMTP server using Telnet
You could also try using a transactional email service. That way you wouldn't need to manage an SMTP-server or even think about deliverability, etc. You would just outsource it to someone else.
There are various providers, some of them are:
AlphaMail
Mandrill
PostageApp
If you're using AlphaMail, you could just use the AlphaMail PHP-client and send your emails like the example below:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // You AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from#example.com"))
->setReceiver(new EmailContact("Joe Doe", "to#example.org"))
->setBodyObject($person) // Any serializable object
);
The templates are constructed in the AlphaMail Dashboard using the Comlang templating language. This means that you can easily edit your emails at any time, without having to dig through code. Templates in Comlang look something like:
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
Sign Up Free!
<# } else { #>
Sign In
<# } #>
</body>
</html>

Lighttpd single subdomain Redirect/rewrite

I am using lighttpd, and I would like to redirect a subdomain to a regular url, but keep the subdomain showing in the browser.
For example, if I have the following url: http://blog.test.com/...
and I would like to redirect it to: http://test.com/blog/...
but still show blog.test.com/... as the URL in the browser.
What is the best way to go about doing this?
You need proxy-core.rewrite-request with something like that:
$HTTP["host"] =~ "blog.test.com" {
proxy-core.rewrite-request = (
"_uri" => ( ".*" => "/blog/$1" ),
"Host" => ( ".*" => "test.com" ),
)
}
Jump to the proxy-core.rewrite-request part of the doc.

SOAP web services over HTTPS is not working

I am currently working in sugarcrm which has url in https. Soap is not working on https url, my code is running perfectly in http url . What are the changes that requires to run the same code in https mode?
i use this code. username, password and url is only for example for you people.
<?php
require_once('nusoap.php');
$client = new soapclient('https://www.sugarcrm.com/soap.php?wsdl',true);
$auth_array = array(
'user_auth' => array(
'user_name' => 'abc',
'password' => md5('abc'),
)
);
$login_results = $client->call('login',$auth_array);
echo $session_id = $login_results['id'];
$user_guid = $client->call('get_user_id',$session_id);
printf("\n".$auth_array['user_auth']['user_name'].' has a GUID of ' . $user_guid . "\n\n");
?>
Make sure the $sugar_config site_url setting properly reflects the https URL. You can change this in the config.php file in the root of your SugarCRM install.