php popen(exim) from a webpage - popen

Problem: Apache accessing programs in /usr/bin
Platform:
Win/7 Pro Sp1
Apache 2.4
Php 5.6
Cygwin emulator gives Linux/Unix emu and has
Exim 4.84-1
program: sendit.php
hndl popen( exim ... )
fwrite(hndle, email_headers);
fwrite(hndle, email_body);
fflush(hndle);
fclose(hndle);
(a)launch from user account
php sendit.php -> exim/exim_main.log updated
reports 368 bytes sent to exim
-> email arrives
demonstrates sendit.php works & Exim config and permissions are correct
(b)launch from apache account uid(apache) gid(srvc)
php sendit.php -> exim/exim_main.log updated
reports 368 bytes sent to exim
-> email arrives
demonstrates sendit.php runs from any account
(c)launch from within a web page
Apache is run from its own uid/gid as in (b)
page.phtml sendit.php
-> NO update to exim log
-> no mail recv'd
reports same NNN bytes send to exim
NO I/O errors
I fwriting_stream 368 bytes ...
* wrote body fragment 368
* wrote total 368
I Wrote Body:(368) of 368
I Wrote EOT(5) of 5
I FLUSHING pipe
I closing pipe
I is closed pipe
I returning 3
adding -d+deliver+host_lookup+lookup+rewrite options to the popen(), yields nice trace - -
EXCEPT when run withing Apache - - nothing shows up
Apache cfg has ExecCGI in the directory and other php / perl programs run there.
Issue is Exim is not within the Apache environment (/usr/bin/exim)
So, created link /usr/bin/exim -> docroot/exim
and reference this instance popen(docroot/exim ...)
Still fails to deliver via pipe -> exim
Any ideas???
btw: have used popen in webpages several places with success
and yes, I verifed the popen return
$PIPE = popen( ... ...);if ($PIPE === false) die("*FE*);

STATUS: SOLVED 2015-05-30
Issue is Windows + Cygwin pathing
PHP tolerates Cygwin as $PATH is available.
Running within
Apache LoadModule php5_module "c:/php/php5.6/php5apache2_4.dll" does not
Must use an absolute WINDOWS path like
c:/cygwin/bin/exim-4.84-1.exe within the server.
php cmdPath_Tests.php
uses file_exists($path) exec to
find that path usable within Apache
Jeff#JeffPC7%
case 0 0 trying:
$ ls -l /usr/bin/exim
lrwxrwxrwx 1 Administrator None 24 Apr 6 09:19 /usr/bin/exim -> /usr/bin/exim-4.84-1.exe
Jeff#JeffPC7%
$ ls -l /usr/bin/exim /cygwin/bin/exim{,-4.84-1}.exe c:/cygwin/bin/exim-4.84-1.exe
case 1 1
ls: cannot access /cygwin/bin/exim.exe: No such file or directory
ls: cannot access /cygwin/bin/exim-4.84-1.exe: No such file or directory
lrwxrwxrwx 1 Administrator None 24 Apr 6 09:19 /usr/bin/exim -> /usr/bin/exim-4.84-1.exe
case 3 1 trying:
-rwxr-xr-x 3 Jeff None 1192467 Jan 25 19:16 c:/cygwin/bin/exim-4.84-1.exe
/usr/bin/exim
0 0 /usr/bin/exim
/usr/bin/exim-4.84-1.exe
0 1 /usr/bin/exim-4.84-1.exe
which: no exim-4.84-1.exe in (/cygwin/bin)
1 1 File Exists
cmd 1 1 trying: /cygwin/bin/exim-4.84-1.exe
results:
/usr/bin/exim-4.84-1.exe
2 1 trying: /usr/bin/exim-4.84-1.exe
I found:
3 1 trying: c:/cygwin/bin/exim-4.84-1.exe
cmd results:
2015-05-30 11:58:24 NP6FDA-000530-QD Completed
ie: email sent

Related

NodeMCU ESP8266 cannot upload sketch - timeout error

Using arduino-cli, the arduino-ide, or directly the esptool.py (from https://github.com/espressif/esptool) I obtain the following error when uploading a simple (correct) sketch.
x#y:~/blink$ ~/tools/arduino-cli upload -p /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcuv2
esptool.py v3.1
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/upload.py", line 66, in <module>
esptool.main(cmdline)
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 4074, in main
esp = esp or get_default_connected_device(ser_list, port=args.port, connect_attempts=args.connect_attempts,
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 121, in get_default_connected_device
_esp.connect(before, connect_attempts)
File "/home/x/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 639, in connect
raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
Error during Upload: Failed uploading: uploading error: exit status 1
esptool.py v3.1
The problem was that my last apt upgrade updated the kernel from the 5.4.0-86-generic to 5.4.0-88-generic (I checked the update in /var/log/apt/history.log.1.gz). The driver CH341 in 5.4.0-88 is not working properly (the ESP I'm using require CH340G drivers). The solution is to go back to the 5.4.0-86 drivers and in the following I list what I've done.
disconnect any ESP or board connected to any USB. Then test that the CH341 module (which allows the serial communication with the EPS) is loaded. You can use this code to test the correct unload/load of the module in steps 2, 3.
x#y:~$ lsmod | egrep serial
usbserial 53248 2 cp210x,ch341
here is where modules of the current (5.4.0-88) and previous (5.4.0-86) kernel are
x#y:~$ ls -larh /lib/modules/
total 164K
drwxr-xr-x 6 root root 4,0K set 29 09:19 5.4.0-88-generic
drwxr-xr-x 6 root root 4,0K set 23 09:45 5.4.0-86-generic
[...]
unload current (5.4.0-88) CH341 module with the command
sudo rmmod /lib/modules/5.4.0-88-generic/kernel/drivers/usb/serial/ch341.ko
load previous (5.4.0-86) CH341 module with the command
sudo insmod /lib/modules/5.4.0-86-generic/kernel/drivers/usb/serial/ch341.ko
That's it :) You should now be able to upload a new sketch to your ESP8266.

react-native run-ios Could not connect to development server npm: '7.19.1' and node : 16.6.0, macincloud.com enviorment

I am using a rdp machine on macincloud.
i am running below commands and failing with "Could not connect to development server"
react-native run-ios
error:
[![enter image description here][1]][1]
Could not connect to development server.
Ensure the following:
- Node server is running and available on the same network - run 'npm start' from react-native root
- Node server URL is correctly set in AppDelegate
- WiFi is enabled and connected to the same network as the Node Server
URL: http://103.228.153.185:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.Appui
RCTFatal
__28-[RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start
0x0
additionally though the debugger connects http://103.228.153.185:8081/debugger-ui/
but in console there is failure with attaching screenshot
i have also added url in Appdelegate.m
return [NSURL URLWithString:#"http://103.228.153.185:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.AppUI"];
i have removed the node_module, clear temp directory,started node server with clean cache, did npm install, nothing seems to work.
other enviorment spec:
node : 16.6.0
npm version
{
npm: '7.19.1',
node: '16.6.0',
v8: '9.2.230.21-node.18',
uv: '1.41.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.17.1',
modules: '93',
nghttp2: '1.42.0',
napi: '8',
llhttp: '6.0.2',
openssl: '1.1.1k+quic',
cldr: '39.0',
icu: '69.1',
tz: '2021a',
unicode: '13.0',
ngtcp2: '0.1.0-DEV',
nghttp3: '0.1.0-DEV'
}
I think this is a environment issue, Any help would be greatly appreciated
Note: app works fine in android
RCA:
This is happening because react-native needs watchman to run in ios, at the same time my user in macincloud.com didn't have privilege to access the watchman that is installed in the machine.
I saw the lack of access privilage from the "npm start" start log.
Welcome to Metro!
Fast - Scalable - Integrated
To reload the app press "r"
To open developer menu press "d"
2021-09-17T19:36:21,739: [] while computing sockname: failed to create /usr/local/var/run/watchman/user-state: Permission denied
Watchman: watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2021-09-17T19:36:21,739: [] while computing sockname: failed to create /usr/local/var/run/watchman/user-state: Permission denied
Solution:
From the error it was obvious that watchman is installed ,but user name cant access it, So what i did is i copied the folder of watchman to a location that i can access and provided the same path in bashrc. As to how i decided which path is needed to go to bashrc. I checked the installation step of watchman on https://facebook.github.io/watchman/docs/install.html,
if you see in the mac installation section, they only copy bin and lib like the below command, note:react-native is not concerned about exact location of watchman, all it wants is to access watchman.
$ sudo cp bin/* /usr/local/bin
$ sudo cp lib/* /usr/local/lib
Exact steps to follow to make this issue go away in macincloud.com or any machine where you are not root and do not have access privilage
cd /Users/{place-your-username}/Documents
mkdir watchman
cd /usr/local/bin/
ls -lart|grep watchman
lrwxr-xr-x 1 temp admin 45 Sep 17 23:04 watchman -> ../Cellar/watchman/2021.09.06.00/bin/watchman
lrwxr-xr-x 1 temp admin 50 Sep 17 23:04 watchman-diag -> ../Cellar/watchman/2021.09.06.00/bin/watchman-diag
lrwxr-xr-x 1 temp admin 50 Sep 17 23:04 watchman-make -> ../Cellar/watchman/2021.09.06.00/bin/watchman-make
lrwxr-xr-x 1 temp admin 68 Sep 17 23:04 watchman-replicate-subscription -> ../Cellar/watchman/2021.09.06.00/bin/watchman-replicate-subscription
lrwxr-xr-x 1 temp admin 50 Sep 17 23:04 watchman-wait -> ../Cellar/watchman/2021.09.06.00/bin/watchman-wait
lrwxr-xr-x 1 temp admin 48 Sep 17 23:04 watchmanctl -> ../Cellar/watchman/2021.09.06.00/bin/watchmanctl
Note: from above you see wathman is present in the machine, for the below command change the version number with respect what you get in the above response
cp -r ../Cellar/watchman/2021.09.06.00/ /Users/{place-your-username}/Documents/watchman
echo $PATH
bashrc might not be present at all and you have to create it for the first time,its ok
vi ~/.bashrc
PATH:/Users/{place-your-username}/Documents/watchman/bin:/Users/{place-your-username}/Documents/watchman/lib:{add-response from above function here or just add $PATH}
source ~/.bashrc
Now you can start your react machine
Note: This should work all machines where you want access to certain app which you want access to but due to privilege you are blocked

How messages from printf are routed to the terminal?

Lets say I have opened two tabs in the konsole (Tab1 and Tab2).
When I run tty in both of them I have:
Tab1:
~$ tty
/dev/pts/23
Tab2:
~$ tty
/dev/pts/24
If I run a simple program hello.c with a printf("Hello") in Tab1, how the system goes from writing to the stdout (file id 1) to writing to /dev/pts/23, being read by the konsole and then appearing in Tab1?
How the system know it has to give the "Hello" string to /dev/pts/23 and not to /dev/pts/24? And how it does that?
Is there a parameter given by the bash to the program so it knows which psudoterminal to send the "Hello"? Or the program sends the string back to the bash (how?) who knows to which pseudoterminal to send the data?
Thank you for your help
If you look at your process open files, you can see that the STDOUT,STDERR, etc points to the specific psuedo terminal that you already figured out using tty in your question
root#hello:~# ls -l /proc/self/fd
total 0
lrwx------ 1 root root 64 May 21 02:18 0 -> /dev/pts/3
lrwx------ 1 root root 64 May 21 02:18 1 -> /dev/pts/3
lrwx------ 1 root root 64 May 21 02:18 2 -> /dev/pts/3
As you might know, a process is created by a fork system call that actually duplicates the open file descriptors from the parent. so basically, your process gets the file descriptors from its parent.
How did the parent hot these associated with him ? well, konsole already dealt with that.

Unable to cd into a grepped directory

I have a volume with spaces and periods that I am unable to cd into
bash-4.3$ ll /Volumes
total 8
drwxrwxrwt# 4 root admin 136 Apr 17 11:08 .
drwxr-xr-x 33 root wheel 1190 Feb 5 19:05 ..
lrwxr-xr-x 1 root admin 1 Apr 17 09:41 Macintosh HD -> /
drwxr-xr-x 4 username wheel 204 Jan 28 02:54 OS X 10.10.2 Update Combo
but trying to cd in this way yields
bash-4.3$ cd "$(ls /Volumes |grep 'OS X')"
bash: cd: OS X 10.10.2 Update Combo: No such file or directory
The problem, as indicated by RC in their comment is that the output from that command substitution is the bare directory name OS X 10.10.2 Update Combo which then is used as cd "OS X 10.10.2 Update Combo" but there is no such directory in the current directory. You would need cd /Volumes/"$(ls /Volumes |grep 'OS X')" to do what you wanted.
That being said using ls and grep for this is not at all appropriate. A better solution is simply to use a glob.
cd /Volumes/*"OS X"*
This will fail (as would the original) if more than one directory/file matches the glob however.

PowerShell remote invocation mysteriously hangs

I have created a series of functions that basically collect all the IIS configurations about a site, when run on a server locally it executes without issue (albeit slowly) however when I run them remotely using an invoke-command in PowerShell 2 it runs through and mysteriously stops approximately 15-20 seconds into the process. It generally stalls on the same request but not always. The same commands executed locally work without any issues. No exception is raised, it just hangs indefinitely.
I can post the code if necessary however it is several hundred lines so I'm more looking for guidance on how to investigate a problem like this or if anyone has encountered something similar.
Comparing IISConfig between [targetserver] and localhost.
Checking Installed IIS version on [targetserver]:
IIS major version : 7
IIS minor version : 5
IIS7+ detected, using WebAdmin module and IIS metabase
Name Value
---- -----
name Default Web Site
id 1
serverAutoStart True
state 1
Site Configuration:
Name Path PSPath Handlers_Ac Access_sslF Asp_AppAllo Asp_AppAllo Asp_limits_ Asp_EnableP Asp_limits_
cessFlags lags wClientDebu wDebugging bufferingLi arentPaths queueTimeou
g mit t
---- ---- ------ ----------- ----------- ----------- ----------- ----------- ----------- -----------
Default ... IIS:Site... WebAdmin... Read,Script False False 25000000 True 00:00:00
WebApp VDir: /MyApp, App Pool: MyApp
App pool Configuration:
AppPoolID Enable32Bit managedPipe managedRunt AppPoolName AppPoolAuto processMode processMode processMode recycling_l
AppOnWin64 lineMode imeVersion Start l_idleTimeo l_identityT l_UserName ogEventOnRe
ut ype cycle
--------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------
False Classic v2.0 MyApp True 00:20:00 LocalSer... Time,Req...
Analyzing web directories for /MyApp, this could take a while....
Initial Collection Completed, found 141... took 0.9516122 seconds
0 C:\inetpub\wwwroot\MyApp\Core
1 C:\inetpub\wwwroot\MyApp\Core\AdminTools
2 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Cache
3 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Extra
4 C:\inetpub\wwwroot\MyApp\Core\AdminTools\HTTPPostTest
5 C:\inetpub\wwwroot\MyApp\Core\AdminTools\IISAdmin
6 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Profiling
7 C:\inetpub\wwwroot\MyApp\Core\AdminTools\RecordTestData
8 C:\inetpub\wwwroot\MyApp\Core\AdminTools\ScrambleTest
9 C:\inetpub\wwwroot\MyApp\Core\AdminTools\Sessions
Analyzed 10 so far... took 6.7236862 seconds, remaining time 88.08028922 seconds
Current Folder: C:\inetpub\wwwroot\MyApp\Core\AdminTools\Sessions
10 C:\inetpub\wwwroot\MyApp\Core\AdminTools\SoapTest
11 C:\inetpub\wwwroot\MyApp\Core\AdminTools\StaticContent
Sometimes it makes it to 15 or so. I tried from my laptop and from one server to another and the behavior is the same.
Here is the loop which is hanging:
$start = [System.DateTime]::Now
$numanalyzed = 0
if ($true) #skip to test
{
# loop through all physical folders as it is much faster
foreach ($folder in $folders)
{
write-host $numanalyzed $folder.fullname
#figure out the virtual path to the folder
$iis7vwebfolderpath = $folder.FullName.Replace($iis7webapp.PhysicalPath, $iis7VDirWebApppath)
#Get-item $iis7vwebfolderpath | gm
$iis7VWebDirConfigItem = Get-LNOSIIS7ConfigForPSPath -PSPath $iis7vwebfolderpath
# add new item to list
$iis7VWebDirConfig += $iis7VWebDirConfigItem
# increment counter and report out progress every 10
$numAnalyzed++
if ($numanalyzed % 10 -eq 0)
{
$end = [System.DateTime]::Now
$timeSoFar = (NEW-TIMESPAN –Start $Start –End $End).TotalSeconds
$timeremaining = ($folders.Count - $numAnalyzed) * ($timeSoFar / $numanalyzed)
"Analyzed {0} so far... took {1} seconds, remaining time {2} seconds" -f $numanalyzed,$timeSoFar,$timeremaining | write-host
"Current Folder: {0}" -f $folder.FullName | Write-Host
}
}
}
$end = [System.DateTime]::Now
"Processed web dirs: {0} took {1} seconds" -f $iis7VWebDirConfig.Count,(NEW-TIMESPAN –Start $Start –End $End).TotalSeconds | write-host | Write-Host
The function I'm having performance problems with and I've got a separate question about but this post has the source code for the function:
web-administration vs WMI to query web directory properties performance problems
In my case, it seemed my PowerShell call froze due to the Idle-Timeout expiration (the call runs for a very long time).
Setting IdleTimeout value to a sufficiently long duration fixed my issue.
Once again, query the current configuration using
winrm get winrm/config/winrs
And set the timeout using
winrm set winrm/config/winrs '#{IdleTimeout="18000000"}'
I think i may have discovered the problem, i started getting some odd failures in other parts of the script:
[SEVERNAME] Processing data from remote server SERVERNAME failed with the following error message: The WSMan provider host process did not return a proper response. A provider in the host process may have behaved improperly. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (SERVERNAME:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : 1726,PSSessionStateBroken
and
Processing data for a remote command failed with the following error message: Not enough storage is available to complete this operation. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OperationStopped (System.Manageme...pressionSyncJob:PSInvokeExpressionSyncJob) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
This lead me to the following site: http://www.gsx.com/blog/bid/83018/Troubleshooting-unknown-PowerShell-error-messages
The following recommendations seems to have cleared up most of the problems although i still have some testing to do.
Excerpt from site below:
As the first error message specifies, an overflow of memory in the remote session has occurred. Open a PowerShell prompt on the remote server and display the configuration of winrs using:
winrm get winrm/config/winrs
Check the "MaxMemoryPerShellMB" value. It is set by default to 150 MB on Windows Server 2008 R2 and Windows 7. This is something that Microsoft changed in Windows Server 2012 and Windows 8 to 1024 MB.
In order to resolve this issue, you need to increase the value to at least 512 MB with the following command:
winrm set winrm/config/winrs `#`{MaxMemoryPerShellMB=`"512`"`}
As an FYI if Invoke-Command always hangs:
Try a simple command to system :
Invoke-Command -ComputerName XXXXX -ScriptBlock { Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion }
Start the Windows Remote Management Service (on that system)
Check for the listening port:
netstat -aon | findstr "5985"
TCP 0.0.0.0:5985 0.0.0.0:0 LISTENING 4
TCP [::]:5985 [::]:0 LISTENING 4

Resources