Author Topic: Maintenance Archive Section for mibew-1.6.4  (Read 17620 times)

0 Members and 1 Guest are viewing this topic.

ChrisS

  • Sr. Member
  • ****
  • Posts: 36
Maintenance Archive Section for mibew-1.6.4
« on: April 24, 2013, 03:36:49 AM »
Hi All,
The below will add a Maintenance menu to the settings section of mibew messenger where at the moment will allow messages to be archived by number specified in the box Default: 30 day's.



Make sure you backup your files & database before implementing always use a proper file editor like  Notepad++  for doing file edits.

Do the following edits & upload the uncompressed attached rar files to the relevant directories or make the files if the rar goes missing or gets corrupt.

The following directories/files can be found inside the main messenger directory as Default called webim, However, you may of changed its name.

Open: libs/common.php

Find:
Code: [Select]
?>
Add Above:
Code: [Select]
// This function will archive ALL messages greater than ? days
function archive()
{
// date function minus ? days tells us what we need to select and move it over
$link = connect();

$sqlresult = mysql_query("UPDATE chatmessage CROSS JOIN chatconfig SET chatmessage.archive = '1' WHERE chatconfig.vckey = 'archive_date' AND chatmessage.dtmcreated < CURRENT_DATE - INTERVAL CAST(chatconfig.vcvalue AS UNSIGNED) DAY",$link) or die(' Query failed: '.mysql_error().": ".$query);

// This adds all information from chatmessage to archivechatmessage
$sqlArchive = mysql_query("INSERT INTO archivechatmessage SELECT * FROM chatmessage WHERE archive = '1'",$link) or die(' Query failed: '.mysql_error().": ".$query);

// This deletes from chatmessage
$sqlDelete = mysql_query("DELETE FROM chatmessage WHERE archive = '1'",$link) or die(' Query failed: '.mysql_error().": ".$query);

}
// end of archive function

Open: libs/settings.php
Find:
Code: [Select]
getlocal("page_settings.tab.themes") => $active != 3 ? "$webimroot/operator/themes.php" : "",Add Below:
Code: [Select]
getlocal("page_settings.tab.maintenance") => $active != 4 ? "$webimroot/operator/maintenance.php" : "",

Open: locales/en/properties

At the very bottom add the following lines or add them into the list alphabetically.
Code: [Select]
maintenance.intro=Welcome to the maintenance page.
maintenance.archivemessagespage=Set amount of day's to archive, Default: 30
maintenance.archivemessagespagedo=What would you like to do?
maintenance.archivemessages=Archive messages older than set above.
maintenance.error=Field Correctly eg, 30 numeric only.
maintenance.noautherror=Not an administrator.
page_settings.tab.maintenance=Maintenance

The Default database name is webim, YOU! may of called it something else, make sure your in the correct database before running the following.
BACKUP the database Create the following table for the messages to be archived too .

