473,756 Members | 5,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is this a PHP script?? BASH?? Please review!

Hi

I've been given what I am told is a PHP script to be used on my server. I
do not know any PHP.

I am trying to use a feature of a program called ArchiCAD. This feauture
allows CAD drawing files to be published on a webpage, and viewed and
commented on using a java applet.

The problem is that with ArchiCAD v10, it now makes spaces and uses other
URL unfriendly characters in the filenames, making this feature not
properly.

This is an example of the faulty output:
http://test404.damnserver.com
Following is what I have been told is a PHP script. It is meant for a
freebsd or MacOS server. It apparently unpacks a zip file, deletes some
temp files that MacOS makes, and renames the files to make them URL
friendly. It then edits the Content.xml file with the filename changes.

First of all, is this actually a PHP script? I need it to run on a Windows
server running IIS. But someone that I gave it to look at has said that he
thinks that it does some strange functions, and he thinks it's actually a
BASH file, and I have no hope of getting it to run on Windows.

I need something that does the same thing for a Windows server running the
website linked earlier. I also do not want the unzip function, and it needs
to be taken out.

I would be grateful for any thoughts or opinion on this.

Cheers.

_______________ _______________ _______________ _______________ _________

function process_gpr($zi p_file, $record_folder_ location) #opens the zip,
makes it web safe
{
if(!ini_get('up load_tmp_dir')) #check php's upload_tmp_dir
{ #if it's not in the ini set it to this value
$upload_tmp_dir = '/var/tmp/';
}
else
{ #otherwise use the ini value
$upload_tmp_dir = ini_get('upload _tmp_dir');
}

$upload_tmp_dir = $upload_tmp_dir . "php/"; #make our own little folder for
unzipping
if(!file_exists ($upload_tmp_di r)) { shell_exec("mkd ir " .
$upload_tmp_dir ); }
if(!shell_exec( "rm -Rf " . $upload_tmp_dir . "*")) #clean it out; if that
went smoothly
{ #unzip the zip file
shell_exec("unz ip -d " . $upload_tmp_dir . " " . $zip_file);

#zip's from osx's finder create this metadata folder
$macosx_only1 = $upload_tmp_dir . "__MACOSX"; #delete it if present
if(file_exists( $macosx_only1)) { if(is_dir($maco sx_only1)) {
shell_exec("rm -Rf " .
$macosx_only1); } }
$macosx_only2 = $upload_tmp_dir . ".DS_Store" ; #and this file too
if(file_exists( $macosx_only2)) { if(is_file($mac osx_only2)) {
shell_exec("rm -Rf " .
$macosx_only2); } }

#find the Reviewer folder in the expanded tree
if(preg_match('/(\/.*\/)Reviewer/i', shell_exec("fin d " . $upload_tmp_dir .
" -type d -name
Reviewer"), $matches))
{ #find the enclosing folder
$gpr['path'] = $enclosing_fold er = $matches[1];

if($dh = opendir($enclos ing_folder)) #open the enclosing folder
{
while(($file = readdir($dh)) !== false) #read it out
{
if((filetype($e nclosing_folder . $file) == "dir") && ($file !== "Reviewer")
&& ($file !==
".") && ($file !== ".."))
{ #find the data folder
$gprf = $file . "/";
}
if((filetype($e nclosing_folder . $file) == "file") && (substr($file, -5) ==
".html") &&
($file !== ".") && ($file !== ".."))
{ #find the html file and rename it
preg_match("/(.+)\..*?$/i", $file, $name);
$gpr['title'] = $name[1]; #save that title for later
rename($enclosi ng_folder . $file, $enclosing_fold er . 'gpr.html');
}
}
closedir($dh); #close the enclosing folder

#create the folder name
$gpr['file_name'] = $gpr['title'] . "-" . date("Y-m-d") . ".gpr";
#find the real filepath leading up to where we're placing it
preg_match("/(\/.*\/)rianachd\/.+\..+/i", $_SERVER['PATH_TRANSLATE D'],
$project_folder _full_path);
$project_folder _full_path = $project_folder _full_path[1] .
substr($record_ folder_location , 3)
.. "/" . $gpr['file_name'] . "/" . $gpr['title'] . "/";
#echo "<h6>project_fo lder_full_path: $project_folder _full_path</h6>";
$gprf = $enclosing_fold er . $gprf; #set this to data folder
$catalog = $gprf . "Catalog.xm l"; #path to catalog file
if($handle = fopen($catalog, "r"))
{ #read out contents of the catalog file
$contents = fread($handle, filesize($catal og));
#replace stupid characters in set, path, title and layout links & titles
#$contents = gpr_replacer($c ontent, $regex, $character, $replacement);
$contents = gpr_replacer($c ontents, "/\<Set\>(.*?)\< \/Set\>/i", "", "_");
$contents = gpr_replacer($c ontents, "/\<Set\>(.*?)\< \/Set\>/i", "", "_");
$contents = preg_replace('/path="(.*?)"/i', 'path="' .
$project_folder _full_path . '"',
$contents);
# $contents = gpr_replacer($c ontents, "/title=\"(.*?)\"/i", "", "_");
$contents = gpr_replacer($c ontents, "/href=\"(.*?)\"/i", "", "_");
$contents = gpr_replacer($c ontents, "/\<Set\>(.*?)\< \/Set\>/i", "&amp;",
"AND");
# $contents = gpr_replacer($c ontents, "/title=\"(.*?)\"/i", "&amp;", "AND");
$contents = gpr_replacer($c ontents, "/href=\"(.*?)\"/i", "&amp;", "AND");

if($handle = fopen($catalog, "w+"))
{ #write out contents and close file
fwrite($handle, $contents);
fclose($handle) ;

if($handle = opendir($gprf))
{ #open the data folder
#shell_exec("mk dir " . $gprf . "/redline");
while (($file = readdir($handle )) !== false)
{
if (($file !== ".") && ($file !== "..") && (substr($file, 0, 1) !== '.') &&
(substr($file,
-4) == '.DWF'))
{ #change the characters of .DWF's here too
$newfile = gpr_replacer($f ile, "/(.*)/i", "", "_");
#newfile is necessary, because the name has been changed after the first
rename
rename($gprf . $file, $gprf . $newfile);
rename($gprf . $newfile, $gprf . gpr_replacer($n ewfile, "/(.*)/i", "&",
"AND"));
#once everything has been done, add a value to the success var
$success++;
}
} #close the data folder
closedir($handl e);
}
}
}
}
}
}
#return array of file_name, title, and path
if($success) { return $gpr; } else { return false; }
}

function gpr_replacer($c ontents, $regex, $character, $replacement) #
{ #if no replacement string is passed, use these
if(!$character) { $character = array("'", '"', ",", "=", "/", " "); }
#match the regular expression
preg_match_all ($regex, $contents, $contents_match es, PREG_SET_ORDER) ;
$contents_match es_cnt = count($contents _matches);
if($contents_ma tches_cnt) #if matches 0
{
for($i=0; $i<$contents_ma tches_cnt; $i++) #do for each match
{ #replace the found string
$insert = str_replace($ch aracter, $replacement, $contents_match es[$i][1]);
$contents = str_replace($co ntents_matches[$i][1], $insert, $contents);
}
}
#return results
return $contents;
}

Oct 26 '06 #1
9 2003
"Synapse Syndrome" <sy*****@NOSPAM gomez404.elitem ail.orgwrote in message
news:wL******** ************@bt .com...
Hi

I've been given what I am told is a PHP script to be used on my server. I
do not know any PHP.
Based on reading the script you provided, it appears to be PHP.

You can find more information about PHP, including function definitions,
language syntax, etc. at:

http://www.php.net

I've left many questions unanswered. I'll leave that for other posters.

Dave.

Oct 26 '06 #2
"Synapse Syndrome" <sy*****@NOSPAM gomez404.elitem ail.orgwrote in message
news:wL******** ************@bt .com...
Hi

I've been given what I am told is a PHP script to be used on my server. I
do not know any PHP.
As I mentioned in my previous post, it appears to be PHP.
This is an example of the faulty output:
http://test404.damnserver.com

Following is what I have been told is a PHP script. It is meant for a
freebsd or MacOS server. It apparently unpacks a zip file, deletes some
temp files that MacOS makes, and renames the files to make them URL
friendly. It then edits the Content.xml file with the filename changes.

First of all, is this actually a PHP script?
Yes.
I need it to run on a Windows server running IIS.
You should be able to do this. The script isn't that complicated. You
should be able to reimplement it using a M$-friendly language, such as .ASP.

PHP does run under Windows, but it might be easier to go with the M$ tool
chain.
But someone that I gave it to look at has said that he thinks that it does
some strange functions.
At first glance, the script looks rather standard. I'm not seeing any
"strange functions".
and he thinks it's actually a BASH file.
It is not a BASH file. This is guaranteed PHP. I see many PHP functions in
the script ... it is PHP.
>and I have no hope of getting it to run on Windows.
The script is not that complicated. Just go through it line-by-line, look
up all the functions at http://www.php.net, and see what you can do on
Windows. You can either use PHP under Windows or reimplement some other
way, perhaps .ASP.
I need something that does the same thing for a Windows server running the
website linked earlier. I also do not want the unzip function, and it
needs to be taken out.

I would be grateful for any thoughts or opinion on this.
Reverse-engineer and reimplement.

Oct 26 '06 #3
Rik
David T. Ashley wrote:
"Synapse Syndrome" <sy*****@NOSPAM gomez404.elitem ail.orgwrote in
message news:wL******** ************@bt .com...
>Hi

I've been given what I am told is a PHP script to be used on my
server. I do not know any PHP.

As I mentioned in my previous post, it appears to be PHP.
It is indeed.
>I need it to run on a Windows server running IIS.

You should be able to do this. The script isn't that complicated.
You should be able to reimplement it using a M$-friendly language,
such as .ASP.

PHP does run under Windows, but it might be easier to go with the M$
tool chain.
Well, in PHP it's just that easy.
The problem here is the script highly relies on shell_exec() for some
things (that needn't be shell functions, and mostly can be handled by
native PHP functions.
>But someone that I gave it to look at has said that he thinks that
it does some strange functions.

At first glance, the script looks rather standard. I'm not seeing any
"strange functions".
I think he's talking about the shell_exec()'s.
>and I have no hope of getting it to run on Windows.

The script is not that complicated. Just go through it line-by-line,
look up all the functions at http://www.php.net, and see what you can
do on Windows. You can either use PHP under Windows or reimplement
some other way, perhaps .ASP.
Yup, it's a fairly easy script. I wouldn't do it for free though :-).
--
Rik Wasmus
Oct 26 '06 #4
Hmmmm...well, as everyone has already pointed out, it is a PHP script.
But as written, it will NOT run under Windows, because the shell
commands are Linux/Unix commands. You will need to replace these
commands with their DOS equivalents. If, however, you have Cygwin or
something similar installed on your Windows machine, it may run just
fine as-is.

Given that someone else wrote this script and gave it to you under the
pretense of trustworthiness , my only advice would be to pay close
attention to the shell commands. Although they might turn out to be
totally innocuous, I'm suspicious of anything that performs "rm -rf"
and wouldn't be so quick to install it on my production systems without
knowing for sure what the consequences are.

Just my two cents. :)

Geoffrey

Oct 26 '06 #5

"David T. Ashley" <dt*@e3ft.comwr ote in message
news:k2******** ************@fe 38.usenetserver .com...
"Synapse Syndrome" <sy*****@NOSPAM gomez404.elitem ail.orgwrote in message
news:wL******** ************@bt .com...
>Hi

I've been given what I am told is a PHP script to be used on my server.
I do not know any PHP.

As I mentioned in my previous post, it appears to be PHP.
>This is an example of the faulty output:
http://test404.damnserver.com

Following is what I have been told is a PHP script. It is meant for a
freebsd or MacOS server. It apparently unpacks a zip file, deletes some
temp files that MacOS makes, and renames the files to make them URL
friendly. It then edits the Content.xml file with the filename changes.

First of all, is this actually a PHP script?

Yes.
>I need it to run on a Windows server running IIS.

You should be able to do this. The script isn't that complicated. You
should be able to reimplement it using a M$-friendly language, such as
.ASP.

PHP does run under Windows, but it might be easier to go with the M$ tool
chain.
>But someone that I gave it to look at has said that he thinks that it
does some strange functions.

At first glance, the script looks rather standard. I'm not seeing any
"strange functions".
>and he thinks it's actually a BASH file.

It is not a BASH file. This is guaranteed PHP. I see many PHP functions
in the script ... it is PHP.
>>and I have no hope of getting it to run on Windows.

The script is not that complicated. Just go through it line-by-line, look
up all the functions at http://www.php.net, and see what you can do on
Windows. You can either use PHP under Windows or reimplement some other
way, perhaps .ASP.
>I need something that does the same thing for a Windows server running
the website linked earlier. I also do not want the unzip function, and
it needs to be taken out.

I would be grateful for any thoughts or opinion on this.

Reverse-engineer and reimplement.
Thanks for your comments. The only problem is that I have no real
programming skill. I just know some HTML/CSS coding, so adjusting this code
to run on Windows looks pretty difficult to me, let alone translating to
..ASP.

But, ideally, I wouild like it to run on .ASP, as my webserver is already
running that.

How long do you think it would take a beginner to go through this script and
get it running on Windows as PHP?

Cheers.

ss.
Oct 27 '06 #6

"Rik" <lu************ @hotmail.comwro te in message
news:28******** *************** ***@news2.tudel ft.nl...
>
Yup, it's a fairly easy script. I wouldn't do it for free though :-).

Thanks for you comments. Do you think it it wouldn't take that long for a
beginner to get it running on Windows with PHP?

ss.
Oct 27 '06 #7

"Geoffrey" <go***********@ yahoo.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Hmmmm...well, as everyone has already pointed out, it is a PHP script.
But as written, it will NOT run under Windows, because the shell
commands are Linux/Unix commands. You will need to replace these
commands with their DOS equivalents. If, however, you have Cygwin or
something similar installed on your Windows machine, it may run just
fine as-is.

Given that someone else wrote this script and gave it to you under the
pretense of trustworthiness , my only advice would be to pay close
attention to the shell commands. Although they might turn out to be
totally innocuous, I'm suspicious of anything that performs "rm -rf"
and wouldn't be so quick to install it on my production systems without
knowing for sure what the consequences are.

Thanks. Just as a quick pointer, what would be the command to replace teh
shell_exec() commands, so I can read about it? I know DOS pretty well.

ss.
Oct 27 '06 #8
As a person that was a beginner at this not that long ago, I think you
should expect it to take quite a bit of time, like days, for instance.
These are the difficulties I have found in starting out in php:

1. Getting a sense of the internal logic of php and the internal logic
of coding if you haven't done this before takes some time. For me, it
was not always instinctual or obvious how things worked. Things are
also not necessarily consistent and I find that there seem to be things
that experience programmers think are obvious that it is really hard
for me to get. There is a lot of stuff carried over from C or java
that people familiar with other languages understand that can seem
crazy to the unititiated.

2. Finding out what is possible and how to do it is often a challenge
and is related to the last comment. My experience is that php.net is
more useful once you understand php than when you are starting. It is
not always obvious to me how to even formulate the question I want
answered. And php seems to search and index around functions.
Operators and conventions are often hard to find.

3. Debugging, e.g. finding the missing period or quotation mark or
curly brace can take hours or even days. It is always startling to me
how the simplest synatactical error can completely break a script. I
would say the biggest leap forward for me in php programming was
learning how to troubleshoot a script in a finite amount of time. You
could be right on target with a minor syntactical error or you could
have missed the mark a mile with your script and in either case, it
won't work at all. In html it breaks or works wrong, giving you some
clues. In php, you just get a rejection.

4. Ask other people for help, but only after you have tried to come up
with a solution yourself. I have found people on this list and others
to be very supportive. It is important to formulate your questions
clearly and specifically and to have done some work yourself first to
solve your problem. It can be helpful as well, when you are starting
out on something to see if people can point you in the right direction.
Then try to implement it yourself and if it doesn't work, ask more
questions.

5. I think doing what you want to do would be a challenge for someone
with no experince with php. And this script also seems to require an
understanding of unix and DOS and the way they relate to each other and
to php. And anything that has to do with Windows or Microsoft seems to
me to amplify any kind of interface issue with other systems, as
Microsoft seems to have an anti-body against interfacing with anything
not Microsoft. I avoid Microsoft like the plague.

6. Get a MAC! They talk with everyone.

Good luck,

--Kenoli
Synapse Syndrome wrote:
>
How long do you think it would take a beginner to go through this script and
get it running on Windows as PHP?

Cheers.

ss.
Oct 27 '06 #9
Rik
Synapse Syndrome wrote:
"Rik" <lu************ @hotmail.comwro te in message
news:28******** *************** ***@news2.tudel ft.nl...
>>
Yup, it's a fairly easy script. I wouldn't do it for free though :-).


