Author Topic: PHP and/or Applescript Help  (Read 1145 times)

billy_gates

  • Member
  • **
  • Posts: 801
  • Kudos: 0
    • http://www.skinner.com/jeffberg
PHP and/or Applescript Help
« on: 19 July 2003, 05:44 »
I have a webdav server on my Mac.
 It is not the easiest thing to make a new webdav folder (for instance if someone wanted their own private space away from others)
 I wanted to know if it would be possible to make an Applescript or a PHP script that did the following...

made a new folder of my choosing in the /Library/WebServer/Documents folder.
 made a file called .htaccess in that folder with the following text.

        AuthName "My Own Name Here"
         AuthType Basic
         AuthUserFile /Library/WebServer/mynameduserfile

      require valid-user

then the script would have to run a
 sudo chown -R www:www /library/webserver/documents/mynewwebdavfolder

Then it would have to make a user file which is made by the command:
 sudo htpasswd -c /library/webserver/mynewuserfile username
 then it asks for a password and then it asks to confirm the password.

now the hardest part (I would assume) it to edit the /etc/httpd/httpd.conf file.  the text below would have to be added after the last </Directory>.  So where the last tag of </Directory> this text would be added

this text would have to be added to it

  #
         # Settings for My Own Name Here WebDAV
         #
         #
         <Directory "/Library/WebServer/Documents/myfoldername/">
                 DAV On
                 DAVMinTimeout 600
                 DAVDepthInfinity On

              AllowOverride AuthConfig
                 AuthName "My Own Name here"
                 AuthType Basic
                 AuthUserFile /Library/WebServer/mynewuserfile

              Require valid-user
         </Directory>

So I guess the variables that it would ask of me before the script would execute would be:

Name of DAV
 Name of the folder
 Name of the user file
 username
 password
 my administrator password for the sudo commands

------------------------------------------
Here is where I am so far.. on the Applescript side

set dd1 to display dialog "Enter a folder name" default answer "untitled"
 set dd2 to display dialog "Enter DAV Name" default answer "Untitled"
 set targFol to "Home:Sites nline:"
 set newFolName to text returned of dd1
 set davName to text returned of dd2
 set complete_ to false

repeat until complete_ is true
         try
                 tell application "Finder" to set newFol to (make new folder at folder targFol with properties {name:newFolName})
                 set complete_ to true
         on error
                 set newFolName to text returned of (display dialog "A folder named '" & newFolName & "' already exists in this location. Choose a new name." default answer "untitled")
         end try
 end repeat

set fileName to ".htaccess"
 set content_ to "\"AuthName \"davName\"  
 AuthType Basic  
 AuthUserFile /Library/WebServer/mynameduserfile  

require valid-user"

try
         set f to open for access file ((newFol as text) & fileName) with write permission
         write content_ to f
         close access f
 on error
         try
                 close access f
         end try
 end try

yes, I changed the location. that part doesn't matter.
 Now I have a dialog that asks for the foldername (the code u gave me)
 I added my own dialog that asks for the DAV Name to be placed in the .htaccess file
 As you probably know exactly why.  I can't get it to put the variable davName in the .htaccess, but instead it puts in davName.  How would I make it put in what davName is equivilant to?

Thanks in advance if you could help me.  As you can see I only have about the first step done. the actual folder.  Help editing the httpd.conf file would be the next step.

billy_gates

  • Member
  • **
  • Posts: 801
  • Kudos: 0
    • http://www.skinner.com/jeffberg
PHP and/or Applescript Help
« Reply #1 on: 20 July 2003, 10:49 »
well... with no thanks from you guys I got it. Thanks to the nice folks on the Apple Discussion Forums.
here is the code if anyone wants it:

--Variables and dialog boxes
set dd1 to display dialog "Please Enter DAV Name" default answer "DAV Name"
set davName to text returned of dd1
set dd2 to display dialog "Please Enter Folder Name" default answer "newfolder"
set newFolName to text returned of dd2
set dd3 to display dialog "Please Enter User File Name" default answer "users"
set userFile to text returned of dd3
set dd4 to display dialog "Please Enter UserName" default answer "username"
set userName to text returned of dd4
set siteDir to "/Library/WebServer/Documents/"
set siteDir2 to "Home:Sites nline:"
set webDir to "/Library/WebServer/"
set complete_ to false

--Makes the DAV Folder and makes the .htaccess File
repeat until complete_ is true
   try
      tell application "Finder" to set newFol to (make new folder at folder siteDir2 with properties {name:newFolName})
      set complete_ to true
   on error
      set newFolName to text returned of (display dialog "A folder named '" & newFolName & "' already exists in this location. Choose a new name." default answer "newfolder")
   end try
end repeat

--This gets typed into the .htaccess file
set fileName to ".htaccess"
set content_ to "AuthName \"" & davName & "\"" &