Code: [Select]
CREATE TABLE IF NOT EXISTS `archivechatmessage` (
  `messageid` int(11) NOT NULL AUTO_INCREMENT,
  `threadid` int(11) NOT NULL,
  `ikind` int(11) NOT NULL,
  `agentId` int(11) NOT NULL DEFAULT '0',
  `tmessage` text NOT NULL,
  `dtmcreated` datetime DEFAULT '0000-00-00 00:00:00',
  `tname` varchar(64) DEFAULT NULL,
  `archive` int(1) NOT NULL,
  PRIMARY KEY (`messageid`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Add the following.

Code: [Select]
INSERT INTO `chatconfig` (`id`, `vckey`, `vcvalue`) VALUES (' ', 'archive_date', '30');
Code: [Select]
ALTER TABLE chatmessage ADD column archive int (1) DEFAULT 0;
Your done try it out.
Regards

Only if uploaded rar is missing or corrupt.

Make a new file called maintenance.php & upload to the operator directory.
Code: [Select]
<?php
/*
 * Copyright 2005-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
require_once('../libs/common.php');
require_once(
'../libs/operator.php');
require_once(
'../libs/settings.php');

// If box is checked, it grabs the box and then does the maintenance
$archive = isset($_POST['archive']);

if(
$archive == '1'){
archive();
}

$operator check_login();
csrfchecktoken();
$page = array('agentId' => '');
$errors = array();
$options = array('archive_date');
loadsettings();
if (
$settings['featuresversion'] != $featuresversion) {
$settings['featuresversion'] = $featuresversion;
update_settings();
}

foreach (
$options as $opt) {
$page[$opt] = $settings[$opt];
}

if (isset(
$_POST['archivedate'])) {
$page['archive_date'] = getparam('archivedate');
if (!is_numeric($page['archive_date'])) {
$errors[] = wrong_field("maintenance.error");
}
if (count($errors) == 0) {
foreach ($options as $opt) {
$settings[$opt] = $page[$opt];
}
update_settings();
header("Location: $webimroot/operator/maintenance.php?stored");
exit;
}
}

if (isset(
$_POST['sent'])) {
if (is_capable($can_administrate$operator)) {
foreach ($options as $opt) {
$settings[$opt] = verifyparam($opt"/^on$/""") == "on" "1" "0";
}
update_settings();
header("Location: $webimroot/operator/maintenance.php?stored");
exit;

} else {
$errors[] = "maintenance.noautherror";
}
}


$page['formarchivedate'] = $page['archive_date'];
$page['canmodify'] = is_capable($can_administrate$operator);
$page['stored'] = isset($_GET['stored']);

prepare_menu($operator);
setup_settings_tabs(4);
start_html_output();
require(
'../view/maintenance.php');
?>

Make a new file called maintenance.php & upload to the view directory.
Code: [Select]
<?php
/*
 * Copyright 2005-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
require_once("inc_menu.php");
require_once(
"inc_tabbar.php");

$page['title'] = getlocal("settings.title");
$page['menuid'] = "settings";

function 
tpl_content() { global $page$webimroot$errors;
?>


<?php echo getlocal("maintenance.intro"?>
<br />
<br />
<?php 
require_once('inc_errors.php');
?>

<?php if( $page['stored'] ) { ?>
<div id="formmessage"><?php echo getlocal("settings.saved"?></div>
<?php ?>

<form name="maintenance" method="post" action="<?php echo $webimroot ?>/operator/maintenance.php">
<?php print_csrf_token_input() ?>
 <div>
<?php print_tabbar(); ?>
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">

<div class="fieldForm">

<div class="field">
<div class="flabel"><?php echo getlocal('maintenance.archivemessagespagedo'?></div>
<br clear="all"/>
<div class="fvalue">
<input type="text" name="archivedate" size="4" value="<?php echo form_value('archivedate'?>" class="formauth"/>
</div>
<div class="fdescr"> &mdash; <?php echo getlocal('maintenance.archivemessagespage'?></div>
<br clear="all"/>
</div>

<div class="fbutton">
<input type="image" name="archivedate" value="" src='<?php echo $webimroot.getlocal("image.button.save"?>' alt='<?php echo getlocal("button.save"?>'/>
</div>

</div>
 </div>
<div class="formbottom"><div class="formbottomi"></div></div></div>
</div>

</form>

<br clear="all"/>

<form name="maintenance" method="post" action="<?php echo $webimroot ?>/operator/maintenance.php">
<?php print_csrf_token_input() ?>
 <div>

<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">

<div class="fieldForm">
<div class="field">

<input type="checkbox" name="archive" value='1' /> &mdash; <?php echo getlocal('maintenance.archivemessages'?>

</div>
</div>

<div class="fbutton">
<input type="image" name="save" value="" src='<?php echo $webimroot.getlocal("image.button.save"?>' alt='<?php echo getlocal("button.save"?>'/>
</div>

</div>

<div class="formbottom"><div class="formbottomi"></div></div></div>
 </div>

</form>

<?php 
/* content */

require_once('inc_main.php');
?>
« Last Edit: September 14, 2013, 07:57:25 PM by ChrisS »

ChrisS

  • Sr. Member
  • ****
  • Posts: 36
Re: Maintenance Archive Section for mibew-1.6.4
« Reply #1 on: April 24, 2013, 03:38:16 AM »
Reserved!

If an error occurs & you have checked your edits, then it's probably the authorization token check for CSRF attack function is not implemented in the messenger your using Always checkout & update your files from the GitHub.

To find out weather it's installed or not. look for the following line in libs/common.php Near the bottom.
Code: [Select]
/* authorization token check for CSRF attack */
If it's not there then the following will have to be done to correct the errors.
Open: view/maintenance.php
Find: X2
Code: [Select]
<?php print_csrf_token_input() ?>Replace with:
Code: [Select]
<!--<z?php print_csrf_token_input() ?>-->
Open: operator/maintenance.php
Find: X1
Code: [Select]
csrfchecktoken();Replace with:
Code: [Select]
//csrfchecktoken();
« Last Edit: September 14, 2013, 07:56:58 PM by ChrisS »

moreeagles

  • Jr. Member
  • **
  • Posts: 3
Re: Maintenance Archive Section for mibew-1.6.4
« Reply #2 on: May 09, 2013, 11:00:08 PM »
I can confirm this works on 1.6.4 in my deployment 100%

gappa

  • Jr. Member
  • **
  • Posts: 1
Re: Maintenance Archive Section for mibew-1.6.4
« Reply #3 on: July 22, 2013, 07:27:03 AM »
Yes it does work, Thank you.