Thanks for you comments. Do you think it it wouldn't take that long
for a beginner to get it running on Windows with PHP?
Well, this particular script? In my early starting days, it would have
taken me a couple of days perhaps. Certainly if you want the skip in
unzipping option, which is most of the work, it could even be done in a day
by a beginner. 'Beginner' in this is someone who is mildly familiar with
PHP, but hasn't really used it yet. If beginner ment 'never coded and never
looked at PHP code', it highly depends on who it is/how fast he/she picks
up things etc...
--
Rik Wasmus
Oct 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3493
by: Bernhard Kuemel | last post by:
Hi! To relief the problems of accessing a unix machine from behind a restrictive firewall or from an internet cafe I started to make a PHP web interface to bash. I'd like to hear your opinions and advice about my concept, especially regarding security. There is already such a thing (http://www.rohitab.com/cgiscripts/cgitelnet.html). However, it lacks interactive input to programs. To fix this I'd use a frame
5
2997
by: Phil Powell | last post by:
I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure out how to do this in bash script as the requirement is necessary for a migration script to obtain the code from a .cfg file and then be able for the "parent" script to run the code it "imported" from the .cfg file, much like PHP's require() or...
2
2091
by: john | last post by:
Newbie about this stuff. I want to run some php scripts from a shell script(bash?) the php script i want to run is this: test.php and it's path is this: home/virtual/blahblah.com/home/abc/mainwebsite_html/bluhbluh/dbtest/
4
3275
by: Tom Purl | last post by:
I just wrote a Python script that is going to be called from bash script. If the Python script fails, I want the bash script to also stop running. Unfortunately, I can't seem to get that to work. Here's the script so far: # custom python script /usr/bin/python /home/username/Dev/Python/packZODB.py \ -s"gsgmc.sigma.zettai.net" -b 7 # next program
11
2993
by: Magnus Jonneryd | last post by:
Hi, I'm planning on writing a program that interactively is fed input via a shell (bash). I also want to be able to write a shell script that executes various commands related to my program. In short i want to provide input to a program using some (or all) of the functionality found in bash. It's mainly the format of the file I'm having trouble with. I wanted to be able to write something like this: #!/bin/bash for x in xs
6
3946
by: Ishpeck | last post by:
I'm using Python to automate testing software for my company. I wanted the computers in my testing lab to automatically fetch the latest version of the python scripts from a CVS repository and then ask a local database server which of the scripts to run. I built the following: #!/bin/bash # Batcher will run the specified scripts.
4
3578
by: melmack3 | last post by:
Hello My PHP script executes many bash/cmd commands. Functions like "exec()" or "system()" cause that new bash/cmd session is started, the command is executed and the session is closed. Unfortunately it is very slow process so I would like to increase performance and open one bash/cmd session on the begin of my script and execute the commands such as in normal system opened bash/cmd window and close it
1
2996
by: Gros Bedo | last post by:
Yes I've seen that each python script calls its own instance of Python. Buthow to know which is the good one in bash ? Is there a command that gets the parameters of process, so I could use grep to select the one containing the name of my script ? _________________________________________________________________ Votre contact a choisi Hotmail, l'e-mail nouvelle génération. Créezun compte. http://www.windowslive.fr/hotmail/default.asp
0
2024
by: norseman | last post by:
Gros Bedo wrote: ============================== Yes. man ps explains try ps -AFL | grep then kill -9 found (check it more than twice) 1) If your script is known to hang use what another wrote: py s.py tokens & capture=$! (get the PID ready)
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.