Jump to content

drkstr

Members
  • Posts

    66
  • Joined

  • Last visited

    Never

Everything posted by drkstr

  1. Just store the last page the user was at in a $_SESSION variable. regards, ...drkstr
  2. Well from what I have read so far, I think I might be able to do it this way. (keep in mind I'm still just tossing around ideas) I can write a shell script which starts a command and dumps the output as raw data to a file (well call it output.txt). It would over write any previous data, and delete the file when there is no more output. The PHP will run the shell script in the background, pause for a second or two, then start a while( file_exists("output.txt") ) loop which reads in the contents of the file, wraps XML tags around it, and makes it available as an XML object to the AJAX client script. The client side would then grab an update of the XML object being hosted on a predefined interval depending on the available bandwidth. Does this sound doable at all? Maybe there is an easier way? Thanks, ...drkstr
  3. I was afraid of this :( Unfortunately, it must be done one way or another. I will have to look into Ajax. Thanks for the tip! ...drkstr
  4. I don't know if that will do it for me, but I could be wrong. I need to have a continual stream open for the output. It's not a command that will just run once and send some output, I need to be able to display the output in real time while the process runs. Is this even possible? Thanks for the help! ...drkstr
  5. If I understand the code correctly, I think you should be able to add it to the def_fy function which appears to filter out text that is past to it. It would probably be the best place to put it. function def_fy( $text ) {   $text = preg_replace(       "#\~GetDEF\((\S*)\)\~#imseU",       "getDEF('$1')",       $text  ); [color=red]  if ( preg_match("/GetDEF/", $text) ) {     $text = "Not found!";   }[/color]   return $text; } If this still does not do it, post the actual output on a undefined word (text in the browser, and the html source that gets printed). It will be esier to trace the program when you look at the output. regards, ...drkstr
  6. [quote author=Satria Ox41464b link=topic=106190.msg424463#msg424463 date=1156915453] have you check http://php.net/outcontrol ? [/quote]No I didn't. Thanks, that looks like what I was looking for. [quote author=Jenk link=topic=106190.msg424526#msg424526 date=1156928577] Use shell_exec() instead of system(), shell_exec() returns all output as a string instead of directly outputting. [/quote]Awesome, thanks for the tip. So if I understand you two correctly, I can start the output buffer with ob_start(), read the output to the command in as a string, explode it into an array of lines by prex_split'ing at "/\n/", then if count > x amount of lines, array_shift the first element off the array, then implode it back to a string and print it to the output buffer? Thanks for the help everyone, ...drkstr
  7. I didn't read though all the code in detail, but are you printing the definition, or is it getting printed in a function that you don't have access to? If you are actually doing the printing, just do an if statement with a preg_match for something like "GetDEF" and not print if it finds it in the string. regards ...drkstr
  8. Hello, I need to be able to run some system commands and scripts which will have a lot of output. I would like to be able to not just it all dump to the screen in a long scrolling list. Is there some way to control the output and have it do things like when it reaches the max allowed lines, it just starts shifting up, erasing the top? I'm not afraid of reading, but I'm not sure where to start. Can someone point me in the right direction? Thanks! ...drkstr PS: I would also like to build a "shell consol" form that simulates a system shell in the browser. This will not happen until further down the road, but if anyone has any ideas about how to attack this problem, I would really like to hear them. Thanks again!
  9. You don't want to execute *any* programs if you don't have to. If the gui front end app is communicating fine with the test app, leave it the way it is. As far as the defunct process goes, can you describe exactly what you mean by this? Give details on what specificly you're experiencing. Is PHP hanging, is it running fine but not killing the process when you close PHP? also give the exact code you're using to start and stop the process. ...drkstr
  10. This might be with PHP 5, but I think you need to access your vars with: [code]      $this->a="A";       echo $this->a;       $this->b="B";       echo $this->a; [/code] regards, ...drkstr
  11. 1. If the application you're running does not require root privileges, run it as user "nobody" by calling it with 'sudo -u nobody your_application'. or 2. Use the "kill" method you mentioned earlier, except call it with 'sudo kill your_application'. This will require you to add user "nobody" to your /etc/sudoers file to enable that user to run the kill command as root without needing to supply a password. Just out of curiosity, how did you run the application as root to begin with? Did you do it with sudo, or is this a "feature" (bug) of PHP? When I run a command with popen, it runs as the user that apache runs under. regards, ...drkstr
  12. Any algorithum junkies out there? My algorithm I wrote takes about 20 seconds to run, but from what I can tell, it only goes though a few iterations. I'm pretty knew to PHP so maybe there are things I need to be carful of when iterating? Would anyone mind sanity checking it for me? Here is what I'm doing: The objects ------------------ DriveList properties:   private $myDisks = array(); #array of Disks Disk properties:   var $myDiskName; #device name of disk   var $myCyls; #number of cyllinders on disk   var $myHeads; #number of heads on disk   var $mySects;  #number of sectors per track   var $mySize;  #size of disk in bytes   var $myPartitions = array(); #array of partitions Partition properties:   var $myInfo = array(); DriveList Contains an array of Disks which contains an array of partitions: The algorithm -------------------- The DriveList constructor reads in the partition table from the disk and fills in the info accordingly. This part works fine (only takes 1 - 2 seconds to run). The problem is, I need the array of Partitions (contained in Disk) to be sorted by location on the Disk, not the device name. So I wrote a sorting algorithm but it greatly reduces the execution time. Note: the throwError function is just an error parsing routine I wrote for this project. Also note the following definitions: #define info we can get from partition. #'s represent array elements define('PNAME', 0);  # PNAME = Partition Name define('SCYL', 1);  # SCYL = Start Cyllinder define('ECYL', 2);  # ECYL = End Cyllinder define('PSIZE', 4);  # PSIZE = Partition Size in Kb (Blocks) define('FSTYP', 6);  # FSTYPE = File System Type [code]<?php #move new partition into correct place     $length = count($this->myPartitions);     if ( $this->myPartitions[$length-1]->myInfo[FSTYP] != 'Empty' ) { #if not Empty, sort by start cyllinder       $end = $length-1;       throwError("Primary Partition found at end = $end ".$this->myPartitions[$end]->myInfo[PNAME], DBG);       #sift partition down until SCYL of $end-1 is not larger       while ( ($end > 0) &&               ($this->myPartitions[$end]->myInfo[SCYL] < $this->myPartitions[$end-1]->myInfo[SCYL] ||               $this->myPartitions[$end-1]->myInfo[FSTYP] == 'Empty') # keep empty partitions at end of table             ) {         throwError("Primary Partition at end = $end ".$this->myPartitions[$end]->myInfo[PNAME].                   " is now end = ". ($end-1), DBG);         $tmpPart = $this->myPartitions[$end-1];         $this->myPartitions[$end-1] = $this->myPartitions[$end];         $this->myPartitions[$end] = $tmpPart;         $end--;       }     }     else { #if Empty partition, see if we can place it in some free space       $end = $length-1; $strt = -1;       throwError("Empty Partition found at end = $end ".$this->myPartitions[$end]->myInfo[PNAME], DBG);       do {         $strt++;         throwError("Checking for empty space at strt = $strt ".$this->myPartitions[$strt]->myInfo[PNAME], DBG);         #if this is the last item, see if space available at end of disk         if ( $this->myPartitions[$strt]->myInfo[FSTYP] == 'Empty' ) {           if ( $this->myPartitions[$strt]->myInfo[ECYL] < $this->myCyls - BUF ) {             throwError("end of disk is empy strt = $strt", DBG);             $this->myPartitions[$strt]->myInfo[SCYL] = $this->myPartitions[$strt-1]->myInfo[ECYL];             $this->myPartitions[$strt]->myInfo[ECYL] = $this->myCyls;             $this->myPartitions[$strt]->myInfo[FSTYP] = "Free Space";             break; #found what we were looking for           }         }         else if ( $this->myPartitions[$strt]->myInfo[ECYL] <  #if current partitions's end cyl is < the next partition's start cyl             $this->myPartitions[$strt+1]->myInfo[SCYL] - BUF ) {  #then must be free space (BUF is tollerance on misalignment)           throwError("Free space found after partition $strt ".$this->myPartitions[$strt]->myInfo[PNAME], DBG);           #start at the end and shift up to make room for insertion           $tmpPart = $this->myPartitions[$length-1];           for ($end = $length-1; $end > $strt+1; $end-- ) {             throwError("Sifting p $end " ." " .$this->myPartitions[$end]->myInfo[PNAME].                       " is now p " .($end-1), DBG);             $this->myPartitions[$end] = $this->myPartitions[$end-1];           }           #now that it's in place, update it's information           $this->myPartitions[$end] = $tmpPart;           $this->myPartitions[$end]->myInfo[SCYL] = $this->myPartitions[$end-1]->myInfo[ECYL];           $this->myPartitions[$end]->myInfo[ECYL] = $this->myPartitions[$end+1]->myInfo[SCYL];           $nSize = ($this->myPartitions[$end]->myInfo[ECYL] - $this->myPartitions[$end]->myInfo[SCYL])                   * ($this->myHeads) * ($this->mySects);           $this->myPartitions[$end]->myInfo[PSIZE] = $nSize;           $this->myPartitions[$end]->myInfo[FSTYP] = "Free Space";           break; #found what we were looking for         }       } while ( $strt < $length ); #failsafe if something goes wrong     } ?>[/code] Output: [code] ** Debug: Primary Partition found at end = 0 /dev/hda1 ** ** Debug: Primary Partition found at end = 1 /dev/hda2 ** ** Debug: Primary Partition found at end = 2 /dev/hda3 ** ** Debug: Primary Partition at end = 2 /dev/hda3 is now end = 1 ** ** Debug: Empty Partition found at end = 3 /dev/hda4 ** ** Debug: Checking for empty space at strt = 0 /dev/hda1 ** ** Debug: Checking for empty space at strt = 1 /dev/hda3 ** ** Debug: Free space found after partition 1 /dev/hda3 ** ** Debug: Sifting p 3 /dev/hda4 is now p 2 ***[/code] This is the partition table this output is based on:  from  popen( "sudo /usr/sbin/sfdisk -l | grep dev", "r" )[code]Disk /dev/hda: 19485 cylinders, 16 heads, 63 sectors/track /dev/hda1          0+    16463-  16464-  8297541  83  Linux /dev/hda2      18407+  19484    1078-    542902+  82  Linux swap /dev/hda3      16463+  18013-  1550    781200    83  Linux /dev/hda4          0              -      0          0        0    Empty [/code] Thanks for your time! ...drkstr
  13. ugh. I give up. I didn't take into account that the developers would try so damn hard to make the DOM classes as un flexible as possible. [quote]When I said I don't think it is possible I didn't mean the concept is flawed, I know it 'should' work, but I think it has been made impossible by the DOM recommendation.[/quote] I think your probably right there. Sorry for the wild goose chase. I used to use perl for this kind of programming so am really happy I stumbled across PHP. However, they lost a few points in my book for this. I really don't like it when a language tries to "protect" you from yourself. This is why I'm such a big fan of C/C++  ;D Well I'm going to keep trying to hack something up. I'm sure you'll here from me again. ...drkstr
  14. [quote author=jvalarta link=topic=105833.msg422861#msg422861 date=1156699578] You do need to tell PHP which variables are to be stored in the session, two ways to do this: session_register('var'); or $_SESSION['var'] (I believe session_register is the old method in which to do this) [/quote] I've always just assigned them without any registration, $_SESSION['var']="this is a string"; Is this not a preferred method? I'm only asking because I am also new to PHP and don't want to get into any bad habits from the beginning. Thanks! ...drkstr
  15. [quote]Im thinking I ned to set the upload fields as an array,. and then do some kinda foreach loop.[/quote]That's how you would do it. what part were you neading help with?
  16. [quote]Yeah, I know, I already did this, but it still doesn't work... I shouldn't need to register session or anything like that should I? Well, thanks anyway.[/quote]You need to start it on every page or tell your php.ini to do it automaticly. Ass far as the undefined thing goes, what data type is the variable your storing? If it is a data structure, you will need to serialize it first, then unserialize when you're ready to retrieve the data. http://us3.php.net/manual/en/function.serialize.php regards, ...drkstr
  17. Well I did a little reading reading up on all this DOM stuff. What a mess! The reason why you having the trouble is because none of the DOM classes have any public/protected data. This means you will have to access all the data through the mrthods that *did* get passed down. Oh, and how nice, they failed to provide a method for setting the DocType. Solution? Extend this from DOMDocument and overwide the two properties for $doctype and $implementation (I got the variable names from http://us3.php.net/manual/en/ref.dom.php ). [code]class YourClass extends DOMDocument  {   protected $doctype;   protected $implementation;   function __construct([your parameters]) {     parent::__construct();  #call the parent and them to initilize their data     $this->implementation = new DomImplementation;     $this->doctype= $domImpl->createDocumentType($rootName,$publicId,$systemId);    }[/code] Let me know how it turns out. I'm taking a shot in the dark here. regards, ...drkstr
  18. [quote]Above echoes 0...[/quote]Does it echo 0 when you use the place holder class correctly? I think this would classify as the "circular reference" they mention in the PHP docs. It might not like grabbing vars from an object that it's extended from. I strongly feel you should move away from the constructor init and just build a "pass though" object that just has a method to grab all the data. [quote]I'm starting to think this is not possible.[/quote]I would have to disagree. I am using this same method of initialization on my own object I created for this project I'm working on. Everything works just like it should. If you want to give me some test values for $rootName, $publicId, and $systemId, I can test it out myself instead of asking you a million "well what about this?" questions. The only major difference between mine and yours are the constructors (I use the old style apparently), and I use a member function to initialize the data. regards, ...drkstr
  19. Hmm, it works for me just fine. What's the exact code for the constructor, and what are you doing with the object? Are you serializing it by any chance? From http://www.php.net/manual/en/ref.session.php: [quote]Warning Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object). [/quote] This is a pretty big shortcoming of PHP if you ask me. If you are not serializing the object, what/when is it failing? I might be able to come up with a work around. regards, ...drkstr **edit** never mind on the serialization bit. I just realized that my object that uses the same method get's serialized and passed around in a $_SESSION variable. But if you could answer the second part of my question, I might be able to help.
  20. Use SSL (Secure Socket Layer) to encrypt all incoming/outgoing traffic from the web server. Then use a simple input protection scheme to prevent injection attacks. On my form, I don't need any special symbols, so I wrote a function that takes a string (user input) as a parameter, passes it through a preg_replace("\W", '', $string) and returns it. This will remove alsl charecters that is not alpanumeric or an underscore. If you need any other special symbols, you should deny all and explicitly allow the ones you need. Also, check out the crypt function for storing data. regards, ...drkstr
  21. I've been reading up on javascript, and I noticed that checkbox elements are are accessed through an array ( form.elements[num].value. Do I need to do the same with the radio buttons? If so, what's the easiest way to see which element is checked? Or should I just loop though until I find it? Thanks! ...drkstr
  22. [quote author=radalin link=topic=105572.msg421872#msg421872 date=1156504561] replace this: [code] <input type="radio" name="selectedUser" value="admin" />admin<br> [/code] with [code] <input type="radio" name="selectedUser" id="selectedUser" value="admin" />admin<br> [/code] and do the changement for every radio button. your form tag should be [code] <form id="selectUserForm" ....> [/code] then in your js change [code] var strName = selectUserForm.selectedUser.value; [/code] with [code] var strName = document.getElementById('selectUserForm').selectedUser.value; [/code] it should work [/quote] Thanks for the help radalin. It's still coming back undefined though. This is now what's getting printed to the html source: [code]//note: < > removed from SCRIPT tags since it wouldn't let me post it like that SCRIPT language="javascript" function callEditUser( selectUserForm ) {   var strName = document.getElementById('selectUserForm').selectedUser.value;   var url = "/edit_user.php?name="+strName;   document.write(url); // window.open(url, "_self"); } function callDeleteUser( selectUserForm ) {   var strName = document.getElementById('selectUserForm').selectedUser.value;     var url = "/delete_user.php?name="+strName;     document.write(url);   // window.open(url, "_self");   } } /SCRIPT[/code] [code]<!-- note: select_user.php is this file --> <form id="selectUserForm" action="/select_user.php" method="POST"> <input type="radio" name="selectedUser" id="selectedUser"  value="admin" />admin<br> <input type="radio" name="selectedUser" id="selectedUser"  value="drkstr" />drkstr<br> <br /> <input type="button" value="Edit" onclick="javascript:callEditUser(this.form)" /> <input type="button" value="Delete" onclick="javascript:callDeleteUser(this.form)" /> </form>[/code]Did I miss something small? Thanks again! ...drkstr
  23. Membership database as in a database of users? I had to cook one up for my php project so threw something together. It won't work by itself since it uses some other classes/functions I wrote, but maybe it will give you an idea on where to start. note: I'm pretty new to PHP, use at your descretion. [code]<?php # user-lib.php (libs) # functions / classes for kitool users include_once("$ROOT/kitool-lib.php"); # kitools user class class User {   # user data   private $myName;   private $myPass;   private $myLoginStatus;   # class initialization (default = Null name/password)   function User( $name = "", $pass = "" ) {     $this->myName = $name;     $this->myPass = crypt($pass);     $this->myLoginStatus = False;   }   # return user name   function getName() {     return $this->myName;   }   # return encrypted password   function getPass() {     return $this->myPass;   }   function isLoggedIn() {     return $this->myLoginStatus;   }   function changePass( $newpass ) {     $this->myPass = crypt($newpass);   }     # reads user from database and assign to this user if password matches   # Then return True, otherwise returns False   function loginUser( $name, $pass ) {       $newUser = new User();     if (! $newUser = readUser($name) ) { #can we get a user from the DB?       throwError("Invalid username and/or password.", STD);       return False;     }     if ( crypt($pass, $newUser->getPass()) != $newUser->getPass() ) { #does the password match?       throwError("Invalid username and/or password.", STD);       return False;     }     #get each property of the new user and assign it to this user     if ( get_class($newUser) != get_class($this) ) {       throwError("Invalid item recieved from databse, could be corrupted", CRI);       return False;     }     $arUserVars = get_object_vars($newUser);     foreach ($arUserVars as $key => $data) {       $this->$key = $data;     }     $this->myLoginStatus = True;     $_SESSION['user'] = serialize($this); #register user in session environment     return True;   }   function logoutUser() {     $this->myLoginStatus = False;     $_SESSION['user'] = ""; #unregister user in session environment   } } # add user to data base. returns True if sucsesfull, otherwise false function addUser( $name, $pass ) {   $user = new User($name,$pass);   if ( $dbUsers = dba_open( getUserDBFile(), "c", "gdbm" ) ) {  #can we open database?     if ( dba_exists($user->getName(), $dbUsers) ) {  #does the user allready exist?       dba_close($dbUsers);       throwError("The user $name allready exists", STD);       return False;     }     else {       dba_insert( $user->getName(), serialize($user), $dbUsers );       dba_close($dbUsers);     }   }   else {     throwError("Failed to open user database file for writing", NCR);     return False;   }   return True;  #if all went well } # returns user in database that matches name # or returns False if fialed function readUser( $name ) {   $user = new User();   if ( ! $dbUsers = dba_open( getUserDBFile(), "r", "gdbm" ) ) {     throwError("Could not open user database file for reading.", CRI);     return False;   }   if ( ! dba_exists($name, $dbUsers) ) {     dba_close($dbUsers);     return False;   }   else {     $user = unserialize(dba_fetch( $name, $dbUsers ));     dba_close($dbUsers);   }   return $user;  # all went well } #delete selected user.  returns true if sucsessfull, otherwise False function deleteUser( $name ) {   if ( ! $dbUsers = dba_open( getUserDBFile(), "w", "gdbm" ) ) {     throwError("Could not open user database file for writing.", NCR);     return False;   }   if ( ! dba_exists($name, $dbUsers) ) {     dba_close($dbUsers);     throwError("User: " .$name. " does not exist in the database.", NCR);     return False;   }   else {     dba_delete($name, $dbUsers);     dba_close($dbUsers);     return Null;   }   return True;  #all went well } # update user in database returns false if failed, function updateUser( $user ) {   $user->logout();  # never save an authenticated login status   if ( ! $dbUsers = dba_open( getUserDBFile(), "w", "gdbm" ) ) {     throwError("Could not open user database file for writing.", NCR);     return False;   }   dba_replace($user->getName(), $user, $dbUsers);   dba_close($dbUsers);   return True; } # returns a sorted array of usernames or False if failed function retriveAllUserNames() {   $arNames = array();   if (! $dbUsers = dba_open( getUserDBFile(), "r", "gdbm" ) ) {     throwError("Failed to open user database file", NCR);     return False;   }   else { # get each key (username) from database and add to an array     $strKey = dba_firstkey($dbUsers);     array_push($arNames,$strKey);     while ( $strKey = dba_nextkey($dbUsers) ) {       array_push($arNames,$strKey);     }   }   dba_close($dbUsers);   sort($arNames);     return $arNames; # all went well } ?>[/code] regards, ...drkstr **edit** By the way, if any one can offer any improvements, please share
  24. [code]DomXhtml extends DomXml, and it's fine that way.[/code] ah, I must of missed that part. You're right, there isn't really any need for the placeholder class if you will not be making a bunch of different types of DOMDocument. OOP is always a trade off between modularity and simplicity. Sometimes it's more trouble then it's worth  ;) Glad I was able to help, I needed to do something similar and had fun trying to figure out a solution. ...drkstr
  25. Hello, sorry for the dumb question, but my js is working like I was expecting it to. I know nothing about javascript, but I need to use it in my php script since there is no easy way to do what I need without it. What I need to do is print out a list of radio buttons, then have a few buttons at the bottom of the form with onclick's that call the apropriate function with this.form as a parameter. I then need to find out which radio button was selected by accessing the value in the function. However, it comes back undefined. [code]<form action="select_user.php" method="POST"> <?php #print selection list of users. note: select_user.php is this file $arNames = retriveAllUserNames(); # get a list of users from DB foreach ( $arNames as $strName) {  # assign elemnt in array to $strName until none left   print "<input type=\"radio\" name=\"selectedUser\" value=\"" .$strName. "\" />" .$strName;   print "<br>\n"; }?> <br /> <input type="button" value="Edit" onclick="javascript:callEditUser(this.form)" /> <input type="button" value="Delete" onclick="javascript:callDeleteUser(this.form)" /> </form>[/code] My Java script section looks like this. [code]function callEditUser( selectUserForm ) {   var strName = selectUserForm.selectedUser.value;   var url = "edit_user.php?name="+strName   document.write(url);  //debug // window.open(url, "_self"); } function callDeleteUser( selectUserForm ) {   var strName = selectUserForm.selectedUser.value;   if (confirm(strConfirmMsg) ) {     var url = "delete_user.php?name="+strName     document.write(url);  //debug   // window.open(url, "_self");   } }[/code] This is what prints to the screen when I hit a button: edit_user.php?name=undefined This is how actually get's printed (from view->source in browser) [code]<form action="/select_user.php" method="POST"> <input type="radio" name="selectedUser" value="admin" />admin<br> <input type="radio" name="selectedUser" value="drkstr" />drkstr<br> <br /> <input type="button" value="Edit" onclick="javascript:callEditUser(this.form)" /> <input type="button" value="Delete" onclick="javascript:callDeleteUser(this.form)" /> </form>[/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.