1#!/usr/bin/env php 2<?php 3 4/** 5 * Observium 6 * 7 * This file is part of Observium. 8 * 9 * @package observium 10 * @subpackage cli 11 * @author Adam Armstrong <adama@observium.org> 12 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 13 * 14 */ 15 16chdir(dirname($argv[0])); 17$scriptname = basename($argv[0]); 18 19$options = getopt("d"); 20if (isset($options['d'])) { array_shift($argv); } // for compatability 21 22include("includes/sql-config.inc.php"); 23 24print_message("%g".OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION."\n%WAdd User%n\n", 'color'); 25 26if (OBS_DEBUG) { print_versions(); } 27 28$auth_file = $config['html_dir'].'/includes/authentication/' . $config['auth_mechanism'] . '.inc.php'; 29if (is_file($auth_file)) 30{ 31 include($auth_file); 32 33 // Include base auth functions calls 34 include($config['html_dir'].'/includes/authenticate-functions.inc.php'); 35} else { 36 print_error("ERROR: no valid auth_mechanism defined."); 37 exit(); 38} 39 40if (auth_usermanagement()) 41{ 42 if (isset($argv[1]) && isset($argv[2]) && isset($argv[3])) 43 { 44 if (!auth_user_exists($argv[1])) 45 { 46 if (adduser($argv[1], $argv[2], $argv[3], @$argv[4])) 47 { 48 print_success("User ".$argv[1]." added successfully."); 49 } else { 50 print_error("User ".$argv[1]." creation failed!"); 51 } 52 } else { 53 print_warning("User ".$argv[1]." already exists!"); 54 } 55 } else { 56 $msg = "%n 57USAGE: 58$scriptname <username> <password> <level 1-10> [email] 59 60EXAMPLE: 61%WADMIN%n: $scriptname <username> <password> 10 [email] 62 63USER LEVELS:" . PHP_EOL; 64 65 foreach($GLOBALS['config']['user_level'] as $level => $entry) 66 { 67 $msg .= ' '.$level.' - %W'.$entry['name'].'%n ('.$entry['subtext'].')'. PHP_EOL; 68 } 69 $msg .= PHP_EOL . "%rInvalid arguments!%n"; 70 71 print_message($msg, 'color', FALSE); 72 } 73} else { 74 print_error("Auth module does not allow adding users!"); 75} 76 77// EOF 78