?
Solved

Access denied when using system() function.

Posted on 2006-05-01
9
Medium Priority
?
257 Views
Last Modified: 2012-05-05
I found the VBS file in system 32 folder for managing IIS6 metabase - its called iisweb.vbs and now im trying the following...

function Batch_File_Gen ($UserName,$DomainName){
     if (file_exists('jobs'.'/'.$UserName.'_'.$DomainName.'.bat')){
     die ('Error:  Batch File Already Exists - Website has probably already been generated!');
     }else{
          if (file_exists ('../../' . $UserName)){
          $Data = 'Iisweb /create D:\\websites\\whatever\\' . $UserName . ' "' . $DomainName . '" /d www.' . $DomainName;
          $fp = fopen ('jobs' . '/' . $UserName . '_' . $DomainName . '.bat',"w");
          fwrite ($fp,$Data);
          fclose ($fp);
          }else{
          die ('Error:  Username does not exist.  Please check and try again.');
                //because if username exists they will already have their own directory...
          }
     }
}

In another function i use system(); function to execute the batch files created using the above function... and it works!!  The only problem now is this:

-----------------------------
You cannot run this command because you are not an administrator on the server you are trying to configure.

-2147024891
-----------------------------

I tried giving IUSR_PCNAME admin rights to iisweb.vbs - and I still get the same error.  I also tried doing "runas" in the bacth file and still cant get access.  I even tried editing the vbs file to remove the access check altogether (risky but despeate).  This is where I got really confused - after commenting out the lines that check permission and saving the file - i still get the same error, so I went back to see the VBS file and the changes i had made had dissapeared!!!  Does Windows think I am a hacker and is it automatically restoring iisweb.vbs?

If I can prevent that then im sure the code will work fine...

Thanks for your help!

NIPPLES
0
Comment
Question by:NIPPLES
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:Joseph Melnick
ID: 16578997
Hello NIPPLES,

Have you looked at LIX. IIS Administration Functions?

There is a PHP extension for handling IIS administration for you.

http://www.php.net/manual/en/ref.iisfunc.php

Joseph Melnick
0
 
LVL 3

Author Comment

by:NIPPLES
ID: 16581460
Hi Joseph,

Thanks for pointing that out.  I just gave it a try and cant get it to work.  I am guessing that it doesnt work with IIS6.  I downloaded the dll file and adjusted php.ini correctly.  There are no errors about loading the extension - it does get loaded - just it doesnt do anything when i use the functions.

Im now this far with my "batch file generator" approach...

function Batch_File_Gen ($UserName,$DomainName){
      
            if (file_exists ('../../' . $UserName)){
            $Data = 'echo Generating Website From: ' . 'D:\\websites\\whatever\\' . $UserName . ' To: ' . $DomainName . "\r\n";
            $Data = $Data . 'Iisweb /create D:\\websites\\jv500\\' . $UserName . ' "' . $DomainName . '" /d www.' . $DomainName . ' >> ' . date("d_m_y") . '_executed.txt' . "\r\n";
            $Data = $Data . 'echo Adding Host Header For: ' . $DomainName . ' so it can also resolve from:  www.' . $DomainName . "\r\n";
            $Data = $Data . 'cscript //nologo translate.js "' . $DomainName . '" > siteid.txt' . "\r\n";
            $Data = $Data . 'for /f %%I in (siteid.txt) do SET SITEID=%%I' . "\r\n";
            $Data = $Data . 'Adsutil set w3svc/%SITEID%/serverbindings "202.190.198.11:80:www.' . $DomainName . '" ":80:www.' . $DomainName . '"' . "\r\n";
            $Data = $Data . 'Adsutil set w3svc/%SITEID%/serverbindings "202.190.198.11:80:' . $DomainName . '" ":80:www.' . $DomainName . '"' . "\r\n";
            $Data = $Data . 'Del siteid.txt' . "\r\n";
            $FileName = 'jobs' . '/' . date("d_m_y") .'.bat';
            $fp = fopen ($FileName,"a+");
            fwrite ($fp,$Data);
            fclose ($fp);
            print '<h3><b>Configuration saved as jobs' . '/' . date("d:m:y") .'.bat</b></h3><br>';
            print 'Configuration file now reads: <br><pre>';
            readfile ('jobs' . '/' . date("d_m_y") .'.bat');
            print '</pre><hr>Thank you,<br><em>Server Robot V1.0</em>';
            }else{
            die ('Error:  Username does not exist.  Please check and try again.');
            }
      
}

I have tested running the batch file and it works but im still disapointed i cant use system() to call the batch file.  Now everyday a batch file is created manually by an admin staff by using the above function - and i will still have to log in and directly run the batch file daily :o(

If I can just get the batch file to execute then it mission is completed!  Any ideas?

NIPPLES
0
 
LVL 11

Expert Comment

by:Joseph Melnick
ID: 16581996
I got some help a long while ago by the creator of that dll and I go it working properly. I recently lost my HD so I do not have those notes but I suspect that the anonymous internet user IUSER_* still does not have sufficient permission to execute functions contained therein. The DLL is loaded by the webserver process which has permission but the functions contained in teh DLL are system administration functions.

Hope thiis helps.

Joseph
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:NIPPLES
ID: 16583174
Hi Joseph,

Ah i see...  Possible work around is to call a custom VB program using the system command that in turn will execute the batch file!  I dont think it will fool the server but its worth a try...  

NIPPLES
0
 
LVL 3

Author Comment

by:NIPPLES
ID: 16583400
Nope... same problem there...

Maybe a rewrite of  iisweb.vbs and saving as a new file in new location with looser access permissions will work - rather than using the actual  iisweb.vbs (and getting access denied when exected from phps system() function....

0
 
LVL 11

Accepted Solution

by:
Joseph Melnick earned 500 total points
ID: 16585867
The Guy that was maintaining the pecl package and helped me was Frank Kromann you can see his tutorial on his homepage at: http://kromann.info/php.php

Joseph
0
 
LVL 3

Author Comment

by:NIPPLES
ID: 16730761
Hi jmelnick,

I managed to do a work around by using the batch file approach.  I schedule the batch files to run every hour on the server and the php web app generates the batch files for adding / removing websites in iis6.  

I still could not get the method you suggested to work - although it would be better as less layers of programs involved.

Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question