1
shank
coding help needed I think.
  • 2006/5/21 16:23

  • shank

  • Not too shy to talk

  • Posts: 144

  • Since: 2004/8/17


ok. So I created a module using the "mypage" idea found HERE.

This new module i'm calling modcreator. What it does is create new modules using the same idea of the "mypage".

After the form is filled out on the index it takes that information and puts it into the xoops_version.php file. it creates a new module directory with the name ehb_$modname which is taken from the form.
and it creates the index.php file with the content of coming soon.

This is still a work in progress, but I'm having an issue.

This module works on my local, and it works on my XOOPS site online, but I tested on someone elses XOOPS site, and it didn't work right. it did create the directory for the new module, and uploaded the file to serve as a logo in the admin, but then it dies. also the folder it created, and the gif file in it are locked and can not be deleted for some reason.

So what I am looking for is someone to take a look at my code and help me figure out why this is happening. also are there any security risks in this module I could fix, and generally just help me clean up the code a bit.

I will post the code of the module now, with a link at the bottom of this post so anyone can download a zip file of the module if they want to.

/modcreator/index.php
<?php
include("../../mainfile.php");
include(
XOOPS_ROOT_PATH."/header.php");
$xoopsOption['show_rblock'] = 1;
?>
//All files that contain the above must keep the above to display in the XOOPS framework
<html>
<title>modcreator</title>
<body>
<table align="center"><tr><td align="center"><h1>New Module</h1><br><br>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="generate.php" method="post">
Module Name:<input type="text" name="name"><br>
Version:<input type="text" name="version"><br>
Description:<input type="text" name="descript"><br>
Author:<input type="text" name="author"><br>
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="3000" />
logo.GIF file(92x52pixels):<input type="file" name="logo"><br>
<input type="submit" value="Generate">
</form>
</td></tr></table>
</body>
//All files that contain the below must keep the below to display in the XOOPS framework
<?php
include(XOOPS_ROOT_PATH."/footer.php");

?>



/modcreator/generate.php
<?php
include("../../mainfile.php");
include(
XOOPS_ROOT_PATH."/header.php");
$xoopsOption['show_rblock'] = 1;
//All files that contain the above must keep the above to display in the XOOPS framework
$modname=$_POST['name'];
$modver=$_POST['version'];
$descript=$_POST['descript'];
$author=$_POST['author'];


if (
$_FILES['logo']['type'] != 'image/gif')
{
echo 
"The File Must Be A GIF file. Please make sure your file has GIF for an extension and try again.<br /><a href="index.php">Go Back To Form</a>";
}
elseif (
$_FILES['logo']['size'] > 3000)
{
echo 
"File is too larger. Files should be less than 3Kb. Please try again.<br /><a href="index.php">Go Back To Form</a>";
}
else
{
mkdir ("../ehb_$modname/"0755);
$logo=($_FILES['logo']['name']);
echo 
"directory /modules/$modname/ has been created.<br />";

$target_path "../ehb_$modname/";
$target_path $target_path basename$_FILES['logo']['name']);
$_FILES['logo']['tmp_name'];

if(
move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)) {
    echo 
"The file "basename$_FILES['logo']['name']). " has been uploaded.<br />";
} else{
    echo 
"Possible file upload attack!n";
    echo 
'Here is some more debugging info:';
    
print_r($_FILES);
}


//Everything from here up works

//This creates a file called xoops_version.txt that we will move later.
$myFile "newxoopsversion.txt";
$fh fopen($myFile'w') or die("can't open file");

$stringData "<?phpn";
fwrite($fh$stringData);

$stringData "$modversion['name'] = "$modname";//name of modulen";
fwrite($fh$stringData);

$stringData "$modversion['version'] = "$modver";n";
fwrite($fh$stringData);

$stringData "$modversion['description'] = "$descript";n";
fwrite($fh$stringData);

$stringData "$modversion['author'] = "$author";n";
fwrite($fh$stringData);

$stringData "$modversion['credits'] = "";n";
fwrite($fh$stringData);

$stringData "$modversion['help'] = "";n";
fwrite($fh$stringData);

