⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.50
Server IP:
41.128.143.86
Server:
Linux host.raqmix.cloud 6.8.0-1025-azure #30~22.04.1-Ubuntu SMP Wed Mar 12 15:28:20 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.3.23
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
proc
/
self
/
root
/
usr
/
share
/
psa-pear
/
pear
/
View File Name :
turba-public-to-horde-share
#!/usr/bin/env php true in * a SQL source (such as 'localsql') - otherwise, you will turn every user's * private address book into a public source! * * Copyright 2005-2017 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (ASL). If you * did not receive this file, see http://www.horde.org/licenses/apache. * * @author Michael J. Rubinsky
* @package Turba */ if (file_exists(__DIR__ . '/../../turba/lib/Application.php')) { $baseDir = __DIR__ . '/../'; } else { require_once 'PEAR/Config.php'; $baseDir = PEAR_Config::singleton() ->get('horde_dir', null, 'pear.horde.org') . '/turba/'; } require_once $baseDir . 'lib/Application.php'; Horde_Registry::appInit('turba', array('cli' => true, 'user_admin' => true)); $cli->writeln('This script will turn all entries in the SQL address book into a globally shared address book.'); $cli->writeln('Make sure you read the script comments and be sure you know what you are doing.'); $sure = $cli->prompt('Are you ' . $cli->bold('sure') . ' you want to do this?', array('no', 'yes')); if (!$sure) { exit; } // Find out what our Auth driver will let us do and // get the list of all users if we can. If your site // has a *large* number of users, you may want to comment // out this section to avoid unnecessary overhead. $auth = $injector->getInstance('Horde_Core_Factory_Auth')->create(); if ($auth->hasCapability('list')) { $users = $auth->listUsers(); } // Get all the details. do { $owner = $cli->prompt('Username of the user you would like to own the new public source.'); // Might as well check this if we have the list. if (!empty($users) && !in_array($owner, $users)) { $cli->message($owner . ' is not a valid user!', 'cli.error'); $owner = ''; } } while(!$owner); do { $title = $cli->prompt('Enter the title you would like to give to the new public source.'); } while (!$title); $sourceKey = $cli->prompt('What is the internal name of the share we are converting? [localsql]'); if (!$sourceKey) { $sourceKey = 'localsql'; } // Create the new share. $turba_shares = $injector->getInstance('Turba_Shares'); $owner_uid = strval(new Horde_Support_Randomid()); $share = $turba_shares->newShare($GLOBALS['registry']->getAuth(), $sourceKey . ':' . $owner_uid, $title); $share->set('owner', $owner); $share->set('perm_default', Horde_Perms::SHOW | Horde_Perms::READ); $turba_shares->addShare($share); $share->save(); $cli->message('Created new Horde_Share object for the shared address book.', 'cli.success'); // Share created, now get a Turba_Driver and make the changes. $driver = $injector->getInstance('Turba_Factory_Driver')->create($sourceKey); $db = &$driver->_db; // Get the tablename in case we aren't using horde defaults. $tableName = $db->dsn['table']; $SQL = 'SELECT COUNT(*) FROM ' . $tableName . ';'; $count = $db->getOne($SQL); $cli->message("Moving $count contacts to $title.", 'cli.message'); $SQL = 'UPDATE ' . $tableName . ' SET owner_id=\'' . $owner_uid . '\';'; $result = $db->query($SQL); if ($result instanceof PEAR_Error) { var_dump($result); exit; } $prefDriver = $conf['prefs']['driver']; if ($prefDriver == 'sql') { // Automatically append this source to the addressbooks pref if desired. $autoAppend = $cli->prompt('Would you like to add the new public source to every user\'s address book preference?', array('no', 'yes')); if ($autoAppend) { $SQL = 'SELECT pref_uid, pref_value FROM horde_prefs WHERE pref_scope=\'turba\' AND pref_name=\'addressbooks\';'; $results = $db->getAll($SQL); if ($results instanceof PEAR_Error) { $cli->message('There was an error updating the user preferences: ' . $results->getMessage(), 'cli.error'); } else { foreach ($results as $row) { $newValue = $row[1] . "\n$sourceKey:$owner_uid"; $SQL = 'UPDATE horde_prefs SET pref_value=\'' . $newValue . '\' WHERE pref_uid=\'' . $row[0] . '\' AND pref_scope=\'turba\' AND pref_name=\'addressbooks\';'; $result = $db->query($SQL); if ($result instanceof PEAR_Error) { $cli->message('Could not update preferences for ' . $row[0] . ': ' . $result->getMessage(), 'cli.error'); } } } if (!($results instanceof PEAR_Error)) { $cli->message('Successfully added new shared address book to the user preferences.', 'cli.success'); } } } else { $cli->message('Your preference backend does not support updating all user preferences.', 'cli.warning'); $cli->message('Your users may have to manually add the new shared address book to their "addressbook" preference.', 'cli.warning'); } // Share our success. $cli->writeln($cli->bold("*** $title successfully created ***")); $cli->writeln('Share Info:'); $cli->writeln($cli->indent('Title: ' . $share->get('name'))); $cli->writeln($cli->indent('Owner: ' . $share->get('owner')));