From 8a1a88d48c556bfd4841ebf68b83fc2a8606b2aa Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 01:20:00 -0700 Subject: [PATCH 1/8] Fix #190 --- code/web/public_php/ams/func/upload.php | 6 ++++++ code/web/public_php/ams/templates/show_ticket.tpl | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/code/web/public_php/ams/func/upload.php b/code/web/public_php/ams/func/upload.php index fdf9f6fd7..ced82c48e 100644 --- a/code/web/public_php/ams/func/upload.php +++ b/code/web/public_php/ams/func/upload.php @@ -28,7 +28,13 @@ session_start(); $fileParts = pathinfo($_FILES['Filedata']['name']); Ticket::add_Attachment($_GET['id'],$_FILES['Filedata']['name'],$_SESSION['id'],$tempFile); + echo "Uploaded :".$_FILES['Filedata']['name']; + } else { + echo "Upload Failed!"; } + echo "Upload Failed!"; } + echo "Upload Failed!"; } + echo "Upload Failed!"; ?> diff --git a/code/web/public_php/ams/templates/show_ticket.tpl b/code/web/public_php/ams/templates/show_ticket.tpl index 19d35b98d..b832f29b1 100644 --- a/code/web/public_php/ams/templates/show_ticket.tpl +++ b/code/web/public_php/ams/templates/show_ticket.tpl @@ -141,12 +141,14 @@ 'multi' : true, 'method' : 'post', 'swf': 'misc/uploadify.swf', - 'uploader': 'func/upload.php?id='+{/literal}{$ticket_id}{literal} + 'displayData': 'percentage', + 'uploader': 'func/upload.php?id='+{/literal}{$ticket_id}{literal}, + 'removeCompleted' : false }); - }); {/literal} +
From 4293518dcfb9766887f79479a05ea3ca0ecb7c27 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 01:21:59 -0700 Subject: [PATCH 2/8] added placeholder --- code/web/public_php/ams/files/PLACEHOLDER | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 code/web/public_php/ams/files/PLACEHOLDER diff --git a/code/web/public_php/ams/files/PLACEHOLDER b/code/web/public_php/ams/files/PLACEHOLDER new file mode 100644 index 000000000..e69de29bb From bd442c985476d1d876417c7e9512f8a6e1097e51 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 01:22:19 -0700 Subject: [PATCH 3/8] added placeholder --- code/web/public_php/ams/files/index.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 code/web/public_php/ams/files/index.html diff --git a/code/web/public_php/ams/files/index.html b/code/web/public_php/ams/files/index.html new file mode 100644 index 000000000..e69de29bb From 5ae905d317048d0939f1da01fbbbd6e869d5d968 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 01:22:39 -0700 Subject: [PATCH 4/8] remove old file --- code/web/public_php/ams/files/PLACEHOLDER | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 code/web/public_php/ams/files/PLACEHOLDER diff --git a/code/web/public_php/ams/files/PLACEHOLDER b/code/web/public_php/ams/files/PLACEHOLDER deleted file mode 100644 index e69de29bb..000000000 From e99c43095e0ebe7fe95399f69014b1849b27aa70 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 01:30:54 -0700 Subject: [PATCH 5/8] Made filesize friendly --- code/web/private_php/ams/autoload/ticket.php | 12 ++++++++++++ code/web/public_php/.htaccess | 2 -- code/web/public_php/ams/templates/show_ticket.tpl | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) delete mode 100644 code/web/public_php/.htaccess diff --git a/code/web/private_php/ams/autoload/ticket.php b/code/web/private_php/ams/autoload/ticket.php index 013dad842..e6af8e188 100644 --- a/code/web/private_php/ams/autoload/ticket.php +++ b/code/web/private_php/ams/autoload/ticket.php @@ -216,6 +216,18 @@ class Ticket{ foreach ($fetchall as &$value) { $webUser = new WebUsers($value['Uploader']); $fetchall[$base]['Username'] = $webUser->getUsername(); + + $bytes = $fetchall[$base]['Filesize']; + $precision = 2; + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + $fetchall[$base]['Filesize'] = round($bytes, $precision) . ' ' . $units[$pow];; $base++; } return $fetchall; diff --git a/code/web/public_php/.htaccess b/code/web/public_php/.htaccess deleted file mode 100644 index c0b74b60d..000000000 --- a/code/web/public_php/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -RewriteEngine On -RewriteRule ^$ /ams [R=301,L] diff --git a/code/web/public_php/ams/templates/show_ticket.tpl b/code/web/public_php/ams/templates/show_ticket.tpl index b832f29b1..deed7c0af 100644 --- a/code/web/public_php/ams/templates/show_ticket.tpl +++ b/code/web/public_php/ams/templates/show_ticket.tpl @@ -42,7 +42,7 @@ {$array['Filename']} {$array['Timestamp']} - {$array['Filesize']} Bytes + {$array['Filesize']} {if $permission > 1} {$array['Username']} {else} From f46de3129ed34f264b9f59517d618b8896ed9db1 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 02:10:09 -0700 Subject: [PATCH 6/8] fix sync --- code/web/private_php/ams/autoload/dblayer.php | 1 + code/web/private_php/ams/autoload/sync.php | 11 ++++++----- code/web/private_php/ams/autoload/users.php | 2 +- code/web/private_php/ams/tmp/placeholder | 0 code/web/public_php/ams/autoload/webusers.php | 4 ++-- .../ams/cron/mail_cron.php | 4 ++-- .../ams/cron/sync_cron.php | 7 +++---- code/web/public_php/ams/index.php | 2 +- code/web/public_php/ams/templates/syncing.tpl | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 code/web/private_php/ams/tmp/placeholder rename code/web/{private_php => public_php}/ams/cron/mail_cron.php (64%) rename code/web/{private_php => public_php}/ams/cron/sync_cron.php (55%) diff --git a/code/web/private_php/ams/autoload/dblayer.php b/code/web/private_php/ams/autoload/dblayer.php index 1f361008b..140f6bfd1 100644 --- a/code/web/private_php/ams/autoload/dblayer.php +++ b/code/web/private_php/ams/autoload/dblayer.php @@ -201,6 +201,7 @@ class DBLayer { $field_option_values = ltrim($field_option_values, ','); try { $sth = $this->PDO->prepare("UPDATE $tb_name SET $field_option_values WHERE $where "); + error_log("UPDATE $tb_name SET $field_option_values WHERE $where "); foreach ($data as $key => $value) { $sth->bindValue(":$key", $value); diff --git a/code/web/private_php/ams/autoload/sync.php b/code/web/private_php/ams/autoload/sync.php index a79ef8b83..fe05e628e 100644 --- a/code/web/private_php/ams/autoload/sync.php +++ b/code/web/private_php/ams/autoload/sync.php @@ -18,14 +18,15 @@ class Sync{ if (function_exists('pcntl_fork')) { $pid = pcntl_fork(); } - $pidfile = '/tmp/ams_cron_pid'; + global $AMS_TMPDIR; + $pidfile = $AMS_TMPDIR.'/ams_cron_pid'; - if(isset($pid)) { + if(isset($pid) and function_exists('pcntl_fork') ) { // We're the main process. } else { if(!file_exists($pidfile)) { $pid = getmypid(); - $file = fopen($pidfile, 'w'); + $file = fopen($pidfile, 'w+'); fwrite($file, $pid); fclose($file); @@ -57,13 +58,13 @@ class Sync{ $decode = json_decode($record['query']); $values = array('Password' => $decode[1]); //make connection with and put into shard db & delete from the lib - $db->update("user", $values, "Login = $decode[0]"); + $db->update("user", $values, "Login = '$decode[0]'"); break; case 'change_mail': $decode = json_decode($record['query']); $values = array('Email' => $decode[1]); //make connection with and put into shard db & delete from the lib - $db->update("user", $values, "Login = $decode[0]"); + $db->update("user", $values, "Login = '$decode[0]'"); break; case 'createUser': $decode = json_decode($record['query']); diff --git a/code/web/private_php/ams/autoload/users.php b/code/web/private_php/ams/autoload/users.php index ea8d134d1..1754a4f05 100644 --- a/code/web/private_php/ams/autoload/users.php +++ b/code/web/private_php/ams/autoload/users.php @@ -436,7 +436,7 @@ class Users{ try { //make connection with and put into shard db $dbs = new DBLayer("shard"); - $dbs->update("user", $values, "Login = $user"); + $dbs->update("user", $values, "Login = '$user'"); return "ok"; } catch (PDOException $e) { diff --git a/code/web/private_php/ams/tmp/placeholder b/code/web/private_php/ams/tmp/placeholder new file mode 100644 index 000000000..e69de29bb diff --git a/code/web/public_php/ams/autoload/webusers.php b/code/web/public_php/ams/autoload/webusers.php index b674f63dd..b01ddf02d 100644 --- a/code/web/public_php/ams/autoload/webusers.php +++ b/code/web/public_php/ams/autoload/webusers.php @@ -234,11 +234,11 @@ class WebUsers extends Users{ $hashpass = crypt($pass, WebUsers::generateSALT()); $reply = WebUsers::setAmsPassword($user, $hashpass); - $values = Array('pass' => $hashpass); + $values = Array('Password' => $hashpass); try { //make connection with and put into shard db $dbw = new DBLayer("web"); - $dbw->update("ams_user", $values,"Login = $user"); + $dbw->update("ams_user", $values,"Login = '$user'"); } catch (PDOException $e) { //ERROR: the web DB is offline diff --git a/code/web/private_php/ams/cron/mail_cron.php b/code/web/public_php/ams/cron/mail_cron.php similarity index 64% rename from code/web/private_php/ams/cron/mail_cron.php rename to code/web/public_php/ams/cron/mail_cron.php index 557a57417..608c3b2c0 100644 --- a/code/web/private_php/ams/cron/mail_cron.php +++ b/code/web/public_php/ams/cron/mail_cron.php @@ -5,8 +5,8 @@ * @author Daan Janssens, mentored by Matthew Lagoe */ -require( '../libinclude.php' ); -require( '../../www/config.php' ); +require( '../../config.php' ); +require_once( $AMS_LIB . '/libinclude.php' );; $mail_handler = new Mail_Handler(); $mail_handler->cron(); \ No newline at end of file diff --git a/code/web/private_php/ams/cron/sync_cron.php b/code/web/public_php/ams/cron/sync_cron.php similarity index 55% rename from code/web/private_php/ams/cron/sync_cron.php rename to code/web/public_php/ams/cron/sync_cron.php index b39da0818..905d1f7dc 100644 --- a/code/web/private_php/ams/cron/sync_cron.php +++ b/code/web/public_php/ams/cron/sync_cron.php @@ -4,8 +4,7 @@ * This small piece of php code calls the syncdata() function of Sync class. * @author Daan Janssens, mentored by Matthew Lagoe */ - -require( '../libinclude.php' ); -require( '../../www/config.php' ); - +error_log('test2'); +require( '../../config.php' ); +require_once( $AMS_LIB . '/libinclude.php' ); Sync::syncdata(); \ No newline at end of file diff --git a/code/web/public_php/ams/index.php b/code/web/public_php/ams/index.php index 1ab707e79..06d780f4a 100644 --- a/code/web/public_php/ams/index.php +++ b/code/web/public_php/ams/index.php @@ -37,7 +37,7 @@ if ( isset( $_GET["cron"] ) ) { } // Always try to sync on page load, ie "lazy" cron -Sync :: syncdata( false ); +Sync :: syncdata( true ); // Decide what page to load if ( ! isset( $_GET["page"] ) ) { diff --git a/code/web/public_php/ams/templates/syncing.tpl b/code/web/public_php/ams/templates/syncing.tpl index 5cd52187d..7ddc82a30 100644 --- a/code/web/public_php/ams/templates/syncing.tpl +++ b/code/web/public_php/ams/templates/syncing.tpl @@ -15,7 +15,7 @@ From f27cd046a01487c4052ac5cb75b2a086fd44c461 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 02:10:32 -0700 Subject: [PATCH 7/8] remove errolog --- code/web/public_php/ams/cron/sync_cron.php | 1 - 1 file changed, 1 deletion(-) diff --git a/code/web/public_php/ams/cron/sync_cron.php b/code/web/public_php/ams/cron/sync_cron.php index 905d1f7dc..dea7f1d7c 100644 --- a/code/web/public_php/ams/cron/sync_cron.php +++ b/code/web/public_php/ams/cron/sync_cron.php @@ -4,7 +4,6 @@ * This small piece of php code calls the syncdata() function of Sync class. * @author Daan Janssens, mentored by Matthew Lagoe */ -error_log('test2'); require( '../../config.php' ); require_once( $AMS_LIB . '/libinclude.php' ); Sync::syncdata(); \ No newline at end of file From 72cfe723e117a2d12b51148945d697fdc82173b1 Mon Sep 17 00:00:00 2001 From: botanic Date: Fri, 5 Sep 2014 02:17:19 -0700 Subject: [PATCH 8/8] fixed some caching --- code/web/private_php/ams/autoload/helpers.php | 5 +++-- code/web/public_php/ams/templates/show_ticket.tpl | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/code/web/private_php/ams/autoload/helpers.php b/code/web/private_php/ams/autoload/helpers.php index 6c6d2227e..6c80813c2 100644 --- a/code/web/private_php/ams/autoload/helpers.php +++ b/code/web/private_php/ams/autoload/helpers.php @@ -22,19 +22,20 @@ class Helpers { global $SITEBASE; global $AMS_TRANS; global $INGAME_LAYOUT; + global $AMS_CACHEDIR; // define('SMARTY_SPL_AUTOLOAD',1); require_once $AMS_LIB . '/smarty/libs/Smarty.class.php'; spl_autoload_register( '__autoload' ); $smarty = new Smarty; $smarty -> setCompileDir( $SITEBASE . '/templates_c/' ); - $smarty -> setCacheDir( $SITEBASE . '/cache/' ); + $smarty -> setCacheDir( $AMS_CACHEDIR ); $smarty -> setConfigDir( $SITEBASE . '/configs/' ); // turn smarty debugging on/off $smarty -> debugging = false; // caching must be disabled for multi-language support $smarty -> caching = false; - $smarty -> cache_lifetime = 5; + $smarty -> cache_lifetime = 300; if (function_exists('apc_cache_info')) { // production diff --git a/code/web/public_php/ams/templates/show_ticket.tpl b/code/web/public_php/ams/templates/show_ticket.tpl index deed7c0af..417b465c7 100644 --- a/code/web/public_php/ams/templates/show_ticket.tpl +++ b/code/web/public_php/ams/templates/show_ticket.tpl @@ -136,7 +136,7 @@ $(document).ready( function () { $('#file_upload').uploadify({ - 'formData' : {'PHPSESSID': '{/literal}{$sessionid}{literal}'}, + 'formData' : {'PHPSESSID': '{/literal}{nocache}{$sessionid}{/nocache}{literal}'}, 'auto' : true, 'multi' : true, 'method' : 'post',