Using the Synology "login" for a custom website

Anything regarding SSL/SSH and other security questions may go here
Forum rules
Please note the disclaimer before modifying your Synology Product.

Using the Synology "login" for a custom website

Postby OgeGOon » Sat Mar 21, 2009 4:59 pm

Hi,

I am unsure about the section where I must post my question... it's related to security, but not to SSL, etc...

I have enabled the Web Station of my DS209+ and made some web pages (php) that I want now to secure.
I would like to use the native login administration of Synology. So I took a look at the Web Manager login and
found how to reused the "webman/modules/login.cgi" from my own login page.

I have now to put some code in all my other pages in order to check that the login has been done and, if it is not, to redirect to the login page.
Unfortunately, I don't find what I can check to detect if the login is done or not :/
It seems that there is not php pages but only cgi for the Synology web manager, so I don't find how Synology does this check.

Does anyone know the solution ? Or is there any (unofficial) documentation that I could read ?

Thanks a lot in advance for any tip.

O.
User avatar
OgeGOon
Novice
Novice
 
Posts: 47
Joined: Sat Mar 14, 2009 11:41 pm

Re: Using the Synology "login" for a custom website

Postby kiwicam » Sun Mar 22, 2009 12:35 am

Unfortunately, I don’t have a solution. However, I would be very interested to read more detail (including the code) of what you have done.
DS-1010+ / DSM 4.2-3202 / 5 x Hitachi HDS722020ALA330
DS-207+ / DSM 3.1-1636 / 2 x Hitachi HDS722020ALA330
User avatar
kiwicam
Versed
Versed
 
Posts: 243
Joined: Wed Sep 10, 2008 10:56 pm

Re: Using the Synology "login" for a custom website

Postby OgeGOon » Sun Mar 22, 2009 9:21 pm

Here is a HTML login page that can be used on the Synology (DS2009+ at least): http://www.4shared.com/file/94374688/c3a3fa2c/index.html (it's a zipped file)

In this page, the port of the synology web admin interface is hardcoded (=5000)
It also redirects successful logins to a "MyWelcomePage.html"

In order to make this page more dynamic (ex.: regarding the port), you can easily use some php scripts.

This page uses the login of the File Station module. Use the 'guest' account, an existing custom account or the 'admin' account to test it.
You well see you get error message if guest is disabled or if you enter a wrong password.
So my understanding is that it works and that I should be able to reuse it to protect my own pages.

As soon as I have some free time, I will investigate the session variables, php variables, etc, etc... (I am not at all an expert in web and php)
I could possibly find in there a value that can be used as a flag (user authenticated or not) ?!

O.
User avatar
OgeGOon
Novice
Novice
 
Posts: 47
Joined: Sat Mar 14, 2009 11:41 pm

Re: Using the Synology "login" for a custom website

Postby OgeGOon » Sun Mar 22, 2009 10:17 pm

Notice: currently, the login page only works with IE due to the hostname passed in the url parameter of :

> ajax_req.open("POST", url, true);

The url is "http://MySynologyServer:5000/webman/modules/login.cgi".

Notice: The login page of the Synology does not need to use a hostname but only "/webman/modules/login.cgi"...

It does not run with FireFox and Chrome because the XMLHttpRequest object assume that a different port is a different domain and it prevents cross-domain post for security reasons.
This is the first time I prefer the Microsoft implementation :o)

O.
User avatar
OgeGOon
Novice
Novice
 
Posts: 47
Joined: Sat Mar 14, 2009 11:41 pm

Re: Using the Synology "login" for a custom website

Postby OgeGOon » Sun Mar 22, 2009 11:59 pm

Here is a login page that will run also within FireFox and Chome: http://www.4shared.com/file/94394477/6830917d/test.html (a zip file)

I am not posting onto the Synology login cgi from a php page, via a socket... No security issue anymore :p
Simply change the administration port in the login.php page accordingly to your own config.

I had a first look in the php session and didn't find anything concrete that I could use :(

