May 22, 2013, 05:29:15 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: THC Hack Challenges Released!
 

 
advertisement:

Pages: [1]
  Print  
Author Topic: Post your code snippets that might help the people out there  (Read 1302 times)
zomgwtfbbq
Challenge Coder
Administrator
Hero Member
*****

Karma: +31341/-1
Posts: I am a geek!!


thc title: thc elite
thc points: 3315
challenges: (69/83)

View Profile
« on: April 23, 2010, 08:29:03 PM »
Share on FacebookFacebook Share

Just came up with the idea that it might be useful to post your code snippets in this thread.
Love to see some miscellaneous scripts out here, not just the ordinary stuff.

I bump into lots of problems that I'm too lazy to do manually and rather program it as a routine, guess most programmers are like that.
Why do it the hard way if it can be done automatically?

I might even add useful scripts to the THC HackSuite module section.
Logged


only registered users with at least 25 hack challenge points can see links:
  click here in order to visit the hack challenges


Ook al ben ik een slet toch houdt ik van je..
zomgwtfbbq
Challenge Coder
Administrator
Hero Member
*****

Karma: +31341/-1
Posts: I am a geek!!


thc title: thc elite
thc points: 3315
challenges: (69/83)

View Profile
« Reply #1 on: April 23, 2010, 08:31:46 PM »
Share on FacebookFacebook Share

<?php
/*
MediaXXX doesn't remove all the files properly when an upload fails, the image mouseovers and the flv file will still be there and can only be deleted manually, which is a lot of work.
When uploads and conversions have failed, the site will get undesired output.
This script cleans all the bad entries, with some tweaking of this script you can integrate it completely into MediaXXX and can keep 
your site clean from upload and proper file deletion failures.

Upload this script to the same server where you installed MediaXXX.

NOTE: you need to edit the settings below in order to get the script to work
*/

// START OF EDIT
// path to data files
$sPath $_SERVER['DOCUMENT_ROOT']."/vdata";
// path to mouse over jpeg files
$sPathImage $_SERVER['DOCUMENT_ROOT']."/uploads/temp";
// database host
$sHost "localhost";
// database user
$sUser "";
// database pass
$sPass "";
// database name
$sName "";
// just do a test or try to clean up the server?
$bTest true;
// only show corrupt entries?
$bCorrupt true;
// max delete, set to zero if you want all corrupt stuff deleted at once.. this is just a pre caution in case you make a mistake
$iMax 10;
// END OF EDIT


if(false===($rConnect = @mysql_connect($sHost,$sUser,$sPass))){
	
die(
"Connection failed");
}
if(!@
mysql_select_db($sName)){
	
die(
"Database doesn't exist");
}
/* Returns all filenames in a directory

Opens a directory and buffers all files in an array.

PARAMETERS:
$sDir: directory to get files from

RETURNS:
ARRAY: filenames in the target directory
FALSE: failed to open directory $sDir
*/

function GetFilesByDirectory($sDir){

	
if(!
$rHandle = @opendir($sDir)){
	
	
return(
false);
	
}
	
$aFileBuffer = array();
	
while(
false!==($sFile = @readdir($rHandle))){
	
	
// buffer all files
	
	
if(
$sFile!="." && $sFile!=".."){
	
	
	
if(!
is_dir($sDir."/".$sFile)){
	
	
	
	
$aFileBuffer[] .= $sFile;
	
	
	
}
	
	
}
	
}
	
@
closedir($rHandle);
	
return 
$aFileBuffer;
}
/* Destroy a directory

Opens a directory and recursively removes files and finally the directory.

PARAMETERS:
$sDir: directory to remove

RETURNS:
TRUE: directory to remove
FALSE: failed to open directory $sDir
*/

