Jump to content

[System Patch] Add Time Zone Selection to Configuration Tile


no42

Recommended Posts

Simple patch that adds functionality to easily change your time zone, from the configuration tile.

Feel free to check the code/patch below, its Saturday night and I've been drinking :) :

diff -Npaur /Volumes/Pineapple/pineapple/components/system/configuration/functions.php /tmp/configuration-new/functions.php
--- /Volumes/Pineapple/pineapple/components/system/configuration/functions.php 2013-10-10 07:54:58.000000000 +0100
+++ /tmp/configuration-new/functions.php 2013-11-02 22:29:15.000000000 +0000
@@ -6,6 +6,10 @@ if(isset($_GET['change_port'])){
   echo change_port($_POST['port']);
 }
 
+if(isset($_GET['change_time'])){
+  echo change_time($_POST['time']);
+}
+
 if(isset($_GET['change_password'])){
   echo change_password($_POST['password'], $_POST['repeat']);
 }
@@ -93,6 +97,14 @@ function change_port($port){
   return '<font color="lime">Port changed to '.$port.'.</font>';
 }
 
+function change_time($time){
+  if (in_array($time, range(-12, 12))) {
+    exec("echo GMT".$time." > /etc/TZ");
+  }else{
+    exec("echo UTC > /etc/TZ");
+  }
+}
+
 function change_password($password, $repeat){
   if($password != $repeat || trim($password) == ''){
     return "<font color='red'>There was an error. Please try again</font>";
diff -Npaur /Volumes/Pineapple/pineapple/components/system/configuration/includes/content/time.php /tmp/configuration-new/includes/content/time.php
--- /Volumes/Pineapple/pineapple/components/system/configuration/includes/content/time.php 1970-01-01 01:00:00.000000000 +0100
+++ /tmp/configuration-new/includes/content/time.php 2013-11-02 22:29:15.000000000 +0000
@@ -0,0 +1,38 @@
+<?php include('/pineapple/includes/api/tile_functions.php'); ?>
+
+<center><div id='config_message'></div></center>
+<fieldset>
+  <legend>Time Settings</legend>
+    <form id='config_change_time' method='POST' action='/components/system/configuration/functions.php?change_time' onSubmit='$(this).AJAXifyForm(update_message); return false;'>
+        Time Zone:
+        <select name="time" id="time">
+              <option value="12">(GMT -12:00) Eniwetok, Kwajalein</option>
+              <option value="11">(GMT -11:00) Midway Island, Samoa</option>
+              <option value="10">(GMT -10:00) Hawaii</option>
+              <option value="9">(GMT -9:00) Alaska</option>
+              <option value="8">(GMT -8:00) Pacific Time (US & Canada)</option>
+              <option value="7">(GMT -7:00) Mountain Time (US & Canada)</option>
+              <option value="6">(GMT -6:00) Central Time (US & Canada), Mexico City</option>
+              <option value="5">(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima</option>
+              <option value="4">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
+              <option value="3">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
+              <option value="2">(GMT -2:00) Mid-Atlantic</option>
+              <option value="1">(GMT -1:00 hour) Azores, Cape Verde Islands</option>
+              <option value="0">(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
+              <option value="-1">(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
+              <option value="-2">(GMT +2:00) Kaliningrad, South Africa</option>
+              <option value="-3">(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
+              <option value="-4">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
+              <option value="-5">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
+              <option value="-6">(GMT +6:00) Almaty, Dhaka, Colombo</option>
+              <option value="-7">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
+              <option value="-8">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
+              <option value="-9">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
+              <option value="-10">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
+              <option value="-11">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
+              <option value="-12">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
+        </select> 
+            <input type='submit' name='change_time' value='Change Time'>
+    </form>
+</fieldset>
+              
diff -Npaur /Volumes/Pineapple/pineapple/components/system/configuration/large_tile.php /tmp/configuration-new/large_tile.php
--- /Volumes/Pineapple/pineapple/components/system/configuration/large_tile.php 2013-10-10 07:54:58.000000000 +0100
+++ /tmp/configuration-new/large_tile.php 2013-11-02 22:29:15.000000000 +0000
@@ -9,5 +9,6 @@
   <li><a id="dnsspoof">DNS Spoof</a></li>
   <li><a id="css">CSS Editor</a></li>
   <li><a id="advanced">Advanced</a></li>
+  <li><a id="time">Time</a></li>
 </ul>
 <div class="tabContainer" />
\ No newline at end of file
Link to comment
Share on other sites

midnitesnake,

Love the idea but after making changes to the two existing files and creating the time.php file all I get in the Configuration Tile: Time tab is an echo of the topmost bar of the Management Page with time uptime and logout.

Any idea what I've done wrong?

Link to comment
Share on other sites

I did it manually. Wasn't sure about those diff commands so I figured it out from what is mentioned and the + symbols that indicated lines added. What you pasted looks exactly what was in the spoiler. I'll check again though. Maybe you could post the 3 files or spoilers of the content....

Link to comment
Share on other sites

Individual paste bin's of the modified and new file:

functions.php http://pastebin.com/AQfwCDt4

large_tile.php http://pastebin.com/ESTMyC8X

includes/content/time.php http://pastebin.com/Tuw2nGcd

but should be simple as:

opkg update
opkg install patch --dest usb
[manually copy n paste patch to file, e.g. vi time.patch]
patch < time.patch
Edited by midnitesnake
Link to comment
Share on other sites

Thanks, that's got it working now. I copied from paste bin and created the .php files then scp'd them over replacing the other files I had edited. There was a 1 byte difference in each file for some reason. Rebooted and there it is.

Link to comment
Share on other sites

  • 2 weeks later...

Timezone changing has been added to the UI, based on the above patches, modified to fit in better with our usual style! Thanks!

love it thanks Seb! although it does not seem to save the timezone for me after a powerdown

Edited by jjd
Link to comment
Share on other sites

That's great... After yesterdays bar update it wiped it again. Was going to do it this evening but thanks to you now it's just built in. I know it's something simple but I always want to see that time up there correct even if I'm not connected via client mode and more importantly I want any logs produced in that configuration to be accurate as well.

Link to comment
Share on other sites

That's great... After yesterdays bar update it wiped it again. Was going to do it this evening but thanks to you now it's just built in. I know it's something simple but I always want to see that time up there correct even if I'm not connected via client mode and more importantly I want any logs produced in that configuration to be accurate as well.

Yeah, the issue for me is, I'm never on a firmware for long enough to care about the TZ. That's why I never added it, as it didn't occur to me. Silly but the truth.

Link to comment
Share on other sites

That's great... After yesterdays bar update it wiped it again. Was going to do it this evening but thanks to you now it's just built in. I know it's something simple but I always want to see that time up there correct even if I'm not connected via client mode and more importantly I want any logs produced in that configuration to be accurate as well.

The logs being correct is the main reason i want the time zone to be set properly as well. Now i do not have to set it manually.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...