Пример #1
0
 /**
  * @dataProvider configurationDataProvider
  */
 public function testSetValue($key, $input, $expected)
 {
     $configuration = new \OCA\User_LDAP\Configuration('t01', false);
     $settingsInput = array('ldapBaseUsers' => array('cn=someUsers,dc=example,dc=org', '  ', ' cn=moreUsers,dc=example,dc=org '));
     $configuration->setConfiguration([$key => $input]);
     $this->assertSame($configuration->{$key}, $expected);
 }
Пример #2
0
        } catch (\Exception $e) {
            \OCP\JSON::error(array('message' => $e->getMessage()));
            exit;
        }
        \OCP\JSON::error();
        exit;
        break;
    case 'save':
        $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
        $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
        if ($key === false || is_null($val)) {
            \OCP\JSON::error(array('message' => $l->t('No data specified')));
            exit;
        }
        $cfg = array($key => $val);
        $setParameters = array();
        $configuration->setConfiguration($cfg, $setParameters);
        if (!in_array($key, $setParameters)) {
            \OCP\JSON::error(array('message' => $l->t($key . ' Could not set configuration %s', $setParameters[0])));
            exit;
        }
        $configuration->saveConfiguration();
        //clear the cache on save
        $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
        $connection->clearCache();
        OCP\JSON::success();
        break;
    default:
        \OCP\JSON::error(array('message' => $l->t('Action does not exist')));
        break;
}
 * 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);