Remote Web Password modification for Svn in Linux

Source: Internet
Author: User

Linux Remote Password Change Tool

Usage:
1. Place the changepasswd. cgi and changepasswd. ini files in the cgi-bin directory under the Apche installation directory.
2. Check the position of the prel tool (My :#! /Usr/bin/perl-W)
/Usr/bin/perl
3. Change changepasswd. cgi 84th to the path where htpasswd is located (My:/project/Apache/bin/htpasswd)
4. Modify the INI file of changepasswd. cgi 128 to the full path (My:/project/Apache/cgi-bin/changepasswd. INI)
5. configuration file changepasswd. ini line 2nd authuserfile = Password Storage path (My:/svndata/SVN-auth-file/passwd)
6. configuration file changepasswd. ini 3rd logfile = operation log storage path (My:/project/Apache/cgi-bin/changpasswd. Log)

Note:
1. Do not use the-M parameter when using htpasswd. If it was previously used, you can re-enter it for update.
2. changpasswd. log must have the "w" Write Permission

 

Copy the following content and save the file changepasswd. ini with the INI suffix.

[Path]
Authuserfile =/Repository/auth/AuthFile
Logfile =/Repository/auth/changpasswd. Log
[Setup]
Pwdminlen = 6
[HTML]
Title = SVN User Password self-help Modification
Description = SVN User Password self-help Modification
Yourname = User Name
Oldpwd = old password
Newpwd1 = New Password
Newpwd2 = confirm new password
Btn_change = Modify
Btn_reset = Reset

Changepwdok = Password Changed successfully
Changepwdfailed = An error occurred while changing the password.
Servererror = Server Error
Passmustgreater = the number of new passwords must be greater
Twopassnotmatched = the two passwords are inconsistent.
Entername = enter the user name
Enterpwd = PASSWORD not entered
Errorpwd = Your password is incorrect
Back = return

 

Copy the following content and save the file changepasswd. cgi with the CGI suffix.

#! /Usr/bin/perl-W

Use strict;
Use CGI;
My $ time = localtime;
My $ remote_id = $ ENV {remote_host} | $ ENV {remote_addr };
My $ admin_email = $ ENV {server_admin };

My $ CGI = new CGI;
My $ pwd_not_alldiginal = "the password cannot be all numbers ";
My $ pwd_not_allchar = "the password cannot be all characters ";
My $ user_not_exists = "this user does not exist ";
My $ file_not_found = "the file does not exist. Contact the Administrator ";

My $ authuserfile;
My $ logfile;
My $ pwdminlen;
My $ title;
My $ description;
My $ yourname;
My $ oldpwd;
My $ newpwd1;
My $ newpwd2;
My $ btn_change;
My $ btn_reset;

My $ changepwdok;
My $ changepwdfailed;
My $ oldpwderror;
My $ passmustgreater;
My $ twopassnotmatched;
My $ entername;
My $ enterpwd;
My $ errorpwd;
My $ back;

& Iniinfo;

If ($ CGI-> param ())
{#8
My $ user = $ CGI-> param ('username ');
My $ userpwd = $ CGI-> param ('oldpwd ');
My $ usernewpwd = $ CGI-> param ('newpwd1 ');
My $ matchnewpwd = $ CGI-> param ('newpwd2 ');

If (! $ User)
{& Writer_log ("enter no user name ");
& Otherhtml ($ title, $ entername, $ back );}
Elsif (! $ Userpwd)
{& Writer_log ("enter no oldpasswd ");
& Otherhtml ($ title, $ enterpwd, $ back );}
Elsif (length ($ usernewpwd) <$ pwdminlen)
{& Writer_log ("password's length must greater than". $ pwdminlen );
& Otherhtml ($ title, $ passmustgreater. $ pwdminlen, $ back );}
Elsif ($ usernewpwd = ~ /^/D + $ /)
{& Writer_log ("New passwd isn't all diginal ");
& Otherhtml ($ title, $ pwd_not_alldiginal, $ back );}
Elsif ($ usernewpwd = ~ /^ [A-Za-Z] + $ /)
{& Writer_log ("New passwd isn't all char ");
& Otherhtml ($ title, $ pwd_not_allchar, $ back );}
Elsif ($ usernewpwd ne $ matchnewpwd)
{& Writer_log ("two new passwords are not matched ");
& Otherhtml ($ title, $ twopassnotmatched, $ back );}
Else
{If ($ authuserfile)
{#6
Open userfile, "<$ authuserfile" or die "failed to open the file: $! ";
While (<userfile>)
{#5
My $ varstr =$ _;

If ($ varstr = ~ /($ User )/)
{#3
My $ eqpos = index ($ varstr ,":");
My $ username = substr ($ varstr, 0, $ eqpos );
My $ cryptpwd = substr ($ varstr, $ eqpos + 1, 13 );

Next if ($ username ne $ user );

If (crypt ($ userpwd, $ cryptpwd) eq $ cryptpwd)
{#
My $ rc = system ("/usr/bin/htpasswd-B $ authuserfile $ user $ usernewpwd ");
If ($ rc = 0)
{#1
& Writer_log ($ user. ": Change passwd ");
& Otherhtml ($ title, $ changepwdok, $ back );
} #1
Else
{#2
& Writer_log ($ user. ": Change passwd failed ");
& Otherhtml ($ title, $ changepwdfailed, $ back );
} #2
Exit;
} #
Else
{# B
& Writer_log ("Old passwd is incorrect ");
& Otherhtml ($ title, $ errorpwd, $ back );
} # B
Exit;
} #3
Else
{#4
If (EOF)
{& Writer_log ($ user. ": No this user ");
& Otherhtml ($ title, $ user_not_exists, $ back );
Exit;
}
Else
{Next ;}
} #4
} #5
Close userfile;
} #6
Else
{#7
& Writer_log ($ authuserfile. ": No found ");
& Otherhtml ($ title, $ file_not_found, $ back );
} #7
}
} #8
Else
{& Index_html ;}

Sub iniinfo {
My $ INIFILE = "/var/www/cgi-bin/changepasswd. ini ";
Open cgi_ini_file, "<$ INIFILE" or die "failed to open the file: $! ";;
While (<cgi_ini_file>)
{
My $ eqpos = index ($ _, '= ');
My $ Len = length ($ _);

If ($ _ = ~ /Authuserfile /)
{$ Authuserfile = substr ($ _, $ eqpos + 1, $ len-$ eqpos-2 );}
Elsif ($ _ = ~ /Logfile /)
{$ Logfile = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Pwdminlen /)
{$ Pwdminlen = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Title /)
{$ Title = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Description /)
{$ Description = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Yourname /)
{$ Yourname = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Oldpwd /)
{$ Oldpwd = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Newpwd1 /)
{$ Newpwd1 = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Newpwd2 /)
{$ Newpwd2 = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Btn_change /)
{$ Btn_change = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Btn_reset /)
{$ Btn_reset = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Changepwdok /)
{$ Changepwdok = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Changepwdfailed /)
{$ Changepwdfailed = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Oldpwderror /)
{$ Oldpwderror = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Passmustgreater /)
{$ Passmustgreater = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Twopassnotmatched /)
{$ Twopassnotmatched = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Entername /)
{$ Entername = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Enterpwd /)
{$ Enterpwd = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Errorpwd /)
{$ Errorpwd = substr ($ _, $ eqpos + 1 );}
Elsif ($ _ = ~ /Back /)
{$ Back = substr ($ _, $ eqpos + 1 );}
}
Close cgi_ini_file;
}

Sub index_html
{
Print "Content-Type: text/html/n ";
Print <end_of_page;
<HTML>
<Head>
<Title> $ title </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
</Head>
<Body>
<Center> </Center>
<Form method = "Post" enctype = "multipart/form-Data" Action = "/cgi-bin/changepasswd. cgi">
<Br>
<Table align = "center">
<Tr> <TD class = "t_text"> $ yourname </TD> <input type = "text" name = "username"/> </TD>/ tr>
<Tr> <TD class = "t_text"> $ oldpwd </TD> <input type = "password" name = "oldpwd"/> </TD>/ tr>
<Tr> <TD class = "t_text"> $ newpwd1 </TD> <input type = "password" name = "newpwd1"/> </TD>/ tr>
<Tr> <TD class = "t_text"> $ newpwd2 </TD> <input type = "password" name = "newpwd2"/> </TD>/ tr>
</Table>
<Br>
<Table align = "center">
<Tr> <TD> <input type = "Submit" name = "chgpasswd" value = "$ btn_change"> <input type = "reset" value = "$ btn_reset"> </TD> </tr>
</Table>
</Form>
<HR>
<Font color = "# ff0000"> note: the number of new passwords must be greater than $ pwdminlen and must be a combination of letters and numbers. </font>
<P> if you have any questions, contact **. </P>

<P> company ** website: </P>
<P> company homepage: http://www.baidu.com/</P>
</Body>
</Html>
End_of_page
}

Sub otherhtml {
Print "Content-Type: text/html/n ";

Print <end_of_page;
<HTML>
<Head>
<Meta http-equiv = "content-language" content = "ZH-CN">
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> $ _ [0] </title>
</Head>

<Body>
<P align = "center"> <font size = "5" >_ _ [1] </font> </P>
<P align = "center"> <a href = "/cgi-bin/changepasswd. cgi "> <font size =" 4 "> $ _ [2] </font> </a> </P>

<HR>
<P> if you have any questions, contact windone via e-mail: <a href = "mailto: $ admin_email"> $ admin_email </a>. </P>
</Body>

</Html>
End_of_page
}

Sub writer_log {
If ($ logfile)
{
My $ loginfo = "[". $ time. "]". "[". $ remote_id. "]". "|". $ _ [0];
Open logfile, ">>$ logfile" or die "couldn't open log file for writing: $! ";
Print logfile ("$ loginfo/N ");
Close logfile;
}
}

 

After completing the steps 1-6, you can modify the user's password through the remote web.

Test Logon: http: // ip/cgi-bin/changepasswd. cgi

 

I wish you success!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.