
niwa3836
Members-
Posts
42 -
Joined
-
Last visited
Never
Everything posted by niwa3836
-
Try unpicking some of this and see if it helps....sorry not pretty...looks like you are not creating a shell? (this is for a Cisco PGW but should work with any SSH2 requirements... let me know how you get on! function PGWscripts($pgwCommandString) { // ------------------- PARAMETERS $Dontrun = 0 ; // set to 1 to avoid actually performing the script $Flush = 0 ; // Normal value is 0 for TDT use (flush kills http headers) $SSH_debug = 1 ; // Yes we want debugs! $SSH_usleep = 1000000 ; // 0.5 sec $SSH_IPaddress = "<removed>" ; // The PGW address to connect to via SSH2 // $SSH_username = "removed" ; // The PGW user // $SSH_password = "removed" ; // The PGW password baa#123 $SSH_username = "removed" ; // The PGW user $SSH_password = "removed" ; // The PGW password baa#123 // $SSH_username = "mgcusr" ; // The PGW user // $SSH_password = "cisco" ; // The PGW password baa#123 // -------------------------------------- niwaWriteLog("PGWscripts: Process Start command string [" . $pgwCommandString . "]","Diag") ; $j = 0 ; $pgwSingleCommand = explode("*",$pgwCommandString) ; while(isset($pgwSingleCommand[$j])) { if($pgwSingleCommand[$j] != NULL || $pgwSingleCommand[$j] != "") niwaWriteLog("PGWscripts: Command [".$j."] is [".$pgwSingleCommand[$j]."]","Diag") ; $j++ ; } // end of while niwaWriteLog("SSH: *** PGW connection, IP Address [" . $SSH_IPaddress . "]","Diag") ; if($Dontrun) // -------------------------------------------- DEBUG ONLY ---------------------------------- { niwaWriteLog("PGWscripts: *************** WARNING DEBUG BREAK OUT IS TURNED ON, NO COMMANDS SENT","Diag") ; return 999 ; } // -------------------------------------------- DEBUG ONLY ---------------------------------- $returncode = 0 ; if (!($resource=@ssh2_connect($SSH_IPaddress))) { // echo "[FAILED]<br />"; if($SSH_debug) niwaWriteLog("SSH: Failed IP connection","Diag") ; return(50); } //echo "[OK]<br />"; if($SSH_debug) niwaWriteLog("SSH: Connected to IP Address [" . $SSH_IPaddress . "]","Diag") ; // Authentification by login/passwd //echo "Authentification "; if($SSH_debug) niwaWriteLog("SSH: Attempt login with username [" . $SSH_username . "]","Diag") ; if (!@ssh2_auth_password($resource,$SSH_username,$SSH_password)) { // echo "[FAILED]<br />"; if($SSH_debug) niwaWriteLog("SSH: Failed to login","Diag") ; return(51); } // echo "[OK]<br />"; if($SSH_debug) niwaWriteLog("SSH: Login OK with username [" . $SSH_username . "]","Diag") ; // We need a shell // echo "Shell stdio "; if($SSH_debug) niwaWriteLog("SSH: Now require SHELL","Diag") ; if (!($stdio = @ssh2_shell($resource,"xterm"))) { // echo "[FAILED]<br />"; if($SSH_debug) niwaWriteLog("SSH: Failed to acquire XTERM SHELL","Diag") ; return(52); } // echo "[OK]<br />"; if($SSH_debug) niwaWriteLog("SSH: SHELL acquired OK","Diag") ; // mml connection // Be careful to add an '\n' at the end of the command $command = "mml\n"; if($SSH_debug) niwaWriteLog("SSH: Sending command [" . stripN($command) . "]","Diag") ; fwrite($stdio,$command); usleep($SSH_usleep); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { if($Flush) flush(); // echo $line."<br />"; if($SSH_debug) niwaWriteLog("SSH: Got Response [" . stripN($line) . "]","Diag") ; } /* --------------------------------- // $command = "numan-add:fullnumbertrans:svcname=\"2E2\",numtype=\"1\",digstring=\"650000\",translatednum=\"0150000\"\n"; $command = "numan-" . $adddelete . ":fullnumbertrans:svcname=\"" . $svcname . "\",numtype=\"" . $numtype . "\",digstring=\"" . $digstring . "\",translatednum=\"". $translatednum ."\"\n"; if($SSH_debug) niwaWriteLog("SSH: Sending command [" . $command . "]","Diag") ; fwrite($stdio,$command); usleep($SSH_usleep); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { flush(); // echo $line."<br />"; if($SSH_debug) niwaWriteLog("SSH: Got Response [" . $line . "]","Diag") ; } ---------------------------- */ $j = 0 ; $pgwSingleCommand = explode("*",$pgwCommandString) ; while(isset($pgwSingleCommand[$j])) { if($pgwSingleCommand[$j] != NULL || $pgwSingleCommand[$j] != "") { niwaWriteLog("PGWscripts: Command [".$j."] is [".$pgwSingleCommand[$j]."]","Diag") ; if($SSH_debug) niwaWriteLog("SSH: Sending command [" . $pgwSingleCommand[$j] . "]","Diag") ; fwrite($stdio,$pgwSingleCommand[$j] . "\n"); usleep($SSH_usleep); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { if($Flush) flush(); // echo $line."<br />"; if($SSH_debug) niwaWriteLog("SSH: Got Response [" . stripN($line) . "]","Diag") ; } // while } // if $j++ ; } // end of while // ------------------------------- $command = "quit\n"; if($SSH_debug) niwaWriteLog("SSH: Sending command [" . $command . "]","Diag") ; fwrite($stdio,$command); usleep($SSH_usleep); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { if($Flush) flush(); // echo $line."<br />"; if($SSH_debug) niwaWriteLog("SSH: Got Response [" . stripN($line) . "]","Diag") ; } // ------------------------------- $command = "exit\n"; if($SSH_debug) niwaWriteLog("SSH: Sending command [" . $command . "]","Diag") ; fwrite($stdio,$command); usleep($SSH_usleep); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { if($Flush) flush(); // echo $line."<br />"; if($SSH_debug) niwaWriteLog("SSH: Got Response [" . stripN($line). "]","Diag") ; } // ------------------------------- $command = "logout\n" ; if($SSH_debug) niwaWriteLog("SSH: Sending command [" . $command . "]","Diag") ; fwrite($stdio,$command); usleep($SSH_usleep); // Then u can fetch the stream to see what happens on stdio while($line = fgets($stdio)) { if($Flush) flush(); // echo $line."<br />"; if($SSH_debug) niwaWriteLog("SSH: Got Response [" . stripN($line). "]","Diag") ; } // ------------------------------- /* ------------cut---------------- $command = ":wq\n"; niwaWriteLog("SSH: Sending command [" . $command . "]","Diag") ; fwrite($stdio,$command); usleep($SSH_usleep); $search = "written" ; $search_preg = "/" . $search . "/i" ; while($line = fgets($stdio)) { flush(); $line=preg_replace("/^.*?\n(.*)\n[^\n]*$/","$1",$line); if (preg_match($search_preg, $line)) niwaWriteLog("SSH: Found command [" . $search . "] OK","Diag") ; niwaWriteLog("SSH: Got Response [" . $line . "]","Diag") ; } -------------------- */ // It's always cleaner to close all stream niwaWriteLog("SSH: PGW Code Finished Result [" . $returncode . "]","Diag") ; usleep($SSH_usleep); // is this needed? fclose($stdio); return $returncode ; } // End of function PGWscripts function stripN($command) { $command = str_replace("\r","",$command) ; $command = str_replace("\n","",$command) ; return($command) ; } // stripN
-
page not loading when empty record in db (using odbc)
niwa3836 replied to psuplat's topic in PHP Coding Help
Hi, I havent had chance to study the code in depth but just picking up on something you say about using die which I guess you are trying to use for troubleshooting. As you know "pages" dont load until its ready (ok there are exceptions but lets not going into those & flushing here). Personally for troubleshooting I use log files, i.e. function dodebug($string) { global $Basedir,$thisprocess ; if(!file_exists($Basedir.'debugs')) mkdir($Basedir.'/debugs/') ; $ff = fopen($Basedir."debugs/".date('Ymd')."-debug.dat","a") ; fwrite($ff,"[".date('H:i:s')."][".$thisprocess."] ".$string."\r\n") ; fclose($ff) ; return(1) ; } //dodebug you can then easily debug your code even when pages dont load. Also on the sql stuff you can test where it successully got the result or "a" result. -
Hi, Is there anyone here who has experience in connecting PHP to outlook or exchange server to get diary entries? I see various snippets of code (that dont seem to work for me yet - possibly because of windows 7) but none of the examples talk about shared calendar access. Basically I am trying to create an app that can check the status of meeting rooms in the office which appear as multiple calendars? Anyone got any experience in this area?
-
Why not just check $POST['Submit'] and then do a header calling the value of Password (might want a catch screen in your apache to catch people typing something wrong or maybe a file_exist() routing first) Then you wouldnt have to keep changing your script.
-
Maybe your right, I cant see anyother reason, unless anyone else knows. As I said I am only affect the remote ip address, i wonder if there is another way of getting it?
-
Not sure I understand the question, but will try and answer as best... 1, when fwrite called, how many msg reply from www.example.com? why use loop to read? Answer> it will continue to read until that buffer is clear 2, can i call fwrite twice first, then call fget twice to get feedback? Answer> You are calling fgets lots until the buffer is cleared. You are entering a little bit of an interesting area here, I set the streams to non blocking and then have a watchdog timer that quits if no data arrived in a while, therefore even if the buffer is initiallly cleared I can still wait, just in case the app sends a little bit more. stream_set_blocking($conn,0) ; if($starttime + 20 < date('U')) break ; if(!feof($conn)) { $result = fgets($conn) ; Thats a little snippett, which might give you an idea (the break leaves a while loop)
-
yes I mean the bcomplier function, thanks for clarifing. I use it to help speed the code up a little and also provide "some" protection of my code on the customer site. As I say everything works fine (and I do lots with it already), its just that the $_SERVER vars dont arrive. Do I have to declare it someother way?
-
Hi, thanks for looking at my problem, can you please help?? Basically when launch some PHP code that has not been bcomplied I see all of the $_SERVER variables (I am interested in REMOTE_ADDR), which is fine, however... When I use bcomplier I dont see an $_SERVER variables at all. The application otherwise runs fine complied, and I do see $_POST and $_GET Any ideas please?
-
Fair point But I am sure someone must have started playing with it, otherwise it will be the drawing board for another SIP engine and possibly do it that way! Still if anyone has anything usually would apprieciate it!
-
Also i would do if(isset($_GET['page]')) $page = $_GET['page'] ; otherwise you will start clocking up errors when page isnt added to the URL ...just nice house keeping.
-
I had a similar problem with hotmail. Once I sorted SPF out it was fine. I would start that now as I found it took a few days to kick in.
-
Hi, has anyone seen or crafted anything in PHP that interacts with Microsoft OCS services? I have had a quick look and there doesnt seem to be much around. Many thanks in advance.
-
Windows XP/2003 using PHP5: Hi, Has anyone here got ldaps and stunnel working that can help. On the php.net site there are discussions around the point that you need to use stunnel to create a SSL connection from the PHP serving machine to the LDAP server if you want to change a password in LDAP. Today I connect fine through normal LDAP v using port 389, however when I configure stunnel and redirect the 389 requests to 636 to go SSL it fails after sending the SSL clienthello. I am sure this is something to do with certificates, but I am not an expert in that area. Has anyone got this working that can point me in the right direction? Many thanks in advance.
-
Must be tired, but tried a number of the GD functions prior will keep looking on my own unless someone knows!
-
Its a little late for me thinking I understand the whole question, however I think what you want to look at is LIKE, i.e. SELECT * FROM freq WHERE frequency LIKE '_".$date."__' _ is a single char, % is multiple chars date('d') doesnt look like the right thing anyway? you might want to format with date('D')?
-
Hi all, Have tried to find a solution to this but dont seem to be able too. I am "sure" something must exist to do it, but wood for the trees and all that. Basically I am happy creating good old 100x100 PNG files. What I would like to be able to do is either from file, or in memory join a number of these to make 1 PNG file 500x500 (i.e. 5 x 5 PNG pictures in a single PNG). Anyone know how? Thanks in advance!
-
Got a sneaking feeling the answer here is no. I am not an expert at this but remember reading something in these forums about why not. Might be worth doing a quick search. If not someone will probably know of their head.
-
Guys, hold off please, might have been a little eager to ask here. I am looking at http://devzone.zend.com/article/1086-Writing-Socket-Servers-in-PHP which seems really useful
-
Guys, I am trying to write some code that looks for any new attempts to connect to a socket whilst servicing other sockets that may already be open (so many clients can connect and be at various stages of being serviced - like most multithreaded programs do i guess). Below is some code from www.php.net (http://uk.php.net/manual/en/function.socket-accept.php#82618) which is just the beginning of my code (i intend to store newc in an array and if valid then service during the while loop, HOWEVER, the demo program (although runs and preforms -i.e. multiple connections at any 1 time) it throws lots of (and I mean lots!!!!!) into the apache log file (which isnt going to work): - [Mon Nov 24 20:22:48 2008] [error] [client 127.0.0.1] PHP Warning: socket_accept() [<a href='function.socket-accept'>function.socket-accept</a>]: unable to accept incoming connection [0]: A non-blocking socket operation could not be completed immediately.\r\n in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\socketin.php on line 11 [Mon Nov 24 20:22:48 2008] [error] [client 127.0.0.1] PHP Warning: socket_accept() [<a href='function.socket-accept'>function.socket-accept</a>]: unable to accept incoming connection [0]: A non-blocking socket operation could not be completed immediately.\r\n in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\socketin.php on line 11 <?php $clients = array(); $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); socket_bind($socket,'0.0.0.0',5555); socket_listen($socket); socket_set_nonblock($socket); while(true) { if(($newc = socket_accept($socket)) !== false) { echo "Client $newc has connected\n"; $clients[] = $newc; } } ?> Any ideas? It makes sense to be non blocking i guess as need to continue to loop to service other connections and cant "wait" for new connections!!
-
Hi, have a look at the messages on the 15/8 as I asked the same question. So what I found was it is limited by memory, think PHP gets 128Mb as default, but can change in php.ini. In my code I did some tests by calling memory_get_usage() and memory_get_peak_usage() during the code running (as debug type statements). Yes mem usage went up during array build outs (never over 2.5Mb though but this depends on array site - my array was about 2511 and 9 columns wide of about 40 chars). Doing an unset of the array freed loads of memory so probably good to do that !
-
CURL, CISCO Firewall and subdomains...experts needed.
niwa3836 replied to sbritton's topic in PHP Coding Help
I see you have fixed but by the way there are various commands in the PIX that can help here. Look at alias as this can help change DNS lookups to internal addresses. -
but how much memory do you allocate? From a design point of view do people actual do this, I havent changed any values as yet as want really to understand why and what to. Is there an incode trap for a failure? As I say some of the records to wander to 100,000 and would love to know if safe to do so.
-
Hi, Hope I am posting this in the right place and someone feels able to help me design thinking. I am getting on fine with PHP generally, however I have noticed that a few of my programs hammer the disks quite hard and therefore I would like to store lots in arrays whilst I do the number crunching. The question is how far can you push arrays. In the old days (15 years ago when I did my last real programming I used to call malloc to make sure that there was memory available for the arrays. I dont see this now in codes, is it still used. So for instance how do I know (or can trap in code) whether an array of, lets say, 30,000 rows, or 10 fields or 20 chars each will cause some memory problems? What about 100,000? Anyone know as its difficult to test and of course I guess every machine that runs the code (different types of servers with different memory etc) may react differently. Am I barking up a tree, or more like a small daisy?
-
Hi, thanks for that, but doesnt show actual max sizes, and then the next question is the max string length actually the same as the maximum amount of data that can be posted between programs and acquired through $_GET?
-
Cant quite work out from your code what is going on, however where is my login.php code that works fine. This code is written for SQL2000 rather than mysql but I am sure you can sort that out. <?php require_once "./niwa-includes/functions001.inc"; /* ----------HTML START ----------- */ pageheader($dbname,$dbusername,$dbpassword) ; ?> <style type="text/css"> <!-- .style1 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <BODY BACKGROUND="2e2images/back1.gif"> <h3 class="style1">2e2 Deployment Tool: Login</h3> <?php if(isset($_POST['name'])) $name = $_POST['name'] ; else $name = '' ; if(isset($_POST['password'])) $password = $_POST['password']; else $password =''; if(isset($_GET['reason'])) $reason = $_GET['reason'] ; else $reason = '' ; if(isset($_GET['sid'])) $sid = $_GET['sid'] ; else $sid = '' ; if ($name && $password ) { $conn = odbc_connect($dbname,$dbusername,$dbpassword) ; if($conn) { $sql = "select name,password from niwausertable where name = '"; $sql .= $name ; $sql .= "'" ; //this function will execute the sql satament $result=odbc_exec($conn, $sql); if(odbc_num_fields($result) == 0) { print("No username found <br />\n") ; niwaWriteLog("User: " . $name . " attempt login but not found","General"); odbc_close ($conn); } else { odbc_fetch_row($result) ; if(odbc_result($result,1) == $name && odbc_result($result,2) == $password) { $sid = md5(date('c')) ; $sql = "update niwausertable set sid = '"; $sql .= $sid ; $sql .= "' where name = '" ; $sql .= $name ; $sql .= "'" ; odbc_exec($conn, $sql); odbc_close ($conn); niwaWriteLog("User: " . $name . " logged in","General"); // $URL = "http://172.30.1.12/deploymain.php?sid=" ; $URL = "deploymain.php?sid=" ; $URL .= $sid ; header("Location: $URL") ; } } } /* if conn */ else { print("<br />\nERROR CONNECTING TO DATABASE<BR />\n" ); niwaWriteLog("There has been an error connecting to the database","General"); } /* bad connection */ } ?> <?php if($name) { print("Username / Password Incorrect<br />\n") ; } if($reason) { if($reason == "BADSID") print("Session has ended, please login again") ; if($reason == "LOGOUT") { $conn = odbc_connect($dbname,$dbusername,$dbpassword) ; $sql = "update niwausertable set sid = ' ' where sid = '"; $sql .= $sid ; $sql .= "'" ; odbc_exec($conn, $sql); odbc_close ($conn); print("User Logged Out") ; } } ?> <FORM METHOD="POST" ACTION="login.php"> <PRE> Your Name: <INPUT TYPE="text" NAME="name" SIZE="20" MAXLENGTH="50" VALUE=""> Your Password: <INPUT TYPE="password" NAME="password" SIZE="20" MAXLENGTH="20" VALUE=""> <input name="Reset" type="reset" id="Reset" value="Reset"> <INPUT TYPE="submit" VALUE="Login"> </PRE> </FORM> </body> </html>