$stringData "$modversion['license'] = "GPL see LICENSE";n";
fwrite($fh$stringData);

$stringData "$modversion['official'] = 0;n";
fwrite($fh$stringData);

$stringData "$modversion['image'] = "$logo";n";
fwrite($fh$stringData);

$stringData "$modversion['dirname'] = "ehb_$modname";//name of directory on servern";
fwrite($fh$stringData);

$stringData "n";
fwrite($fh$stringData);

$stringData "// Admin thingsn";
fwrite($fh$stringData);

$stringData "$modversion['hasAdmin'] = 1;n";
fwrite($fh$stringData);

$stringData "$modversion['adminpath'] = "admin.php";n";
fwrite($fh$stringData);

$stringData "n";
fwrite($fh$stringData);

$stringData "// Menu/Sub Menun";
fwrite($fh$stringData);

$stringData "$modversion['hasMain'] = 0; //make 0 to not have this appear in main menun";
fwrite($fh$stringData);

$stringData "n";
fwrite($fh$stringData);

$stringData "?>";
fwrite($fh$stringData);
fclose($fh);
echo 
"new file has been created,";
//Now let's move it
rename("newxoopsversion.txt""../ehb_$modname/xoops_version.php");
echo 
"and moved to directory /modules/$modname/xoopsversion.php<br /><br />";

//Now we'll create the new index.php file
$myIndex "index.txt";
$fh fopen($myIndex'w') or die("can't open file");

$stringData "<?phpn";
fwrite($fh$stringData);

$stringData "include("../../mainfile.php");n";
fwrite($fh$stringData);

$stringData "include(XOOPS_ROOT_PATH."/header.php");n";
fwrite($fh$stringData);

$stringData "$xoopsOption['show_rblock'] = 1;n";
fwrite($fh$stringData);

$stringData "?>n";
fwrite($fh$stringData);

$stringData "Coming Soon!n";
fwrite($fh$stringData);

$stringData "<?phpn";
fwrite($fh$stringData);

$stringData "include(XOOPS_ROOT_PATH."/footer.php");n";
fwrite($fh$stringData);

$stringData "n";
fwrite($fh$stringData);

$stringData "?>";
fwrite($fh$stringData);
fclose($fh);
echo 
"new index file has been created,";
//Now let's move it
rename("index.txt""../ehb_$modname/index.php");
echo 
"and moved to directory /modules/ehb_$modname/index.php<br /><br />";
}
//All files that contain the below must keep the below to display in the XOOPS framework
include(XOOPS_ROOT_PATH."/footer.php");

?>



Isn't it some ugly code.

Incase you can't tell I am not a php coder, just a wannabe.

Here is the zip file:
modcreator.zip

Thanks,
Steve
s l s h a n k l e @ b e l l s o u t h . n e t

2
shank
Re: coding help needed I think.
  • 2006/5/21 17:53

  • shank

  • Not too shy to talk

  • Posts: 144

  • Since: 2004/8/17


here is some php debug info from the non working install.

Quote:

Warning [PHP]: mkdir(../ehb_XXX/): Permission denied in file modules/modcreator/generate.php line 22
Warning [PHP]: move_uploaded_file(../ehb_XXX/logo.gif): failed to open stream: No such file or directory in file modules/modcreator/generate.php line 30
Warning [PHP]: move_uploaded_file(): Unable to move '/tmp/php7CrNNx' to '../ehb_XXX/logo.gif' in file modules/modcreator/generate.php line 30
Warning [PHP]: fopen(newxoopsversion.txt): failed to open stream: Permission denied in file modules/modcreator/generate.php line 43
s l s h a n k l e @ b e l l s o u t h . n e t

3
shank
Re: coding help needed I think.
  • 2006/5/21 21:14

  • shank

  • Not too shy to talk

  • Posts: 144

  • Since: 2004/8/17


Nevermind, I figured it out.

Now if I could just figure out how to change the chmod of the created folder.


edited to add: scratch that too. I got it fixed.
s l s h a n k l e @ b e l l s o u t h . n e t

Login

Who's Online

185 user(s) are online (116 user(s) are browsing Support Forums)


Members: 0


Guests: 185


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits