Beispiel #1
0
 /**
  * constructor
  * This should be called
  * @param int|null $id
  * @param boolean $cached
  */
 public function __construct($id = null, $cached = true)
 {
     $sid = session_id();
     if (!$cached) {
         $this->id = 'nocache';
         return true;
     }
     if (is_null($id)) {
         $this->reset();
         $data = self::_serialize($this->_state);
         $sql = 'INSERT INTO `tmp_browse` (`sid`, `data`) VALUES(?, ?)';
         Dba::write($sql, array($sid, $data));
         $this->id = Dba::insert_id();
         return true;
     } else {
         $sql = 'SELECT `data` FROM `tmp_browse` WHERE `id` = ? AND `sid` = ?';
         $db_results = Dba::read($sql, array($id, $sid));
         if ($results = Dba::fetch_assoc($db_results)) {
             $this->id = $id;
             $this->_state = (array) self::_unserialize($results['data']);
             return true;
         }
     }
     AmpError::add('browse', T_('Browse not found or expired, try reloading the page'));
     return false;
 }
Beispiel #2
0
 /**
  * set
  *
  * This sets config values.
  * @param string $name
  * @param boolean $clobber
  */
 public static function set($name, $value, $clobber = false)
 {
     if (isset(self::$_global[$name]) && !$clobber) {
         debug_event('Config', "Tried to overwrite existing key {$name} without setting clobber", 5);
         AmpError::add('Config Global', sprintf(T_('Trying to clobber \'%s\' without setting clobber'), $name));
         return false;
     }
     self::$_global[$name] = $value;
 }
Beispiel #3
0
 /**
  * add
  * This is a public static function it adds a new error message to the array
  * It can optionally clobber rather then adding to the error message
  */
 public static function add($name, $message, $clobber = 0)
 {
     // Make sure its set first
     if (!isset(AmpError::$errors[$name])) {
         AmpError::$errors[$name] = $message;
         AmpError::$state = true;
         $_SESSION['errors'][$name] = $message;
     } elseif ($clobber) {
         AmpError::$state = true;
         AmpError::$errors[$name] = $message;
         $_SESSION['errors'][$name] = $message;
     } else {
         AmpError::$state = true;
         AmpError::$errors[$name] .= "<br />\n" . $message;
         $_SESSION['errors'][$name] .= "<br />\n" . $message;
     }
     // If on SSE worker, output the error directly.
     if (defined('SSE_OUTPUT')) {
         echo "data: display_sse_error('" . addslashes($message) . "')\n\n";
         ob_flush();
         flush();
     }
 }
