
niwa3836
Members-
Posts
42 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
niwa3836's Achievements

Member (2/5)
0
Reputation
-
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')?