Ejemplo n.º 1
0
OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$l = \OC::$server->getL10N('user_ldap');
if (!isset($_POST['action'])) {
    \OCP\JSON::error(array('message' => $l->t('No action specified')));
}
$action = (string) $_POST['action'];
if (!isset($_POST['ldap_serverconfig_chooser'])) {
    \OCP\JSON::error(array('message' => $l->t('No configuration specified')));
}
$prefix = (string) $_POST['ldap_serverconfig_chooser'];
$ldapWrapper = new \OCA\User_LDAP\LDAP();
$configuration = new \OCA\User_LDAP\Configuration($prefix);
$con = new \OCA\User_LDAP\Connection($ldapWrapper, '', null);
$con->setConfiguration($configuration->getConfiguration());
$con->ldapConfigurationActive = true;
$con->setIgnoreValidation(true);
$userManager = new \OCA\User_LDAP\User\Manager(\OC::$server->getConfig(), new \OCA\User_LDAP\FilesystemHelper(), new \OCA\User_LDAP\LogWrapper(), \OC::$server->getAvatarManager(), new \OCP\Image(), \OC::$server->getDatabaseConnection(), \OC::$server->getUserManager());
$access = new \OCA\User_LDAP\Access($con, $ldapWrapper, $userManager);
$wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access);
switch ($action) {
    case 'guessPortAndTLS':
    case 'guessBaseDN':
    case 'detectEmailAttribute':
    case 'detectUserDisplayNameAttribute':
    case 'determineGroupMemberAssoc':
    case 'determineUserObjectClasses':
    case 'determineGroupObjectClasses':
    case 'determineGroupsForUsers':
    case 'determineGroupsForGroups':
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
// Check user and app status
OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$helper = new \OCA\User_LDAP\Helper();
$serverConnections = $helper->getServerConfigurationPrefixes();
sort($serverConnections);
$lk = array_pop($serverConnections);
$ln = intval(str_replace('s', '', $lk));
$nk = 's' . str_pad($ln + 1, 2, '0', STR_PAD_LEFT);
$resultData = array('configPrefix' => $nk);
$newConfig = new \OCA\User_LDAP\Configuration($nk, false);
if (isset($_POST['copyConfig'])) {
    $originalConfig = new \OCA\User_LDAP\Configuration($_POST['copyConfig']);
    $newConfig->setConfiguration($originalConfig->getConfiguration());
} else {
    $configuration = new \OCA\User_LDAP\Configuration($nk, false);
    $newConfig->setConfiguration($configuration->getDefaults());
    $resultData['defaults'] = $configuration->getDefaults();
}
$newConfig->saveConfiguration();
OCP\JSON::success($resultData);