VirtualHost *>
ServerAdmin email@somedomain.com
ServerName somedomain.net
ServerAlias www.somedomain.net
Redirect permanent / http://www.somedomain.com/
/VirtualHost>
Wednesday, May 19, 2010
Thursday, May 13, 2010
PHP Sockets Loop
$i=0;
$jsonPing = "{\"c\":\"ping\",\"d\":{}}\0";
while (1) {
$i++;
if($i == 1000) {
fwrite($socket,$jsonPing);
$i=0;
}
$data = "";
$data .= @fread($socket, 4096);
$data = str_replace("\x1f", " ", $data);
$data = str_replace("part", " part", $data);
$data = str_replace("join", " join", $data);
$data = str_replace("said", " said: ", $data);
$data = trim($data);
$jsonData = json_decode($data,true);
if ($jsonData['from'] == "ayt") {
$data="";
flush();
}else{
if( ($jsonData['u']) && ($jsonData['t']) && (strpos($data, "said")) ) {
echo $jsonData['u']." : ".str_replace($jsonData['u'], "", $jsonData['t'])."
\n";
flush();
ob_flush(); }
}}
fclose($socket);
$jsonPing = "{\"c\":\"ping\",\"d\":{}}\0";
while (1) {
$i++;
if($i == 1000) {
fwrite($socket,$jsonPing);
$i=0;
}
$data = "";
$data .= @fread($socket, 4096);
$data = str_replace("\x1f", " ", $data);
$data = str_replace("part", " part", $data);
$data = str_replace("join", " join", $data);
$data = str_replace("said", " said: ", $data);
$data = trim($data);
$jsonData = json_decode($data,true);
if ($jsonData['from'] == "ayt") {
$data="";
flush();
}else{
if( ($jsonData['u']) && ($jsonData['t']) && (strpos($data, "said")) ) {
echo $jsonData['u']." : ".str_replace($jsonData['u'], "", $jsonData['t'])."
\n";
flush();
ob_flush(); }
}}
fclose($socket);
Monday, May 10, 2010
Check to see which server is which (XML output)
header("Content-type: text/xml");
$getBeta = `/usr/bin/dig beta.sampledomain.com A +short`;
$getBeta = trim($getBeta);
$amIBeta = $_SERVER[SERVER_ADDR];
$amIBeta = trim($amIBeta);
if ($getBeta == $amIBeta) {
$IAmBeta = "true";
}else{
$IAmBeta = "false"; }
$getBeta = `/usr/bin/dig beta.sampledomain.com A +short`;
$getBeta = trim($getBeta);
$amIBeta = $_SERVER[SERVER_ADDR];
$amIBeta = trim($amIBeta);
if ($getBeta == $amIBeta) {
$IAmBeta = "true";
}else{
$IAmBeta = "false"; }
header.php
Quick header file to use include or require with in PHP:
$mysql_user="mysqluser";
$mysql_host="mysql.sample.com";
$mysql_db="mydb";
$mysql_pass = "mysqlpassword";
mysql_connect($mysql_host,$mysql_user,$mysql_pass);
@mysql_select_db($mysql_db) or die("Unable to connect to database...");
foreach ($_REQUEST as $key => $value) {
$_REQUEST[$key] = mysql_real_escape_string($value);
}
$mysql_user="mysqluser";
$mysql_host="mysql.sample.com";
$mysql_db="mydb";
$mysql_pass = "mysqlpassword";
mysql_connect($mysql_host,$mysql_user,$mysql_pass);
@mysql_select_db($mysql_db) or die("Unable to connect to database...");
foreach ($_REQUEST as $key => $value) {
$_REQUEST[$key] = mysql_real_escape_string($value);
}
Thursday, May 6, 2010
XInetD config
Just a quickie so I don't have to go dig it up again...
insert a new file under /etc/xinetd.d/ (under Ubuntu, anyway):
# default: on
# description: xinetd service to emulate Flash Remoting banner
#
service dummy
{
disable = no
type = UNLISTED
id = dummy
socket_type = stream
protocol = tcp
user = root
server = /usr/local/bin/dumbdumbdumbdumbdumb
wait = no
port = 843
}
contents of /usr/local/bin/dumbdumbdumbdumbdumb:
#!/bin/bash
echo "Oh, fiddlesticks..."
exit 0
Make sure /usr/local/bin/dumbdumbdumbdumbdumb is +x
insert a new file under /etc/xinetd.d/ (under Ubuntu, anyway):
# default: on
# description: xinetd service to emulate Flash Remoting banner
#
service dummy
{
disable = no
type = UNLISTED
id = dummy
socket_type = stream
protocol = tcp
user = root
server = /usr/local/bin/dumbdumbdumbdumbdumb
wait = no
port = 843
}
contents of /usr/local/bin/dumbdumbdumbdumbdumb:
#!/bin/bash
echo "Oh, fiddlesticks..."
exit 0
Make sure /usr/local/bin/dumbdumbdumbdumbdumb is +x
Tomcat setup to only listen on localhost (for use with Apache Mod_Proxy)
server.xml changes:
< Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
address="127.0.0.1"/ >
Note the "address" section....
< Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
address="127.0.0.1"/ >
Note the "address" section....
httpd.conf for mod_auth_mysql
Auth_MySQL_Info MySQL.Server username password
Auth_MySQL_General_DB DB with auth info
Auth_MySQL_General_DB DB with auth info
Getting Mod_Proxy to bounce to Tomcat (FINALLY)
This particular problem has been plaguing me for months. How to make HTTPD proxy to a Tomcat instance. Finally got it figured out. BONUS: Also configured it to authenticate via MySQL before proxying the connection. This is using a self-signed SSL cert.
NameVirtualHost zookeeper.mydomain.com:443
< VirtualHost zookeeper.mydomain.com:443 >
ServerAdmin gene@mydomain.com
SSLEngine On
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
ProxyRequests Off
ProxyPreserveHost On
< Proxy * >
Order deny,allow
Allow from all
< /Proxy >
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
< Location >
AuthName "Level 4 Staff Tools Login"
AuthType Basic
AuthUserFile /dev/null
AuthBasicAuthoritative Off
Auth_MySQL On
Auth_MySQL_Password_Table users
Auth_Mysql_Group_Table staffGroups
Auth_MySQL_Username_Field userName
Auth_MySQL_Password_Field password
Auth_MySQL_Group_Field groups
Auth_MySQL_Empty_Passwords Off
Auth_MySQL_Encryption_Types Plaintext Crypt_DES MySQL
require group engineering art
# Order allow,deny
# Allow from all
< /Location >
ErrorLog /var/log/apache2/error.log
NameVirtualHost zookeeper.mydomain.com:443
< VirtualHost zookeeper.mydomain.com:443 >
ServerAdmin gene@mydomain.com
SSLEngine On
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
ProxyRequests Off
ProxyPreserveHost On
< Proxy * >
Order deny,allow
Allow from all
< /Proxy >
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
< Location >
AuthName "Level 4 Staff Tools Login"
AuthType Basic
AuthUserFile /dev/null
AuthBasicAuthoritative Off
Auth_MySQL On
Auth_MySQL_Password_Table users
Auth_Mysql_Group_Table staffGroups
Auth_MySQL_Username_Field userName
Auth_MySQL_Password_Field password
Auth_MySQL_Group_Field groups
Auth_MySQL_Empty_Passwords Off
Auth_MySQL_Encryption_Types Plaintext Crypt_DES MySQL
require group engineering art
# Order allow,deny
# Allow from all
< /Location >
ErrorLog /var/log/apache2/error.log
Wednesday, May 5, 2010
Post Vars as an Array
$result_storeList=mysql_query('SELECT * FROM stores');
while($arrayStoreName=mysql_fetch_array($result_storeList)) {
echo "".$arrayStoreName['name']."(put html checkbox here with $arrayStoreName['ID']).(other HTML here)\n";
}
Submit that to:
$getStore = "SELECT * from stores";
$getStoreQuery = mysql_query($getStore);
while($getStoreArray = mysql_fetch_array($getStoreQuery)) {
$totalStoreNum = $getStoreArray['ID'];
if(htmlspecialchars($_POST[$getStoreArray['ID']])) {
$storeChoice = $getStoreArray['ID'];
$sql_Query = "INSERT INTO storeItems (storeID,itemID) VALUES ('".$storeChoice."','".$recordID."')";
mysql_query($sql_Query); }
}
while($arrayStoreName=mysql_fetch_array($result_storeList)) {
echo "".$arrayStoreName['name']."(put html checkbox here with $arrayStoreName['ID']).(other HTML here)\n";
}
Submit that to:
$getStore = "SELECT * from stores";
$getStoreQuery = mysql_query($getStore);
while($getStoreArray = mysql_fetch_array($getStoreQuery)) {
$totalStoreNum = $getStoreArray['ID'];
if(htmlspecialchars($_POST[$getStoreArray['ID']])) {
$storeChoice = $getStoreArray['ID'];
$sql_Query = "INSERT INTO storeItems (storeID,itemID) VALUES ('".$storeChoice."','".$recordID."')";
mysql_query($sql_Query); }
}
File Uploading
// Where the file is going to be placed
$target_path = "/tmp/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['itemUpload']['name']);
if(move_uploaded_file($_FILES['itemUpload']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['itemUpload']['name']).
" has been uploaded
\n";
} else{
echo "There was an error uploading the file, please try again!";
}
$localFile = "/tmp/".basename( $_FILES['itemUpload']['name']);
$remoteFile = "/var/www/push/".basename( $_FILES['itemUpload']['name']);
$scp_connection = ssh2_connect('remotehost',22);
ssh2_auth_password($scp_connection, 'username', 'password');
ssh2_scp_send($scp_connection, $localFile, $remoteFile , 0664);
Upload a file via HTTP, then SCP it to another server. Been using the hell out of this so I can "sanitize" what files get uploaded to the production server (and force them to push it to Dev first).
$target_path = "/tmp/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['itemUpload']['name']);
if(move_uploaded_file($_FILES['itemUpload']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['itemUpload']['name']).
" has been uploaded
\n";
} else{
echo "There was an error uploading the file, please try again!";
}
$localFile = "/tmp/".basename( $_FILES['itemUpload']['name']);
$remoteFile = "/var/www/push/".basename( $_FILES['itemUpload']['name']);
$scp_connection = ssh2_connect('remotehost',22);
ssh2_auth_password($scp_connection, 'username', 'password');
ssh2_scp_send($scp_connection, $localFile, $remoteFile , 0664);
Upload a file via HTTP, then SCP it to another server. Been using the hell out of this so I can "sanitize" what files get uploaded to the production server (and force them to push it to Dev first).
Subscribe to:
Posts (Atom)