However, because I know that I get {"result":"success"} from the cgi for a successful login, I can create and manage my own "flag" in the login.php page
It's a quite ugly solution, but it's ok for my purpose...

In the login.php page, I have set this (just before the last line) :

if (strlen(strstr($content,"success"))>0)
{
_setCredentials($login);
}

All the pages to be secured must start with:

<?php
require_once("security.php");
_checkCredentials();

where security.php contains:

<?php
session_start();

function _setCredentials($username) {
$_SESSION['username'] = $username;
}

function _checkCredentials() {
if ($_SESSION['username'] == null)
{
session_destroy();
header("location:/index.php");
exit;
}
}

function _clearCredentials() {
session_destroy();
header("location:/index.php");
}
?>

Obviously, the login.php page also starts with:

<?php
require_once("security.php");

I will check with some friends more capable in php than me if this is secure "enough"...

O.
User avatar
OgeGOon
Novice
Novice
 
Posts: 47
Joined: Sat Mar 14, 2009 11:41 pm

Re: Using the Synology "login" for a custom website

Postby gastonet » Tue Mar 02, 2010 4:50 pm

Hello guys, links are broken and I'm trying to mod the login page.

Can anyone help me? My email (if you want to send the code) is gastonet (at) gmail (dot) com

Many thanks in advance.

Gaston
gastonet
I'm New!
I'm New!
 
Posts: 1
Joined: Tue Mar 02, 2010 4:46 pm

Re: Using the Synology "login" for a custom website

Postby E-wawa.pl » Mon Jan 17, 2011 4:01 pm

Code: Select all
<?php
   session_start();
   /*
   /* Using this
   /* Navigate to login.php?domain=yourservernameordomain&port=5000&user=yourlogin&pass=yourpassword
   */
   $username = $_GET['user'];
   $password = $_GET['pass'];
   $port = $_GET['port'];
   $domain = $_GET['domain'];
   $url = 'http://'.$domain.':'.$port.'/webman/login.cgi?username='.$username.'&passwd='.$password;
   $data =  @file_get_contents($url);
   if(preg_match('#\"success\" \: true#',$data)){
      $_SESSION['username'] = $username;
   }else{
      echo 'Wrong credentials';
      unset($_SESSION['username']);
   }
   
   if(isset($_SESSION['username'])){
      echo 'Welcome '.ucfirst($_SESSION['username']);
      echo exec('cat /etc/synouser.conf > temp.tmp');
      //echo file_get_contents('temp.tmp');
      preg_match('#'.$username.'\:[0-9]{1,5}\:.*\@.*#',file_get_contents('temp.tmp'),$match);
      $email = explode(":",$match[0]);
      echo '<br />Your email is '. $email[2];
      unlink('temp.tmp');
   }
?>
User avatar
E-wawa.pl
Experienced
Experienced
 
Posts: 119
Joined: Fri Jan 15, 2010 2:34 pm

Re: Using the Synology "login" for a custom website

Postby TommyN » Thu Mar 24, 2011 7:53 pm

This is really clever. I don't have any use for it yet, but I just had to try it :)
The "Your email is:" is empty when I try it though..

DS712+ / DSM 4.1-2668 / 2 x 3 TB WD30EZRX / RAID 1
Seagate FreeAgent 500 GB in USB 1
ASUS RT-56U FW:3.0.0.4.342
Boxee Box by D-Link
Logitech Squeezebox Boom
User avatar
TommyN
Knowledgeable
Knowledgeable
 
Posts: 341
Joined: Fri May 11, 2007 1:42 pm
Location: Denmark

Re: Using the Synology "login" for a custom website

Postby partikule » Fri Aug 19, 2011 10:53 am

@E-wawa.pl : Nice, but doesn't work anymore in DSM 3.2
partikule
I'm New!
I'm New!
 
Posts: 1
Joined: Thu Aug 18, 2011 12:19 pm


Return to Security/Secured Mods

Who is online

Users browsing this forum: No registered users and 0 guests