HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Tips/Tricks/Mods (http://www.howtoforge.com/forums/forumdisplay.php?f=19)
-   -   Simple HTML Login Form (http://www.howtoforge.com/forums/showthread.php?t=2895)

Glorfindel 5th March 2006 20:41

Simple HTML Login Form
 
Please look below for a more advanced login script

Heres a quick little tip to save some time looking at the ISPConfig login.php file, or for those who don't know php/html very well :p

HTML Code:

<form method="POST" action="http://YOUR_DOMAIN_HERE:81/login/login.php">
  Username: <input type="text" name="username" size="15" /><br />
  Password: <input type="password" name="passwort" size="15" /><br />
  <div align="center">
    <p><input type="submit" value="Login" /></p>
  </div>
</form>

This is just some simple HTML code that will log in to the ISPConfig panel from anywhere you want to put it. (It will redirect you to the port 81 server, of course, but it will skip the login screen... supposing you put in a valid username and password.)

Also, note that "passwort" is not a typo. ISPConfig seemingly was not coded in english.

Hope this helps someone,
Glorfindel

Glorfindel 7th March 2006 19:03

Ok, there are two things I really don't like about ISPConfig. One, there are a lot of passwords and usernames for each user to remeber. Two, there is a lack of remoting (can't wait for them to release the remoting plugin!! :D )

Here is a much more advanced login script in PHP. This script displays the most important parts of ISPConfig (in my opinion) based on the ISPConfig panel login username and password. Once the user uses this login, the login form will be replaced with a link to the ISPConfig panel, webmail, and phpMyAdmin for each of the databases that they have created. All these log in automatically in a new window.

http://www.glorf.com/img/script_example.gif


As a disclaimer... I'm primarily a C++ coder, and I don't do much PHP, so there are surely many improvements to be made!

Connect.php
PHP Code:

<?php
// db info
$hostname="localhost";
$mysql_login="root";
$mysql_password="YOUR_ROOT_PASSWORD";
$database="THE_ISPCONFIG_DATABASE_NAME";

if (!(
$db mysql_connect($hostname$mysql_login $mysql_password))){
  die(
"Can't connect to mysql.");    
}else{
  if (!(
mysql_select_db("$database",$db)))  {
    die(
"Can't connect to db.");
  }
}
?>

This file simply sets up a connection to the ISPConfig database. Make sure to replace the root password, and ISPConfig database name with your own. :D

login.php
PHP Code:

<?php
/***************************************************************************
 ISP Config Login Interface
     Author: Glorfindel       
 ---------------------------------------------------------------------------
 Desc: Provides a unified log-in outside of the ISPConfig control panel.   
 This unified login checks the ISPConfig user tables, and provides links   
 to each of the ISPConfig panels with one, unified, password outside port  
 81.                                                                       
***************************************************************************/

// start session
session_start(); 

include(
"connect.php");

function 
checkLogin()
{
    
// convert username and password from _GET to _SESSION
    
if($_GET){
      
$_SESSION['username']=$_GET["username"];
      
$_SESSION['passwort']=$_GET["passwort"];  
    } 
    
    
$username $_SESSION['username'];
    
$passwort $_SESSION['passwort'];
    
    
$username addslashes($username);
    
$passwort addslashes($passwort);
    
    
$sql "SELECT * FROM sys_user WHERE username = '$username' AND (passwort = '".md5($passwort)."' OR passwort = PASSWORD('$passwort'))";
    
    
$result=mysql_query($sql);
    if (!
$_SESSION['verified'])
    {
        if (( 
$num mysql_num_rows($result) ) and ($passwort != ""))
        {
            if (
$num != 0)
            {
                
$_SESSION['ERROR'] = "";
                
$_SESSION['verified'] = 1;
                
                
// lets get their e-mail alias.
                
$sql "SELECT user_email FROM isp_isp_user WHERE user_name='$username'";
                
$result mysql_query($sql);
                
$_SESSION['email'] = mysql_result($result,0,"user_email");
            } 
        } 
        else 
        {
            
$_SESSION['ERROR'] = "login is WRONG!!";
        }
    }
    
    if (
$_SESSION['verified'] != 1$_SESSION['ERROR'] = "Login Failed. <br />";
}


//////////////////////////
// Main Bit Starts Here //
//////////////////////////
//
if ($_SESSION['verified'] != and $_GET['action'] == "login")
    
checkLogin(); 
    
if (
$_GET['action'] == "logout")
{
    
$_SESSION = array();
    
session_destroy();
    
$_SESSION['ERROR'] = "You have successfully logged out. <BR />";
}
    
if (
$_SESSION['verified'] != 1)
{
    
// User is NOT logged in, so lets give him a login form...
    
echo("<!--Begin Login -->");
    echo(
"<font color='red'>");
    echo(
$_SESSION['ERROR']);
    
$_SESSION['ERROR'] = ""// reset the error message if there is one.
    
echo("</font><br />");
    echo(
"<form method=\"GET\" action=\"");
    echo(
$_SERVER['PHP_SELF']);
    echo(
"\">");
    echo(
"Username: <br /><input type=\"text\" name=\"username\" size=\"15\" /><br />");
    echo(
"Password: <br /><input type=\"password\" name=\"passwort\" size=\"15\" /><br />");
    echo(
"<input type=\"hidden\" name=\"action\" value=\"login\" />");
    echo(
"<p><input type=\"submit\" value=\"Login\" /></p>");
    echo(
"</form>");
    echo(
"<!--End Login -->");
    } else {
    
// if the user IS logged in, give him options here.
    
    // Javascript to make POST data submittable thru link...
    // Web Admin Panel
    
echo("<script language='JavaScript' type='text/javascript'>\n");
    echo(
"<!--\n");
    echo(
"function submit()\n");
    echo(
"{\n");
    echo(
"document.loginform.submit();\n");
    echo(
"}\n");
    echo(
"-->\n");
    
    
// Mail
    //echo("<script language='JavaScript' type='text/javascript'>\n");
    
echo("<!--\n");
    echo(
"function submit1()\n");
    echo(
"{\n");
    echo(
"document.loginform1.submit();\n");
    echo(
"}\n");
    echo(
"-->\n");
    
    
// PhpMyAdmin
    //echo("<script language='JavaScript' type='text/javascript'>\n");
    
echo("<!--\n");
    echo(
"function submit2()\n");
    echo(
"{\n");
    echo(
"document.loginform2.submit();\n");
    echo(
"}\n");
    echo(
"-->\n");
    echo(
"</script>\n");
    
////////////////////////////////////////////////////////////////////
    // Note: Newlines are required, else it screws up the javascript  //
    ////////////////////////////////////////////////////////////////////
    
    
echo("<B>Control Panel: </B><BR />");
    
    echo(
"<form method='POST' target=_blank action='http://www.glorf.com:81/login/login.php' name='loginform'>\n");
    echo(
"<input type=\"hidden\" name=\"username\" value=\"");
    echo(
$_SESSION['username']);
    echo(
"\"><input type=\"hidden\" name=\"passwort\" value=\"");
    echo(
$_SESSION['passwort']);
    echo(
"\">");
    echo(
"</form>");
    echo(
"<a href='javascript: submit()'>Website Admin Panel</a>\n");

    echo(
"<form method='POST' target=_blank action='http://www.glorf.com:81/webmail/msglist.php' name='loginform1'>\n");
    echo(
"<input type=\"hidden\" name=\"f_email\" value=\"");
    echo(
$_SESSION['email']);
    echo(
"@glorfy.com\"><input type=\"hidden\" name=\"f_pass\" value=\"");
    echo(
$_SESSION['passwort']);
    echo(
"\">");
    echo(
"</form>");
    echo(
"<a href='javascript: submit1()'>Web Mail</a><br />\n");
    
    
    echo(
"<BR /><B>Databases: </B><BR />");
    
    
// Now lets get the database names...
    // first that means we need to link the username to a web_id.
    
$email $_SESSION['email'];
    
$sql "SELECT web_id FROM isp_fakt_record WHERE notiz= '$email'";
    
$result mysql_query($sql);
    
$_SESSION['web_id'] = mysql_result($result,0,"web_id");
    
$web_id $_SESSION['web_id'];
    
    
// now we need to use that to grab all the DB names for displaying.
    
$sql "SELECT datenbankuser FROM isp_isp_datenbank WHERE web_id = '$web_id'";
    
$result mysql_query($sql);
    
// now lets loop the results and store them into an array for later display purposes.
    
global $dbs$num_db;
    
$num_db mysql_num_rows($result);
    
$dbs = array(30); // a user can't have more than 30 databases :)
    
for ($i=0$i $num_db$i+=1)
    {
        
$dbs[$i] = mysql_result($result,$i,"datenbankuser");
        echo(
"<a href=\"http://");
        echo(
$dbs[$i]);
        echo(
":");
        echo(
$_SESSION['passwort']);
        echo(
"@www.glorf.com:81/phpmyadmin/index.php");
        echo(
"\">");
        echo(
$dbs[$i]);
        echo(
"</a><br />");
    }
    
    
///////////////////////////////////////
    
echo("<hr />");
    echo(
"<a href=\"");
    echo(
$_SERVER['PHP_SELF']);
    echo(
"?action=logout\">logout<br></a>");

mysql_close();
?>

This file is the meat of the script. You need to use a search and replace to replace all "glorf.com" with "your.com" DO NOT put a www. on that... I used www off and on throughout the script, so your find and replace would end up making some www.www. if you do that!

Now, wherever you would like to have the login, you need to add the code...
PHP Code:

<?php include("login.php"); ?>

I suggest you do this inside a table, as that is how I am using it.

Feel free to modify the code, but let me know if you make improvements, so that I can put them into my own version!! :D

Green-Sky 15th January 2011 14:56

Which mysql banks I have to make?

falko 16th January 2011 12:54

Why do you mean with "mysql banks"?


All times are GMT +2. The time now is 05:17.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.