Beispiel #4
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog()
 {
     $songsadded = 0;
     try {
         $api = $this->createClient();
         if ($api != null) {
             // Get all liked songs
             $songs = json_decode($api->get('me/favorites'));
             if ($songs) {
                 foreach ($songs as $song) {
                     if ($song->streamable == true && $song->kind == 'track') {
                         $data = array();
                         $data['artist'] = $song->user->username;
                         $data['album'] = $data['artist'];
                         $data['title'] = $song->title;
                         $data['year'] = $song->release_year;
                         $data['mode'] = 'vbr';
                         $data['genre'] = explode(' ', $song->genre);
                         $data['comment'] = $song->description;
                         $data['file'] = $song->stream_url . '.mp3';
                         // Always stream as mp3, if evolve => $song->original_format;
                         $data['size'] = $song->original_content_size;
                         $data['time'] = intval($song->duration / 1000);
                         if ($this->check_remote_song($data)) {
                             debug_event('soundcloud_catalog', 'Skipping existing song ' . $data['file'], 5);
                         } else {
                             $data['catalog'] = $this->id;
                             debug_event('soundcloud_catalog', 'Adding song ' . $data['file'], 5, 'ampache-catalog');
                             if (!Song::insert($data)) {
                                 debug_event('soundcloud_catalog', 'Insert failed for ' . $data['file'], 1);
                                 AmpError::add('general', T_('Unable to Insert Song - %s'), $data['file']);
                             } else {
                                 $songsadded++;
                             }
                         }
                     }
                 }
                 UI::update_text('', T_('Completed updating SoundCloud catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
                 // Update the last update value
                 $this->update_last_update();
             } else {
                 AmpError::add('general', T_('API Error: cannot get song list.'));
             }
         } else {
             AmpError::add('general', T_('API Error: cannot connect to SoundCloud.'));
         }
     } catch (Exception $ex) {
         AmpError::add('general', T_('SoundCloud exception: ') . $ex->getMessage());
     }
     return true;
 }
                    <input type="text" name="start" value="<?php 
if ($action == 'show_add_current') {
    echo scrub_out($_SERVER['REMOTE_ADDR']);
} else {
    echo scrub_out($_REQUEST['start']);
}
?>
" />
            </td>
            <td>
                <?php 
echo T_('End');
?>
:
                    <?php 
AmpError::display('end');
?>
                    <input type="text" name="end" value="<?php 
if ($action == 'show_add_current') {
    echo scrub_out($_SERVER['REMOTE_ADDR']);
} else {
    echo scrub_out($_REQUEST['end']);
}
?>
" />
            </td>
        </tr>
    </table>
    <div class="formValidation">
        <?php 
echo Core::form_register('add_acl');
Beispiel #6
0
     if (!User::check_username($username)) {
         AmpError::add('username', T_('Error Username already exists'));
     }
     // Check the mail for correct address formation.
     if (!Mailer::validate_address($email)) {
         AmpError::add('email', T_('Invalid email address'));
     }
     /* If we've got an error then show add form! */
     if (AmpError::occurred()) {
         require_once AmpConfig::get('prefix') . UI::find_template('show_add_user.inc.php');
         break;
     }
     /* Attempt to create the user */
     $user_id = User::create($username, $fullname, $email, $website, $pass1, $access, $state, $city);
     if (!$user_id) {
         AmpError::add('general', T_("Error: Insert Failed"));
     }
     $user = new User($user_id);
     $user->upload_avatar();
     if ($access == 5) {
         $access = T_('Guest');
     } elseif ($access == 25) {
         $access = T_('User');
     } elseif ($access == 100) {
         $access = T_('Admin');
     }
     /* HINT: %1 Username, %2 Access num */
     show_confirmation(T_('New User Added'), sprintf(T_('%1$s has been created with an access level of %2$s'), $username, $access), AmpConfig::get('web_path') . '/admin/users.php');
     break;
 case 'enable':
     $client = new User($_REQUEST['user_id']);
            </ul>
            </div>
            <?php 
AmpError::display('general');
?>

            <h2><?php 
echo T_('Generate Config File');
?>
</h2>
            <h3><?php 
echo T_('Database connection');
?>
</h3>
            <?php 
AmpError::display('config');
?>
<form method="post" action="<?php 
echo $web_path . "/install.php?action=create_config";
?>
" enctype="multipart/form-data" autocomplete="off">
<div class="form-group">
    <label for="web_path" class="col-sm-4 control-label"><?php 
echo T_('Web Path');
?>
</label>
    <div class="col-sm-8">
        <input type="text" class="form-control" id="web_path" name="web_path" value="<?php 
echo scrub_out($web_path_guess);
?>
">
Beispiel #8
0
 /**
  * create
  * This is a static function that takes a key'd array for input
  * and if everything is good creates the object.
  */
 public static function create(array $data)
 {
     // Make sure we've got a name
     if (!strlen($data['name'])) {
         AmpError::add('name', T_('Name Required'));
     }
     $allowed_array = array('https', 'http', 'mms', 'mmsh', 'mmsu', 'mmst', 'rtsp', 'rtmp');
     $elements = explode(":", $data['url']);
     if (!in_array($elements['0'], $allowed_array)) {
         AmpError::add('url', T_('Invalid URL must be http:// or https://'));
     }
     if (!empty($data['site_url'])) {
         $elements = explode(":", $data['site_url']);
         if (!in_array($elements['0'], $allowed_array)) {
             AmpError::add('site_url', T_('Invalid URL must be http:// or https://'));
         }
     }
     // Make sure it's a real catalog
     $catalog = Catalog::create_from_id($data['catalog']);
     if (!$catalog->name) {
         AmpError::add('catalog', T_('Invalid Catalog'));
     }
     if (AmpError::occurred()) {
         return false;
     }
     // If we've made it this far everything must be ok... I hope
     $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`codec`) " . "VALUES (?, ?, ?, ?, ?)";
     $db_results = Dba::write($sql, array($data['name'], $data['site_url'], $data['url'], $catalog->id, $data['codec']));
     return $db_results;
 }
Beispiel #9
0
 /**
  * update
  * This function is an all encompasing update function that
  * calls the mini ones does all the error checking and all that
  * good stuff
  */
 public function update(array $data)
 {
     if (empty($data['username'])) {
         AmpError::add('username', T_('Error Username Required'));
     }
     if ($data['password1'] != $data['password2'] and !empty($data['password1'])) {
         AmpError::add('password', T_("Error Passwords don't match"));
     }
     if (AmpError::occurred()) {
         return false;
     }
     if (!isset($data['fullname_public'])) {
         $data['fullname_public'] = false;
     }
     foreach ($data as $name => $value) {
         if ($name == 'password1') {
             $name = 'password';
         } else {
             $value = scrub_in($value);
         }
         switch ($name) {
             case 'password':
             case 'access':
             case 'email':
             case 'username':
             case 'fullname':
             case 'fullname_public':
             case 'website':
             case 'state':
             case 'city':
                 if ($this->{$name} != $value) {
                     $function = 'update_' . $name;
                     $this->{$function}($value);
                 }
                 break;
             case 'clear_stats':
                 Stats::clear($this->id);
                 break;
             default:
                 // Rien a faire
                 break;
         }
     }
     return $this->id;
 }
Beispiel #10
0
 public static function process_action($action, $catalogs, $options = null)
 {
     if (!$options || !is_array($options)) {
         $options = array();
     }
     switch ($action) {
         case 'add_to_all_catalogs':
             $catalogs = Catalog::get_catalogs();
         case 'add_to_catalog':
             if ($catalogs) {
                 foreach ($catalogs as $catalog_id) {
                     $catalog = Catalog::create_from_id($catalog_id);
                     if ($catalog !== null) {
                         $catalog->add_to_catalog($options);
                     }
                 }
                 if (!defined('SSE_OUTPUT')) {
                     AmpError::display('catalog_add');
                 }
             }
             break;
         case 'update_all_catalogs':
             $catalogs = Catalog::get_catalogs();
         case 'update_catalog':
             if ($catalogs) {
                 foreach ($catalogs as $catalog_id) {
                     $catalog = Catalog::create_from_id($catalog_id);
                     if ($catalog !== null) {
                         $catalog->verify_catalog();
                     }
                 }
             }
             break;
         case 'full_service':
             if (!$catalogs) {
                 $catalogs = Catalog::get_catalogs();
             }
             /* This runs the clean/verify/add in that order */
             foreach ($catalogs as $catalog_id) {
                 $catalog = Catalog::create_from_id($catalog_id);
                 if ($catalog !== null) {
                     $catalog->clean_catalog();
                     $catalog->verify_catalog();
                     $catalog->add_to_catalog();
                 }
             }
             Dba::optimize_tables();
             break;
         case 'clean_all_catalogs':
             $catalogs = Catalog::get_catalogs();
         case 'clean_catalog':
             if ($catalogs) {
                 foreach ($catalogs as $catalog_id) {
                     $catalog = Catalog::create_from_id($catalog_id);
                     if ($catalog !== null) {
                         $catalog->clean_catalog();
                     }
                 }
                 // end foreach catalogs
                 Dba::optimize_tables();
             }
             break;
         case 'update_from':
             $catalog_id = 0;
             // First see if we need to do an add
             if ($options['add_path'] != '/' && strlen($options['add_path'])) {
                 if ($catalog_id = Catalog_local::get_from_path($options['add_path'])) {
                     $catalog = Catalog::create_from_id($catalog_id);
                     if ($catalog !== null) {
                         $catalog->add_to_catalog(array('subdirectory' => $options['add_path']));
                     }
                 }
             }
             // end if add
             // Now check for an update
             if ($options['update_path'] != '/' && strlen($options['update_path'])) {
                 if ($catalog_id = Catalog_local::get_from_path($options['update_path'])) {
                     $songs = Song::get_from_path($options['update_path']);
                     foreach ($songs as $song_id) {
                         Catalog::update_single_item('song', $song_id);
                     }
                 }
             }
             // end if update
             if ($catalog_id <= 0) {
                 AmpError::add('general', T_("This subdirectory is not part of an existing catalog. Update cannot be processed."));
             }
             break;
         case 'gather_media_art':
             if (!$catalogs) {
                 $catalogs = Catalog::get_catalogs();
             }
             // Iterate throught the catalogs and gather as needed
             foreach ($catalogs as $catalog_id) {
                 $catalog = Catalog::create_from_id($catalog_id);
                 if ($catalog !== null) {
                     require AmpConfig::get('prefix') . UI::find_template('show_gather_art.inc.php');
                     flush();
                     $catalog->gather_art();
                 }
             }
             break;
     }
 }
Beispiel #11
0
    echo scrub_out($client->city);
    ?>
" />
                </td>
            </tr>
        <?php 
}
?>
        <tr>
            <td><?php 
echo T_('New Password');
?>
:</td>
            <td>
                <?php 
AmpError::display('password');
?>
                <input type="password" name="password1" id="password1" />
            </td>
        </tr>
        <tr>
            <td><?php 
echo T_('Confirm Password');
?>
:</td>
            <td>
                <input type="password" name="password2" id="password2" />
            </td>
        </tr>
        <tr>
            <td>
Beispiel #12
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog($type = 0)
 {
     set_time_limit(0);
     $remote_handle = $this->connect();
     if (!$remote_handle) {
         return false;
     }
     // Get the song count, etc.
     $remote_catalog_info = $remote_handle->info();
     // Tell 'em what we've found, Johnny!
     UI::update_text('', sprintf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']));
     // Hardcoded for now
     $step = 500;
     $current = 0;
     $total = $remote_catalog_info['songs'];
     while ($total > $current) {
         $start = $current;
         $current += $step;
         try {
             $songs = $remote_handle->send_command('songs', array('offset' => $start, 'limit' => $step));
         } catch (Exception $e) {
             AmpError::add('general', $e->getMessage());
             AmpError::display('general');
             flush();
         }
         // Iterate over the songs we retrieved and insert them
         foreach ($songs as $data) {
             if ($this->check_remote_song($data['song'])) {
                 debug_event('remote_catalog', 'Skipping existing song ' . $data['song']['url'], 5);
             } else {
                 $data['song']['catalog'] = $this->id;
                 $data['song']['file'] = preg_replace('/ssid=.*?&/', '', $data['song']['url']);
                 if (!Song::insert($data['song'])) {
                     debug_event('remote_catalog', 'Insert failed for ' . $data['song']['self']['id'], 1);
                     AmpError::add('general', T_('Unable to Insert Song - %s'), $data['song']['title']);
                     AmpError::display('general');
                     flush();
                 }
             }
         }
     }
     // end while
     UI::update_text('', T_('Completed updating remote catalog(s).'));
     // Update the last update value
     $this->update_last_update();
     return true;
 }
Beispiel #13
0
/**
 * install_create_account
 * this creates your initial account and sets up the preferences for the -1 user and you
 */
function install_create_account($username, $password, $password2)
{
    if (!strlen($username) or !strlen($password)) {
        AmpError::add('general', T_('No Username/Password specified'));
        return false;
    }
    if ($password !== $password2) {
        AmpError::add('general', T_('Passwords do not match'));
        return false;
    }
    if (!Dba::check_database()) {
        AmpError::add('general', sprintf(T_('Database connection failed: %s'), Dba::error()));
        return false;
    }
    if (!Dba::check_database_inserted()) {
        AmpError::add('general', sprintf(T_('Database select failed: %s'), Dba::error()));
        return false;
    }
    $username = Dba::escape($username);
    $password = Dba::escape($password);
    $insert_id = User::create($username, 'Administrator', '', '', $password, '100');
    if (!$insert_id) {
        AmpError::add('general', sprintf(T_('Administrative user creation failed: %s'), Dba::error()));
        return false;
    }
    // Fix the system users preferences
    User::fix_preferences('-1');
    return true;
}
Beispiel #14
0
 /**
  * create_type
  *
  * This creates a new catalog type entry for a catalog
  * It checks to make sure its parameters is not already used before creating
  * the catalog.
  */
 public static function create_type($catalog_id, $data)
 {
     // TODO: This Method should be required / provided by parent
     $uri = $data['uri'];
     if (substr($uri, 0, 7) != 'http://' && substr($uri, 0, 8) != 'https://') {
         AmpError::add('general', T_('Error: Beets selected, but path is not a URL'));
         return false;
     }
     // Make sure this uri isn't already in use by an existing catalog
     $selectSql = 'SELECT `id` FROM `catalog_beets` WHERE `uri` = ?';
     $db_results = Dba::read($selectSql, array($uri));
     if (Dba::num_rows($db_results)) {
         debug_event('catalog', 'Cannot add catalog with duplicate uri ' . $uri, 1);
         AmpError::add('general', sprintf(T_('Error: Catalog with %s already exists'), $uri));
         return false;
     }
     $insertSql = 'INSERT INTO `catalog_beetsremote` (`uri`, `catalog_id`) VALUES (?, ?)';
     Dba::write($insertSql, array($uri, $catalog_id));
     return true;
 }
Beispiel #15
0
 /**
  * create
  *
  * This takes a keyed array of data and trys to insert it as a
  * new ACL entry
  * @param array $data
  * @return boolean
  */
 public static function create(array $data)
 {
     if (!self::_verify_range($data['start'], $data['end'])) {
         return false;
     }
     // Check existing ACLs to make sure we're not duplicating values here
     if (self::exists($data)) {
         debug_event('ACL Create', 'Error: An ACL equal to the created one already exists. Not adding another one: ' . $data['start'] . ' - ' . $data['end'], 1);
         AmpError::add('general', T_('Duplicate ACL defined'));
         return false;
     }
     $start = @inet_pton($data['start']);
     $end = @inet_pton($data['end']);
     $name = $data['name'];
     $user = $data['user'] ?: '-1';
     $level = intval($data['level']);
     $type = self::validate_type($data['type']);
     $enabled = make_bool($data['enabled']) ? 1 : 0;
     $sql = 'INSERT INTO `access_list` (`name`, `level`, `start`, `end`, ' . '`user`,`type`,`enabled`) VALUES (?, ?, ?, ?, ?, ?, ?)';
     Dba::write($sql, array($name, $level, $start, $end, $user, $type, $enabled));
     return true;
 }
Beispiel #16
0
 public static function create(array $data)
 {
     $feed = $data['feed'];
     // Feed must be http/https
     if (strpos($feed, "http://") !== 0 && strpos($feed, "https://") !== 0) {
         AmpError::add('feed', T_('Wrong feed url'));
     }
     $catalog_id = intval($data['catalog']);
     if ($catalog_id <= 0) {
         AmpError::add('catalog', T_('Target catalog required'));
     } else {
         $catalog = Catalog::create_from_id($catalog_id);
         if ($catalog->gather_types !== "podcast") {
             AmpError::add('catalog', T_('Wrong target catalog type'));
         }
     }
     if (AmpError::occurred()) {
         return false;
     }
     $title = T_('Unknown');
     $website = null;
     $description = null;
     $language = null;
     $copyright = null;
     $generator = null;
     $lastbuilddate = 0;
     $episodes = array();
     $arturl = '';
     $xmlstr = file_get_contents($feed);
     if ($xmlstr === false) {
         AmpError::add('feed', T_('Cannot access the feed.'));
     } else {
         $xml = simplexml_load_string($xmlstr);
         if ($xml === false) {
             AmpError::add('feed', T_('Cannot read the feed.'));
         } else {
             $title = html_entity_decode($xml->channel->title);
             $website = $xml->channel->link;
             $description = html_entity_decode($xml->channel->description);
             $language = $xml->channel->language;
             $copyright = html_entity_decode($xml->channel->copyright);
             $generator = html_entity_decode($xml->channel->generator);
             $lastbuilddatestr = $xml->channel->lastBuildDate;
             if ($lastbuilddatestr) {
                 $lastbuilddate = strtotime($lastbuilddatestr);
             }
             if ($xml->channel->image) {
                 $arturl = $xml->channel->image->url;
             }
             $episodes = $xml->channel->item;
         }
     }
     if (AmpError::occurred()) {
         return false;
     }
     $sql = "INSERT INTO `podcast` (`feed`, `catalog`, `title`, `website`, `description`, `language`, `copyright`, `generator`, `lastbuilddate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $db_results = Dba::write($sql, array($feed, $catalog_id, $title, $website, $description, $language, $copyright, $generator, $lastbuilddate));
     if ($db_results) {
         $id = Dba::insert_id();
         $podcast = new Podcast($id);
         $dirpath = $podcast->get_root_path();
         if (!is_dir($dirpath)) {
             if (mkdir($dirpath) === false) {
                 debug_event('podcast', 'Cannot create directory ' . $dirpath, 1);
             }
         }
         if (!empty($arturl)) {
             $art = new Art($id, 'podcast');
             $art->insert_url($arturl);
         }
         if (count($episodes) > 0) {
             $podcast->add_episodes($episodes);
         }
     }
     return $db_results;
 }
AmpError::display('site_url');
?>
    </td>
</tr>
<tr>
    <td><?php 
echo T_('Stream URL');
?>
</td>
    <td>
        <input type="text" name="url" value="<?php 
echo scrub_out($_REQUEST['url']);
?>
" />
        <?php 
AmpError::display('url');
?>
    </td>
</tr>
<tr>
    <td><?php 
echo T_('Codec');
?>
</td>
    <td>
        <input type="text" name="codec" value="<?php 
echo scrub_out($_REQUEST['codec']);
?>
" />
    </td>
</tr>
Beispiel #18
0
 public static function create(array $data)
 {
     $subject = trim(strip_tags($data['subject']));
     $message = trim(strip_tags($data['message']));
     if (empty($subject)) {
         AmpError::add('subject', T_('Error: Subject Required'));
     }
     $to_user = User::get_from_username($data['to_user']);
     if (!$to_user->id) {
         AmpError::add('to_user', T_('Error: Unknown user'));
     }
     if (!AmpError::occurred()) {
         $from_user = $data['from_user'] ?: $GLOBALS['user']->id;
         $creation_date = $data['creation_date'] ?: time();
         $is_read = $data['is_read'] ?: 0;
         $sql = "INSERT INTO `user_pvmsg` (`subject`, `message`, `from_user`, `to_user`, `creation_date`, `is_read`) " . "VALUES (?, ?, ?, ?, ?, ?)";
         if (Dba::write($sql, array($subject, $message, $from_user, $to_user->id, $creation_date, $is_read))) {
             $insert_id = Dba::insert_id();
             // Never send email in case of user impersonation
             if (!isset($data['from_user']) && $insert_id) {
                 if (Preference::get_by_user($to_user->id, 'notify_email')) {
                     if (!empty($to_user->email)) {
                         $mailer = new Mailer();
                         $mailer->set_default_sender();
                         $mailer->recipient = $to_user->email;
                         $mailer->recipient_name = $to_user->fullname;
                         $mailer->subject = "[" . T_('Private Message') . "] " . $subject;
                         $mailer->message = sprintf(T_("You just received a new private message from %s.\n\n\n        ----------------------\n        %s\n        ----------------------\n\n        %s\n        "), $GLOBALS['user']->fullname, $message, AmpConfig::get('web_path') . "/pvmsg.php?action=show&pvmsg_id=" . $insert_id);
                         $mailer->send();
                     }
                 }
             }
             return $insert_id;
         }
     }
     return false;
 }
Beispiel #19
0
 /**
  * update_remote_catalog
  *
  * Pulls the data from a remote catalog and adds any missing songs to the
  * database.
  */
 public function update_remote_catalog()
 {
     debug_event('subsonic_catalog', 'Updating remote catalog...', 5);
     $subsonic = $this->createClient();
     $songsadded = 0;
     // Get all artists
     $artists = $subsonic->getIndexes();
     if ($artists['success']) {
         foreach ($artists['data']['indexes']['index'] as $index) {
             foreach ($index['artist'] as $artist) {
                 // Get albums for artist
                 $albums = $subsonic->getMusicDirectory(array('id' => $artist['id']));
                 if ($albums['success']) {
                     foreach ($albums['data']['directory']['child'] as $album) {
                         if (is_array($album)) {
                             $songs = $subsonic->getMusicDirectory(array('id' => $album['id']));
                             if ($songs['success']) {
                                 foreach ($songs['data']['directory']['child'] as $song) {
                                     if (is_array($song)) {
                                         $data = array();
                                         $data['artist'] = html_entity_decode($song['artist']);
                                         $data['album'] = html_entity_decode($song['album']);
                                         $data['title'] = html_entity_decode($song['title']);
                                         $data['bitrate'] = $song['bitRate'] * 1000;
                                         $data['size'] = $song['size'];
                                         $data['time'] = $song['duration'];
                                         $data['track'] = $song['track'];
                                         $data['disk'] = $song['discNumber'];
                                         $data['mode'] = 'vbr';
                                         $data['genre'] = explode(' ', html_entity_decode($song['genre']));
                                         $data['file'] = $this->uri . '/rest/stream.view?id=' . $song['id'] . '&filename=' . urlencode($song['path']);
                                         if ($this->check_remote_song($data)) {
                                             debug_event('subsonic_catalog', 'Skipping existing song ' . $data['path'], 5);
                                         } else {
                                             $data['catalog'] = $this->id;
                                             debug_event('subsonic_catalog', 'Adding song ' . $song['path'], 5, 'ampache-catalog');
                                             if (!Song::insert($data)) {
                                                 debug_event('subsonic_catalog', 'Insert failed for ' . $song['path'], 1);
                                                 AmpError::add('general', T_('Unable to Insert Song - %s'), $song['path']);
                                             } else {
                                                 $songsadded++;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 debug_event('subsonic_catalog', 'Song error:' . $songs['error'], 3);
                                 AmpError::add('general', T_('Song Error.') . ": " . $songs['error']);
                             }
                         }
                     }
                 } else {
                     debug_event('subsonic_catalog', 'Album error:' . $albums['error'], 3);
                     AmpError::add('general', T_('Album Error.') . ": " . $albums['error']);
                 }
             }
         }
         UI::update_text('', T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
         // Update the last update value
         $this->update_last_update();
     } else {
         debug_event('subsonic_catalog', 'Artist error:' . $artists['error'], 3);
         AmpError::add('general', T_('Artist Error.') . ": " . $artists['error']);
     }
     debug_event('subsonic_catalog', 'Catalog updated.', 5);
     return true;
 }
Beispiel #20
0
 /**
  * Add the song to the DB
  * @param array $song
  * @return integer
  */
 protected function insertSong($song)
 {
     $inserted = Song::insert($song);
     if ($inserted) {
         debug_event('beets_catalog', 'Adding song ' . $song['file'], 5, 'ampache-catalog');
     } else {
         debug_event('beets_catalog', 'Insert failed for ' . $song['file'], 1);
         AmpError::add('general', T_('Unable to Insert Song - %s'), $song['file']);
         AmpError::display('general');
     }
     flush();
     return $inserted;
 }
Beispiel #21
0
     $_POST['username'] = $GLOBALS['user']->username;
     $mandatory_fields = (array) AmpConfig::get('registration_mandatory_fields');
     if (in_array('fullname', $mandatory_fields) && !$_POST['fullname']) {
         AmpError::add('fullname', T_("Please fill in your full name (Firstname Lastname)"));
     }
     if (in_array('website', $mandatory_fields) && !$_POST['website']) {
         AmpError::add('website', T_("Please fill in your website"));
     }
     if (in_array('state', $mandatory_fields) && !$_POST['state']) {
         AmpError::add('state', T_("Please fill in your state"));
     }
     if (in_array('city', $mandatory_fields) && !$_POST['city']) {
         AmpError::add('city', T_("Please fill in your city"));
     }
     if (!$GLOBALS['user']->update($_POST)) {
         AmpError::add('general', T_('Error Update Failed'));
     } else {
         $GLOBALS['user']->upload_avatar();
         //$_REQUEST['action'] = 'confirm';
         $title = T_('Updated');
         $text = T_('Your Account has been updated');
         $next_url = AmpConfig::get('web_path') . '/preferences.php?tab=account';
     }
     $notification_text = T_('User updated successfully');
     break;
 case 'grant':
     // Make sure we're a user and they came from the form
     if (!Access::check('interface', '25') && $GLOBALS['user']->id > 0) {
         UI::access_denied();
         exit;
     }
echo T_('Confirm Password');
?>
:</label>
                        <input type='password' name='password_2' id='password_2' />
                    </div>

                    <br />
                    <div class="registerInformation">
                        <span><?php 
echo T_('* Required fields');
?>
</span>
                    </div>

                    <?php 
if (AmpConfig::get('captcha_public_reg')) {
    echo captcha::form("&rarr;&nbsp;");
    AmpError::display('captcha');
}
?>

                    <div class="registerButtons">
                        <input type="hidden" name="action" value="add_user" />
                        <input type='submit' name='submit_registration' id='submit_registration' value='<?php 
echo T_('Register User');
?>
' />
                    </div>
                </form>
<?php 
UI::show_footer();
Beispiel #23
0
 /**
  * _clean_chunk
  * This is the clean function, its broken into
  * said chunks to try to save a little memory
  */
 private function _clean_chunk($media_type, $chunk, $chunk_size)
 {
     debug_event('clean', "Starting chunk {$chunk}", 5);
     $dead = array();
     $count = $chunk * $chunk_size;
     $sql = "SELECT `id`, `file` FROM `{$media_type}` " . "WHERE `catalog`='{$this->id}' LIMIT {$count},{$chunk_size}";
     $db_results = Dba::read($sql);
     while ($results = Dba::fetch_assoc($db_results)) {
         debug_event('clean', 'Starting work on ' . $results['file'] . '(' . $results['id'] . ')', 5);
         $count++;
         if (UI::check_ticker()) {
             $file = str_replace(array('(', ')', '\''), '', $results['file']);
             UI::update_text('clean_count_' . $this->id, $count);
             UI::update_text('clean_dir_' . $this->id, scrub_out($file));
         }
         $file_info = Core::get_filesize(Core::conv_lc_file($results['file']));
         if (!file_exists(Core::conv_lc_file($results['file'])) || $file_info < 1) {
             debug_event('clean', 'File not found or empty: ' . $results['file'], 5);
             AmpError::add('general', sprintf(T_('Error File Not Found or 0 Bytes: %s'), $results['file']));
             // Store it in an array we'll delete it later...
             $dead[] = $results['id'];
         } else {
             if (!Core::is_readable(Core::conv_lc_file($results['file']))) {
                 debug_event('clean', $results['file'] . ' is not readable, but does exist', 1);
             }
         }
     }
     return $dead;
 }
Beispiel #24
0
AmpError::display('email');
?>
    </td>
</tr>
<tr>
    <td><?php 
echo T_('Website');
?>
</td>
    <td>
        <input type="text" name="website" value="<?php 
echo scrub_out($_REQUEST['website']);
?>
" />
        <?php 
AmpError::display('website');
?>
    </td>
</tr>
</table>
<div class="formValidation">
    <?php 
echo Core::form_register('add_label');
?>
    <input class="button" type="submit" value="<?php 
echo T_('Add');
?>
" />
</div>
</form>
<?php 
?>
</li>
    </ul>
    <p><strong><?php 
echo T_('Step 3 - Set up the initial account');
?>
</strong></p>
    <dl>
        <dd><?php 
echo T_('This step creates your initial Ampache admin account. Once your admin account has been created you will be redirected to the login page.');
?>
</dd>
    </dl>
</div>
    <?php 
AmpError::display('general');
?>
    <h2><?php 
echo T_('Create Admin Account');
?>
</h2>
    <form method="post" action="<?php 
echo $web_path . "/install.php?action=create_account&amp;htmllang={$htmllang}&amp;charset={$charset}";
?>
" enctype="multipart/form-data">

<div class="form-group">
    <label for="local_username" class="col-sm-3 control-label"><?php 
echo T_('Username');
?>
</label>
Beispiel #26
0
     switch (AmpConfig::get('auto_user')) {
         case 'admin':
             $access = '100';
             break;
         case 'user':
             $access = '25';
             break;
         case 'guest':
         default:
             $access = '5';
             break;
     }
     // auto-user level
     $new_user = User::create($username, $fullname, $email, $website, $pass1, $access, $state, $city, AmpConfig::get('admin_enable_required'));
     if (!$new_user) {
         AmpError::add('duplicate_user', T_("Error: Insert Failed"));
         require_once AmpConfig::get('prefix') . UI::find_template('show_user_registration.inc.php');
         break;
     }
     if (!AmpConfig::get('user_no_email_confirm')) {
         $client = new User($new_user);
         $validation = md5(uniqid(rand(), true));
         $client->update_validation($validation);
         // Notify user and/or admins
         Registration::send_confirmation($username, $fullname, $email, $website, $pass1, $validation);
     }
     require_once AmpConfig::get('prefix') . UI::find_template('show_registration_confirmation.inc.php');
     break;
 case 'show_add_user':
 default:
     require_once AmpConfig::get('prefix') . UI::find_template('show_user_registration.inc.php');
Beispiel #27
0
 /**
  * update_360051
  *
  * Copy default .htaccess configurations
  */
 public static function update_360051()
 {
     require_once AmpConfig::get('prefix') . '/lib/install.lib.php';
     if (!install_check_server_apache()) {
         debug_event('update', 'Not using Apache, update 360051 skipped.', '5');
         return true;
     }
     $htaccess_play_file = AmpConfig::get('prefix') . '/play/.htaccess';
     $htaccess_rest_file = AmpConfig::get('prefix') . '/rest/.htaccess';
     $htaccess_channel_file = AmpConfig::get('prefix') . '/channel/.htaccess';
     $ret = true;
     if (!is_readable($htaccess_play_file)) {
         $created = false;
         if (check_htaccess_play_writable()) {
             if (!install_rewrite_rules($htaccess_play_file, AmpConfig::get('raw_web_path'), false)) {
                 AmpError::add('general', T_('File copy error.'));
             } else {
                 $created = true;
             }
         }
         if (!$created) {
             AmpError::add('general', T_('Cannot copy default .htaccess file.') . ' Please copy <b>' . $htaccess_play_file . '.dist</b> to <b>' . $htaccess_play_file . '</b>.');
             $ret = false;
         }
     }
     if (!is_readable($htaccess_rest_file)) {
         $created = false;
         if (check_htaccess_rest_writable()) {
             if (!install_rewrite_rules($htaccess_rest_file, AmpConfig::get('raw_web_path'), false)) {
                 AmpError::add('general', T_('File copy error.'));
             } else {
                 $created = true;
             }
         }
         if (!$created) {
             AmpError::add('general', T_('Cannot copy default .htaccess file.') . ' Please copy <b>' . $htaccess_rest_file . '.dist</b> to <b>' . $htaccess_rest_file . '</b>.');
             $ret = false;
         }
     }
     if (!is_readable($htaccess_channel_file)) {
         $created = false;
         if (check_htaccess_channel_writable()) {
             if (!install_rewrite_rules($htaccess_channel_file, AmpConfig::get('raw_web_path'), false)) {
                 AmpError::add('general', T_('File copy error.'));
             } else {
                 $created = true;
             }
         }
         if (!$created) {
             AmpError::add('general', T_('Cannot copy default .htaccess file.') . ' Please copy <b>' . $htaccess_channel_file . '.dist</b> to <b>' . $htaccess_channel_file . '</b>.');
             $ret = false;
         }
     }
     return $ret;
 }
AmpError::display('stream_type');
?>
    </td>
</tr>
<tr>
    <td><?php 
echo T_('Bitrate');
?>
</td>
    <td>
        <input type="text" name="bitrate" value="<?php 
echo scrub_out($_REQUEST['bitrate'] ?: '128');
?>
" />
        <?php 
AmpError::display('bitrate');
?>
    </td>
</tr>
</table>
<div class="formValidation">
    <?php 
echo Core::form_register('add_channel');
?>
    <input class="button" type="submit" value="<?php 
echo T_('Create');
?>
" />
</div>
</form>
<?php 
Beispiel #29
0
 /**
  * gather_folder
  * This returns the art from the folder of the files
  * If a limit is passed or the preferred filename is found the current
  * results set is returned
  * @param int $limit
  * @return array
  */
 public function gather_folder($limit = 5)
 {
     if (!$limit) {
         $limit = 5;
     }
     $results = array();
     $preferred = false;
     // For storing which directories we've already done
     $processed = array();
     /* See if we are looking for a specific filename */
     $preferred_filename = AmpConfig::get('album_art_preferred_filename');
     // Array of valid extensions
     $image_extensions = array('bmp', 'gif', 'jp2', 'jpeg', 'jpg', 'png');
     $dirs = array();
     if ($this->type == 'album') {
         $media = new Album($this->uid);
         $songs = $media->get_songs();
         foreach ($songs as $song_id) {
             $song = new Song($song_id);
             $dirs[] = Core::conv_lc_file(dirname($song->file));
         }
     } else {
         if ($this->type == 'video') {
             $media = new Video($this->uid);
             $dirs[] = Core::conv_lc_file(dirname($media->file));
         }
     }
     foreach ($dirs as $dir) {
         if (isset($processed[$dir])) {
             continue;
         }
         debug_event('folder_art', "Opening {$dir} and checking for Album Art", 3);
         /* Open up the directory */
         $handle = opendir($dir);
         if (!$handle) {
             AmpError::add('general', T_('Error: Unable to open') . ' ' . $dir);
             debug_event('folder_art', "Error: Unable to open {$dir} for album art read", 2);
             continue;
         }
         $processed[$dir] = true;
         // Recurse through this dir and create the files array
         while (false !== ($file = readdir($handle))) {
             $extension = pathinfo($file);
             $extension = $extension['extension'];
             // Make sure it looks like an image file
             if (!in_array($extension, $image_extensions)) {
                 continue;
             }
             $full_filename = $dir . '/' . $file;
             // Make sure it's got something in it
             if (!Core::get_filesize($full_filename)) {
                 debug_event('folder_art', "Empty file, rejecting {$file}", 5);
                 continue;
             }
             // Regularise for mime type
             if ($extension == 'jpg') {
                 $extension = 'jpeg';
             }
             // Take an md5sum so we don't show duplicate
             // files.
             $index = md5($full_filename);
             if ($file == $preferred_filename) {
                 // We found the preferred filename and
                 // so we're done.
                 debug_event('folder_art', "Found preferred image file: {$file}", 5);
                 $preferred[$index] = array('file' => $full_filename, 'mime' => 'image/' . $extension, 'title' => 'Folder');
                 break;
             }
             debug_event('folder_art', "Found image file: {$file}", 5);
             $results[$index] = array('file' => $full_filename, 'mime' => 'image/' . $extension, 'title' => 'Folder');
         }
         // end while reading dir
         closedir($handle);
     }
     // end foreach dirs
     if (is_array($preferred)) {
         // We found our favourite filename somewhere, so we need
         // to dump the other, less sexy ones.
         $results = $preferred;
     }
     debug_event('folder_art', 'Results: ' . json_encode($results), 5);
     if ($limit && count($results) > $limit) {
         $results = array_slice($results, 0, $limit);
     }
     return array_values($results);
 }
Beispiel #30
0
require_once 'lib/init.php';
$action = isset($_POST['action']) ? $_POST['action'] : "";
switch ($action) {
    case 'send':
        /* Check for posted email */
        $result = false;
        if (isset($_POST['email']) && $_POST['email']) {
            /* Get the email address and the current ip*/
            $email = scrub_in($_POST['email']);
            $current_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
            $result = send_newpassword($email, $current_ip);
        }
        if ($result) {
            AmpError::add('general', T_('Password has been sent'));
        } else {
            AmpError::add('general', T_('Password has not been sent'));
        }
        require AmpConfig::get('prefix') . UI::find_template('show_login_form.inc.php');
        break;
    default:
        require AmpConfig::get('prefix') . UI::find_template('show_lostpassword_form.inc.php');
}
function send_newpassword($email, $current_ip)
{
    /* get the Client and set the new password */
    $client = User::get_from_email($email);
    if ($client && $client->email == $email) {
        $newpassword = generate_password(6);
        $client->update_password($newpassword);
        $mailer = new Mailer();
        $mailer->set_default_sender();