function RemoveFiles($sDir){

	
if(!
$rHandle = @opendir($sDir)){
	
	
return(
false);
	
}
	
while(
false!==($sFile = @readdir($rHandle))){
	
	
// buffer all files
	
	
if(
$sFile!="." && $sFile!=".."){
	
	
	
if(!
is_dir($sDir."/".$sFile)){
	
	
	
	
unlink($sDir."/".$sFile);
	
	
	
}
	
	
}
	
}
	
@
closedir($rHandle);
	
return(
rmdir($sDir));
}
// flv video files
$aFiles GetFilesByDirectory($sPath);
// mouse over files
$aFilesImage GetFilesByDirectory($sPathImage);
if(!@
count($aFiles)){
	
die(
"No files in video data directory, maybe you misspelled the directory?");
}
if(!@
count($aFilesImage)){
	
die(
"No files in mouseover data directory, maybe you misspelled the directory?");
}
// okidoki let's get our thang in action, we'll map the whole structure of the scenery to get a clear overview
$aOverview = array();
for(
$x=0;$x<count($aFiles);$x++){
	
if(
$aFiles[$x]=="index.html"){
	
	
continue;
	
}
	
// get file properties
	
$aFile explode(".",$aFiles[$x]);
	
// mouse over dir
	
$sDir $sPathImage."/".$aFile[0];
	
// new map item
	
$aOverview[$x] = array();
	
$aOverview[$x]['id'] = $aFile[0];
	
// so does the record for this flv exist?... yes I know this is quite heavy if u have many video files, but this is just a code u might use only once ;)
	
$sQuery3 "SELECT title FROM videos WHERE VIDEOID=".$aOverview[$x]['id'];
	
$rQuery3 mysql_query($sQuery3);
	
$sTitle = @mysql_result($rQuery3,0,'title');
	
$aOverview[$x]['db'] = ((strlen($sTitle)>0) ? $sTitle false);
	
$aOverview[$x]['mover'] = ((@count(GetFilesByDirectory($sDir))>0) ? true false);
}
mysql_close();
// template the output, forget standards just output the stuff we want
if($bTest==true){
	

	
// ok let's see what things exactly are missing
	
echo
"<center><table border=\"1\" width=\"500\">\n";
	
echo
"<tr><th colspan=3>flash video summary</th></tr>\n";
	
for(
$x=0;$x<count($aOverview);$x++){
	
	
if(
$bCorrupt && $aOverview[$x]['mover']!=false && $aOverview[$x]['db']!=false){
	
	
	
continue;
	
	
}
	
	
echo
"<tr>";
	
	
echo
"<td>".$aOverview[$x]['id'].".flv</td>\n";
	
	
echo (
$aOverview[$x]['db'] ? "<td>".stripslashes($aOverview[$x]['db'])."</td>" "<td><b>no db record</b></td>")."\n";
	
	
echo (
$aOverview[$x]['mover'] ? "<td>present</td>" "<td><b>no mouse overs</b></td>")."\n";
	
	
echo
"</tr>\n";
	
}
	
echo
"</table></center>\n";
}
else{
	
// ok let's see what things exactly are missing and clean up the stuff
	
echo
"<center><table border=\"1\">\n";
	
echo
"<tr><th colspan=3>overview of action</th></tr>\n";
	
$iCount 0;
	
for(
$x=0;$x<count($aOverview);$x++){
	
	
if(
$iCount==$iMax && $iMax!=&& $iCount>0){
	
	
	
// security break
	
	
	
break;
	
	
}
	
	
if(
$aOverview[$x]['db']!==false){
	
	
	
// nothing to do
	
	
	
continue;
	
	
}
	
	
echo
"<tr>";
	
	
echo
"<td>".$aOverview[$x]['id'].".flv</td>\n";
	
	
echo (@
unlink($sPath."/".$aOverview[$x]['id'].".flv") ? "<td>deleted video</td>" "<td>video not deleted</td>");
	
	
echo (
RemoveFiles($sDir) ? "<td>deleted mouseovers</td>" "<td>mouseovers not deleted</td>");
	
	
echo
"</tr>\n";
	
	
$iCount++;
	
}
	
if(
$iCount==0){
	
	
echo
"<tr><td colspan=3>nothing to clean, everything is clear :)</td></tr>\n";
	
}
	
echo
"</table></center>\n";
}
?>
« Last Edit: April 23, 2010, 08:42:10 PM by zomgwtfbbq » Logged


only registered users with at least 25 hack challenge points can see links:
  click here in order to visit the hack challenges


Ook al ben ik een slet toch houdt ik van je..
zomgwtfbbq
Challenge Coder
Administrator
Hero Member
*****

Karma: +31341/-1
Posts: I am a geek!!


thc title: thc elite
thc points: 3315
challenges: (69/83)

View Profile
« Reply #2 on: April 24, 2010, 06:33:42 PM »
Share on FacebookFacebook Share

<?php
/*
This script fetches missing images from an array.
Stumbled upon an error in my ad management for mediaxxx when I checked the result of pages where the ads are being used, 
it seemed a lot of images didn't exist.
So something must have gone wrong when I uploaded them to the server, sadly my computer where I put them in didn't wanna boot after it fell on 
the ground. :(
So I had to find a way of getting the missing affiliate banners.

The array that contains the ad looks like this:
$_AD_BIG['teen'] = array();
$_AD_BIG['teen'][0] = array("affiliate link","image name");

You need to edit the variables below in order to get it to work, this script is based upon the array structure above.
*/

