GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   removing user from htpasswd via php (https://gfy.com/showthread.php?t=747804)

Donkey Punch 07-02-2007 04:01 AM

removing user from htpasswd via php
 
anyone have a snippet of code I could borrow to do this?

or at least point me in the right direction?

Thanks :)

tomud 07-02-2007 04:19 AM

sure :)

http://www.scriptsearch.com/details/964.html

Tomud

fris 07-02-2007 04:21 AM

30$ for a script like that? could code one quicker

Donkey Punch 07-02-2007 04:29 AM

that's a little over my .20 cent budget

tomud 07-02-2007 04:40 AM

Quote:

Originally Posted by Donkey Punch (Post 12690174)
that's a little over my .20 cent budget

:1orglaugh:1orglaugh:1orglaugh

Tomud

quantum-x 07-02-2007 05:15 AM

steal / use the ccbill or epoch one that everyone has.

Donkey Punch 07-02-2007 05:29 AM

Quote:

Originally Posted by quantum-x (Post 12690238)
steal / use the ccbill or epoch one that everyone has.

is it php or cgi ?

and where can I get it ?

:\

Wolfy 07-02-2007 05:32 AM

Quote:

Originally Posted by Fris (Post 12690160)
30$ for a script like that? could code one quicker


I bet you $60 you can't code even a hello script faster than I can swipe my VISA for $30.

Tell me when you want to fire the gun :D

Donkey Punch 07-02-2007 05:42 AM

shit, got everything working..

sign up, recover pass and cancel (remove from db) except for the removing from htpasswd part

ima go crazy :)

Donkey Punch 07-02-2007 06:37 AM

If anyone cares... I found a solution. Now to integrate it into my script

http://www.thewebmasters.net/php/Htpasswd.phtml

;)

Thanks to everyone who tried to help me. I appreciate it.

budz 07-02-2007 08:17 AM

Thanks for the "LINK" haha ;)

takaya 07-02-2007 09:50 AM

A simple version
 
<form action=<?=$PHP_SELF?> method=post>
Username <input name=username><p>
Password <input name=password></p>
| Add <input type=radio name=do_what value=Add> | Modify <input type=radio name=do_what value=Modify> | Delete <input type=radio name=do_what value=Delete> |<br>
<input type=submit value=submit>
</form>
<?
// find path and filename in .htaccess
// change access permission of filename to to allow write
$htaccess_file = "path_of_file/filename";
$username = trim($_POST["username"]); // from yout post form
$password = trim($_POST["password"]); // from your post form
$action = $_POST["do_what"]; // from your post form
$user_string = $username . ":" . crypt($password) ."\n";

if($action == "Add") {
$fp=fopen($htaccess_file, "a+");
if ($fp) {
while (!feof($fp)) {
$htpassinfo = fgets($fp, 4096);
list($ht_username, $ht_password) = explode(":", $htpassinfo);
if(trim($username) == trim($ht_username)) {
echo "Username $username is already existed";
exit;
}
}
if (fwrite($fp, $user_string) === FALSE) {
echo "FAIL to Add";
fclose($fp);
exit;
}
fclose($fp);
echo "Add Successful";
}
} else {
$fp=fopen($htaccess_file, "r");
if ($fp) {
$i=0;
while (!feof($fp)) {
$htpassinfo = fgets($fp, 4096);
list($ht_username, $ht_password) = explode(":", $htpassinfo);
if(trim($username) == trim($ht_username)) {
if($action == "Delete") {
$htlist[$i] = "";
$msg = "Deleted";
} else if($action == "Modify") {
$htlist[$i] = $user_string;
$msg = "Modified";
} else {
$htlist[$i] = $htpassinfo;
}
} else {
$htlist[$i] = $htpassinfo;
}
$i++;
}
fclose($fp);
} else {
echo "fail to open file";
exit;
}
$fp=fopen($htaccess_file, "w");
if ($fp) {
for($i=0;$i<count($htlist);$i++) {
fputs($fp, $htlist[$i]);
}
echo $msg;
}
}
?>

Donkey Punch 07-02-2007 09:53 AM

include("class.Htpasswd.php3");

$UserID = "$user";

$Htpasswd = new Htpasswd;
$Htpasswd->initialize("/home/topsecretdomainbeforewebdirectory/.htpasswd");

if(!($Htpasswd->EXISTS))
{
#O KNOEZ !!
exit;
}

if($Htpasswd->deleteUser($UserID))

J.P. 07-02-2007 10:48 AM

grep -Ev "^desired_username:" .htpasswd > .htpasswd.tmp;mv -f .htpasswd.tmp .htpasswd

you can use PHP's exec() function to execute this shell command... you will have to use full paths of course

Donkey Punch 07-02-2007 10:49 AM

Quote:

Originally Posted by J.P. (Post 12691346)
grep -Ev "^desired_username:" .htpasswd > .htpasswd.tmp;mv -f .htpasswd.tmp .htpasswd

you can use PHP's exec() function to execute this shell command... you will have to use full paths of course

lol, I had the command line earlier and I gave up trying to get it to work!

Thanks for the post though :))

takaya 07-02-2007 11:21 AM

ok, people asked about code.

The code above I posted is a working code, you need to change the path and htaccess file permission, easy way is in command line -- chmod 666 filename

that's it

J.P. 07-03-2007 03:36 AM

Quote:

Originally Posted by Donkey Punch (Post 12691356)
lol, I had the command line earlier and I gave up trying to get it to work!

Thanks for the post though :))

No problem, anytime :)

rowan 07-03-2007 05:59 AM

Just be careful you don't end up with two processes writing the password file at the same time. None of the methods posted in here use locking.


All times are GMT -7. The time now is 05:53 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123