Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
add_remove_url.php
1 <?php
25 error_reporting(E_ALL);
26 if ((php_sapi_name() != 'cli')) {
27  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
28 }
29 
30 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
31 if (empty($SYSTEM_ROOT)) {
32  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
33  exit();
34 }
35 
36 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
37  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
38  exit();
39 }
40 
41 require_once $SYSTEM_ROOT.'/core/include/init.inc';
42 
43 // ask for the root password for the system
44 echo 'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.'": ';
45 system('stty -echo');
46 $root_password = rtrim(fgets(STDIN, 4094));
47 system('stty echo');
48 
49 // check that the correct root password was entered
50 $root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
51 if (!$root_user->comparePassword($root_password)) {
52  echo "ERROR: The root password entered was incorrect\n";
53  exit();
54 }
55 $GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user);
56 
57 echo "\n";
58 
59 $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
60 $db =& $GLOBALS['SQ_SYSTEM']->db;
61 
62 
63 $action = NULL;
64 while ($action != 'add' && $action != 'remove') {
65  $action = get_line('Please specify whether you want to \'add\' or \'remove\' a URL: ');
66 }
67 
68 require_once $SYSTEM_ROOT.'/scripts/url_manager.inc';
69 
70 if ($action == 'add') {
71  $inputs = URL_Manager::cliInterfaceAddUrl();
72  $queries = URL_Manager::addUrl($inputs['http'], $inputs['https'], $inputs['new_url'], $inputs['existing_url'], $inputs['siteid'], $inputs['update_file_public_live_assets'], $inputs['existing_urlid'], $SYSTEM_ROOT);
73 } else if ($action == 'remove') {
74  $remove_url_info = URL_Manager::cliInterfaceRemoveUrl();
75  $queries = URL_Manager::removeUrl($remove_url_info['remove_urlid'], $remove_url_info['remove_assetid'], $remove_url_info['remove_url'], FALSE, $SYSTEM_ROOT);
76 }//end else if
77 
78 
79  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
80  $GLOBALS['SQ_SYSTEM']->restoreCurrentUser();
81 
82  exit(0);
83 
84 
93 function get_line($prompt='')
94 {
95  echo $prompt;
96  // now get their entry and remove the trailing new line
97  return rtrim(fgets(STDIN, 4096));
98 
99 }//end get_line()
100 
101 
102 ?>