Saturday, December 8, 2012
MySQL timestamp versus datetime
Friday, November 16, 2012
PHP Objects to XML
//So first we need an object of objects.
class rootObject {
public $root;
public function populateRoot() {
$root=new singleFirstTierObject();
$root->populateSingleFirstTier();
$this->root=$root;
}
public function toXML() {
$serializer = new XMLSerializer();
return $serializer->objToXML($this);
}
}
class singleFirstTierObject {
public $singleFirstTier;
public $singleOtherFirstTier;
public function populateSingleFirstTier() {
$singleFirstTier=new singleSecondTierObject();
$singleFirstTier->populateSingleSecondTier();
$this->singleFirstTier=$singleFirstTier;
$singleOtherFirstTier=new multipleSecondTierObject();
$singleOtherFirstTier->populateSingleSecondTier();
$this->singleOtherFirstTier=$singleOtherFirstTier;
}
}
class singleSecondTierObject {
public $singleSecondTier;
public function populateSingleSecondTier() {
$this->singleSecondTier='singleSecondTier';
}
}
class multipleSecondTierObject {
public $singleSecondTier;
public $singleOtherSecondTier=array();
public function populateSingleSecondTier() {
$this->singleSecondTier='singleSecondTier';
$argumentArray=array();
for($i=0;$i<5;$i++) {
$arrayComponent=new multipleThirdTier();
$arrayComponent->populateMultipleThirdTier();
$argumentArray[]=$arrayComponent;
}
$this->singleOtherSecondTier=$argumentArray;
}
}
class multipleThirdTier {
public $multipleThirdTier;
public function populateMultipleThirdTier() {
$this->multipleThirdTier='multipleThirdTier';
}
}
$object = new rootObject();
$object->populateRoot();
echo "<hr />\n<pre>\$object: <br />\n";
echo print_r($object);
echo "</pre><hr />\n";
//Now we have an object that will translate into XML via the XMLSerializer class below using the toXML function in the rootObject class.
//http://www.akchauhan.com/php-class-for-converting-xml-to-object-and-object-to-xml/
class XMLSerializer {
private static $xml;
// Constructor
public function __construct() {
$this->xml = new XmlWriter();
$this->xml->openMemory();
$this->xml->startDocument('1.0');
$this->xml->setIndent(true);
}
// Method to convert Object into XML string
public function objToXML($obj) {
$this->getObject2XML($this->xml, $obj);
$this->xml->endElement();
return $this->xml->outputMemory(true);
}
// Method to convert XML string into Object
public function xmlToObj($xmlString) {
return simplexml_load_string($xmlString);
}
private function getObject2XML(XMLWriter $xml, $data) {
foreach($data as $key => $value) {
if(is_object($value)) {
$xml->startElement($key);
$this->getObject2XML($xml, $value);
$xml->endElement();
continue;
}
else if(is_array($value)) {
$this->getArray2XML($xml, $key, $value);
}
if (is_string($value)) {
$xml->writeElement($key, $value);
}elseif(is_numeric($value)) {
$xml->writeElement($key, $value);
}
}
}
private function getArray2XML(XMLWriter $xml, $keyParent, $data) {
foreach($data as $key => $value) {
if (is_string($value)) {
$xml->writeElement($keyParent, $value);
continue;
}
if (is_numeric($key)) {
$xml->startElement($keyParent);
}
if(is_object($value)) {
$this->getObject2XML($xml, $value);
}
else if(is_array($value)) {
$this->getArray2XML($xml, $key, $value);
continue;
}
if (is_numeric($key)) {
$xml->endElement();
}
}
}
}
$xmlOutput1=$object->toXML();
echo "<hr />\n<pre>\$xmlOutput1: <br />\n";
echo $xmlOutput1;
echo "</pre><hr />\n";
//What if we want to add attributes or edit the XML object though?
$xmlObject = new SimpleXMLElement($xmlOutput1);
echo "<hr />\n<pre>\$xmlObject: <br />\n";
echo "Round 1: <br />\n";
echo print_r($xmlObject);
echo "</pre><hr />\n";
//$xmlObject->singleOtherFirstTier->singleOtherSecondTier[$child_count]->multipleThirdTier
$child_count=0;
foreach($xmlObject->singleOtherFirstTier->singleOtherSecondTier as $element){
$xmlObject->singleOtherFirstTier->singleOtherSecondTier[$child_count]->multipleThirdTier->addAttribute('child-element',$child_count);
$child_count++;
}
echo "<hr />\n<pre>\$xmlObject: <br />\n";
echo "Round 2: with new attributes <br />\n";
echo print_r($xmlObject);
echo "</pre><hr />\n";
//Sorry, I know you looked. But, you won't be able to see they are there. And what is worse if you want to access them similarly now that they exist, the attribute name will need encapsulated in {curly braces}.
//And we convert our SimpleXML object back into an XML string.
$xmlOutput2=$xmlObject->asXML();
echo "<hr />\n<pre>\$xmlOutput2: <br />\n";
echo $xmlOutput2;
echo "</pre><hr />\n";
//Also, whitespace is a waste of bandwidth if you are talking to a machine.
//The following code will enable us to fine tune how we want whitespace handled by converting our data in an XML string into a DOM document object.
$domObject = new DOMDocument('1.0');
$domObject->preserveWhiteSpace = false; //self explanatory
$domObject->formatOutput = true; //false = no whitespace, true = human friendly tabbed indenting
//Now that we have a DOM document object with the settings we like let's load the XML string into it.
$domObject->loadXML($xmlOutput2);
//Last thing to do is output our finished DOM document object as XML document using the saveXML method.
echo "<hr />\n<pre>\$domObject->saveXML(): <br />\n";
echo $domObject->saveXML();
echo "</pre><hr />\n";
?>
<hr /> <pre>$object: <br /> rootObject Object ( [root] => singleFirstTierObject Object ( [singleFirstTier] => singleSecondTierObject Object ( [singleSecondTier] => singleSecondTier ) [singleOtherFirstTier] => multipleSecondTierObject Object ( [singleSecondTier] => singleSecondTier [singleOtherSecondTier] => Array ( [0] => multipleThirdTier Object ( [multipleThirdTier] => multipleThirdTier ) [1] => multipleThirdTier Object ( [multipleThirdTier] => multipleThirdTier ) [2] => multipleThirdTier Object ( [multipleThirdTier] => multipleThirdTier ) [3] => multipleThirdTier Object ( [multipleThirdTier] => multipleThirdTier ) [4] => multipleThirdTier Object ( [multipleThirdTier] => multipleThirdTier ) ) ) ) ) 1</pre><hr /> <hr /> <pre>$xmlOutput1: <br /> <?xml version="1.0"?> <root> <singleFirstTier> <singleSecondTier>singleSecondTier</singleSecondTier> </singleFirstTier> <singleOtherFirstTier> <singleSecondTier>singleSecondTier</singleSecondTier> <singleOtherSecondTier> <multipleThirdTier>multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier>multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier>multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier>multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier>multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> </singleOtherFirstTier> </root> </pre><hr /> <hr /> <pre>$xmlObject: <br /> Round 1: <br /> SimpleXMLElement Object ( [singleFirstTier] => SimpleXMLElement Object ( [singleSecondTier] => singleSecondTier ) [singleOtherFirstTier] => SimpleXMLElement Object ( [singleSecondTier] => singleSecondTier [singleOtherSecondTier] => Array ( [0] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [1] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [2] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [3] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [4] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) ) ) ) 1</pre><hr /> <hr /> <pre>$xmlObject: <br /> Round 2: with new attributes <br /> SimpleXMLElement Object ( [singleFirstTier] => SimpleXMLElement Object ( [singleSecondTier] => singleSecondTier ) [singleOtherFirstTier] => SimpleXMLElement Object ( [singleSecondTier] => singleSecondTier [singleOtherSecondTier] => Array ( [0] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [1] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [2] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [3] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) [4] => SimpleXMLElement Object ( [multipleThirdTier] => multipleThirdTier ) ) ) ) 1</pre><hr /> <hr /> <pre>$xmlOutput2: <br /> <?xml version="1.0"?> <root> <singleFirstTier> <singleSecondTier>singleSecondTier</singleSecondTier> </singleFirstTier> <singleOtherFirstTier> <singleSecondTier>singleSecondTier</singleSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="0">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="1">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="2">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="3">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="4">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> </singleOtherFirstTier> </root> </pre><hr /> <hr /> <pre>$domObject->saveXML(): <br /> <?xml version="1.0"?> <root> <singleFirstTier> <singleSecondTier>singleSecondTier</singleSecondTier> </singleFirstTier> <singleOtherFirstTier> <singleSecondTier>singleSecondTier</singleSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="0">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="1">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="2">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="3">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> <singleOtherSecondTier> <multipleThirdTier child-element="4">multipleThirdTier</multipleThirdTier> </singleOtherSecondTier> </singleOtherFirstTier> </root> </pre><hr />
Thursday, October 11, 2012
Automatic Touchpad Disable While Typing in Ubuntu (Kubuntu)
sudo apt-get install gsynaptics
to get additional options for the configuration of your Synaptics or Synaptics compatible touchpad. --I've been grazing the touchpad while typing, but there is a feature that disables the touchpad for a short while if a keyboard key is touched. Huge reduction in stupid and annoying accidental typo corrections.
Wednesday, September 26, 2012
Recursive String Replacement
by properly escaped, I mean using the backslash character(\) before special characters ( \. \/ \\ )
I should make myself a tool for this.
Installing the Papyrus Eclipse Plugin
http://download.eclipse.org/modeling/mdt/papyrus/updates/releases/juno/main
Then you will need to install the modeling libraries from eclipse.org. I ended up just installing them all.
For whatever reason, I did not have a 'palette' tool box on my first model. It is there now, I created a new specific model (use case checkbox) with basic primitive types (checkbox) and they were magically there-- if you don't see any way to add diagram graphics via the 'palette'.
About Cloned Wordpress Servers and Logging In to the Wrong Server
On that server was a wordpress installation.
The server was logging in to the wrong wordpress installation.
There is probably a 'correct' way to do this. But I found the wordpress options I needed to change in the wordpress database in the prefix_options table. (We have prefixes set to ON for multiple wordpress installations. Our tables are prefixed and referenced with prefix_ prepended in this post.)
SELECT * FROM prefix_options LIMIT 0,20;
From there, you should see why your new wordpress is logging you in to your old wordpress...
Hint:
mysql> select * from prefix_options limit 0,20;
+---------+-----------+-------------------------+--------+
|option_id|option_name|option_value |autoload|
+---------+-----------+-------------------------+--------+
| 1|siteurl |http://notdevelopment.com|yes |
mysql> UPDATE prefix_options SET option_value='http://development.com' WHERE option_id=1;
Monday, September 24, 2012
Changing the default user and group for files in linux directories
chmod u+s
or issue this command to have new files in the directory get set with the group that is the same as the group of the directory
chmod g+s
also restricting deletion by any non-owner or privileged user is chmod +t to set the sticky bit
Capitalization is used to show whether the execute permission is set or not since these settings show up in the same spaces as the execute bit.
Here are a few examples that you might see if you ls -la:
rwSrwSrwT
(that means rwxrwxrwx with uid, gid, & sticky set)
rwxrwSrwt
(that means rwxrwxrw- with only the gid & sticky set)
Thursday, August 30, 2012
Kate Regex Search and Replace
So if you are wanting to switch wordsomething to somethingword in Kate, your regex will look like this (word)(something) and your replacement will look like this \2\1 to end up with somethingword when it is all done
wordsomething find (word)(something)
replace with \2\1 finishes with something word
Thursday, August 2, 2012
Best value web hosting
Granted, it is a lot more work than other hosts I have used because it is so much like having a raw machine-- but the response and flexibility of the platform is well worth the ~$20 per node and effort each month.
The successes and happiness with the outcomes of incremental efforts have made it so worth it.
We are using fusemail as our email service provider. They are sufficient at $2 per account each month. I would consider other providers.
Thursday, March 29, 2012
Get Column Names Text from MySQL
select column_name from information_schema.columns where table_name='tablename';
Thursday, March 15, 2012
Recovering a Text File in Linux
grep -a -A800 -B800 'obustness' /dev/sda5 | strings > recovered_file
Everyone loves grep
-a says to process binary as text
-A[number] tells grep to include 800 lines after the matching term is found
-B[number] tells grep to include 800 lines before the matching term is found
then of course you will want to supply a term for grep to match against
and finally where you want grep to look /dev/sda5 happens to be my /home partition
Then pipe all that off to strings to be redirected into a file.
The reason you would do that is because it will clean up some of the gobbledygook the -a option of grep will not.
--I figured that Robustness would be a somewhat rare string to search for. And I could make it case insensitive by just leaving off the 'R' (yes, it can be done with switches).
Interesting thing to note, people besides me use the word Robustness. Not as rare as I was hoping.
Friday, January 27, 2012
Default Select Box "Prefilling" to emulate a Choice of the Existing Data
//$address is just an integer counter that starts at 0 and increments before a new address is pulled from the database.
//So, having said that, let's build the HTML select element where $address makes this chunk of code able to be specifically referenced later on by creating a unique id="state0", id="state1", id="state2", and so on for each address.
<?php
echo "<div>State:<select id=\"state" . $address . "\" name=\"UTstate\">\n
<optgroup label=\"U.S. States\">\n
<option value=\"IN\">Indiana</option>\n
<option value=\"MI\">Michigan</option>\n
<option value=\"NY\">New York</option>\n
<option value=\"OH\">Ohio</option>\n
<option value=\"PA\">Pennsylvania</option>\n
<option value=\"TN\">Tennessee</option>\n
<option value=\"VA\">Virginia</option>\n
<option value=\"WV\">West Virginia</option>\n
</optgroup>\n
</select>\n";
//There we have it. But now to make things easier for editing let's make the default value the same as what had been in the database using jQuery magic.
//This short chunk of jQuery JavaScript selects the corresponding state0, state1, or state2 and so on which should be the preceeding address state select block. It searches for the $row2['state'] database information within the option group tags. When it finds a match, it modifies the selected attribute of the tag to be set to selected.
Can we just show the HTML? Please?
Sure, hold on to your biscuits.
//This is what we start off with. All of the PHP code has done it's thing, this has become raw HTML code. Note that database read resulted in OH and we pumped OH into the jQuery JavaScript as you will soon see.
State:<select id="state0" name="UTstate">
<optgroup label="U.S. States">
<option value="VA">Virginia</option>
//Then as I said we hit the short chunk of jQuery JavaScript. The OH was read from the database as mentioned earlier telling the browser which option tag identified by it's value to modify contained within the state0 select tag.
//The DOM gets modified and now the <otion value="OH">Ohio</option> tag has been modified as far as the user can see and the browser is keeping track of. It now looks and acts as so...
<optgroup label="U.S. States">
<option value="VA">Virginia</option>
Yaay!
This is for examples where only one selection is expected, for select boxes that allow multiple selections the code will be somewhat different but a similar method can be used.
Friday, January 6, 2012
WinSCP
I have been using and recommending Filezilla which currently does not have that feature despite being great and free. I have many choices for how I wish to keep my files stored redundantly and Filezilla works with most of the Operating Systems I use, so I will continue to use it.
The thing that WinSCP does for me is that it allows me to not need Samba on my file servers.
Friday, December 23, 2011
A Unicode Post That Is More for Me Than You
From the MySQL Documentation
For any Unicode character set, operations performed using the _general_ci collation are faster than those for the _unicode_ci collation. For example, comparisons for the utf8_general_ci collation are faster, but slightly less correct, than comparisons for utf8_unicode_ci. The reason for this is that utf8_unicode_ci supports mappings such as expansions; that is, when one character compares as equal to combinations of other characters. For example, in German and some other languages “ß” is equal to “ss”. utf8_unicode_ci also supports contractions and ignorable characters. utf8_general_ci is a legacy collation that does not support expansions, contractions, or ignorable characters. It can make only one-to-one comparisons between characters.In a nutshell--
UTF-8 General is usually faster because it does not factor into any cases where two glyphs or glyph combinations that are equivalent via the encoding. Either the glyph is what it is or it isn't with a one to one relationship. This is the default UTF-8 encoding.
UTF-8 Unicode does facilitate how language is actually used and operates on more complicated conventions. It is the newer, more correct implementation at the cost of frugal resource usage.
Saturday, December 17, 2011
DOSBox Key Commands I Care About
Just the ones I want to use and need on an infrequent basis.
I am not a fan of old programs. But when it is what needs to be run, that is what is run.
Ctrl+F11 / Ctrl+F12 Reduce / increase the game speed, if it's too fast or too slow.
Alt+Enter Toggle between fullscreen and windowed.
Alt+Pause Pause DOSBox.
Ctrl+F10 Switch mouse control between Windows and DOSBox.
MOUNT [Drive-Letter] [Local-Directory] Wednesday, October 19, 2011
Firefox Add-ons I Love
Firefox Add-ons I Love
1. LastPass
Used in conjuction with the LastPass on-line password manager service. Free/Premium@$12. Highly recommend them.
2. Firebug
Web development tool.
3. ChatZilla
Feature rich, user friendly in-browser IRC chat client.
4. Lazarus
Lost form data recovery tool. So far very awesome.
5. Down Them All
Works great to pull many files from a web server to a folder on your computer-- initiated directly from the browser.
6. Random Color Tool - Using Rainbow currently
I always install some kind of 'color tool' to help me quickly find out what color that is on the web.
Firefox Add-ons I Would Love to See
A. A Good Torrent Tool
There are two that I know of that are okay. Opera integrates torrenting into it's browser, but I don't really use Opera.
Friday, October 7, 2011
The Problem with TeamViewer (TeamViewer Is Awesome BTW)
The Things I Love About TeamViewer
It is multi-platform. It works on many *nix machines that have an X-Windows GUI. It works on all Windows Machines; Server2008, Win7 Pro, XP Home Edition-- it doesn't care. When other mixed technologies fail, TeamViewer usually works (I have a lot of 'unnecessary' technology in my house.). The same client install serves and acts as a client. You can start a session from your Linux laptop to your wife's Win7 laptop to fix that problem she was having. Later you can use her Win7 laptop to get into your Linux laptop to see if that compile finished. It is the same client. Configuration could be a hair more intuitive, but that is like asking for a revision of the Sistine Chapel. Could it be better, sure. Is it great the way it is, yes. For individual non-commercial use, it is free to use. And do so, it is great. It is the program I use in my home when I don't feel like using CLI. It is the technology I tell my wife and sister to use, their skills are above average-- but that is because most people's technological knowledge is poor. I even think many technologically bereft people could figure out how to use TeamViewer. Tell your friends. (Write about it's awesomeness in a blog maybe.) Nerds, listen up. If you are a Netflix subscriber, you have probably seen the 'You Can't Do That' screen from RDP. TeamViewer works. I regularly control my HTPC connected to my TV with my Android phone-- there is a TeamViewer Android app.I Thought You Said Something About Problems
I would use the product heavily for SFTP maybe once a month. I would use the product for a few minutes about twice a week to fix some little thing and be done. But, I don't use it for work. I could use it happily instead of RDP, SFTP, CLI over SSH, and remote connection via DDNS like features. If it is so great, why don't you use it? Licensing costs. I want to pay them. I love their product. Licensing is big with me. I want to be legit. I don't want anyone knocking on my door. I am beholden to no-one. Therefore, I use a lot of open source products. Open source is not free. I charge a modest amount of money for each product. Those specific proceeds are donated. I have donated to OpenBSD, the Illumos Foundation, and Debian through SPI. It is important that the projects I like and use get money. Period. They just have so few licensing options, their cheapest option is to pay over $400 per year to rent the software. It is roughly $37 dollars per month. It is harder to give what I feel I can to closed source enterprises, pricing is rigid. What I currently use is free. My other options, (which are sufficient, but not better) are much less expensive. My motivation to use non-free solutions is to simplify my life. Setups and configurations for free solutions take time and effort. I want to do my work, get in and get out. The more time I take, the less money I make on jobs with a fixed cost being billed to the client. Their competitor LogMeIn is good, for the time being that is the product I will use. It is not great like TeamViewer is, but it is less than a third of the price for what I want to do.Hopes and Dreams
It costs very little for TeamViewer to restructure their product pricing-- or get creative on a case by case basis. I am a raving fan that wants to give them money and I cannot justify giving them what they are asking given my current situation and my infrequent, short lived needs of their product. Their product is an excellent solution to a common problem and most people will like it a lot. If you have room in the budget, I have no qualms with recommending it with all the good I can relay. But, at this time is not at a sufficient price point or with licensing terms that are compatible with the work I do for me to use it.Had A ZFS Pool with Raw Disk Access Disappear
zpool import POOLNAME
brought it back.
Friday, September 16, 2011
DDNS for OpenIndiana
I am hosting all kinds of machines on a DHCP connection. Shhh....
So I signed up with No-IP which I like very much.
I put a brand new SFTP server in service to replace my somewhat less secure FTP server I only had access to locally.
With all of it's shiny UNIX security, I tried to make it externally accessible-- but was unable with the tools provided by No-IP.
I will be supplementing my primary paid DDNS with No-IP by also using a free DynDNS account.
I plan on keeping No-IP because of their rock solid service that I have noticed 0 issues or problems with in several years.
Depending on how things go, I may also fork some money over to DynDNS.
On to the task at hand.
I chose DynDNS because I have a few friends that use it.
This is important. To avoid getting shut off for abuse while testing solutions, DynDNS has a few dummy accounts that can be used.
http://dyn.com/support/developers/test-account
There is something to be said about the multitude of solutions to a finite set of problems. It took me three tries to get something new to work. Just keep at it, eventually you will get it.
Plan C
Create a heading in your log just for stuff and giggles.
vi /var/log/updatedns.log
DNS Update Log
Write the script that will do the dirty work.
vi /usr/sbin/updatedns.sh
#!/bin/sh
#Get the data that allows for checking that the DNS service has a good IP.
#I use no-ip for bradchesney.net, which does not facilitate sftp server DDNS services.
#However, I can us it to see what my current IP is.
#I leave finding the immediate value of your current external IP to you.
extip=`dig +short bradchesney.net`
#Then I retrieve what my second DDNS provider thinks my SFTP server's IP is.
sftpserv=`dig +short sftpserv.dyndns.com`
#Grab the date for simple logging purposes.
thedate=`date`
#Compare the values.
if [ "$extip" = "$sftpserv" ]; then
#These lines test that the cron service is running the script and the basic logging works.
#These are debugging lines and should be commented out during normal usage.
#echo "#######################################################" >> /var/log/updatedns.log
#echo "$thedate : EXTIP $extip; SFTPSERV $sftpserv -- Debug" >> /var/log/updatedns.log
#If the both IPs match, do nothing.
exit
else
#If they are different, update the IP with cURL and log the update.
#Create the string to feed to curl
update="https://DYNDNSLOGIN:DYNDNSPASSWORD@members.dyndns.org/nic/update?system=dyndns&hostname=CHOSENDYNDNSHOSTNAME.dyndns.CHOSENDYNDNSTLD&myip=$extip"
#This is a good debugging test string to avoid getting banned.
#update="https://test:test@members.dyndns.org/nic/update?system=dyndns&hostname=test.mine.nu&myip=$extip"
#Update via curl and log the output and/or results
echo "#######################################################" >> /var/log/updatedns.log
echo "$thedate : EXTIP $extip; SFTPSERV $sftpserv" >> /var/log/updatedns.log
curl -k $update >> /var/log/updatedns.log > /dev/null
echo -e /r/n
fi
Change the owner, group, and permissions on the script.
chown root:bin /usr/sbin/updatedns.sh
chmod 751 /usr/sbin/updatedns.sh
Setup a cron job for the script.
I have mine set to check that I have a good IP every six minutes.
chrontab -e
Append the following text to run the script every six minutes.
0,6,12,18,24,30,36,42,48,54 * * * * /usr/bin/updatedns.sh
Boom, a somewhat resilient DDNS updater. --I am open to suggestions regarding a better way, but this should work rather well.
(Also, while building the curl command I noticed that I was contacting members.dyndns.org:8245 for ddclient in Plan B. Port 8245 is an unencrypted http port. I have a feeling that if I were to have changed that to port 443 or no port at all, the ddclient script may have worked. Hindsight.)
Plan B -- Failed
ddclient is a perl script that will meet the needs and supports many DDNS service providers.
Download the script.
http://sourceforge.net/projects/ddclient/files/ddclient/ddclient-3.8.1/ddclient-3.8.1.tar.gz/download
Install ddclient.
cp /file/extraction/location/ddclient /usr/sbin
mkdir /etc/ddclient
mkdir /etc/var/cache/ddclient
cp /file/extraction/location/sample-etc_ddclient /etc/ddclient/ddclient.conf
(! I don't know where you extracted the files. You can find / -name ddclient to have your system tell you where you put them.
Configure ddclient
vi /etc/ddclient/ddclient.conf
######################################################################
##
## $Id: sample-etc_ddclient.conf 125 2011-05-19 20:31:20Z wimpunk $
##
## Define default global variables with lines like:
## var=value [, var=value]*
## These values will be used for each following host unless overridden
## with a local variable definition.
##
## Define local variables for one or more hosts with:
## var=value [, var=value]* host.and.domain[,host2.and.domain...]
##
## Lines can be continued on the following line by ending the line
## with a \
##
##
## Warning: not all supported routers or dynamic DNS services
## are mentioned here.
##
######################################################################
daemon=3600
syslog=no
ssl=no
#ssl=yes # use ssl-support.
# Works with ssl-library.
fw-login=ROUTERUSERNAME, fw-password=ROUTERPASSWORD # FW login and password
## To obtain an IP address from FW status page (using fw-login, fw-password)
use=fw, fw='https://192.168.1.1/Status_Internet.asp', fw-skip='LAN IP' # found after IP Address
## Above is the web address of a page on my router that shows my external IP.
## After that is fw-skip. The visible text immediately after my external IP is LAN IP.
## ddclient must look for that text and then find my external IP relative to it.
login=DYNDNSLOGIN # default login
password=DYNDNSPASSWORD # default password
server=members.dyndns.org:8245 \ # default server (bypassing proxies)
protocol=dyndns2, \
CHOSENDYNDNSHOSTNAME.dyndns.CHOSENDYNDNSTLD
Install SUNWopenssl, perl510extra, net-ssleay, pmtools, and perl510 from the package manager if not already installed.
They can be easily found by simply searching for perl in the package manager.
Seemingly unavailable from the packages are the IO-Socket-SSL modules for perl.
The following instructions installed the missing files in places ddclient could find them.
The source (that creates the make files via an initial perl script) can be found at:
http://www.cpan.org/modules/by-module/IO/IO-Socket-SSL-1.44.tar.gz
cd /file/extraction/location/
perl Makefile.PL
make
make test
make install
At this point you can begin attempting to update your DDNS information with ddclient.
You can use /usr/sbin/ddclient -daemon=0 -noquiet -debug to get information if things don't go as expected.
Alternatively the truss -a -f /usr/sbin/ddclient -daemon 600 command is very cool at seeing the system calls if needed.
Start the ddclient daemon and keep it started
I am using a cron job in conjunction with a script to monitor whether ddclient is running or not.
vi /usr/bin/ddnsupdate.sh
##########################################
#!/bin/sh
#Check for ddclient.
#If not running, run ddclient.
if ps | grep ddclient > /dev/null
then
exit
else
/usr/bin/ddclient
fi
##########################################
Change the owner, group, and permissions on the script.
chown root:bin /usr/sbin/ddnsupdate.sh
chmod 751 /usr/sbin/ddnsupdate.sh
Create the line of code that will make cron run the script.
vi /var/spool/cron/crontabs/root
Append
*/10 * * * * /usr/bin/updateddns.sh
to the end of the file.
Plan A -- Failed
inadyn requires linux files that are not present on an OpenIndiana installation.
inadyn requires linux files that are very difficult to put on an OpenIndiana installation.
Saturday, August 13, 2011
As-Is, Not Everything I Do Works Out As I Had Hoped
So, putting my file server on a VM did not have the outcome I was hoping.
But, I did do a few cool things that may save someone else a few minutes and some hair pulling. So, some of the steps I took access to the raw disks from a VM are provided below as-is. So, my notes are presented unformatted as such below.
My old fileserver with all my most treasured files was highly under utilized. So the plan was to move it to a virtual machine host. This begged giving a OpenIndiana VM access to raw disks for zpooling (and maybe raid-z when I get better hardware for the house). I backed up my files and started with empty platters on my spindles. Step 1 Attach two physical disks to the host machine which become the storage mediums of the upcoming zpool. no partitions - don't make any or get rid any preexisting My Debian Host OS recognized the new drives as /dev/sdb & /dev/sdc and we will not mount and/or prevent mounting them. Everything else will be easiest to accomplish as the root user. su brad will be the user VirtualBox will be running under change the ownership and mode of the device nodes to allow ufettered access by the user running VirtualBox chown brad /dev/sdb chown brad /dev/sdc chmod 775 /dev/sdb chmod 775 /dev/sdc Add the user of the VirtualBox process to the disk group sudo usermod -a -G disk brad create the .vmdk files VBoxManage internalcommands createrawvmdk -filename /home/brad/.VirtualBox/a1.vmdk -rawdisk /dev/sdb -relative VBoxManage internalcommands createrawvmdk -filename /home/brad/.VirtualBox/a2.vmdk -rawdisk /dev/sdc -relative change the ownership and mode of the pointer files to allow ufettered access by the user running VirtualBox chown brad /home/brad/.VirtualBox/a1.vmdk chown brad /home/brad/.VirtualBox/a2.vmdk chmod 775 /home/brad/.VirtualBox/a1.vmdk chmod 775 /home/brad/.VirtualBox/a2.vmdk log out log in add the .vmdk files to your virtual machine via the GUI. Time to boot the VM. Yeah, that's it. Fire her up. My username within the OpenIndiana VM will also be brad. Do whatever administrative things you might do with a new machine. Set the network connection to a fixed IP. Give good users privileges, take privileges away from bad users-- or the other way around if you desire a little more excitement in your life. Setting up your first zpool is easiest as root. I am choosing to mount my zpool in a non-standard spot with the -m option. su mkdir /export/home/zfs/ zpool create -m /export/home/zfs/ memory mirror /dev/dsk/c1t2d0p0 /dev/dsk/c1t3d0p0 Create filesystems on your zpool that is much like a software RAID 1 volume. Except ZFS cares about the integrity of your data and the effects bitrot. zfs create memory/photos zfs create memory/iso zfs create memory/music zfs create memory/videos zfs create memory/misc zfs create memory/work zfs create memory/holding groupadd securftp usermod -G securftp brad chgrp securftp /var/zfs/holding chmod 774 /var/zfs/holding