// START OF EDIT
// path to the image folder
$sImagePath $_SERVER['DOCUMENT_ROOT']."/images/banner/big/";
// path to the image folder(http)
$sImagePathHTTP "http://".$_SERVER['HTTP_HOST']."/images/banner/big/";
// name of array variable
$sVar "_AD_BIG";
// variable key in $sVar where you hold the image string
$mKey 1;
// path to array data file, if you keep this empty you must define the variable $sVar right after // END OF EDIT
$sDataPath "";
// END OF EDIT
// ok make sure we have the data we need
if($sDataPath!=""){
	
if(!
file_exists($sDataPath)){
	
	
die(
"Path to data file is invalid");
	
}
	
include(
$sDataPath);
}
if(!
is_array($$sVar)){
	
die(
"<b>\$".$sVar."</b> isn't an array");
}
$x 0;
echo
"<center><table border=\"1\" width=\"500\">\n";
echo
"<tr><th colspan=3>data output</th></tr>\n";
$aTemp = $$sVar;
foreach(
$aTemp as $sKey=>$aValues){
	
for(
$y=0;$y<count($aTemp[$sKey]);$y++){
	
	
if(!isset(
$aValues[$y][$mKey])){
	
	
	
echo
"<tr><td colspan=3>The var <b>\$".$sVar."[".$sKey."][".$mKey."]</b> doesn't exist</td></tr>\n";
	
	
	
if(
$x==0){
	
	
	
	
// if the first one fails, it must be an invalid path, otherwise show error and keep going
	
	
	
	
break;
	
	
	
}
	
	
}
	
	
else{
	
	
	
$sFileHTTP $sImagePathHTTP.$aValues[$mKey];
	
	
	
$sFile $sImagePath.$aValues[$mKey];
	
	
	
echo
"<tr><td>".$aValues[$y][$mKey]."</td><td>".$sKey."</td><td>".(@file_exists($sImagePath.$aValues[$y][$mKey]) ? "<img src=\"".$sImagePathHTTP.$aValues[$y][$mKey]."\" border=\"0\">" "<b>image doesn't exist</b>")."</td></tr>\n";
	
	
	
$x++;
	
	
}
	
}
}
echo
"</table></center>\n";
?>
« Last Edit: April 24, 2010, 06:38:43 PM by zomgwtfbbq » Logged


only registered users with at least 25 hack challenge points can see links:
  click here in order to visit the hack challenges


Ook al ben ik een slet toch houdt ik van je..
zomgwtfbbq
Challenge Coder
Administrator
Hero Member
*****

Karma: +31341/-1
Posts: I am a geek!!


thc title: thc elite
thc points: 3315
challenges: (69/83)

View Profile
« Reply #3 on: April 24, 2010, 08:44:09 PM »
Share on FacebookFacebook Share

<?php
/*
When I mass uploaded videos with MediaXXX I didn't change the title but just used the file's name instead.
That kind of .. well .. looked horrible, needed to isolate those files.

Here's what I came up with.

Upload this script to the same server where you installed MediaXXX.

NOTE: you need to edit the settings below in order to get the script to work
*/

// START OF EDIT
// database host
$sHost "localhost";
// database user
$sUser "";
// database pass
$sPass "";
// database name
$sName "";
// output all records or just the ones we think that look like a filename without the the extension
$bAll false;
// END OF EDIT


if(false===($rConnect = @mysql_connect($sHost,$sUser,$sPass))){
	
die(
"Connection failed");
}
if(!@
mysql_select_db($sName)){
	
die(
"Database doesn't exist");
}
$sQuery "SELECT title,VIDEOID,filesize FROM videos";
$rQuery mysql_query($sQuery);
echo
"<center><table border=\"1\" width=\"500\">\n";
echo
"<tr><th colspan=3>data output</th></tr>\n";
$iMatch 0;
while(
false!==($aData = @mysql_fetch_array($rQuery,MYSQL_ASSOC))){
	
if(
$bAll==true || !strpos($aData['title']," ")){
	
	
$iMatch++;
	
	
echo
"<tr>";
	
	
echo
"<td>".stripslashes($aData['title'])."</td>\n";
	
	
echo
"<td>".$aData['VIDEOID']."</td>\n";
	
	
echo
"<td>".$aData['filesize']."</td>\n";
	
	
echo
"</tr>\n";
	
}
}
echo
"<tr><td colspan=3>matches: ".$iMatch."</td></tr>\n";
echo
"</table></center>\n";
mysql_close();
?>
Logged


only registered users with at least 25 hack challenge points can see links:
  click here in order to visit the hack challenges


Ook al ben ik een slet toch houdt ik van je..
Mandara
Ninja Assassin
Global Moderator
Full Member
*****

Karma: +197/-0
Posts: 238


thc title: n00b
thc points: 65
challenges: (5/83)

View Profile WWW
« Reply #4 on: December 04, 2010, 12:18:41 PM »
Share on FacebookFacebook Share

MediaXXX runs on your adult website? Still selling it?
Logged

Give me your hand and I'll protect you, squeeze mine and I'll break yours.
zomgwtfbbq
Challenge Coder
Administrator
Hero Member
*****

Karma: +31341/-1
Posts: I am a geek!!


thc title: thc elite
thc points: 3315
challenges: (69/83)

View Profile
« Reply #5 on: December 17, 2010, 03:47:21 PM »
Share on FacebookFacebook Share

MediaXXX runs on your adult website? Still selling it?
Yeps, but it's likely that I will just remove the content, nobody wants to buy it. rolling over floor laughing my arse out!

For ppl interested:

only registered users with at least 25 hack challenge points can see links:
  click here in order to visit the hack challenges
http://www.watchpornvideosnow.com
Logged


only registered users with at least 25 hack challenge points can see links:
  click here in order to visit the hack challenges


Ook al ben ik een slet toch houdt ik van je..
Pages: [1]
  Print  
 
Jump to:  


SMF Board hacked and modded by zomgwtfbekjam aka Rembo from Tools & Design